Beispiel #1
0
 def _drawGlyphOutlines(self, glyphName):
     dt.save()
     dt.fill(*BLACK)
     dt.stroke(None)
     glyphToDisplay = self.fontObj[glyphName]
     dt.drawGlyph(glyphToDisplay)
     dt.restore()
	def draw(self, info):
		if not self.calculatePreview:
			return
		cur = CurrentGlyph()
		if cur == None:
			return;

		scale = info['scale']
		layerToConvert = self.layers[self.w.layerPopup.get()]
		otherLayer = layerToConvert != 'foreground'
		if (not otherLayer) and (CurrentFont().lib['com.typemytype.robofont.segmentType'] == 'qcurve'):
			return
		if otherLayer: cur.flipLayers('foreground', layerToConvert)
		copy = cur.copy()
		if otherLayer: cur.flipLayers('foreground', layerToConvert)
		convert(copy, self.maxDistanceValue, self.minLengthValue, self.useArcLength)

		for c in copy:
			for p in c.points:
				if p.type == 'offCurve':
					color = OffColor
					r = 4*scale
				else:
					color = OnColor
					r = 6*scale
				self.drawDiscAtPoint(r, p.x, p.y, color)
		save()
		stroke(0.2, .8, .8, 1)
		fill(None)
		strokeWidth(scale)
		drawGlyph(copy)
		restore()
 def _curvePreview(self, info):
     _doodle_glyph = info["glyph"]
     if CurrentGlyph() is not None and _doodle_glyph is not None and len(_doodle_glyph.components) == 0 and _doodle_glyph.selection != []:
         ########
         # Here's how this works: if there is a current glyph, and that glyph has a selection, we get here
         # then there is a temp glyph, in memory. Every "draw", this is called, it clears the glyph
         # and then draws the current glyph in its place, then equilizes that glyph in a different
         # method, then draws it into this view.
         # The problem is the outline is not updating. If you commit the change it shows up, but this memory
         # glyph isn't getting redrawn ever. The glyph is redrawing the same thing over and over.
         #######
         self.tmp_glyph.clear()
         self.tmp_glyph.appendGlyph(_doodle_glyph)
         # I think what needs to happen here is instead of this mysterious function happening, 
         # it needs to return an equilized glyph object that is then drawn onto the view
         # instead of maintaining a virtual copy that needs to be cleared and updated each draw
         # more like tmp_glyph = self._equalized_glyph(_doodle_glyph); drawGlyph(tmp_glyph)
         # vvvvvvvvvvvvvvvv
         self._eqSelected()
         # ^^^^^^^^^^^^^^^^^
         self.tmp_glyph.update()
         save()
         stroke(random(), random(), random(), 1.0)
         # stroke(0, 0, 0, 0.5)
         #if self.method == "hobby":
         #    fill(1, 0, 0, 0.9)
         #else:
         fill(None)
         strokeWidth(info["scale"])
         drawGlyph(self.tmp_glyph)
         restore()
Beispiel #4
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()
Beispiel #5
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()
Beispiel #6
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)
Beispiel #7
0
    def draw(self, info):
        if not self.calculatePreview:
            return
        cur = CurrentGlyph()
        if cur == None:
            return

        scale = info['scale']
        layerToConvert = self.layers[self.w.layerPopup.get()]
        otherLayer = layerToConvert != 'foreground'
        if (not otherLayer) and (
                CurrentFont().lib['com.typemytype.robofont.segmentType']
                == 'qcurve'):
            return
        if otherLayer: cur.flipLayers('foreground', layerToConvert)
        copy = cur.copy()
        if otherLayer: cur.flipLayers('foreground', layerToConvert)
        convert(copy, self.maxDistanceValue, self.minLengthValue,
                self.useArcLength)

        for c in copy:
            for p in c.points:
                if p.type == 'offCurve':
                    color = OffColor
                    r = 4 * scale
                else:
                    color = OnColor
                    r = 6 * scale
                self.drawDiscAtPoint(r, p.x, p.y, color)
        save()
        stroke(0.2, .8, .8, 1)
        fill(None)
        strokeWidth(scale)
        drawGlyph(copy)
        restore()
    def _curvePreview(self, info):
        _doodle_glyph = info["glyph"]

        if roboFontVersion > "3.1":
            _doodle_glyph_selected_points = _doodle_glyph.selectedPoints
        else:
            _doodle_glyph_selected_points = _doodle_glyph.selection

        if CurrentGlyph() is not None \
            and _doodle_glyph is not None \
            and len(_doodle_glyph.components) == 0 \
            and _doodle_glyph_selected_points != []:
            self.tmp_glyph = CurrentGlyph().copy()
            self._eqSelected()
            if self.previewCurves:
                save()
                stroke(0, 0, 0, 0.5)
                fill(None)
                strokeWidth(info["scale"])
                drawGlyph(self.tmp_glyph)
                restore()
            if self.drawGeometry:
                self._drawGeometry(info)
            if self.previewHandles:
                self._handlesPreview(info)
Beispiel #9
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()
Beispiel #10
0
 def drawDiffGlyph(self, info):
     g = info["glyph"]
     if g is not None:
         if g.name in self.headGlyphs:
             save()
             strokeWidth(None)
             fill(1,0,0,0.2)
             drawGlyph(self.headGlyphs[g.name])
             restore()
Beispiel #11
0
 def drawVariationPreview(self, glyph, scale, color, strokecolor):
     mjdt.save()
     mjdt.fill(*color)
     mjdt.stroke(*strokecolor)
     mjdt.strokeWidth(scale)
     loc = {}
     if glyph.sourcesList:
         loc = {x["Axis"]: x["PreviewValue"] for x in glyph.sourcesList}
     for g in glyph.preview(loc, forceRefresh=False):
         # for g in glyph.previewGlyph:
         mjdt.drawGlyph(self.roundGlyph(g.glyph))
     mjdt.restore()
Beispiel #12
0
    def draw(self, info):
        self.w.pointSize.set(self.w.multiLineView.getPointSize())
        glyph = self.RCJKI.currentFont[info["glyph"].name]#, self.RCJKI.currentFont._RFont)
        scale = info["scale"]
        sourcesList = {x["Axis"]:x["PreviewValue"] for x in self.sourcesList}

        mjdt.save()
        mjdt.fill(0, 0, 0, 1)
        mjdt.stroke(0, 0, 0, 0)
        mjdt.strokeWidth(scale)
        for c in glyph.preview(sourcesList, forceRefresh=True):
            mjdt.drawGlyph(c.glyph)
        mjdt.restore()
Beispiel #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()
Beispiel #14
0
 def _curvePreview(self, info):
     _doodle_glyph = info["glyph"]
     if _doodle_glyph is not None and len(_doodle_glyph.components) == 0 and _doodle_glyph.selection != []:
         self.tmp_glyph.clear()
         self.tmp_glyph.appendGlyph(_doodle_glyph)
         self._eqSelected()
         save()
         stroke(0, 0, 0, 0.5)
         #if self.method == "hobby":
         #    fill(1, 0, 0, 0.9)
         #else:
         fill(None)
         strokeWidth(info["scale"])
         drawGlyph(self.tmp_glyph)
         restore()
    def spaceCenterDraw(self, notification):
        glyph = notification["glyph"]
        attrValues = self.getAttributes()
        outGlyph = self.getGlyph(glyph, *attrValues)

        box = glyph.box
        if box:
            x, y, maxx, maxy = box
            w = maxx - x
            h = maxy - y
            drawingTools.fill(1)  
            offset = 10      
            drawingTools.rect(x-offset, y-offset, w+offset*2, h+offset*2)
            
        drawingTools.fill(0)
        drawingTools.drawGlyph(outGlyph)
Beispiel #16
0
 def _curvePreview(self, info):
     _doodle_glyph = info["glyph"]
     if _doodle_glyph is not None and len(
             _doodle_glyph.components
     ) == 0 and _doodle_glyph.selection != []:
         self.tmp_glyph.clear()
         self.tmp_glyph.appendGlyph(_doodle_glyph)
         self._eqSelected()
         save()
         stroke(0, 0, 0, 0.5)
         #if self.method == "hobby":
         #    fill(1, 0, 0, 0.9)
         #else:
         fill(None)
         strokeWidth(info["scale"])
         drawGlyph(self.tmp_glyph)
         restore()
Beispiel #17
0
 def _observer_draw_glyph_window(self, info):
     # draw the color glyph in the glyph window
     # print("DEBUG: _observer_draw_glyph_window")
     if self.glyphPreview in self.cfont.keys():
         # print("DEBUG: draw glyph")
         save()
         self.setFill(self.color)
         for i in range(len(self.layer_glyphs_glyph_window)):
             layerGlyph = self.layer_glyphs_glyph_window[i]
             if layerGlyph in self.font:
                 if i < len(self.layer_colors_glyph_window):
                     _color = self.layer_colors_glyph_window[i]
                     self.setFill(_color)
                     drawGlyph(self.font[layerGlyph])
         restore()
     if self._debug_enable_live_editing:
         self.w.preview.update()
Beispiel #18
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()
    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()
    def spaceCenterDraw(self, notification):
        glyph = notification["glyph"]
        spaceCenter = notification["spaceCenter"]
        scale = notification["scale"]

        attrValues = self.getAttributes()
        outGlyph = self.getGlyph(glyph, *attrValues)

        inverse = spaceCenter.glyphLineView.getDisplayStates()['Inverse']
        foreground = tuple(getDefault('spaceCenterGlyphColor')) if not inverse else tuple(getDefault('spaceCenterBackgroundColor'))
        background = tuple(getDefault('spaceCenterBackgroundColor')) if not inverse else tuple(getDefault('spaceCenterGlyphColor')) 

        # cover current glyph
        drawingTools.fill(*background)
        drawingTools.stroke(*background)
        drawingTools.strokeWidth(2*scale)
        drawingTools.drawGlyph(glyph)
        drawingTools.stroke(None)

        # draw glyph preview
        drawingTools.fill(*foreground)
        drawingTools.drawGlyph(outGlyph)
    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)
Beispiel #22
0
    def _drawGlyphOutlinesFromGroups(self, aPair, kerningReference,
                                     correction):
        prevGlyphName, eachGlyphName = aPair
        if kerningReference is not None:
            lftReference, rgtReference = kerningReference
        else:
            lftReference = whichGroup(prevGlyphName, 'left', self.fontObj)
            rgtReference = whichGroup(eachGlyphName, 'right', self.fontObj)

        prevGlyph, eachGlyph = self.fontObj[prevGlyphName], self.fontObj[
            eachGlyphName]
        reverseScalingFactor = 1 / (
            self.ctrlHeight /
            (self.canvasScalingFactor * self.fontObj.info.unitsPerEm))

        # _L__ group
        if lftReference:
            if lftReference.startswith('@MMK_L_'):
                dt.save()
                dt.fill(*LAYERED_GLYPHS_COLOR)
                groupContent = self.fontObj.groups[lftReference]
                if len(groupContent) > 1:
                    for eachGroupSibling in groupContent:
                        if eachGroupSibling != prevGlyphName:
                            glyphToDisplay = self.fontObj[eachGroupSibling]
                            dt.save()
                            dt.translate(
                                -glyphToDisplay.width, 0
                            )  # back, according to his width, otherwise it does not coincide
                            dt.drawGlyph(glyphToDisplay)
                            dt.restore()

                dt.fill(*BLACK)  # caption
                dt.translate(-prevGlyph.width,
                             0)  # we need a caption in the right place
                dt.font(SYSTEM_FONT_NAME)
                dt.fontSize(GROUP_NAME_BODY_SIZE * reverseScalingFactor)
                textWidth, textHeight = dt.textSize(lftReference)
                dt.text(lftReference,
                        (glyphToDisplay.width / 2. - textWidth / 2.,
                         -GROUP_NAME_BODY_SIZE * reverseScalingFactor * 2))
                dt.restore()

        # _R__ group
        if rgtReference:
            if rgtReference.startswith('@MMK_R_'):
                dt.save()
                dt.translate(correction, 0)
                dt.fill(*LAYERED_GLYPHS_COLOR)
                groupContent = self.fontObj.groups[rgtReference]

                if len(groupContent) > 1:
                    for eachGroupSibling in groupContent:
                        if eachGroupSibling != eachGlyphName:
                            glyphToDisplay = self.fontObj[eachGroupSibling]
                            dt.drawGlyph(glyphToDisplay)

                dt.fill(*BLACK)
                dt.font(SYSTEM_FONT_NAME)
                dt.fontSize(GROUP_NAME_BODY_SIZE * reverseScalingFactor)
                textWidth, textHeight = dt.textSize(rgtReference)
                dt.text(rgtReference,
                        (glyphToDisplay.width / 2. - textWidth / 2.,
                         -GROUP_NAME_BODY_SIZE * reverseScalingFactor * 2))
                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()
Beispiel #24
0
    def drawAxisPreview(self,
                        glyph,
                        color,
                        scale,
                        customColor,
                        view=False,
                        flatComponentColor=(.8, .6, 0, .7),
                        drawSelectedElements=True):
        mjdt.save()
        index = None
        # loc = {}
        # if glyph.selectedSourceAxis:
        #     loc = {glyph.selectedSourceAxis:1}
        # for i, atomicInstance in enumerate(glyph.preview()):
        for i, atomicInstance in enumerate(
                glyph.preview(forceRefresh=False, axisPreview=True)):
            # for i, atomicInstance in enumerate(glyph.previewGlyph):
            transformIntance = atomicInstance._transformation
            atomicInstance = atomicInstance.glyph

            mjdt.fill(*color)
            if drawSelectedElements and i in glyph.selectedElement:
                mjdt.save()
                mjdt.stroke(1, 0, 0, 1)
                mjdt.strokeWidth(1 * scale)
                tx = transformIntance['x'] + transformIntance['tcenterx']
                ty = transformIntance['y'] + transformIntance['tcentery']
                mjdt.line((tx - 5 * scale, ty), (tx + 5 * scale, ty))
                mjdt.line((tx, ty - 5 * scale), (tx, ty + 5 * scale))
                mjdt.stroke(None)
                mjdt.fill(1, 0, 0, 1)
                mjdt.fontSize(8 * scale)
                mjdt.textBox(
                    f"{int(transformIntance['tcenterx'])} {int(transformIntance['tcentery'])}",
                    ((tx - 30 * scale, ty - 30 * scale, 60 * scale,
                      20 * scale)),
                    align="center")
                mjdt.restore()
                mjdt.fill(0, .8, .8, .5)

            # for c in atomicInstance:
            #     if c.clockwise:
            #         mjdt.stroke(1, 0, 0, 1)
            #         mjdt.strokeWidth(2*scale)
            mjdt.save()
            # mjdt.drawGlyph(atomicInstance.getTransformedGlyph(round = self.RCJKI.roundToGrid))
            mjdt.drawGlyph(atomicInstance)
            mjdt.restore()
            if customColor is None and view:
                if i != index:
                    self.drawIndexOfElements(i, atomicInstance, view)
                    if glyph.type == "characterGlyph":
                        response = self.RCJKI.currentFont.mysqlGlyphData.get(
                            glyph.name, False)
                        try:
                            if response:
                                for dc in response["made_of"]:
                                    if dc["name"] != glyph._deepComponents[
                                            i].name:
                                        continue
                                    char = getChar(dc["name"])
                                    if not char: continue
                                    txt = "%s/%s\nused at %s%s" % (
                                        len(dc["used_by"]),
                                        len(self.RCJKI.currentFont.
                                            deepComponents2Chars[char]),
                                        round(
                                            (len(dc["used_by"]) /
                                             len(self.RCJKI.currentFont.
                                                 deepComponents2Chars[char])) *
                                            100), "%")
                                    x, y = atomicInstance[0].points[
                                        0].x, atomicInstance[0].points[0].y
                                    mjdt.fill(1, 0, 1, 1)
                                    mjdt.fontSize(10 * scale)
                                    mjdt.text(txt, (x, y - 30 * scale))
                        except Exception as e:
                            pass
            index = i
        if customColor is None:
            mjdt.fill(customColor)
        else:
            mjdt.fill(*customColor)

        mjdt.drawGlyph(glyph)
        mjdt.restore()

        for c in glyph.flatComponents:
            if self.RCJKI.currentFont[c.baseGlyph].type == "atomicElement":
                mjdt.drawGlyph(
                    self.roundGlyph(self.RCJKI.currentFont[c.baseGlyph]))
            else:
                # self.RCJKI.currentFont[c.baseGlyph].preview.computeDeepComponents(update = False)
                self.drawAxisPreview(self.RCJKI.currentFont[c.baseGlyph],
                                     flatComponentColor, scale, customColor,
                                     view)
Beispiel #25
0
 def _drawCentralBackgroundGlyph(self, glyph):
     dt.save()
     dt.fill(*LIGHT_GRAY_COLOR)
     dt.drawGlyph(glyph)
     dt.restore()
Beispiel #26
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)