From a95aace05e6275f273ec47fbafb96fcedccaf080 Mon Sep 17 00:00:00 2001 From: justvanrossum Date: Thu, 23 Jul 2020 07:07:01 +0200 Subject: [PATCH 1/3] add snippet that shows how to decompose glyphs in a TTF --- Snippets/decompose-ttf.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Snippets/decompose-ttf.py diff --git a/Snippets/decompose-ttf.py b/Snippets/decompose-ttf.py new file mode 100644 index 000000000..baac8c4df --- /dev/null +++ b/Snippets/decompose-ttf.py @@ -0,0 +1,28 @@ +import sys +from fontTools.ttLib import TTFont +from fontTools.pens.recordingPen import DecomposingRecordingPen +from fontTools.pens.ttGlyphPen import TTGlyphPen + + +if len(sys.argv) != 3: + print("usage: decompose-ttf.py fontfile.ttf outfile.ttf") + sys.exit(1) + + +src = sys.argv[1] +dst = sys.argv[2] + +with TTFont(src) as f: + glyfTable = f["glyf"] + glyphSet = f.getGlyphSet() + + for glyphName in glyphSet.keys(): + if not glyfTable[glyphName].isComposite(): + continue + dcPen = DecomposingRecordingPen(glyphSet) + glyphSet[glyphName].draw(dcPen) + ttPen = TTGlyphPen(None) + dcPen.replay(ttPen) + glyfTable[glyphName] = ttPen.glyph() + + f.save(dst) From 2bc53e75ad41ff2d88cb22c4de03569613f2ec4b Mon Sep 17 00:00:00 2001 From: justvanrossum Date: Thu, 23 Jul 2020 07:11:11 +0200 Subject: [PATCH 2/3] add hashbang and comment; add +x mode --- Snippets/decompose-ttf.py | 6 ++++++ 1 file changed, 6 insertions(+) mode change 100644 => 100755 Snippets/decompose-ttf.py diff --git a/Snippets/decompose-ttf.py b/Snippets/decompose-ttf.py old mode 100644 new mode 100755 index baac8c4df..b8bb37442 --- a/Snippets/decompose-ttf.py +++ b/Snippets/decompose-ttf.py @@ -1,3 +1,9 @@ +#! /usr/bin/env python3 + +# Example script to decompose the composite glyphs in a TTF into +# non-composite outlines. + + import sys from fontTools.ttLib import TTFont from fontTools.pens.recordingPen import DecomposingRecordingPen From 39301b235aca81db6e6179bdf43951e66da25ec3 Mon Sep 17 00:00:00 2001 From: justvanrossum Date: Thu, 23 Jul 2020 07:12:34 +0200 Subject: [PATCH 3/3] whitespace --- Snippets/decompose-ttf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Snippets/decompose-ttf.py b/Snippets/decompose-ttf.py index b8bb37442..36f56d218 100755 --- a/Snippets/decompose-ttf.py +++ b/Snippets/decompose-ttf.py @@ -14,7 +14,6 @@ if len(sys.argv) != 3: print("usage: decompose-ttf.py fontfile.ttf outfile.ttf") sys.exit(1) - src = sys.argv[1] dst = sys.argv[2]