Cython is used to compile some hot paths into native Python extensions. These hot paths were identified through running ufocompile with the hotshot profiler and then converting file by file to Cython, starting with the "hottest" paths and continuing until returns were deminishing. This means that only a few Python files were converted to Cython. Closes #23 Closes #20 (really this time)
23 lines
821 B
Cython
23 lines
821 B
Cython
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)
|