def testCustomFileNamingScheme(self): def myGlyphNameToFileName(glyphName, glyphSet): return "prefix" + glyphNameToFileName(glyphName, glyphSet) src = GlyphSet(GLYPHSETDIR) dst = GlyphSet(self.dstDir, myGlyphNameToFileName) for glyphName in src.keys(): g = src[glyphName] g.drawPoints(None) # load attrs dst.writeGlyph(glyphName, g, g.drawPoints) d = {} for k, v in src.contents.items(): print k, v d[k] = "prefix" + v self.assertEqual(d, dst.contents)
def testReverseContents2(self): src = GlyphSet(GLYPHSETDIR) dst = GlyphSet(self.dstDir) dstMap = dst.getReverseContents() self.assertEqual(dstMap, {}) for glyphName in src.keys(): g = src[glyphName] g.drawPoints(None) # load attrs dst.writeGlyph(glyphName, g, g.drawPoints) self.assertNotEqual(dstMap, {}) srcMap = dict(src.getReverseContents()) # copy self.assertEqual(dstMap, srcMap) del srcMap["a.glif"] dst.deleteGlyph("a") self.assertEqual(dstMap, srcMap)
def testCustomFileNamingScheme(self): def myGlyphNameToFileName(glyphName, glyphSet): return "prefix" + glyphNameToFileName(glyphName, glyphSet) src = GlyphSet(GLYPHSETDIR) dst = GlyphSet(self.dstDir, myGlyphNameToFileName) for glyphName in src.keys(): g = src[glyphName] g.drawPoints(None) # load attrs dst.writeGlyph(glyphName, g, g.drawPoints) d = {} for k, v in src.contents.items(): print k, v d[k] = "prefix" + v self.assertEqual(d, dst.contents)
def testRoundTrip(self): srcDir = GLYPHSETDIR dstDir = self.dstDir src = GlyphSet(srcDir) dst = GlyphSet(dstDir) for glyphName in src.keys(): g = src[glyphName] g.drawPoints(None) # load attrs dst.writeGlyph(glyphName, g, g.drawPoints) # compare raw file data: for glyphName in src.keys(): fileName = src.contents[glyphName] org = file(os.path.join(srcDir, fileName), READ_MODE).read() new = file(os.path.join(dstDir, fileName), READ_MODE).read() self.assertEqual(org, new, "%r .glif file differs after round tripping" % glyphName)
def testReverseContents2(self): src = GlyphSet(GLYPHSETDIR) dst = GlyphSet(self.dstDir) dstMap = dst.getReverseContents() self.assertEqual(dstMap, {}) for glyphName in src.keys(): g = src[glyphName] g.drawPoints(None) # load attrs dst.writeGlyph(glyphName, g, g.drawPoints) self.assertNotEqual(dstMap, {}) srcMap = dict(src.getReverseContents()) # copy self.assertEqual(dstMap, srcMap) del srcMap["a.glif"] dst.deleteGlyph("a") self.assertEqual(dstMap, srcMap)
def testRoundTrip(self): srcDir = GLYPHSETDIR dstDir = self.dstDir src = GlyphSet(srcDir) dst = GlyphSet(dstDir) for glyphName in src.keys(): g = src[glyphName] g.drawPoints(None) # load attrs dst.writeGlyph(glyphName, g, g.drawPoints) # compare raw file data: for glyphName in src.keys(): fileName = src.contents[glyphName] org = file(os.path.join(srcDir, fileName), READ_MODE).read() new = file(os.path.join(dstDir, fileName), READ_MODE).read() self.assertEqual( org, new, "%r .glif file differs after round tripping" % glyphName)
print "selection", todo if g is not None: todo.append(g.name) for f in AllFonts(): ufoPath = None print "f.path", f, f.path if f.path is None: # huh, in case there is a ghost font. print "skipping", f continue ufoPath = f.path.replace(".vfb", ".ufo") if not os.path.exists(ufoPath): ufoPath = GetFolder("Select a UFO to save the GLIF in:") if ufoPath.find(".ufo") == -1: Message("You need to select an UFO. Quitting.") ufoPath = None if ufoPath is None: continue for c in todo: if c not in f: print "font is missing", c continue g = f[c] path = os.path.join(os.path.dirname(ufoPath), os.path.basename(ufoPath), "glyphs") print "saving glyph %s in %s"%(g.name, path) gs = GlyphSet(path, glyphNameToFileNameFunc=glyphNameToShortFileName) gs.writeGlyph(g.name, g, g.drawPoints) gs.writeContents() print 'done'
"""Read all glyphs from the demo font, and write them out again. This is useful for testing round-tripping stability, but also to update the font when the GLIF format changes. The third application is to update the contents.plist file in case glyphs have been added or removed. """ import os from robofab.test.testSupport import getDemoFontPath from robofab.glifLib import GlyphSet from robofab.pens.adapterPens import GuessSmoothPointPen ufoPath = getDemoFontPath() glyphSet = GlyphSet(os.path.join(ufoPath, "glyphs")) glyphSet.rebuildContents( ) # ignore existing contents.plist, rebuild from dir listing for name in glyphSet.keys(): g = glyphSet[name] g.drawPoints(None) # force all attrs to be loaded def drawPoints(pen): pen = GuessSmoothPointPen(pen) g.drawPoints(pen) glyphSet.writeGlyph(name, g, drawPoints) glyphSet.writeContents() # write out contents.plist
"""Read all glyphs from the demo font, and write them out again. This is useful for testing round-tripping stability, but also to update the font when the GLIF format changes. The third application is to update the contents.plist file in case glyphs have been added or removed. """ import os from robofab.test.testSupport import getDemoFontPath from robofab.glifLib import GlyphSet from robofab.pens.adapterPens import GuessSmoothPointPen ufoPath = getDemoFontPath() glyphSet = GlyphSet(os.path.join(ufoPath, "glyphs")) glyphSet.rebuildContents() # ignore existing contents.plist, rebuild from dir listing for name in glyphSet.keys(): g = glyphSet[name] g.drawPoints(None) # force all attrs to be loaded def drawPoints(pen): pen = GuessSmoothPointPen(pen) g.drawPoints(pen) glyphSet.writeGlyph(name, g, drawPoints) glyphSet.writeContents() # write out contents.plist