big change: the glyph order is now dumped as a separate table and not as part of glyf (which didn't make much sense to begin with, but can't work at all in the case of CFF...)
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@252 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
parent
fe665777ea
commit
0011bb6910
@ -42,7 +42,7 @@ Dumping 'prep' table...
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
#
|
#
|
||||||
# $Id: __init__.py,v 1.29 2002-05-22 20:15:10 jvr Exp $
|
# $Id: __init__.py,v 1.30 2002-05-23 09:42:45 jvr Exp $
|
||||||
#
|
#
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -78,7 +78,7 @@ class TTFont:
|
|||||||
The 'checkChecksums' argument is used to specify how sfnt
|
The 'checkChecksums' argument is used to specify how sfnt
|
||||||
checksums are treated upon reading a file from disk:
|
checksums are treated upon reading a file from disk:
|
||||||
0: don't check (default)
|
0: don't check (default)
|
||||||
1: check, print warnings if a wrong checksum is found (default)
|
1: check, print warnings if a wrong checksum is found
|
||||||
2: check, raise an exception if a wrong checksum is found.
|
2: check, raise an exception if a wrong checksum is found.
|
||||||
|
|
||||||
The TTFont constructor can also be called without a 'file'
|
The TTFont constructor can also be called without a 'file'
|
||||||
@ -154,6 +154,7 @@ class TTFont:
|
|||||||
closeStream = 0
|
closeStream = 0
|
||||||
|
|
||||||
tags = self.keys()
|
tags = self.keys()
|
||||||
|
tags.remove("GlyphOrder")
|
||||||
numTables = len(tags)
|
numTables = len(tags)
|
||||||
writer = sfnt.SFNTWriter(file, numTables, self.sfntVersion)
|
writer = sfnt.SFNTWriter(file, numTables, self.sfntVersion)
|
||||||
|
|
||||||
@ -201,18 +202,17 @@ class TTFont:
|
|||||||
|
|
||||||
for i in range(numTables):
|
for i in range(numTables):
|
||||||
tag = tables[i]
|
tag = tables[i]
|
||||||
xmlTag = tagToXML(tag)
|
|
||||||
if splitTables:
|
if splitTables:
|
||||||
tablePath = fileNameTemplate % tagToIdentifier(tag)
|
tablePath = fileNameTemplate % tagToIdentifier(tag)
|
||||||
tableWriter = xmlWriter.XMLWriter(tablePath)
|
tableWriter = xmlWriter.XMLWriter(tablePath)
|
||||||
tableWriter.begintag("ttFont", ttLibVersion=version)
|
tableWriter.begintag("ttFont", ttLibVersion=version)
|
||||||
tableWriter.newline()
|
tableWriter.newline()
|
||||||
tableWriter.newline()
|
tableWriter.newline()
|
||||||
writer.simpletag(xmlTag, src=os.path.basename(tablePath))
|
writer.simpletag(tagToXML(tag), src=os.path.basename(tablePath))
|
||||||
writer.newline()
|
writer.newline()
|
||||||
else:
|
else:
|
||||||
tableWriter = writer
|
tableWriter = writer
|
||||||
self._tableToXML(tableWriter, tag, xmlTag, progress)
|
self._tableToXML(tableWriter, tag, progress)
|
||||||
if splitTables:
|
if splitTables:
|
||||||
tableWriter.endtag("ttFont")
|
tableWriter.endtag("ttFont")
|
||||||
tableWriter.newline()
|
tableWriter.newline()
|
||||||
@ -225,7 +225,7 @@ class TTFont:
|
|||||||
if self.verbose:
|
if self.verbose:
|
||||||
debugmsg("Done dumping TTX")
|
debugmsg("Done dumping TTX")
|
||||||
|
|
||||||
def _tableToXML(self, writer, tag, xmlTag, progress):
|
def _tableToXML(self, writer, tag, progress):
|
||||||
if self.has_key(tag):
|
if self.has_key(tag):
|
||||||
table = self[tag]
|
table = self[tag]
|
||||||
report = "Dumping '%s' table..." % tag
|
report = "Dumping '%s' table..." % tag
|
||||||
@ -239,6 +239,7 @@ class TTFont:
|
|||||||
print report
|
print report
|
||||||
if not self.has_key(tag):
|
if not self.has_key(tag):
|
||||||
return
|
return
|
||||||
|
xmlTag = tagToXML(tag)
|
||||||
if hasattr(table, "ERROR"):
|
if hasattr(table, "ERROR"):
|
||||||
writer.begintag(xmlTag, ERROR="decompilation error")
|
writer.begintag(xmlTag, ERROR="decompilation error")
|
||||||
else:
|
else:
|
||||||
@ -269,6 +270,8 @@ class TTFont:
|
|||||||
return 1
|
return 1
|
||||||
elif self.reader and self.reader.has_key(tag):
|
elif self.reader and self.reader.has_key(tag):
|
||||||
return 1
|
return 1
|
||||||
|
elif tag == "GlyphOrder":
|
||||||
|
return 1
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@ -279,7 +282,9 @@ class TTFont:
|
|||||||
if key not in keys:
|
if key not in keys:
|
||||||
keys.append(key)
|
keys.append(key)
|
||||||
keys.sort()
|
keys.sort()
|
||||||
return keys
|
if "GlyphOrder" in keys:
|
||||||
|
keys.remove("GlyphOrder")
|
||||||
|
return ["GlyphOrder"] + keys
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.keys())
|
return len(self.keys())
|
||||||
@ -288,6 +293,10 @@ class TTFont:
|
|||||||
try:
|
try:
|
||||||
return self.tables[tag]
|
return self.tables[tag]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
if tag == "GlyphOrder":
|
||||||
|
table = GlyphOrder(tag)
|
||||||
|
self.tables[tag] = table
|
||||||
|
return table
|
||||||
if self.reader is not None:
|
if self.reader is not None:
|
||||||
import traceback
|
import traceback
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
@ -514,6 +523,33 @@ class TTFont:
|
|||||||
raise KeyError, tag
|
raise KeyError, tag
|
||||||
|
|
||||||
|
|
||||||
|
class GlyphOrder:
|
||||||
|
|
||||||
|
"""A fake table. The glyph order isn't in the font as a separate table,
|
||||||
|
but it's nice to present it as such in the TTX format.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, tag):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def toXML(self, writer, ttFont):
|
||||||
|
glyphOrder = ttFont.getGlyphOrder()
|
||||||
|
writer.comment("The 'id' attribute is merely a reading aid; "
|
||||||
|
"it is ignored when read.")
|
||||||
|
writer.newline()
|
||||||
|
for i in range(len(glyphOrder)):
|
||||||
|
glyphName = glyphOrder[i]
|
||||||
|
writer.simpletag("GlyphID", id=i, name=glyphName)
|
||||||
|
writer.newline()
|
||||||
|
|
||||||
|
def fromXML(self, (name, attrs, content), ttFont):
|
||||||
|
if not hasattr(self, "glyphOrder"):
|
||||||
|
self.glyphOrder = []
|
||||||
|
ttFont.setGlyphOrder(self.glyphOrder)
|
||||||
|
if name == "GlyphID":
|
||||||
|
self.glyphOrder.append(attrs["name"])
|
||||||
|
|
||||||
|
|
||||||
def _test_endianness():
|
def _test_endianness():
|
||||||
"""Test the endianness of the machine. This is crucial to know
|
"""Test the endianness of the machine. This is crucial to know
|
||||||
since TrueType data is always big endian, even on little endian
|
since TrueType data is always big endian, even on little endian
|
||||||
@ -632,6 +668,8 @@ def tagToXML(tag):
|
|||||||
import re
|
import re
|
||||||
if tag == "OS/2":
|
if tag == "OS/2":
|
||||||
return "OS_2"
|
return "OS_2"
|
||||||
|
elif tag == "GlyphOrder":
|
||||||
|
return "GlyphOrder"
|
||||||
if re.match("[A-Za-z_][A-Za-z_0-9]* *$", tag):
|
if re.match("[A-Za-z_][A-Za-z_0-9]* *$", tag):
|
||||||
return string.strip(tag)
|
return string.strip(tag)
|
||||||
else:
|
else:
|
||||||
|
@ -30,7 +30,6 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
|
|||||||
loca = ttFont['loca']
|
loca = ttFont['loca']
|
||||||
last = loca[0]
|
last = loca[0]
|
||||||
self.glyphs = {}
|
self.glyphs = {}
|
||||||
self.glyphOrder = []
|
|
||||||
self.glyphOrder = glyphOrder = ttFont.getGlyphOrder()
|
self.glyphOrder = glyphOrder = ttFont.getGlyphOrder()
|
||||||
for i in range(0, len(loca)-1):
|
for i in range(0, len(loca)-1):
|
||||||
glyphName = glyphOrder[i]
|
glyphName = glyphOrder[i]
|
||||||
@ -46,6 +45,8 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
|
|||||||
# raise ttLib.TTLibError, "too much 'glyf' table data"
|
# raise ttLib.TTLibError, "too much 'glyf' table data"
|
||||||
|
|
||||||
def compile(self, ttFont):
|
def compile(self, ttFont):
|
||||||
|
if not hasattr(self, "glyphOrder"):
|
||||||
|
self.glyphOrder = ttFont.getGlyphOrder()
|
||||||
import string
|
import string
|
||||||
locations = []
|
locations = []
|
||||||
currentLocation = 0
|
currentLocation = 0
|
||||||
@ -64,16 +65,6 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def toXML(self, writer, ttFont, progress=None):
|
def toXML(self, writer, ttFont, progress=None):
|
||||||
writer.newline()
|
|
||||||
glyphOrder = ttFont.getGlyphOrder()
|
|
||||||
writer.begintag("GlyphOrder")
|
|
||||||
writer.newline()
|
|
||||||
for i in range(len(glyphOrder)):
|
|
||||||
glyphName = glyphOrder[i]
|
|
||||||
writer.simpletag("GlyphID", id=i, name=glyphName)
|
|
||||||
writer.newline()
|
|
||||||
writer.endtag("GlyphOrder")
|
|
||||||
writer.newline()
|
|
||||||
writer.newline()
|
writer.newline()
|
||||||
glyphNames = ttFont.getGlyphNames()
|
glyphNames = ttFont.getGlyphNames()
|
||||||
writer.comment("The xMin, yMin, xMax and yMax values\nwill be recalculated by the compiler.")
|
writer.comment("The xMin, yMin, xMax and yMax values\nwill be recalculated by the compiler.")
|
||||||
@ -103,19 +94,8 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
|
|||||||
writer.newline()
|
writer.newline()
|
||||||
|
|
||||||
def fromXML(self, (name, attrs, content), ttFont):
|
def fromXML(self, (name, attrs, content), ttFont):
|
||||||
if name == "GlyphOrder":
|
if name <> "TTGlyph":
|
||||||
glyphOrder = []
|
return
|
||||||
for element in content:
|
|
||||||
if type(element) <> TupleType:
|
|
||||||
continue
|
|
||||||
name, attrs, content = element
|
|
||||||
if name == "GlyphID":
|
|
||||||
index = safeEval(attrs["id"])
|
|
||||||
glyphName = attrs["name"]
|
|
||||||
glyphOrder = glyphOrder + (1 + index - len(glyphOrder)) * [".notdef"]
|
|
||||||
glyphOrder[index] = glyphName
|
|
||||||
ttFont.setGlyphOrder(glyphOrder)
|
|
||||||
elif name == "TTGlyph":
|
|
||||||
if not hasattr(self, "glyphs"):
|
if not hasattr(self, "glyphs"):
|
||||||
self.glyphs = {}
|
self.glyphs = {}
|
||||||
glyphName = attrs["name"]
|
glyphName = attrs["name"]
|
||||||
|
@ -62,15 +62,17 @@ class ExpatParser:
|
|||||||
importXML(self.ttFont, subFile, self.progress)
|
importXML(self.ttFont, subFile, self.progress)
|
||||||
self.contentStack.append([])
|
self.contentStack.append([])
|
||||||
return
|
return
|
||||||
msg = "Parsing '%s' table..." % ttLib.xmlToTag(name)
|
tag = ttLib.xmlToTag(name)
|
||||||
|
msg = "Parsing '%s' table..." % tag
|
||||||
if self.progress:
|
if self.progress:
|
||||||
self.progress.setlabel(msg)
|
self.progress.setlabel(msg)
|
||||||
elif self.ttFont.verbose:
|
elif self.ttFont.verbose:
|
||||||
ttLib.debugmsg(msg)
|
ttLib.debugmsg(msg)
|
||||||
else:
|
else:
|
||||||
print msg
|
print msg
|
||||||
tag = ttLib.xmlToTag(name)
|
if tag == "GlyphOrder":
|
||||||
if attrs.has_key("ERROR"):
|
tableClass = ttLib.GlyphOrder
|
||||||
|
elif attrs.has_key("ERROR"):
|
||||||
tableClass = DefaultTable
|
tableClass = DefaultTable
|
||||||
else:
|
else:
|
||||||
tableClass = ttLib.getTableClass(tag)
|
tableClass = ttLib.getTableClass(tag)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user