how to remove characters from a font file?

Abdelouahab Pp picture Abdelouahab Pp · Oct 19, 2012 · Viewed 9.2k times · Source

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?

Answer

John picture John · Jan 28, 2018

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