how to remove characters from a font file?

2019-01-22 21:29发布

问题:

i've downloaded the DejaVu open source font and want to use it ad a WebFont, but even when converting it, i get a large file, and because the website i'll use will be only in few languages (arabic, french, amazigh) then, i dont need some characters.

so is there a way to browse the font file and delete the unnecessary range of unicode characters that i'll not need?

回答1:

Using FontForge, you may open Element->Font Info->Unicode Ranges. You will see all available ranges and you can select a whole Unicode range in a single click. Then, you can tune your selection and delete using Encoding->Detach & Remove Glyphs.

Also, you can use Edit->Select->Select by Script.



回答2:

The easiest method I found is to use pyftsubset tool from FontTools. Here's an example:

$ pyftsubset NotoSans-Regular.ttf \
      --unicodes=U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116 \
      --output-file=NotoSans-Regular.cyrillic.woff2 \
      --flavor=woff2

Note: woff2 output requires Brotli.

I wrote a simple script around it which automates the whole process including generation of a CSS file after splitting the font file. You may find it here: https://github.com/johncf/ttf2web