Beispiel #1
0
 def layerActions(self):
     glyph = self.view.glyph()
     newLayer, action, ok = LayerActionsDialog.getLayerAndAction(
         self, glyph)
     if ok and newLayer is not None:
         # TODO: whole glyph for now, but consider selection too
         if not glyph.name in newLayer:
             newLayer.newGlyph(glyph.name)
         otherGlyph = newLayer[glyph.name]
         otherGlyph.disableNotifications()
         if action == "Swap":
             tempGlyph = TGlyph()
             otherGlyph.drawPoints(tempGlyph.getPointPen())
             tempGlyph.width = otherGlyph.width
             otherGlyph.clearContours()
         glyph.drawPoints(otherGlyph.getPointPen())
         otherGlyph.width = glyph.width
         if action != "Copy":
             glyph.disableNotifications()
             glyph.clearContours()
             if action == "Swap":
                 tempGlyph.drawPoints(glyph.getPointPen())
                 glyph.width = tempGlyph.width
             glyph.enableNotifications()
         otherGlyph.enableNotifications()
Beispiel #2
0
def FilterSelectionFactory(glyph):
    copyGlyph = TGlyph()
    pen = copyGlyph.getPointPen()
    for anchor in glyph.anchors:
        if anchor.selected:
            anchorDict = dict(
                x=anchor.x, y=anchor.y, name=anchor.name, color=anchor.color, identifier=anchor.identifier
            )
            copyGlyph.appendAnchor(anchorDict)
    for contour in glyph:
        onCurvesSelected = True
        for point in contour:
            if point.segmentType and not point.selected:
                onCurvesSelected = False
                break
        if onCurvesSelected:
            contour.drawPoints(pen)
        else:
            # TODO: somehow make this into a pen?
            # I'm wary of doing it because it warrants reordering and so on
            segments = contour.segments
            # put start point at the beginning of a subcontour
            lastSubcontour = None
            for index, segment in reversed(list(enumerate(segments))):
                if segment[-1].selected:
                    lastSubcontour = index
                else:
                    if lastSubcontour is not None:
                        break
            if lastSubcontour is None:
                continue
            segments = segments[lastSubcontour:] + segments[:lastSubcontour]
            # now draw filtered
            shouldMoveTo = True
            for index, segment in enumerate(segments):
                on = segment[-1]
                if not on.selected:
                    if not shouldMoveTo:
                        pen.endPath()
                        shouldMoveTo = True
                    continue
                if on.segmentType == "move" and not shouldMoveTo:
                    pen.endPath()
                    shouldMoveTo = True
                if shouldMoveTo:
                    pen.beginPath()
                    pen.addPoint((on.x, on.y), segmentType="move", smooth=on.smooth, name=on.name)
                    shouldMoveTo = False
                    continue
                for point in segment:
                    pen.addPoint(
                        (point.x, point.y), segmentType=point.segmentType, smooth=point.smooth, name=point.name
                    )
            if not shouldMoveTo:
                pen.endPath()
    for component in glyph.components:
        if component.selected:
            component.drawPoints(pen)
    return copyGlyph
Beispiel #3
0
 def fetchGlyphs(glyphNames, leftGlyphs=[], rightGlyphs=[]):
     ret = []
     for name in glyphNames:
         if name == "\u2029":
             glyph = TGlyph()
             glyph.unicode = 2029
             ret.append(glyph)
         elif name in self.font:
             ret.extend(leftGlyphs)
             ret.append(self.font[name])
             ret.extend(rightGlyphs)
     return ret
Beispiel #4
0
 def fetchGlyphs(glyphNames, leftGlyphs=[], rightGlyphs=[]):
     ret = []
     for name in glyphNames:
         if name == "\u2029":
             glyph = TGlyph()
             glyph.unicode = 2029
             ret.append(glyph)
         elif name in self.font:
             ret.extend(leftGlyphs)
             ret.append(self.font[name])
             ret.extend(rightGlyphs)
     return ret
Beispiel #5
0
 def layerActions(self):
     glyph = self.view.glyph()
     newLayer, action, ok = LayerActionsDialog.getLayerAndAction(
         self, glyph)
     if ok and newLayer is not None:
         # TODO: whole glyph for now, but consider selection too
         if not glyph.name in newLayer:
             newLayer.newGlyph(glyph.name)
         otherGlyph = newLayer[glyph.name]
         otherGlyph.disableNotifications()
         if action == "Swap":
             tempGlyph = TGlyph()
             otherGlyph.drawPoints(tempGlyph.getPointPen())
             tempGlyph.width = otherGlyph.width
             otherGlyph.clearContours()
         glyph.drawPoints(otherGlyph.getPointPen())
         otherGlyph.width = glyph.width
         if action != "Copy":
             glyph.disableNotifications()
             glyph.clearContours()
             if action == "Swap":
                 tempGlyph.drawPoints(glyph.getPointPen())
                 glyph.width = tempGlyph.width
             glyph.enableNotifications()
         otherGlyph.enableNotifications()
Beispiel #6
0
 def pasteOutlines(self):
     glyph = self.view.glyph()
     clipboard = QApplication.clipboard()
     mimeData = clipboard.mimeData()
     if mimeData.hasFormat("application/x-defconQt-glyph-data"):
         data = pickle.loads(
             mimeData.data("application/x-defconQt-glyph-data"))
         if len(data) == 1:
             pen = glyph.getPointPen()
             pasteGlyph = TGlyph()
             pasteGlyph.deserialize(data[0])
             # TODO: if we serialize selected state, we don't need to do
             # this
             pasteGlyph.selected = True
             if len(pasteGlyph) or len(pasteGlyph.components) or \
                     len(pasteGlyph.anchors):
                 glyph.prepareUndo()
                 pasteGlyph.drawPoints(pen)
Beispiel #7
0
 def pasteOutlines(self):
     glyph = self.view.glyph()
     clipboard = QApplication.clipboard()
     mimeData = clipboard.mimeData()
     if mimeData.hasFormat("application/x-defconQt-glyph-data"):
         data = pickle.loads(mimeData.data(
             "application/x-defconQt-glyph-data"))
         if len(data) == 1:
             pen = glyph.getPointPen()
             pasteGlyph = TGlyph()
             pasteGlyph.deserialize(data[0])
             # TODO: if we serialize selected state, we don't need to do
             # this
             pasteGlyph.selected = True
             if len(pasteGlyph) or len(pasteGlyph.components) or \
                     len(pasteGlyph.anchors):
                 glyph.prepareUndo()
                 pasteGlyph.drawPoints(pen)
Beispiel #8
0
def FilterSelectionFactory(glyph):
    # TODO: somehow make this all a pen?
    # I'm wary of doing it because it warrants reordering and so on
    copyGlyph = TGlyph()
    pen = copyGlyph.getPointPen()
    for anchor in glyph.anchors:
        if anchor.selected:
            anchorDict = dict(
                x=anchor.x,
                y=anchor.y,
                name=anchor.name,
                color=anchor.color,
                identifier=anchor.identifier,
            )
            copyGlyph.appendAnchor(anchorDict)
    for contour in glyph:
        onCurvesSelected = True
        for point in contour:
            if point.segmentType and not point.selected:
                onCurvesSelected = False
                break
        if onCurvesSelected:
            contour.drawPoints(pen)
        else:
            lastSubcontour = None
            segments = contour.segments
            # put start point at the beginning of a subcontour
            for index, segment in reversed(list(enumerate(segments))):
                if segment[-1].selected:
                    lastSubcontour = index
                else:
                    if lastSubcontour is not None:
                        break
            if lastSubcontour is None:
                continue
            segments = segments[lastSubcontour:] + segments[:lastSubcontour]
            # now draw filtered
            pen.beginPath()
            shouldMoveTo = False
            for index, segment in enumerate(segments):
                on = segment[-1]
                if not on.selected:
                    if not shouldMoveTo:
                        pen.endPath()
                        shouldMoveTo = True
                    continue
                if shouldMoveTo or not index:
                    if shouldMoveTo:
                        pen.beginPath()
                        shouldMoveTo = False
                    pen.addPoint((on.x, on.y),
                                 segmentType="move",
                                 smooth=on.smooth,
                                 name=on.name)
                    continue
                for point in segment:
                    pen.addPoint((point.x, point.y),
                                 segmentType=point.segmentType,
                                 smooth=point.smooth,
                                 name=point.name)
            if not shouldMoveTo:
                pen.endPath()
    for component in glyph.components:
        if component.selected:
            component.drawPoints(pen)
    return copyGlyph