Skip to content

Instantly share code, notes, and snippets.

@inklesspen
Created March 23, 2026 20:36
Show Gist options
  • Select an option

  • Save inklesspen/0ef2ec09fc7968510c58e37176932389 to your computer and use it in GitHub Desktop.

Select an option

Save inklesspen/0ef2ec09fc7968510c58e37176932389 to your computer and use it in GitHub Desktop.
creates a modified version of a truetype font where each glyph has been rotated 180 degrees
import math
from fontTools import ttLib
from fontTools.pens.transformPen import TransformPen
from fontTools.pens.ttGlyphPen import TTGlyphPen
from fontTools.misc.transform import Transform
rotate = Transform().rotate(math.radians(180))
def transformglyphs(font: ttLib.TTFont):
for glyphName in font["glyf"].keys():
glyph = font["glyf"][glyphName]
# Avoid double-transforming composite glyphs
if glyph.isComposite():
continue
print(glyphName)
glyphPen = TTGlyphPen(font.getGlyphSet())
transformPen = TransformPen(glyphPen, rotate)
glyph.draw(transformPen, font["glyf"])
font["glyf"][glyphName] = glyphPen.glyph()
def main():
font = ttLib.TTFont(open("font.ttf", "rb"))
transformglyphs(font)
font.save(open("font-flipped.ttf", "wb"))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment