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"
__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"
import os
@ -82,9 +82,14 @@ class TTFont:
argument: this is the way to create a new empty font.
In this case you can optionally supply the 'sfntVersion' argument.
If the recalcBBoxes argument is false, glyph bounding boxes will
not be recalculated, but taken as they were. This is needed with
certain kinds of CJK fonts (ask Werner Lemberg ;-).
If the recalcBBoxes argument is false, a number of things will not
be recalculated upon save/compile:
- 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

View File

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

View File

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

View File

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