summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Godfrey-Kittle <jamesgk19@gmail.com>2015-09-21 11:28:04 -0700
committerJames Godfrey-Kittle <jamesgk19@gmail.com>2015-09-21 11:28:04 -0700
commit3ed96d26a9ce30200c3b8c2bece4101104c6b44e (patch)
tree4057c1c1d1cc69456795e9882cd9d8f5cc8e3786
parent76c00548b5e339f607e0d0e3e4fed3075ccbd0e4 (diff)
parent53ddf6da91536bfe4f09778a31c77c7d30f6ee35 (diff)
Merge pull request #110 from jamesgk/shape-fix
Decompose nested components.
-rw-r--r--scripts/lib/fontbuild/decomposeGlyph.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/scripts/lib/fontbuild/decomposeGlyph.py b/scripts/lib/fontbuild/decomposeGlyph.py
index b3db2d6..8cab1b4 100644
--- a/scripts/lib/fontbuild/decomposeGlyph.py
+++ b/scripts/lib/fontbuild/decomposeGlyph.py
@@ -2,11 +2,23 @@ def decomposeGlyph(font, glyphName):
"""Moves the components of a glyph to its outline."""
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)
- glyph.clear(contours=False, anchors=False, guides=False)
+ deepCopyContours(font, glyph, glyph, (0, 0), (1, 1))
+ glyph.clearComponents()
+
+
+def deepCopyContours(font, parent, component, offset, scale):
+ """Copy contours to parent from component, including nested components."""
+
+ for nested in component.components:
+ deepCopyContours(
+ font, parent, font[nested.baseGlyph],
+ (offset[0] + nested.offset[0], offset[1] + nested.offset[1]),
+ (scale[0] * nested.scale[0], scale[1] * nested.scale[1]))
+
+ if component == parent:
+ return
+ for contour in component:
+ contour = contour.copy()
+ contour.scale(scale)
+ contour.move(offset)
+ parent.appendContour(contour)