summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Godfrey-Kittle <jamesgk@google.com>2015-09-17 17:59:08 -0700
committerJames Godfrey-Kittle <jamesgk@google.com>2015-09-17 17:59:08 -0700
commit1234a9ce9738a65546b4500e9bc69ebfbd6a65c4 (patch)
tree2d4d6354f2f9c00502ff4a9ba7c82f4c86c0134a
parent76c00548b5e339f607e0d0e3e4fed3075ccbd0e4 (diff)
Decompose nested components.
If components of components aren't also decomposed, we may miss some contours in the resulting glyphs.
-rw-r--r--scripts/lib/fontbuild/decomposeGlyph.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/scripts/lib/fontbuild/decomposeGlyph.py b/scripts/lib/fontbuild/decomposeGlyph.py
index b3db2d6..b3cc8ea 100644
--- a/scripts/lib/fontbuild/decomposeGlyph.py
+++ b/scripts/lib/fontbuild/decomposeGlyph.py
@@ -3,10 +3,24 @@ def decomposeGlyph(font, glyphName):
glyph = font[glyphName]
for component in glyph.components:
- componentGlyph = font[component.baseGlyph]
- for contour in componentGlyph:
- contour = contour.copy()
- contour.scale(component.scale)
- contour.move(component.offset)
- glyph.appendContour(contour)
+ decompose(font, glyphName, component.baseGlyph,
+ component.offset, component.scale)
glyph.clear(contours=False, anchors=False, guides=False)
+
+
+def decompose(font, parentName, componentName, offset, scale):
+ """Copy contours to parent from component, including nested components."""
+
+ parent = font[parentName]
+ component = font[componentName]
+
+ for nested in component.components:
+ decompose(font, parentName, nested.baseGlyph,
+ (offset[0] + nested.offset[0], offset[1] + nested.offset[1]),
+ (scale[0] * nested.scale[0], scale[1] * nested.scale[1]))
+
+ for contour in component:
+ contour = contour.copy()
+ contour.scale(scale)
+ contour.move(offset)
+ parent.appendContour(contour)