tests/test_pdfbase_ttfonts.py
branchrtl-support
changeset 3467 4f25b3a34c5f
parent 2984 c63f149d55aa
--- a/tests/test_pdfbase_ttfonts.py	Mon Nov 23 13:27:57 2009 +0000
+++ b/tests/test_pdfbase_ttfonts.py	Thu Oct 21 10:34:13 2010 +0000
@@ -17,6 +17,7 @@
                                       parse_utf8, makeToUnicodeCMap, \
                                       FF_SYMBOLIC, FF_NONSYMBOLIC, \
                                       calcChecksum, add32
+from reportlab import rl_config
 
 def utf8(code):
     "Convert a given UCS character index into UTF-8"
@@ -66,7 +67,7 @@
             for i in xrange(32):
                 for j in xrange(32):
                     ch = utf8(i * 32 + j+p*alter)
-                    c.drawString(80 + j * 13 + int(j / 16) * 4, 600 - i * 13 - int(i / 8) * 8, ch)
+                    c.drawString(80 + j * 13 + int(j / 16.0) * 4, 600 - i * 13 - int(i / 8.0) * 8, ch)
         c.showPage()
     c.save()
 
@@ -315,36 +316,46 @@
 
     def testParallelConstruction(self):
         "Test that TTFont can be used for different documents at the same time"
-        doc1 = PDFDocument()
-        doc2 = PDFDocument()
-        font = TTFont("Vera", "Vera.ttf")
-        self.assertEquals(font.splitString(u'hello ', doc1), [(0, 'hello ')])
-        self.assertEquals(font.splitString(u'hello ', doc2), [(0, 'hello ')])
-        self.assertEquals(font.splitString(u'\u0410\u0411'.encode('UTF-8'), doc1), [(0, '\x80\x81')])
-        self.assertEquals(font.splitString(u'\u0412'.encode('UTF-8'), doc2), [(0, '\x80')])
-        font.addObjects(doc1)
-        self.assertEquals(font.splitString(u'\u0413'.encode('UTF-8'), doc2), [(0, '\x81')])
-        font.addObjects(doc2)
+        ttfAsciiReadable = rl_config.ttfAsciiReadable
+        try:
+            rl_config.ttfAsciiReadable = 1
+            doc1 = PDFDocument()
+            doc2 = PDFDocument()
+            font = TTFont("Vera", "Vera.ttf")
+            self.assertEquals(font.splitString(u'hello ', doc1), [(0, 'hello ')])
+            self.assertEquals(font.splitString(u'hello ', doc2), [(0, 'hello ')])
+            self.assertEquals(font.splitString(u'\u0410\u0411'.encode('UTF-8'), doc1), [(0, '\x80\x81')])
+            self.assertEquals(font.splitString(u'\u0412'.encode('UTF-8'), doc2), [(0, '\x80')])
+            font.addObjects(doc1)
+            self.assertEquals(font.splitString(u'\u0413'.encode('UTF-8'), doc2), [(0, '\x81')])
+            font.addObjects(doc2)
+        finally:
+            rl_config.ttfAsciiReadable = ttfAsciiReadable
 
     def testAddObjects(self):
         "Test TTFont.addObjects"
         # Actually generate some subsets
-        doc = PDFDocument()
-        font = TTFont("Vera", "Vera.ttf")
-        font.splitString('a', doc)            # create some subset
-        internalName = font.getSubsetInternalName(0, doc)[1:]
-        font.addObjects(doc)
-        pdfFont = doc.idToObject[internalName]
-        self.assertEquals(doc.idToObject['BasicFonts'].dict[internalName], pdfFont)
-        self.assertEquals(pdfFont.Name, internalName)
-        self.assertEquals(pdfFont.BaseFont, "AAAAAA+BitstreamVeraSans-Roman")
-        self.assertEquals(pdfFont.FirstChar, 0)
-        self.assertEquals(pdfFont.LastChar, 127)
-        self.assertEquals(len(pdfFont.Widths.sequence), 128)
-        toUnicode = doc.idToObject[pdfFont.ToUnicode.name]
-        self.assert_(toUnicode.content != "")
-        fontDescriptor = doc.idToObject[pdfFont.FontDescriptor.name]
-        self.assertEquals(fontDescriptor.dict['Type'], '/FontDescriptor')
+        ttfAsciiReadable = rl_config.ttfAsciiReadable
+        try:
+            rl_config.ttfAsciiReadable = 1
+            doc = PDFDocument()
+            font = TTFont("Vera", "Vera.ttf")
+            font.splitString('a', doc)            # create some subset
+            internalName = font.getSubsetInternalName(0, doc)[1:]
+            font.addObjects(doc)
+            pdfFont = doc.idToObject[internalName]
+            self.assertEquals(doc.idToObject['BasicFonts'].dict[internalName], pdfFont)
+            self.assertEquals(pdfFont.Name, internalName)
+            self.assertEquals(pdfFont.BaseFont, "AAAAAA+BitstreamVeraSans-Roman")
+            self.assertEquals(pdfFont.FirstChar, 0)
+            self.assertEquals(pdfFont.LastChar, 127)
+            self.assertEquals(len(pdfFont.Widths.sequence), 128)
+            toUnicode = doc.idToObject[pdfFont.ToUnicode.name]
+            self.assert_(toUnicode.content != "")
+            fontDescriptor = doc.idToObject[pdfFont.FontDescriptor.name]
+            self.assertEquals(fontDescriptor.dict['Type'], '/FontDescriptor')
+        finally:
+            rl_config.ttfAsciiReadable = ttfAsciiReadable
 
     def testMakeToUnicodeCMap(self):
         "Test makeToUnicodeCMap"