From 0f675860ce081e9aeaf880ccc4a8e5d49e83f553 Mon Sep 17 00:00:00 2001 From: Just Date: Mon, 2 Oct 2000 07:51:42 +0000 Subject: [PATCH] improved support for writing to (in memory) streams git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@119 4cde692c-a291-49d1-8350-778aa11640f8 --- Lib/fontTools/ttLib/__init__.py | 10 ++++++---- Lib/fontTools/ttLib/sfnt.py | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Lib/fontTools/ttLib/__init__.py b/Lib/fontTools/ttLib/__init__.py index e6c678a73..18520fd61 100644 --- a/Lib/fontTools/ttLib/__init__.py +++ b/Lib/fontTools/ttLib/__init__.py @@ -42,7 +42,7 @@ Dumping 'prep' table... """ # -# $Id: __init__.py,v 1.15 2000-08-23 12:31:52 Just Exp $ +# $Id: __init__.py,v 1.16 2000-10-02 07:51:42 Just Exp $ # __version__ = "1.0a6" @@ -138,8 +138,9 @@ class TTFont: On the Mac, if makeSuitcase is true, a suitcase (resource fork) file will we made instead of a flat .ttf file. """ - import sfnt + from fontTools.ttLib import sfnt if type(file) == types.StringType: + closeStream = 1 if os.name == "mac" and makeSuitcase: import macUtils file = macUtils.SFNTResourceWriter(file, self) @@ -150,7 +151,8 @@ class TTFont: fss = macfs.FSSpec(file.name) fss.SetCreatorType('mdos', 'BINA') else: - pass # assume "file" is a writable file object + # assume "file" is a writable file object + closeStream = 0 tags = self.keys() numTables = len(tags) @@ -160,7 +162,7 @@ class TTFont: for tag in tags: self._writeTable(tag, writer, done) - writer.close() + writer.close(closeStream) def saveXML(self, fileOrPath, progress=None, tables=None, skipTables=None, splitTables=0, disassembleInstructions=1): diff --git a/Lib/fontTools/ttLib/sfnt.py b/Lib/fontTools/ttLib/sfnt.py index 4a4a7e731..da3f37e2a 100644 --- a/Lib/fontTools/ttLib/sfnt.py +++ b/Lib/fontTools/ttLib/sfnt.py @@ -105,7 +105,7 @@ class SFNTWriter: entry.checkSum = calcchecksum(data) self.tables[tag] = entry - def close(self): + def close(self, closeStream=1): """All tables must have been written to disk. Now write the directory. """ @@ -123,7 +123,8 @@ class SFNTWriter: self.calcmasterchecksum(directory) self.file.seek(0) self.file.write(directory) - self.file.close() + if closeStream: + self.file.close() def calcmasterchecksum(self, directory): # calculate checkSumAdjustment