def test_apply_instance_data(tmpdir, instance_names): font = glyphsLib.GSFont(TESTFILE_PATH) instance_dir = "instances" designspace = glyphsLib.to_designspace(font, instance_dir=instance_dir) path = str(tmpdir / (font.familyName + '.designspace')) write_designspace_and_UFOs(designspace, path) builder = DesignSpaceDocumentReader(designspace.path, ufoVersion=3) if instance_names is None: # generate all instances builder.process() include_filenames = None else: # generate only selected instances for name in instance_names: builder.readInstance(("stylename", name)) # make relative filenames from paths returned by MutatorMath include_filenames = {os.path.relpath(instance_path, str(tmpdir)) for instance_path in builder.results.values()} ufos = apply_instance_data(designspace.path, include_filenames=include_filenames) for filename in include_filenames or (): assert os.path.isdir(str(tmpdir / filename)) assert len(ufos) == len(builder.results) assert isinstance(ufos[0], defcon.Font)
def test_apply_instance_data(tmpdir, instance_names, ufo_module): font = glyphsLib.GSFont(os.path.join(DATA, "GlyphsUnitTestSans.glyphs")) instance_dir = "instances" designspace = glyphsLib.to_designspace(font, instance_dir=instance_dir) path = str(tmpdir / (font.familyName + ".designspace")) write_designspace_and_UFOs(designspace, path) test_designspace = DesignSpaceDocument() test_designspace.read(designspace.path) if instance_names is None: # Collect all instances. test_instances = [instance.filename for instance in test_designspace.instances] else: # Collect only selected instances. test_instances = [ instance.filename for instance in test_designspace.instances if instance.styleName in instance_names ] # Generate dummy UFOs for collected instances so we don't actually need to # interpolate. tmpdir.mkdir(instance_dir) for instance in test_instances: ufo = ufo_module.Font() ufo.save(str(tmpdir / instance)) ufos = apply_instance_data(designspace.path, include_filenames=test_instances) for filename in test_instances: assert os.path.isdir(str(tmpdir / filename)) assert len(ufos) == len(test_instances) for ufo in ufos: assert ufo.info.openTypeOS2WeightClass in { 100, 200, 300, 400, 500, 700, 900, 357, } assert ufo.info.openTypeOS2WidthClass is None # GlyphsUnitTestSans is wght only
def interpolate(ufos, master_dir, out_dir, instance_data, round_geometry=True): """Create MutatorMath designspace and generate instances. Returns instance UFOs. """ # Problem with this function: should take a designspace explicitly. from mutatorMath.ufo import build designspace_path, instance_files = build_designspace( ufos, master_dir, out_dir, instance_data) logger.info('Building instances') for path, _ in instance_files: clean_ufo(path) build(designspace_path, outputUFOFormatVersion=3, roundGeometry=round_geometry) instance_ufos = apply_instance_data(instance_files) return instance_ufos
def test_reencode_glyphs(tmpdir): data_dir = py.path.local(DATA) designspace_path = data_dir / "TestReencode.designspace" designspace_path.copy(tmpdir) ufo_path = data_dir / "TestReencode-Regular.ufo" ufo_path.copy(tmpdir.ensure_dir("TestReencode-Regular.ufo")) instance_dir = tmpdir.ensure_dir("instance_ufo") ufo_path.copy(instance_dir.ensure_dir("TestReencode-Regular.ufo")) ufo_path.copy(instance_dir.ensure_dir("TestReencodeUI-Regular.ufo")) ufos = apply_instance_data(str(tmpdir / "TestReencode.designspace")) assert len(ufos) == 2 assert ufos[0]["A"].unicode == 0x0041 assert ufos[0]["A.alt"].unicode is None assert ufos[0]["C"].unicode == 0x0043 # Reencode Glyphs: A.alt=0041, C= assert ufos[1]["A"].unicode is None assert ufos[1]["A.alt"].unicode == 0x0041 assert ufos[1]["C"].unicode is None