Search code examples
unicodefontsfont-facewebfontstruetype

Subset Font By Specific Glyphs


I have a 14MB TTF containing mostly Simplified Chinese characters.

I'd like to reduce the size by creating a subset which only contains the specific characters within an HTML page.

So, ideally, I'd like to pass a (Linux) program an block of text and have it recreate the font based on the characters contained.

E.g.

 ./magic-font-squisher input.tff "ABC123水小长"

or

 ./magic-font-squisher input.tff /path/to/test.html

The new font would then only have those 9 characters present.


Solution

  • Have used https://bitbucket.org/philip/font-optimizer/src

    ./subset.pl --chars="ABC 123 水小长" input.ttf output.ttf
    

    Which is exactly what I want.

    How I Found It

    Google Font Directory contains a subset tool. The README says

    --string=: Generate subset for just the specified string. Useful for creating a menu subset. Generally we use subset.pl from Font Optimizer for this, however.

    A search for Font Optimizer took me to a demo site which allows you to test the script.

    There is also a forked GitHub repo which has better documentation.