def initCachedFont(self): currentFont = self.currentFont self.cachedFont = RFont(showInterface=False) if currentFont is not None: for metric in ['ascender', 'descender', 'unitsPerEm']: setattr(self.cachedFont.info, metric, getattr(currentFont.info, metric))
def getGlyphPath(ufo, glyph): font = RFont(ufo) glyph = font[glyph] B = BezierPath() for contour in glyph: for i, segment in enumerate(contour): # curveTo if len(segment.points) == 3: if i == 0: if len(contour.segments[-1].points) == 3: x, y = contour.segments[-1].points[ 2].x, contour.segments[-1].points[2].y else: x, y = contour.segments[-1].points[ 0].x, contour.segments[-1].points[0].y B.moveTo((x, y)) x1, y1 = segment.points[0].x, segment.points[0].y x2, y2 = segment.points[1].x, segment.points[1].y x3, y3 = segment.points[2].x, segment.points[2].y B.curveTo((x1, y1), (x2, y2), (x3, y3)) # lineTo or moveTo else: x, y = segment.points[0].x, segment.points[0].y if i == 0: B.moveTo((x, y)) else: B.lineTo((x, y)) B.closePath() return B
def extractValue(m, attrName, expected=None): f = RFont() f.info.fromMathInfo(m) v = getattr(f.info, attrName) if v == expected: t = ok else: t = notOk print("\t", t, v, "\t", attrName)
def generateGlyphsToFont(self, exportFont=None, layerName=None): font = RFont(showInterface=False) if exportFont is None else exportFont currentFont = self.currentFont filterName = self.currentFilterName currentFilter = self.filters[filterName] if currentFont is not None and len(currentFont.selectedGlyphs): glyphs = [ currentFont[glyphName] for glyphName in currentFont.selectedGlyphNames if glyphName in currentFont ] for glyph in glyphs: if len(glyph.components) > 0: for comp in glyph.components: baseGlyphName = comp.baseGlyph baseGlyph = currentFont[baseGlyphName] baseFilteredGlyph = currentFilter(baseGlyph) newFont.insertGlyph(baseFilteredGlyph, baseGlyphName) newFont[ baseGlyphName].unicode = baseFilteredGlyph.unicode filteredGlyph = currentFilter(glyph) if filteredGlyph is not None: if exportFont is None: font.insertGlyph(filteredGlyph, glyph.name) else: glyph = font[ glyph.name] if layerName is None else font[ glyph.name].getLayer(layerName) glyph.clearContours() glyph.clearComponents() glyph.appendGlyph(filteredGlyph) font.openInterface() else: message('PenBallWizard', 'No selected glyphs to generate')
def generateSource(masterName, xHeight, ascender, width, thickness, roundness): master = RFont() master.info.familyName = familyName master.info.styleName = styleName master.info.xHeight = xHeight master.info.capHeight = capHeight master.info.unitsPerEm = capHeight + abs(ascender) master.info.descender = -ascender master.info.ascender = ascender spacing = 50 glyph_space(master, xHeight, ascender, width, thickness, spacing, roundness) glyph_a(master, xHeight, ascender, width, thickness, spacing, roundness) glyph_b(master, xHeight, ascender, width, thickness, spacing, roundness) glyph_o(master, xHeight, ascender, width, thickness, spacing, roundness) source = doc.newSourceDescriptor() source.font = master.naked() source.location = dict(Width = width) if width == 1 and thickness == 50 : source.copyLib = True doc.addSource(source)
def drawGlyph(x, y, sc, ufo, glyphs): font = RFont(ufo) UPM = font.info.unitsPerEm for g in glyphs: glyph = font[g] B = BezierPath() for contour in glyph: for i, segment in enumerate(contour): # curveTo if len(segment.points) == 3: if i == 0: if len(contour.segments[-1].points) == 3: x, y = contour.segments[-1].points[ 2].x, contour.segments[-1].points[2].y else: x, y = contour.segments[-1].points[ 0].x, contour.segments[-1].points[0].y B.moveTo((x, y)) x1, y1 = segment.points[0].x, segment.points[0].y x2, y2 = segment.points[1].x, segment.points[1].y x3, y3 = segment.points[2].x, segment.points[2].y B.curveTo((x1, y1), (x2, y2), (x3, y3)) # lineTo or moveTo else: x, y = segment.points[0].x, segment.points[0].y if i == 0: B.moveTo((x, y)) else: B.lineTo((x, y)) B.closePath() B.scale(sc / UPM) translate(x, y) drawPath(B)
notOk = "🚫" def extractValue(m, attrName, expected=None): f = RFont() f.info.fromMathInfo(m) v = getattr(f.info, attrName) if v == expected: t = ok else: t = notOk print("\t", t, v, "\t", attrName) # master 1 f1 = RFont() f1.info.ascender = 800 # present in both masters f1.info.openTypeHheaAscender = 330 # example value that won't be in master 2 m1 = f1.info.toMathInfo() f2 = RFont() f2.info.ascender = 750 # present in both masters f2.info.openTypeOS2TypoAscender = 555 # example value that won't be in master 1 m2 = f2.info.toMathInfo() # subtraction m3 = m1 - m2 print("\nm1 \"default\"") extractValue(m1, "ascender", 800)
def getPath(ufo, glyph): font = RFont(ufo) g = font[glyph] pen = PrintingSegmentPen() g.draw(pen)
def test_fontshell_RFont_empty(self): RFont()