Saturday, December 01, 2012

Fixing japanese font rendering in android jelly bean 4.1 (docomo galaxy nexus SC-04D)

A couple weeks ago Docomo/Samsung finally pushed the OTA upgrade to jelly bean 4.1.1. It's been a great improvement, but one thing you may immediately noticed was the japanese font rendering looked ugly. This happened if your locale (settings|language) was set to english (or anything non japanese). Here's a screenshot comparing the rendering in english locale versus in japanese locale (or previous android version in any locale).


Side-by-side comparison of Nikkei website (on the left is in English locale, on the right is in Japanese locale)

Things got worse when the font size was blown up. Here's how AnkiDroid looked like.

Side-by-side comparison of AnkiDroid (on the left is in English locale, on the right is in Japanese locale)
To fix this, you'll need to have your phone rooted and do the following:
  • Create a file named fallback_fonts.xml with the following content:
  • <?xml version="1.0" encoding="utf-8"?>
    <!--
        Vendor-provided fallback fonts
    
        This file can be edited to add references to fonts that are not installed or referenced in the
        default system. The file should then be placed in /vendor/etc/fallback_fonts.xml.
        See /system/etc/system_fonts.xml and /system/etc/fallback_fonts.xml for more information
        and to understand the order in which the default system fonts are loaded and structured for
        lookup.
    -->
    
    <familyset>
        <family order="0">
            <fileset>
                <file>MTLmr3m.ttf</file>
            </fileset>
        </family>
    </familyset>
  • Copy this fallback_fonts.xml file to the sdcard. You can either simply copy it by connecting your phone to your PC or use adb: adb push fallback_fonts.xml /sdcard/fallback_fonts.xml
  • Put the file above in /system/vendor/etc, make sure you don't have the file above yet:
  • adb shell
    • su
    • mount -o remount,rw /system
    • ls /system/vendor/etc # Make sure you don't have fallback_fonts.xml
    • cp /sdcard/fallback_fonts.xml /system/vendor/etc
    • rm /sdcard/fallback_fonts.xml
    • mount -o remount,ro /system
    • reboot
  • Lo and behold, I got back my motoya font.
There are other ways to fix this too, if you know what's going on behind the scenes. Basically when you set your phone to english locale, android consults /system/etc/fallback_fonts.xml to find out which font it should render CJK characters in. When you set your locale to japanese, it'll look at /system/etc/fallback_fonts-ja.xml. If you compare these two files, you'll notice that in fallback_fonts-ja.xml, MTLm3rm.ttf is listed before DroidSansFallback.ttf. But in fallback_fonts.xml, MTLm3rm.ttf is listed after DroidSansFallback.ttf. DroidSansFallback.ttf has better support for all CJK character sets, however I think MTLm3rm.ttf (Motoya) has better japanese glyph (more cursive & gothic). So you can also just change /system/etc/fallback_fonts.xml and have MTLm3rm.ttf listed before DroidSansFallback.ttf.