Tuesday, December 21, 2010

Opening new windows in iBooks

Rick Gordon mentioned that the ebooks on programming that Apple just published to the iBookstore had some interesting features, among them tables that opened up into a new window, similarly to what happens when you double-click an image:
  • the table fills the iPad space, ignoring the typical iBooks margins,
  • the regular navigational and presentation features disappear, so you can't move directly to the next page, or change the font or font-size
  • if the table doesn't fit in the space, you can pan down or to the right to see the rest of it
  • double-clicking the table or clicking Done in the upper-right corner returns you to where you were
  • although tables are a natural use for new windows, you can put anything in one
Here is the table as it would appear regularly in iBooks (ew!):
Open New Windows in iBooks

And here is what it looks like in its own window (ah!):
Open New Windows in iBooks

You can pan down to see the lower part of the table:
Open New Windows in iBooks

And when you tilt the iPad vertically, the table resizes to fit:
Open New Windows in iBooks

Since tables are really hard to show well in iBooks (or any ereader), this is a really welcome development. Now, any time you have a complicated table, instead of risking having it mangled, you can just have it show up in its own neat window, and be sure your readers will be able to see it properly.

How do you do it? You simply go into the content.opf file and in the spine section add linear="no" to the document that should open in its own window. Remember that the spine is the place where you define the order of the documents in your ebook. I have complete details about the content.opf file, and the spine in particular, in my book, EPUB Straight to the Point.

I've found that the text in the new window is smaller by default than text in the regular book pages. Again, it is not affected by the text size choice of the reader, so you have to make sure you set it big enough to start with.

You can download my sample EPUB file and look at the code. It's published with a Share Alike and Give Attribution Creative commons license. You'll notice that ePubCheck complains that I didn't fix the Wikipedia footnotes and that I didn't get rid of the iTunesMetadata.plist file. But I'm running out of time and wanted to get this up today. I'll fix those minor things later.

It feels like there's a lot we can do with us. I'd love to hear about what you create!

If you like this article, consider buying my book. It's a great foundation for all things EPUB.

Friday, December 17, 2010

Apple disses ebook developers at its peril

I'm feeling really grumpy today, and I've traced it back to a Twitter conversation last night in which I discovered that Apple has been giving support and information on how to create their new fixed-layout ebooks for iBooks 1.2 only to a select group of ebook producers, and under non-disclosure agreements (NDA).

I just don't understand why Apple wouldn't want to help all ebook developers make great looking ebooks that display beautifully on the iPad and so help sell millions of units. Instead, those of us who aren't on the list have to sleuth out, through time-intensive trial and error, just what will work and what won't.

Sure, that's my job. I'm good at explaining how to do things and figuring what people want and need to know and putting it in a way that makes sense. I don't need them to help me. But what I don't understand is why they don't want to. Why do they want to keep their documentation a secret?

That's not Apple's strategy for Safari, whose documentation is very useful and complete. Perhaps that is because they realize the web does not belong to them? The only way to compete is to offer a powerful browser and to explain to people how to get the most out of it.

For iBooks, though, it's all hush-hush. Perhaps they don't want to admit that they're new fixed layout "illustrated books" are nothing more than glorified PDFs— EPUB files in name only. Perhaps not invalid, but many of these fixed layout books are almost impossible to read because the type is so small, and they are all but unusable on smaller screens than the iPad. What is the point?

And Apple has been less than forthcoming with information about earlier versions of iBooks as well, publicizing books that violate the very requirements listed on their web site, promising to follow the EPUB standard, but picking and choosing just which pieces to support.

The ebook market has taken many years to take off, since both readers and books are needed to make it go, and both were lacking. When ereaders were so expensive, few people had them, so there was little demand and thus little production of ebooks. For me, the iPad was a fiendish way to get ereaders into the hands of millions of people who were curious about ebooks but reluctant to spend $400 on a standalone ereader. iPad buyers could justify the price because of all the other things it could do. All of a sudden, millions of people had an ereader, and were clamoring for more books. It was only after the iPad existed that the price of the Kindle and Nook fell to the ground, encouraging even more people to jump on board. More ereaders means more demand for ebooks, which makes ereaders more attractive, and so on.

Apple's strengths in the ebook market are its beautiful color ereaders (e.g., iBooks on iPad), its support of HTML5 to include audio and video, and its embrace of the standard, non-proprietary EPUB format. These features are a big part of why EPUB is still a viable option, in the face of Amazon's juggernaut.

But an ereader is only as good as the books you can read on it. The iBookstore is practically empty. I hear from more and more people that they would like to buy books from the iBookstore but what they're looking for is not available. No wonder, if Apple is keeping its documentation under lock and key. I would love to help people make gorgeous books for the iPad and iPhone. Apple, you ignore us at your peril.

Thursday, December 16, 2010

Page Breaks in iBooks 1.2 (Updated!)

Updated 11 Feb 2011: The bug described in this post has been fixed as of iBooks 1.2.1. The app now recognizes the page-break properties both in local CSS and external CSS. See Page Breaks, Turning off Hyphenation and Horizontal Bolding Bug in iBooks for more details.

One of the most annoying failings of iBooks to date has been its lack of support of one of CSS' most basic controls: when and where to place page breaks in the text. Without this control, you can't force a header to begin at the top of the page, nor keep a caption with its paragraph.

When the new version of iBooks came out yesterday, I heard (through Fabio Brivio on Twitter) that these page break controls were now supported, but I couldn't seem to make it work. I asked Fabio if he would share his EPUB with me, and he kindly emailed it. (Thanks, Fabio!)

After pulling it apart, and applying it to my files, I finally figured it out what the key was: iBooks only supports CSS page break controls when they're in a local style sheet. They won't work in an external one.

So, if you want each of your h3 elements to begin on a new page, in the head section of each of the pages in your EPUB, add:

<style type="text/css">
h3 {page-break-before: always;}
</style>


pagebreakbefore

Other possible values for page-break-before include avoid, if you'd rather a page break did not occur right before the element, and the very interesting, but not yet supported left and right, which push the element in question to the first left or right page, respectively.

You can also create page breaks after an element (or group of elements). Use page-break-after.

Finally, you can use page-break-inside: avoid to keep an element on a single page. For example, you might apply this rule to a div that contained an image and its caption.

CSS also has ways for controlling widows and orphans (stray lines that appear at the top and bottom of pages), but unfortunately, iBooks doesn't yet support them. (Nook, and other ereaders, do.)

I cover these page break features in detail in my book, HTML, XHTML, and CSS: Visual QuickStart Guide, which is a big help for any EPUB book designer who wants to create a really polished ebook. You can learn more about how to get inside an EPUB file, and what to do there, in my EPUB Straight to the Point.

At some point, iBooks will properly support all of the page break values, and will support them both in local CSS as well as the more useful and common external CSS. You'll read about it here first!

Embedding Fonts in iBooks 1.2



Actually, you've been able to embed fonts since iBooks 1.12, but you needed iOS 4.2 to make it work. I'll go over it anyway, because it's awesome.

First, you need to use OpenType Fonts. They have the .otf extension. It looks like TrueType fonts (with the .ttf extension) and on which OpenType fonts are based, are also OK. Remember that getting a font into your ebook is only a part of the battle. You also have to have the permission to distribute the font with your book. Read the font license carefully.

Once you have a font file that you want to embed for your ebook, there are two steps you have to follow. First, you have to use an @font-face rule at the top of your CSS file.

Something like this:

@font-face {
font-family: "FontName";
font-style: normal;
font-weight: normal;
src: url(../fonts/Fontname.otf);
}


I have not found much correlation between specifying a font-style or font-weight in the @font-face rule and success. That is, sometimes I've found that for an italic font you have to specify font-style: italic and sometimes you have to specify font-style: normal, which makes little sense, but that's the way it goes. It does seem necessary to create an @font-face rule for each and every style of every font you want to embed.

The next step is to use the fonts that you've now embedded in the actual style rules of your document:

p {font-family: "FontName";
font-size: 2em;
...
}


It's important that the font name you use be the official one. Any multi-word names should be enclosed in quotes.

The third step is to place the OTF font files in a fonts folder within your OEBPS folder in your EPUB document. If the actual font files aren't in there, they won't be embedded.

And finally, you have to declare those font files in the manifest of your EPUB:

<item id="fontname" href="fonts/fontname.otf" media-type="application/x-font-otf" />

(You can find more details on the manifest in my EPUB Straight to the Point book.)

You can use any id as long as it's unique. Make sure the path accurately reflects where you plced the OTF file. And be sure and use "application/x-font-otf" for the media-type.

And you're done! Here's a screenshot from one of Apple's new illustrated books with a new font. Note that Apple has used the font, Filosofia Regular, for the body text, even though their Publication guidelines expressly discourage such usage. They use various forms of Caecilia for the notes and inline headers.

EmbedFonts

And herein lies one of the main problems with the new "illustrated books" in iBooks 1.2. The reader can't change the font, and the reader can't change the font size. The text in this particular book is really hard to read. I'm racking my brain trying to figure out why this is better than a PDF, but I don't get it yet.

iBooks 1.2 - Going Back and Forward

There are lots of interesting features in the new version of iBooks 1.2. I'm going to see if I can get through them all today, but instead of putting them all in one post, I'm going to publish them as I finish each section.

You can go back

Now when you click on a link in a book a tiny link appears in the lower left corner of the page allowing you go back to the page from whence you came. When you go back, there is then a link in the lower right corner letting you go back to where you came back from (that is, forward).

This is a huge improvement, and makes footnotes/endnotes and links in general MUCH more useful. I love it.

Imagine you're on a links page in Walden:

backlink

You click on the line "I have always been regretting that I was not as wise as the day I was born." and jump to the page that contains that link.

In the bottom-left corner of the new page, you see "Back to page xx".

Backbutton-aft

If you click on it, you'll go back to the page you came from. And now on the page you came from, you'll see a light gray link in the bottom-right corner that lets you go forward again to the page you had clicked to go to.

Thursday, December 9, 2010

Apple, stop invalidating my EPUBs with your iTunesMetadata.plist file

Dear Apple:

I'm really tired of iTunes adding an iTunesMetadata.plist file to my original EPUB files every time I test said EPUB files on my iPad or iPhone through iTunes. To add insult to injury, every time you do it, it causes an error in ePubCheck—since the EPUB file now contains a non-manifested file—thus making the file invalid for uploading to your iBookstore.

Could you please quit it?

Sincerely,
Liz Castro

____________

Feel the same way? Feel free to copy the above letter and post it in your own name to Apple's Feedback page for iTunes. Perhaps if enough of us speak up, they'll listen.

For more information, see iTunes invalidates EPUB file for iBookstore???

More of my books