Esempio n. 1
0
 def _distributeSpacing(self, index, title):
     glyph = CurrentGlyph()
     if glyph is None:
         return
     rects, selectedContours, selectedBPoints = getSelectionData(glyph)
     if len(rects) < 3:
         return
     widths = []
     heights = []
     edgeRect = None
     for rect in rects:
         xMin, yMin, xMax, yMax = rect
         widths.append(xMax - xMin)
         heights.append(yMax - yMin)
         if edgeRect is None:
             edgeRect = rect
         else:
             edgeRect = unionRect(edgeRect, rect)
     objectWidth = sum(widths)
     objectHeight = sum(heights)
     xMin, yMin, xMax, yMax = edgeRect
     overallWidth = xMax - xMin
     overallHeight = yMax - yMin
     availableXSpace = overallWidth - objectWidth
     availableYSpace = overallHeight - objectHeight
     xSpace = availableXSpace / (len(rects) - 1)
     ySpace = availableYSpace / (len(rects) - 1)
     spaceBetweenObjects = (xSpace, ySpace)[index]
     ordered = [(bPoint.anchor[index], (bPoint.anchor[0], bPoint.anchor[1],
                                        bPoint.anchor[0], bPoint.anchor[1]),
                 bPoint) for bPoint in selectedBPoints]
     ordered += [(contour.bounds[index], contour.bounds, contour)
                 for contour in selectedContours]
     ordered.sort()
     glyph.prepareUndo(title)
     prevEdge = None
     for pos, bounds, obj in ordered[:-1]:
         xMin, yMin, xMax, yMax = bounds
         width = xMax - xMin
         height = yMax - yMin
         size = (width, height)[index]
         if prevEdge is None:
             newPos = (xMin, yMin)[index]
         else:
             newPos = prevEdge + spaceBetweenObjects
         d = newPos - pos
         print(d)
         if d != 0:
             if index == 0:
                 obj.moveBy((d, 0))
             else:
                 obj.moveBy((0, d))
         prevEdge = newPos + size
     for bPoint in selectedBPoints:
         bPoint.round()
     for contour in selectedContours:
         contour.round()
     glyph.changed()
     glyph.performUndo()
     UpdateCurrentGlyphView()
Esempio n. 2
0
 def view_callback(self, sender):
     if sender.get():
         self.on()
     else:
         self.off()
     # update glyph view
     g = CurrentGlyph()
     g.changed()
Esempio n. 3
0
def attachLabelToSelectedPoints(labelName):
    myGlyph = CurrentGlyph()
    for eachContour in myGlyph:
        for eachPt in eachContour.points:
            if eachPt.selected is True:
                eachPt.name = labelName
    if version[0] == '2':
        myGlyph.changed()
    else:
        myGlyph.update()
    UpdateCurrentGlyphView()
Esempio n. 4
0
 def _distribute(self, methods, title):
     glyph = CurrentGlyph()
     if glyph is None:
         return
     rects, selectedContours, selectedBPoints = getSelectionData(glyph)
     if len(rects) < 3:
         return
     glyph.prepareUndo(title)
     for method in methods:
         method(rects, selectedContours, selectedBPoints)
     for bPoint in selectedBPoints:
         bPoint.round()
     for contour in selectedContours:
         contour.round()
     glyph.changed()
     glyph.performUndo()
     UpdateCurrentGlyphView()
Esempio n. 5
0
    def addOverlap(self, sender):

        g = CurrentGlyph()

        selection = []
        selectedPoints = g.selectedPoints

        for p in selectedPoints:
            p.selected = False
            selection.append((p.x, p.y))

        pen = AddOverlapPointPen(selection)

        g.drawPoints(pen)

        with g.undo("Add Overlap"):
            g.clearContours()
            pen.drawPoints(g.getPointPen())
            g.changed()