Reducing truetype font file size for embedded systems

Orange Pi Development Boards

Embedded systems often have limited memory, that can be a challenge when your application requires Asian languages where fonts might be several megabytes large. Below we describe a method to reduce the file size with Fontforge using simhei.ttf, a CJK font as an example.

Fontforge

Fontforge is an open source font editor running under Linux and Windows/Cygwin. For the latest version see http://fontforge.sourceforge.net/

Reducing Font Size

  • Removing Bitmap from Font File.

Some TrueType files embed a bitmap version of the font. When Fontforge opens such a file, it will ask whether to keep the bitmap or not. We can remove the bitmap to reduce the file size.

  • Using a glyphs subset adapted to your application.

We can use Fontforge with cidmap (Fontforge proprietary) and/or Cmap (from adobe) to perform this task. Please check http://partners.adobe.com/public/developer/font/index.html#ckf for further information on CJK/CID file for your language.

In our example (simhei.ttf), which can be obtained from Microsoft Windows font directory, if we want to keep the glyphs for simplified Chinese, we can choose to use Adobe-GB1-0. We just need to edit the cidmap Adobe-GB1-4.cidmap in Fontforge directory and keep only lines for CID numbers from 0 to 7716 (This is compatible with GB2318 – Cf paragraph 2 http://partners.adobe.com/public/developer/en/font/5079.Adobe-GB1-4.pdf.) save the file as Adobe-GB1-0.cidmap.  In the top menu in Fontforge, select CID->Convert to CID , then browse to get Adobe-GB1-0.cidmap and click OK.  You should see the following box appear:

fontforge-extraneous-glyphs

Select Delete to remove the extraneous glyphs.

Then on the top menu click on CID->Flatten to return to normal font type.

  • Removing Glyphs Names.

The final step is to remove the Glyphs names which takes a lot of space and are of no use for embedded systems. In the top menu, select File->Generate Fonts, then Options and make sure that PS Glyph Names is unchecked:

fontforge-glyphs-name-options

    Conclusion

    Following the three steps above, we reduce the file size of simhei.ttf from 9.57MB to 1.98MB.
    Further minor size reduction should be possible by using Elements->Font Info. However, some of the options may reduce the font quality.

    Support CNX Software - Donate via PayPal or become a Patron on Patreon

    12
    Leave a Reply

    avatar
    12 Comment threads
    0 Thread replies
    0 Followers
     
    Most reacted comment
    Hottest comment thread
    5 Comment authors
    RyanSriDanAnTweets that mention CNXSoft – Embedded Software Development » Reducing truetype font file size for embedded systems -- Topsy.com Recent comment authors
      Subscribe  
    newest oldest most voted
    Notify of
    trackback

    […] This post was mentioned on Twitter: Reducing truetype font file size for embedded systems http://bit.ly/9IJg5b […]

    An
    Guest
    An

    I open simhei.ttf in fontforge, and instead of asking me to remove the bitmap version of the font (does it exist?), font forge just alerts me that “The PostScript font name “(Chinese characters)” is invalid. It should be printable ASCII, must not contain ()[][]% or space and must be shorter than 63 characters

    An
    Guest
    An

    @cnxsoft
    Oh, it seems that some steps can be “partially reproduced”. I downloaded simhei.ttf from the Internet (just Google’d), so I’m not sure what “version” it is of. Fontforge doesn’t ask to remove the bitmap of it, though. (It just alerts me that “The Postscript … is invalid”. I will take a look into that one and its meaning. )

    Also, I found that I don’t have Adobe-GB1-4.cidmap, but I do have Adobe-GB1-5.cidmap. I will try to work with that one.

    Oh, the last step of unchecking “PS Glyph Names” still works.

    An
    Guest
    An

    Oh, awesome. I resized a 873 Kb font to 469 Kb.

    What will happen if I just empty the Adobe-GB1-* to an absolutely empty file, I wonder. : >

    An
    Guest
    An

    oh, no. The 873 Kb was another font. Simhei I downloaded is 10 Mb :), and it also got reduced a lot – to 2.1 Mb. Thanks for the article :).

    Dan
    Guest
    Dan

    Does anyone help to reduce Ubuntu R font size and give me to [email protected]. I’m VietNamese, i can’t install FontForge :(.

    Sri
    Guest
    Sri

    @An
    Where was the final generated font file saved?

    Ryan
    Guest
    Ryan

    This was really helpful. Thanks!