By now, I am sure you’ve heard that every device in the market has its own little quirks. Whether it’s not scaling images correctly, ignoring transparency, overlooking style settings in certain tags or some other weird behavior, the process of formatting ebooks across platforms is anything than straight-forward.

Today I want to direct your attention to one issue in particular, the way iBooks is handling font switches. Ordinarily, and on all other platforms, changing the font in a block of text is one of the most rudimentary and trivial things to do. You would set up styles and then use a, <p>, <span> or <label> tag to switch the style and consequently the font type with it, just as outlined here with these style settings…

span.sans-serif { font-family: sans-serif; }
span.serif { font-family: serif; }
span.monospace { font-family: monospace; }

…and the following HTML paragraph.

<p>This is an example for a <span class=”sans-serif”>sans-serif font</span>, while this is a switch to a <span class=”monospace”>monospace font</span> and this here a quick look at a <span class=”serif”>serif font</span>.</p>

Unfortunately on various occasions, Apple has decided, for unfathomable reasons, to break with convention and create implementations that are more tedious than they really need to be. The approach I just illustrated is not working in iBooks—or rather I should say, it is not always working. Especially when you use embedded fonts that are included using the @font-face rule, you will find that they simply do not show up.

There are two small additional steps that are necessary to get iBooks to properly display your fonts, though small they may be, they are also incredibly cumbersome.

The process involves getting inside the actual ePub file and adding information. Fortunately Calibre lets us do that fairly elegantly, but it is nonetheless a tedium because you will have to do this every time you rebuild your book.

When you right-click your book in Calibre a context menu appears and you will find an entry called “Edit the book” at the bottom of the list. Naturally you will first have to build an ePub version of your book for this to show up, but when you select it, a new window will open showing you the structure of the eBook on the left hand side and the file contents at the center. You now have access to the internal structure of the ePub file, which is a packaged-up assortment of individual files, actually.

In the Files Browser window on the left side of the screen scroll down to the Miscellaneous area where you will find a file called content.opf. Double-click that file and its contents will be displayed in the large window at the center of the screen.

Now enter the following code in that file

<meta property="ibooks:specified-fonts">true</meta>

Best place it right at the end of the <metadata> section just before the closing </metadata> tag.

Now comes the trickier part. We actually need to include a completely new file. First open up a text editor and create a new text file. There, enter the following lines


<display_options>
   <platform name="*"> <!-- allowed values for platform "iphone", "ipad", or "*" for all -->
     <option name="specified-fonts">true <!-- must be set to "true" for embedded fonts -->
   </platform>
</display_options>

and then save the file as com.apple.ibooks.display-options.xml. Alternatively, simply right-click this link and save the file to your computer.

addbtnWith the “Edit Book” details page still open in Calibre, click on the “New File” icon in the upper left corner of the window.

Now enter meta-inf/com.apple.ibooks.display-options.xml in the dialog box and then click on the “Import resource file” button. Locate and chose the com.apple.ibooks.display-options.xml file just we created and hit the “Open” button, followed by “Okay.” You will now see that the file com.apple.ibooks.display-options.xml is appearing in the “Miscellaneous” section of the book structure.

savebtnNow save your changes and close the “Edit Book” window. Back on the Calibre main screen, hit the “Save to Disc” button to save the modified ePub version to your computer.

That is it. You now have properly embedded the necessary information in your ePub file that makes it possible for iOS devices to correctly display different fonts.

If you do not use Calibre, you can also make these changes by hand. All you have to do is unzip your ePub file using whatever software you would ordinarily use to unzip a regular ZIP file.

Once completed, you will find a subfolder on your computer, containing the individual files the eBook consists of. Locate the file content.opf and make the same changes I described above.

Then navigate into the meta-inf subfolder and place the file com.apple.ibooks.display-options.xml in there. The process to create or obtain the file is the same one I described earlier.

The changes are now complete, but will have to zip all these files back up into an ePub file.

This is best done using a command line version of your zip tool. Once you have opened a command line or terminal on your computer, navigate to the directory where your actual eBook files are that you need to zip up. Then enter the following command.

zip -X0 ebook.zip mimetype

This creates the base package for the eBook. We now zip all the content files into it using the following command

zip -rDX9 ebook.zip * -x "*.DS_Store" -x mimetype

Once this is complete, you will see a new file called ebook.zip in the folder. All we need to do is rename it now. If you are working on a Windows computer, simply enter the following command.

ren ebook.zip title_of_your_book.epub

Alternatively, if you are working on a Mac, the following command will do the trick

mv ebook.zip title_of_your_book.epub

That’s all there is to it. Keep in mind, however, that these steps will have to be repeated every time you rebuild the book!


ZenCoverIf you want to keep up with my eBook formatting work, don’t forget to subscribe to my Newsletter. That way I can keep you updated about the latest developments, updates to my books, code snippets, techniques and formatting tips.

Also, don’t forget to check out my book Zen of eBook Formatting that is filled with tips, techniques and valuable information about the eBook formatting process.

Facebooktwittergoogle_plusredditpinterestlinkedinmail