def makeTestFonts(rootPath): """ Make some test fonts that have the kerning problem.""" path1 = os.path.join(rootPath, "geometryMaster1.ufo") path2 = os.path.join(rootPath, "geometryMaster2.ufo") path3 = os.path.join(rootPath, "my_test_instance_dir_one", "geometryInstance%3.3f.ufo") path4 = os.path.join(rootPath, "my_test_instance_dir_two", "geometryInstanceAnisotropic1.ufo") path5 = os.path.join(rootPath, "my_test_instance_dir_two", "geometryInstanceAnisotropic2.ufo") f1 = Font() fillInfo(f1) addGlyphs(f1, 100) f1.features.text = u"# features text from master 1" f2 = Font() fillInfo(f2) addGlyphs(f2, 500) f2.features.text = u"# features text from master 2" f1.info.ascender = 400 f1.info.descender = -200 f2.info.ascender = 600 f2.info.descender = -100 f1.info.copyright = u"This is the copyright notice from master 1" f2.info.copyright = u"This is the copyright notice from master 2" f1.lib['ufoProcessor.test.lib.entry'] = "Lib entry for master 1" f2.lib['ufoProcessor.test.lib.entry'] = "Lib entry for master 2" f1.save(path1, 2) f2.save(path2, 2) return path1, path2, path3, path4, path5
def makeSwapFonts(rootPath): """ Make some test fonts that have the kerning problem.""" path1 = os.path.join(rootPath, "Swap.ufo") path2 = os.path.join(rootPath, "Swapped.ufo") f1 = Font() fillInfo(f1) addGlyphs(f1, 100) f1.features.text = u"# features text from master 1" f1.info.ascender = 800 f1.info.descender = -200 f1.kerning[('glyphOne', 'glyphOne')] = -10 f1.kerning[('glyphTwo', 'glyphTwo')] = 10 f1.save(path1, 2) return path1, path2
def makeTestFonts(rootPath): """ Make some test fonts that have the kerning problem.""" path1 = os.path.join(rootPath, "mutingMaster1.ufo") path2 = os.path.join(rootPath, "mutingMaster2.ufo") path3 = os.path.join(rootPath, "mutedGlyphInstance.ufo") # Two masters f1 = Font() addGlyphs(f1, 0) f1.info.unitsPerEm = 1000 f1.kerning[('glyphOne', 'glyphOne')] = -100 f2 = Font() addGlyphs(f2, 33) f2.info.unitsPerEm = 2000 f2.kerning[('glyphOne', 'glyphOne')] = -200 # save f1.save(path1, 3) f2.save(path2, 3) return path1, path2, path3
def _makeTestFonts(rootPath): """ Make some test fonts that have the kerning problem.""" path1 = os.path.join(rootPath, "masters", "geometryMaster1.ufo") path2 = os.path.join(rootPath, "masters", "geometryMaster2.ufo") path3 = os.path.join(rootPath, "instances", "geometryInstance%3.3f.ufo") path4 = os.path.join(rootPath, "anisotropic_instances", "geometryInstanceAnisotropic1.ufo") path5 = os.path.join(rootPath, "anisotropic_instances", "geometryInstanceAnisotropic2.ufo") f1 = Font() fillInfo(f1) addGlyphs(f1, 100) f1.features.text = u"# features text from master 1" f2 = Font() fillInfo(f2) addGlyphs(f2, 500) f2.features.text = u"# features text from master 2" f1.info.ascender = 400 f1.info.descender = -200 f2.info.ascender = 600 f2.info.descender = -100 f1.info.copyright = u"This is the copyright notice from master 1" f2.info.copyright = u"This is the copyright notice from master 2" f1.lib['ufoProcessor.test.lib.entry'] = "Lib entry for master 1" f2.lib['ufoProcessor.test.lib.entry'] = "Lib entry for master 2" f1.groups["public.kern1.groupA"] = ['glyphOne', 'glyphTwo'] f1.groups["public.kern2.groupB"] = ['glyphThree', 'glyphFour'] f2.groups.update(f1.groups) f1.kerning[('public.kern1.groupA', 'public.kern2.groupB')] = -100 f2.kerning[('public.kern1.groupA', 'public.kern2.groupB')] = -200 f1.kerning[('glyphOne', 'glyphOne')] = -100 f2.kerning[('glyphOne', 'glyphOne')] = 0 f1.kerning[('glyphOne', 'glyphThree')] = 10 f1.kerning[('glyphOne', 'glyphFour')] = 10 # exception f2.kerning[('glyphOne', 'glyphThree')] = 1 f2.kerning[('glyphOne', 'glyphFour')] = 0 f1.save(path1, 3) f2.save(path2, 3) return path1, path2, path3, path4, path5
def makeTestFonts(rootPath): """ Make some test fonts that have the kerning problem.""" path1 = os.path.join(rootPath, "geometryMaster1.ufo") path2 = os.path.join(rootPath, "geometryMaster2.ufo") path3 = os.path.join(rootPath, "geometryInstance.ufo") path4 = os.path.join(rootPath, "geometryInstanceAnisotropic1.ufo") path5 = os.path.join(rootPath, "geometryInstanceAnisotropic2.ufo") # Two masters f1 = Font() addGlyphs(f1, 100) f2 = Font() addGlyphs(f2, 500) fillInfo(f1) fillInfo(f2) # save f1.save(path1, 2) f2.save(path2, 2) return path1, path2, path3, path4, path5
def testSwap(docPath): srcPath, dstPath = _makeSwapFonts(os.path.dirname(docPath)) f = Font(srcPath) swapGlyphNames(f, "narrow", "wide") f.info.styleName = "Swapped" f.save(dstPath) # test the results in newly opened fonts old = Font(srcPath) new = Font(dstPath) assert new.kerning.get(("narrow", "narrow")) == old.kerning.get( ("wide", "wide")) assert new.kerning.get(("wide", "wide")) == old.kerning.get( ("narrow", "narrow")) # after the swap these widths should be the same assert old['narrow'].width == new['wide'].width assert old['wide'].width == new['narrow'].width # The following test may be a bit counterintuitive: # the rule swaps the glyphs, but we do not want glyphs that are not # specifically affected by the rule to *appear* any different. # So, components have to be remapped. assert new['wide.component'].components[0].baseGlyph == "narrow" assert new['narrow.component'].components[0].baseGlyph == "wide"
def makeTestFonts(rootPath): """ Make some test fonts that have the kerning problem.""" path1 = os.path.join(rootPath, "validMaster1.ufo") path2 = os.path.join(rootPath, "validMaster2.ufo") path3 = os.path.join(rootPath, "invalidInstance.ufo") # Two masters f1 = Font() f1.groups['public.kern1.@MMK_L_one'] = ['glyphOne', 'glyphTwo'] f1.groups['public.kern2.@MMK_R_two'] = ['glyphThree', 'glyphFour'] addGlyphs(f1) f2 = Font() f2.groups.update(f1.groups) # both masters have the same groups addGlyphs(f2) assert f1.groups == f2.groups # a normal group / group pair in each master f1.kerning[('public.kern1.@MMK_L_one', 'public.kern2.@MMK_R_two')] = 1000 f1.kerning[('a', 'b')] = 10 f2.kerning[('public.kern1.@MMK_L_one', 'public.kern2.@MMK_R_two')] = 2000 f2.kerning[('a', 'b')] = 10 # a valid exception to this pair in each master f1.kerning[('public.kern1.@MMK_L_one', 'glyphThree')] = -500 f2.kerning[('glyphOne', 'public.kern2.@MMK_R_two')] = -800 # make sure the kerning and groups in each master validate. #assert kerningValidatorReportPairs(f1.kerning, f1.groups) == (True, [], []) #assert kerningValidatorReportPairs(f2.kerning, f2.groups) == (True, [], []) # save f1.save(path1, 3) f2.save(path2, 3) return path1, path2, path3
from defcon.objects.font import Font import os glyphOrder = [] with open("glyphorder.txt", "r") as f: glyphOrder = f.read().splitlines() DIR = "master_ufo" for fn in os.listdir(DIR): if fn.endswith(".ufo"): font = Font(os.path.join(DIR, fn)) font.glyphOrder = glyphOrder font.save() print fn print "Done"