diff options
author | Rasmus Andersson <rasmus@notion.se> | 2017-08-22 10:05:20 +0300 |
---|---|---|
committer | Rasmus Andersson <rasmus@notion.se> | 2017-08-22 12:23:08 +0300 |
commit | 3b1fffade1473f20f2558733fbd218f4580fc7c3 (patch) | |
tree | ea4f80b43b08744d493bb86ab646444ec04ddc7f /misc/pylib/fontbuild/decomposeGlyph.py | |
download | inter-3b1fffade1473f20f2558733fbd218f4580fc7c3.tar.xz |
Initial public commitv1.0
Diffstat (limited to 'misc/pylib/fontbuild/decomposeGlyph.py')
-rw-r--r-- | misc/pylib/fontbuild/decomposeGlyph.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/misc/pylib/fontbuild/decomposeGlyph.py b/misc/pylib/fontbuild/decomposeGlyph.py new file mode 100644 index 000000000..0470fa60b --- /dev/null +++ b/misc/pylib/fontbuild/decomposeGlyph.py @@ -0,0 +1,23 @@ +def decomposeGlyph(font, glyph): + """Moves the components of a glyph to its outline.""" + if len(glyph.components): + 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) |