示例#1
0
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
示例#3
0
def interpolate_layout(designspace_filename,
                       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.
	"""
    ds = load_designspace(designspace_filename)

    log.info("Building interpolated font")
    log.info("Loading master fonts")
    basedir = os.path.dirname(designspace_filename)
    master_ttfs = [
        master_finder(os.path.join(basedir, m.filename)) for m in ds.masters
    ]
    master_fonts = [TTFont(ttf_path) for ttf_path in master_ttfs]

    #font = master_fonts[ds.base_idx]
    font = TTFont(master_ttfs[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
示例#4
0
def interpolate_layout(designspace_filename, 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.
	"""
	ds = load_designspace(designspace_filename)

	log.info("Building interpolated font")
	log.info("Loading master fonts")
	basedir = os.path.dirname(designspace_filename)
	master_ttfs = [
		master_finder(os.path.join(basedir, m.filename)) for m in ds.masters
	]
	master_fonts = [TTFont(ttf_path) for ttf_path in master_ttfs]

	#font = master_fonts[ds.base_idx]
	font = TTFont(master_ttfs[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
示例#5
0
    def test_designspace_fill_in_location(self):
        ds_path = self.get_test_input("VarLibLocationTest.designspace")
        ds = DesignSpaceDocument.fromfile(ds_path)
        ds_loaded = load_designspace(ds)

        assert ds_loaded.instances[0].location == {"weight": 0, "width": 50}