def draw(self, pen): """ Draw the contour with **pen**. """ from robofab.pens.adapterPens import PointToSegmentPen pointPen = PointToSegmentPen(pen) self.drawPoints(pointPen)
def __getPointPen(self): """Return a point pen. Note: FontForge doesn't support segment pen, so return an adapter. """ from robofab.pens.adapterPens import PointToSegmentPen segmentPen = self._object.glyphPen() return PointToSegmentPen(segmentPen)
def thresholdGlyph(aGlyph, threshold=10): from robofab.pens.adapterPens import PointToSegmentPen new = _RGlyph() filterpen = ThresholdPen(new.getPen(), threshold) wrappedPen = PointToSegmentPen(filterpen) aGlyph.drawPoints(wrappedPen) aGlyph.clear() aGlyph.appendGlyph(new) aGlyph.update() return aGlyph
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)
def thresholdGlyph(aGlyph, threshold=10): """ Convenience function that handles the filtering. """ from robofab.pens.adapterPens import PointToSegmentPen new = _RGlyph() filterpen = ThresholdPen(new.getPen(), threshold) wrappedPen = PointToSegmentPen(filterpen) aGlyph.drawPoints(wrappedPen) aGlyph.clear() aGlyph.appendGlyph(new) aGlyph.update() return aGlyph
def draw(self, pen): """ Draw the contour with **pen**. """ # >>> # from ufoLib.pointPen import PointToSegmentPen # --- Patched with the line from defcon in FDK 64958 --- from robofab.pens.adapterPens import PointToSegmentPen # <<< pointPen = PointToSegmentPen(pen) self.drawPoints(pointPen)
def thresholdGlyph(aGlyph, threshold=10): """Convenience function that applies the **ThresholdPen** to a glyph. Returns a new glyph object (from objectsRF.RGlyph).""" from robofab.pens.adapterPens import PointToSegmentPen new = _RGlyph() filterpen = ThresholdPen(new.getPen(), threshold) wrappedPen = PointToSegmentPen(filterpen) aGlyph.drawPoints(wrappedPen) aGlyph.clear() aGlyph.appendGlyph(new) aGlyph.update() return aGlyph
def flattenGlyph(aGlyph, threshold=10, segmentLines=True): """Convenience function that applies the **FlattenPen** pen to a glyph. Returns a new glyph object.""" from robofab.pens.adapterPens import PointToSegmentPen if len(aGlyph.contours) == 0: return new = _RGlyph() writerPen = new.getPen() filterpen = FlattenPen(writerPen, threshold, segmentLines) wrappedPen = PointToSegmentPen(filterpen) aGlyph.drawPoints(wrappedPen) aGlyph.clear() aGlyph.appendGlyph(new) aGlyph.update() return aGlyph
def flattenGlyph(aGlyph, threshold=10, segmentLines=True): """Replace curves with series of straight l ines.""" from robofab.pens.adapterPens import PointToSegmentPen if len(aGlyph.contours) == 0: return new = _RGlyph() writerPen = new.getPen() filterpen = FlattenPen(writerPen, threshold, segmentLines) wrappedPen = PointToSegmentPen(filterpen) aGlyph.drawPoints(wrappedPen) aGlyph.clear() aGlyph.appendGlyph(new) aGlyph.update() return aGlyph
def draw(self, pen): pointPen = PointToSegmentPen(pen) self.drawPoints(pointPen)
def draw(self, pen): """Draw this glyph onto a *FontTools* Pen.""" from robofab.pens.adapterPens import PointToSegmentPen pointPen = PointToSegmentPen(pen) self.drawPoints(pointPen)
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]
def draw(self, pen): """draw self using pen""" from robofab.pens.adapterPens import PointToSegmentPen pointPen = PointToSegmentPen(pen) self.drawPoints(pointPen)
def draw(self, pen): """draw self using pen""" pointPen = PointToSegmentPen(pen) self.drawPoints(pointPen)