Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 11-07-2009, 06:12 PM   #1
fiery
Member
fiery began at the beginning.
 
Posts: 12
Karma: 18
Join Date: Nov 2009
Device: Cybook Opus
Post 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);
}
fiery is offline   Reply With Quote
Old 11-07-2009, 08:07 PM   #2
wallcraft
reader
wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.
 
wallcraft's Avatar
 
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.
wallcraft is offline   Reply With Quote
Advert
Old 11-09-2009, 03:45 PM   #3
brewt
Boo-Frickety-Hoo-Erizer
brewt will become famous soon enoughbrewt will become famous soon enoughbrewt will become famous soon enoughbrewt will become famous soon enoughbrewt will become famous soon enoughbrewt will become famous soon enough
 
brewt's Avatar
 
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
Attached Files
File Type: epub BasicSet2003-test2 - Unknown.epub (122.6 KB, 3270 views)
brewt is offline   Reply With Quote
Old 11-09-2009, 04:59 PM   #4
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 72,546
Karma: 309960766
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:
Originally Posted by brewt View Post
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
pdurrant is offline   Reply With Quote
Old 11-09-2009, 09:12 PM   #5
FizzyWater
You kids get off my lawn!
FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.
 
FizzyWater's Avatar
 
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?
FizzyWater is offline   Reply With Quote
Advert
Old 11-10-2009, 09:01 AM   #6
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 72,546
Karma: 309960766
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.

Quote:
Originally Posted by FizzyWater View Post
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?
pdurrant is offline   Reply With Quote
Old 11-10-2009, 12:40 PM   #7
brewt
Boo-Frickety-Hoo-Erizer
brewt will become famous soon enoughbrewt will become famous soon enoughbrewt will become famous soon enoughbrewt will become famous soon enoughbrewt will become famous soon enoughbrewt will become famous soon enough
 
brewt's Avatar
 
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:
@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
brewt is offline   Reply With Quote
Old 11-10-2009, 10:21 PM   #8
FizzyWater
You kids get off my lawn!
FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.FizzyWater ought to be getting tired of karma fortunes by now.
 
FizzyWater's Avatar
 
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:
Originally Posted by pdurrant View Post
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).
FizzyWater is offline   Reply With Quote
Old 11-22-2009, 04:58 AM   #9
padman
Junior Member
padman began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Nov 2009
Device: Cybook Gen3, Cybook Opus, Cool-ER, iRex DR1000, iRex iLiad
Quote:
Originally Posted by fiery View Post
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.
padman is offline   Reply With Quote
Old 11-22-2009, 06:49 AM   #10
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 72,546
Karma: 309960766
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.

Quote:
Originally Posted by padman View Post
@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.
pdurrant is offline   Reply With Quote
Old 11-22-2009, 05:24 PM   #11
fiery
Member
fiery began at the beginning.
 
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.
fiery is offline   Reply With Quote
Old 11-22-2009, 05:38 PM   #12
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 76,495
Karma: 136564766
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by pdurrant View Post
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.
What I do is unzip the ePub, and then make the changes and put back just the files that I've changed. Works quite easily.
JSWolf is offline   Reply With Quote
Old 11-22-2009, 07:23 PM   #13
Valloric
Created Sigil, FlightCrew
Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.
 
Valloric's Avatar
 
Posts: 1,982
Karma: 350515
Join Date: Feb 2008
Device: Kobo Clara HD
Quote:
Originally Posted by JSWolf View Post
What I do is unzip the ePub, and then make the changes and put back just the files that I've changed. Works quite easily.
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.
Valloric is offline   Reply With Quote
Old 11-22-2009, 08:23 PM   #14
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 76,495
Karma: 136564766
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by Valloric View Post
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.
I am using WinRAR to do this. So when I update the changed files, does it changes things enough to be out of spec?
JSWolf is offline   Reply With Quote
Old 11-23-2009, 04:48 AM   #15
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 72,546
Karma: 309960766
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
I don't know - but a quick run through epubcheck will tell you.

Quote:
Originally Posted by JSWolf View Post
I am using WinRAR to do this. So when I update the changed files, does it changes things enough to be out of spec?
pdurrant is offline   Reply With Quote
Reply


Forum Jump

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


All times are GMT -4. The time now is 08:46 PM.


MobileRead.com is a privately owned, operated and funded community.