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