示例#1
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()
示例#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 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()
示例#4
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()
    def spaceCenterDrawObserver(self, notification):

        glyph = notification['glyph']
        scale = notification['scale']

        lockStatus = self.getLockStatus(glyph)
        if not lockStatus:  # is None:
            return

        lockStatusIcon = '🔒' if lockStatus else '🔓'  # 'L' if lockStatus else 'U'
        ctx.save()
        ctx.scale(1, -1)
        ctx.fontSize(120)
        ctx.text(lockStatusIcon, (glyph.width - 100, 30))
        ctx.restore()
示例#6
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)
示例#7
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()
示例#8
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()
示例#9
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()
示例#10
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)
示例#11
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)
示例#12
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()
    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()
示例#14
0
    def draw(self):

        try:
            glyphsToDisplay = splitText(self.displayedWord,
                                        self.fontObj.naked().unicodeData)

            # if the user switches the glyphs from the groups
            # here we have to arrange the list of glyphnames properly
            if self.activePair is not None:
                lftName, rgtName = self.activePair
                glyphsToDisplay[self.indexPair] = lftName
                glyphsToDisplay[self.indexPair + 1] = rgtName

            # here we draw
            dt.save()

            # this is for safety reason, user should be notified about possible unwanted kerning corrections
            if self.isSwappedEditingOn is True:
                dt.save()
                dt.fill(*FLIPPED_BACKGROUND_COLOR)
                dt.rect(0, 0, self.ctrlWidth, self.ctrlHeight)
                dt.restore()

            if self.isSymmetricalEditingOn is True:
                dt.save()
                dt.fill(*SYMMETRICAL_BACKGROUND_COLOR)
                dt.rect(0, 0, self.ctrlWidth, self.ctrlHeight)
                dt.restore()

            dt.scale(
                self.ctrlHeight /
                (self.canvasScalingFactor * self.fontObj.info.unitsPerEm)
            )  # the canvas is virtually scaled according to self.canvasScalingFactor value and canvasSize
            dt.translate(TEXT_MARGIN, 0)

            # group glyphs
            dt.translate(0, 600)

            if self.areGroupsShown is True:
                dt.save()
                prevGlyphName = None
                for indexChar, eachGlyphName in enumerate(glyphsToDisplay):
                    eachGlyph = self.fontObj[eachGlyphName]

                    # this is for kerning
                    if indexChar > 0:
                        correction, kerningReference, pairKind = getCorrection(
                            (prevGlyphName, eachGlyphName), self.fontObj)

                        if kerningReference:
                            exceptionStatus, doesExists, exceptionParents = isPairException(
                                kerningReference, self.fontObj)
                            if exceptionStatus is True:
                                self._drawException(
                                    (prevGlyphName, eachGlyphName), correction)

                        if (indexChar - 1) == self.indexPair:
                            if correction is None:
                                offsetCorrection = 0
                            else:
                                offsetCorrection = correction
                            self._drawGlyphOutlinesFromGroups(
                                (prevGlyphName, eachGlyphName),
                                kerningReference, offsetCorrection)

                        if correction and correction != 0 and self.isKerningDisplayActive:
                            dt.translate(correction, 0)

                    dt.translate(eachGlyph.width, 0)
                    prevGlyphName = eachGlyphName
                dt.restore()

            # background loop
            dt.save()
            glyphsToDisplayTotalWidth = 0
            prevGlyphName = None
            for indexChar, eachGlyphName in enumerate(glyphsToDisplay):
                eachGlyph = self.fontObj[eachGlyphName]

                # this is for kerning
                if indexChar > 0:
                    correction, kerningReference, pairKind = getCorrection(
                        (prevGlyphName, eachGlyphName), self.fontObj)
                    if self.isKerningDisplayActive and correction is not None:
                        if correction != 0 and self.isColorsActive is True:
                            self._drawColoredCorrection(correction)

                        if self.isCorrectionActive is True:
                            self._drawMetricsCorrection(correction)

                        dt.translate(correction, 0)
                        glyphsToDisplayTotalWidth += correction

                    if (indexChar - 1) == self.indexPair:
                        if correction is None:
                            offsetCorrection = 0
                        else:
                            offsetCorrection = correction
                        self._drawCursor(offsetCorrection, pairKind)

                # # draw metrics info
                if self.isMetricsActive is True:
                    self._drawMetricsData(eachGlyphName, 52)

                if self.isSidebearingsActive is True:
                    self._drawBaseline(eachGlyphName)
                    self._drawSidebearings(eachGlyphName)

                dt.translate(eachGlyph.width, 0)
                glyphsToDisplayTotalWidth += eachGlyph.width
                prevGlyphName = eachGlyphName
            dt.restore()

            # foreground loop
            dt.save()
            prevGlyphName = None
            for indexChar, eachGlyphName in enumerate(glyphsToDisplay):
                eachGlyph = self.fontObj[eachGlyphName]

                # this is for kerning
                if indexChar > 0:
                    correction, kerningReference, pairKind = getCorrection(
                        (prevGlyphName, eachGlyphName), self.fontObj)

                    if correction and correction != 0 and self.isKerningDisplayActive:
                        dt.translate(correction, 0)

                self._drawGlyphOutlines(eachGlyphName)
                dt.translate(eachGlyph.width, 0)

                prevGlyphName = eachGlyphName
            dt.restore()

            # collisions loop
            if self.areCollisionsShown is True:
                dt.save()
                prevGlyphName = None
                for indexChar, eachGlyphName in enumerate(glyphsToDisplay):
                    eachGlyph = self.fontObj[eachGlyphName]

                    if indexChar > 0:
                        correction, kerningReference, pairKind = getCorrection(
                            (prevGlyphName, eachGlyphName), self.fontObj)
                        if correction and correction != 0 and self.isKerningDisplayActive:
                            dt.translate(correction, 0)

                        if (indexChar - 1) == self.indexPair:
                            self._drawCollisions(
                                (prevGlyphName, eachGlyphName))

                    dt.translate(eachGlyph.width, 0)
                    prevGlyphName = eachGlyphName

                dt.restore()

            # main restore, it wraps the three loops
            dt.restore()

            if self.areVerticalLettersDrawn is True:
                # separate from the rest, we put the vertical letters
                dt.save()
                # we push the matrix forward
                dt.translate(self.ctrlWidth, 0)
                # then we rotate
                dt.rotate(90)
                # then we scale, but how much? a quarter of the main lettering
                dt.scale(
                    self.ctrlHeight /
                    (self.canvasScalingFactor * self.fontObj.info.unitsPerEm) *
                    .25)
                # the reference is the baseline, so we have to put some air below the letters
                dt.translate(0, 600)  # upm value
                # let's define the graphics
                dt.fill(*BLACK)
                dt.stroke(None)
                # then we draw, we need a prevGlyphName in order to get kerning correction
                prevGlyphName = None
                # we iterate on the letters we need to draw + a space as a margin
                for indexChar, eachGlyphName in enumerate(['space'] +
                                                          glyphsToDisplay):
                    # accessing the glyph obj
                    eachGlyph = self.fontObj[eachGlyphName]
                    # if it isn't the first letter...
                    if indexChar > 0:
                        # ... we grab the kerning correction from the pair
                        correction, kerningReference, pairKind = getCorrection(
                            (prevGlyphName, eachGlyphName), self.fontObj)
                        # if there is any correction...
                        if correction and correction != 0 and self.isKerningDisplayActive:
                            # ... we apply it to the transformation matrix
                            dt.translate(correction, 0)
                    # then we draw the outlines
                    self._drawGlyphOutlines(eachGlyphName)
                    # and we move the transformation matrix according to glyph width
                    dt.translate(eachGlyph.width, 0)
                    # then we load the glyph to the prevGlyphName
                    prevGlyphName = eachGlyphName
                # restoring the vertical drawing
                dt.restore()

        except Exception:
            print traceback.format_exc()
示例#15
0
    def draw(self, info, customColor=None, refGlyph=None, onlyPreview=False):
        view = info["view"]
        scale = info['scale']
        color = customColor
        # if self.RCJKI.currentGlyph.preview.variationPreview:
        if info["notificationName"] == "draw":
            previewColor = [(0, 0, 0, 0), (0, 0, 0, .7)][onlyPreview]
            previewStrokeColor = [(0, 0, 0, .2), (0, 0, 0, 0)][onlyPreview]
        else:
            previewColor = [(0, 0, 0, 0), (0, 0, 0, 1)][onlyPreview]
            previewStrokeColor = [(0, 0, 0, .2), (0, 0, 0, 0)][onlyPreview]

        self.drawVariationPreview(self.RCJKI.currentGlyph,
                                  scale,
                                  color=previewColor,
                                  strokecolor=previewStrokeColor)

        # if not onlyPreview:
        #     mjdt.save()
        #     locker = self.RCJKI.currentFont.glyphLockedBy(self.RCJKI.currentGlyph)
        #     if locker != self.RCJKI.currentFont.lockerUserName:
        #         mjdt.fill(1, 0, 0, .1)
        #         mjdt.rect(0, -2000, self.RCJKI.currentFont.defaultGlyphWidth, 10000)
        #         mjdt.fill(1, 0, 0, 1)
        #         mjdt.font("Helvetica")
        #         mjdt.fontSize(40)
        #         mjdt.textBox(f"Already locked by {locker}", (0, 900, 1000, 100), align = 'center')
        #     mjdt.restore()

        if self.RCJKI.currentGlyph.type == "atomicElement": return

        if self.refGlyph is not None:
            mjdt.save()
            mjdt.fill(0, 0, 0, .2)
            mjdt.translate(*self.refGlyphPos)
            mjdt.scale(*self.refGlyphScale)
            mjdt.drawGlyph(self.roundGlyph(self.refGlyph))
            mjdt.restore()

        if self.existingInstance is not None:
            mjdt.save()
            mjdt.fill(1, .8, 0, .8)
            mjdt.translate(*self.existingInstancePos)
            mjdt.scale(*self.existingInstanceScale)
            for c in self.existingInstance:
                mjdt.drawGlyph(self.roundGlyph(c))
            mjdt.restore()

        if onlyPreview: return
        if self.RCJKI.currentGlyph.type == "deepComponent":
            if not color:
                if not self.RCJKI.currentGlyph.selectedSourceAxis:
                    color = (0, .5, .25, .4)
                else:
                    color = (.5, .25, 0, .2)

        elif self.RCJKI.currentGlyph.type == "characterGlyph":
            if not color:
                if not self.RCJKI.currentGlyph.selectedSourceAxis:
                    color = (.25, 0, .5, .8)
                else:
                    color = (.5, 0, .25, .4)

        self.drawAxisPreview(self.RCJKI.currentGlyph, color, scale,
                             customColor, view)