| 1 |
#!/usr/bin/env ../utility/fontforge-interp.sh |
| 2 |
|
| 3 |
__doc__ = """ |
| 4 |
private_use.py |
| 5 |
|
| 6 |
fontforge -script private_use.py font_file_path... |
| 7 |
|
| 8 |
Output is HTML showing all the font's glyphs that are in Unicode "Private Use" |
| 9 |
areas. |
| 10 |
Also reports whether glyphs have references, or if they are ligatures. |
| 11 |
""" |
| 12 |
__author__ = "Stevan White <[email protected]>" |
| 13 |
__date__ = "Dec 2009" |
| 14 |
__version__ = "$Revision: 1.2 $" |
| 15 |
|
| 16 |
import fontforge |
| 17 |
import sys |
| 18 |
|
| 19 |
|
| 20 |
preamble = """<?xml version="1.0" encoding="utf-8"?> |
| 21 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 22 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 23 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
| 24 |
<head> |
| 25 |
<title>Private Use area</title> |
| 26 |
<style type="text/css"> |
| 27 |
.nonchar { background-color: red; } |
| 28 |
table, tr, td { font-family: inherit; } |
| 29 |
table, tr, td { font-style: inherit; } |
| 30 |
table, tr, td { font-weight: inherit; } |
| 31 |
td { text-align: right; } |
| 32 |
td { line-height: 1; } |
| 33 |
.ligatures td { width: 2em; } |
| 34 |
.ligatures th { text-align: left; font-family: freemono, monospace; } |
| 35 |
</style> |
| 36 |
</head> |
| 37 |
<body> |
| 38 |
""" |
| 39 |
|
| 40 |
def makePreamble(): |
| 41 |
return preamble |
| 42 |
|
| 43 |
postamble=""" |
| 44 |
</body> |
| 45 |
</html> |
| 46 |
""" |
| 47 |
|
| 48 |
def print_private( fontPath ): |
| 49 |
font = fontforge.open( fontPath ) |
| 50 |
|
| 51 |
print '<div style="font-family: \'' + font.familyname + '\'; ' \ |
| 52 |
'\">' |
| 53 |
print '<h2>Private Use Area in ' + font.fontname + '</h2>' |
| 54 |
|
| 55 |
font.selection.select(("ranges",None),0xe000,0xf8ff) |
| 56 |
print '<table>' |
| 57 |
for g in font.selection.byGlyphs: |
| 58 |
print '<tr><td>' |
| 59 |
print '%s%0.4x%s' %( "0x", g.encoding, "" ) |
| 60 |
print '</td><td>' |
| 61 |
print '' + g.glyphname |
| 62 |
print '</td><td>' |
| 63 |
if g.getPosSub( '*' ): |
| 64 |
print "is ligature" |
| 65 |
if g.references: |
| 66 |
print "has references" |
| 67 |
print '</td><td>' |
| 68 |
print '</td></tr>' |
| 69 |
|
| 70 |
print '</table>' |
| 71 |
print '</div>' |
| 72 |
sys.stdout.flush() |
| 73 |
|
| 74 |
def printentity( font, s ): |
| 75 |
if s == -1: |
| 76 |
print >> sys.stderr, 'Missing glyph: ' + a |
| 77 |
sys.stdout.write( '<span class="nonchar"> </span>' ) |
| 78 |
else: |
| 79 |
sys.stdout.write( formatted_hex_value( s ) ) |
| 80 |
|
| 81 |
def formatted_hex_value( n ): |
| 82 |
return '%s%0.4x%s' %( "&#x", n, ";" ) |
| 83 |
|
| 84 |
args = sys.argv[1:] |
| 85 |
|
| 86 |
if len( args ) < 1 or len( args[0].strip() ) == 0: |
| 87 |
sys.exit( 0 ) |
| 88 |
|
| 89 |
print makePreamble() |
| 90 |
for font_name in args: |
| 91 |
print_private( font_name ) |
| 92 |
print postamble |