View Full Version : ePub + Embedded Fonts


Cygfrydd
02-26-2009, 08:12 PM
Totally new to these forums, so this seems like a splended time for a first post.

I'm hand-making ePubs for my Sony Reader PRS-505 (not entirely by hand, using some custom Python scripts to help things along), and have been embedding TTF fonts to override the standard Reader fonts (as well as gaining true italics, etc.); that is to say, including them in the "zip" instead of pointing at fonts already loaded in the Data directory on the Reader. The following works just fine in both the desktop version of ADE, and on the Reader:

@font-face {
font-family: BerlingAntiqua ;
font-style: normal ;
font-weight: normal ;
src: url(fonts/base/berling.ttf) ;
}
...
p {
font-family: BerlingAntiqua ;
margin: 0 ;
padding: 0 ;
text-align: justify ;
text-indent: 1em ;
font-size: 120% ;
}


I got to thinking about the consequences of this. It seems to me that the font files themselves ought to be listed in the <manifest> portion of content.opf; obviously it works fine without, and epubcheck doesn't complain. But if they were listed... what media-type should I use? Googling has been no help, except to locate a few posts with proposals for media-types for fonts, but nothing concrete. Has anyone else explored this?


ó @yg

-=<>=-=<>=-=<>=-=<>=-=<>=-=<>=-=<>=-
Cygfrydd Llewellyn | cygfrydd@gmail.com
-=<>=-=<>=-=<>=-=<>=-=<>=-=<>=-=<>=-

Guilt was the grease in which the wheels of the authority turned.
ó (Terry Pratchett, Small Gods)

llasram
02-26-2009, 09:20 PM
The OPF 2.0 spec is very clear that font files must be listed in the <manifest/> for the book to be correct. (Epubcheck doesn't parse or check CSS and thus doesn't see the references to complain.) But you are correct -- there is no official assigned MIME type for TrueType or OpenType fonts. Most common seems to be 'application/x-font-opentype' and 'application/x-font-truetype', which is what calibre uses.

Jellby
02-27-2009, 10:52 AM
Most common seems to be 'application/x-font-opentype' and 'application/x-font-truetype', which is what calibre uses.

I used "application/x-truetype-font", I don't know where I copied that from...

Anyway, the usual recomendation is not to force a particular font on the main text of the book, you can use embedded fonts for titles, banners, etc., but let the user select the font he/she likes best for the tex.

hekkel
02-27-2009, 12:53 PM
It seems to me that the font files themselves ought to be listed in the <manifest> portion of content.opf; obviously it works fine without, and epubcheck doesn't complain. But if they were listed... what media-type should I use?

application/x-font-ttf

That's what I use and what I found in e.g. the books from Penguin.

-maarten

Cygfrydd
02-27-2009, 02:22 PM
Outstanding and helpful reply, folks. As far as the suggestion about leaving the fonts up to the user, I think Iíll go with the url('res:///Data/fonts/foobar.ttf') scheme, storing the fonts on the Reader itself, instead of packing them inside the ePub, unless thereís a pressing need for something custom... even then, if itís a one-off instance, I could just convert the type to outlines and embed it as a SVG. Makes for a drastically smaller ePub when you're using fonts with a lot of glyphs, as well.

ó @yg

Jellby
02-27-2009, 03:08 PM
Outstanding and helpful reply, folks. As far as the suggestion about leaving the fonts up to the user, I think I’ll go with the url('res:///Data/fonts/foobar.ttf') scheme, storing the fonts on the Reader itself, instead of packing them inside the ePub

I wouldn't rely on that, that'd work only in the Sony reader, other readers may have fonts stored in different places (and with different filenames). If you need/want a specific font, include it in the ePub file (if the license allows it). This, of course, applies only if you plan to distribute the ePub file, if it's only for you, do whatever works for you :)

JSWolf
03-02-2009, 05:10 PM
Where in the Reader do the fonts go so they don't have to be included in the ePub?

zelda_pinwheel
03-02-2009, 05:13 PM
Where in the Reader do the fonts go so they don't have to be included in the ePub?

it might be different on the 505, but on the 700 you just create a folder called "fonts" (no quotes) at the root of the main memory, next to the other folders. then specify the file path as indicated.

JSWolf
03-02-2009, 05:25 PM
I'll give it a go. Thanks!

Cygfrydd
03-02-2009, 05:26 PM
Where in the Reader do the fonts go so they don't have to be included in the ePub?

On a PRS-505/700, you can access the Readerís internal memory like a flash drive; it should mount automatically when you connect the USB. On that mount, create a directory (I just call mine "fonts"), and put the fonts there.

You can then access them from your stylesheets by using something akin to this:

@font-face {
font-family: BerlingAntiqua ;
font-style: normal ;
font-weight: normal ;
src: url('res:///Data/fonts/berling.ttf') ;
}

@font-face {
font-family: BerlingAntiqua ;
font-style: oblique ;
font-weight: normal ;
src: url('res:///Data/fonts/berlingi.ttf') ;
}

@font-face {
font-family: BerlingAntiqua ;
font-style: normal ;
font-weight: bold ;
src: url('res:///Data/fonts/berlingb.ttf') ;
}

@font-face {
font-family: BerlingAntiqua ;
font-style: oblique ;
font-weight: bold ;
src: url('res:///Data/fonts/berlingz.ttf') ;
}

p {
font-family: BerlingAntiqua, serif ;
margin : 0 ;
padding : 0 ;
text-align : justify ; /* not working on Sony yet */
text-indent : 1em ;
font-size: 120% ;
}

ó @yg

-=<>=-=<>=-=<>=-=<>=-=<>=-=<>=-=<>=-
Cygfrydd Llewellyn | cygfrydd@gmail.com
-=<>=-=<>=-=<>=-=<>=-=<>=-=<>=-=<>=-

Old Tom was the single cracked bronze bell in the University bell tower.
The clapper dropped out shortly after it was cast, but the bell still
tolled out some tremendously sonorous silences every hour.
ó (Terry Pratchett, Eric)

JSWolf
03-02-2009, 05:55 PM
It works the same on the 505 as it does on the 700.

zelda_pinwheel
03-02-2009, 05:56 PM
It works the same on the 505 as it does on the 700.

good to know !