| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import sys, fontforge |
| 16 |
|
| 17 |
dontFailTest = False |
| 18 |
|
| 19 |
problemsSeen = 0 |
| 20 |
|
| 21 |
inputFilepath = sys.argv[1] |
| 22 |
print("Opening input file '" + inputFilepath + "'") |
| 23 |
font1 = fontforge.open(inputFilepath) |
| 24 |
|
| 25 |
print(" Font '%s' from %s" % (font1.fontname, font1.path)) |
| 26 |
print("") |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
glyphNamesInGIDOrder = [] |
| 32 |
glyphNamesInEncOrder = [] |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
if True: |
| 41 |
print("Listing glyph names over range of encoding values:") |
| 42 |
|
| 43 |
|
| 44 |
for enc in range(1024): |
| 45 |
if enc in font1: |
| 46 |
glyph = font1[enc] |
| 47 |
glyphName = glyph.glyphname |
| 48 |
print(" {:3d} glyphName: '{}'".format(enc, glyphName)) |
| 49 |
glyphNamesInEncOrder.append(glyphName) |
| 50 |
|
| 51 |
|
| 52 |
print("") |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
iterGlyph = font1 |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
if True: |
| 68 |
print("Listing glyph names using \"for glyphName in font:\" iterator:") |
| 69 |
|
| 70 |
for glyphName in iterGlyph: |
| 71 |
glyph = font1[glyphName] |
| 72 |
enc = glyph.encoding |
| 73 |
print(" {:3d} glyphName: '{}'".format(enc, glyphName)) |
| 74 |
glyphNamesInGIDOrder.append(glyphName) |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
if len(glyphNamesInEncOrder) != len(glyphNamesInGIDOrder): |
| 79 |
print("*Error: the list of glyph names saved from using font iterator does not match the lists from other API usage") |
| 80 |
print(" Previous list count: {:d}".format(len(glyphNamesInEncOrder))) |
| 81 |
print(" this list count: {:d}".format(len(glyphNamesInGIDOrder))) |
| 82 |
print(" Previous list: {}".format(glyphNamesInEncOrder)) |
| 83 |
print(" this list: {}".format(glyphNamesInGIDOrder)) |
| 84 |
problemsSeen += 1 |
| 85 |
|
| 86 |
print("") |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
if True: |
| 91 |
print("Listing glyph names using font.glyphs() iterator:") |
| 92 |
|
| 93 |
glyphNames = [] |
| 94 |
|
| 95 |
for glyph in font1.glyphs(): |
| 96 |
glyphName = glyph.glyphname |
| 97 |
enc = glyph.encoding |
| 98 |
print(" {:3d} glyphName: '{}'".format(enc, glyphName)) |
| 99 |
glyphNames.append(glyphName) |
| 100 |
|
| 101 |
|
| 102 |
if glyphNamesInGIDOrder != glyphNames: |
| 103 |
print("*Error: the list of glyph names saved from using iterator font.glyphs() does not match the lists from other API usage") |
| 104 |
print(" Previous list count: {:d}".format(len(glyphNamesInGIDOrder))) |
| 105 |
print(" this list count: {:d}".format(len(glyphNames))) |
| 106 |
print(" Previous list: {}".format(glyphNamesInGIDOrder)) |
| 107 |
print(" this list: {}".format(glyphNames)) |
| 108 |
problemsSeen += 1 |
| 109 |
|
| 110 |
print("") |
| 111 |
|
| 112 |
print("Listing glyph names using font.glyphs('encoding') iterator:") |
| 113 |
|
| 114 |
glyphNames = [] |
| 115 |
|
| 116 |
for glyph in font1.glyphs('encoding'): |
| 117 |
glyphName = glyph.glyphname |
| 118 |
enc = glyph.encoding |
| 119 |
print(" {:3d} glyphName: '{}'".format(enc, glyphName)) |
| 120 |
glyphNames.append(glyphName) |
| 121 |
|
| 122 |
|
| 123 |
if glyphNamesInEncOrder != glyphNames: |
| 124 |
print("*Error: the list of glyph names saved from using iterator font.glyphs('encoding') does not match the lists from other API usage") |
| 125 |
print(" Previous list count: {:d}".format(len(glyphNamesInEncOrder))) |
| 126 |
print(" this list count: {:d}".format(len(glyphNames))) |
| 127 |
print(" Previous list: {}".format(glyphNamesInEncOrder)) |
| 128 |
print(" this list: {}".format(glyphNames)) |
| 129 |
problemsSeen += 1 |
| 130 |
|
| 131 |
print("") |
| 132 |
|
| 133 |
|
| 134 |
if True: |
| 135 |
print("Listing glyph names in list and checking with \"glyphName in font\":") |
| 136 |
|
| 137 |
glyphNames = [] |
| 138 |
|
| 139 |
for glyphName in glyphNamesInEncOrder: |
| 140 |
if glyphName in font1: |
| 141 |
glyph = font1[glyphName] |
| 142 |
enc = glyph.encoding |
| 143 |
print(" {:3d} glyphName: '{}'".format(enc, glyphName)) |
| 144 |
glyphNames.append(glyphName) |
| 145 |
else: |
| 146 |
print("*Warning: known glyph name '{:s}' not found using test \"'{:s}' in font\"".format(glyphName, glyphName)) |
| 147 |
|
| 148 |
if glyphNamesInEncOrder != glyphNames: |
| 149 |
print("*Error: the list of glyph names found using \"glyphName in font\" does not match the lists from other API usage") |
| 150 |
print(" Previous list count: {:d}".format(len(glyphNamesInEncOrder))) |
| 151 |
print(" this list count: {:d}".format(len(glyphNames))) |
| 152 |
print(" Previous list: {}".format(glyphNamesInEncOrder)) |
| 153 |
print(" this list: {}".format(glyphNames)) |
| 154 |
problemsSeen += 1 |
| 155 |
|
| 156 |
print("") |
| 157 |
|
| 158 |
|
| 159 |
if problemsSeen: |
| 160 |
if dontFailTest: |
| 161 |
print(" %d problem results were detected - would fail this test..." % (problemsSeen)) |
| 162 |
print(" but 'no fail' flag set.") |
| 163 |
sys.exit(0) |
| 164 |
else: |
| 165 |
print(" %d problem results were detected - failing this test!" % (problemsSeen)) |
| 166 |
sys.exit(" %d failing glyphs were detected - failing this test!" % (problemsSeen)) |
| 167 |
else: |
| 168 |
print(" No problems found - test successful") |
| 169 |
sys.exit(0) |
| 170 |
|
| 171 |
|