def _load_fontfile(self): try: if self.fontfile.endswith(".ufo") or self.fontfile.endswith("tf"): # Single master workflow self.font = Babelfont.open(self.fontfile) self.variations = None else: self.variations = VariableFont(self.fontfile) # We need a "scratch copy" because we will be trashing the # glyph data with our interpolations if len(self.variations.masters.keys()) == 1: self.font = list(self.variations.masters.values())[0] self.variations = None else: firstmaster = self.variations.designspace.sources[0].path if firstmaster: self.font = Babelfont.open(firstmaster) else: # Glyphs, fontlab? self.font = Babelfont.open(self.fontfile) except Exception as e: if self.editor: self.editor.showError("Couldn't open %s: %s" % (self.fontfile, e)) else: raise e return False return True
def load_masters(self): if self.masters: return for src in self.config["sources"]: if src.endswith("glyphs"): gsfont = glyphsLib.GSFont(src) self.masters[src] = [] for master in gsfont.masters: self.masters[src].append( Babelfont.open(src, master=master.name)) elif src.endswith("designspace"): continue else: self.masters[src] = [Babelfont.open(src)]
def test_roundtrip(): if sys.platform != "darwin": pytest.skip("Needs to be run on OS X") font = Babelfont.open("tests/data/Test1.glyphs") Babelfont.save(font, "tests/data/Test1.roundtrip.glyphs") pl1_json = subprocess.run( ["plutil", "-convert", "xml1", "-o", "-", "tests/data/Test1.glyphs"], capture_output=True, ) pl2_json = subprocess.run( [ "plutil", "-convert", "xml1", "-o", "-", "tests/data/Test1.roundtrip.glyphs" ], capture_output=True, ) pl1 = plistlib.load(BytesIO(pl1_json.stdout)) pl2 = plistlib.load(BytesIO(pl2_json.stdout)) assert pl1 == pl2
def test_load_glyph(): filename = "tests/data/Castoro Roman.vfj" font = Babelfont.open(filename) assert len(font["A"].contours[0]) == 20 assert len(font["A"].contours[1]) == 4
def test_loader(): filename = "tests/data/Castoro Roman.vfj" font = Babelfont.open(filename)
def test_ufo_roundtrip(): font = Babelfont.open("tests/data/Test1.ufo") Babelfont.save(font, "tests/data/Test1.roundtrip.ufo") dc1 = defcon.Font("tests/data/Test1.ufo") dc2 = defcon.Font("tests/data/Test1.roundtrip.ufo") assert dc1.getDataForSerialization() == dc2.getDataForSerialization()
def test_ufo_load(): font = Babelfont.open("tests/data/Test1.ufo") assert font.glyphForCodepoint(ord("A")) == "A"
def test_ufo_to_glyphs(): font = Babelfont.open("tests/data/Test1.ufo") Babelfont.save(font, "tests/data/Test1-from-ufo.glyphs")
def test_glyphs_to_ufo(): font = Babelfont.open("tests/data/Test1.glyphs") Babelfont.save(font, "tests/data/Test1-from-glyphs.ufo")