Example #1
0
    def a_magnet(self):
        ctx.newPath()
        ctx.fill(0, 0, 0, .75)
        ctx.moveTo((25, 15))
        ctx.curveTo((20.0, 15.0), (17, 16), (17, 20))
        ctx.lineTo((17, 45))
        ctx.curveTo((17.0, 48.0), (15, 50), (9, 50))
        ctx.curveTo((2, 50), (0, 48.0), (0, 45))
        ctx.lineTo((0, 22))
        ctx.curveTo((0, 6), (9, 0), (25, 0))
        ctx.curveTo((41.0, 0.0), (50, 6), (50, 22))
        ctx.lineTo((50, 45))
        ctx.curveTo((50, 48), (48, 50), (41, 50))
        ctx.curveTo((35, 50), (33, 48), (33, 45))
        ctx.lineTo((33, 20))
        ctx.curveTo((33, 16), (30, 15), (25, 15))
        ctx.closePath()
        ctx.drawPath()

        ctx.newPath()
        ctx.fill(1)
        ctx.moveTo((25, 3))
        ctx.curveTo((11.0, 3), (3, 8), (3, 22))
        ctx.lineTo((3, 34))
        ctx.lineTo((14, 34))
        ctx.lineTo((14, 20))
        ctx.curveTo((14.0, 14.0), (18, 12), (25, 12))
        ctx.curveTo((32.0, 12.0), (36.0, 14.0), (36, 20))
        ctx.lineTo((36, 34))
        ctx.lineTo((47, 34))
        ctx.lineTo((47, 22))
        ctx.curveTo((47, 8), (39, 3), (25, 3))
        ctx.closePath()
        ctx.drawPath()
    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)
Example #3
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)
Example #4
0
 def _drawGlyphOutlines(self, glyphName):
     dt.save()
     dt.fill(*BLACK)
     dt.stroke(None)
     glyphToDisplay = self.fontObj[glyphName]
     dt.drawGlyph(glyphToDisplay)
     dt.restore()
Example #5
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()
Example #6
0
    def _drawOffgridPoints(self, glyph, scalingFactor):
        dt.save()
        dt.fill(*RED_COLOR)
        dt.stroke(None)

        scaledRadius = OFFGRID_RADIUS * scalingFactor
        for eachContour in glyph:
            for eachBPT in eachContour.bPoints:
                if eachBPT.anchor[0] % 4 != 0 or eachBPT.anchor[1] % 4 != 0:
                    dt.oval(eachBPT.anchor[0] - scaledRadius / 2.,
                            eachBPT.anchor[1] - scaledRadius / 2.,
                            scaledRadius, scaledRadius)

                if eachBPT.bcpIn != (0, 0):
                    bcpInAbs = eachBPT.anchor[0] + eachBPT.bcpIn[
                        0], eachBPT.anchor[1] + eachBPT.bcpIn[1]
                    if bcpInAbs[0] % 4 != 0 or bcpInAbs[1] % 4 != 0:
                        dt.oval(bcpInAbs[0] - scaledRadius / 2.,
                                bcpInAbs[1] - scaledRadius / 2., scaledRadius,
                                scaledRadius)

                if eachBPT.bcpOut != (0, 0):
                    bcpOutAbs = eachBPT.anchor[0] + eachBPT.bcpOut[
                        0], eachBPT.anchor[1] + eachBPT.bcpOut[1]
                    if bcpOutAbs[0] % 4 != 0 or bcpOutAbs[1] % 4 != 0:
                        dt.oval(bcpOutAbs[0] - scaledRadius / 2.,
                                bcpOutAbs[1] - scaledRadius / 2., scaledRadius,
                                scaledRadius)
        dt.restore()
    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()
    def _handlesPreview(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 != []:
            glyph = self.tmp_glyph #.copy()
            ref_glyph = CurrentGlyph()
            save()
            stroke(0, 0, 0, 0.3)
            strokeWidth(info["scale"])
            fill(None)
            l = 4 * info["scale"]
            for contourIndex in range(len(glyph)):
                contour = self.tmp_glyph.contours[contourIndex]
                ref_contour = ref_glyph.contours[contourIndex]
                for i in range(len(contour.segments)):
                    segment = contour[i]
                    if ref_contour[i].selected and segment.type == "curve":
                        for p in segment.points[0:2]:
                            x = p.x
                            y = p.y
                            line((x-l, y-l), (x+l, y+l))
                            line((x-l, y+l), (x+l, y-l))
            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()
	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()
Example #11
0
	def drawBroadNibBackground(self, info):
		
		# 칠할 필요가 없다면 종료
		state = getExtensionDefault(DefaultKey+".state")
		if bool(state) is not True:
			return

		# paint current group's contour
		targetGlyph = info["glyph"].getLayer(self.layerName)
		# picks current contours which should be painted from current group
		contourList = []


		try :
			targetIdxList = getExtensionDefault(DefaultKey+".groupDict")[targetGlyph]
			setExtensionDefault(DefaultKey + ".contourNumber", targetIdxList[0])
			
			color = getExtensionDefault(DefaultKey+".color")
			r,g,b,a = color
			fill(r,g,b,a)

			step = getExtensionDefault(DefaultKey+".step"); width = getExtensionDefault(DefaultKey+".width"); height = getExtensionDefault(DefaultKey+".height");


			if info["glyph"].layerName == self.layerName or not self.currentPen:
				self.currentPen = BroadNibPen(None, step, width, height, 0, oval)

			for idx in targetIdxList:
				targetGlyph.contours[idx].draw(self.currentPen)


		except Exception as e:
			setExtensionDefault(DefaultKey + ".contourNumber", None)
			return
Example #12
0
 def drawBackground(self, info):
     #print('Drawing' ,info['glyph'])
     if not self.updating:
         glyph = info['glyph']
         self.w.mySlider.set(glyph.width)
     if self.w.doDraw.get():
         fill(0, 0, 1, 0.5)
         rect(0, 0, glyph.width, 50)
Example #13
0
 def setFill(self, nscolor, opacity_factor=1):
     # set fill color for mojoDrawingTools, optionally with changed opacity
     if nscolor.colorSpaceName != NSCalibratedRGBColorSpace:
         nscolor = nscolor.colorUsingColorSpaceName_(
             NSCalibratedRGBColorSpace)
     fill(nscolor.redComponent(), nscolor.greenComponent(),
          nscolor.blueComponent(),
          nscolor.alphaComponent() * opacity_factor)
Example #14
0
def textQualities(scaledFontSize, weight='regular', color=BLACK_COLOR):
    dt.stroke(None)
    dt.fill(*color)
    if weight == 'bold':
        dt.font(SYSTEM_FONT_NAME_BOLD)
    else:
        dt.font(SYSTEM_FONT_NAME)
    dt.fontSize(scaledFontSize)
Example #15
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()
Example #16
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()
Example #17
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()
Example #18
0
 def draw(self, char: str, scale: float = 1.0):
     save()
     for refFont in self.controller.settings:
         font(str(refFont), refFont.size)
         fill(*refFont.color)
         text(char, refFont.position)
         font(str(refFont), 20)
         text(str(refFont), (refFont.position[0], refFont.position[1]-10))
     restore()
Example #19
0
    def _drawColoredCorrection(self, correction):
        dt.save()

        if correction > 0:
            dt.fill(*LIGHT_GREEN)
        else:
            dt.fill(*LIGHT_RED)
        dt.rect(0, self.fontObj.info.descender, correction,
                self.fontObj.info.unitsPerEm)
        dt.restore()
Example #20
0
    def draw(self):
        self.graph_in_window = []
        c_width, c_height = self.parent.graph_width, self.parent.graph_height

        drawBot.fill(None)

        # horizontal line
        drawBot.stroke(0)
        drawBot.strokeWidth(0.5)
        drawBot.line((0, c_height / 2), (c_width, c_height / 2))

        # vertical lines
        # the combination of both margins equal one additional step
        graph_margin = self.parent.step_dist / 2
        for i in range(self.parent.steps + 1):
            x = graph_margin + i * self.parent.step_dist
            drawBot.line((x, 0), (x, c_height))

        # the graph
        drawBot.stroke(0, 0, 1)
        drawBot.strokeWidth(5)
        drawBot.lineCap('round')

        prev = None
        max_value = max([abs(v) for v in self.parent.number_values])
        zero_point = c_height / 2
        min_scale = 40
        self.max_allowed_value = 500
        self.graph_scale = max_value / self.parent.graph_height
        self.min_graph_scale = min_scale / self.parent.graph_height
        slider_controls = []

        for i, value in enumerate(self.parent.number_values):
            if max_value > min_scale:
                self.amplitude = value / max_value
            else:
                self.amplitude = value / min_scale

            x = graph_margin + i * self.parent.step_dist
            y = zero_point + c_height * 0.4 * self.amplitude
            y_window = (self.parent.w_height - self.parent.graph_height + y -
                        self.parent.padding)
            self.graph_in_window.append((x, y_window))
            if prev:
                drawBot.line(prev, (x, y))
            prev = x, y
            slider_controls.append((x, y))

        # slider heads
        for x, y in slider_controls:
            radius = 10
            drawBot.fill(1)
            drawBot.stroke(0)
            drawBot.strokeWidth(0.5)
            drawBot.oval(x - radius, y - radius, 2 * radius, 2 * radius)
Example #21
0
 def drawPreview(self, scale):
     # only draws if there are already outlines in the glyph
     if self._xMin is None: return
     ctx.save()
     ctx.stroke(1, .4, 0)
     ctx.strokeWidth(2 * scale)
     ctx.lineDash(10 * scale, 20 * scale)
     ctx.fill(0)
     self.buildShapePath(scale)
     ctx.drawPath()
     ctx.restore()
Example #22
0
 def draw(self, scale):
     size = 20 * scale
     save()
     fill(0.2, 0.5, 0.35, 0.3)
     stroke(None)
     #for contour in self.errors.keys():
     #    for p in contour:
     #        oval(p[0]-5, p[1]-5, 10, 10)
     for p in self.errors:
         oval(p[0] - size / 2, p[1] - size / 2, size, size)
     restore()
Example #23
0
 def dot(self, p, s=4, scale=1, stacked=False):
     # draw a dot
     ctx.save()
     ctx.stroke(None)
     if stacked:
         ctx.fill(0, .5, 1)
     else:
         ctx.fill(1, .5, 0)
     s *= scale
     ctx.oval(p[0] - .5 * s, p[1] - .5 * s, s, s)
     ctx.restore()
Example #24
0
 def draw(self, scale):
     size = 20 * scale
     save()
     fill(0.2, 0.5, 0.35, 0.3)
     stroke(None)
     #for contour in self.errors.keys():
     #    for p in contour:
     #        oval(p[0]-5, p[1]-5, 10, 10)
     for p in self.errors:
         oval(p[0]-size/2, p[1]-size/2, size, size)
     restore()
Example #25
0
 def _setup_draw(self, preview=False):
     if preview:
         fill(0)
         stroke(0)
     else:
         fill(0.6, 0.7, 0.9, 0.5)
         stroke(0.6, 0.7, 0.9)
     # strokeWidth(self.height)
     # strokeWidth(1)
     strokeWidth(0)
     stroke(None)
     lineJoin(self.line_join)
 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()
Example #27
0
    def _drawBaseline(self, glyphName):
        glyphToDisplay = self.fontObj[glyphName]

        dt.save()
        dt.stroke(*BLACK)
        dt.fill(None)
        # reversed scaling factor
        dt.strokeWidth(
            1 / (self.ctrlHeight /
                 (self.canvasScalingFactor * self.fontObj.info.unitsPerEm)))
        dt.line((0, 0), (glyphToDisplay.width, 0))
        dt.restore()
    def drawPoints(self, info):
    
        newPoints = self.getValues(None)
        if newPoints != None:
            glyph = CurrentGlyph()
        
            onCurveSize = getDefault("glyphViewOncurvePointsSize") * 5
            offCurveSize = getDefault("glyphViewOncurvePointsSize") * 3
            fillColor = tuple([i for i in getDefault("glyphViewCurvePointsFill")])
        
            upmScale = (glyph.font.info.unitsPerEm/1000) 
            scale = info["scale"]
            oPtSize = onCurveSize * scale
            fPtSize = offCurveSize * scale

            d.save()

            # thanks Erik!
            textLoc = newPoints[0][3][0] + math.cos(self.returnAngle(newPoints)) * (scale*.25*120) * 2, newPoints[0][3][1] + math.sin(self.returnAngle(newPoints)) * (scale*.25*120) * 2

            for b in newPoints:
                for a in b:
                    if a == newPoints[1][0] or a == newPoints[0][-1]:
                        d.oval(a[0]-oPtSize/2,a[1]-oPtSize/2, oPtSize, oPtSize) 
                    else:
                        d.oval(a[0]-fPtSize/2,a[1]-fPtSize/2, fPtSize, fPtSize) 
                    d.fill(fillColor[0],fillColor[1],fillColor[2],fillColor[3])
        
            d.stroke(fillColor[0],fillColor[1],fillColor[2],fillColor[3])
            d.strokeWidth(scale)
            d.line(newPoints[0][2],newPoints[1][1])
            d.restore()

            # https://robofont.com/documentation/building-tools/toolspace/observers/draw-info-text-in-glyph-view/?highlight=draw%20text

            glyphWindow = CurrentGlyphWindow()
            if not glyphWindow:
                return
            glyphView = glyphWindow.getGlyphView()
            textAttributes = {
                AppKit.NSFontAttributeName: AppKit.NSFont.userFixedPitchFontOfSize_(11),
            }
            glyphView.drawTextAtPoint(
            f'{round(abs(math.degrees(self.returnAngle(newPoints)))%180,4)}°\n{str(round(self.returnRatio(newPoints),4))}',
            textAttributes,
            textLoc,
            yOffset=0,
            drawBackground=True,
            centerX=True,
            centerY=True,
            roundBackground=False,)

            UpdateCurrentGlyphView()
Example #29
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()
Example #30
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()
Example #31
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()
Example #32
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()
Example #33
0
 def _curvePreview(self, info):
     dg = info["glyph"]
     scale = info["scale"]
     if dg is not None:
         self.tmpGlyph.clear()
         self.tmpGlyph.appendGlyph(CurrentGlyph())
         self._eqSelected()
         mPen = MojoDrawingToolsPen(self.tmpGlyph, CurrentFont())
         save()
         stroke(0, 0, 0, 0.5)
         fill(None)
         strokeWidth(scale)
         self.tmpGlyph.draw(mPen)
         mPen.draw()
         restore()
Example #34
0
 def _curvePreview(self, info):
     dg = info["glyph"]
     scale = info["scale"]
     if dg is not None:
         self.tmpGlyph.clear()
         self.tmpGlyph.appendGlyph(CurrentGlyph())
         self._eqSelected()
         mPen = MojoDrawingToolsPen(self.tmpGlyph, CurrentFont())
         save()
         stroke(0, 0, 0, 0.5)
         fill(None)
         strokeWidth(scale)
         self.tmpGlyph.draw(mPen)
         mPen.draw()
         restore()
Example #35
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()
Example #36
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._hobbycurve()
            pen = MojoDrawingToolsPen(self.tmp_glyph, _doodle_glyph.getParent())
            save()
            stroke(0, 0, 0, 0.5)
            fill(1, 0, 0, 0.9)
            strokeWidth(info["scale"])
            self.tmp_glyph.draw(pen)
            pen.draw()
            restore()
            UpdateCurrentGlyphView()
    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)
Example #38
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()
Example #39
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()
Example #40
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()
Example #41
0
 def _drawArrows(self, notification):
     glyph = notification["glyph"]
     if glyph is None:
         return
     font = glyph.getParent()
     
     if roboFontVersion > "1.5.1":
         self.errors = glyph.getRepresentation("de.kutilek.RedArrow.report")
     else:
         self.errors = getGlyphReport(font, glyph)
     
     scale = notification["scale"]
     size = 10 * scale
     width = 3 * scale
     errors_by_position = {}
     for e in self.errors:
         #if not e.kind == "Vector on closepath": # FIXME
         if e.position in errors_by_position:
             errors_by_position[e.position].extend([e])
         else:
             errors_by_position[e.position] = [e]
     for pos, errors in errors_by_position.iteritems():
         message = ""
         for e in errors:
             if e.badness is None or not DEBUG:
                 message += "%s, " % (e.kind)
             else:
                 message += "%s (Severity %0.1f), " % (e.kind, e.badness)
         self._drawArrow(pos, message.strip(", "), size, width)
     if options.get("show_bbox"):
         box = glyph.box
         if box is not None:
             save()
             fill(None)
             strokeWidth(0.5 * scale)
             stroke(1, 0, 0, 0.5)
             x, y, w, h = box
             rect(x, y, w-x, h-y)
             restore()
Example #42
0
 def _drawGrid(self):
     label_every = 1
     if self.units > 24:
         label_every = 2
     drawing.save()
     drawing.strokeWidth(0)
     drawing.stroke(None)
     drawing.fill(0.88, 0.92, 0.98)
     if self.system is not None:
         if self.system.min_units is not None:
             drawing.rect(0, 0, 10 + self.system.min_units * self.histogram_width / (self.units * self.ems_horizontal), self.histogram_height)
         if self.system.max_units is not None:
             drawing.rect(10 + self.system.max_units * self.histogram_width / (self.units * self.ems_horizontal), 0, self.histogram_width, self.histogram_height)
     
     drawing.strokeWidth(1.0)
     drawing.stroke(0.8, 0.8, 0.8)
     drawing.fill(0.6, 0.6, 0.6)
     for u in range(0, int(ceil(self.units * self.ems_horizontal))):
         x = 10 + u * self.histogram_width / (self.units * self.ems_horizontal)
         if u == self.units:
             # mark the full em
             drawing.stroke(0, 0, 0)
             drawing.line(x, 20, x, self.histogram_height-10)
             drawing.strokeWidth(0)
             drawing.text("1 em", x + 4, self.histogram_height - 21)
             drawing.strokeWidth(1.0)
         elif u % 10 == 0:
             # make every 10th line darker
             drawing.stroke(0.5, 0.5, 0.5)
             drawing.line(x, 20, x, self.histogram_height - 20)
         else:
             drawing.stroke(0.8, 0.8, 0.8)
             drawing.line(x, 20, x, self.histogram_height - 30)
         if u % label_every == 0:
             drawing.strokeWidth(0)
             drawing.text("%s" % (u), x - 3 * len(str(u)), 5)
     drawing.restore()
	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()
Example #44
0
 def draw_histogram(self, font, upm, color, show_glyphs=False, histogram=None):
     if histogram is None:
         if self.histogram is None:
             return
         histogram = self.histogram
     drawing.save()
     drawing.fill(1, 0.5, 0.2, 1.0)
     drawing.stroke(color[0], color[1], color[2], color[3])
     for width in sorted(histogram.keys()):
         num = len(histogram[width])
         x = 10 + width * self.histogram_width / (upm * self.ems_horizontal)
         drawing.save()
         if show_glyphs:
             drawing.save()
             drawing.fill(color[0], color[1], color[2], 0.2)
             drawing.fontsize(self.scale_vertical)
             for i in range(len(histogram[width])):
                 glyph_name = histogram[width][i]
                 if glyph_name in font:
                     u = font[glyph_name].unicode
                     if u:
                         drawing.text("%s" % unichr(u), x + 4, 18 + i * self.scale_vertical)
                     else:
                         drawing.text("%s" % glyph_name, x + 4, 18 + i * self.scale_vertical)
                 else:
                     drawing.text("%s" % glyph_name, x + 4, 18 + i * self.scale_vertical)
             drawing.restore()
             drawing.strokewidth(2)
         else:
             drawing.strokewidth(6)
         # draw bars
         drawing.line(x, 20, x, 20 + num * self.scale_vertical)
         drawing.strokewidth(0)
         drawing.text("%s" % (num), x - 3 * len(str(num)), 22 + num * self.scale_vertical)
         drawing.restore()
     drawing.restore()