def build_variable_fonts(designspace, *steps): for font in [source.font for source in designspace.sources]: for step in steps: step(font) set_font_metaData(font, "var") familyName = designspace.default.font.info.familyName file_stem = familyName.replace(" ", "") file_path = (OUTPUT_DIR / file_stem).with_suffix(f".ttf") print(f"[{familyName}] Compiling") varFont = ufo2ft.compileVariableTTF(designspace) print(f"[{familyName}] Adding STAT table") styleSpace = classes.Stylespace.from_file(INPUT_DIR / "STAT.plist") lib.apply_stylespace_to_variable_font(styleSpace, varFont, {}) print(f"[{familyName}] Merging VTT") vttLib.transfer.merge_from_file(varFont, VTT_DATA_FILE) print(f"[{familyName}] Saving") varFont.save(file_path) print(f"[{familyName}] Done: {file_path}")
def build_variable_fonts(designspace, *steps): sourceFonts = [ ufoLib2.Font.open(INPUT_DIR / designspace.sources[0].filename), ufoLib2.Font.open(INPUT_DIR / designspace.sources[1].filename), ufoLib2.Font.open(INPUT_DIR / designspace.sources[2].filename) ] for source in sourceFonts: set_font_metaData(source, "var") designspace.sources[0].font = sourceFonts[0] #ExtraLight designspace.sources[1].font = sourceFonts[1] #Regular designspace.sources[2].font = sourceFonts[2] #Bold for font in sourceFonts: for step in steps: step(font) familyName = sourceFonts[1].info.familyName file_stem = sourceFonts[1].info.familyName.replace(" ", "") file_path = (OUTPUT_DIR / file_stem).with_suffix(f".ttf") print(f"[{familyName}] Compiling") varFont = ufo2ft.compileVariableTTF(designspace) print(f"[{familyName}] Adding STAT table") styleSpace = classes.Stylespace.from_file(INPUT_DIR / "STAT.plist") lib.apply_stylespace_to_variable_font(styleSpace, varFont, {}) print(f"[{familyName}] Merging VTT") vttLib.transfer.merge_from_file(varFont, VTT_DATA_FILE) print(f"[{familyName}] Saving") varFont.save(file_path) print(f"[{familyName}] Done: {file_path}") print(f"[{familyName}] Compiling CFF2") file_path_cff2 = (OUTPUT_DIR / file_stem).with_suffix(f".otf") #Do not optimize, because we have to do it again after autohinting. varFontCFF2 = ufo2ft.compileVariableCFF2( designspace, inplace=True, useProductionNames=True, optimizeCFF=ufo2ft.CFFOptimization.NONE, ) print(f"[{familyName}] Adding STAT table") styleSpace = classes.Stylespace.from_file(INPUT_DIR / "STAT.plist") lib.apply_stylespace_to_variable_font(styleSpace, varFontCFF2, {}) print(f"[{familyName}] Saving") varFontCFF2.save(file_path_cff2) print(f"[{familyName}] Done: {file_path_cff2}")
def build_fonts(designspace, static, *steps): for font in [source.font for source in designspace.sources]: for step in steps: step(font) set_font_metaData(font, "var") familyName = designspace.default.font.info.familyName file_stem = familyName.replace(" ", "") file_path = (OUTPUT_DIR / file_stem).with_suffix(f".ttf") print(f"[{familyName}] Compiling") varFont = ufo2ft.compileVariableTTF(designspace) print(f"[{familyName}] Adding STAT table") styleSpace = classes.Stylespace.from_file(INPUT_DIR / "STAT.plist") lib.apply_stylespace_to_variable_font(styleSpace,varFont,{}) print(f"[{familyName}] Merging VTT") vttLib.transfer.merge_from_file(varFont, VTT_DATA_FILE) varFont = overlapFlag(varFont) print(f"[{familyName}] Saving") varFont.save(file_path) print(f"[{familyName}] Done: {file_path}") if static: if os.path.exists(OUTPUT_DIR / "static") == False: os.mkdir(OUTPUT_DIR / "static") generator = fontmake.instantiator.Instantiator.from_designspace(designspace) print(f"[{familyName}] Building static instances") for instance_descriptor in designspace.instances: instance = generator.generate_instance(instance_descriptor) print(f"[{familyName}] "+instance.info.styleName) instance = generator.generate_instance(instance_descriptor) staticTTF = ufo2ft.compileTTF(instance,removeOverlaps=True) staticOTF = ufo2ft.compileOTF(instance,removeOverlaps=True) file_name = file_stem+"-"+instance.info.styleName file_path_static = (OUTPUT_DIR / "static" / file_name).with_suffix(f".ttf") file_path_static_otf = (OUTPUT_DIR / "static" / file_name).with_suffix(f".otf") staticTTF.save(file_path_static) staticOTF.save(file_path_static_otf) print(f"[{familyName}] Done building static instances")
def add_STAT(designspacePath, fontPath, stylespacePath=None): if stylespacePath is None: stylespacePath = getStyleSpacePath(designspacePath) ds = DesignSpaceDocument.fromfile(designspacePath) makeStyleSpace(ds, stylespacePath) if stylespacePath is not None: print("Adding STAT table") additional_locations = ds.lib.get("org.statmake.additionalLocations", {}) font = fontTools.ttLib.TTFont(fontPath) stylespace = Stylespace.from_file(stylespacePath) apply_stylespace_to_variable_font(stylespace, font, additional_locations) font.save(fontPath)
def build_variable( designspacePath, stylespacePath=None, out=None, verbose="ERROR", ): """ Builds a variable font from a designspace using fontmake. Post applies the STAT table using a stylespace if given. *designspacePath* a `string` of the path to the designspace *stylespacePath* a `string` of the path to the stylespace *out* a `string` of the path where the varible font should be saved *verbose* sets the verbosity level for fontmake. Defaults to "ERROR" """ if out is None: out = os.path.splitext( os.path.basename(designspacePath))[0] + "-VF.ttf" else: if not os.path.exists(os.path.split(out)[0]): os.mkdir(os.path.split(out)[0]) print("🏗 Constructing variable font") fp = FontProject(verbose=verbose) fp.build_variable_font(designspacePath, output_path=out, useProductionNames=True) if stylespacePath is not None: print("🏗 Adding STAT table") ds = DesignSpaceDocument.fromfile(designspacePath) additional_locations = ds.lib.get("org.statmake.additionalLocations", {}) font = fontTools.ttLib.TTFont(out) stylespace = Stylespace.from_file(stylespacePath) apply_stylespace_to_variable_font(stylespace, font, additional_locations) font.save(out) print("✅ Built variable font")
def build_variable_fonts(designspace, *steps): sourceFonts = [ ufoLib2.Font.open(INPUT_DIR / designspace.sources[0].filename), ufoLib2.Font.open(INPUT_DIR / designspace.sources[1].filename), ufoLib2.Font.open(INPUT_DIR / designspace.sources[2].filename) ] for source in sourceFonts: set_font_metaData(source, "var") designspace.sources[0].font = sourceFonts[0] #ExtraLight designspace.sources[1].font = sourceFonts[1] #Regular designspace.sources[2].font = sourceFonts[2] #Bold for font in sourceFonts: for step in steps: step(font) familyName = sourceFonts[1].info.familyName file_stem = sourceFonts[1].info.familyName.replace(" ", "") file_path = (OUTPUT_DIR / file_stem).with_suffix(f".ttf") print(f"[{familyName}] Compiling") varFont = ufo2ft.compileVariableTTF(designspace) print(f"[{familyName}] Adding STAT table") styleSpace = classes.Stylespace.from_file(INPUT_DIR / "STAT.plist") lib.apply_stylespace_to_variable_font(styleSpace, varFont, {}) print(f"[{familyName}] Merging VTT") vttLib.transfer.merge_from_file(varFont, VTT_DATA_FILE) print(f"[{familyName}] Saving") varFont.save(file_path) print(f"[{familyName}] Done: {file_path}")
def build_variable( designspacePath, stylespacePath=None, out=None, verbose="ERROR", ): """ Builds a variable font from a designspace using fontmake. Post applies the STAT table using a stylespace if given. *designspacePath* a `string` of the path to the designspace *stylespacePath* a `string` of the path to the stylespace *out* a `string` of the path where the varible font should be saved *verbose* sets the verbosity level for fontmake. Defaults to "ERROR" """ if out is None: out = os.path.splitext( os.path.basename(designspacePath))[0] + "-VF.ttf" else: if not os.path.exists(os.path.split(out)[0]): os.mkdir(os.path.split(out)[0]) print("🏗 Constructing variable font") fp = FontProject(verbose=verbose) fp.build_variable_font(designspacePath, output_path=out, useProductionNames=True) if stylespacePath is not None: print("🏗 Adding STAT table") ds = DesignSpaceDocument.fromfile(designspacePath) additional_locations = ds.lib.get("org.statmake.additionalLocations", {}) font = fontTools.ttLib.TTFont(out) stylespace = Stylespace.from_file(stylespacePath) apply_stylespace_to_variable_font(stylespace, font, additional_locations) font.save(out) font = fontTools.ttLib.TTFont(out) print("🏗 Add gasp table") gasp = fontTools.ttLib.newTable("gasp") gasp.gaspRange = {0xFFFF: 15} font["gasp"] = gasp print("🏗 Fix prep table") program = fontTools.ttLib.tables.ttProgram.Program() assembly = ['PUSHW[]', '511', 'SCANCTRL[]', 'PUSHB[]', '4', 'SCANTYPE[]'] program.fromAssembly(assembly) prep = fontTools.ttLib.newTable("prep") prep.program = program font["prep"] = prep print("🏗 Add dsig table") dsig = fontTools.ttLib.newTable("DSIG") dsig.ulVersion = 1 dsig.usFlag = 0 dsig.usNumSigs = 0 dsig.signatureRecords = [] font["DSIG"] = dsig print("🏗 Set fsType to 0") font["OS/2"].fsType = 0 font.save(out) print("✅ Built variable font")