View Single Post
Old 12-06-2017, 09:24 AM   #1
plainbriny
Member
plainbriny began at the beginning.
 
plainbriny's Avatar
 
Posts: 10
Karma: 10
Join Date: Dec 2017
Device: Kindle Oasis 2, Nook Glowlight 3
5.9.2: Custom font possible without jailbreak?

Hi,

Currently I am using 7" Kindle Oasis, and it updated to 5.9.2 automatically the day I got it, therefore jailbreak is not possible right now.

However, during the initial setup, I have tried to switch the language to Simplified Chinese, and Kindle prompted font updates available, and downloaded and installed the font, again automatically.

Recently while browsing the system folder in kindle, I found there is a file under kindle's system/fonts directory, called "zh-Hans.font", apparently for "Simplified Chinese fonts".

Out of curiosity, I opened this file with hex editor, and found the file is actually a compressed romfs file. So I copy it to a linux machine and mount it. There are two files and two directories in it.

The first file is called "image_manifest", with the content:
Spoiler:
Code:
{
  "languages": "zh-Hans",
  "type": "font",
  "uniqueIdentifier": "zh-Hans",
  "files": "zh-Hans.font",
  "STKaiMedium.ttf.md5": "8bf50fdd905cf05f89f5a528e23d8160",
  "STKaiBold.ttf.md5": "9e50b61591073d7f2512250995e73268",
  "STYuanMedium.ttf.md5": "aefef3de36d833c3f7600a95b0b6882d",
  "STYuanBold.ttf.md5": "5e43cb48f2fbf44b45e1fdb8bb9f6cc4",
  "version": 20170523,
  "fonts.zh-Hans": "stkai,styuan",
  "font.stkai.display": "\u6977\u4f53",
  "font.styuan.display": "\u5706\u4f53"
}


So it describes the content of this cromfs file, ttf font files and their names when tapping the "Aa" button while reading.

Another file is a fontconfig file named "02-zh-Hans.conf" with the content:
Spoiler:
Code:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <dir>/var/local/font/mnt/zh-Hans_font/fonts</dir>
    <cachedir>/var/cache/fontconfig</cachedir>
    <cachedir>/var/local/font/cache</cachedir>

    <!-- Kai fonts -->
    <match target="scan">
        <test name="family" compare="eq">
            <string>STKaiti</string>
        </test>
        <test name="style" compare="eq">
            <string>Regular</string>
        </test>
        <edit name="family" mode="assign">
            <string>STKai</string>
        </edit>
        <edit name="style" mode="assign">
            <string>Medium</string>
        </edit>
        <edit name="rasterizer" mode="assign">
            <string>ft</string>
        </edit>
    </match>
    <match target="scan">
        <test name="family" compare="eq">
            <string>STKaiti</string>
        </test>
        <test name="style" compare="eq">
            <string>Bold</string>
        </test>
        <edit name="family" mode="assign">
            <string>STKai</string>
        </edit>
        <edit name="style" mode="assign">
            <string>Bold</string>
        </edit>
    </match>
    <!-- alias of old font name for compatibility -->
    <match target="pattern">
        <test qual="any" name="family">
            <string>MKai PRC</string>
	</test>
	<edit name="family" mode="assign" binding="same">
	    <string>STKai</string>
	</edit>
    </match>

    <!-- Yuan fonts -->
    <match target="scan">
        <test name="family" compare="eq">
            <string>STZhongyuan</string>
        </test>
        <test name="style" compare="eq">
            <string>Regular</string>
        </test>
        <edit name="family" mode="assign">
            <string>STYuan</string>
        </edit>
        <edit name="style" mode="assign">
            <string>Medium</string>
        </edit>
        <edit name="rasterizer" mode="assign">
            <string>ft</string>
        </edit>
    </match>
</fontconfig>


The "dir" tag implies that kindle mount this cromfs font file to the directory specified, and use the fonts provided in this file.

The two directories are "fonts" where the ttf font files are located, and a "cache" directory for fontconfig cache.

I was wondering whether I can add new fonts using this approach, so I create similar directory structures and files for zh-Hant (Traditional Chinese) with one single font and it's md5sum. I don't have tool to build compressed romfs file, so I just use genromfs to generate a non-compressed romfs file, named "zh-Hant.font".

I then put this file into system/fonts/ directory, when I eject kindle storage, the "font update" screen appears on kindle but shortly disappeared. Afterward, nothing changes, reboot does no effect, and when I check system/fonts/ again, the file I put was deleted.

I think this approach might work for adding new custom fonts to kindle (without substitute old ones), but so far I haven't success yet.

There are be several approached worth trying. First, perhaps I should use compressed romfs instead of plain romfs, but then I need to install fuse and cromfs. Second, maybe I need to pre-generate cache file for the font to be installed, but my linux box is now 64bit and kindle is 32bit, need some work to do that (if possible).

Not sure whether this works for other languages, I assume it does, because kindle will try to install fonts with xx_yyyy.font file placed in system/fonts/. But it may take some effort to figure out how it works...
plainbriny is offline   Reply With Quote