Example #1
0
 def drawPoints(self, pen):
     """drawPoints
     
     Note: FontForge implements glyph.draw, but not glyph.drawPoints.
     """
     from robofab.pens.adapterPens import PointToSegmentPen, SegmentToPointPen
     adapter = SegmentToPointPen(pen)
     self._object.draw(adapter)
     pen = None
Example #2
0
	def _doTest(self, shapeFunc, shapeName):
		pen = DigestPointPen(ignoreSmoothAndName=True)
		shapeFunc(pen)
		digest1 = pen.getDigest()

		digestPen = DigestPointPen(ignoreSmoothAndName=True)
		pen = PointToSegmentPen(SegmentToPointPen(digestPen))
		shapeFunc(pen)
		digest2 = digestPen.getDigest()
		self.assertEqual(digest1, digest2, "%r failed round tripping" % shapeName)
Example #3
0
 def testFabPenCompatibility(self):
     for glyph in self.font:
         digestPen = DigestPointPen(ignoreSmoothAndName=True)
         pen = FabToFontToolsPenAdapter(SegmentToPointPen(digestPen))
         glyph.draw(pen)
         digest1 = digestPen.getDigest()
         digestPen = DigestPointPen(ignoreSmoothAndName=True)
         glyph.drawPoints(digestPen)
         digest2 = digestPen.getDigest()
         self.assertEqual(
             digest1, digest2,
             "%r not the same for gl.draw() and gl.drawPoints()" %
             glyph.name)
Example #4
0
 def testSegmentPenInterface(self):
     for glyph in self.font:
         digestPen = DigestPointPen(ignoreSmoothAndName=True)
         pen = SegmentToPointPen(digestPen)
         glyph.draw(pen)
         digest1 = digestPen.getDigest()
         digestPen = DigestPointPen(ignoreSmoothAndName=True)
         glyph.drawPoints(digestPen)
         digest2 = digestPen.getDigest()
         self.assertEqual(
             digest1, digest2,
             "%r not the same for gl.draw() and gl.drawPoints()" %
             glyph.name)
Example #5
0
 def drawPoints(pen):
     pen = SegmentToPointPen(pen)
     glyph.draw(pen)
def makeBlueprint(font):

    # copy fg to bg and mark the glyph red if it contains any contours
    for name in font:
        glyph = font[name]
        background = glyph.layers[0]
        foreground = glyph.layers[1]
        if len(background):
            print glyph, 'had a background ({0} contours)'.format(len(background))
        # copy fg to bg
        glyph.layers[0] = foreground;
        if len(foreground):
            # Glyphs marked red are the ones that need new outlines
            # not red marked glyphs contain only references
            glyph.color = 0xff0000
        else:
            glyph.color = 0xffffff

    # This draws a scrambled echo of the original glyphs to the foreground
    # so it is easy to spot where work is needed and also still which glyph
    # is in which place.

    #we are going to draw with cubics
    font.layers['Fore'].is_quadratic = False;

    for name in font:
        glyph = font[name]

        width = glyph.width
        vwidth = glyph.vwidth
        anchorPoints = tuple(glyph.anchorPoints)

        newFg = fontforge.layer();
        newFg.is_quadratic = False;
        glyph.layers[1] = newFg;

        background = glyph.background # this creates a copy
        if not len(background): continue

        # convert the copy to cubics the real background stays quadratics
        background.is_quadratic = False
        layerPen = glyph.glyphPen() # <= pen will remove more than it should

        # outer line of the outline
        toSegments = PointToSegmentPen(layerPen)
        rand = RandomizePointPen(toSegments, [-7, 7])
        moved = MovePointsPointPen(rand, -15, cmath.pi * .5)
        points = SegmentToPointPen(moved)
        background.draw(points)

        # inner line of the outline
        toSegments = PointToSegmentPen(layerPen)
        rand = RandomizePointPen(toSegments, [-7, 7])
        moved = MovePointsPointPen(rand, 15, -cmath.pi * .5)
        reverse = ReverseContourPointPen(moved)
        points = SegmentToPointPen(reverse)
        background.draw(points)

        # restore stuff that a pen should rather not change automagically
        # in fact, the pen should not reset anything besides outline and components.
        glyph.width = width
        glyph.vwidth = vwidth
        [glyph.addAnchorPoint(*p) for p in anchorPoints]
Example #7
0
 def getPen(self):
     from robofab.pens.adapterPens import SegmentToPointPen
     return SegmentToPointPen(self.getPointPen())
 def getPen(self):
     return SegmentToPointPen(self.getPointPen())
Example #9
0
 def getPen(self):
     """
     Get the pen used to draw into this glyph.
     """
     from robofab.pens.adapterPens import SegmentToPointPen
     return SegmentToPointPen(self.getPointPen())