| 1 | import sys |
| 2 | import fontforge |
| 3 | |
| 4 | # This script looks for bugs in remove overlap. The only way I know to do that |
| 5 | # is to pile shapes on top of one another and see if remove overlap has problems |
| 6 | # with the combination. To this end we take an already existing font (as a |
| 7 | # command line argument) and test all combinations of two glyphs. Failure |
| 8 | # notices should appear on stderr with the two glyphs that cause the problem |
| 9 | # indicated by "<glyphname1>__<glyphname2>". |
| 10 | # Even nastier is to reverse the direction of one of the glyphs. Currently |
| 11 | # that is commented out. |
| 12 | |
| 13 | font = fontforge.open(sys.argv[1]) |
| 14 | font.encoding = "Original" |
| 15 | font.unlinkReferences() |
| 16 | testf = fontforge.font() |
| 17 | testf.em = font.em |
| 18 | testf.layers["Fore"].is_quadratic = font.layers["Fore"].is_quadratic |
| 19 | testg = testf.createChar(0x65) |
| 20 | |
| 21 | i=0 |
| 22 | cnt = len(font) |
| 23 | while ( i<cnt ) : |
| 24 | g1 = font[i] |
| 25 | fore1 = g1.foreground |
| 26 | j=i |
| 27 | while ( j<cnt ) : |
| 28 | g2 = font[j] |
| 29 | fore2 = g2.foreground |
| 30 | testg.foreground = fore1 + fore2 |
| 31 | testg.glyphname = g1.glyphname + "__" + g2.glyphname |
| 32 | testg.removeOverlap() |
| 33 | #Contour order seems to matter... (It shouldn't, but it can) |
| 34 | testg.foreground = fore2 + fore1 |
| 35 | testg.glyphname = g2.glyphname + "__" + g1.glyphname |
| 36 | testg.removeOverlap() |
| 37 | #And then reversing the direction |
| 38 | # testg.foreground = fore1 + fore2.reverseDirection() |
| 39 | # testg.glyphname = g1.glyphname + "__" + g2.glyphname + "_R" |
| 40 | # testg.removeOverlap() |
| 41 | j += 1 |
| 42 | i+=1 |