freetypy.Outline.decompose

Outline.decompose()

Decompose the outline into individual segments and Bézier arcs. This function also emits ‘move to’ operations to indicate the start of new contours in the outline.

Depending on the context, the values passed to the callback object will either be in 26.6, 16.16 or native font units.

Parameters:
  • callback_object (object) –

    A Python object containing methods that will be called for each element of the outline. The methods are:

    • move_to(point)
    • line_to(point)
    • conic_to(control, endpoint)
    • cubic_to(control1, control2, endpoint)

    ⨎ If callback_object does not have a conic_to method, conic curves will be converted to cubic ones and cubic_to will be called.

  • shift (int, optional) – The number of bits to shift coordinates before they are sent to the emitter.
  • delta (int, optional) –

    The delta that is applied to coordinates before they are sent to the emitter, but after the shift.

    The transformation applied by shift and delta is:

    x' = (x << shift) - delta
    y' = (y << shift) - delta
    

Examples

class Decomposer(object):
    def __init__(self):
        self.entries = []

    def move_to(self, point):
        self.entries.append(('move_to', point))

    def line_to(self, point):
        self.entries.append(('line_to', point))

    def conic_to(self, a, b):
        self.entries.append(('conic_to', a, b))

    def cubic_to(self, a, b, c):
        self.entries.append(('cubic_to', a, b, c))

face = ft.Face("Vera.ttf")
face.set_char_size(12, 12, 300, 300)
glyph = face.load_char(ord('B'))

d = Decomposer()
glyph.outline.decompose(d)
print(d.entries)

Notes

The point coordinates sent to the emitters are the transformed version of the original coordinates (this is important for high accuracy during scan-conversion). The transformation is simple:

x = (x << shift) - delta
y = (y << shift) - delta