Created
March 23, 2026 20:36
-
-
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
This file contains hidden or 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
| 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