From 1234a9ce9738a65546b4500e9bc69ebfbd6a65c4 Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Thu, 17 Sep 2015 17:59:08 -0700 Subject: Decompose nested components. If components of components aren't also decomposed, we may miss some contours in the resulting glyphs. --- scripts/lib/fontbuild/decomposeGlyph.py | 26 ++++++++++++++++++++------ 1 file 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) -- cgit v1.2.3 From a9ff306231162a2a62d1dec67ac09da2169679fc Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Fri, 18 Sep 2015 18:33:33 -0700 Subject: Reduce code outside of decomposeGlyph's recursion. --- scripts/lib/fontbuild/decomposeGlyph.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/scripts/lib/fontbuild/decomposeGlyph.py b/scripts/lib/fontbuild/decomposeGlyph.py index b3cc8ea..94b9404 100644 --- a/scripts/lib/fontbuild/decomposeGlyph.py +++ b/scripts/lib/fontbuild/decomposeGlyph.py @@ -2,23 +2,20 @@ def decomposeGlyph(font, glyphName): """Moves the components of a glyph to its outline.""" glyph = font[glyphName] - for component in glyph.components: - decompose(font, glyphName, component.baseGlyph, - component.offset, component.scale) - glyph.clear(contours=False, anchors=False, guides=False) + decompose(font, glyph, glyph, (0, 0), (1, 1)) + glyph.clearComponents() -def decompose(font, parentName, componentName, offset, scale): +def decompose(font, parent, component, 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, + decompose(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) -- cgit v1.2.3 From 53ddf6da91536bfe4f09778a31c77c7d30f6ee35 Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Mon, 21 Sep 2015 11:24:06 -0700 Subject: Rename decomposeGlyph's recursive helper function. --- scripts/lib/fontbuild/decomposeGlyph.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/lib/fontbuild/decomposeGlyph.py b/scripts/lib/fontbuild/decomposeGlyph.py index 94b9404..8cab1b4 100644 --- a/scripts/lib/fontbuild/decomposeGlyph.py +++ b/scripts/lib/fontbuild/decomposeGlyph.py @@ -2,17 +2,18 @@ def decomposeGlyph(font, glyphName): """Moves the components of a glyph to its outline.""" glyph = font[glyphName] - decompose(font, glyph, glyph, (0, 0), (1, 1)) + deepCopyContours(font, glyph, glyph, (0, 0), (1, 1)) glyph.clearComponents() -def decompose(font, parent, component, offset, scale): +def deepCopyContours(font, parent, component, offset, scale): """Copy contours to parent from component, including nested components.""" for nested in component.components: - decompose(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])) + 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 -- cgit v1.2.3