| 1 |
#!/usr/bin/env ../utility/fontforge-interp.sh |
| 2 |
from __future__ import print_function |
| 3 |
|
| 4 |
__doc__ = """ |
| 5 |
private_use.py |
| 6 |
|
| 7 |
fontforge -script private_use.py font_file_path... |
| 8 |
|
| 9 |
Output is HTML showing all the font's glyphs that are in Unicode "Private Use" |
| 10 |
areas. |
| 11 |
Also reports whether glyphs have references, or if they are ligatures. |
| 12 |
""" |
| 13 |
__author__ = "Stevan White <[email protected]>" |
| 14 |
__date__ = "Dec 2009" |
| 15 |
__version__ = "$Revision: 3916 $" |
| 16 |
|
| 17 |
import fontforge |
| 18 |
from sys import argv, exit, stdout, stderr |
| 19 |
|
| 20 |
|
| 21 |
preamble = """<!doctype html> |
| 22 |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"> |
| 23 |
<head> |
| 24 |
<meta charset="UTF-8" /> |
| 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: \'%s\'; ">' % ( font.familyname ) ) |
| 52 |
print( '<h2>Private Use Area in ' + font.fontname + '</h2>' ) |
| 53 |
|
| 54 |
font.selection.select(("ranges",None),0xe000,0xf8ff) |
| 55 |
print( '<table>' ) |
| 56 |
for g in font.selection.byGlyphs: |
| 57 |
print( '<tr><td>' ) |
| 58 |
print( '%s%0.4x%s' %( "0x", g.encoding, "" ) ) |
| 59 |
print( '</td><td>' ) |
| 60 |
print( '' + g.glyphname ) |
| 61 |
print( '</td><td>' ) |
| 62 |
if g.getPosSub( '*' ): |
| 63 |
print( "is ligature" ) |
| 64 |
if g.references: |
| 65 |
print( "has references" ) |
| 66 |
print( '</td><td>' ) |
| 67 |
print( '</td></tr>' ) |
| 68 |
|
| 69 |
print( '</table>' ) |
| 70 |
print( '</div>' ) |
| 71 |
stdout.flush() |
| 72 |
|
| 73 |
def printentity( font, s ): |
| 74 |
if s == -1: |
| 75 |
print( 'Missing glyph:', a ) |
| 76 |
stdout.write( '<span class="nonchar"> </span>' ) |
| 77 |
else: |
| 78 |
stdout.write( formatted_hex_value( s ) ) |
| 79 |
|
| 80 |
def formatted_hex_value( n ): |
| 81 |
return '%s%0.4x%s' %( "&#x", n, ";" ) |
| 82 |
|
| 83 |
args = argv[1:] |
| 84 |
|
| 85 |
__usage = """Usage |
| 86 |
private_use.py font_file_name |
| 87 |
""" |
| 88 |
|
| 89 |
if len( args ) < 1 or len( args[0].strip() ) == 0: |
| 90 |
print( __usage, file=stderr ) |
| 91 |
exit( 1 ) |
| 92 |
|
| 93 |
print( makePreamble() ) |
| 94 |
for font_name in args: |
| 95 |
print_private( font_name ) |
| 96 |
print( postamble ) |