Ejemplo n.º 1
0
 def draw(self, pen):
     """
     Draw the component with **pen**.
     """
     from ufoLib.pointPen import PointToSegmentPen
     pointPen = PointToSegmentPen(pen)
     self.drawPoints(pointPen)
Ejemplo n.º 2
0
 def _draw(self, pen, **kwargs):
     """
     Subclasses may override this method.
     """
     from ufoLib.pointPen import PointToSegmentPen
     adapter = PointToSegmentPen(pen)
     self.drawPoints(adapter)
Ejemplo n.º 3
0
def SelectedComponentsQPainterPathFactory(glyph):
    pen = OnlyComponentsQtPen(glyph.layer)
    pointPen = PointToSegmentPen(pen)
    selectedPen = OnlyComponentsQtPen(glyph.layer)
    selectedPointPen = PointToSegmentPen(selectedPen)
    originPts = []
    for component in glyph.components:
        if component.selected:
            component.drawPoints(selectedPointPen)
            t = Transform(*component.transformation)
            originPts.append(t.transformPoint((0, 0)))
        else:
            component.drawPoints(pointPen)
    pen.path.setFillRule(Qt.WindingFill)
    selectedPen.path.setFillRule(Qt.WindingFill)
    return (pen.path, selectedPen.path, originPts)
Ejemplo n.º 4
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, 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
Ejemplo n.º 5
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
Ejemplo n.º 6
0
def deepolation(newGlyph, masterGlyph, layersInfo = {}):
    
    if not deepCompatible(masterGlyph, list(layersInfo.keys())):
        return False
    
    pen = PointToSegmentPen(newGlyph.getPen())
    
    for contourIndex, contour in enumerate(masterGlyph):
        
        pen.beginPath()
        
        for pointIndex, point in enumerate(contour.points):
            
            px, py = point.x, point.y
            ptype = point.type if point.type != 'offcurve' else None
            
            points = [(px, py)]
            for layerName, value in layersInfo.items():
                
                ratio = value/1000*(len(layersInfo)+1)
                layerGlyph = masterGlyph.getLayer(layerName)
                
                pI = layerGlyph[contourIndex].points[pointIndex]
                pxI, pyI = pI.x, pI.y
                
                newPx = px + (pxI - px) * ratio
                newPy = py + (pyI - py) * ratio
                
                points.append((newPx, newPy))
                
            newX = int(sum(p[0] for p in points) / len(points))
            newY = int(sum(p[1] for p in points) / len(points))
            pen.addPoint((newX, newY), ptype)
            
        pen.endPath()
        
    return newGlyph
Ejemplo n.º 7
0
    def find_shape_diffs(self):
        """Report differences in glyph shapes, using BooleanOperations."""

        self.build_names()

        area_pen = GlyphAreaPen(None)
        pen = PointToSegmentPen(area_pen)
        mismatched = {}
        for name in self.names:
            glyph_a = Glyph()
            glyph_b = Glyph()
            self.glyph_set_a[name].draw(
                Qu2CuPen(glyph_a.getPen(), self.glyph_set_a))
            self.glyph_set_b[name].draw(
                Qu2CuPen(glyph_b.getPen(), self.glyph_set_b))
            booleanOperations.xor(list(glyph_a), list(glyph_b), pen)
            area = abs(area_pen.pop())
            if area:
                mismatched[name] = (area)

        stats = self.stats['compared']
        for name, area in mismatched.items():
            stats.append((area, name, self.basepath))
Ejemplo n.º 8
0
 def draw(self, pen):
     self.drawPoints(PointToSegmentPen(pen))
Ejemplo n.º 9
0
 def getPointPen(self):
     """Return a PointPen adapter that can 'draw' on this glyph."""
     return PointToSegmentPen(self._pen)
Ejemplo n.º 10
0
 def draw(self, pen):
     """Use another SegmentPen to replay the glyph's outline commands,
     indirectly through an adapter.
     """
     pointPen = PointToSegmentPen(pen)
     self.drawPoints(pointPen)
Ejemplo n.º 11
0
 def draw(self, pen):
     pointPen = PointToSegmentPen(pen)
     self.drawPoints(pointPen)
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
 def draw(self, pen):
     """draw self using pen"""
     pointPen = PointToSegmentPen(pen)
     self.drawPoints(pointPen)