| 1 |
|
| 2 |
# |
| 3 |
# Copyright (C) 2013 Matthew Skala |
| 4 |
# |
| 5 |
# This file is part of FontForge. |
| 6 |
# |
| 7 |
# FontForge is free software: you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation, either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# FontForge is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with FontForge. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
# |
| 20 |
# For more details see the COPYING.gplv3 file in the root directory of this |
| 21 |
# distribution. |
| 22 |
# |
| 23 |
# Based on the Tsukurimashou Project's fontlint script (same author). |
| 24 |
# |
| 25 |
|
| 26 |
# Things to check for: |
| 27 |
# check_for[i][0] is 0, 1, or 2, for don't check, warn, or fatal |
| 28 |
# check_for[i][1] is a string message |
| 29 |
# check_for[0]..[31] refer to LSB to MSB of Validate() return |
| 30 |
# check_for[32]..[63] refer to LSB to MSB of $loadState |
| 31 |
# check_for[64]..[95] refer to LSB to MSB of $privateState |
| 32 |
# check_for[96]..[whatever] are sequentially assigned other things |
| 33 |
|
| 34 |
# note: to work around a bug in FontForge (multidimensional arrays being |
| 35 |
# horribly broken), check_for[i][j] is actually stored as check_for[2*i+j] |
| 36 |
|
| 37 |
check_for=[ \ |
| 38 |
1,"Unknown Validate() return bit 0x1", \ |
| 39 |
2,"Open contour", \ |
| 40 |
2,"Self-intersecting glyph", \ |
| 41 |
2,"Wrong direction", \ |
| 42 |
2,"Flipped reference", \ |
| 43 |
2,"Missing points at extrema", \ |
| 44 |
2,"Unknown glyph referenced in GSUB/GPOS/MATH", \ |
| 45 |
2,"More points in a glyph than PostScript allows", \ |
| 46 |
2,"Too many hints", \ |
| 47 |
2,"Bad glyph name", \ |
| 48 |
2,"More points in a glyph than specified in 'maxp'", \ |
| 49 |
2,"More paths in a glyph than specified in 'maxp'", \ |
| 50 |
2,"More points in a composite glyph than specified in 'maxp'", \ |
| 51 |
2,"More paths in a composite glyph than specified in 'maxp'", \ |
| 52 |
2,"Instructions longer than allowed in 'maxp'", \ |
| 53 |
2,"More references in a glyph than specified in 'maxp'", \ |
| 54 |
2,"References nested more deeply than specified in 'maxp'", \ |
| 55 |
1,"The 'prep' or 'fpgm' tables are longer than specified in 'maxp'\n" \ |
| 56 |
+" (may not be an error)", \ |
| 57 |
2,"Adjacent points too far apart in a glyph", \ |
| 58 |
2,"Non-integral coordinates in a glyph", \ |
| 59 |
1,"A glyph uses at least one, but not all, anchor classes in a\n" \ |
| 60 |
+" subtable (may not be an error)", \ |
| 61 |
2,"Two glyphs have the same name", \ |
| 62 |
2,"Two glyphs have the same Unicode code point", \ |
| 63 |
2,"Overlapping hints in a glyph", \ |
| 64 |
1,"Unknown Validate() return bit 0x1000000", \ |
| 65 |
1,"Unknown Validate() return bit 0x2000000", \ |
| 66 |
1,"Unknown Validate() return bit 0x4000000", \ |
| 67 |
1,"Unknown Validate() return bit 0x8000000", \ |
| 68 |
1,"Unknown Validate() return bit 0x10000000", \ |
| 69 |
1,"Unknown Validate() return bit 0x20000000", \ |
| 70 |
1,"Unknown Validate() return bit 0x40000000", \ |
| 71 |
1,"Unknown Validate() return bit 0x80000000", \ |
| 72 |
2,"Bad PostScript fontname entry in the 'name' table", \ |
| 73 |
2,"Bad 'glyf' or 'loca' table", \ |
| 74 |
2,"Bad 'CFF ' table", \ |
| 75 |
2,"Bad 'hhea', 'hmtx', 'vhea' or 'vmtx' table", \ |
| 76 |
2,"Bad 'cmap' table", \ |
| 77 |
2,"Bad 'EBDT', 'bdat', 'EBLC' or 'bloc' (embedded bitmap) table", \ |
| 78 |
2,"Bad Apple GX advanced typography table", \ |
| 79 |
2,"Bad OpenType advanced typography table", \ |
| 80 |
2,"Bad version number in OS/2 table (must be >0, and must be >1 for\n" \ |
| 81 |
+" OT-CFF fonts)", \ |
| 82 |
2,"Bad sfnt file header", \ |
| 83 |
1,"Unknown loadState bit 0x400", \ |
| 84 |
1,"Unknown loadState bit 0x800", \ |
| 85 |
1,"Unknown loadState bit 0x1000", \ |
| 86 |
1,"Unknown loadState bit 0x2000", \ |
| 87 |
1,"Unknown loadState bit 0x4000", \ |
| 88 |
1,"Unknown loadState bit 0x8000", \ |
| 89 |
1,"Unknown loadState bit 0x10000", \ |
| 90 |
1,"Unknown loadState bit 0x20000", \ |
| 91 |
1,"Unknown loadState bit 0x40000", \ |
| 92 |
1,"Unknown loadState bit 0x80000", \ |
| 93 |
1,"Unknown loadState bit 0x100000", \ |
| 94 |
1,"Unknown loadState bit 0x200000", \ |
| 95 |
1,"Unknown loadState bit 0x400000", \ |
| 96 |
1,"Unknown loadState bit 0x800000", \ |
| 97 |
1,"Unknown loadState bit 0x1000000", \ |
| 98 |
1,"Unknown loadState bit 0x2000000", \ |
| 99 |
1,"Unknown loadState bit 0x4000000", \ |
| 100 |
1,"Unknown loadState bit 0x8000000", \ |
| 101 |
1,"Unknown loadState bit 0x1000000", \ |
| 102 |
1,"Unknown loadState bit 0x20000000", \ |
| 103 |
1,"Unknown loadState bit 0x40000000", \ |
| 104 |
1,"Unknown loadState bit 0x80000000", \ |
| 105 |
2,"Odd number of elements in either the BlueValues or OtherBlues\n" \ |
| 106 |
+" entries in the PostScript Private dictionary", \ |
| 107 |
2,"Disordered elements in either the BlueValues or OtherBlues\n" \ |
| 108 |
+" entries in the PostScript Private dictionary", \ |
| 109 |
2,"Too many elements in either the BlueValues or OtherBlues entries\n" \ |
| 110 |
+" in the PostScript Private dictionary", \ |
| 111 |
2,"Elements too close in either the BlueValues or OtherBlues\n" \ |
| 112 |
+" entries in the PostScript Private dictionary (must " \ |
| 113 |
+"be at least\n 2*BlueFuzz+1 apart)", \ |
| 114 |
2,"Non-integral elements in either the BlueValues or OtherBlues\n" \ |
| 115 |
+" entries in the PostScript Private dictionary", \ |
| 116 |
2,"Alignment zone height in either the BlueValues or OtherBlues is\n" \ |
| 117 |
+" too big for the BlueScale in the PostScript Private " \ |
| 118 |
+"dictionary", \ |
| 119 |
1,"Unknown privateState bit 0x40", \ |
| 120 |
1,"Unknown privateState bit 0x80", \ |
| 121 |
2,"Odd number of elements in either the FamilyBlues or\n" \ |
| 122 |
+" FamilyOtherBlues entries in the PostScript Private " \ |
| 123 |
+"dictionary", \ |
| 124 |
2,"Disordered elements in either the FamilyBlues or\n" \ |
| 125 |
+" FamilyOtherBlues entries in the PostScript Private " \ |
| 126 |
+"dictionary", \ |
| 127 |
2,"Too many elements in either the FamilyBlues or FamilyOtherBlues\n" \ |
| 128 |
+" entries in the PostScript Private dictionary", \ |
| 129 |
2,"Elements too close in either the FamilyBlues or\n" \ |
| 130 |
+" FamilyOtherBlues entries in the PostScript Private " \ |
| 131 |
+"dictionary\n (must be at least 2*BlueFuzz+1 apart)", \ |
| 132 |
2,"Non-integral elements in either the FamilyBlues or\n" \ |
| 133 |
+" FamilyOtherBlues entries in the PostScript Private " \ |
| 134 |
+"dictionary", \ |
| 135 |
2,"Alignment zone height in either the FamilyBlues or\n" \ |
| 136 |
+" FamilyOtherBlues is too big for the BlueScale in " \ |
| 137 |
+"the PostScript\n Private dictionary", \ |
| 138 |
1,"Unknown privateState bit 0x4000", \ |
| 139 |
1,"Unknown privateState bit 0x8000", \ |
| 140 |
2,"Missing BlueValues entry in PostScript Private dictionary", \ |
| 141 |
2,"Bad BlueFuzz entry in PostScript Private dictionary", \ |
| 142 |
2,"Bad BlueScale entry in PostScript Private dictionary", \ |
| 143 |
2,"Bad StdHW entry in PostScript Private dictionary", \ |
| 144 |
2,"Bad StdVW entry in PostScript Private dictionary", \ |
| 145 |
2,"Bad StemSnapH entry in PostScript Private dictionary", \ |
| 146 |
2,"Bad StemSnapV entry in PostScript Private dictionary", \ |
| 147 |
2,"StemSnapH does not contain StdHW value in PostScript Private\n" \ |
| 148 |
+" dictionary", \ |
| 149 |
2,"StemSnapV does not contain StdVW value in PostScript Private\n" \ |
| 150 |
+" dictionary", \ |
| 151 |
2,"Bad BlueShift entry in PostScript Private dictionary", \ |
| 152 |
1,"Unknown privateState bit 0x4000000", \ |
| 153 |
1,"Unknown privateState bit 0x8000000", \ |
| 154 |
1,"Unknown privateState bit 0x1000000", \ |
| 155 |
1,"Unknown privateState bit 0x20000000", \ |
| 156 |
1,"Unknown privateState bit 0x40000000", \ |
| 157 |
1,"Unknown privateState bit 0x80000000", \ |
| 158 |
0,"Missing BlueValues entry (issue #80) when the font is quadratic\n" \ |
| 159 |
+" (overrides general setting)", \ |
| 160 |
0,"Non-integral coordinates (issue #19) when the font is cubic\n" \ |
| 161 |
+" (overrides general setting)", \ |
| 162 |
2,"Self-intersecting glyph (issue #2) when FontForge is able to\n" \ |
| 163 |
+" correct this (overrides general setting)", \ |
| 164 |
1,"Flags in the OS/2 table say the font is non-free" \ |
| 165 |
]; |
| 166 |
|
| 167 |
# display usage message |
| 168 |
usage_message= \ |
| 169 |
"\nfontlint [OPTIONS] {fontfile} ...\n" \ |
| 170 |
+" Validates the listed fonts\n\n" \ |
| 171 |
+"Options accepted:\n" \ |
| 172 |
+" -f, --fatal ISSUES treat ISSUES as fatal errors\n" \ |
| 173 |
+" -i, --ignore ISSUES ignore ISSUES\n" \ |
| 174 |
+" -h, --help display help\n" \ |
| 175 |
+" -l, --list list issues, their numbers, and disposition\n" \ |
| 176 |
+" -w, --warning ISSUES treat ISSUES as warnings\n\n" \ |
| 177 |
+"Lists of ISSUES may include comma-separated numbers and ranges, like\n" \ |
| 178 |
+" 1,2,5,8-21,24-29,48\n"; |
| 179 |
if ($argc<=1) |
| 180 |
Print(usage_message); |
| 181 |
Quit(1); |
| 182 |
endif |
| 183 |
|
| 184 |
# process command line |
| 185 |
allowing_options=1; |
| 186 |
any_fatal=0; |
| 187 |
while ($argc>1) |
| 188 |
# handle -- to terminate option processing |
| 189 |
if ($argv[1]=='--') |
| 190 |
allowing_options=0; |
| 191 |
|
| 192 |
# handle options |
| 193 |
elseif (allowing_options && (Strsub($argv[1]+' ',0,1)=='-')) |
| 194 |
arg_type=-1; |
| 195 |
|
| 196 |
# make issues into fatal errors |
| 197 |
if ((Strsub($argv[1]+' ',0,2)=='-f') \ |
| 198 |
|| (Strsub($argv[1]+' ',1,3)=='-f')) |
| 199 |
arg_type=2; |
| 200 |
|
| 201 |
# explicit request for help message |
| 202 |
elseif ((Strsub($argv[1]+' ',0,2)=='-h') \ |
| 203 |
|| (Strsub($argv[1]+' ',1,3)=='-h')) |
| 204 |
Print(usage_message); |
| 205 |
|
| 206 |
# make issues ignored |
| 207 |
elseif ((Strsub($argv[1]+' ',0,2)=='-i') \ |
| 208 |
|| (Strsub($argv[1]+' ',1,3)=='-i')) |
| 209 |
arg_type=0; |
| 210 |
|
| 211 |
# list current configuration |
| 212 |
elseif ((Strsub($argv[1]+' ',0,2)=='-l') \ |
| 213 |
|| (Strsub($argv[1]+' ',1,3)=='-l')) |
| 214 |
Print("INFO Here are all the currently-checked issues and " \ |
| 215 |
+"their status"); |
| 216 |
i=0; |
| 217 |
while (i<SizeOf(check_for)/2) |
| 218 |
istr=" "+ToString(i); |
| 219 |
istr=Strsub(istr,Strlen(istr)-3); |
| 220 |
if (check_for[i*2]==0) |
| 221 |
Print("IGNORED "+istr+" "+check_for[i*2+1]); |
| 222 |
elseif (check_for[i*2]==1) |
| 223 |
Print("WARNING "+istr+" "+check_for[i*2+1]); |
| 224 |
elseif (check_for[i*2]==2) |
| 225 |
Print("ERROR "+istr+" "+check_for[i*2+1]); |
| 226 |
endif |
| 227 |
i=i+1; |
| 228 |
endloop |
| 229 |
Print(); |
| 230 |
|
| 231 |
# make issues into warnings |
| 232 |
elseif ((Strsub($argv[1]+' ',0,2)=='-w') \ |
| 233 |
|| (Strsub($argv[1]+' ',1,3)=='-w')) |
| 234 |
arg_type=1; |
| 235 |
|
| 236 |
else |
| 237 |
Print("ERROR Unknown option "+$argv[1]); |
| 238 |
any_fatal=1; |
| 239 |
endif |
| 240 |
|
| 241 |
# process fatal/ignore/warn options, which share syntax |
| 242 |
if (arg_type>=0) |
| 243 |
i=0; |
| 244 |
while (i<Strlen($argv[1])) |
| 245 |
if (IsDigit(Strsub($argv[1],i,i+1))) |
| 246 |
break; |
| 247 |
endif |
| 248 |
i=i+1; |
| 249 |
endloop |
| 250 |
if (i<Strlen($argv[1])) |
| 251 |
optarg=Strsub($argv[1],i); |
| 252 |
else |
| 253 |
shift; |
| 254 |
optarg=$argv[1]; |
| 255 |
endif |
| 256 |
subargs=StrSplit(optarg,','); |
| 257 |
i=0; |
| 258 |
while (i<SizeOf(subargs)) |
| 259 |
rangevals=StrSplit(subargs[i],'-'); |
| 260 |
if (SizeOf(rangevals)==1) |
| 261 |
check_for[Strtol(rangevals[0])*2]=arg_type; |
| 262 |
elseif ((SizeOf(rangevals)==2) \ |
| 263 |
&& (Strtol(rangevals[1])>=Strtol(rangevals[0]))) |
| 264 |
j=Strtol(rangevals[0]); |
| 265 |
while (j<=Strtol(rangevals[1])) |
| 266 |
check_for[j*2]=arg_type; |
| 267 |
j=j+1; |
| 268 |
endloop |
| 269 |
else |
| 270 |
endif |
| 271 |
i=i+1; |
| 272 |
endloop |
| 273 |
endif |
| 274 |
|
| 275 |
# handle filenames |
| 276 |
else |
| 277 |
Print("CHECKING "+$argv[1]); |
| 278 |
fatal_here=0; |
| 279 |
|
| 280 |
Open($argv[1],9); |
| 281 |
ls_result=$loadState; |
| 282 |
v_result=Validate(); |
| 283 |
ps_result=$privateState; |
| 284 |
|
| 285 |
i=0; |
| 286 |
ibit=1; |
| 287 |
test_result=v_result; |
| 288 |
while (i<96) |
| 289 |
if (i==32) |
| 290 |
test_result=ls_result; |
| 291 |
ibit=1; |
| 292 |
elseif (i==64) |
| 293 |
test_result=ps_result; |
| 294 |
ibit=1; |
| 295 |
endif |
| 296 |
|
| 297 |
if (test_result & ibit) |
| 298 |
|
| 299 |
# handle overrides |
| 300 |
if ((i==2) && (check_for[2*2]!=check_for[98*2])) |
| 301 |
Print("CHECKING 98 "+check_for[98*2+1]); |
| 302 |
SelectAll(); |
| 303 |
FindIntersections(); |
| 304 |
RemoveOverlap(); |
| 305 |
if (Validate()&0x4) |
| 306 |
ci=i; |
| 307 |
else |
| 308 |
ci=98; |
| 309 |
endif |
| 310 |
elseif ((i==19) && ($order==3)) |
| 311 |
ci=97; |
| 312 |
elseif ((i==80) && ($order==2)) |
| 313 |
ci=96; |
| 314 |
else |
| 315 |
ci=i; |
| 316 |
endif |
| 317 |
|
| 318 |
istr=" "+ToString(ci); |
| 319 |
istr=Strsub(istr,Strlen(istr)-3); |
| 320 |
if (check_for[2*ci]==1) |
| 321 |
Print("WARNING "+istr+" "+check_for[ci*2+1]); |
| 322 |
elseif (check_for[2*ci]==2) |
| 323 |
Print("ERROR "+istr+" "+check_for[ci*2+1]); |
| 324 |
fatal_here=1; |
| 325 |
endif |
| 326 |
endif |
| 327 |
|
| 328 |
i=i+1; |
| 329 |
ibit=ibit*2; |
| 330 |
endloop |
| 331 |
|
| 332 |
if (GetOS2Value("FSType")!=0) |
| 333 |
if (check_for[2*99]==1) |
| 334 |
Print("WARNING 99 "+check_for[99*2+1]); |
| 335 |
elseif (check_for[2*99]==2) |
| 336 |
Print("ERROR 99 "+check_for[99*2+1]); |
| 337 |
any_fatal=1; |
| 338 |
endif |
| 339 |
endif |
| 340 |
|
| 341 |
Close(); |
| 342 |
|
| 343 |
if (fatal_here) |
| 344 |
Print("FAIL "+$argv[1]); |
| 345 |
any_fatal=1; |
| 346 |
else |
| 347 |
Print("PASS "+$argv[1]); |
| 348 |
endif |
| 349 |
Print(""); |
| 350 |
endif |
| 351 |
|
| 352 |
shift; |
| 353 |
endloop |
| 354 |
|
| 355 |
Quit(any_fatal); |