def test_load_masters_layerName_without_required_font(): ds = DesignSpaceDocument() s = SourceDescriptor() s.font = None s.layerName = "Medium" ds.addSource(s) with pytest.raises( AttributeError, match="specified a layer name but lacks the required TTFont object", ): load_masters(ds)
def test_load_masters_layerName_without_required_font(): ds = DesignSpaceDocument() s = SourceDescriptor() s.font = None s.layerName = "Medium" ds.addSource(s) with pytest.raises( AttributeError, match="specified a layer name but lacks the required TTFont object", ): load_masters(ds)
def main(args=None): options = get_options(args) if os.path.exists(options.var_font_path): os.remove(options.var_font_path) designspace = DesignSpaceDocument.fromfile(options.design_space_path) ds_data = varLib.load_designspace(designspace) master_fonts = varLib.load_masters(designspace, otfFinder) logger.progress("Reading source fonts...") for i, master_font in enumerate(master_fonts): designspace.sources[i].font = master_font # Subset source fonts if options.include_glyphs_path: logger.progress("Subsetting source fonts...") subsetDict = getSubset(options.include_glyphs_path) subset_masters(designspace, subsetDict) if options.check_compatibility: logger.progress("Checking outline compatibility in source fonts...") font_list = [src.font for src in designspace.sources] default_font = designspace.sources[ds_data.base_idx].font vf = deepcopy(default_font) # We copy vf from default_font, because we use VF to hold # merged arguments from each source font charstring - this alters # the font, which we don't want to do to the default font. do_compatibility(vf, font_list, ds_data.base_idx) logger.progress("Building variable OTF (CFF2) font...") # Note that we now pass in the design space object, rather than a path to # the design space file, in order to pass in the modified source fonts # fonts without having to recompile and save them. try: varFont, _, _ = varLib.build(designspace, otfFinder) except VarLibCFFPointTypeMergeError: logger.error("The input set requires compatibilization. Please try " "again with the -c (--check-compat) option.") return 0 if not options.keep_glyph_names: suppress_glyph_names(varFont) if options.omit_mac_names: remove_mac_names(varFont) stat_file_path = os.path.join(os.path.dirname(options.var_font_path), STAT_FILENAME) if os.path.exists(stat_file_path): logger.progress("Importing STAT table override...") import_stat_override(varFont, stat_file_path) validate_stat_axes(varFont) validate_stat_values(varFont) update_stat_name_ids(varFont) varFont.save(options.var_font_path) logger.progress(f"Built variable font '{options.var_font_path}'")
def interpolate_layout(designspace, loc, master_finder=lambda s: s, mapped=False): """ Interpolate GPOS from a designspace file and location. If master_finder is set, it should be a callable that takes master filename as found in designspace file and map it to master font binary as to be opened (eg. .ttf or .otf). If mapped is False (default), then location is mapped using the map element of the axes in designspace file. If mapped is True, it is assumed that location is in designspace's internal space and no mapping is performed. """ if hasattr(designspace, "sources"): # Assume a DesignspaceDocument pass else: # Assume a file path from fontTools.designspaceLib import DesignSpaceDocument designspace = DesignSpaceDocument.fromfile(designspace) ds = load_designspace(designspace) log.info("Building interpolated font") log.info("Loading master fonts") master_fonts = load_masters(designspace, master_finder) font = deepcopy(master_fonts[ds.base_idx]) log.info("Location: %s", pformat(loc)) if not mapped: loc = {name: ds.axes[name].map_forward(v) for name, v in loc.items()} log.info("Internal location: %s", pformat(loc)) loc = models.normalizeLocation(loc, ds.internal_axis_supports) log.info("Normalized location: %s", pformat(loc)) # Assume single-model for now. model = models.VariationModel(ds.normalized_master_locs) assert 0 == model.mapping[ds.base_idx] merger = InstancerMerger(font, model, loc) log.info("Building interpolated tables") # TODO GSUB/GDEF merger.mergeTables(font, master_fonts, ['GPOS']) return font
def test_varlib_build_sparse_masters_MVAR(self): import fontTools.varLib.mvar ds_path = self.get_test_input("SparseMasters.designspace") ds = DesignSpaceDocument.fromfile(ds_path) load_masters(ds) # Trigger MVAR generation so varLib is forced to create deltas with a # sparse master inbetween. font_0_os2 = ds.sources[0].font["OS/2"] font_0_os2.sTypoAscender = 1 font_0_os2.sTypoDescender = 1 font_0_os2.sTypoLineGap = 1 font_0_os2.usWinAscent = 1 font_0_os2.usWinDescent = 1 font_0_os2.sxHeight = 1 font_0_os2.sCapHeight = 1 font_0_os2.ySubscriptXSize = 1 font_0_os2.ySubscriptYSize = 1 font_0_os2.ySubscriptXOffset = 1 font_0_os2.ySubscriptYOffset = 1 font_0_os2.ySuperscriptXSize = 1 font_0_os2.ySuperscriptYSize = 1 font_0_os2.ySuperscriptXOffset = 1 font_0_os2.ySuperscriptYOffset = 1 font_0_os2.yStrikeoutSize = 1 font_0_os2.yStrikeoutPosition = 1 font_0_vhea = newTable("vhea") font_0_vhea.ascent = 1 font_0_vhea.descent = 1 font_0_vhea.lineGap = 1 font_0_vhea.caretSlopeRise = 1 font_0_vhea.caretSlopeRun = 1 font_0_vhea.caretOffset = 1 ds.sources[0].font["vhea"] = font_0_vhea font_0_hhea = ds.sources[0].font["hhea"] font_0_hhea.caretSlopeRise = 1 font_0_hhea.caretSlopeRun = 1 font_0_hhea.caretOffset = 1 font_0_post = ds.sources[0].font["post"] font_0_post.underlineThickness = 1 font_0_post.underlinePosition = 1 font_2_os2 = ds.sources[2].font["OS/2"] font_2_os2.sTypoAscender = 800 font_2_os2.sTypoDescender = 800 font_2_os2.sTypoLineGap = 800 font_2_os2.usWinAscent = 800 font_2_os2.usWinDescent = 800 font_2_os2.sxHeight = 800 font_2_os2.sCapHeight = 800 font_2_os2.ySubscriptXSize = 800 font_2_os2.ySubscriptYSize = 800 font_2_os2.ySubscriptXOffset = 800 font_2_os2.ySubscriptYOffset = 800 font_2_os2.ySuperscriptXSize = 800 font_2_os2.ySuperscriptYSize = 800 font_2_os2.ySuperscriptXOffset = 800 font_2_os2.ySuperscriptYOffset = 800 font_2_os2.yStrikeoutSize = 800 font_2_os2.yStrikeoutPosition = 800 font_2_vhea = newTable("vhea") font_2_vhea.ascent = 800 font_2_vhea.descent = 800 font_2_vhea.lineGap = 800 font_2_vhea.caretSlopeRise = 800 font_2_vhea.caretSlopeRun = 800 font_2_vhea.caretOffset = 800 ds.sources[2].font["vhea"] = font_2_vhea font_2_hhea = ds.sources[2].font["hhea"] font_2_hhea.caretSlopeRise = 800 font_2_hhea.caretSlopeRun = 800 font_2_hhea.caretOffset = 800 font_2_post = ds.sources[2].font["post"] font_2_post.underlineThickness = 800 font_2_post.underlinePosition = 800 varfont, _, _ = build(ds) mvar_tags = [vr.ValueTag for vr in varfont["MVAR"].table.ValueRecord] assert all(tag in mvar_tags for tag in fontTools.varLib.mvar.MVAR_ENTRIES)
def test_varlib_build_sparse_masters_MVAR(self): import fontTools.varLib.mvar ds_path = self.get_test_input("SparseMasters.designspace") ds = DesignSpaceDocument.fromfile(ds_path) load_masters(ds) # Trigger MVAR generation so varLib is forced to create deltas with a # sparse master inbetween. font_0_os2 = ds.sources[0].font["OS/2"] font_0_os2.sTypoAscender = 1 font_0_os2.sTypoDescender = 1 font_0_os2.sTypoLineGap = 1 font_0_os2.usWinAscent = 1 font_0_os2.usWinDescent = 1 font_0_os2.sxHeight = 1 font_0_os2.sCapHeight = 1 font_0_os2.ySubscriptXSize = 1 font_0_os2.ySubscriptYSize = 1 font_0_os2.ySubscriptXOffset = 1 font_0_os2.ySubscriptYOffset = 1 font_0_os2.ySuperscriptXSize = 1 font_0_os2.ySuperscriptYSize = 1 font_0_os2.ySuperscriptXOffset = 1 font_0_os2.ySuperscriptYOffset = 1 font_0_os2.yStrikeoutSize = 1 font_0_os2.yStrikeoutPosition = 1 font_0_vhea = newTable("vhea") font_0_vhea.ascent = 1 font_0_vhea.descent = 1 font_0_vhea.lineGap = 1 font_0_vhea.caretSlopeRise = 1 font_0_vhea.caretSlopeRun = 1 font_0_vhea.caretOffset = 1 ds.sources[0].font["vhea"] = font_0_vhea font_0_hhea = ds.sources[0].font["hhea"] font_0_hhea.caretSlopeRise = 1 font_0_hhea.caretSlopeRun = 1 font_0_hhea.caretOffset = 1 font_0_post = ds.sources[0].font["post"] font_0_post.underlineThickness = 1 font_0_post.underlinePosition = 1 font_2_os2 = ds.sources[2].font["OS/2"] font_2_os2.sTypoAscender = 800 font_2_os2.sTypoDescender = 800 font_2_os2.sTypoLineGap = 800 font_2_os2.usWinAscent = 800 font_2_os2.usWinDescent = 800 font_2_os2.sxHeight = 800 font_2_os2.sCapHeight = 800 font_2_os2.ySubscriptXSize = 800 font_2_os2.ySubscriptYSize = 800 font_2_os2.ySubscriptXOffset = 800 font_2_os2.ySubscriptYOffset = 800 font_2_os2.ySuperscriptXSize = 800 font_2_os2.ySuperscriptYSize = 800 font_2_os2.ySuperscriptXOffset = 800 font_2_os2.ySuperscriptYOffset = 800 font_2_os2.yStrikeoutSize = 800 font_2_os2.yStrikeoutPosition = 800 font_2_vhea = newTable("vhea") font_2_vhea.ascent = 800 font_2_vhea.descent = 800 font_2_vhea.lineGap = 800 font_2_vhea.caretSlopeRise = 800 font_2_vhea.caretSlopeRun = 800 font_2_vhea.caretOffset = 800 ds.sources[2].font["vhea"] = font_2_vhea font_2_hhea = ds.sources[2].font["hhea"] font_2_hhea.caretSlopeRise = 800 font_2_hhea.caretSlopeRun = 800 font_2_hhea.caretOffset = 800 font_2_post = ds.sources[2].font["post"] font_2_post.underlineThickness = 800 font_2_post.underlinePosition = 800 varfont, _, _ = build(ds) mvar_tags = [vr.ValueTag for vr in varfont["MVAR"].table.ValueRecord] assert all(tag in mvar_tags for tag in fontTools.varLib.mvar.MVAR_ENTRIES)