Exemplo n.º 1
0
    def _makeOvershoot(self, glyph: RGlyph, origin_x: int, origin_y: int,
                       width: int, height: int, inside: int, outside: int, ty):
        ox = origin_x - outside
        oy = origin_y - outside
        width += outside
        height += outside
        pen = glyph.getPen()
        pen.moveTo((ox, oy))
        pen.lineTo((ox + width + outside, oy))
        pen.lineTo((ox + width + outside, oy + height + outside))
        pen.lineTo((ox, oy + height + outside))
        pen.closePath()
        ox = origin_x + inside
        oy = origin_y + inside
        width -= outside + inside
        height -= outside + inside
        pen.moveTo((ox, oy))
        pen.lineTo((ox, oy + height - inside))
        pen.lineTo((ox + width - inside, oy + height - inside))
        pen.lineTo((ox + width - inside, oy))
        pen.closePath()
        glyph.round()
        glyph.moveBy((0, ty))

        self.elements.append((glyph, (0.4, .75, 1, .1), 'fill'))
Exemplo n.º 2
0
    def trace_path(self, out_glyph):
        from mojo.roboFont import RGlyph

        tmp = RGlyph()
        p = tmp.getPen()
        first = True
        for path in self.path:
            if first:
                first = False
            else:
                p.closePath()
                out_glyph.appendGlyph(tmp)
                tmp.clear()
            p.moveTo(self.round_pt(path[0][0]))
            for segment in path[1:]:
                if len(segment) == 1:
                    p.lineTo(self.round_pt(segment[0]))
                elif len(segment) == 3:
                    p.curveTo(
                        self.round_pt(segment[0]),
                        self.round_pt(segment[1]),
                        self.round_pt(segment[2]),
                    )

                else:
                    print("Unknown segment type:", segment)
        p.closePath()
        # tmp.correctDirection()
        out_glyph.appendGlyph(tmp)
        # out_glyph.removeOverlap()
        # out_glyph.removeOverlap()
        out_glyph.update()
Exemplo n.º 3
0
 def draw_background(self, notification):
     s  = notification['scale']
     g1 = notification['glyph']
     # get colors
     _mark_color = self.w.mark_color.get()
     _mark_color = (
         _mark_color.redComponent(),
         _mark_color.greenComponent(),
         _mark_color.blueComponent(),
         _mark_color.alphaComponent(),
     )
     _mark_color_2 = self.w.mark_color_2.get()
     _mark_color_2 = (
         _mark_color_2.redComponent(),
         _mark_color_2.greenComponent(),
         _mark_color_2.blueComponent(),
         _mark_color_2.alphaComponent(),
     )
     # get fonts
     f1 = CurrentFont()
     i  = self.w.f2.get()
     f2 = self.all_fonts[sorted(self.all_fonts.keys())[i]]
     r = 2
     # interpolate steps
     if f1 != f2:
         # check if f2 has this glyph
         if f2.has_key(g1.name):
             g2 = f2[g1.name]
             # check if glyph in f2 is compatible
             if g1.isCompatible(g2):
                 # create colors
                 c1 = Color.NewFromRgb(*_mark_color)
                 c2 = Color.NewFromRgb(*_mark_color_2)
                 colors = c1.Gradient(c2, self.steps)
                 # create steps and draw
                 for i in range(self.steps):
                     factor = i * (1.0 / (self.steps-1))
                     g3 = RGlyph()
                     g3.interpolate(factor, g1, g2)
                     save()
                     fill(None)
                     stroke(*colors[i])
                     strokeWidth(s)
                     if g3.width != g1.width:
                         diff = g3.width - g1.width
                         translate(-diff*0.5, 0)
                     drawGlyph(g3)
                     for c in g3.contours:
                         for pt in c.points:
                             rect(pt.x-r, pt.y-r, r*2, r*2)
                     restore()
                 # done
                 # restore()
         else:
             if self.verbose:
                 print '%s not in font 2' % g1.name
Exemplo n.º 4
0
 def draw_background(self, notification):
     s = notification['scale']
     g1 = notification['glyph']
     # get colors
     _mark_color = self.w.mark_color.get()
     _mark_color = (
         _mark_color.redComponent(),
         _mark_color.greenComponent(),
         _mark_color.blueComponent(),
         _mark_color.alphaComponent(),
     )
     _mark_color_2 = self.w.mark_color_2.get()
     _mark_color_2 = (
         _mark_color_2.redComponent(),
         _mark_color_2.greenComponent(),
         _mark_color_2.blueComponent(),
         _mark_color_2.alphaComponent(),
     )
     # get fonts
     f1 = CurrentFont()
     i = self.w.f2.get()
     f2 = self.all_fonts[sorted(self.all_fonts.keys())[i]]
     r = 2
     # interpolate steps
     if f1 != f2:
         # check if f2 has this glyph
         if f2.has_key(g1.name):
             g2 = f2[g1.name]
             # check if glyph in f2 is compatible
             if g1.isCompatible(g2):
                 # create colors
                 c1 = Color.NewFromRgb(*_mark_color)
                 c2 = Color.NewFromRgb(*_mark_color_2)
                 colors = c1.Gradient(c2, self.steps)
                 # create steps and draw
                 for i in range(self.steps):
                     factor = i * (1.0 / (self.steps - 1))
                     g3 = RGlyph()
                     g3.interpolate(factor, g1, g2)
                     save()
                     fill(None)
                     stroke(*colors[i])
                     strokeWidth(s)
                     if g3.width != g1.width:
                         diff = g3.width - g1.width
                         translate(-diff * 0.5, 0)
                     drawGlyph(g3)
                     for c in g3.contours:
                         for pt in c.points:
                             rect(pt.x - r, pt.y - r, r * 2, r * 2)
                     restore()
                 # done
                 # restore()
         else:
             if self.verbose:
                 print '%s not in font 2' % g1.name
Exemplo n.º 5
0
 def _makeVerGrid(self, glyph: RGlyph, x: int, y: int, w: int, h: int,
                  ty: int, step: int):
     pen = glyph.getPen()
     dist = x + w / step
     for i in range(step - 1):
         pen.moveTo((dist, y))
         pen.lineTo((dist, y + h))
         pen.closePath()
         dist += w / step
     # db.drawGlyph(glyph)
     glyph.moveBy((0, ty))
     self.elements.append((glyph, (.80, 0.56, .66, 1), 'stroke'))
Exemplo n.º 6
0
 def _makeVerSecLine(self, glyph: RGlyph, origin_x: int, origin_y: int,
                     width: int, height: int, ty):
     pen = glyph.getPen()
     pen.moveTo((origin_x, origin_y))
     pen.lineTo((origin_x, origin_y + height))
     pen.closePath()
     pen.moveTo((width, origin_y))
     pen.lineTo((width, origin_y + height))
     pen.closePath()
     glyph.round()
     glyph.moveBy((0, ty))
     self.elements.append((glyph, (.80, 0.56, .66, 1), 'stroke'))
Exemplo n.º 7
0
 def applyCallback(self, sender):
     if self.currentGlyph is not None:
         xml = self.w.xml.get()
         
         dummyGlyph = RGlyph()
         try:
             readGlyphFromString(str(xml), dummyGlyph, dummyGlyph.getPointPen())
         except:
             import traceback
             error = "A problem occured when trying to parse the glif plist."
             suggestion = traceback.format_exc(5)
             self.showMessage(error, suggestion)
             return
             
         self.currentGlyph.clear()
         readGlyphFromString(str(xml), self.currentGlyph, self.currentGlyph.getPointPen())
Exemplo n.º 8
0
    def draw(self,
             glyph=None,
             notificationName: str = "",
             mainFrames: bool = True,
             customsFrames: bool = True,
             proximityPoints: bool = False,
             translate_secondLine_X: int = 0,
             translate_secondLine_Y: int = 0,
             scale: int = 1):

        if notificationName == 'drawPreview' and not self.drawPreview: return
        if not self.controller.designFrame: return
        x, y = 0, 0
        w, h = self.controller.designFrame.em_Dimension
        translateY = -12 * h / 100

        if mainFrames:
            self._getFrame(x, y, w, h, translateY)

            frame = self._getEmRatioFrame(
                self.controller.designFrame.characterFace, w, h, translateY)
            outside, inside = self.controller.designFrame.overshoot
            self._makeOvershoot(RGlyph(), *frame,
                                *self.controller.designFrame.overshoot,
                                translateY)

        self._makeHorGrid(RGlyph(), *frame, translateY, step=24)
        self._makeVerGrid(RGlyph(), *frame, translateY, step=24)

        # if self.secondLines:
        #     if self.controller.designFrame.type == "han":
        #         ratio = (h * .5 * (self.controller.designFrame.horizontalLine / 50))
        #         y = h * .5 - ratio
        #         height = h * .5 + ratio
        #         self._makeHorSecLine(RGlyph(), 0, y + translate_secondLine_Y, w, height + translate_secondLine_Y, translateY)

        #         ratio = (w * .5 * (self.controller.designFrame.verticalLine / 50))
        #         x = w * .5 - ratio
        #         width = w * .5 + ratio
        #         self._makeVerSecLine(RGlyph(), x + translate_secondLine_X, 0, width + translate_secondLine_X, h, translateY)
        #     else:
        #         self._makeHorGrid(RGlyph(), *frame, step = int(self.controller.designFrame.horizontalLine))
        #         self._makeVerGrid(RGlyph(), *frame, step = int(self.controller.designFrame.verticalLine))

        if self.customsFrames:
            for frame in self.controller.designFrame.customsFrames:
                if not "Value" in frame: continue
    def applyCallback(self, sender):
        if self.currentGlyph is not None:
            xml = self.w.xml.get()

            dummyGlyph = RGlyph()
            try:
                readGlyphFromString(str(xml), dummyGlyph,
                                    dummyGlyph.getPointPen())
            except:
                import traceback
                error = "A problem occured when trying to parse the glif plist."
                suggestion = traceback.format_exc(5)
                self.showMessage(error, suggestion)
                return

            self.currentGlyph.clear()
            readGlyphFromString(str(xml), self.currentGlyph,
                                self.currentGlyph.getPointPen())
Exemplo n.º 10
0
 def drawMorf(self, g, path):
     if self.w.onOff.get():
         save()
         translate(g.width, 0)
         fill(0)
         #stroke(1,0,0)
         q = RGlyph()
         writePathInGlyph(path, q)
         drawGlyph(q)
         restore()
Exemplo n.º 11
0
	def extraGlyphsCallback(self, *sender):
		del self.extraGlyphsList[:] # empty the list
		self.extraGlyphs = self.w.extraGlyphs.get()
		glyphNamesList = self.extraGlyphs.split()
		for gName in glyphNamesList:
			try:
				extraGlyph = self.font[gName]
				# must create a new glyph in order to be able to increase the sidebearings without modifying the font
				newGlyph = RGlyph()
				newGlyph.setParent(self.font)
				# must use deepAppend because the extra glyph may have components (which will cause problems to the MultiLineView)
				newGlyph = self.deepAppendGlyph(newGlyph, extraGlyph)
				newGlyph.width = extraGlyph.width
			except RoboFontError:
				continue
			newGlyph.leftMargin += self.extraSidebearings[0]
			newGlyph.rightMargin += self.extraSidebearings[1]
			self.extraGlyphsList.append(newGlyph)
		self.glyphPreviewCacheDict.clear()
		self.updateExtensionWindow()
Exemplo n.º 12
0
def NibGuideGlyphFactory(glyph, font, angle):
    # pen = ExtremePointPen(vertical=True, horizontal=True)
    g = RGlyph(glyph).copy()
    # g.rotateBy(degrees(-angle))
    # # g.extremePoints()
    # g.drawPoints(pen)
    # g.clear()
    # out_pen = g.getPointPen()
    # pen.drawPoints(out_pen)
    # g.rotateBy(degrees(angle))
    return g
Exemplo n.º 13
0
 def extraGlyphsCallback(self, *sender):
     del self.extraGlyphsList[:]  # empty the list
     self.extraGlyphs = self.w.extraGlyphs.get()
     glyphNamesList = self.extraGlyphs.split()
     for gName in glyphNamesList:
         try:
             extraGlyph = self.font[gName]
             # must create a new glyph in order to be able to increase the sidebearings without modifying the font
             newGlyph = RGlyph()
             newGlyph.setParent(self.font)
             # must use deepAppend because the extra glyph may have components (which will cause problems to the MultiLineView)
             newGlyph = self.deepAppendGlyph(newGlyph, extraGlyph)
             newGlyph.width = extraGlyph.width
         except Exception:
             continue
         newGlyph.leftMargin += self.extraSidebearings[0]
         newGlyph.rightMargin += self.extraSidebearings[1]
         self.extraGlyphsList.append(newGlyph)
     self.glyphPreviewCacheDict.clear()
     self.updateExtensionWindow()
Exemplo n.º 14
0
	def updateCalibrateMode(self, *sender):
		glyphsList = []
		newLine = self.w.lineView.createNewLineGlyph()

		# cycle thru the UI Groups and collect the strings
		for i in range(1,5):
			group = getattr(self.cm, "group%d" % i)
			baseGlyphsNamesList = group.baseInput.get().split()
			markGlyphsNamesList = group.markInput.get().split()

			# iterate thru the base+mark combinations
			for gBaseName, gMarkName in product(baseGlyphsNamesList, markGlyphsNamesList):
				newGlyph = RGlyph()
				newGlyph.setParent(self.font)
				# skip invalid glyph names
				try:
					baseGlyph = self.font[gBaseName]
					markGlyph = self.font[gMarkName]
				except RoboFontError:
					continue
				# append base glyph
				newGlyph = self.deepAppendGlyph(newGlyph, baseGlyph)
				# append mark glyph
				newGlyph = self.deepAppendGlyph(newGlyph, markGlyph, self.getAnchorOffsets(baseGlyph, markGlyph))
				# set the advanced width
				dfltSidebearings = self.upm * .05 # 5% of the UPM
				newGlyph.leftMargin = dfltSidebearings + self.extraSidebearings[0]
				newGlyph.rightMargin = dfltSidebearings + self.extraSidebearings[1]
				# append the assembled glyph to the list
				glyphsList.extend(self.extraGlyphsList)
				glyphsList.append(newGlyph)

			# add line break, if both input fields have content
			if baseGlyphsNamesList and markGlyphsNamesList:
				glyphsList.extend(self.extraGlyphsList)
				glyphsList.append(newLine)

		# update the contents of the MultiLineView
		self.w.lineView.set(glyphsList)
Exemplo n.º 15
0
    def glyphs(self):
        x = 0
        y = (self.position[3] - self.fontSize) * (1000 / self.fontSize)

        for char in self.text:
            charName = files.unicodeName(char)
            try:
                rglyph = self.RCJKI.currentFont[charName]
                glyph = RGlyph()
                if not self.sourceList:
                    # rglyph.preview.computeDeepComponents(update = False)
                    for atomicInstance in rglyph.preview(self.sourceList):
                        atomicInstance = atomicInstance.glyph
                        atomicInstance.draw(glyph.getPen())
                        # for c in atomicInstance.getTransformedGlyph():
                        #     glyph.appendContour(c)
                else:
                    for atomicInstance in rglyph.preview():
                        atomicInstance = atomicInstance.glyph
                        atomicInstance.draw(glyph.getPen())

                yield (x, y), glyph

                for c in rglyph.flatComponents:
                    g = self.RCJKI.currentFont[c.baseGlyph]
                    glyph = RGlyph()
                    if not self.sourceList:
                        # g.preview.computeDeepComponents(update = False)
                        for atomicInstance in g.preview(self.sourceList):
                            atomicInstance = atomicInstance.glyph
                            atomicInstance.draw(glyph.getPen())
                            # for c in atomicInstance.getTransformedGlyph():
                            #     glyph.appendContour(c)
                    else:
                        for atomicInstance in g.preview():
                            atomicInstance = atomicInstance.glyph
                            atomicInstance.draw(glyph.getPen())

                    yield (x, y), glyph

                x += rglyph.width + self.tracking * (1000 / self.fontSize)
                if (x + rglyph.width) // (1000 /
                                          self.fontSize) > self.position[2]:
                    y -= self.lineHeight
                    x = 0
            except:  # Exception as e:
                # raise e
                continue
Exemplo n.º 16
0
    def _getFrame(self, x: int, y: int, w: int, h: int, ty) -> tuple:
        glyph = RGlyph()
        pen = glyph.getPen()
        pen.moveTo((x, y))
        pen.lineTo((w + x, y))
        pen.lineTo((w + x, h + y))
        pen.lineTo((x, h + y))
        pen.closePath()

        glyph.round()
        glyph.moveBy((0, ty))

        self.elements.append((glyph, (0, 0, 0, 1), 'stroke'))
Exemplo n.º 17
0
    def updateCalibrateMode(self, *sender):
        glyphsList = []
        newLine = self.w.lineView.createNewLineGlyph()

        # cycle thru the UI Groups and collect the strings
        for i in range(1, 5):
            group = getattr(self.cm, "group%d" % i)
            baseGlyphsNamesList = group.baseInput.get().split()
            markGlyphsNamesList = group.markInput.get().split()

            # iterate thru the base+mark combinations
            for gBaseName, gMarkName in product(baseGlyphsNamesList,
                                                markGlyphsNamesList):
                newGlyph = RGlyph()
                if self.rf3:
                    newGlyph.layer = self.layer
                else:
                    newGlyph.font = newGlyph.getParent()
                # skip invalid glyph names
                try:
                    baseGlyph = self.font[gBaseName]
                    markGlyph = self.font[gMarkName]
                except Exception:
                    continue
                # append base glyph
                newGlyph = self.deepAppendGlyph(newGlyph, baseGlyph)
                # append mark glyph
                newGlyph = self.deepAppendGlyph(
                    newGlyph, markGlyph,
                    self.getAnchorOffsets(baseGlyph, markGlyph))
                # set the advanced width
                dfltSidebearings = self.upm * .05  # 5% of UPM
                newGlyph.leftMargin = (dfltSidebearings +
                                       self.extraSidebearings[0])
                newGlyph.rightMargin = (dfltSidebearings +
                                        self.extraSidebearings[1])
                # append the assembled glyph to the list
                glyphsList.extend(self.extraGlyphsList)
                glyphsList.append(newGlyph)

            # add line break, if both input fields have content
            if baseGlyphsNamesList and markGlyphsNamesList:
                glyphsList.extend(self.extraGlyphsList)
                glyphsList.append(newLine)

        # update the contents of the MultiLineView
        self.w.lineView.set(glyphsList)
Exemplo n.º 18
0
    def _getEmRatioFrame(self, frame: int, w: int, h: int, ty) -> tuple:
        charfaceW = w * frame / 100
        charfaceH = h * frame / 100
        x = (w - charfaceW) * .5
        y = (h - charfaceH) * .5

        glyph = RGlyph()
        pen = glyph.getPen()
        pen.moveTo((x, y))
        pen.lineTo((charfaceW + x, y))
        pen.lineTo((charfaceW + x, charfaceH + y))
        pen.lineTo((x, charfaceH + y))
        pen.closePath()

        glyph.round()
        glyph.moveBy((0, ty))

        self.elements.append((glyph, (0, 0, 0, 1), 'stroke'))

        return x, y, charfaceW, charfaceH
Exemplo n.º 19
0
 def _newPage(self, width, height):
     self._glyphs.append(RGlyph())
     self._pen = self._glyphs[-1].getPen()
     self.reset()
Exemplo n.º 20
0
    def updateExtensionWindow(self):
        if self.calibrateMode:
            self.updateCalibrateMode()
            return

        # NOTE: CurrentGlyph() will return zero (its length),
        # so "is not None" is necessary
        if CurrentGlyph() is not None:
            self.glyph = CurrentGlyph()
            self.glyphNamesList = self.makeGlyphNamesList(self.glyph)
            self.updateListView()
            currentGlyphName = self.glyph.name

            # base glyph + accent combinations preview
            # first check if there's a cached glyph
            if currentGlyphName in self.glyphPreviewCacheDict:
                self.w.lineView.set(
                    self.glyphPreviewCacheDict[currentGlyphName])

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

                    newGlyph = RGlyph()
                    if self.rf3:
                        newGlyph.layer = self.layer
                    else:
                        newGlyph.font = newGlyph.getParent()

                    # the glyph in the UI list is a mark
                    if glyphNameInUIList in self.marksDict:
                        markGlyph = self.font[glyphNameInUIList]

                        # append base glyph
                        newGlyph = self.deepAppendGlyph(newGlyph, self.glyph)
                        # append mark glyph
                        newGlyph = self.deepAppendGlyph(
                            newGlyph, markGlyph,
                            self.getAnchorOffsets(self.glyph, markGlyph,
                                                  glyphNameCXTportion))

                        # set the advanced width
                        # combining marks or other glyphs with
                        # a small advanced width
                        if self.glyph.width < 10:
                            newGlyph.leftMargin = self.upm * .05  # 5% of UPM
                            newGlyph.rightMargin = newGlyph.leftMargin
                        else:
                            newGlyph.width = self.glyph.width

                    # the glyph in the UI list is a base
                    else:
                        baseGlyph = self.font[glyphNameInUIList]

                        # append base glyph
                        newGlyph = self.deepAppendGlyph(newGlyph, baseGlyph)
                        # append mark glyph
                        newGlyph = self.deepAppendGlyph(
                            newGlyph, self.glyph,
                            self.getAnchorOffsets(baseGlyph, self.glyph))

                        # set the advanced width
                        # combining marks or other glyphs with
                        # a small advanced width
                        if self.glyph.width < 10:
                            newGlyph.leftMargin = self.upm * .05
                            newGlyph.rightMargin = newGlyph.leftMargin
                        else:
                            newGlyph.width = baseGlyph.width

                    # pad the new glyph if it has too much overhang
                    if newGlyph.leftMargin < self.upm * .15:
                        newGlyph.leftMargin = self.upm * .05
                    if newGlyph.rightMargin < self.upm * .15:
                        newGlyph.rightMargin = self.upm * .05

                        # add extra sidebearings
                        newGlyph.leftMargin += self.extraSidebearings[0]
                        newGlyph.rightMargin += self.extraSidebearings[1]

                    # one last check for making sure the new glyph
                    # can be displayed
                    if not newGlyph.components:
                        glyphsList.extend(self.extraGlyphsList)
                        glyphsList.append(newGlyph)
                    else:
                        print("Combination with mark glyph %s can't be "
                              "previewed because it contains component %s." %
                              (glyphNameInUIList + glyphNameCXTportion,
                               newGlyph.components[0].baseGlyph))

                glyphsList.extend(self.extraGlyphsList)
                self.w.lineView.set(glyphsList)

                # add to the cache
                self.glyphPreviewCacheDict[currentGlyphName] = glyphsList
        else:
            self.w.lineView.set([])
Exemplo n.º 21
0
    def _drawElements(self, glyph, color, distance, mode):
        assert mode == 'canvas' or mode == 'foreground'
        assert self.elementShape in SHAPE_OPTIONS

        if mode == 'foreground':
            phantomGlyph = RGlyph()

        for eachContour in glyph:
            for indexSegment, eachSegment in enumerate(eachContour):
                if indexSegment != len(eachContour) - 1:
                    nextSegment = eachContour[indexSegment + 1]
                else:
                    if eachContour.open is True:
                        continue
                    else:
                        nextSegment = eachContour[0]

                pt1 = eachSegment.onCurve.x, eachSegment.onCurve.y
                pt4 = nextSegment.onCurve.x, nextSegment.onCurve.y

                if nextSegment.offCurve:
                    pt2 = nextSegment.offCurve[0].x, nextSegment.offCurve[0].y
                    pt3 = nextSegment.offCurve[1].x, nextSegment.offCurve[1].y
                else:
                    pt2 = pt1
                    pt3 = pt4
                pt1 = eachSegment.onCurve.x, eachSegment.onCurve.y
                pt4 = nextSegment.onCurve.x, nextSegment.onCurve.y

                if eachSegment.onCurve.naked().uniqueID in glyph.lib[PLUGIN_KEY] and \
                   nextSegment.onCurve.naked().uniqueID in glyph.lib[PLUGIN_KEY]:
                    startLib = glyph.lib[PLUGIN_KEY][
                        eachSegment.onCurve.naked().uniqueID]
                    endLib = glyph.lib[PLUGIN_KEY][
                        nextSegment.onCurve.naked().uniqueID]

                    bezPoints = collectsPointsOnBezierCurveWithFixedDistance(
                        pt1, pt2, pt3, pt4, distance)
                    for indexBezPt, eachBezPt in enumerate(bezPoints):
                        factor = indexBezPt / float(len(bezPoints))
                        width = lerp(startLib['width'], endLib['width'],
                                     factor)
                        height = lerp(startLib['height'], endLib['height'],
                                      factor)
                        angle = lerp(startLib['angle'], endLib['angle'],
                                     factor)

                        if mode == 'canvas':
                            save()
                            fill(*color)
                            translate(eachBezPt[0][0], eachBezPt[0][1])
                            rotate(angle)

                            if self.elementShape == 'Oval':
                                oval(-width / 2., -height / 2., width, height)
                            else:
                                rect(-width / 2., -height / 2., width, height)
                            restore()

                        else:
                            matrix = Identity
                            matrix = matrix.translate(eachBezPt[0][0],
                                                      eachBezPt[0][1])
                            matrix = matrix.rotate(math.radians(angle))

                            if self.elementShape == 'Oval':
                                robofabOval(phantomGlyph, 0, 0, width, height)
                            else:
                                robofabRect(phantomGlyph, 0, 0, width, height)
                            phantomGlyph[len(phantomGlyph) -
                                         1].transform(matrix)

        if mode == 'foreground':
            phantomGlyph.removeOverlap()
            flattenGlyph(phantomGlyph, 20)
            thresholdGlyph(phantomGlyph, 5)
            if version[0] == '2':
                glyph.getLayer('public.default',
                               clear=True).appendGlyph(phantomGlyph, (0, 0))
            else:
                glyph.getLayer('foreground',
                               clear=True).appendGlyph(phantomGlyph, (0, 0))
Exemplo n.º 22
0
def RedArrowReportFactory(glyph):
    glyph = RGlyph(glyph)
    font = glyph.getParent()
    return getGlyphReport(font, glyph, options)
Exemplo n.º 23
0
	def updateExtensionWindow(self):
		if self.calibrateMode:
			self.updateCalibrateMode()
			return

		if CurrentGlyph() is not None: # NOTE: CurrentGlyph() will return zero (its length), so "is not None" is necessary
			self.glyph = CurrentGlyph()
			self.glyphNamesList = self.makeGlyphNamesList(self.glyph)
			self.updateListView()
			currentGlyphName = self.glyph.name

			# base glyph + accent combinations preview
			# first check if there's a cached glyph
			if currentGlyphName in self.glyphPreviewCacheDict:
				self.w.lineView.set(self.glyphPreviewCacheDict[currentGlyphName])

			# assemble the glyphs
			else:
				glyphsList = []
				for glyphNameInUIList in self.glyphNamesList:
					newGlyph = RGlyph()
					newGlyph.setParent(self.font)

					# the glyph in the UI list is a mark
					if glyphNameInUIList in self.marksDict:
						markGlyph = self.font[glyphNameInUIList]

						# append base glyph
						newGlyph = self.deepAppendGlyph(newGlyph, self.glyph)
						# append mark glyph
						newGlyph = self.deepAppendGlyph(newGlyph, markGlyph, self.getAnchorOffsets(self.glyph, markGlyph))

						# set the advanced width
						if self.glyph.width < 10: # combining marks or other glyphs with a small advanced width
							newGlyph.leftMargin = self.upm * .05 # 5% of the UPM
							newGlyph.rightMargin = newGlyph.leftMargin
						else:
							newGlyph.width = self.glyph.width

					# the glyph in the UI list is a base
					else:
						baseGlyph = self.font[glyphNameInUIList]

						# append base glyph
						newGlyph = self.deepAppendGlyph(newGlyph, baseGlyph)
						# append mark glyph
						newGlyph = self.deepAppendGlyph(newGlyph, self.glyph, self.getAnchorOffsets(baseGlyph, self.glyph))

						# set the advanced width
						if self.glyph.width < 10: # combining marks or other glyphs with a small advanced width
							newGlyph.leftMargin = self.upm * .05
							newGlyph.rightMargin = newGlyph.leftMargin
						else:
							newGlyph.width = baseGlyph.width

					# pad the new glyph if it has too much overhang
					if newGlyph.leftMargin < self.upm * .15:
						newGlyph.leftMargin = self.upm * .05
					if newGlyph.rightMargin < self.upm * .15:
						newGlyph.rightMargin = self.upm * .05

					# add extra sidebearings
						newGlyph.leftMargin += self.extraSidebearings[0]
						newGlyph.rightMargin += self.extraSidebearings[1]

					# one last check for making sure the new glyph can be displayed
					if not newGlyph.components:
						glyphsList.extend(self.extraGlyphsList)
						glyphsList.append(newGlyph)
					else:
						print "Combination with mark glyph %s can't be previewed because it contains component %s." % (glyphNameInUIList, newGlyph.components[0].baseGlyph)

				glyphsList.extend(self.extraGlyphsList)
				self.w.lineView.set(glyphsList)

				# add to the cache
				self.glyphPreviewCacheDict[currentGlyphName] = glyphsList
		else:
			self.w.lineView.set([])
Exemplo n.º 24
0
def RedArrowReportFactory(glyph, font):
    glyph = RGlyph(glyph)
    font = glyph.getParent()
    return getGlyphReport(font, glyph, options)