Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 12-06-2017, 08:24 AM   #1
plainbriny
Enthusiast
plainbriny began at the beginning.
 
plainbriny's Avatar
 
Posts: 26
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
Old 12-06-2017, 11:19 AM   #2
coplate
Guru
coplate ought to be getting tired of karma fortunes by now.coplate ought to be getting tired of karma fortunes by now.coplate ought to be getting tired of karma fortunes by now.coplate ought to be getting tired of karma fortunes by now.coplate ought to be getting tired of karma fortunes by now.coplate ought to be getting tired of karma fortunes by now.coplate ought to be getting tired of karma fortunes by now.coplate ought to be getting tired of karma fortunes by now.coplate ought to be getting tired of karma fortunes by now.coplate ought to be getting tired of karma fortunes by now.coplate ought to be getting tired of karma fortunes by now.
 
Posts: 645
Karma: 1888888
Join Date: Jun 2009
Device: prs-505, Kindle Keyboard 3g, PW3
I did do some attempts with this a while back, and I learned the files are signed with some method. I don't remember too many details, but I know it checked something so I could not put in any random file.
coplate is offline   Reply With Quote
Advert
Old 12-06-2017, 12:03 PM   #3
plainbriny
Enthusiast
plainbriny began at the beginning.
 
plainbriny's Avatar
 
Posts: 26
Karma: 10
Join Date: Dec 2017
Device: Kindle Oasis 2, Nook Glowlight 3
some corrections:
I thought "Compressed ROMFS" refers to "cromfs", but I am wrong, it's actually "cramfs".
Now I generate "zh-Hant.font" using mkcramfs and with some progress, the file now stays in system/fonts and is not deleted by kinlde. However, I still can't see new font added. Maybe I need to add pre-generated fontconfig cache for my font, but I have no clue how to do that at the moment.

I am curious however, does kindle not upgraded to 5.9.2 have "system" folder?

As for the file check, since the font update is independent of system update, such check should be self-contained. The question is the directories specified in "02-zh-Hans.conf", are they already in kindle or automatically generated from this file?
plainbriny is offline   Reply With Quote
Old 12-06-2017, 12:20 PM   #4
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
Keep in mind that over USB cable (without a jail break) you are seeing a very tiny bit of the overall file system tree.

What is your goal?
Is it you want to install Traditional Chinese fonts?

Once upon a time, Kindles supported a "USE_ALT_FONTS" option.
Long time gone from the firmware.

That fonts from Amazon are signed.
There should be tools in the Wiki for handling the file packages.

Since you can not sign the font packages with Amazon's private key (they keep it in a safe at the Amazon headquarters), you will have to sign the font package with our private key(s).
But that just means you have to have our public key installed on the Kindle.
Which in turn requires a jail break.

Note:
You can download the 5.9.2 update package from Amazon -
You can download the current KindleTool from:
https://www.mobileread.com/forums/sh...d.php?t=225030
Use Kindletool to convert it to a *.tar.gz archive file -
Open it -
The file: rootfs.img will be just what you would expect from the name - the complete system image.
You can mount it on your linux system with the mount command, no arguments needed, your linux system mount command will recognize it.
(It had better, Kindles run the Amazon distribution of Linux.)
knc1 is offline   Reply With Quote
Old 12-06-2017, 07:34 PM   #5
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,477
Karma: 26012494
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
IIRC, the whole font package stuff is signed/manifested, and locked down somewhat tightly.

That said, I only very vaguely looked at it, and quite a while ago at that, so, yeah, go crazy if you want to dig into it further .
NiLuJe is offline   Reply With Quote
Advert
Old 12-06-2017, 08:15 PM   #6
feelmaroon
Connoisseur
feelmaroon began at the beginning.
 
Posts: 89
Karma: 12
Join Date: May 2012
Device: Sony PRS-350, Kindle 4, PW2, Voyage, Oasis, Kobo Aura One
Fonts

I just use Calibre and choose any font I want and use it as the Publisher Font from Mobi or Epub to Azw3. Works perfectly (although sometimes I have to remove the publisher style sheet) with the 7" on 5.9.2
feelmaroon is offline   Reply With Quote
Old 12-06-2017, 08:35 PM   #7
plainbriny
Enthusiast
plainbriny began at the beginning.
 
plainbriny's Avatar
 
Posts: 26
Karma: 10
Join Date: Dec 2017
Device: Kindle Oasis 2, Nook Glowlight 3
Quote:
Originally Posted by feelmaroon View Post
I just use Calibre and choose any font I want and use it as the Publisher Font from Mobi or Epub to Azw3. Works perfectly (although sometimes I have to remove the publisher style sheet) with the 7" on 5.9.2
Yes embedded font works. But CJK fonts are huge.
plainbriny is offline   Reply With Quote
Old 12-06-2017, 08:38 PM   #8
plainbriny
Enthusiast
plainbriny began at the beginning.
 
plainbriny's Avatar
 
Posts: 26
Karma: 10
Join Date: Dec 2017
Device: Kindle Oasis 2, Nook Glowlight 3
Just browsing the rootfs.img, found "opt/amazon/data.whitelist" which contains the following lines:
Code:
....
./system/fonts/ja.font
./system/fonts/zh-Hans.font
./system/fonts
./system
....
So it looks right now font update will only work for Japanese and Simplified Chinese.
Keep digging.
plainbriny is offline   Reply With Quote
Old 12-06-2017, 08:40 PM   #9
plainbriny
Enthusiast
plainbriny began at the beginning.
 
plainbriny's Avatar
 
Posts: 26
Karma: 10
Join Date: Dec 2017
Device: Kindle Oasis 2, Nook Glowlight 3
Quote:
Originally Posted by knc1 View Post
Keep in mind that over USB cable (without a jail break) you are seeing a very tiny bit of the overall file system tree.

What is your goal?
Is it you want to install Traditional Chinese fonts?
Thanks for pointing to the rootfs, it surely looks very interesting.

I just want to see whether it will work. I did jailbreak my previous kindles and installed fonthack, but at the end I always come back to Amazon's own font.
plainbriny is offline   Reply With Quote
Old 12-06-2017, 09:54 PM   #10
plainbriny
Enthusiast
plainbriny began at the beginning.
 
plainbriny's Avatar
 
Posts: 26
Karma: 10
Join Date: Dec 2017
Device: Kindle Oasis 2, Nook Glowlight 3
Quote:
Originally Posted by coplate View Post
I did do some attempts with this a while back, and I learned the files are signed with some method. I don't remember too many details, but I know it checked something so I could not put in any random file.
Quote:
Originally Posted by NiLuJe View Post
IIRC, the whole font package stuff is signed/manifested, and locked down somewhat tightly.

That said, I only very vaguely looked at it, and quite a while ago at that, so, yeah, go crazy if you want to dig into it further .
found manifest files (/usr/lib/font/manifests/) in rootfs, which include md5sum for the zh-Hans.font/ja.font files, so, yes it will check whether the font file is exactly the one from Amazon.
plainbriny is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Jailbreak 5.3.7.2 and remove special ads/add custom screensaver Stacker344 Kindle Developer's Corner 2 09-25-2014 05:59 AM
Could i change the font size choice without jailbreak? crcc25 Kindle Developer's Corner 5 06-03-2013 12:58 PM
Removing custom screensavers and jailbreak alansplace Kindle Developer's Corner 3 09-15-2012 02:36 PM
Hacks Best custom font? robollama Amazon Kindle 7 05-01-2011 07:33 PM
Jailbreak and custom Apps question joblack Kindle Developer's Corner 0 07-04-2010 08:12 AM


All times are GMT -4. The time now is 09:50 AM.


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