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
diff --git a/Lib/fontTools/ttLib/__init__.py b/Lib/fontTools/ttLib/__init__.py
index e6c678a..18520fd 100644
--- a/Lib/fontTools/ttLib/__init__.py
+++ b/Lib/fontTools/ttLib/__init__.py
@@ -42,7 +42,7 @@
"""
#
-# $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 @@
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 @@
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 @@
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 4a4a7e7..da3f37e 100644
--- a/Lib/fontTools/ttLib/sfnt.py
+++ b/Lib/fontTools/ttLib/sfnt.py
@@ -105,7 +105,7 @@
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 @@
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