summaryrefslogtreecommitdiff
path: root/scripts/lib/fontbuild/decomposeGlyph.py
blob: 94b94047c5435b6ab8f090cf6f86915326ca1277 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def decomposeGlyph(font, glyphName):
    """Moves the components of a glyph to its outline."""

    glyph = font[glyphName]
    decompose(font, glyph, glyph, (0, 0), (1, 1))
    glyph.clearComponents()


def decompose(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]))

    if component == parent:
        return
    for contour in component:
        contour = contour.copy()
        contour.scale(scale)
        contour.move(offset)
        parent.appendContour(contour)