/transformGlyphs.py Secret
Created
July 15, 2024 06:47
fontTools Transform Glyphs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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