Sigil User Guide

0.7.2

Include Custom Fonts

— Embedding Fonts In Your Book —

This tutorial shows you how to use custom fonts in your EPUB.

One of the benefits of ereaders is that you can choose your own font, so it’s usually best to only use embedded fonts to highlight specific types of text – such as chapter headings, quotes, etc. – and not to change the font of the entire book.

To use a font in an EPUB you need to load the font into the EPUB, define a style for the font, and then apply the style to your text.

You will need to know about stylesheets to embed fonts so you should read through the Stylesheets chapter first.

Adding Fonts to your EPUB

To add fonts to your book, use the Add Existing Files button document-add_22px. This will display a dialog allowing you to select one or more files from your computer. Select as many font files as you want.

Many fonts are not free. Before you include fonts in your EPUB please make sure that you have a license or permission to use them. There are many free fonts available online if you search for them.

Fonts files must be either OpenType (.otf) or TrueType (.ttf) format. All ereaders should support otf but most will likely support both formats.

The fonts will be added to the Fonts folder in the Book Browser. However, they are not yet actually used anywhere in your book – they are just available to use.

Defining Styles for Your Font

Once the fonts are in your EPUB, you must define a style that includes them.

Add or open a stylesheet that is linked to your HTML files (see the Stylesheets chapter for more details).

Add a definition of the font, e.g.:

@font-face {
    font-family: 'Garamond';
    font-weight: normal;
    font-style: normal;
    src: url('../Fonts/Garamond.ttf');
}

@font-face {
    font-family: 'Garamond';
    font-weight: bold;
    font-style: normal;
    src: url('../Fonts/Garamond Bold.ttf');
}

@font-face {
    font-family: 'Garamond ;
    font-weight: normal;
    font-style: italic;
    src: url('../Fonts/Garamond Italic.ttf');
}

Font names are case-sensitive!

You must define one @font-face rule for each style of font (normal, bold, italics, etc.).

When using the name of a font-family the font name must either be quoted or unquoted every time you use it – you cannot mix quoted and unquoted names. Always using quotes around the font name makes things more consistent and avoids having to check if a name is valid without quotes.

The font still isn’t actually being used in the book yet, that’s the next step.

Apply Your Font to Text

To make use of the font you need to create another style that you will then assign to sections of your text.

So, for example, to use your new font for headings, define the style for the heading tag as follows:

h1 { 
    font-family: 'Garamond', serif;
}

Or to certain paragraphs:

p.longhand { 
    font-family: 'Garamond', serif;
    font-style: italic;
}

Or if you want, although it’s not recommended, you can apply the font to all text in the book:

body { 
    font-family: 'Garamond', serif;
    font-weight: bold;
}

The font-family rules above instruct the ereader to use your font if possible for the text, but if it’s not possible use a generic serif font.

Font Obfuscation

When you use a font in an EPUB, the font file could be extracted by someone and used somewhere else. If your fonts are licensed you may want to prevent this.

You can use Sigil’s font obfuscation menu to scramble the font file using one of two standard methods, Adobe or IDPF – which one is up to you, but you should test on your target ereader to make sure the font is still readable. Obfuscation is not encryption – it just modifies the font file making it hard to use elsewhere while still being useable by readers to display fonts.

To use font obfuscation, right-click on your fonts in the Book Browser window, right-click and select Font Obfuscation from the menu and choose a method to use for obfuscation.

tutorial-font-obfuscate

Testing Your Font

Not all devices will show embedded fonts. Even Sigil may not show all your embedded fonts. Its best to test on your target device to check if your fonts are displayed as you expect.

Table of contents

previous page start next page