def buildGlyphOrderAndAlias(fontPath, root): """ Using the font's glyphOrder and postscriptNames, generates a GlyphOrderAndAliasDB file. *fontPath* is a `string` path to a UFO *root* is the directory to save the GlyphOrderAndAliasDB to """ font = Font(fontPath) order = font.glyphOrder mapping = font.lib["public.postscriptNames"] path = os.path.join(root, "GlyphOrderAndAliasDB") with open(path, "w") as f: for name in order: if name in font.keys(): glyph = font[name] finalName = mapping[name] if len(glyph.unicodes) > 1: unicodes = [f"uni{uni:04X}" for uni in glyph.unicodes] out = f"{finalName}\t{name}\t{','.join(unicodes)}\n" else: out = f"{finalName}\t{name}\n" f.write(out) f.write("\n")
def _makeTestFont(): # make a simple glyph that we can test the pens with. from fontParts.fontshell import RFont testFont = RFont() baseGlyph = testFont.newGlyph("baseGlyph") pen = baseGlyph.getPen() pen.moveTo((100, 100)) pen.lineTo((600, 100)) pen.lineTo((600, 600)) pen.lineTo((100, 600)) pen.closePath() testGlyph = testFont.newGlyph("testGlyph") testGlyph.appendComponent("baseGlyph", scale=.5) return testGlyph
def buildInstances(designspacePath, root): doc = DesignSpaceProcessor() doc.useVarlib = True doc.roundGeometry = True doc.read(designspacePath) for i in doc.instances: path = os.path.join(root, i.familyName.strip().replace(" ", ""), i.styleName.strip().replace(" ", ""), os.path.split(i.filename)[1]) i.path = path print("Generating instance UFOs") doc.generateUFO() print("Decomposing and removing overlap") ufos = getFiles(root, ".ufo") length = len(ufos) printProgressBar(0, length, prefix='Progress:', suffix='Complete', length=50) for i, ufo in enumerate(ufos): font = RFont(ufo) for glyph in font: glyph.decompose() for glyph in font: glyph.removeOverlap() font.save(ufo) printProgressBar(i + 1, length, prefix='Progress:', suffix='Complete', length=50) print("Seting Panose, weight, and standard stems") length = len(ufos) printProgressBar(0, length, prefix='Progress:', suffix='Complete', length=50) for i, ufo in enumerate(ufos): font = RFont(ufo) fillInPanoseValues(font) font.info.openTypeOS2WeightClass = weightMap[ font.info.styleName.split()[2]] if font.info.styleName.split()[0] == "Mono": font.info.postscriptIsFixedPitch = True fixStandardStems(font) font.save(ufo) printProgressBar(i + 1, length, prefix='Progress:', suffix='Complete', length=50)
By default it makes a copy of the designspace and sources, so your working files are never overwritten. This may be overridden. """ parser = argparse.ArgumentParser(description=description) parser.add_argument("designspacePath", help="The path to a designspace file") parser.add_argument("-o", "--overwrite", action="store_true", help="Overwrite source files in place.") parser.add_argument("-v", "--version", help="Version to set in files") args = parser.parse_args() designspacePath = args.designspacePath if not args.overwrite: print("🏗 Copying files") ds = DesignSpaceDocument.fromfile(designspacePath) font = Font(ds.sources[0].path) fn = font.info.familyName.replace(" ", "_").lower() font.close() now = datetime.datetime.now() fn += "-varfontprep-" + now.strftime("%Y_%m_%d-%H_%M_%S") directory, file = os.path.split(designspacePath) root = os.path.join(directory, fn) designspacePath = copyFiles(designspacePath, root) prep(designspacePath, args.version)
print('The files GSPen.py and objectsGS.py are needed for ' 'Robofab to work in Glyphs. Please get them at ' 'https://github.com/schriftgestalt/Glyphs-Scripts') try: test = getattr(GSLayer, "removeOverlap") if not callable(test): raise except: raise AttributeError( 'Please update your objectsGS.py file. ' 'Download the latest verion at: ' 'https://github.com/schriftgestalt/Glyphs-Scripts') # Check if a font is open -- if not, create a new one. if IN_SHELL: f = RFont() else: f = CurrentFont() if f is None: f = RFont() if f is not None and IN_GLYPHS: Font.disableUpdateInterface() def roundInt(float): return int(round(float)) def floatRange(x, y, step):
from fontMath.mathKerning import MathKerning import fontMath.mathKerning from defcon.objects.font import Font from fontParts.fontshell import RFont from ufoProcessor.varModels import VariationModelMutator from mutatorMath.objects.mutator import buildMutator from fontTools.designspaceLib import AxisDescriptor # kerning exception value. Different results for 1 and 0 value = 0 #f = Font() f = RFont() # doesn't make a difference f.groups["public.kern1.groupA"] = ['one', 'Bee'] f.groups["public.kern2.groupB"] = ['two', 'Three'] f.kerning[('public.kern1.groupA', 'public.kern2.groupB')] = -100 f.kerning[("one", "two")] = value m = MathKerning(f.kerning, f.groups) print("mathKerning object items:", m.items()) print("\tpair", ('public.kern1.groupA', 'public.kern2.groupB'), m[('public.kern1.groupA', 'public.kern2.groupB')]) print("\tpair", ('public.kern1.groupA', 'two'), m[('public.kern1.groupA', 'two')]) print("\tpair", ('one', 'public.kern2.groupB'), m[('one', 'public.kern2.groupB')]) print("\tpair", ('one', 'two'), m[('one', 'two')]) items = [(dict(w=0), m), (dict(w=1), m)] a = AxisDescriptor()
#coding=utf-8 from mutatorScale.objects.scaler import MutatorScaleEngine from mutatorScale.utilities.fontUtils import intersect from fontParts.fontshell import RFont paths = [ 'testFonts/two-axes/regular-low-contrast.ufo', 'testFonts/two-axes/bold-low-contrast.ufo' ] outputPath = 'testFonts/two-axes/scaled-low-contrast.ufo' fonts = [] for p in paths: fonts.append(RFont(p)) scaler = MutatorScaleEngine(fonts) scaler.set({ 'scale' : (0.85, 0.8) }) outputFont = RFont() for glyphName in 'AHIO': glyph = scaler.getScaledGlyph(glyphName, (95, 75)) outputFont.insertGlyph(glyph, glyphName) outputFont.save(outputPath)