Thursday, May 03, 2012

Read Vietnamese on Sony Reader PRS-T1

Fully embed fonts:
  1. Add the ePub book into Calibre. Right click on the book, choose Tweak Book. Choose Explode ePub.
  2. The file browser (Windows Explorer) will open at an temporary address like C:\Users\UserName\AppData\Local\Temp\calibre_0.8.44_tmp_2s_358\qsvcc__exploded. There should be files stylesheet.css and content.opf.
  3. In the directory containing the .css file, make a new directory named fonts. Copy 4 Gentium Book Basic fonts to that directory (the fonts can be download at scripts.sil.org/Gentium_basic).
  4. Open the .css file in a text editor and add 4 @font-face statements. (Notice the url at src:.) (There may be other .calibre, .calibre1,... in the file.)
    @font-face {
        font-family: serif;
        font-weight: normal;
        font-style: normal;
        src: url(fonts/GenBkBasR.ttf)
        }
    @font-face {
        font-family: serif;
        font-weight: normal;
        font-style: italic;
        src: url(fonts/GenBkBasI.ttf)
        }
    @font-face {
        font-family: serif;
        font-weight: bold;
        font-style: normal;
        src: url(fonts/GenBkBasB.ttf)
        }
    @font-face {
        font-family: serif;
        font-weight: bold;
        font-style: italic;
        src: url(fonts/GenBkBasBI.ttf)
        }
    
    Anywhere in the .css file where there is
    font-family: "Gentium Book", serif;
    can either be replaced with
    font-family: serif;
    or removed altogether because serif is the default font used by the reader.
  5. Edit the .opf file, manually add the 4 font files to the section. (In theory, this step is to make a compliant epub. In practice, it may make no difference to whether the epub will read correctly on PRS-T1.)
    <manifest>
        ... lots of file paths ...
        <item href="fonts/GenBkBasR.ttf" id="serifr" media-type="application/x-truetype-font"/>
        <item href="fonts/GenBkBasI.ttf" id="serifi" media-type="application/x-truetype-font"/>
        <item href="fonts/GenBkBasB.ttf" id="serifb" media-type="application/x-truetype-font"/>
        <item href="fonts/GenBkBasBI.ttf" id="serifbi" media-type="application/x-truetype-font"/>
    </manifest>
    
    The href attribute needs to be the path of the .ttf file relative to the .opf file inside the epub.
  6. Save and close all the edited files. Run Rebuild ePub in the window from Calibre.
Note:
  1. It is not a good idea to do a Calibre conversion on an epub after it has fonts fully embedded. Sometimes the fonts no longer work afterwards.
  2. The fonts may not work on the reader when fully embedded to an epub which has previously been added @font-face statements during a Calibre conversion using the ExtraCSS box. The conversion process will have placed all the @font-faces in each and every (x)html file inside the epub rather than in the .css file. These may well override the ones just manually added to the .css file. If this is the problem, manually removing the @font-faces from the html files should correct it.
More to read: 3 ways to achieve epubs with customized fonts
  1. Embedding. Font files are copied into the epub, @font-face css is added to the epub's existing css file.
    Often used by publishers for DRM'd retail epubs; but can be done for epubs not locked by DRM.
    Pros
    - epub should work on any reader which uses the Adobe renderer.
    Cons
    - non-DRM epubs only
    - The font files would be contained in every single epub. Some are quite large and add up to a lot of disk space if thousands of books are kept on the reader.
    - Have to manually edit each epub to embed font files, extra @font-face css and make some changes to the epub's .opf file.
  2. Font files are copied to the reader, @font-face css is placed in a specially-named .css file on the reader.
    This requires the firmware on the reader to be slightly modified to recognise the .css filename containing the @font-faces. This is because Adobe has seen fit to hide its default css file deep inside the firmware where users can't get at it.
    Pros
    - Can be used for all epubs whether they have DRM or not.
    - Only need to copy the font files and @font-face css to the reader once.
    - Don't need to do anything special in Calibre, nor to edit each epub.
    Cons
    - Have to 'hack' the reader firmware.
  3. A kind of hybrid. Font files are copied to the reader, @font-face css added to each epub's css file.
    The @font-face css can be added into each epub's css file manually using Calibre's Tweak-epub feature. Or this can also be done by a Calibre conversion to epub, by copying the @font-face css into Calibre's Convert - Look&Feel - ExtraCSS box.
    Pros
    - no hacking required
    - Only need to copy the font files to the reader once.
    - If the @font-face css is added to Calibre Preferences, this process is only needed to be done once. Cons
    - non-DRM epubs only
    - Because the @font-face css is slightly different for each brand of reader, the same epub cannot be used on different readers, e.g. an epub prepared for a Sony will not display correctly on a PocketBook, and vice versa.
Acknowledgments: jackie_w from mobileread.com
  • http://www.mobileread.com/forums/showpost.php?p=1818037&postcount=11
  • http://www.mobileread.com/forums/showpost.php?p=1726853&postcount=190