| 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 2016, 2017, 2018 Stevan White" |
| 21 |
__date__ = "$Date: $" |
| 22 |
__version__ = "$Revision: 3050 $" |
| 23 |
|
| 24 |
__doc__ = """ |
| 25 |
For glyphs in Unicode ranges, the OpenType Glyph Class should usually be |
| 26 |
left automatic, to be determined from the standards. |
| 27 |
|
| 28 |
For glyphs in non-Unicode blocks, it may be important to set the Glyph Class. |
| 29 |
(Mark Positoning depends on this, for example.) |
| 30 |
|
| 31 |
This script checks that Unicode glyphs all have Glyph Class "automatic", |
| 32 |
and that a zero-width glyph in any other block is *not* "automatic". |
| 33 |
Then it checks that mark anchors belong to glyphs meant to be combining |
| 34 |
and that base anchors belown to base glyphs. |
| 35 |
""" |
| 36 |
|
| 37 |
import fontforge |
| 38 |
import sys |
| 39 |
import unicode_data |
| 40 |
|
| 41 |
problem = False |
| 42 |
|
| 43 |
def isException( glyph ): |
| 44 |
e = glyph.encoding |
| 45 |
# Malayalam vowels are Mark to allow positioning of subsequent marks. |
| 46 |
return ( e in range( 0x0D3E, 0X0D40 + 1 ) |
| 47 |
or e in range( 0x0D46, 0x0D4C + 1 ) |
| 48 |
or e in range( 0x0D57, 0x0D57 + 1 ) |
| 49 |
) |
| 50 |
|
| 51 |
def inPrivateUseRange( glyph ): |
| 52 |
e = glyph.encoding |
| 53 |
|
| 54 |
return ( ( e >= 0xE000 and e <= 0xF8FF ) |
| 55 |
or ( e >= 0xFF000 and e <= 0xFFFFD ) |
| 56 |
or ( e >= 0x100000 and e <= 0x10FFFD ) ) |
| 57 |
|
| 58 |
def isSpecialTrueType( glyph ): |
| 59 |
""" Fontforge treats three control characters as the special |
| 60 |
TrueType characters recommended by that standard |
| 61 |
""" |
| 62 |
e = glyph.encoding |
| 63 |
|
| 64 |
return e == 0 or e == 1 or e == 0xD |
| 65 |
|
| 66 |
def rprt( glyph, problem ): |
| 67 |
print( "Glyph at slot", glyph.encoding, problem ) |
| 68 |
markanch = ( 'mark', 'basemark' ) |
| 69 |
baseanch = ( 'base', 'ligature' ) |
| 70 |
zeroWidthOK = ('mark', 'component', 'noclass' ) |
| 71 |
|
| 72 |
from os import path |
| 73 |
def checkOTGlyphClass( fontDir, fontFile ): |
| 74 |
if isinstance( fontFile, ( list, tuple ) ): |
| 75 |
print( "In directory " + fontDir ) |
| 76 |
for fontName in fontFile: |
| 77 |
checkOTGlyphClass( fontDir, fontName ) |
| 78 |
return |
| 79 |
|
| 80 |
print( "Checking OpenType Glyph Class in " + fontFile ) |
| 81 |
font = fontforge.open( path.join( fontDir, fontFile ) ) |
| 82 |
|
| 83 |
g = font.selection.all() |
| 84 |
g = font.selection.byGlyphs |
| 85 |
|
| 86 |
valid = True |
| 87 |
for glyph in g: |
| 88 |
gclass = glyph.glyphclass |
| 89 |
comb = False |
| 90 |
if inPrivateUseRange( glyph ): |
| 91 |
comb = ( gclass == "mark" ) |
| 92 |
if gclass == 'automatic': |
| 93 |
rprt( glyph, |
| 94 |
" in private use range, marked 'automatic'." ) |
| 95 |
problem = True |
| 96 |
if glyph.width == 0 and not gclass in zeroWidthOK: |
| 97 |
rprt( glyph, |
| 98 |
" is zero width but isn't a mark or component" ) |
| 99 |
problem = True |
| 100 |
else: |
| 101 |
guni = glyph.unicode |
| 102 |
if guni > 32: # bug in unichr() ? |
| 103 |
gu = unichr( guni ) |
| 104 |
try: |
| 105 |
#unicode_data.name( gu ) |
| 106 |
comb = unicode_data.is_combining_character( gu ) |
| 107 |
except Exception as e: |
| 108 |
#FIXME unicodedata woefully out of date |
| 109 |
#print( "NOT FOUND in unicodedata", glyph.glyphname ) |
| 110 |
gclass = glyph.glyphclass |
| 111 |
comb = ( gclass == "mark" ) |
| 112 |
print( "WOHAH", e ) |
| 113 |
raise( e) |
| 114 |
|
| 115 |
if gclass != 'automatic': |
| 116 |
if isException( glyph ): |
| 117 |
#rprt( glyph, |
| 118 |
# "has exceptonal Glyph Class" ) |
| 119 |
pass |
| 120 |
else: |
| 121 |
rprt( glyph, |
| 122 |
"has non-automatic Glyph Class" ) |
| 123 |
problem = True |
| 124 |
for a in glyph.anchorPoints: |
| 125 |
aname = a[0] |
| 126 |
atype = a[1] |
| 127 |
if comb: |
| 128 |
if atype in baseanch: |
| 129 |
rprt( glyph, |
| 130 |
"is combining but has base anchor " |
| 131 |
+ aname ) |
| 132 |
problem = True |
| 133 |
else: |
| 134 |
if atype in markanch: |
| 135 |
rprt( glyph, |
| 136 |
"isn't combining but has mark anchor " |
| 137 |
+ aname ) |
| 138 |
problem = True |
| 139 |
|
| 140 |
# -------------------------------------------------------------------------- |
| 141 |
args = sys.argv[1:] |
| 142 |
|
| 143 |
if len( args ) < 1 or len( args[0].strip() ) == 0: |
| 144 |
checkOTGlyphClass( '../../sfd/', |
| 145 |
( 'FreeSerif.sfd', 'FreeSerifItalic.sfd', |
| 146 |
'FreeSerifBold.sfd', 'FreeSerifBoldItalic.sfd', |
| 147 |
'FreeSans.sfd', 'FreeSansOblique.sfd', |
| 148 |
'FreeSansBold.sfd', 'FreeSansBoldOblique.sfd', |
| 149 |
'FreeMono.sfd', 'FreeMonoOblique.sfd', |
| 150 |
'FreeMonoBold.sfd', 'FreeMonoBoldOblique.sfd' ) ) |
| 151 |
else: |
| 152 |
checkOTGlyphClass( args[0], args[1:] ) |
| 153 |
|
| 154 |
#print( unicode_data.unidata_version ) |
| 155 |
if problem: |
| 156 |
sys.exit( 1 ) |