From 3e097c609540944dd9290ad58df346ca86492031 Mon Sep 17 00:00:00 2001 From: Just Date: Thu, 23 Dec 1999 14:44:16 +0000 Subject: [PATCH] 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 --- Lib/fontTools/ttLib/__init__.py | 13 +++++++++---- Lib/fontTools/ttLib/tables/_g_l_y_f.py | 14 +++++++------- Lib/fontTools/ttLib/tables/_h_h_e_a.py | 5 ++--- Lib/fontTools/ttLib/tables/_m_a_x_p.py | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Lib/fontTools/ttLib/__init__.py b/Lib/fontTools/ttLib/__init__.py index 9e570f72b..d8c128eb9 100644 --- a/Lib/fontTools/ttLib/__init__.py +++ b/Lib/fontTools/ttLib/__init__.py @@ -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 diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py index c644aa235..734b76737 100644 --- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py +++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py @@ -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: diff --git a/Lib/fontTools/ttLib/tables/_h_h_e_a.py b/Lib/fontTools/ttLib/tables/_h_h_e_a.py index fca75cb39..d8d297a91 100644 --- a/Lib/fontTools/ttLib/tables/_h_h_e_a.py +++ b/Lib/fontTools/ttLib/tables/_h_h_e_a.py @@ -31,14 +31,13 @@ class table__h_h_e_a(DefaultTable.DefaultTable): sstruct.unpack(hheaFormat, data, self) def compile(self, ttFont): - self.recalc(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 diff --git a/Lib/fontTools/ttLib/tables/_m_a_x_p.py b/Lib/fontTools/ttLib/tables/_m_a_x_p.py index 1c75e6d5e..07a355056 100644 --- a/Lib/fontTools/ttLib/tables/_m_a_x_p.py +++ b/Lib/fontTools/ttLib/tables/_m_a_x_p.py @@ -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!!!