Files
spring-boot-demo/pdf-invoice/scripts/make_fonts.py
T

22 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python3
"""Cut static Regular and Bold instances out of the Noto Sans Devanagari variable font.
Source (SIL OFL 1.1, copyright The Noto Project Authors; OFL.txt next to the output files):
https://cdn.jsdelivr.net/gh/google/fonts@main/ofl/notosansdevanagari/NotoSansDevanagari%5Bwdth%2Cwght%5D.ttf
(a jsDelivr mirror of github.com/google/fonts; raw.githubusercontent.com was blocked in the sandbox this was built in)
Why static instances: OpenPDF and iText read a variable font's default master only, and Flying Saucer
picks weights by file. Two small static files make "regular" and "bold" mean the same thing in all three.
Needs: pip install fonttools
"""
import sys
from fontTools.ttLib import TTFont
from fontTools.varLib import instancer
src, outdir = sys.argv[1], sys.argv[2]
for name, wght in (("Regular", 400), ("Bold", 700)):
font = TTFont(src)
inst = instancer.instantiateVariableFont(font, {"wght": wght, "wdth": 100}, updateFontNames=True)
inst.save(f"{outdir}/NotoSansDevanagari-{name}.ttf")
print("wrote", name)