ttfonts.py: allow unicode filenames (suggestion from Yoann Roman <yroman-reportlab@altalang.com>)
authorrgbecker
Wed, 11 Mar 2009 10:42:19 +0000
changeset 3132 f87241ffab1c
parent 3131 0f15fabe9d8d
child 3134 e403094e7c98
ttfonts.py: allow unicode filenames (suggestion from Yoann Roman <yroman-reportlab@altalang.com>)
src/reportlab/pdfbase/ttfonts.py
--- a/src/reportlab/pdfbase/ttfonts.py	Tue Mar 03 17:38:41 2009 +0000
+++ b/src/reportlab/pdfbase/ttfonts.py	Wed Mar 11 10:42:19 2009 +0000
@@ -1,6 +1,5 @@
-#Copyright ReportLab Europe Ltd. 2000-2004
+#Copyright ReportLab Europe Ltd. 2000-2009
 #see license.txt for license details
-#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/pdfbase/ttfonts.py
 __version__ = '$Id$'
 __doc__="""TrueType font support
 
@@ -53,7 +52,6 @@
 """
 
 import string
-from types import StringType, UnicodeType
 from struct import pack, unpack
 from reportlab.lib.utils import getStringIO
 from reportlab.pdfbase import pdfmetrics, pdfdoc
@@ -258,13 +256,13 @@
             raise TTFError('Not a TrueType font: version=0x%8.8X' % version)
         return version==self.ttfVersions[-1]
 
-    def readFile(self,file):
-        if type(file) is StringType:
-            self.filename, file = TTFOpenFile(file)
+    def readFile(self,f):
+        if hasattr(f,'read'):
+            self.filename = '(ttf)'
         else:
-            self.filename = '(ttf)'
+            self.filename, f = TTFOpenFile(f)
 
-        self._ttf_data = file.read()
+        self._ttf_data = f.read()
         self._pos = 0
 
     def checksumTables(self):
@@ -999,7 +997,7 @@
 
     def _py_stringWidth(self, text, size, encoding='utf-8'):
         "Calculate text width"
-        if type(text) is not UnicodeType:
+        if not isinstance(text,unicode):
             text = unicode(text, encoding or 'utf-8')   # encoding defaults to utf-8
         g = self.face.charWidths.get
         dw = self.face.defaultWidth
@@ -1029,7 +1027,7 @@
         curSet = -1
         cur = []
         results = []
-        if type(text) is not UnicodeType:
+        if not isinstance(text,unicode):
             text = unicode(text, encoding or 'utf-8')   # encoding defaults to utf-8
         assignments = state.assignments
         subsets = state.subsets