def getGlyph(self, glyph, skew, rotation, addComponents=False):
        skew = radians(skew)
        rotation = radians(-rotation)

        dest = glyph.copy()

        if not addComponents:
            for component in dest.components:
                pointPen = DecomposePointPen(glyph.getParent(), dest.getPointPen(), component.transformation)
                component.drawPoints(pointPen)
                dest.removeComponent(component)

        for contour in list(dest):
            if contour.open:
                dest.removeContour(contour)

        if skew == 0 and rotation == 0:
            return dest

        for contour in dest:
            for bPoint in contour.bPoints:
                bcpIn = bPoint.bcpIn
                bcpOut = bPoint.bcpOut
                if bcpIn == (0, 0):
                    continue
                if bcpOut == (0, 0):
                    continue
                if bcpIn[0] == bcpOut[0] and bcpIn[1] != bcpOut[1]:
                    bPoint.anchorLabels = ["extremePoint"]
                if rotation and bcpIn[0] != bcpOut[0] and bcpIn[1] == bcpOut[1]:
                    bPoint.anchorLabels = ["extremePoint"]

        cx, cy = 0, 0
        box = glyph.box
        if box:
            cx = box[0] + (box[2] - box[0]) * .5
            cy = box[1] + (box[3] - box[1]) * .5

        t = Transform()
        t = t.skew(skew)
        t = t.translate(cx, cy).rotate(rotation).translate(-cx, -cy)

        # RF3
        if version >= "3.0":
            dest.transformBy(tuple(t))
        # RF1
        else:
            dest.transform(t)

        dest.extremePoints(round=0)
        for contour in dest:
            for point in contour.points:
                if "extremePoint" in point.labels:
                    point.selected = True
                    point.smooth = True
                else:
                    point.selected = False
        dest.removeSelection()
        dest.round()
        return dest
Beispiel #2
0
 def skew(self, x=0, y=0, point=None):
     t = Transform()
     if not point:
         point = self.bounds().point("C") # maybe should be getFrame()?
     t = t.translate(point.x, point.y)
     t = t.skew(x, y)
     t = t.translate(-point.x, -point.y)
     return self.transform(t)
Beispiel #3
0
 def skew(self, x=0, y=0, unalign=True):
     t = Transform()
     if unalign != False:
         point = self.bounds().point("SW")  # maybe should be getFrame()?
         t = t.translate(point.x, point.y)
     t = t.skew(x, y)
     if unalign != False:
         t = t.translate(-point.x, -point.y)
     return self.transform(t)
Beispiel #4
0
def makeTransformVarCo(x, y, rotation, scalex, scaley, skewx, skewy, tcenterx,
                       tcentery):
    t = Transform()
    t = t.translate(x + tcenterx, y + tcentery)
    t = t.rotate(math.radians(rotation))
    t = t.scale(scalex, scaley)
    t = t.skew(math.radians(skewx), math.radians(skewy))
    t = t.translate(-tcenterx, -tcentery)
    return t
 def getGlyph(self, glyph, skew, rotation, addComponents=False):
     skew = radians(skew)
     rotation = radians(-rotation)
     
     dest = glyph.copy()
     if skew == 0 and rotation == 0:
         return dest
     for contour in dest:
         for bPoint in contour.bPoints:
             bcpIn = bPoint.bcpIn
             bcpOut = bPoint.bcpOut
             if bcpIn == (0, 0):
                 continue
             if bcpOut == (0, 0):
                 continue
             if bcpIn[0] == bcpOut[0] and bcpIn[1] != bcpOut[1]:
                 bPoint.anchorLabels = ["extremePoint"]
             if rotation and bcpIn[0] != bcpOut[0] and bcpIn[1] == bcpOut[1]:
                 bPoint.anchorLabels = ["extremePoint"]
     
     cx, cy = 0, 0
     box = dest.box
     if box:
         cx = box[0] + (box[2] - box[0]) * .5
         cy = box[1] + (box[3] - box[1]) * .5
         
     t = Transform()
     t = t.skew(skew)
     t = t.translate(cx, cy).rotate(rotation).translate(-cx, -cy)
     
     dest.transform(t)
     
     dest.extremePoints(round=0)
     for contour in dest:
         for point in contour.points:
             if "extremePoint" in point.labels:
                 point.selected = True
                 point.smooth = True
             else:
                 point.selected = False
     dest.removeSelection()
     dest.round() 
     return dest
Beispiel #6
0
 def skew(self, x, y=0, center=(0, 0)):
     t = Transform()
     t = t.skew(math.radians(x), math.radians(y))
     self.transform(t, center=center)
    def getGlyph(self, glyph, skew, rotation, addComponents=False, skipComponents=False):
        skew = radians(skew)
        rotation = radians(-rotation)

        dest = glyph.copy()

        if not addComponents:
            for component in dest.components:
                pointPen = DecomposePointPen(glyph.layer, dest.getPointPen(), component.transformation)
                component.drawPoints(pointPen)
                dest.removeComponent(component)

        for contour in list(dest):
            if contour.open:
                dest.removeContour(contour)

        if skew == 0 and rotation == 0:
            return dest

        for contour in dest:
            for bPoint in contour.bPoints:
                bcpIn = bPoint.bcpIn
                bcpOut = bPoint.bcpOut
                if bcpIn == (0, 0):
                    continue
                if bcpOut == (0, 0):
                    continue
                if bcpIn[0] == bcpOut[0] and bcpIn[1] != bcpOut[1]:
                    bPoint.anchorLabels = ["extremePoint"]
                if rotation and bcpIn[0] != bcpOut[0] and bcpIn[1] == bcpOut[1]:
                    bPoint.anchorLabels = ["extremePoint"]

        cx, cy = 0, 0
        box = glyph.bounds
        if box:
            cx = box[0] + (box[2] - box[0]) * .5
            cy = box[1] + (box[3] - box[1]) * .5

        t = Transform()
        t = t.skew(skew)
        t = t.translate(cx, cy).rotate(rotation).translate(-cx, -cy)

        if not skipComponents:
            dest.transformBy(tuple(t))
        else:
            for contour in dest.contours:
                contour.transformBy(tuple(t))

            # this seems to work !!!
            for component in dest.components:
                # get component center
                _box = glyph.layer[component.baseGlyph].bounds
                if not _box:
                    continue
                _cx = _box[0] + (_box[2] - _box[0]) * .5
                _cy = _box[1] + (_box[3] - _box[1]) * .5
                # calculate origin in relation to base glyph
                dx = cx - _cx
                dy = cy - _cy
                # create transformation matrix
                tt = Transform()
                tt = tt.skew(skew)
                tt = tt.translate(dx, dy).rotate(rotation).translate(-dx, -dy)
                # apply transformation matrix to component offset
                P = RPoint()
                P.position = component.offset
                P.transformBy(tuple(tt))
                # set component offset position
                component.offset = P.position

        dest.extremePoints(round=0)
        for contour in dest:
            for point in contour.points:
                if "extremePoint" in point.labels:
                    point.selected = True
                    point.smooth = True
                else:
                    point.selected = False
        dest.removeSelection()
        dest.round()
        return dest