Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_interpolation(data_dir):
designspace = designspaceLib.DesignSpaceDocument.fromfile(
data_dir / "DesignspaceTest" / "DesignspaceTest.designspace"
)
generator = fontmake.instantiator.Instantiator.from_designspace(
designspace, round_geometry=True
)
instance_font = generator.generate_instance(designspace.instances[0])
assert instance_font["l"].width == 220
def test_interpolation_weight_width_class(data_dir):
designspace = designspaceLib.DesignSpaceDocument.fromfile(
data_dir / "MutatorSans" / "MutatorSans.designspace"
)
generator = fontmake.instantiator.Instantiator.from_designspace(
designspace, round_geometry=True
)
for instance in designspace.instances:
instance.font = generator.generate_instance(instance)
# LightCondensed
font = designspace.instances[0].font
assert font.info.openTypeOS2WeightClass == 1
assert font.info.openTypeOS2WidthClass == 1
# BoldCondensed
font = designspace.instances[1].font
assert font.info.openTypeOS2WeightClass == 1000
assert font.info.openTypeOS2WidthClass == 1
include()s and writes the resulting full feature file to all instance
UFOs. Use this if you share feature files among masters in external
files. Otherwise, the relative include paths can break as instances
may end up elsewhere. Only done on interpolation.
Returns:
generator of ufoLib2.Font objects corresponding to the UFO instances.
Raises:
ValueError: The Designspace has no default source or contains incompatible
glyphs or contains anisotropic (MutatorMath) locations or contains a
substitution for a non-existant glyph.
"""
from glyphsLib.interpolation import apply_instance_data_to_ufo
logger.info("Interpolating master UFOs from designspace")
designspace = designspaceLib.DesignSpaceDocument.fromfile(designspace.path)
generator = instantiator.Instantiator.from_designspace(
designspace, round_geometry=round_instances
)
if expand_features_to_instances:
logger.debug("Expanding features to instance UFOs")
fea_txt = parseLayoutFeatures(designspace.default.font).asFea()
generator = attr.evolve(generator, copy_feature_text=fea_txt)
for instance in designspace.instances:
# Skip instances that have been set to non-export in Glyphs, stored as the
# instance's `com.schriftgestaltung.export` lib key.
if not instance.lib.get("com.schriftgestaltung.export", True):
continue
# Skip instances that do not match the user's inclusion regex if given.
if include is not None and not fullmatch(include, instance.name):