Mobileread
How to embed fonts in ePub after Calibre
#1  fiery 11-07-2009, 05:12 PM
This is my simple step by step guide how to embed fonts in epub files after Calibre convertion. For me the most important advantage is that ADE and my reader device finally show readable Cyrillic letters instead of ???.

1. When you convert with Calibre turn on "No default cover" available at EPUB Output!

2. Open the epub file using 7-zip (or other zip utility). Add the fonts bellow and edit the files directly in the archive through the 7-zip explorer (you may need to change the default editor for .css/.opf/.xhtml files to WordPad for example (I use SciTE)).

---------------
3. Add the following Serif fonts to the epub file. Fonts are available at C:\Program Files\Calibre2\resources\fonts\liberation:
---------------
LiberationSerif-Regular.ttf
LiberationSerif-Italic.ttf
LiberationSerif-BoldItalic.ttf
LiberationSerif-Bold.ttf

---------------
4. content.opf - insert the <item... lines after the <manifest>
---------------
<manifest>
<item href="LiberationSerif-Regular.ttf" media-type="application/octet-stream" id="id1"/>
<item href="LiberationSerif-Italic.ttf" media-type="application/octet-stream" id="id2"/>
<item href="LiberationSerif-BoldItalic.ttf" media-type="application/octet-stream" id="id3"/>
<item href="LiberationSerif-Bold.ttf" media-type="application/octet-stream" id="id4"/>


---------------
5. stylesheet.css - insert the following text after the first line
---------------
@font-face {
font-style: italic;
font-family: 'Liberation', serif, sans-serif;
font-weight: normal;
src: url(LiberationSerif-Italic.ttf);
}
@font-face {
font-style: normal;
font-family: 'Liberation', serif, sans-serif;
font-weight: normal;
src: url(LiberationSerif-Regular.ttf);
}
@font-face {
font-style: italic;
font-family: 'Liberation', serif, sans-serif;
font-weight: bold;
src: url(LiberationSerif-BoldItalic.ttf);
}
@font-face {
font-style: normal;
font-family: 'Liberation', serif, sans-serif;
font-weight: bold;
src: url(LiberationSerif-Bold.ttf);
}



-----------------------------------------------------------------
Cybook Opus users - if you want to use these fonts only on your device - first copy all Liberation fonts to your Cybook Opus Fonts folder. Then edit the stylesheet.css file (or enter it at Calibre -> Look & Feel -> External CSS field):
----------------
1. stylesheet.css - insert the following text after the first line
----------------
@font-face {
font-style: italic;
font-family: 'Liberation', serif, sans-serif;
font-weight: normal;
src: url(res:///mnt/fat/Fonts/LiberationSerif-Italic.ttf);
}
@font-face {
font-style: normal;
font-family: 'Liberation', serif, sans-serif;
font-weight: normal;
src: url(res:///mnt/fat/Fonts/LiberationSerif-Regular.ttf);
}
@font-face {
font-style: italic;
font-family: 'Liberation', serif, sans-serif;
font-weight: bold;
src: url(res:///mnt/fat/Fonts/LiberationSerif-BoldItalic.ttf);
}
@font-face {
font-style: normal;
font-family: 'Liberation', serif, sans-serif;
font-weight: bold;
src: url(res:///mnt/fat/Fonts/LiberationSerif-Bold.ttf);
}
Reply 

#2  wallcraft 11-07-2009, 07:07 PM
For embedded fonts:

Many ePubs with embedded fonts do not include them in the manifest. I don't know what the standard says, but it is presumably safe to skip step 4.

Steps 3,4,5 assume the fonts go in the same folder as the content.opf and stylesheet.css. I have more often seen the fonts in their own sub-folder of this folder. If this is called "Fonts" then use (step 5):
src: url(Fonts/LiberationSerif-Italic.ttf);


For on-device user fonts:

This also works on Sonys (ePub custom Fonts on 700, 505, 300, 600) and Hanlins ( Fonts and Epub - What works on Sony, Works for Pocket Pro too!). All that differs between the Cybooks, Sonys and Hanlins is the location of the user provided font directory (e.g. SD card vs internal memory) and how it is named in the src: line.
Reply 

#3  brewt 11-09-2009, 02:45 PM
Liked the plan here, but wow, am I ever doing this wrong.

I can get it to embed it so that the calibre viewer can see it, but not adobe's. Even after re-installing adobe. Nor Sony.
Zulu doesn't do it, neither does fbreader (but I'm not sure they handle embedded fonts anyway).

Ideas? I keep hoping epub will be come more universalized in the viewings, but the different readers are vastly different in their interpretations of pretty much anything I produce - maybe I'm just bad at it.

-bjc
[epub] BasicSet2003-test2 - Unknown.epub (122.6 KB, 1198 views)
Reply 

#4  pdurrant 11-09-2009, 03:59 PM
This file doesn't pass epubcheck, but none of the errors are significant for your problem.

Your @font-face CSS for Perpetua and Broadway seem to be over-ridden by file-specific CSS, which no longer defines the URL for the font.

Your BROADW.TFF font file is missing from the manifest

I believe that in @font-face declarations, non-generic font-family: attributes should be enclosed in "", as should the path in the url part of the src attribute. See the example in

http://www.w3.org/TR/1998/REC-CSS2-19980512/fonts.html#font-selection

Perhaps fixing these problem will improve consistency of rendering

Quote brewt
Liked the plan here, but wow, am I ever doing this wrong.

I can get it to embed it so that the calibre viewer can see it, but not adobe's. Even after re-installing adobe. Nor Sony.
Zulu doesn't do it, neither does fbreader (but I'm not sure they handle embedded fonts anyway).

Ideas? I keep hoping epub will be come more universalized in the viewings, but the different readers are vastly different in their interpretations of pretty much anything I produce - maybe I'm just bad at it.

-bjc
Reply 

#5  FizzyWater 11-09-2009, 08:12 PM
If I made epubs like this, and later put them on a new reader that doesn't have a "Fonts" folder (or have the fonts saved into it), would the ebooks be unreadable, or would it simply display them in the default fonts?
Reply 

#6  pdurrant 11-10-2009, 08:01 AM
The books being discussed here have the fonts inside the ePub, so should display the font on any ePub reader that handles custom fonts.

If you made an ePub with references to fonts inside a particular reader's fonts folder, one a reader without the fonts installed the ePub reader should just use its default fonts.

Quote FizzyWater
If I made epubs like this, and later put them on a new reader that doesn't have a "Fonts" folder (or have the fonts saved into it), would the ebooks be unreadable, or would it simply display them in the default fonts?
Reply 

#7  brewt 11-10-2009, 11:40 AM
Thanks for lookin'. God, mybad on typo.

In my original html, the styles and @fontface calls were in a real css, not at the top of the html - did calibre re-embed? (Built with Word, hand-excised styles references)

Not in original html, in calibre-rendered html's:
Quote
@page { margin-bottom: 5.000000pt; margin-top: 5.000000pt; }
@font-face {
font-family: Tahoma;
panose-1: 2 11 6 4 3 5 4 4 2 4
}

@font-face {
font-family: "Ocean Sans Std Bold Ext"
}

@font-face {
font-family: Inconsolata
}

@font-face {
font-family: Perpetua
}

@font-face {
font-family: Broadway
}
Also, in the calibre-built epub's css, there are calibre styles that I didn't have in the original.....
Quote
<link rel="Stylesheet" type="text/css" media="all" href="styles.css"/>
<meta content="http://www.w3.org/1999/xhtml; charset=utf-8" http-equiv="Content-Type"/><link href="stylesheet.css" type="text/css"
Quote
.calibre4 {
display: block;
font-family: Perpetua;
font-size: 1.125em;
font-weight: bold;
margin-bottom: 3pt;
margin-left: 0;
margin-right: 0;
margin-top: 12pt;
page-break-after: avoid
}
etc
Are these just the styles I had in my original css that I didn't use?

...understanding fading.....

-bjc
Reply 

#8  FizzyWater 11-10-2009, 09:21 PM
Quote pdurrant
The books being discussed here have the fonts inside the ePub, so should display the font on any ePub reader that handles custom fonts.


So sorry! I just read on another thread to include the generic "serif" and/or "sanserif" in the font declaration so that if the font you declare is unavailable, the book will use the default serif or sanserif (depending on which you declare).
Reply 

#9  padman 11-22-2009, 03:58 AM
Quote fiery
2. Open the epub file using 7-zip (or other zip utility). Add the fonts bellow and edit the files directly in the archive through the 7-zip explorer (you may need to change the default editor for .css/.opf/.xhtml files to WordPad for example (I use SciTE)).
@fiery,
Thanks for your guide. You're suggesting editing files through an archive editor. Can you first unzip the epub, make the changes and then compile again? I couldn't find any tool that would make this compilation.
Reply 

#10  pdurrant 11-22-2009, 05:49 AM
Yes, you can unzip, edit and then zip again.

When zipping, the mimetype file must be the first file in the zip, and it must be zipped uncompressed. The other files must follow.

I wrote an Applescript for Mac OS X that does this zipping. I'm sure a batch file for Windows could be written too.

Quote padman
@fiery,
Thanks for your guide. You're suggesting editing files through an archive editor. Can you first unzip the epub, make the changes and then compile again? I couldn't find any tool that would make this compilation.
Reply 

  Next »  Last »  (1/8)
Today's Posts | Search this Thread | Login | Register