def assertUFORoundtrip(self, font): self._normalize(font) expected = write_to_lines(font) # Don't propagate anchors when intending to round-trip designspace = to_designspace( font, propagate_anchors=False, minimize_glyphs_diffs=True) # Check that round-tripping in memory is the same as writing on disk roundtrip_in_mem = to_glyphs(designspace) self._normalize(roundtrip_in_mem) actual_in_mem = write_to_lines(roundtrip_in_mem) directory = tempfile.mkdtemp() path = os.path.join(directory, font.familyName + '.designspace') write_designspace_and_UFOs(designspace, path) designspace_roundtrip = DesignSpaceDocument() designspace_roundtrip.read(path) roundtrip = to_glyphs(designspace_roundtrip) self._normalize(roundtrip) actual = write_to_lines(roundtrip) with open('expected.txt', 'w') as f: f.write('\n'.join(expected)) with open('actual_in_mem.txt', 'w') as f: f.write('\n'.join(actual_in_mem)) with open('actual.txt', 'w') as f: f.write('\n'.join(actual)) self.assertLinesEqual( actual_in_mem, actual, "The round-trip in memory or written to disk should be equivalent") self.assertLinesEqual( expected, actual, "The font should not be modified by the roundtrip")
def test_master_with_light_weight_but_thin_name(self): font = generate_minimal_font() master = font.masters[0] name = "Thin" # In Glyphs.app, show "Thin" in the sidebar weight = "Light" # In Glyphs.app, have the light "n" icon width = None # No data => should be equivalent to Regular custom_name = "Thin" master.set_all_name_components(name, weight, width, custom_name) assert master.name == "Thin" assert master.weight == "Light" ufo, = to_ufos(font) font_rt = to_glyphs([ufo]) master_rt = font_rt.masters[0] assert master_rt.name == "Thin" assert master_rt.weight == "Light" tmpdir = tempfile.mkdtemp() try: filename = os.path.join(tmpdir, "test.glyphs") font_rt.save(filename) font_rt_written = GSFont(filename) master_rt_written = font_rt_written.masters[0] assert master_rt_written.name == "Thin" assert master_rt_written.weight == "Light" finally: shutil.rmtree(tmpdir)
def assertDesignspaceRoundtrip(self, designspace): directory = tempfile.mkdtemp() font = to_glyphs(designspace, minimize_ufo_diffs=True) # Check that round-tripping in memory is the same as writing on disk roundtrip_in_mem = to_designspace(font, propagate_anchors=False) tmpfont_path = os.path.join(directory, "font.glyphs") font.save(tmpfont_path) font_rt = classes.GSFont(tmpfont_path) roundtrip = to_designspace(font_rt, propagate_anchors=False) font.save("intermediary.glyphs") write_designspace_and_UFOs(designspace, "expected/test.designspace") for source in designspace.sources: normalize_ufo_lib(source.path) normalizeUFO(source.path, floatPrecision=3, writeModTimes=False) write_designspace_and_UFOs(roundtrip, "actual/test.designspace") for source in roundtrip.sources: normalize_ufo_lib(source.path) normalizeUFO(source.path, floatPrecision=3, writeModTimes=False) self.assertDesignspacesEqual( roundtrip_in_mem, roundtrip, "The round-trip in memory or written to disk should be equivalent", ) self.assertDesignspacesEqual( designspace, roundtrip, "The font should not be modified by the roundtrip" )
def test_italic_angle(self): font = generate_minimal_font() ufo, = to_ufos(font) ufo.info.italicAngle = 1 ufo_rt, = to_ufos(to_glyphs([ufo])) assert ufo_rt.info.italicAngle == 1 ufo.info.italicAngle = 1.5 ufo_rt, = to_ufos(to_glyphs([ufo])) assert ufo_rt.info.italicAngle == 1.5 ufo.info.italicAngle = 0 font_rt = to_glyphs([ufo]) assert font_rt.masters[0].italicAngle == 0 ufo_rt, = to_ufos(font_rt) assert ufo_rt.info.italicAngle == 0
def test_unique_masterid(self): font = generate_minimal_font() master2 = GSFontMaster() master2.ascender = 0 master2.capHeight = 0 master2.descender = 0 master2.xHeight = 0 font.masters.append(master2) ufos = to_ufos(font, minimize_glyphs_diffs=True) try: to_glyphs(ufos) except Exception as e: self.fail("Unexpected exception: " + str(e)) ufos[1].lib["com.schriftgestaltung.fontMasterID"] = ufos[0].lib[ "com.schriftgestaltung.fontMasterID" ] font_rt = to_glyphs(ufos) assert len({m.id for m in font_rt.masters}) == 2
def assertUFORoundtrip(self, font): expected = write_to_lines(font) roundtrip = to_glyphs(to_ufos(font)) actual = write_to_lines(roundtrip) self.assertLinesEqual(expected, actual, "The font has been modified by the roundtrip")