Debian Codegraph @

texmf-dist/doc/fonts/gnu-freefont/tools/test/validate.py

raw
1 #!/usr/bin/env ../utility/fontforge-interp.sh
2 __license__ = """
3 This file is part of Gnu FreeFont.
4
5 Gnu FreeFont is free software: you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation, either version 3 of the License, or (at your option) any later
8 version.
9
10 Gnu FreeFont is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 Gnu FreeFont. If not, see <http://www.gnu.org/licenses/>.
16 """
17 __author__ = "Stevan White"
18 __email__ = "[email protected]"
19 __copyright__ = "Copyright 2009, 2010, Stevan White"
20 __date__ = "$Date: 2010-09-14 13:02:02 $"
21 __version__ = "$Revision: 1.5 $"
22
23 __doc__ = """
24 Runs the FontForge validate function on all the font faces.
25 Prints report on standard output.
26 Returns 1 if problems found 0 otherwise.
27 """
28
29 import fontforge
30 import sys
31
32 problem = False
33
34
35 """ Haven't really figured out why TT limit warniings are turndd on,
36 or where the limits are set.
37 """
38 def countPointsInLayer( layer ):
39 problem = True
40 p = 0
41 for c in layer:
42 p += len( c )
43 return p
44
45 def printProblemLine( e, msg ):
46 print "\t" + e.glyphname + msg
47
48 def dealWithValidationState( state, e ):
49 if state & 0x2:
50 printProblemLine( e, " has open contour" )
51 if state & 0x4:
52 printProblemLine( e, " intersects itself" )
53 if state & 0x8:
54 printProblemLine( e, " is drawn in wrong direction" )
55 if state & 0x10:
56 printProblemLine( e, " has a flipped reference" )
57 if state & 0x20:
58 printProblemLine( e, " is missing extrema" )
59 if state & 0x40:
60 printProblemLine( e, " is missing a reference in a table" )
61 if state & 0x80:
62 printProblemLine( e, " has more than 1500 pts" )
63 if state & 0x100:
64 printProblemLine( e, " has more than 96 hints" )
65 if state & 0x200:
66 printProblemLine( e, " has invalid PS name" )
67 """
68 # Not meaningfully set for non-TrueType fonts )
69 if state & 0x400:
70 printProblemLine( e, " has more points than allowed by TT: " + str( countPointsInLayer( e.layers[1] ) ) )
71 if state & 0x800:
72 printProblemLine( e, " has more paths than allowed by TT" )
73 if state & 0x1000:
74 printProblemLine( e, " has more points in composite than allowed by TT" )
75 if state & 0x2000:
76 printProblemLine( e, " has more paths in composite than allowed by TT" )
77 if state & 0x4000:
78 printProblemLine( e, " has instruction longer than allowed" )
79 if state & 0x8000:
80 printProblemLine( e, " has more references than allowed" )
81 if state & 0x10000:
82 printProblemLine( e, " has references deeper than allowed" )
83 if state & 0x20000:
84 print e.glyphname + " fpgm or prep tables longer than allowed" )
85 """
86
87 def validate( dir, fontFile ):
88 try:
89 font = fontforge.open( dir + fontFile )
90 print "Validating " + fontFile
91
92 g = font.selection.all()
93 g = font.selection.byGlyphs
94
95 valid = True
96 for e in g:
97 state = e.validate()
98 if state != 0:
99 dealWithValidationState( state, e )
100 font.validate
101 except Exception, e:
102 problem = True
103 print >> sys.stderr, str( e )
104
105 validate( '../sfd/', 'FreeSerif.sfd' )
106 validate( '../sfd/', 'FreeSerifItalic.sfd' )
107 validate( '../sfd/', 'FreeSerifBold.sfd' )
108 validate( '../sfd/', 'FreeSerifBoldItalic.sfd' )
109 validate( '../sfd/', 'FreeSans.sfd' )
110 validate( '../sfd/', 'FreeSansOblique.sfd' )
111 validate( '../sfd/', 'FreeSansBold.sfd' )
112 validate( '../sfd/', 'FreeSansBoldOblique.sfd' )
113 validate( '../sfd/', 'FreeMono.sfd' )
114 validate( '../sfd/', 'FreeMonoOblique.sfd' )
115 validate( '../sfd/', 'FreeMonoBold.sfd' )
116 validate( '../sfd/', 'FreeMonoBoldOblique.sfd' )
117
118 validate( '../sfd/', 'FreeSerif.ttf' )
119 validate( '../sfd/', 'FreeSerifItalic.ttf' )
120 validate( '../sfd/', 'FreeSerifBold.ttf' )
121 validate( '../sfd/', 'FreeSerifBoldItalic.ttf' )
122 validate( '../sfd/', 'FreeSans.ttf' )
123 validate( '../sfd/', 'FreeSansOblique.ttf' )
124 validate( '../sfd/', 'FreeSansBold.ttf' )
125 validate( '../sfd/', 'FreeSansBoldOblique.ttf' )
126 validate( '../sfd/', 'FreeMono.ttf' )
127 validate( '../sfd/', 'FreeMonoOblique.ttf' )
128 validate( '../sfd/', 'FreeMonoBold.ttf' )
129 validate( '../sfd/', 'FreeMonoBoldOblique.ttf' )
130
131 validate( '../sfd/', 'FreeSerif.otf' )
132 validate( '../sfd/', 'FreeSerifItalic.otf' )
133 validate( '../sfd/', 'FreeSerifBold.otf' )
134 validate( '../sfd/', 'FreeSerifBoldItalic.otf' )
135 validate( '../sfd/', 'FreeSans.otf' )
136 validate( '../sfd/', 'FreeSansOblique.otf' )
137 validate( '../sfd/', 'FreeSansBold.otf' )
138 validate( '../sfd/', 'FreeSansBoldOblique.otf' )
139 validate( '../sfd/', 'FreeMono.otf' )
140 validate( '../sfd/', 'FreeMonoOblique.otf' )
141 validate( '../sfd/', 'FreeMonoBold.otf' )
142 validate( '../sfd/', 'FreeMonoBoldOblique.otf' )
143
144
145 if problem:
146 sys.exit( 1 )