| 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, 2011, 2018 Stevan White" |
| 21 |
__date__ = "$Date: 2018-06-03 22:33:16 +0200 (So, 03. Jun 2018) $" |
| 22 |
__version__ = "$Revision: 3925 $" |
| 23 |
|
| 24 |
__doc__ = """ |
| 25 |
For most unicode ranges, glyph slot numbers should be the same as the |
| 26 |
Unicode value. |
| 27 |
The Private Use ranges are the exception: those characters should have a |
| 28 |
definate non-Unicode number: -1 |
| 29 |
|
| 30 |
This script checks that this is the case, and prints out a warning |
| 31 |
whenever it isn't. |
| 32 |
""" |
| 33 |
|
| 34 |
import fontforge |
| 35 |
from sys import argv, exit |
| 36 |
|
| 37 |
problem = False |
| 38 |
|
| 39 |
def inPrivateUseRange( glyph ): |
| 40 |
e = glyph.encoding |
| 41 |
|
| 42 |
return ( ( e >= 0xE000 and e <= 0xF8FF ) |
| 43 |
or ( e >= 0xFF000 and e <= 0xFFFFD ) |
| 44 |
or ( e >= 0x100000 and e <= 0x10FFFD ) ) |
| 45 |
|
| 46 |
def isSpecialTrueType( glyph ): |
| 47 |
""" Fontforge treats three control characters as the special |
| 48 |
TrueType characters recommended by that standard |
| 49 |
""" |
| 50 |
e = glyph.encoding |
| 51 |
|
| 52 |
return e == 0 or e == 1 or e == 0xD |
| 53 |
|
| 54 |
from os import path |
| 55 |
def checkGlyphNumbers( fontDir, fontFile ): |
| 56 |
if isinstance( fontFile, ( list, tuple ) ): |
| 57 |
print( "In directory " + fontDir ) |
| 58 |
for fontName in fontFile: |
| 59 |
checkGlyphNumbers( fontDir, fontName ) |
| 60 |
return |
| 61 |
|
| 62 |
print( "Checking slot numbers in " + fontFile ) |
| 63 |
font = fontforge.open( path.join( fontDir, fontFile ) ) |
| 64 |
|
| 65 |
g = font.selection.all() |
| 66 |
g = font.selection.byGlyphs |
| 67 |
|
| 68 |
valid = True |
| 69 |
for glyph in g: |
| 70 |
if isSpecialTrueType( glyph ): |
| 71 |
# FIXME really should complain if it DOESNT exist |
| 72 |
pass |
| 73 |
elif inPrivateUseRange( glyph ): |
| 74 |
if glyph.unicode != -1: |
| 75 |
print( "Glyph at slot " + str( glyph.encoding ) |
| 76 |
+ " is Private Use but has Unicode" ) |
| 77 |
problem = True |
| 78 |
else: |
| 79 |
if glyph.encoding != glyph.unicode: |
| 80 |
print( "Glyph at slot " + str( glyph.encoding ) |
| 81 |
+ " has wrong Unicode" ) |
| 82 |
problem = True |
| 83 |
|
| 84 |
# -------------------------------------------------------------------------- |
| 85 |
args = argv[1:] |
| 86 |
|
| 87 |
if len( args ) < 1 or len( args[0].strip() ) == 0: |
| 88 |
checkGlyphNumbers( '../../sfd/', |
| 89 |
( 'FreeSerif.sfd', 'FreeSerifItalic.sfd', |
| 90 |
'FreeSerifBold.sfd', 'FreeSerifBoldItalic.sfd', |
| 91 |
'FreeSans.sfd', 'FreeSansOblique.sfd', |
| 92 |
'FreeSansBold.sfd', 'FreeSansBoldOblique.sfd', |
| 93 |
'FreeMono.sfd', 'FreeMonoOblique.sfd', |
| 94 |
'FreeMonoBold.sfd', 'FreeMonoBoldOblique.sfd' ) ) |
| 95 |
else: |
| 96 |
checkGlyphNumbers( args[0], args[1:] ) |
| 97 |
|
| 98 |
if problem: |
| 99 |
exit( 1 ) |