- fixed broken agl import
- changed TTFOnt.saveXML + splitTables<>0 behavior: now expects a path to a directory git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@40 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
parent
1670f7af0e
commit
7dcc91674e
@ -40,11 +40,14 @@ Dumping 'prep' table...
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = "Just van Rossum, just@letterror.com"
|
#
|
||||||
__version__ = "$Id: __init__.py,v 1.8 1999-12-27 19:48:21 Just Exp $"
|
# $Id: __init__.py,v 1.9 1999-12-29 13:06:08 Just Exp $
|
||||||
__release__ = "1.0a6"
|
#
|
||||||
|
|
||||||
|
__version__ = "1.0a6"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import string
|
||||||
import types
|
import types
|
||||||
|
|
||||||
class TTLibError(Exception): pass
|
class TTLibError(Exception): pass
|
||||||
@ -158,8 +161,13 @@ class TTFont:
|
|||||||
|
|
||||||
writer.close()
|
writer.close()
|
||||||
|
|
||||||
def saveXML(self, file, progress=None, tables=None, splitTables=0):
|
def saveXML(self, fileOrPath, progress=None, tables=None, splitTables=0):
|
||||||
"""Export the font as an XML-based text file."""
|
"""Export the font as an XML-based text file, or as a series of text
|
||||||
|
files when splitTables is true. In the latter case, the 'fileOrPath'
|
||||||
|
argument should be a path to a directory.
|
||||||
|
The 'tables' argument must either be None (dump all tables) or a
|
||||||
|
list of tables to dump.
|
||||||
|
"""
|
||||||
import xmlWriter
|
import xmlWriter
|
||||||
if not tables:
|
if not tables:
|
||||||
tables = self.keys()
|
tables = self.keys()
|
||||||
@ -168,22 +176,24 @@ class TTFont:
|
|||||||
if progress:
|
if progress:
|
||||||
progress.set(0, numTables * numGlyphs)
|
progress.set(0, numTables * numGlyphs)
|
||||||
if not splitTables:
|
if not splitTables:
|
||||||
writer = xmlWriter.XMLWriter(file)
|
writer = xmlWriter.XMLWriter(fileOrPath)
|
||||||
writer.begintag("ttFont", sfntVersion=`self.sfntVersion`[1:-1],
|
writer.begintag("ttFont", sfntVersion=`self.sfntVersion`[1:-1],
|
||||||
ttLibVersion=__release__)
|
ttLibVersion=__version__)
|
||||||
writer.newline()
|
writer.newline()
|
||||||
writer.newline()
|
writer.newline()
|
||||||
else:
|
else:
|
||||||
# 'file' must now be a string
|
# 'fileOrPath' must now be a path (pointing to a directory)
|
||||||
base, ext = os.path.splitext(file)
|
if not os.path.exists(fileOrPath):
|
||||||
fileNameTemplate = base + ".%s" + ext
|
os.mkdir(fileOrPath)
|
||||||
|
fileNameTemplate = os.path.join(fileOrPath,
|
||||||
|
os.path.basename(fileOrPath)) + ".%s.xml"
|
||||||
|
|
||||||
for i in range(numTables):
|
for i in range(numTables):
|
||||||
tag = tables[i]
|
tag = tables[i]
|
||||||
if splitTables:
|
if splitTables:
|
||||||
writer = xmlWriter.XMLWriter(fileNameTemplate % tag2identifier(tag))
|
writer = xmlWriter.XMLWriter(fileNameTemplate % tag2identifier(tag))
|
||||||
writer.begintag("ttFont", sfntVersion=`self.sfntVersion`[1:-1],
|
writer.begintag("ttFont", sfntVersion=`self.sfntVersion`[1:-1],
|
||||||
ttLibVersion=__release__)
|
ttLibVersion=__version__)
|
||||||
writer.newline()
|
writer.newline()
|
||||||
writer.newline()
|
writer.newline()
|
||||||
table = self[tag]
|
table = self[tag]
|
||||||
@ -342,13 +352,12 @@ class TTFont:
|
|||||||
tempcmap = self['cmap'].getcmap(3, 1)
|
tempcmap = self['cmap'].getcmap(3, 1)
|
||||||
if tempcmap is not None:
|
if tempcmap is not None:
|
||||||
# we have a unicode cmap
|
# we have a unicode cmap
|
||||||
import agl, string
|
from fontTools import agl
|
||||||
cmap = tempcmap.cmap
|
cmap = tempcmap.cmap
|
||||||
# create a reverse cmap dict
|
# create a reverse cmap dict
|
||||||
reversecmap = {}
|
reversecmap = {}
|
||||||
for unicode, name in cmap.items():
|
for unicode, name in cmap.items():
|
||||||
reversecmap[name] = unicode
|
reversecmap[name] = unicode
|
||||||
assert len(reversecmap) == len(cmap)
|
|
||||||
for i in range(numGlyphs):
|
for i in range(numGlyphs):
|
||||||
tempName = glyphOrder[i]
|
tempName = glyphOrder[i]
|
||||||
if reversecmap.has_key(tempName):
|
if reversecmap.has_key(tempName):
|
||||||
@ -533,7 +542,6 @@ def tag2identifier(tag):
|
|||||||
|
|
||||||
def identifier2tag(ident):
|
def identifier2tag(ident):
|
||||||
"""the opposite of tag2identifier()"""
|
"""the opposite of tag2identifier()"""
|
||||||
import string
|
|
||||||
if len(ident) % 2 and ident[0] == "_":
|
if len(ident) % 2 and ident[0] == "_":
|
||||||
ident = ident[1:]
|
ident = ident[1:]
|
||||||
assert not (len(ident) % 2)
|
assert not (len(ident) % 2)
|
||||||
@ -556,7 +564,7 @@ def tag2xmltag(tag):
|
|||||||
to a valid XML element name. Since XML element names are
|
to a valid XML element name. Since XML element names are
|
||||||
case sensitive, this is a fairly simple/readable translation.
|
case sensitive, this is a fairly simple/readable translation.
|
||||||
"""
|
"""
|
||||||
import string, re
|
import re
|
||||||
if tag == "OS/2":
|
if tag == "OS/2":
|
||||||
return "OS_2"
|
return "OS_2"
|
||||||
if re.match("[A-Za-z_][A-Za-z_0-9]* *$", tag):
|
if re.match("[A-Za-z_][A-Za-z_0-9]* *$", tag):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user