11-07-2009, 06:12 PM | #1 |
Member
Posts: 12
Karma: 18
Join Date: Nov 2009
Device: Cybook Opus
|
How to embed fonts in ePub after Calibre
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); } |
11-07-2009, 08:07 PM | #2 |
reader
Posts: 6,975
Karma: 5183568
Join Date: Mar 2006
Location: Mississippi, USA
Device: Kindle 3, Kobo Glo HD
|
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. |
Advert | |
|
11-09-2009, 03:45 PM | #3 |
Boo-Frickety-Hoo-Erizer
Posts: 251
Karma: 686
Join Date: Oct 2007
Device: Kobo Glo HD!
|
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 |
11-09-2009, 04:59 PM | #4 | |
The Grand Mouse 高貴的老鼠
Posts: 72,497
Karma: 309060442
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
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-1...font-selection Perhaps fixing these problem will improve consistency of rendering Quote:
|
|
11-09-2009, 09:12 PM | #5 |
You kids get off my lawn!
Posts: 4,220
Karma: 73492664
Join Date: Aug 2007
Location: Columbus, Ohio
Device: Oasis 2 and Libra H2O and half a dozen older models I can't let go of
|
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?
|
Advert | |
|
11-10-2009, 09:01 AM | #6 |
The Grand Mouse 高貴的老鼠
Posts: 72,497
Karma: 309060442
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
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. |
11-10-2009, 12:40 PM | #7 | |||
Boo-Frickety-Hoo-Erizer
Posts: 251
Karma: 686
Join Date: Oct 2007
Device: Kobo Glo HD!
|
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:
Quote:
Quote:
...understanding fading..... -bjc |
|||
11-10-2009, 10:21 PM | #8 | |
You kids get off my lawn!
Posts: 4,220
Karma: 73492664
Join Date: Aug 2007
Location: Columbus, Ohio
Device: Oasis 2 and Libra H2O and half a dozen older models I can't let go of
|
Quote:
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). |
|
11-22-2009, 04:58 AM | #9 | |
Junior Member
Posts: 4
Karma: 10
Join Date: Nov 2009
Device: Cybook Gen3, Cybook Opus, Cool-ER, iRex DR1000, iRex iLiad
|
Quote:
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. |
|
11-22-2009, 06:49 AM | #10 |
The Grand Mouse 高貴的老鼠
Posts: 72,497
Karma: 309060442
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
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. |
11-22-2009, 05:24 PM | #11 |
Member
Posts: 12
Karma: 18
Join Date: Nov 2009
Device: Cybook Opus
|
@padman,
Instead of editing files directly in the epub file, you can change its extension from .epub to .zip and then extract the files. On Windows XP and later you can do this very easily through the explorer contextual menu command "Extract All". After file editing, zip first the mimetype file (use the explorer "Send to" -> "Compressed (zipped) folder" command). Then add all other files in the zip (just drag and drop them over the zip file). Finally, change the .zip extension to .epub. The epub format requires that mimetype file should be put first without compression (don't worry Windows will not compress it due to its size) in the epub file. However, ADE as well as my device read epub files even if the mimetype file is not first. In fact, if you do direct editing through the 7-zip utility, it will put edited files above mimetype file and an epub verification would complain about this. So, if you want to produce a strict epub file you should unzip it, edit files and zip it again as explained above. Last edited by fiery; 11-22-2009 at 05:27 PM. |
11-22-2009, 05:38 PM | #12 | |
Resident Curmudgeon
Posts: 76,370
Karma: 136466962
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
11-22-2009, 07:23 PM | #13 |
Created Sigil, FlightCrew
Posts: 1,982
Karma: 350515
Join Date: Feb 2008
Device: Kobo Clara HD
|
If the mimetype file is not the first file and/or is not uncompressed, your epub might not work in all epub-supporting software. Calibre, ADE and Sigil can still handle this, but your epub is still non-conformant and may not work elsewhere.
|
11-22-2009, 08:23 PM | #14 |
Resident Curmudgeon
Posts: 76,370
Karma: 136466962
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
I am using WinRAR to do this. So when I update the changed files, does it changes things enough to be out of spec?
|
11-23-2009, 04:48 AM | #15 |
The Grand Mouse 高貴的老鼠
Posts: 72,497
Karma: 309060442
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can it embed fonts? | chalimac | Kobo Reader | 1 | 06-27-2017 06:46 PM |
Best Practice: Embed Fonts?? | luthar28 | ePub | 37 | 11-01-2011 05:16 AM |
Possible to embed fonts in CSS of .lit file? | tanzer21 | Calibre | 9 | 06-30-2010 08:26 PM |
Is it possible to UN embed fonts? | lmronan | Sigil | 14 | 06-04-2010 10:26 AM |
Any free software can embed fonts in epub | droople | ePub | 4 | 03-06-2010 06:40 PM |