def testUnicodeValue(self, glyph): """ A Unicode value should appear only once per font. """ report = [] font = glyph.getParent() uni = glyph.unicode name = glyph.name # test against AGL expectedUni = AGL2UV.get(name) if expectedUni != uni: report.append("Incorrect Unicode value?: %s." % name) glyph.mark = (0, 0, 1, 0.3) # look for duplicates if uni is not None: duplicates = [] for name in sorted(font.keys()): if name == glyph.name: continue other = font[name] if other.unicode == uni: duplicates.append(name) glyph.mark = (0, 0, 1, 0.3) report.append("The Unicode for this glyph is also used by: %s" % " ".join(duplicates))
def testUnicodeValue(glyph): """ A Unicode value should appear only once per font. """ report = [] font = glyph.getParent() uni = glyph.unicode name = glyph.name # test for uniXXXX name m = uniNamePattern.match(name) if m is not None: uniFromName = m.group(1) uniFromName = int(uniFromName, 16) if uni != uniFromName: report.append( "The Unicode value for this glyph does not match its name.") # test against AGLFN else: expectedUni = AGL2UV.get(name) if expectedUni != uni: report.append( "The Unicode value for this glyph may not be correct.") # look for duplicates if uni is not None: duplicates = [] for name in sorted(font.keys()): if name == glyph.name: continue other = font[name] if other.unicode == uni: duplicates.append(name) if duplicates: report.append("The Unicode for this glyph is also used by: %s." % " ".join(duplicates)) return report
def compileDecompileCompareDumps(features, expectedDump): # make the font font = Font() font.info.unitsPerEm = 1000 font.info.ascender = 750 font.info.descender = -250 font.info.xHeight = 500 font.info.capHeight = 750 font.info.familyName = "Test" font.info.styleName = "Regular" glyphNames = [i for i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"] for glyphName in glyphNames: font.newGlyph(glyphName) glyph = font[glyphName] glyph.unicode = AGL2UV.get(glyphName) font.features.text = features # compile to OTF handle, path = tempfile.mkstemp() compiler = OTFCompiler() errors = compiler.compile(font, path)["makeotf"] # extract the features try: tables = decompileBinaryToObject(path, compress=True) # print compiler errors except TTLibError: print errors # get rid of the temp file finally: os.remove(path) # dump writer = DumpWriter() tables["GSUB"].write(writer) dump = writer.dump() # compare compareDumps(expectedDump, dump)
def testUnicodeValue(glyph): """ A Unicode value should appear only once per font. """ report = [] font = glyph.getParent() uni = glyph.unicode name = glyph.name # test for uniXXXX name m = uniNamePattern.match(name) if m is not None: uniFromName = m.group(1) uniFromName = int(uniFromName, 16) if uni != uniFromName: report.append("The Unicode value for this glyph does not match its name.") # test against AGLFN else: expectedUni = AGL2UV.get(name) if expectedUni != uni: report.append("The Unicode value for this glyph may not be correct.") # look for duplicates if uni is not None: duplicates = [] for name in sorted(font.keys()): if name == glyph.name: continue other = font[name] if other.unicode == uni: duplicates.append(name) if duplicates: report.append("The Unicode for this glyph is also used by: %s." % " ".join(duplicates)) return report
def _makeTestFont(): from fontTools.agl import AGL2UV from defcon import Font font = Font() for name in "ABCD": font.newGlyph(name) font.newGlyph(name + ".alt1") font.newGlyph(name + ".alt2") for glyph in font: glyph.unicode = AGL2UV.get(glyph.name) return font
def extractType1Glyphs(source, destination): glyphSet = source.getGlyphSet() for glyphName in sorted(glyphSet.keys()): sourceGlyph = glyphSet[glyphName] # make the new glyph destination.newGlyph(glyphName) destinationGlyph = destination[glyphName] # outlines pen = destinationGlyph.getPen() sourceGlyph.draw(pen) # width destinationGlyph.width = sourceGlyph.width # synthesize the unicode value destinationGlyph.unicode = AGL2UV.get(glyphName)
def test_unique_unicode_values(self): """ Font unicode values are unique? """ font = robofab.world.OpenFont(self.operator.path) for glyphname in font.keys(): glyph = font[glyphname] uni = glyph.unicode name = glyph.name # test for uniXXXX name m = uniNamePattern.match(name) if m is not None: uniFromName = m.group(1) uniFromName = int(uniFromName, 16) if uni != uniFromName: self.fail(("Unicode value of glyph {} " "does not match glyph name " "of uniXXXX").format(name)) # test against AGLFN else: expectedUni = AGL2UV.get(name) if expectedUni != uni: self.fail(("Unicode value of glyph {} " "does not match glyph name " "from fontTools AGL2UV").format(name)) # look for duplicates if uni is not None: duplicates = [] for name in sorted(font.keys()): if name == glyph.name: continue other = font[name] if other.unicode == uni: duplicates.append(name) if duplicates: self.fail( "Unicode value of {0} is also used by {1}".format( glyph.name, " ".join(duplicates)))
def test_unique_unicode_values(self): """ Font unicode values are unique? """ font = robofab.world.OpenFont(self.operator.path) for glyphname in font.keys(): glyph = font[glyphname] uni = glyph.unicode name = glyph.name # test for uniXXXX name m = uniNamePattern.match(name) if m is not None: uniFromName = m.group(1) uniFromName = int(uniFromName, 16) if uni != uniFromName: self.fail(("Unicode value of glyph {} " "does not match glyph name " "of uniXXXX").format(name)) # test against AGLFN else: expectedUni = AGL2UV.get(name) if expectedUni != uni: self.fail(("Unicode value of glyph {} " "does not match glyph name " "from fontTools AGL2UV").format(name)) # look for duplicates if uni is not None: duplicates = [] for name in sorted(font.keys()): if name == glyph.name: continue other = font[name] if other.unicode == uni: duplicates.append(name) if duplicates: self.fail("Unicode value of {0} is also used by {1}".format(glyph.name, " ".join(duplicates)))
def testUnicodeValue(glyph): """ A Unicode value should appear only once per font. """ report = [] font = glyph.getParent() uni = glyph.unicode name = glyph.name # test against AGL expectedUni = AGL2UV.get(name) if expectedUni != uni: report.append("The Unicode value for this glyph may not be correct.") # look for duplicates if uni is not None: duplicates = [] for name in sorted(font.keys()): if name == glyph.name: continue other = font[name] if other.unicode == uni: duplicates.append(name) report.append("The Unicode for this glyph is also used by: %s." % " ".join(duplicates)) return report
def testUnicodeValue(self): """ A Unicode value should appear only once per font """ font = robofab.world.OpenFont(self.operator.path) for glyphname in font.keys(): glyph = font[glyphname] uni = glyph.unicode name = glyph.name # test for uniXXXX name m = uniNamePattern.match(name) if m is not None: uniFromName = m.group(1) uniFromName = int(uniFromName, 16) if uni != uniFromName: self.fail("The Unicode value for {} does not match its name.".format(name)) # test against AGLFN else: expectedUni = AGL2UV.get(name) if expectedUni != uni: self.fail("The Unicode value for {} may not be correct.".format(name)) # look for duplicates if uni is not None: duplicates = [] for name in sorted(font.keys()): if name == glyph.name: continue other = font[name] if other.unicode == uni: duplicates.append(name) if duplicates: self.fail("The Unicode for {0} is also used by: {1}.".format(glyph.name, " ".join(duplicates)))