def reverseContours(glyph): glyphCopy = RGlyph() glyphCopy.width = glyph.width pointPen = glyphCopy.getPointPen() reversePen = ReverseContourPointPen(pointPen) glyph.drawPoints(reversePen) return glyphCopy
def extractComposites(glyph): """Return a new glyph with outline copies of each composite from the source glyph.""" decomposedComposites = RGlyph() if len(glyph.components): font = glyph.layer for comp in reversed(glyph.components): # obtain source data baseGlyphName = comp.baseGlyph baseGlyph = font[baseGlyphName] t = transform.Transform(*comp.transformation) # create a temporary glyph on which to draw the decomposed composite single_decomposedComposite = RGlyph() decompPen = single_decomposedComposite.getPen() baseGlyph.draw(decompPen) single_decomposedComposite.transformBy(tuple(t)) # add single composite to the returned glyph decomposedComposites.appendGlyph(single_decomposedComposite) return decomposedComposites
def _makeTestGlyphLine(): from fontParts.fontshell import RGlyph testGlyph = RGlyph() testGlyph.name = "testGlyph" testGlyph.width = 500 testPen = testGlyph.getPen() testPen.moveTo((10, 0)) testPen.lineTo((30, 0)) testPen.lineTo((50, 0)) testPen.lineTo((70, 0)) testPen.lineTo((90, 0)) testPen.endPath() return testGlyph
def _makeTestGlyphRect(): # make a simple glyph that we can test the pens with. from fontParts.fontshell import RGlyph testGlyph = RGlyph() testGlyph.name = "testGlyph" testGlyph.width = 500 pen = testGlyph.getPen() pen.moveTo((100, 100)) pen.lineTo((100, 300)) pen.lineTo((300, 300)) pen.lineTo((300, 100)) pen.closePath() return testGlyph
def _makeTestGlyphWithCurve(): # make a simple glyph that we can test the pens with. from fontParts.fontshell import RGlyph testGlyph = RGlyph() testGlyph.name = "testGlyph" testGlyph.width = 500 pen = testGlyph.getPen() pen.moveTo((84, 37)) pen.lineTo((348, 37)) pen.lineTo((348, 300)) pen.curveTo((265, 350.0), (177, 350.0), (84, 300)) pen.closePath() return testGlyph
def _makeTestGlyph(): # make a simple glyph that we can test the pens with. from fontParts.fontshell import RGlyph testGlyph = RGlyph() testGlyph.name = "testGlyph" testGlyph.width = 500 pen = testGlyph.getPen() pen.moveTo((10, 10)) pen.lineTo((10, 30)) pen.lineTo((30, 30)) pen.lineTo((30, 10)) pen.closePath() return testGlyph
def _makeTestGlyph(): # make a simple glyph that we can test the pens with. from fontParts.fontshell import RGlyph testGlyph = RGlyph() testGlyph.name = "testGlyph" testGlyph.width = 1000 pen = testGlyph.getPen() pen.moveTo((100, 100)) pen.lineTo((900, 100)) pen.lineTo((900, 109)) pen.lineTo((900, 800)) pen.lineTo((100, 800)) pen.closePath() pen.addComponent("a", (1, 0, 0, 1, 0, 0)) return testGlyph
def _getInstanceGlyph(self, location, masters): I = self._getInstance(location, masters) if I is not None: return I.extractGlyph(RGlyph()) else: errorMessage = self.mutatorErrors[-1]['error'] return ErrorGlyph('Interpolation', errorMessage)
def test_extract_scaled_glyph_as_FontParts_Glyph(self): """Test scaled glyph retrieval as a FontParts Glyph.""" from fontParts.fontshell import RGlyph for testFont in [self.smallFont, self.stemedSmallFont]: scaledGlyph = RGlyph() for glyphName in self.glyphNames: testFont.extractGlyph(glyphName, scaledGlyph) self.assertIsInstance(scaledGlyph, RGlyph)
def removeOverlap(glyph): glyphCopy = RGlyph() glyphCopy.width = glyph.width pointPen = glyphCopy.getPointPen() glyph.drawPoints(pointPen) glyphCopy.removeOverlap() return glyphCopy
def copyContours(glyph): glyphCopy = RGlyph() glyphCopy.width = glyph.width pen = glyphCopy.getPen() glyph.draw(pen) glyphCopy.unicode = glyph.unicode glyphCopy.name = glyph.name return glyphCopy
def freezeGlyph(glyph): """Return a copy of a glyph, with components decomposed and all overlap removed.""" toRFGlyph = RGlyph() toRFpen = toRFGlyph.getPen() glyph.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