예제 #1
0
 def draw(self):
     # draw the color glyph on the canvas
     if self._font is not None:
         save()
         self.setFill(self.colorbg)
         rect(0, 0, 310, 200)
         self.setFill(self.color)
         scale(self.scale)
         translate(50.5, -self.metrics[0] + 20.5)
         self._canvas_draw_metrics()
         for i in range(len(self.layer_glyphs)):
             layerGlyph = self.layer_glyphs[i]["Layer Glyph"]
             if self._selected_color_index is None:
                 op_factor = 1.0
             else:
                 if self._selected_color_index == self.layer_glyphs[i][
                         "layer_color_index"]:
                     op_factor = 1.0
                 else:
                     op_factor = 0.2
             if layerGlyph in self.font:
                 if i < len(self.layer_colors):
                     _color = self.layer_colors[i]
                     self.setFill(_color, op_factor)
                     drawGlyph(self.font[layerGlyph])
         restore()
예제 #2
0
    def drawOnGlyphCanvas(self, infoDict):
        glyphOnCanvas = infoDict['glyph']
        scalingFactor = infoDict['scale']
        bodySize = .25
        horizontalOffset = 80

        if PLUGIN_LIB_NAME in glyphOnCanvas.lib:
            thisLib = glyphOnCanvas.lib[PLUGIN_LIB_NAME]
        else:
            return None

        lftGlyph = None
        if thisLib['lft'] != '':
            lftGlyph = self.selectedFont[thisLib['lft']]

        rgtGlyph = None
        if thisLib['rgt'] != '':
            rgtGlyph = self.selectedFont[thisLib['rgt']]

        try:
            dt.fill(*GRAY)

            if lftGlyph is not None:
                dt.save()
                dt.translate(-lftGlyph.width * bodySize - horizontalOffset,
                             -self.selectedFont.info.unitsPerEm * bodySize)

                # glyph
                dt.scale(bodySize)
                dt.drawGlyph(lftGlyph)

                # lock
                if thisLib['lftActive'] is True:
                    txt = u'🔒'
                else:
                    txt = u'🔓'
                dt.fontSize(300)
                txtWdt, txtHgt = dt.textSize(txt)
                dt.text(txt, (-txtWdt, 0))
                dt.restore()

            if rgtGlyph is not None:
                dt.save()
                dt.translate(glyphOnCanvas.width + horizontalOffset,
                             -self.selectedFont.info.unitsPerEm * bodySize)
                dt.scale(bodySize)
                dt.drawGlyph(rgtGlyph)

                # lock
                if thisLib['rgtActive'] is True:
                    txt = u'🔒'
                else:
                    txt = u'🔓'
                dt.fontSize(300)
                dt.text(txt, (rgtGlyph.width, 0))

                dt.restore()

        except Exception as error:
            print(error)
예제 #3
0
    def _drawLeftNeighborsGlyphs(self, glyph, stroke=True, scale=1):
        if glyph is None:
            return
        font = glyph.font

        left = self.view.unicodeLeftEditText.get()
        left = self.stringToGlyphs(left, font)

        save()
        for index, leftGlyph in enumerate(reversed(list(left))):
            if leftGlyph in font:

                leftGlyph = font[leftGlyph]

                # translate back the width of the glyph
                translate(-leftGlyph.width, 0)
                # performance tricks, the naked attr will return the defcon object
                # and get the cached bezier path to draw
                path = leftGlyph.naked().getRepresentation(
                    "defconAppKit.NSBezierPath")
                # fill the path
                path.fill()
                if stroke:
                    path.setLineWidth_(scale)
                    strokePixelPath(path)
        restore()
예제 #4
0
    def _drawNeighborsGlyphs(self, glyph, stroke=True, scale=1):
        if glyph is None:
            return
        font = glyph.font
        baseName = self.getBaseGlyph(glyph.name)
        left, right = RamsayStData.get(baseName, ("n", "n"))

        if left in font:
            leftGlyph = font[left]
            save()
            # translate back the width of the glyph
            translate(-leftGlyph.width, 0)
            # performance tricks, the naked attr will return the defcon object
            # and get the cached bezier path to draw
            path = leftGlyph.naked().getRepresentation("defconAppKit.NSBezierPath")
            # fill the path
            path.fill()
            if stroke:
                path.setLineWidth_(scale)
                strokePixelPath(path)
            restore()

        # do the same for the other glyph
        if right in font:
            rightGlyph = font[right]
            save()
            # translate forward the width of the current glyph
            translate(glyph.width, 0)
            path = rightGlyph.naked().getRepresentation("defconAppKit.NSBezierPath")
            path.fill()
            if stroke:
                path.setLineWidth_(scale)
                strokePixelPath(path)
            restore()
    def _drawNeighborsGlyphs(self, glyph, stroke=True, scale=1):
        if glyph is None:
            return
        font = glyph.getParent()
        baseName = self.getBaseGlyph(glyph.name)
        left, right = RamsayStData.get(baseName, ("n", "n"))

        if left in font:
            leftGlyph = font[left]
            save()
            # translate back the width of the glyph
            translate(-leftGlyph.width, 0)
            # performance tricks, the naked attr will return the defcon object
            # and get the cached bezier path to draw
            path = leftGlyph.naked().getRepresentation("defconAppKit.NSBezierPath")
            # fill the path
            path.fill()
            if stroke:
                path.setLineWidth_(scale)
                strokePixelPath(path)
            restore()

        # do the same for the other glyph
        if right in font:
            rightGlyph = font[right]
            save()
            # translate forward the width of the current glyph
            translate(glyph.width, 0)
            path = rightGlyph.naked().getRepresentation("defconAppKit.NSBezierPath")
            path.fill()
            if stroke:
                path.setLineWidth_(scale)
                strokePixelPath(path)
            restore()
예제 #6
0
    def _drawGlyphs(self, info):
        """ draw stuff in the glyph window view """
        translateBefore = (0, 0)

        for glyphName in self.selectedGlyphNamesList:
            # trim the contextual portion of the UI glyph name
            # and keep track of it
            if CONTEXTUAL_ANCHOR_TAG in glyphName:
                cxtTagIndex = glyphName.find(CONTEXTUAL_ANCHOR_TAG)
                glyphNameCXTportion = glyphName[cxtTagIndex:]
                glyphName = glyphName[:cxtTagIndex]  # this line must be last!
            else:
                glyphNameCXTportion = ''

            glyphToDraw = self.font[glyphName]

            # determine the offset of the anchors
            offset = self.getAnchorOffsets(self.glyph, glyphToDraw,
                                           glyphNameCXTportion)

            # set the offset of the drawing
            translate(offset[0] - translateBefore[0],
                      offset[1] - translateBefore[1])

            # record the shift amounts (these are needed for resetting the drawing position when more than one mark is selected on the list)
            translateBefore = offset

            # set the fill & stroke
            fill(0, 0, self.Blue, self.Alpha)
            strokeWidth(None)

            # draw it
            mojoPen = MojoDrawingToolsPen(glyphToDraw, self.font)
            glyphToDraw.draw(mojoPen)
            mojoPen.draw()
예제 #7
0
    def _drawRightNeighborsGlyphs(self, glyph, stroke=True, scale=1):
        if glyph is None:
            return
        font = glyph.font

        # left = self.view.unicodeLeftEditText.get()
        right = self.view.unicodeRightEditText.get()
        # right = self.rightInput
        right = self.stringToGlyphs(right, font)

        save()

        for index, rightGlyph in enumerate(list(right)):
            if rightGlyph in font:
                rightGlyph = font[rightGlyph]

                # translate back the width of the glyph
                if index == 0:
                    translate(glyph.width, 0)
                else:
                    translate(font[list(right)[index - 1]].width, 0)
                # performance tricks, the naked attr will return the defcon object
                # and get the cached bezier path to draw
                path = rightGlyph.naked().getRepresentation(
                    "defconAppKit.NSBezierPath")
                # fill the path
                path.fill()
                if stroke:
                    path.setLineWidth_(scale)
                    strokePixelPath(path)
        restore()
예제 #8
0
 def drawGlyph(self):
     if not self.previousGlyph == None:
         path = self.previousGlyph.naked().getRepresentation(
             "defconAppKit.NSBezierPath")
         dt.save()
         dt.translate(self.currentGlyph.width)
         path.fill()
         dt.restore()
예제 #9
0
    def _drawDiagonals(self, currentGlyph, scalingFactor, offset_X=0):
        if DIAGONALS_KEY not in currentGlyph.lib:
            return None

        diagonalsData = calcDiagonalsData(currentGlyph, DIAGONALS_KEY)
        for ptsToDisplay, angle, distance in diagonalsData:
            pt1, pt2 = ptsToDisplay

            dt.save()
            dt.stroke(*self.diagonalColor)
            dt.fill(None)
            dt.strokeWidth(1 * scalingFactor)

            if 90 < angle <= 180 or -180 < angle < -90:
                direction = -1
                adjustedAngle = angle + 180 + 90
            else:
                direction = 1
                adjustedAngle = angle + 90

            diagonalPt1 = pt1[0] + cos(radians(adjustedAngle)) * (
                (DIAGONAL_OFFSET - 1) * direction), pt1[1] + sin(
                    radians(adjustedAngle)) * (
                        (DIAGONAL_OFFSET - 1) * direction)
            diagonalPt2 = pt2[0] + cos(radians(adjustedAngle)) * (
                (DIAGONAL_OFFSET - 1) * direction), pt2[1] + sin(
                    radians(adjustedAngle)) * (
                        (DIAGONAL_OFFSET - 1) * direction)
            offsetPt1 = pt1[0] + cos(radians(
                adjustedAngle)) * DIAGONAL_OFFSET * direction, pt1[1] + sin(
                    radians(adjustedAngle)) * DIAGONAL_OFFSET * direction
            offsetPt2 = pt2[0] + cos(radians(
                adjustedAngle)) * DIAGONAL_OFFSET * direction, pt2[1] + sin(
                    radians(adjustedAngle)) * DIAGONAL_OFFSET * direction

            dt.line((pt1), (offsetPt1))
            dt.line((pt2), (offsetPt2))
            dt.line((diagonalPt1), (diagonalPt2))
            dt.restore()

            dt.save()
            textQualities(BODYSIZE_CAPTION * scalingFactor)
            offsetMidPoint = calcMidPoint(offsetPt1, offsetPt2)
            dt.translate(offsetMidPoint[0], offsetMidPoint[1])

            if 90 < angle <= 180 or -180 < angle < -90:
                dt.rotate(angle + 180)
                textBoxY = -BODYSIZE_CAPTION * 1.2 * scalingFactor
            else:
                dt.rotate(angle)
                textBoxY = 0

            dataToPlot = u'∡{:.1f} ↗{:d}'.format(angle % 180, int(distance))
            textWidth, textHeight = dt.textSize(dataToPlot)
            dt.textBox(dataToPlot, (-textWidth / 2., textBoxY, textWidth,
                                    BODYSIZE_CAPTION * 1.2 * scalingFactor),
                       align='center')
            dt.restore()
예제 #10
0
    def _drawGlyphBlack(self, glyph, scalingFactor, offset_X=0):
        dt.save()
        dt.translate(offset_X, 0)

        dt.fill(*BLACK_COLOR)
        dt.stroke(None)
        dt.drawGlyph(glyph)

        dt.restore()
 def _drawPoints(self, points):
     for point in points:
         x, y = point
         self.drawPath.append((x, y))
         save()  # 현재 상태 저장
         translate(x, y)  # x,y 만큼 평행이동
         rotate(self.angle)  # 각도 만큼 회전
         translate(-self.width / 2, -self.height / 2)  #설정한 높낮이 만큼 평행이동
         self.shape(0, 0, self.width,
                    self.height)  #이동한 위치에서 설정한 모양대로 그림 그리기
         restore()  #원래 위치로 돌아가기
 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()
예제 #13
0
    def _drawGlyphOutline(self, glyph, scalingFactor, offset_X=0):
        dt.save()
        dt.translate(offset_X, 0)

        dt.fill(None)
        dt.strokeWidth(1 * scalingFactor)
        dt.stroke(*LIGHT_GRAY_COLOR)
        dt.drawGlyph(glyph)

        scaledRadius = BCP_RADIUS * scalingFactor

        for eachContour in glyph:
            for eachBPT in eachContour.bPoints:
                dt.stroke(None)
                dt.fill(*LIGHT_GRAY_COLOR)
                dt.rect(eachBPT.anchor[0] - scaledRadius / 2.,
                        eachBPT.anchor[1] - scaledRadius / 2., scaledRadius,
                        scaledRadius)

                if eachBPT.bcpIn != (0, 0):
                    dt.stroke(None)
                    dt.fill(*LIGHT_GRAY_COLOR)
                    dt.oval(
                        eachBPT.anchor[0] + eachBPT.bcpIn[0] -
                        scaledRadius / 2., eachBPT.anchor[1] +
                        eachBPT.bcpIn[1] - scaledRadius / 2., scaledRadius,
                        scaledRadius)

                    dt.stroke(*LIGHT_GRAY_COLOR)
                    dt.fill(None)
                    dt.line((eachBPT.anchor[0], eachBPT.anchor[1]),
                            (eachBPT.anchor[0] + eachBPT.bcpIn[0],
                             eachBPT.anchor[1] + eachBPT.bcpIn[1]))

                if eachBPT.bcpOut != (0, 0):
                    dt.stroke(None)
                    dt.fill(*LIGHT_GRAY_COLOR)
                    dt.oval(
                        eachBPT.anchor[0] + eachBPT.bcpOut[0] -
                        scaledRadius / 2., eachBPT.anchor[1] +
                        eachBPT.bcpOut[1] - scaledRadius / 2., scaledRadius,
                        scaledRadius)

                    dt.stroke(*LIGHT_GRAY_COLOR)
                    dt.fill(None)
                    dt.line((eachBPT.anchor[0], eachBPT.anchor[1]),
                            (eachBPT.anchor[0] + eachBPT.bcpOut[0],
                             eachBPT.anchor[1] + eachBPT.bcpOut[1]))

        dt.restore()
예제 #14
0
def drawLock(closed, startingX, glyphQuota, scalingFactor):
    dt.save()
    dt.fill(*BLACK)
    dt.translate(startingX, 0)
    dt.scale(scalingFactor, scalingFactor)
    dt.translate(0, glyphQuota)
    dt.fontSize(300)
    if closed is True:
        txt = u'🔒'
    else:
        txt = u'🔓'
    txtWdt, txtHgt = dt.textSize(txt)
    dt.text(txt, (-txtWdt / 2, 0))
    dt.restore()
예제 #15
0
    def _drawStems(self, currentGlyph, scalingFactor, offset_X=0):
        if STEM_KEY not in currentGlyph.lib:
            return None

        stemData = calcStemsData(currentGlyph, STEM_KEY)
        for PTs, DIFFs, middlePoint in stemData:
            pt1, pt2 = PTs
            horDiff, verDiff = DIFFs

            dt.save()
            dt.translate(offset_X, 0)
            dt.stroke(*self.stemColor)
            dt.fill(None)
            dt.strokeWidth(1 * scalingFactor)

            dt.newPath()
            if horDiff > verDiff:  # ver
                rightPt, leftPt = PTs
                if pt1.x > pt2.x:
                    rightPt, leftPt = leftPt, rightPt
                dt.moveTo((leftPt.x, leftPt.y))
                dt.curveTo((leftPt.x - horDiff / 2, leftPt.y),
                           (rightPt.x + horDiff / 2, rightPt.y),
                           (rightPt.x, rightPt.y))

            else:  # hor
                topPt, btmPt = PTs
                if pt2.y > pt1.y:
                    btmPt, topPt = topPt, btmPt
                dt.moveTo((btmPt.x, btmPt.y))
                dt.curveTo((btmPt.x, btmPt.y + verDiff / 2),
                           (topPt.x, topPt.y - verDiff / 2),
                           (topPt.x, topPt.y))
            dt.drawPath()
            dt.restore()

            dt.save()
            dt.translate(offset_X, 0)
            textQualities(BODYSIZE_CAPTION * scalingFactor)
            dataToPlot = u'↑{:d}\n→{:d}'.format(int(verDiff), int(horDiff))
            textWidth, textHeight = dt.textSize(dataToPlot)
            textRect = (middlePoint[0] - textWidth / 2.,
                        middlePoint[1] - textHeight / 2., textWidth,
                        textHeight)
            dt.textBox(dataToPlot, textRect, align='center')
            dt.restore()
예제 #16
0
 def _drawMetricsCorrection(self, correction):
     dt.save()
     dt.fill(*BLACK)
     dt.stroke(None)
     dt.translate(
         0,
         self.fontObj.info.unitsPerEm + self.fontObj.info.descender + 100)
     dt.scale(1 /
              (self.ctrlHeight /
               (self.canvasScalingFactor * self.fontObj.info.unitsPerEm)))
     dt.font(SYSTEM_FONT_NAME)
     dt.fontSize(BODY_SIZE)
     textWidth, textHeight = dt.textSize('{:+d}'.format(correction))
     dt.textBox('{:+d}'.format(correction),
                (-textWidth / 2., -textHeight / 2., textWidth, textHeight),
                align='center')
     dt.restore()
예제 #17
0
 def _drawArrow(self, position, kind, size, width):
     x, y = position
     save()
     translate(x, y)
     fill(0, 0.8, 0, 0.1)
     strokeWidth(width)
     stroke(0.9, 0.1, 0, 0.85)
     line(-width/2, 0, size, 0)
     line(0, width/2, 0, -size)
     line(0, 0, size, -size)
     #rect(x-scale, y-scale, scale, scale)
     if self.showLabels:
         fill(0.4, 0.4, 0.4, 0.7)
         stroke(None)
         font("LucidaGrande")
         fontSize(int(round(size * 1.1)))
         text(kind, (int(round(size * 1.8)), int(round(-size))))
     restore()
예제 #18
0
 def _drawArrow(self, position, kind, size, width):
     x, y = position
     save()
     translate(x, y)
     fill(0, 0.8, 0, 0.1)
     strokeWidth(width)
     stroke(0.9, 0.1, 0, 0.85)
     line(-width / 2, 0, size, 0)
     line(0, width / 2, 0, -size)
     line(0, 0, size, -size)
     #rect(x-scale, y-scale, scale, scale)
     if self.showLabels:
         fill(0.4, 0.4, 0.4, 0.7)
         stroke(None)
         font("LucidaGrande")
         fontSize(int(round(size * 1.1)))
         text(kind, (int(round(size * 1.8)), int(round(-size))))
     restore()
예제 #19
0
    def drawText(self, scale):
        glyph = self.glyph
        scaleValue = scale["scale"]

        magnet_scale = 3  # The original magnet drawing is too big, this value reduce it

        ctx.save()
        ctx.translate(-25 * (scaleValue / magnet_scale),
                      CurrentFont().info.capHeight / magnet_scale)
        ctx.scale(scaleValue / magnet_scale)
        self.a_magnet()
        ctx.restore()

        ctx.save()
        ctx.translate(-25 * (scaleValue / magnet_scale) + glyph.width,
                      CurrentFont().info.capHeight / magnet_scale)
        ctx.scale(scaleValue / magnet_scale)
        self.a_magnet()
        ctx.restore()
예제 #20
0
    def draw(self):
        if not self.RCJKI.get("currentFont"): return
        if not self.glyph: return

        # self.glyph = self.RCJKI.currentFont[self.glyphName]

        # glyph = self.glyph.preview.computeCharacterGlyphPreview(self.glyph, {"WGHT":1})

        mjdt.save()
        scale = .15
        mjdt.scale(scale, scale)
        mjdt.translate(((200-(self.glyph.width*scale))/scale)*.5, 450)
        # for g in self.glyph.preview({}, forceRefresh=False):
        locationKey = ','.join([k+':'+str(v) for k,v in self.glyph.getLocation().items()])
        if locationKey in self.glyph.previewLocationsStore:
            for g in self.glyph.previewLocationsStore[locationKey]:
            # for g in self.glyph.preview({}, forceRefresh=False):
                mjdt.drawGlyph(g.glyph)
            mjdt.restore()
예제 #21
0
 def _drawGlyphCellArrow(self, num_errors):
     x = 3
     y = 3
     width = 2
     size = 7
     save()
     translate(4, 4)
     
     fill(0.9, 0.4, 0.3, 1)
     rect(-1, -1, size+1, size+1)
     
     lineJoin("round")
     lineCap("butt") # butt, square, round
     strokeWidth(width)
     stroke(1, 1, 1)
     line(-width/2, 0, size, 0)
     line(0, -width/2, 0, size)
     line(width/2, width/2, size-0.5, size-0.5)
     
     restore()
    def drawAnchoredGlyphs(self, glyph, preview=False):
        self.setStroke(0)
        if preview:
            self.setFill(self.preview_color)
        else:
            self.setFill()

        #start = time()

        dbx = 0
        dby = 0

        for a in glyph.anchors:
            anchor_name = a.name
            #print("     %s" % anchor_name)
            if self.fontAnchors.getVisibility("anchor", anchor_name):
                glyphsToDraw = self.fontAnchors.getAnchoredGlyphNames(
                    anchor_name)
                # get translation for base anchor
                dbx = a.x
                dby = a.y
                save()
                for gn in glyphsToDraw:
                    if (anchor_name[0] != "_"
                            and self.fontAnchors.getVisibility(
                                "mark", gn,
                                False)) or (anchor_name[0] == "_"
                                            and self.fontAnchors.getVisibility(
                                                "glyph", gn, False)):
                        # get translation for current mark anchor
                        dmx, dmy = self.fontAnchors.anchorPositions[
                            gn,
                            self.fontAnchors.getMatchingAnchorName(anchor_name
                                                                   )]
                        x = dbx - dmx
                        y = dby - dmy
                        translate(x, y)
                        drawGlyph(self.fontAnchors.font[gn])
                        dbx = dmx
                        dby = dmy
                restore()
예제 #23
0
def drawReferenceGlyph(aGlyph,
                       scalingFactor,
                       startingX,
                       left=False,
                       right=False):
    dt.save()
    dt.fill(*BLACK)
    dt.stroke(None)
    dt.translate(startingX, 0)
    dt.scale(scalingFactor, scalingFactor)
    dt.translate(0, -aGlyph.getParent().info.descender)
    dt.translate(-aGlyph.width / 2, 0)
    dt.fill(*BLACK)
    dt.drawGlyph(aGlyph)

    descender = aGlyph.getParent().info.descender
    unitsPerEm = aGlyph.getParent().info.unitsPerEm
    baseTck = 40
    if left is True:
        dt.fill(*RED)
        dt.rect(0, -baseTck, aGlyph.leftMargin, baseTck)
        dt.rect(0, descender, 8, unitsPerEm)

    if right is True:
        dt.fill(*BLUE)
        dt.rect(aGlyph.width - aGlyph.rightMargin, -baseTck,
                aGlyph.rightMargin, baseTck)
        dt.rect(aGlyph.width, descender, 8, unitsPerEm)

    dt.restore()
    def drawBkgnd(self, info):
        # Draw the interpolated glyph outlines
        scale = info["scale"]
        ptSize = 7 * scale
        if self.interpolatedGlyph:
            # Draw the glyph outline
            pen = CocoaPen(None)
            self.interpolatedGlyph.draw(pen)
            dt.fill(r=None, g=None, b=None, a=1)
            dt.stroke(r=0, g=0, b=0, a=0.4)
            dt.strokeWidth(2 * scale)
            dt.save()
            dt.translate(self.currentGlyph.width)
            dt.drawPath(pen.path)
            dt.stroke(r=0, g=0, b=0, a=1)
            # Draw the points and handles
            for contour in self.interpolatedGlyph.contours:
                for bPoint in contour.bPoints:
                    inLoc = self.addPoints(bPoint.anchor, bPoint.bcpIn)
                    outLoc = self.addPoints(bPoint.anchor, bPoint.bcpOut)
                    dt.line(inLoc, bPoint.anchor)
                    dt.line(bPoint.anchor, outLoc)
                    dt.fill(r=1, g=1, b=1, a=1)
                    dt.oval(bPoint.anchor[0] - (ptSize * 0.5),
                            bPoint.anchor[1] - (ptSize * 0.5), ptSize, ptSize)
                    dt.fill(0)
                    # Draw an "X" over each BCP
                    if not bPoint.bcpIn == (0, 0):
                        dt.oval(inLoc[0] - (ptSize * 0.5),
                                inLoc[1] - (ptSize * 0.5), ptSize, ptSize)
                        #dt.line((inLoc[0]-(ptSize*0.5), inLoc[1]-(ptSize*0.5)), (inLoc[0]+(ptSize*0.5), inLoc[1]+(ptSize*0.5)))
                        #dt.line((inLoc[0]+(ptSize*0.5), inLoc[1]-(ptSize*0.5)), (inLoc[0]-(ptSize*0.5), inLoc[1]+(ptSize*0.5)))
                    if not bPoint.bcpOut == (0, 0):
                        dt.oval(outLoc[0] - (ptSize * 0.5),
                                outLoc[1] - (ptSize * 0.5), ptSize, ptSize)
                        #dt.line((outLoc[0]-(ptSize*0.5), outLoc[1]-(ptSize*0.5)), (outLoc[0]+(ptSize*0.5), outLoc[1]+(ptSize*0.5)))
                        #dt.line((outLoc[0]+(ptSize*0.5), outLoc[1]-(ptSize*0.5)), (outLoc[0]-(ptSize*0.5), outLoc[1]+(ptSize*0.5)))

            dt.restore()
예제 #25
0
    def draw(self):
        try:
            dt.save()
            dt.font(SYSTEM_FONT_NAME)
            dt.fontSize(CAPTION_BODY_SIZE)
            for indexGlyphName, eachGlyphName in enumerate(
                    self.glyphNamesToDisplay):

                # in this way it does not draw what's outside the canvas frame!
                if SPACING_COL_WIDTH * indexGlyphName > self.getPosSize()[2]:
                    continue

                self._drawMatrixColumn(eachGlyphName)
                dt.translate(SPACING_COL_WIDTH, 0)

                self._setBoxQualities()
                dt.line((0, 0), (0, self.getPosSize()[3]))

            dt.restore()

        except Exception, error:
            print traceback.format_exc()
예제 #26
0
    def draw(self):
        if not self.RCJKI.get("currentFont"): return
        if not self.glyph: return

        # self.glyph = self.RCJKI.currentFont[self.glyphName]

        # glyph = self.glyph.preview.computeCharacterGlyphPreview(self.glyph, {"WGHT":1})

        mjdt.save()
        scale = .15
        mjdt.scale(scale, scale)
        mjdt.translate(((200 - (self.glyph.width * scale)) / scale) * .5, 450)
        # for g in self.glyph.preview({}, forceRefresh=False):
        locationKey = ','.join(
            [k + ':' + str(v) for k, v in self.glyph.getLocation().items()])
        if locationKey in self.glyph.previewLocationsStore:
            for g in self.glyph.previewLocationsStore[locationKey]:
                # for g in self.glyph.preview({}, forceRefresh=False):
                mjdt.drawGlyph(g.glyph)
            mjdt.restore()
            # outlines, items, width = self.instantiateCharacterGlyph(self.glyph, {"WGHT":1})
            # print(outlines, items, width)

            # self.glyph = self.RCJKI.currentFont[self.glyphName]
            # d = self.glyph._glyphVariations
            # if self.glyph.type ==  "atomicElement":
            #     self.glyph.sourcesList = [
            #         {"Axis":axisName, "Layer":layer, "PreviewValue":layer.minValue} for axisName, layer in  d.items()
            #         ]
            # else:
            #     self.glyph.sourcesList = [
            #         {"Axis":axisName, "Layer":layerName, "PreviewValue":layerName.minValue} for axisName, layerName in  d.items()
            #         ]

            if self.glyph.markColor is not None:
                mjdt.fill(*self.glyph.markColor)
                mjdt.rect(0, 0, 200, 20)
예제 #27
0
    def drawRect_(self, rect):
        # draw here!

        if self.delegate.checked:
            AppKit.NSColor.selectedControlColor().set()
            selectionPath = AppKit.NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                AppKit.NSInsetRect(rect, 2, 2), 4, 4)
            AppKit.NSColor.selectedControlColor().colorWithAlphaComponent_(
                0.1).set()
            selectionPath.fill()
            AppKit.NSColor.selectedControlColor().set()
            selectionPath.stroke()

        frame_width, frame_height = self.frame().size
        w, h = [i - 2 * self._inset for i in self.frame().size]

        glyph_pair = self._glyphData
        glyph_l, glyph_r = glyph_pair
        font = glyph_l.getParent()
        upm = font.info.unitsPerEm
        scale_factor = h / (upm * 1.2)
        drawBot.translate(frame_width / 2, self._inset)
        drawBot.scale(scale_factor)

        drawBot.stroke(None)
        if self._kern_value <= 0:
            drawBot.fill(1, 0.3, 0.75)
        else:
            drawBot.fill(0, 0.8, 0)

        drawBot.rect(  # bottom rectangle
            0 - abs(self._kern_value) / 2, self._inset / scale_factor,
            abs(self._kern_value), 2 * self._inset / scale_factor)
        drawBot.rect(  # top rectangle
            0 - abs(self._kern_value) / 2, (h - self._inset) / scale_factor,
            abs(self._kern_value), 2 * self._inset / scale_factor)
        drawBot.translate(0, upm / 3)
        drawBot.translate(-glyph_l.width - self._kern_value / 2, 0)

        for glyph in glyph_pair:
            path = glyph.getRepresentation('defconAppKit.NSBezierPath')

            drawBot.stroke(None)
            drawBot.fill(0)
            drawBot.drawPath(path)
            drawBot.translate(glyph.width + self._kern_value, 0)
예제 #28
0
	def _drawGlyphs(self, info):
		""" draw stuff in the glyph window view """
		translateBefore = (0, 0)

		for glyphName in self.selectedGlyphNamesList:
			glyphToDraw = self.font[glyphName]

			# determine the offset of the anchors
			offset = self.getAnchorOffsets(self.glyph, glyphToDraw)

			# set the offset of the drawing
			translate(offset[0] - translateBefore[0], offset[1] - translateBefore[1])

			# record the shift amounts (these are needed for resetting the drawing position when more than one mark is selected on the list)
			translateBefore = offset

			# set the fill & stroke
			fill(0, 0, self.Blue, self.Alpha)
			strokeWidth(None)

			# draw it
			mojoPen = MojoDrawingToolsPen(glyphToDraw, self.font)
			glyphToDraw.draw(mojoPen)
			mojoPen.draw()
예제 #29
0
    def _drawGlyphCellArrow(self, num_errors):
        x = 3
        y = 3
        width = 2
        size = 7
        save()
        translate(4, 4)

        stroke(0.2)
        strokeWidth(0.5)
        lineJoin("miter")
        fill(0.9, 0.4, 0.3)
        rect(-1, -1, size + 1, size + 1)

        lineCap("butt")  # butt, square, round
        strokeWidth(width)
        stroke(1, 0.9, 0.65)
        line((0, width / 2 - 0.5), (size - width / 2 + 0.5, width / 2 - 0.5))
        line((width / 2 - 0.5, width / 2 - 1.5),
             (width / 2 - 0.5, size - width / 2 + 0.5))
        lineCap("round")
        line((width // 2, width // 2), (size - 1.5, size - 1.5))

        restore()
예제 #30
0
    def drawRect_(self, rect):
        # draw here!
        frame_width, frame_height = self.frame().size
        w, h = [i - 2 * self._inset for i in self.frame().size]
        drawBot.fill(None)
        drawBot.rect(self._inset, self._inset, w, h)
        drawBot.stroke(0)
        drawBot.strokeWidth(1)

        glyph_pair = self._glyphData
        glyph_l, glyph_r = glyph_pair
        font = glyph_l.getParent()
        upm = font.info.unitsPerEm
        scale_factor = h / (upm * 1.2)
        drawBot.translate(frame_width / 2, self._inset)
        drawBot.scale(scale_factor)

        drawBot.stroke(None)
        if self._kern_value <= 0:
            drawBot.fill(1, 0.3, 0.75)
        else:
            drawBot.fill(0, 0.8, 0)
            # drawBot.fill(0.4, 1, 0.8)
        drawBot.rect(
            0 - abs(self._kern_value) / 2, 0,
            abs(self._kern_value), h * 1 / scale_factor)

        drawBot.translate(0, upm / 3)
        drawBot.translate(-glyph_l.width - self._kern_value / 2, 0)

        for glyph in glyph_pair:
            path = glyph.getRepresentation('defconAppKit.NSBezierPath')

            drawBot.stroke(None)
            # drawBot.fill(0, 1, 0)
            drawBot.fill(0)
            drawBot.drawPath(path)
            drawBot.translate(glyph.width + self._kern_value, 0)
예제 #31
0
    def _drawMetricsData(self, glyphName, offset):
        dt.save()
        glyphToDisplay = self.fontObj[glyphName]
        dt.translate(0, self.fontObj.info.descender)
        reverseScalingFactor = 1 / (
            self.ctrlHeight /
            (self.canvasScalingFactor * self.fontObj.info.unitsPerEm))

        if self.isSidebearingsActive is True:
            dt.fill(None)
            dt.stroke(*BLACK)
            dt.strokeWidth(reverseScalingFactor)
            dt.line((0, 0), (0, -offset * reverseScalingFactor))
            dt.line((glyphToDisplay.width, 0),
                    (glyphToDisplay.width, -offset * reverseScalingFactor))
        dt.restore()

        dt.save()
        dt.translate(0, self.fontObj.info.descender)
        dt.translate(0, -offset * reverseScalingFactor)
        dt.fill(*BLACK)

        dt.stroke(None)
        dt.font(SYSTEM_FONT_NAME)
        dt.fontSize(BODY_SIZE * reverseScalingFactor)

        textWidth, textHeight = dt.textSize(u'{}'.format(glyphToDisplay.width))
        dt.textBox(u'{:d}'.format(int(glyphToDisplay.width)),
                   (0, 0, glyphToDisplay.width, textHeight * 2),
                   align='center')
        dt.textBox(u'\n{:d}'.format(int(glyphToDisplay.leftMargin)),
                   (0, 0, glyphToDisplay.width / 2., textHeight * 2),
                   align='center')
        dt.textBox(u'\n{:d}'.format(int(glyphToDisplay.rightMargin)),
                   (glyphToDisplay.width / 2., 0, glyphToDisplay.width / 2.,
                    textHeight * 2),
                   align='center')
        dt.restore()
    def draw(self):
        w = self.w.c.width()
        h = self.w.c.height()
        m = 130
        center = w * .5, h * .5
        d = self.dotSize
        r = min(.5 * (h - 2 * m), .5 * (w - 2 * m))
        if self.pointer is None:
            self.pointer = center

        a1 = self.orientation * math.pi
        a2 = a1 + 2 / 3 * math.pi
        a3 = a1 - 2 / 3 * math.pi
        self.p1 = p1 = center[0] + (r * math.sin(a1)), center[1] + (
            r * math.cos(a1))
        self.p2 = p2 = center[0] + (r * math.sin(a2)), center[1] + (
            r * math.cos(a2))
        self.p3 = p3 = center[0] + (r * math.sin(a3)), center[1] + (
            r * math.cos(a3))

        self.snapped = None
        if self.closeToPoint(self.p1, self.pointer):
            self.pointer = self.p1
            self.snapped = 0
        if self.closeToPoint(self.p2, self.pointer):
            self.pointer = self.p2
            self.snapped = 1
        if self.closeToPoint(self.p3, self.pointer):
            self.pointer = self.p3
            self.snapped = 2

        p1d = p1[0] - .5 * d, p1[1] - .5 * d, d, d
        p2d = p2[0] - .5 * d, p2[1] - .5 * d, d, d
        p3d = p3[0] - .5 * d, p3[1] - .5 * d, d, d

        ctx.save()
        ctx.stroke(.8, .8, .7)
        ctx.strokeWidth(.4)
        ctx.strokeWidth(.8)
        ctx.line(p1, p2)
        ctx.line(p2, p3)
        ctx.line(p3, p1)

        if self.pointer is not None:
            ctx.line(p1, self.pointer)
            ctx.line(p2, self.pointer)
            ctx.line(p3, self.pointer)

        ctx.stroke(None)
        ctx.fill(0)
        ctx.oval(*p1d)
        ctx.oval(*p2d)
        ctx.oval(*p3d)

        g1, g2, g3 = self.glyphs
        if g1 is not None:
            ctx.save()
            ctx.translate(p1[0], p1[1])
            ctx.scale(self.glyphScale)
            ctx.translate(100, 0)
            ctx.drawGlyph(g1)
            ctx.restore()
        if g2 is not None:
            ctx.save()
            ctx.translate(p2[0], p2[1])
            ctx.scale(self.glyphScale)
            ctx.translate(100, 0)
            ctx.drawGlyph(g2)
            ctx.restore()
        if g3 is not None:
            ctx.save()
            ctx.translate(p3[0], p3[1])
            ctx.scale(self.glyphScale)
            ctx.translate(100, 0)
            ctx.drawGlyph(g3)
            ctx.restore()

        if self.pointer:
            ctx.save()
            ctx.fill(1, 0, 0)
            ctx.stroke(None)
            d = 10
            ctx.oval(self.pointer[0] - .5 * d, self.pointer[1] - .5 * d, d, d)

            f1, f2, f3 = ip(p1, p2, p3, self.pointer)
            self._factors = f1, f2, f3
            r = None
            if self.mGlyphs is not None:
                if None not in self.mGlyphs:
                    try:
                        self.result = r = f1 * self.mGlyphs[
                            0] + f2 * self.mGlyphs[1] + f3 * self.mGlyphs[2]
                    except IndexError or TypeError:
                        print("Sorry, these glyphs can't interpolate..")
                    if r:
                        ctx.save()
                        ctx.translate(self.pointer[0], self.pointer[1])
                        ctx.scale(self.glyphScale)
                        ctx.translate(100, 0)
                        g = RGlyph()
                        g.fromMathGlyph(r)
                        ctx.drawGlyph(g)

                        t = "{:02.2f}, {:02.2f}, {:02.2f}".format(f1, f2, f3)
                        ctx.font("Menlo-Regular")
                        ctx.fontSize(6 / self.glyphScale)
                        ctx.text(t, (0, -200))
                        ctx.restore()
            ctx.restore()
        ctx.restore()
예제 #33
0
 def draw(self, info):
     
     if not self._drawing:
         return
         
     glyph = info.get("glyph")
     drawingScale = info.get('scale')
     
     if glyph is None:
         return
         
     current = glyph.getParent()
     fonts = self.getActiveFonts()
     
     for font in fonts:
         
         nakedFont = font.naked()
         
         contextLeft, contextCurrent, contextRight = self.getContexts()
         contextLeft = splitText(contextLeft or '', nakedFont.unicodeData or '')
         contextLeft = [font[gname] for gname in contextLeft if gname in font.keys()]
         contextRight = splitText(contextRight or '', nakedFont.unicodeData or '')
         contextRight = [font[gname] for gname in contextRight if gname in font.keys()]
         contextCurrent = splitText(contextCurrent or '', nakedFont.unicodeData or '')
         if len(contextCurrent) > 0:
             contextCurrent = [font[gname] for gname in [contextCurrent[0]] if gname in font.keys()]
             if len(contextCurrent) > 0:
                 sourceGlyph = contextCurrent[0]
             else:
                 sourceGlyph = None
         elif glyph.name in font.keys():
             sourceGlyph = font[glyph.name]
             contextCurrent = [sourceGlyph]
         else:
             sourceGlyph = None
             contextCurrent = []
         
         save()
         
         self._fillColor.setFill()
         self._strokeColor.setStroke()
         scale(current.info.unitsPerEm/float(font.info.unitsPerEm))
         
         # Draw left context
         previousGlyph = sourceGlyph
         contextLeft.reverse()
         totalWidth = 0
         for i, cbGlyph in enumerate(contextLeft):
             kernValue = self.getKernValue(nakedFont, cbGlyph, previousGlyph) # right to left
             translate(-cbGlyph.width-kernValue, 0)
             totalWidth += cbGlyph.width + kernValue
             glyphBezierPath = cbGlyph.naked().getRepresentation("defconAppKit.NSBezierPath")
             if self._fill:
                 glyphBezierPath.fill()
             if self._stroke:
                 glyphBezierPath.setLineWidth_(self._strokeWidth*drawingScale)
                 strokePixelPath(glyphBezierPath)
             previousGlyph = cbGlyph
         translate(totalWidth, 0)
         
         # Draw current context or current glyph 
         if contextCurrent:
             previousGlyph = None
             alignment = self.getAlignment()
             if alignment == 'left':
                 offset = 0
             elif alignment == 'center':
                 offset = (glyph.width - contextCurrent[0].width)/2                                        
             elif alignment == 'right':
                 offset = glyph.width - contextCurrent[0].width                                     
             totalWidth = offset
             translate(totalWidth, 0)
         
         for i, cbGlyph in enumerate(contextCurrent):
             #if cbGlyph == glyph:
             #    continue # Don't show if is current glyph
             kernValue = self.getKernValue(nakedFont, previousGlyph, cbGlyph)
             translate(kernValue, 0)
             glyphBezierPath = cbGlyph.naked().getRepresentation("defconAppKit.NSBezierPath")
             if self._fill:
                 glyphBezierPath.fill()
             if self._stroke:
                 glyphBezierPath.setLineWidth_(self._strokeWidth*drawingScale)
                 strokePixelPath(glyphBezierPath)
             if self._points:
                 self.drawPoints(cbGlyph, info['scale'])
             translate(cbGlyph.width, 0)
             totalWidth += cbGlyph.width + kernValue
             previousGlyph = cbGlyph
         translate(-totalWidth, 0)
         
         # Draw right context
         translate(glyph.width)
         totalWidth = glyph.width
         for i, cbGlyph in enumerate(contextRight):
             kernValue = self.getKernValue(nakedFont, previousGlyph, cbGlyph)
             translate(kernValue, 0)
             glyphBezierPath = cbGlyph.naked().getRepresentation("defconAppKit.NSBezierPath")
             if self._fill:
                 glyphBezierPath.fill()
             if self._stroke:
                 glyphBezierPath.setLineWidth_(self._strokeWidth*drawingScale)
                 strokePixelPath(glyphBezierPath)
             translate(cbGlyph.width, 0)
             totalWidth += cbGlyph.width + kernValue
             previousGlyph = cbGlyph
             
         restore()
예제 #34
0
    def _drawMatrixColumn(self, glyphName):
        dt.save()

        # definitive
        dt.translate(
            0,
            self.getPosSize()[3] - vanillaControlsSize['EditTextSmallHeight'])

        # top
        dt.fill(*BLACK)
        dt.stroke(None)

        textWidth, textHeight = dt.textSize(glyphName)
        self._setTypeQualities(BLACK)
        dt.text(glyphName,
                (SPACING_COL_WIDTH / 2. - textWidth / 2., BASELINE_CORRECTION))
        dt.translate(0, -vanillaControlsSize['EditTextSmallHeight'])

        # metrics
        for eachFont in self.fontsOrder:
            try:
                eachGlyph = eachFont[glyphName]
            except Exception, error:
                continue

            if eachGlyph == self.lineViewSelectedGlyph:
                color = RED
            else:
                color = BLACK

            # line over glyph width
            self._setBoxQualities()
            dt.line((0, vanillaControlsSize['EditTextSmallHeight']),
                    (SPACING_COL_WIDTH,
                     vanillaControlsSize['EditTextSmallHeight']))

            widthString = '{:d}'.format(int(round(eachGlyph.width, 0)))
            textWidth, textHeight = dt.textSize(widthString)
            self._setTypeQualities(color)
            dt.text(
                widthString,
                (SPACING_COL_WIDTH / 2. - textWidth / 2., BASELINE_CORRECTION))

            # line over sidebearings
            self._setBoxQualities()
            dt.line((0, 0), (SPACING_COL_WIDTH, 0))
            dt.translate(0, -vanillaControlsSize['EditTextSmallHeight'])

            leftMarginString = '{:d}'.format(
                int(round(eachGlyph.leftMargin, 0)))
            textWidth, textHeight = dt.textSize(leftMarginString)
            self._setTypeQualities(color)
            dt.text(
                leftMarginString,
                (SPACING_COL_WIDTH / 4. - textWidth / 2., BASELINE_CORRECTION))

            self._setBoxQualities()
            dt.line((SPACING_COL_WIDTH / 2., 0),
                    (SPACING_COL_WIDTH / 2.,
                     vanillaControlsSize['EditTextSmallHeight']))

            rightMarginString = '{:d}'.format(
                int(round(eachGlyph.rightMargin, 0)))
            textWidth, textHeight = dt.textSize(rightMarginString)
            self._setTypeQualities(color)
            dt.text(rightMarginString,
                    (SPACING_COL_WIDTH * 3 / 4. - textWidth / 2.,
                     BASELINE_CORRECTION))

            dt.translate(0, -vanillaControlsSize['EditTextSmallHeight'])