#!/usr/bin/fontforge -script
from __future__ import print_function
__license__ = """
This file is part of GNU FreeFont.
GNU FreeFont is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
GNU FreeFont is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
GNU FreeFont. If not, see .
"""
__author__ = "Stevan White"
__email__ = "stevan.white@googlemail.com"
__copyright__ = "Copyright 2009, 2010, 2011, 2017, 2018 Stevan White"
__date__ = "$Date: 2018-06-03 22:07:11 +0200 (So, 03. Jun 2018) $"
__version__ = "$Revision: 3916 $"
import fontforge
from sys import stdout as out, stderr as err
from OpenType.UnicodeRanges import *
def get_kern_subtables( font ):
try:
tables = []
for lookup in font.gpos_lookups:
if font.getLookupInfo( lookup )[0] == 'gpos_pair':
sts = font.getLookupSubtables( lookup )
for st in sts:
if font.isKerningClass( st ):
tables.append( st )
return tables
except EnvironmentError as e:
print( 'EnvironmentError', e, file=err )
except TypeError as t:
print( 'TypeError', t, file=err )
return None
preamble = """
glyph kerning classes in GNU FreeFont
"""
postamble="""
"""
def print_kerns( fontPath ):
font = fontforge.open( fontPath )
print( 'Kerning classes in ' + font.fontname + '
' )
weight = ''
if font.os2_weight > 500:
weight = 'B'
style = ''
if font.italicangle < 0.0:
style = 'I'
print( '' )
subtables = get_kern_subtables( font )
for st in subtables:
print( '
Subtable ' + st + '
' )
printKernsOfSubtable( font, st )
print( '' )
out.flush()
def printKernsOfSubtable( font, subtable ):
kclass = font.getKerningClass( subtable )
n = 0
leftclasses = kclass[0]
rightclasses = kclass[1]
kerns = kclass[2]
nr = len( rightclasses )
print( '' )
print( '| left classes: | ' )
print( 'right classes: | ' )
print( '
' )
for lc in leftclasses:
if lc:
for c in lc:
writeentity( font, c )
print( " " )
print( " | " )
print( "" )
for rc in rightclasses:
if rc:
for c in rc:
writeentity( font, c )
print( " " )
print( " | " )
print( "
" )
print( "
" )
print( "" )
print( "" )
print( " | " )
for rc in rightclasses:
if rc:
out.write( "" + entitystr( font, rc[0] ) + " | " )
print( "
" )
for lc in leftclasses:
m = 0
if lc:
print( "" )
out.write( "| " + entitystr( font, lc[0] ) + " | " )
for rc in rightclasses:
kern = kerns[ n * nr + m ]
if rc:
ccolor = ''
ncolor = ''
if kern > 0:
ncolor = ' class="pos"'
if kern == 0:
ccolor = ' class="zero"'
out.write( '' )
if kern == 0:
out.write( ' ' )
else:
out.write( str( kern ) )
out.write( ' ' )
printpair( font, lc[0], rc[0] )
out.write( ' | ' )
m += 1
print( "
" )
n += 1
print( "
" )
def writeentity( font, a ):
out.write( entitystr( font, a ) )
def entitystr( font, a ):
s = font.findEncodingSlot( a )
v = formatted_hex_value( s )
if s == -1:
v = ' '
print( font.fullname, 'Missing glyph: ' + a, file=err )
elif not codepointIsInSomeRange( s ):
print( font.fullname, 'Non-unicode: ' + v, file=err )
return v
def printpair( font, p, q ):
writeentity( font, p )
writeentity( font, q )
out.write( ' ' )
def formatted_hex_value( n ):
return '%s%0.4x%s' %( "", n, ";" )
def printlist( lst ):
s = ''
delim = ''
for m in lst:
s += delim + m
delim = ' '
print( s )
print( preamble )
print_kerns( '../../sfd/FreeSerif.sfd' )
print_kerns( '../../sfd/FreeSerifItalic.sfd' )
print_kerns( '../../sfd/FreeSerifBold.sfd' )
print_kerns( '../../sfd/FreeSerifBoldItalic.sfd' )
print_kerns( '../../sfd/FreeSans.sfd' )
print_kerns( '../../sfd/FreeSansOblique.sfd' )
print_kerns( '../../sfd/FreeSansBold.sfd' )
print_kerns( '../../sfd/FreeSansBoldOblique.sfd' )
print_kerns( '../../sfd/FreeMono.sfd' )
print_kerns( '../../sfd/FreeMonoOblique.sfd' )
print_kerns( '../../sfd/FreeMonoBold.sfd' )
print_kerns( '../../sfd/FreeMonoBoldOblique.sfd' )
print( postamble )