def testReverseContourOpenPath(self): digestPen = DigestPointPen() TestShapes.openPath(digestPen) d1 = digestPen.getDigest() digestPen = DigestPointPen() pen = ReverseContourPointPen(digestPen) pen.beginPath() pen.addPoint((600, 100), "move") pen.addPoint((600, 600), "line") pen.addPoint((100, 600), "line") pen.addPoint((100, 100), "line") pen.endPath() d2 = digestPen.getDigest() self.assertEqual(d1, d2)
def drawShapeWithRectInGlyph(self, shape, rect, glyph): # draw the shape into the glyph # tell the glyph something is going to happen (undo is going to be prepared) glyph.prepareUndo("Drawing Shapes") # get the pen to draw with pen = glyph.getPointPen() if glyph.preferredSegmentType == "qcurve" and not self.shouldReverse: pen = ReverseContourPointPen(pen) elif self.shouldReverse: pen = ReverseContourPointPen(pen) x, y, w, h = rect # draw with the pen a rect in the glyph if shape == "rect": pen.beginPath() pen.addPoint(_roundPoint(x, y), "line") pen.addPoint(_roundPoint(x + w, y), "line") pen.addPoint(_roundPoint(x + w, y + h), "line") pen.addPoint(_roundPoint(x, y + h), "line") pen.endPath() # draw with the pen an oval in the glyph elif shape == "oval": hw = w / 2. hh = h / 2. r = .55 segmentType = glyph.preferredSegmentType if glyph.preferredSegmentType == "qcurve": r = .42 pen.beginPath() pen.addPoint(_roundPoint(x + hw, y), segmentType, True) pen.addPoint(_roundPoint(x + hw + hw * r, y)) pen.addPoint(_roundPoint(x + w, y + hh - hh * r)) pen.addPoint(_roundPoint(x + w, y + hh), segmentType, True) pen.addPoint(_roundPoint(x + w, y + hh + hh * r)) pen.addPoint(_roundPoint(x + hw + hw * r, y + h)) pen.addPoint(_roundPoint(x + hw, y + h), segmentType, True) pen.addPoint(_roundPoint(x + hw - hw * r, y + h)) pen.addPoint(_roundPoint(x, y + hh + hh * r)) pen.addPoint(_roundPoint(x, y + hh), segmentType, True) pen.addPoint(_roundPoint(x, y + hh - hh * r)) pen.addPoint(_roundPoint(x + hw - hw * r, y)) pen.endPath() # tell the glyph you are done with your actions so it can handle the undo properly glyph.performUndo()
def drawShapeWithRectInGlyph(self, shape, rect, glyph): # draw the shape into the glyph # tell the glyph something is going to happen (undo is going to be prepared) glyph.prepareUndo("Drawing Shapes") # get the pen to draw with pen = glyph.getPointPen() if glyph.preferredSegmentType == "qcurve" and not self.shouldReverse: pen = ReverseContourPointPen(pen) elif self.shouldReverse: pen = ReverseContourPointPen(pen) x, y, w, h = rect # draw with the pen a rect in the glyph if shape == "rect": pen.beginPath() pen.addPoint(_roundPoint(x, y), "line") pen.addPoint(_roundPoint(x + w, y), "line") pen.addPoint(_roundPoint(x + w, y + h), "line") pen.addPoint(_roundPoint(x, y + h), "line") pen.endPath() # draw with the pen an oval in the glyph elif shape == "oval": hw = w/2. hh = h/2. r = .55 segmentType = glyph.preferredSegmentType if glyph.preferredSegmentType == "qcurve": r = .42 pen.beginPath() pen.addPoint(_roundPoint(x + hw, y), segmentType, True) pen.addPoint(_roundPoint(x + hw + hw*r, y)) pen.addPoint(_roundPoint(x + w, y + hh - hh*r)) pen.addPoint(_roundPoint(x + w, y + hh), segmentType, True) pen.addPoint(_roundPoint(x + w, y + hh + hh*r)) pen.addPoint(_roundPoint(x + hw + hw*r, y + h)) pen.addPoint(_roundPoint(x + hw, y + h), segmentType, True) pen.addPoint(_roundPoint(x + hw - hw*r, y + h)) pen.addPoint(_roundPoint(x, y + hh + hh*r)) pen.addPoint(_roundPoint(x, y + hh), segmentType, True) pen.addPoint(_roundPoint(x, y + hh - hh*r)) pen.addPoint(_roundPoint(x + hw - hw*r, y)) pen.endPath() # tell the glyph you are done with your actions so it can handle the undo properly glyph.performUndo()
def addShapeInGlyphForPoint(self, glyph, point): w = h = self.size if self.useGrid: x = int(floor(point.x / float(w))) * w y = int(floor(point.y / float(h))) * h else: x = point.x - w*.5 y = point.y - h*.5 pen = glyph.getPointPen() if glyph.preferedSegmentType == "qcurve": pen = ReverseContourPointPen(pen) if self.drawingMode == RECT_MODE: pen.beginPath() pen.addPoint(_roundPoint(x, y), "line") pen.addPoint(_roundPoint(x + w, y), "line") pen.addPoint(_roundPoint(x + w, y + h), "line") pen.addPoint(_roundPoint(x, y + h), "line") pen.endPath() elif self.drawingMode == OVAL_MODE: hw = w/2. hh = h/2. r = .55 segmentType = glyph.preferedSegmentType if glyph.preferedSegmentType == "qcurve": r = .42 pen.beginPath() pen.addPoint(_roundPoint(x + hw, y), segmentType) pen.addPoint(_roundPoint(x + hw + hw*r, y)) pen.addPoint(_roundPoint(x + w, y + hh - hh*r)) pen.addPoint(_roundPoint(x + w, y + hh), segmentType) pen.addPoint(_roundPoint(x + w, y + hh + hh*r)) pen.addPoint(_roundPoint(x + hw + hw*r, y + h)) pen.addPoint(_roundPoint(x + hw, y + h), segmentType) pen.addPoint(_roundPoint(x + hw - hw*r, y + h)) pen.addPoint(_roundPoint(x, y + hh + hh*r)) pen.addPoint(_roundPoint(x, y + hh), segmentType) pen.addPoint(_roundPoint(x, y + hh - hh*r)) pen.addPoint(_roundPoint(x + hw - hw*r, y)) pen.endPath() elif self.drawingMode == COMPONENT_MODE and self.componentName and self.componentName != glyph.name: pen.addComponent(self.componentName, [1, 0, 0, 1, x, y])