Exemple #1
0
 def mouseDown(self, point, clickCount):
     if self.selection.hasSelection():
         return
     if not self.optionDown:
         self.pen = CocoaPen(None)
     else:
         self.pen = self._oldPen
     self.pen.moveTo((point.x, point.y))
    def drawLetters(self):

        xFactor = self.xHeightTarget / xHeightCurrent

        self.drawDescender()

        fill(0, 0, 0, 1)
        stroke(0, 0, 0, 0)

        translate(margin, pageHeight - margin - self.xHeightTarget)

        for g in self.inputText:
            scale(xFactor)
            pen = CocoaPen(f)
            f[g].draw(pen)
            drawPath(pen.path)
            translate(f[g].width, 0)
            scale(1 / xFactor)

            # if g == " ":
            #     print f["space"].unicode
            #     translate(f["space"].width, 0)
            # else:
            #     print f[g].name
            #     scale(xFactor)
            #     pen = CocoaPen(f)
            #     f[g].draw(pen)
            #     drawPath(pen.path)
            #     translate(f[g].width, 0)
            #     scale(1/xFactor)

        self.refreshCanvas()
Exemple #3
0
    def drawLetters(self):

        xFactor = calculateMetrics(self.xHeightDrawing)[0]

        if self.grayLettersBoxDrawing == 1:
            cmykFill(0, 0, 0, .15, 1)
            cmykStroke(None)

        else:
            cmykFill(0, 0, 0, 1, 1)
            cmykStroke(None)

        translate(marginLBR, self.xHeightList[0] - self.xHeightDrawing)

        for g in self.inputTextDrawing:

            pen = CocoaPen(f)

            scale(xFactor)

            f[g].draw(pen)
            drawPath(pen.path)
            translate(f[g].width, 0)

            scale(1 / xFactor)
Exemple #4
0
 def drawRotationPreview(self, info):
     outline = self.getRotatedGlyph()
     pen = CocoaPen(None)
     self.w.color.get().set()
     outline.draw(pen)
     pen.path.setLineWidth_(0.5)
     pen.path.stroke()
Exemple #5
0
        def drawLetters():

            # Check if this class has inputText before drawing letters
            # This helps with scaling & saving functions
            if hasattr(self, "inputText"):

                xFactor = calculateMetrics(self.xHeightTarget)[0]

                if self.grayLettersBox == 1:
                    cmykFill(0, 0, 0, .15, 1)
                    cmykStroke(None)

                else:
                    cmykFill(0, 0, 0, 1, 1)
                    cmykStroke(None)

                translate(marginLBR, firstXHeightLine - self.xHeightTarget)

                for g in self.inputText:

                    pen = CocoaPen(f)

                    scale(xFactor)

                    f[g].draw(pen)
                    drawPath(pen.path)
                    translate(f[g].width, 0)

                    scale(1 / xFactor)

                self.refreshCanvas()
Exemple #6
0
    def drawLetters(self):    
    
        xFactor = self.xHeightTarget / xHeightCurrent
        descenderTarget = descender * xFactor
        
        pageWidth = drawBot.width()
        pageHeight = drawBot.height()
        
        if self.descBox == 1:
            drawBot.stroke(1,0,0, 1)
            drawBot.line((margin, pageHeight-margin-self.xHeightTarget+descenderTarget),(pageWidth-dpi, pageHeight-margin-self.xHeightTarget+descenderTarget))
        
        elif self.descBox == 0:
            drawBot.stroke(0,0,0,0)
        
        drawBot.fill(0,0,0, 1)
        drawBot.stroke(0,0,0, 0)

        drawBot.translate(margin, pageHeight-margin-self.xHeightTarget)

        drawBot.scale(xFactor)

        for g in self.text:
            pen = CocoaPen(f)
            f[g].draw(pen)
            drawBot.drawPath(pen.path)
            drawBot.translate(f[g].width, 0)
        

        pdf = drawBot.pdfImage()
        self.w.canvas.setPDFDocument(pdf)
Exemple #7
0
 def test_draw(self):
     pen = CocoaPen(None)
     draw(pen)
     self.assertEqual(
         "moveto 50.0 0.0 lineto 50.0 500.0 lineto 200.0 500.0 curveto 350.0 500.0 450.0 400.0 450.0 250.0 curveto 450.0 100.0 350.0 0.0 200.0 0.0 close ",
         cocoaPathToString(pen.path)
     )
    def draw(self):
        self.xFactor = self.targetXheight / currentXheight

        drawBot.newDrawing()
        drawBot.newPage("LetterLandscape")

        pageWidth = drawBot.width()

        drawBot.fill(0, 0, 0, 0.5)
        drawBot.stroke(0, 0, 0, 1)

        drawBot.rect(.5 * dpi, .5 * dpi, pageWidth - (1 * dpi),
                     self.targetXheight)

        drawBot.translate(0.5 * dpi, .5 * dpi)
        drawBot.scale(self.xFactor)

        for g in self.text:
            pen = CocoaPen(f)
            f[g].draw(pen)
            drawBot.drawPath(pen.path)
            drawBot.translate(f[g].width, 0)

        pdf = drawBot.pdfImage()
        # set the pdf data in the canvas
        self.w.canvas.setPDFDocument(pdf)
Exemple #9
0
 def addGlyph(self, glyph):
     if hasattr(glyph, "getRepresentation"):
         path = glyph.getRepresentation("defconAppKit.NSBezierPath")
     else:
         pen = CocoaPen(glyph.getParent())
         glyph.draw(pen)
         path = pen.path
     self.getNSBezierPath().appendBezierPath_(path)
Exemple #10
0
def drawGlyph(glyph):
    if hasattr(glyph, "getRepresentation"):
        path = glyph.getRepresentation("defconAppKit.NSBezierPath")
    else:
        pen = CocoaPen(glyph.getParent())
        glyph.draw(pen)
        path = pen.path
    _drawBotDrawingTool.drawPath(path)
Exemple #11
0
def drawLetter(f, glyphName, fontSize):
    fontScale = float(fontSize) / f.info.unitsPerEm
    save()
    scale(fontScale)
    c = CocoaPen(f)
    f[glyphName].draw(c)
    drawPath(c.path)
    restore()
 def mouseDown(self, point, clickCount):
     if self.selection.hasSelection():
         return
     if not self.optionDown:
         self.pen = CocoaPen(None)
     else:
         self.pen = self._oldPen
     self.pen.moveTo((point.x, point.y))
def test_getOutlinePath():
    ftf, ttfGlyphSet = _getFonts("IBMPlexSans-Regular.ttf")

    for glyphName in ["a", "B", "O", "period", "bar", "aring"]:
        p = ftf.getOutlinePath(glyphName)
        pen = CocoaPen(ttfGlyphSet)
        ttfGlyphSet[glyphName].draw(pen)
        assert _comparePaths(p, pen.path)
Exemple #14
0
 def getOutline(self, cocoa=True):
     if cocoa:
         pen = CocoaPen(None)  # by now there are no more composites
         self.draw(pen)
         return pen.path
     else:
         pen = RecordingPen()
         self.draw(pen)
         return pen
Exemple #15
0
 def drawSolidPreview(self, info):
     outline = self.getRotatedGlyph()
     pen = CocoaPen(None)
     outline.draw(pen)
     defaultPreviewColor = getDefault('glyphViewPreviewFillColor')
     fillColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(
         *defaultPreviewColor)
     fillColor.set()
     pen.path.fill()
Exemple #16
0
 def _addOutlinePathToGlyph(self, glyph):
     if self.cocoa:
         pen = CocoaPen(self.glyphSet)
         glyph.draw(pen)
         glyph.outline = pen.path
     else:
         pen = RecordingPen()
         glyph.draw(pen)
         glyph.outline = pen
Exemple #17
0
def myDrawGlyph(glyph):
    """
    Similar to drawBot / mojo.drawingTools drawGlyph.

    Written here to test a hypothesis and as a reference
    for the facetDrawGlyph() function below.
    """
    pen = CocoaPen(glyph.getParent())
    glyph.draw(pen)
    drawPath(pen.path)
Exemple #18
0
    def draw(self):
        #rect(10, 10, self.size, self.size)
        pen = CocoaPen(f)

        fill(0, 0, 0, 0.5)
        stroke(0, 0, 0, 1)

        translate(0, 80)
        scale(self.size)
        g.draw(pen)
        drawPath(pen.path)
 def drawPreview(self, info):
     # Draw a filled in version of the interpolated glyph
     scale = info["scale"]
     if self.interpolatedGlyph:
         pen = CocoaPen(None)
         self.interpolatedGlyph.draw(pen)
         dt.fill(r=0, g=0, b=0, a=0.6)
         dt.stroke(r=None, g=None, b=None, a=1)
         dt.save()
         dt.translate(self.currentGlyph.width)
         dt.drawPath(pen.path)
         dt.restore()
Exemple #20
0
    def drawLetter(self):
        newPage(300, 300)
        pen = CocoaPen(f)

        fill(0, 0, 0, 0.5)
        stroke(0, 0, 0, 1)

        translate(0, 80)
        scale(self.size)
        g.draw(pen)

        drawPath(pen.path)
Exemple #21
0
def drawGlyph(g):
    # Get glyph outline
    f = g.font
    pen = CocoaPen(f)
    g.draw(pen)
    bezierPath = pen.path
    # Draw
    with db.savedState():
        db.translate(-g.width * 0.5, 450)  # Center the glyph
        path = db.BezierPath()
        path.setNSBezierPath(bezierPath)
        db.drawPath(path)
    def draw(self):

        fill(0, 0, 0, 0.45)
        stroke(0, 0, 0, 1)

        translate(0, 80)
        scale(self.size)

        for g in self.text:
            pen = CocoaPen(f)
            f[g].draw(pen)
            drawPath(pen.path)
            translate(f[g].width, 0)
Exemple #23
0
    def draw(self):

        fill(0, 0, 0, .5)
        stroke(0, 0, 0, 1)

        translate(10, 80)
        scale(.1)

        for g in self.text:
            pen = CocoaPen(f)
            f[g].draw(pen)
            drawPath(pen.path)
            rect(-10, -self.offset, f[g].width + 20, -self.thickness)
            translate(f[g].width, 0)
Exemple #24
0
    def drawOutline(self, info):
        if not self.w.preview.get():
            return
        outline = self.calculate(glyph=info["glyph"])
        pen = CocoaPen(None)
        outline.draw(pen)

        self.w.color.get().set()
        if self.w.fill.get():
            pen.path.fill()

        if self.w.stroke.get():
            pen.path.setLineWidth_(info["scale"])
            pen.path.stroke()
class PolygonSelectionTool(EditingTool):
    
    def setup(self):
        self.pen = None
        self._oldPen = None
        
    def mouseDown(self, point, clickCount):
        if self.selection.hasSelection():
            return
        if not self.optionDown:
            self.pen = CocoaPen(None)
        else:
            self.pen = self._oldPen
        self.pen.moveTo((point.x, point.y))
    
    def mouseDragged(self, point, delta):
        if self.pen is None:
            return
        self.pen.lineTo((point.x, point.y))
    
    def mouseUp(self, point):
        if self.pen is None:
            return
        self.pen.closePath()
        
        glyph = self.getGlyph()
        path = self.pen.path
        for contour in glyph:
            for point in contour.points:
                result = path.containsPoint_((point.x, point.y))
                if self.controlDown:
                    point.selected = not result
                else:
                    point.selected = result
        
        self._oldPen = self.pen
        self.pen = None
        
    def draw(self, scale):
        if self.pen is None:
            return
        fill( 1 , 0 , 0 , .2 )
        #stroke(0, .6)
        #strokeWidth(scale)
        drawPath(self.pen.path)
    
    def canSelectWithMarque(self):
        return False
    
    def getToolbarTip(self):
        return "Polygon Selection Tool"

    def getToolbarIcon(self):
        icon = NSImage.alloc().initWithContentsOfFile_("polygon-select.png")
        if icon :
            return icon 
Exemple #26
0
class PolygonSelectionTool(EditingTool):
    def setup(self):
        self.pen = None
        self._oldPen = None

    def mouseDown(self, point, clickCount):
        if self.selection.hasSelection():
            return
        if not self.optionDown:
            self.pen = CocoaPen(None)
        else:
            self.pen = self._oldPen
        self.pen.moveTo((point.x, point.y))

    def mouseDragged(self, point, delta):
        if self.pen is None:
            return
        self.pen.lineTo((point.x, point.y))

    def mouseUp(self, point):
        if self.pen is None:
            return
        self.pen.closePath()

        glyph = self.getGlyph()
        path = self.pen.path
        for contour in glyph:
            for point in contour.points:
                result = path.containsPoint_((point.x, point.y))
                if self.controlDown:
                    point.selected = not result
                else:
                    point.selected = result

        self._oldPen = self.pen
        self.pen = None

    def draw(self, scale):
        if self.pen is None:
            return
        fill(1, 0, 0, .2)
        #stroke(0, .6)
        #strokeWidth(scale)
        drawPath(self.pen.path)

    def canSelectWithMarque(self):
        return False

    def getToolbarTip(self):
        return "Polygon Selection Tool"

    def getToolbarIcon(self):
        icon = NSImage.alloc().initWithContentsOfFile_("polygon-select.pdf")
        if icon:
            return icon
Exemple #27
0
    def drawGlyphs(self, font, content, size, **kwargs):
        scale = getScale(font, size)
        ascender = getAscenderHeight(font, size)
        self.context.scale(scale)

        x = 0
        y = self.context.b.height() - (ascender + size) * scale * self.leading

        for c in content:
            pen = CocoaPen(font)
            self.context.fill(0)
            self.context.stroke(None)
            glyph = font[c]
            self.context.translate(x, y)
            self.context.drawGlyphPath(glyph)
            self.context.translate(-x, -y)
            x += glyph.width
Exemple #28
0
 def drawDuplicateContours(self, contours, scale):
     glyph = CurrentGlyph()
     font = glyph.getParent()
     duplicateContourColor.set()
     for contourIndex in contours:
         contour = glyph[contourIndex]
         pen = CocoaPen(font)
         contour.draw(pen)
         path = pen.path
         path.fill()
         path.setLineWidth_(5 * scale)
         path.stroke()
         xMin, yMin, xMax, yMax = contour.box
         mid = calcMid((xMin, yMin), (xMax, yMin))
         x, y = mid
         drawString((x, y - (10 * scale)), "Duplicate Contour", 10, scale,
                    duplicateContourColor)
Exemple #29
0
    def drawLetters(self):

        fill(0, 0, 0, 1)
        stroke(0, 0, 0, 0)

        translate(marginLBR, firstXHeightLine - xHeightTarget)

        for g in self.inputText:

            pen = CocoaPen(f)

            scale(xFactor)

            f[g].draw(pen)
            drawPath(pen.path)
            translate(f[g].width, 0)

            scale(1 / xFactor)
Exemple #30
0
 def drawActionPreview(self, data):
     if not self.previewObjects:
         return
     pen = CocoaPen(glyphSet=self.glyph.layer)
     for obj in self.previewObjects:
         if isinstance(obj, BaseBPoint):
             pass
         elif isinstance(obj, BaseContour):
             obj.draw(pen)
         elif isinstance(obj, BaseComponent):
             obj.draw(pen)
     pixel = 1.0 / data["scale"]
     r, g, b, a = getDefault("glyphViewEchoStrokeColor")
     with bot.savedState():
         bot.fill(None)
         bot.stroke(r, g, b, a)
         bot.strokeWidth(pixel)
         bot.drawPath(pen.path)
Exemple #31
0
    def _getGlyphDrawing(self, glyphName, colorLayers):
        if "VarC" in self.ttFont:
            from fontTools.pens.cocoaPen import CocoaPen
            pen = CocoaPen(None)
            location = self._currentVarLocation or {}
            self.varcFont.drawGlyph(pen, glyphName, location)
            return GlyphDrawing(pen.path)
        if colorLayers:
            if self.colorLayers is not None:
                layers = self.colorLayers.get(glyphName)
                if layers is not None:
                    drawingLayers = [(self.ftFont.getOutlinePath(layer.name), layer.colorID)
                                     for layer in layers]
                    return GlyphLayersDrawing(drawingLayers)
            elif self.colorFont is not None:
                return GlyphCOLRv1Drawing(glyphName, self.colorFont)

        outline = self.ftFont.getOutlinePath(glyphName)
        return GlyphDrawing(outline)
Exemple #32
0
    def drawLetters(self):        
    
       # self.drawDescender()

        fill(0, 0, 0, 1)
        stroke(0, 0, 0, 0)

        translate(marginLBR, topLine-xHeightTarget)

        for g in self.inputText:
            
            pen = CocoaPen(f)
            
            scale(xFactor)
            
            f[g].draw(pen)
            drawPath(pen.path)
            translate(f[g].width, 0)
            
            scale(1/xFactor)

        self.refreshCanvas()