reordered/regrouped some methods for clarity

git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@288 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
jvr 2002-07-23 08:43:03 +00:00
parent 8e48312f88
commit 4105ca0b95

View File

@ -129,8 +129,46 @@ class OTTableWriter:
self.valueFormat = valueFormat self.valueFormat = valueFormat
self.pos = None self.pos = None
def getSubWriter(self): # assembler interface
return self.__class__(self.tableType, self.valueFormat)
def getAllData(self):
"""Assemble all data, including all subtables."""
self._doneWriting()
tables = self._gatherTables()
tables.reverse()
# Gather all data in two passes: the absolute positions of all
# subtable are needed before the actual data can be assembled.
pos = 0
for table in tables:
table.pos = pos
pos = pos + table.getDataLength()
data = []
for table in tables:
tableData = table.getData()
data.append(tableData)
return "".join(data)
def getDataLength(self):
"""Return the length of this table in bytes, without subtables."""
l = 0
for item in self.items:
if hasattr(item, "getData") or hasattr(item, "getCountData"):
l = l + 2 # sizeof(UShort)
else:
l = l + len(item)
return l
def getData(self):
"""Assemble the data for this writer/table, without subtables."""
items = list(self.items) # make a shallow copy
for i in range(len(items)):
item = items[i]
if hasattr(item, "getData"):
items[i] = packUShort(item.pos - self.pos)
return "".join(items)
def __hash__(self): def __hash__(self):
# only works after self._doneWriting() has been called # only works after self._doneWriting() has been called
@ -171,42 +209,10 @@ class OTTableWriter:
tables.append(self) tables.append(self)
return tables return tables
def getAllData(self): # interface for gathering data, as used by table.compile()
"""Return all data, including all subtables."""
self._doneWriting()
tables = self._gatherTables()
tables.reverse()
pos = 0 def getSubWriter(self):
for table in tables: return self.__class__(self.tableType, self.valueFormat)
table.pos = pos
pos = pos + table.getDataLength()
data = []
for table in tables:
tableData = table.getData()
data.append(tableData)
return "".join(data)
def getDataLength(self):
"""Return the length of this table in bytes, without subtables."""
l = 0
for item in self.items:
if hasattr(item, "getData") or hasattr(item, "getCountData"):
l = l + 2 # sizeof(UShort)
else:
l = l + len(item)
return l
def getData(self):
"""Return the data for this writer/table, without any subtables."""
items = list(self.items) # make a shallow copy
for i in range(len(items)):
item = items[i]
if hasattr(item, "getData"):
items[i] = packUShort(item.pos - self.pos)
return "".join(items)
def writeUShort(self, value): def writeUShort(self, value):
assert 0 <= value < 0x10000 assert 0 <= value < 0x10000