Saturday, May 8, 2010

Palatino bug in iBooks on iPad

[Update: With iBooks 1.1, Apple has changed much of the system for applying fonts. Please read Apple damaging ePub standards with pseudo-support and Apple kills fonts in iBooks, strikes blow to standards.]

I discovered a big and important bug in iBooks on the iPad: if you don't have some text specified as Palatino (in some form or other), no other fonts will be displayed and everything will display in Palatino.

So, imagine you have this for your CSS:

p.palatino {font-family:"Palatino";}
p.other {font-family:"Optima";}

In the XHTML, the first paragraph is styled with the palatino class, and the rest is other.

Since Palatino is explicitly called, everything is displayed correctly:
palatino bug1
Now, you decide you don't really want Palatino, but would prefer Zapfino. Your CSS now looks like this:

p.palatino {font-family:"Zapfino";}
p.other {font-family:"Optima";}

Here's where the bug kicks in. Since there is no paragraph explicitly or implicitly styled with Palatino, iBooks freaks out and makes everything Palatino:
palatino bug 2
There are various solutions. As you can see with the first example, if Palatino is called for and used explicitly, everything is fine.

But you don't actually have to call the font explicitly, you can just call no font (which in effect also means Palatino, since that's the default font in iBooks). I've tried this with explicitly font-related styles, like font-size, and with less font-related properties like text-align. As long as there's some selector with at least one rule, and that doesn't specify a font, you're good:

p {text-align:left;}
p.other {font-family:"Optima";}

And again, it works fine:
palatino bug 4

Ah, but what if you don't want Palatino in your ebook at all? If you remove it from the XHTML, even if you leave it in the CSS, iBooks goes nutso again:
palatino bug6
The solution is to leave a Palatino style in your CSS, with display:none if you like and call that style at least once in your XHTML.

CSS:
p.palatino {font-family:"Palatino";display:none;}
p.other {font-family:"Optima";}

XHTML:
<p class="palatino"> </p>

And voilĂ : no Palatino, and the Optima (or whatever other font you want), displays perfectly well!
palatino bug7

13 comments:

  1. All that is a bit scary. Shades of doing CSS hacks for ADE. I can see an ePub that is doing more than a novel, having about 5K of device hack CSS just to start the various engines.

    Without appearing to order up additional tests Liz, does the same happen with the default font-family: serif; and font-family: sans-serif, and of course faithful old monospace. I noticed some errors on my own books using generic font names after playing with the default font as per your earlier post.

    ReplyDelete
  2. What I like most about my iPad is the possibility to read ebooks on it.

    ReplyDelete
  3. How is the ePub/iBook tomb coming? I hope it will be in iBook format, as I find it difficult to use your HTML book in it's Kindle form: no search capability, for example, and I must go through highlights and notes manually. Awkward. Good writing,

    ReplyDelete
  4. Sorry. tome. Hope that wasn't some kind of a Freudian slip

    ReplyDelete
  5. I hope you've logged this as a bug in iBooks with Apple via Radar (their bug reporting/tracking tool). Otherwise they aren't going to address it ... https://bugreport.apple.com/cgi-bin/WebObjects/RadarWeb.woa/wa/signIn

    ReplyDelete
  6. Love all the work you're doing, Liz.

    ReplyDelete
  7. Is this still an issue or has it been fixed in iBooks?
    I'm mucking about with an epub version of one of my favourite books. I converted from it's original .pdb format into .epub with Calibre and now I'm going through it page by page trying to make it resemble the same fonts and page inserts that my original hardback copy has.

    However, looking through the files in Sigil, I cannot see Palatino declared anywhere in the css. But when I've specified Zapfino for a "In the beginning..." line at the start, it displays fine.
    I shall perform some tests on fresh files tonight after work and let you know.

    ReplyDelete
  8. Yes, as far as I know, it's still an issue. If you have an example that doesn't trigger it, I'd love to see it.

    Note that Apple will be releasing an update to iBooks at the end of June with the new iPhone. Hopefully, this bug will be fixed then (I'll post it here if so).

    ReplyDelete
  9. ah no, i see where i went wrong. i had a paragraph style in the css that was setting font size and nothing else. but as you say above, that is sufficient to make it think you are specifying palatino as the default font.

    ReplyDelete
  10. That Palatino bug is pretty bad-after reading your blog about it, I checked a book that was saved in Sigil that had that problem...and Sigil breaks up the ePub internally into multiple XML documents...and I think the "palatino" thing has to be put in every XML document in the ePub. Hopefully they fix the issue soon.

    Apple Blog

    ReplyDelete
  11. @faris. Well, in iBooks 1.1.1 it's worse. This solution no longer works. See http://www.pigsgourdsandwikis.com/2010/06/apple-kills-fonts-in-ibooks-strikes.html

    ReplyDelete
  12. Hello Liz,

    my name is Theresa, I am a student of book and media production in Leipzig/Germany.Currently I am doing a presentation on Typography on mobile devices. I've been reading all your posts about font-embedding on iBooks and ePub and wanted to ask, if you know whether this problem has been solved in iBooks or if it is still an issue, I could report about in my presentation. It would be wonderful, if you could answer me. Gladly via eMail too (theresa.neubauer@gmail.com)

    Thank you very much!
    Best, Theresa

    ReplyDelete

More of my books