def testOuroborosKerning(rootPath, cleanUp=True): # that works, let's do it via MutatorMath path1, path2, path3 = makeTestFonts(rootPath) documentPath = os.path.join(rootPath, "kerningTest.designspace") doc = DesignSpaceDocumentWriter(documentPath, verbose=True) doc.addSource( path1, name="master_1", location=dict(width=0), copyLib=True, copyGroups=True, copyInfo=True, copyFeatures=True ) doc.addSource( path2, name="master_2", location=dict(width=1000), copyLib=False, copyGroups=False, copyInfo=False, copyFeatures=False, ) doc.startInstance(fileName=path3, familyName="TestInstance", styleName="Regular", location=dict(width=100)) doc.writeKerning(location=dict(width=500)) doc.endInstance() doc.save() # execute the designspace. Kerning errors should be tripped by the doc = DesignSpaceDocumentReader(documentPath, 2, roundGeometry=True, verbose=True, progressFunc=testingProgressFunc) doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True) if cleanUp: # remove the mess shutil.rmtree(path1) shutil.rmtree(path2) shutil.rmtree(path3) return True
def testOuroborosKerning(rootPath, cleanUp=True): # that works, let's do it via MutatorMath path1, path2, path3 = makeTestFonts(rootPath) documentPath = os.path.join(rootPath, 'kerningTest.designspace') logPath = os.path.join(rootPath,"kerningTest.log") try: testLogFile = open(logPath, 'w') testLogFile.close() except: print "Can't make a logfile." doc = DesignSpaceDocumentWriter(documentPath, verbose=True) doc.addSource( path1, name="master_1", location=dict(width=0), copyLib=True, copyGroups=True, copyInfo=True, copyFeatures=True, ) doc.addSource( path2, name="master_2", location=dict(width=1000), copyLib=False, copyGroups=False, copyInfo=False, copyFeatures=False, ) doc.startInstance(fileName=path3, familyName="TestInstance", styleName="Regular", location=dict(width=100) ) doc.writeKerning(location=dict(width=500)) doc.endInstance() doc.save() # execute the designspace. Kerning errors should be tripped by the doc = DesignSpaceDocumentReader(documentPath, 2, roundGeometry=True, verbose=True, logPath=logPath, progressFunc=testingProgressFunc) doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True) # did we log the error? report = u"""invalidInstance.ufo:\nThese kerning pairs failed validation and have been removed:\nglyphOne, public.kern2.@MMK_R_two (-400) conflicts with public.kern1.@MMK_L_one, glyphThree (-250)\npublic.kern1.@MMK_L_one, glyphThree (-250) conflicts with glyphOne, public.kern2.@MMK_R_two (-400)""" log = open(logPath, 'r') logText = log.read() log.close() #print logText #assert report in logText if cleanUp: # remove the mess shutil.rmtree(path1) shutil.rmtree(path2) shutil.rmtree(path3) return True
def testOuroborosKerning(rootPath, cleanUp=True): # that works, let's do it via MutatorMath path1, path2, path3 = makeTestFonts(rootPath) documentPath = os.path.join(rootPath, 'kerningTest.designspace') logPath = os.path.join(rootPath,"kerningTest.log") try: testLogFile = open(logPath, 'w') testLogFile.close() except: print("Can't make a logfile.") doc = DesignSpaceDocumentWriter(documentPath, verbose=True) doc.addSource( path1, name="master_1", location=dict(width=0), copyLib=True, copyGroups=True, copyInfo=True, copyFeatures=True, ) doc.addSource( path2, name="master_2", location=dict(width=1000), copyLib=False, copyGroups=False, copyInfo=False, copyFeatures=False, ) doc.startInstance(fileName=path3, familyName="TestInstance", styleName="Regular", location=dict(width=100) ) doc.writeKerning(location=dict(width=500)) doc.endInstance() doc.save() # execute the designspace. Kerning errors should be tripped by the doc = DesignSpaceDocumentReader(documentPath, 2, roundGeometry=True, verbose=True, logPath=logPath, progressFunc=testingProgressFunc) doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True) # did we log the error? report = u"""invalidInstance.ufo:\nThese kerning pairs failed validation and have been removed:\nglyphOne, public.kern2.@MMK_R_two (-400) conflicts with public.kern1.@MMK_L_one, glyphThree (-250)\npublic.kern1.@MMK_L_one, glyphThree (-250) conflicts with glyphOne, public.kern2.@MMK_R_two (-400)""" log = open(logPath, 'r') logText = log.read() log.close() #print logText #assert report in logText if cleanUp: # remove the mess shutil.rmtree(path1) shutil.rmtree(path2) shutil.rmtree(path3) return True
def testOuroborosKerning(rootPath, cleanUp=True): # that works, let's do it via MutatorMath path1, path2, path3 = makeTestFonts(rootPath) documentPath = os.path.join(rootPath, 'kerningTest.designspace') doc = DesignSpaceDocumentWriter(documentPath, verbose=True) doc.addSource( path1, name="master_1", location=dict(width=0), copyLib=True, copyGroups=True, copyInfo=True, copyFeatures=True, ) doc.addSource( path2, name="master_2", location=dict(width=1000), copyLib=False, copyGroups=False, copyInfo=False, copyFeatures=False, ) doc.startInstance(fileName=path3, familyName="TestInstance", styleName="Regular", location=dict(width=100)) doc.writeKerning(location=dict(width=500)) doc.endInstance() doc.save() # execute the designspace. Kerning errors should be tripped by the doc = DesignSpaceDocumentReader(documentPath, 2, roundGeometry=True, verbose=True, progressFunc=testingProgressFunc) doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True) if cleanUp: # remove the mess shutil.rmtree(path1) shutil.rmtree(path2) shutil.rmtree(path3) return True def test1(): """
def generate_designspace(family, path): def normalize_path(path): return os.path.join(family['working_directory'], path) doc = DesignSpaceDocumentWriter(normalize_path(path)) for i, master in enumerate(family['masters']): doc.addSource( path = normalize_path(master['path']), name = 'master-' + master['name'], location = {'weight': master['interpolation_value']}, copyLib = True if i == 0 else False, copyGroups = True if i == 0 else False, copyInfo = True if i == 0 else False, # muteInfo = False, # muteKerning = False, # mutedGlyphNames = None, ) for style in family['styles']: doc.startInstance( name = 'instance-' + style['name'], location = {'weight': style['interpolation_value']}, familyName = family['output_name'], styleName = style['name'], fileName = normalize_path(style['path']), postScriptFontName = style['output_full_name_postscript'], # styleMapFamilyName = None, # styleMapStyleName = None, ) doc.writeInfo() if family['has_kerning']: doc.writeKerning() doc.endInstance() doc.save()
def testMutingOptions(rootPath, cleanUp=True): # that works, let's do it via MutatorMath # path1 and path2 are masters. path3 is the instance path1, path2, path3 = makeTestFonts(rootPath) documentPath = os.path.join(rootPath, 'mutingTest.designspace') logPath = os.path.join(rootPath,"mutingTest.log") try: testLogFile = open(logPath, 'w') testLogFile.close() except: print "Can't make a logfile." doc = DesignSpaceDocumentWriter(documentPath, verbose=True) doc.addSource( path1, name="master_1", location=dict(width=0), copyLib=True, copyGroups=True, copyInfo=True, copyFeatures=True, muteKerning=True ) doc.addSource( path2, name="master_2", location=dict(width=1000), copyLib=False, copyGroups=False, copyInfo=False, copyFeatures=False, muteInfo=True, mutedGlyphNames=['glyphThree'] # mute glyphThree in master 1 ) doc.startInstance(fileName=path3, familyName="TestInstance", styleName="Regular", location=dict(width=500) ) doc.writeGlyph('glyphFour', mute=True) # mute glyphFour in the instance doc.writeKerning() doc.writeInfo() doc.endInstance() doc.save() # execute the designspace. doc = DesignSpaceDocumentReader(documentPath, 2, roundGeometry=True, verbose=True, logPath=logPath, progressFunc=testingProgressFunc) doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True) # look at the results m1 = Font(path1) m2 = Font(path2) r = Font(path3) # # the glyphThree master was muted in the second master # so the instance glyphThree should be the same as the first master: assert r['glyphThree'].bounds == m1['glyphThree'].bounds # we muted glyphFour in the instance. # so it should not be part of the instance UFO: assert "glyphFour" not in r # font.info is muted for master2, so the instance has to have the values from master 1 assert r.info.unitsPerEm == m1.info.unitsPerEm # kerning is muted for master1, so the instance has to have the kerning from master 2 assert r.kerning[('glyphOne', 'glyphOne')] == m2.kerning[('glyphOne', 'glyphOne')] if cleanUp: # remove the mess try: shutil.rmtree(path1) shutil.rmtree(path2) shutil.rmtree(path3) except: pass return True
def testMutingOptions(rootPath, cleanUp=True): # that works, let's do it via MutatorMath # path1 and path2 are masters. path3 is the instance path1, path2, path3 = makeTestFonts(rootPath) documentPath = os.path.join(rootPath, 'mutingTest.designspace') doc = DesignSpaceDocumentWriter(documentPath, verbose=True) doc.addSource(path1, name="master_1", location=dict(width=0), copyLib=True, copyGroups=True, copyInfo=True, copyFeatures=True, muteKerning=True) doc.addSource( path2, name="master_2", location=dict(width=1000), copyLib=False, copyGroups=False, copyInfo=False, copyFeatures=False, muteInfo=True, mutedGlyphNames=['glyphThree'] # mute glyphThree in master 1 ) doc.startInstance(fileName=path3, familyName="TestInstance", styleName="Regular", location=dict(width=500)) doc.writeGlyph('glyphFour', mute=True) # mute glyphFour in the instance doc.writeKerning() doc.writeInfo() doc.endInstance() doc.save() # execute the designspace. doc = DesignSpaceDocumentReader(documentPath, 2, roundGeometry=True, verbose=True, progressFunc=testingProgressFunc) doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True) # look at the results m1 = Font(path1) m2 = Font(path2) r = Font(path3) # # the glyphThree master was muted in the second master # so the instance glyphThree should be the same as the first master: assert r['glyphThree'].bounds == m1['glyphThree'].bounds # we muted glyphFour in the instance. # so it should not be part of the instance UFO: assert "glyphFour" not in r # font.info is muted for master2, so the instance has to have the values from master 1 assert r.info.unitsPerEm == m1.info.unitsPerEm # kerning is muted for master1, so the instance has to have the kerning from master 2 assert r.kerning[('glyphOne', 'glyphOne')] == m2.kerning[('glyphOne', 'glyphOne')] if cleanUp: # remove the mess try: shutil.rmtree(path1) shutil.rmtree(path2) shutil.rmtree(path3) except: pass return True
# dict(fileName="instances/Amstelvar-Italic-opsz144-wght100-wdth125.ufo", location=dict(wght=100, wdth=125, opsz=144), styleName="opsz144-wght100-wdth125", familyName=familyName, postScriptFontName=None, styleMapFamilyName=None, styleMapStyleName=None), # dict(fileName="instances/Amstelvar-Italic-opsz144-wght100-wdth075.ufo", location=dict(wght=100, wdth=87, opsz=144), styleName="opsz144-wght100-wdth075", familyName=familyName, postScriptFontName=None, styleMapFamilyName=None, styleMapStyleName=None), # dict(fileName="instances/Amstelvar-Italic-opsz144-wght100-wdth50.ufo", location=dict(wght=100, wdth=75, opsz=144), styleName="opsz144-wght100-wdth50", familyName=familyName, postScriptFontName=None, styleMapFamilyName=None, styleMapStyleName=None), # dict(fileName="instances/Amstelvar-Italic-opsz144-wght900-wdth125.ufo", location=dict(wght=900, wdth=125, opsz=144), styleName="opsz144-wght900-wdth125", familyName=familyName, postScriptFontName=None, styleMapFamilyName=None, styleMapStyleName=None), # dict(fileName="instances/Amstelvar-Italic-opsz144-wght900-wdth075.ufo", location=dict(wght=900, wdth=76, opsz=144), styleName="opsz144-wght900-wdth075", familyName=familyName, postScriptFontName=None, styleMapFamilyName=None, styleMapStyleName=None), # dict(fileName="instances/Amstelvar-Italic-opsz144-wght900-wdth50.ufo", location=dict(wght=900, wdth=75, opsz=144), styleName="opsz144-wght900-wdth50", familyName=familyName, postScriptFontName=None, styleMapFamilyName=None, styleMapStyleName=None), # dict(fileName="instances/Amstelvar-Italic-opsz144-wdth125.ufo", location=dict(wght=400, wdth=125, opsz=144), styleName="opsz144-wdth125", familyName=familyName, postScriptFontName=None, styleMapFamilyName=None, styleMapStyleName=None), # dict(fileName="instances/Amstelvar-Italic-opsz144-wdth075.ufo", location=dict(wght=400, wdth=80, opsz=144), styleName="opsz144-wdth075", familyName=familyName, postScriptFontName=None, styleMapFamilyName=None, styleMapStyleName=None), # dict(fileName="instances/Amstelvar-Italic-opsz144-wdth50.ufo", location=dict(wght=400, wdth=75, opsz=144), styleName="opsz144-wdth50", familyName=familyName, postScriptFontName=None, styleMapFamilyName=None, styleMapStyleName=None), ] for instance in instances: doc.startInstance(**instance) doc.writeInfo() doc.writeKerning() doc.endInstance() doc.save() # read and process the designspace doc = DesignSpaceDocumentReader(tmpDesignSpace, ufoVersion=2, roundGeometry=False, verbose=False) print("Reading DesignSpace...") doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True) os.remove(tmpDesignSpace) # clean up # update the instances with the source fonts # print str(instances) + ' instances! ' for instance in instances: