decomposeGlyph.py 816 B

123456789101112131415161718192021222324
  1. def decomposeGlyph(font, glyphName):
  2. """Moves the components of a glyph to its outline."""
  3. glyph = font[glyphName]
  4. deepCopyContours(font, glyph, glyph, (0, 0), (1, 1))
  5. glyph.clearComponents()
  6. def deepCopyContours(font, parent, component, offset, scale):
  7. """Copy contours to parent from component, including nested components."""
  8. for nested in component.components:
  9. deepCopyContours(
  10. font, parent, font[nested.baseGlyph],
  11. (offset[0] + nested.offset[0], offset[1] + nested.offset[1]),
  12. (scale[0] * nested.scale[0], scale[1] * nested.scale[1]))
  13. if component == parent:
  14. return
  15. for contour in component:
  16. contour = contour.copy()
  17. contour.scale(scale)
  18. contour.move(offset)
  19. parent.appendContour(contour)