don't recalc a number of things then TTFont().recalcBBoxes is off. This allows us to compact glyphs right after they've been parsed from XML, which should greatly reduce memory usage, and therefore should speedup compiling large fonts.

git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@31 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
Just 1999-12-23 14:44:16 +00:00
parent fd5a93240e
commit 3e097c6095
4 changed files with 19 additions and 15 deletions

View File

@ -41,7 +41,7 @@ Dumping 'prep' table...
""" """
__author__ = "Just van Rossum, just@letterror.com" __author__ = "Just van Rossum, just@letterror.com"
__version__ = "$Id: __init__.py,v 1.5 1999-12-18 21:32:40 Just Exp $" __version__ = "$Id: __init__.py,v 1.6 1999-12-23 14:44:02 Just Exp $"
__release__ = "1.0a6" __release__ = "1.0a6"
import os import os
@ -82,9 +82,14 @@ class TTFont:
argument: this is the way to create a new empty font. argument: this is the way to create a new empty font.
In this case you can optionally supply the 'sfntVersion' argument. In this case you can optionally supply the 'sfntVersion' argument.
If the recalcBBoxes argument is false, glyph bounding boxes will If the recalcBBoxes argument is false, a number of things will not
not be recalculated, but taken as they were. This is needed with be recalculated upon save/compile:
certain kinds of CJK fonts (ask Werner Lemberg ;-). - glyph bounding boxes
- maxp font bounding box
- hhea min/max values
This is needed with certain kinds of CJK fonts (ask Werner Lemberg ;-)
but also limits memory use greatly, which should have some impact on
the time needed to compile large fonts.
""" """
import sfnt import sfnt

View File

@ -49,7 +49,7 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
dataList = [] dataList = []
recalcBBoxes = ttFont.recalcBBoxes recalcBBoxes = ttFont.recalcBBoxes
for glyphName in ttFont.getGlyphOrder(): for glyphName in ttFont.getGlyphOrder():
glyph = self[glyphName] glyph = self.glyphs[glyphName]
glyphData = glyph.compile(self, recalcBBoxes) glyphData = glyph.compile(self, recalcBBoxes)
locations.append(currentLocation) locations.append(currentLocation)
currentLocation = currentLocation + len(glyphData) currentLocation = currentLocation + len(glyphData)
@ -126,6 +126,8 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
if type(element) == types.StringType: if type(element) == types.StringType:
continue continue
glyph.fromXML(element, ttFont) glyph.fromXML(element, ttFont)
if not ttFont.recalcBBoxes:
glyph.compact(self, 0)
def setGlyphOrder(self, glyphOrder): def setGlyphOrder(self, glyphOrder):
self.glyphOrder = glyphOrder self.glyphOrder = glyphOrder
@ -137,12 +139,6 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
# XXX optimize with reverse dict!!! # XXX optimize with reverse dict!!!
return self.glyphOrder.index(glyphName) return self.glyphOrder.index(glyphName)
#def keys(self):
# return self.glyphOrder[:]
#
#def has_key(self, glyphName):
# return self.glyphs.has_key(glyphName)
#
def __getitem__(self, glyphName): def __getitem__(self, glyphName):
glyph = self.glyphs[glyphName] glyph = self.glyphs[glyphName]
glyph.expand(self) glyph.expand(self)
@ -215,6 +211,10 @@ class Glyph:
if not hasattr(self, "data"): if not hasattr(self, "data"):
# already unpacked # already unpacked
return return
if not self.data:
# empty char
self.numberOfContours = 0
return
dummy, data = sstruct.unpack2(glyphHeaderFormat, self.data, self) dummy, data = sstruct.unpack2(glyphHeaderFormat, self.data, self)
del self.data del self.data
if self.numberOfContours == -1: if self.numberOfContours == -1:

View File

@ -31,14 +31,13 @@ class table__h_h_e_a(DefaultTable.DefaultTable):
sstruct.unpack(hheaFormat, data, self) sstruct.unpack(hheaFormat, data, self)
def compile(self, ttFont): def compile(self, ttFont):
self.recalc(ttFont) if ttFont.isLoaded('glyf') and ttFont.recalcBBoxes:
self.recalc(ttFont)
return sstruct.pack(hheaFormat, self) return sstruct.pack(hheaFormat, self)
def recalc(self, ttFont): def recalc(self, ttFont):
hmtxTable = ttFont['hmtx'] hmtxTable = ttFont['hmtx']
if ttFont.has_key('glyf'): if ttFont.has_key('glyf'):
if not ttFont.isLoaded('glyf'):
return
glyfTable = ttFont['glyf'] glyfTable = ttFont['glyf']
advanceWidthMax = -100000 # arbitrary big negative number advanceWidthMax = -100000 # arbitrary big negative number
minLeftSideBearing = 100000 # arbitrary big number minLeftSideBearing = 100000 # arbitrary big number

View File

@ -41,7 +41,7 @@ class table__m_a_x_p(DefaultTable.DefaultTable):
def compile(self, ttFont): def compile(self, ttFont):
if ttFont.has_key('glyf'): if ttFont.has_key('glyf'):
if ttFont.isLoaded('glyf'): if ttFont.isLoaded('glyf') and ttFont.recalcBBoxes:
self.recalc(ttFont) self.recalc(ttFont)
else: else:
pass # XXX CFF!!! pass # XXX CFF!!!