def test_reverse_point_pen(contour, expected):
    try:
        from ufoLib.pointPen import (ReverseContourPointPen, PointToSegmentPen,
                                     SegmentToPointPen)
    except ImportError:
        pytest.skip("ufoLib not installed")

    recpen = RecordingPen()
    pt2seg = PointToSegmentPen(recpen, outputImpliedClosingLine=True)
    revpen = ReverseContourPointPen(pt2seg)
    seg2pt = SegmentToPointPen(revpen)
    for operator, operands in contour:
        getattr(seg2pt, operator)(*operands)

    # for closed contours that have a lineTo following the moveTo,
    # and whose points don't overlap, our current implementation diverges
    # from the ReverseContourPointPen as wrapped by ufoLib's pen converters.
    # In the latter case, an extra lineTo is added because of
    # outputImpliedClosingLine=True. This is redundant but not incorrect,
    # as the number of points is the same in both.
    if (contour and contour[-1][0] == "closePath" and contour[1][0] == "lineTo"
            and contour[1][1] != contour[0][1]):
        expected = expected[:-1] + [("lineTo", contour[0][1])] + expected[-1:]

    assert recpen.value == expected
Example #2
0
def thresholdGlyph(aGlyph, threshold=10):
    """
    Convenience function that applies the **ThresholdPen** to a glyph. Returns a new glyph object (from objectsRF.RGlyph).
    """
    from ufoLib.pointPen import SegmentToPointPen
    from fontPens.dataPointPen import DataPointPen
    data = DataPointPen()
    filterpen = ThresholdPen(SegmentToPointPen(data), threshold)
    aGlyph.draw(filterpen)
    aGlyph.clear()
    data.draw(aGlyph.getPen())
    return aGlyph
Example #3
0
def test_reverse_point_pen(contour, expected):
    try:
        from ufoLib.pointPen import (ReverseContourPointPen, PointToSegmentPen,
                                     SegmentToPointPen)
    except ImportError:
        pytest.skip("ufoLib not installed")

    recpen = RecordingPen()
    pt2seg = PointToSegmentPen(recpen)
    revpen = ReverseContourPointPen(pt2seg)
    seg2pt = SegmentToPointPen(revpen)
    for operator, operands in contour:
        getattr(seg2pt, operator)(*operands)
    assert recpen.value == expected
Example #4
0
def flattenGlyph(aGlyph, threshold=10, segmentLines=True):
    """
    Convenience function that applies the **FlattenPen** pen to a glyph. Returns a new glyph object.
    """
    if len(aGlyph) == 0:
        return aGlyph
    from ufoLib.pointPen import SegmentToPointPen
    from fontPens.dataPointPen import DataPointPen
    data = DataPointPen()
    filterpen = FlattenPen(SegmentToPointPen(data),
                           approximateSegmentLength=threshold,
                           segmentLines=segmentLines)
    aGlyph.draw(filterpen)
    aGlyph.clear()
    data.draw(aGlyph.getPen())
    return aGlyph
Example #5
0
 def __init__(self, other_pen):
     adapter_point_pen = PointToSegmentPen(other_pen)
     reverse_point_pen = ReverseContourPointPen(adapter_point_pen)
     SegmentToPointPen.__init__(self, reverse_point_pen)
Example #6
0
	def drawPoints(self, pointPen):
		pen = SegmentToPointPen(pointPen)
		self.draw(pen)
Example #7
0
 def getPen(self):
     """Return a SegmentPen adapter that can 'draw' on this glyph."""
     return SegmentToPointPen(self._pen)
Example #8
0
 def drawPoints(self, pointPen):
     """Use another PointPen to replay the glyph's outline commands,
     indirectly through an adapter.
     """
     pen = SegmentToPointPen(pointPen)
     self.draw(pen)
Example #9
0
 def __init__(self, other_pen):
     adapter_point_pen = PointToSegmentPen(other_pen)
     reverse_point_pen = ReverseContourPointPen(adapter_point_pen)
     SegmentToPointPen.__init__(self, reverse_point_pen)
Example #10
0
 def getPen(self):
     """
     Get the pen used to draw into this glyph.
     """
     from ufoLib.pointPen import SegmentToPointPen
     return SegmentToPointPen(self.getPointPen())
Example #11
0
 def drawPoints(pointPen):
     pen = TransformPen(SegmentToPointPen(pointPen), transform)
     parse_path(path, pen)
Example #12
0
 def drawPoints(pointPen):
     pen = SegmentToPointPen(pointPen)
     outline.draw(pen)