added -x <table> option, to exclude a specific table.
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@51 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
parent
7cb6272bd4
commit
e9af618843
19
tt2xml.py
19
tt2xml.py
@ -1,7 +1,7 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
"""\
|
||||
usage: %s [-hvs] [-t <table>] TrueType-file [XML-output-file]
|
||||
usage: %s [-hvs] [-t <table>] [-x <table>] TrueType-file [XML-output-file]
|
||||
Dump a TrueType font as an XML file. If the XML-output-file argument
|
||||
is omitted, the out put file name will be constructed from the input
|
||||
file name, like so: *.ttf becomes *.xml. Either way, existing files
|
||||
@ -11,6 +11,8 @@ usage: %s [-hvs] [-t <table>] TrueType-file [XML-output-file]
|
||||
-t <table> specify a table to dump. Multiple -t options
|
||||
are allowed. When no -t option is specified, all tables
|
||||
will be dumped
|
||||
-x <table> specify a table to exclude from the dump. Multiple
|
||||
-x options are allowed. -t and -x are mutually exclusive.
|
||||
-v verbose: messages will be written to stdout about what is
|
||||
being done.
|
||||
-s split tables: save the XML in a separate XML file per table.
|
||||
@ -24,11 +26,12 @@ usage: %s [-hvs] [-t <table>] TrueType-file [XML-output-file]
|
||||
import sys, os, getopt
|
||||
from fontTools import ttLib
|
||||
|
||||
options, args = getopt.getopt(sys.argv[1:], "shvt:")
|
||||
options, args = getopt.getopt(sys.argv[1:], "shvt:x:")
|
||||
|
||||
verbose = 0
|
||||
splitTables = 0
|
||||
tables = []
|
||||
skipTables = []
|
||||
for option, value in options:
|
||||
if option == "-t":
|
||||
if len(value) > 4:
|
||||
@ -37,6 +40,13 @@ for option, value in options:
|
||||
# normalize tag
|
||||
value = value + (4 - len(value)) * " "
|
||||
tables.append(value)
|
||||
elif option == "-x":
|
||||
if len(value) > 4:
|
||||
print "illegal table tag: " + value
|
||||
sys.exit(2)
|
||||
# normalize tag
|
||||
value = value + (4 - len(value)) * " "
|
||||
skipTables.append(value)
|
||||
elif option == "-v":
|
||||
verbose = 1
|
||||
elif option == "-h":
|
||||
@ -45,6 +55,9 @@ for option, value in options:
|
||||
elif option == "-s":
|
||||
splitTables = 1
|
||||
|
||||
if tables and skipTables:
|
||||
print "-t and -x options are mutually exlusive"
|
||||
sys.exit(2)
|
||||
|
||||
if len(args) == 1:
|
||||
ttPath = args[0]
|
||||
@ -60,4 +73,4 @@ else:
|
||||
sys.exit(2)
|
||||
|
||||
tt = ttLib.TTFont(ttPath, verbose=verbose)
|
||||
tt.saveXML(xmlPath, tables=tables, splitTables=splitTables)
|
||||
tt.saveXML(xmlPath, tables=tables, skipTables=skipTables, splitTables=splitTables)
|
||||
|
19
ttDump.py
19
ttDump.py
@ -1,7 +1,7 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
"""\
|
||||
usage: %s [-hvs] [-t <table>] TrueType-file [XML-output-file]
|
||||
usage: %s [-hvs] [-t <table>] [-x <table>] TrueType-file [XML-output-file]
|
||||
Dump a TrueType font as an XML file. If the XML-output-file argument
|
||||
is omitted, the out put file name will be constructed from the input
|
||||
file name, like so: *.ttf becomes *.xml. Either way, existing files
|
||||
@ -11,6 +11,8 @@ usage: %s [-hvs] [-t <table>] TrueType-file [XML-output-file]
|
||||
-t <table> specify a table to dump. Multiple -t options
|
||||
are allowed. When no -t option is specified, all tables
|
||||
will be dumped
|
||||
-x <table> specify a table to exclude from the dump. Multiple
|
||||
-x options are allowed. -t and -x are mutually exclusive.
|
||||
-v verbose: messages will be written to stdout about what is
|
||||
being done.
|
||||
-s split tables: save the XML in a separate XML file per table.
|
||||
@ -24,11 +26,12 @@ usage: %s [-hvs] [-t <table>] TrueType-file [XML-output-file]
|
||||
import sys, os, getopt
|
||||
from fontTools import ttLib
|
||||
|
||||
options, args = getopt.getopt(sys.argv[1:], "shvt:")
|
||||
options, args = getopt.getopt(sys.argv[1:], "shvt:x:")
|
||||
|
||||
verbose = 0
|
||||
splitTables = 0
|
||||
tables = []
|
||||
skipTables = []
|
||||
for option, value in options:
|
||||
if option == "-t":
|
||||
if len(value) > 4:
|
||||
@ -37,6 +40,13 @@ for option, value in options:
|
||||
# normalize tag
|
||||
value = value + (4 - len(value)) * " "
|
||||
tables.append(value)
|
||||
elif option == "-x":
|
||||
if len(value) > 4:
|
||||
print "illegal table tag: " + value
|
||||
sys.exit(2)
|
||||
# normalize tag
|
||||
value = value + (4 - len(value)) * " "
|
||||
skipTables.append(value)
|
||||
elif option == "-v":
|
||||
verbose = 1
|
||||
elif option == "-h":
|
||||
@ -45,6 +55,9 @@ for option, value in options:
|
||||
elif option == "-s":
|
||||
splitTables = 1
|
||||
|
||||
if tables and skipTables:
|
||||
print "-t and -x options are mutually exlusive"
|
||||
sys.exit(2)
|
||||
|
||||
if len(args) == 1:
|
||||
ttPath = args[0]
|
||||
@ -60,4 +73,4 @@ else:
|
||||
sys.exit(2)
|
||||
|
||||
tt = ttLib.TTFont(ttPath, verbose=verbose)
|
||||
tt.saveXML(xmlPath, tables=tables, splitTables=splitTables)
|
||||
tt.saveXML(xmlPath, tables=tables, skipTables=skipTables, splitTables=splitTables)
|
||||
|
Loading…
x
Reference in New Issue
Block a user