def reverseContours(glyph): glyphCopy = RGlyph() glyphCopy.width = glyph.width pointPen = glyphCopy.getPointPen() reversePen = ReverseContourPointPen(pointPen) glyph.drawPoints(reversePen) return glyphCopy
def removeOverlap(glyph): glyphCopy = RGlyph() glyphCopy.width = glyph.width pointPen = glyphCopy.getPointPen() glyph.drawPoints(pointPen) glyphCopy.removeOverlap() return glyphCopy
def freezeGlyph(glyph): """Return a copy of a glyph, with components decomposed and all overlap removed.""" toRFGlyph = RGlyph() toRFpen = toRFGlyph.getPen() # draw only the contours, decomposed components will be added later on for contour in glyph: contour.draw(toRFpen) if len(glyph.components): decomposedComponents = extractComposites(glyph) decomposedComponents.draw(toRFpen) singleContourGlyph = RGlyph() singleContourGlyph.width = glyph.width singleContourGlyph.name = glyph.name pointPen = singleContourGlyph.getPointPen() if len(toRFGlyph.contours) > 1: try: booleanGlyphs = [] for c in toRFGlyph.contours: if len(c) > 1: b = BooleanGlyph() pen = b.getPen() c.draw(pen) booleanGlyphs.append(b) finalBooleanGlyph = reduce(lambda g1, g2: g1 | g2, booleanGlyphs) finalBooleanGlyph.drawPoints(pointPen) except: toRFGlyph.drawPoints(pointPen) else: toRFGlyph.drawPoints(pointPen) return singleContourGlyph