Skip to content

Instantly share code, notes, and snippets.

@weiweihuanghuang
Created July 15, 2024 06:47
fontTools Transform Glyphs
from fontTools import ttLib
from fontTools.pens.transformPen import TransformPen
from fontTools.pens.ttGlyphPen import TTGlyphPen
from fontTools.misc.transform import Transform
font = ttLib.TTFont(filePath)
glyphPen = TTGlyphPen(font.getGlyphSet())
transformPen = TransformPen(glyphPen, Transform().scale(0.95,0.95).translate(0, -25))
for glyphName in font["glyf"].keys():
glyph = font.getGlyphSet().get(glyphName)
glyph.draw(transformPen)
transformedGlyph = glyphPen.glyph()
font["glyf"][glyphName] = transformedGlyph
font.save(newFontFilePath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment