Ejemplo n.º 1
0
 def testParallelConstruction(self):
     "Test that TTFont can be used for different documents at the same time"
     ttfAsciiReadable = rl_config.ttfAsciiReadable
     try:
         rl_config.ttfAsciiReadable = 1
         doc1 = PDFDocument()
         doc2 = PDFDocument()
         font = TTFont("Vera", "Vera.ttf")
         self.assertEquals(font.splitString('hello ', doc1),
                           [(0, b'hello ')])
         self.assertEquals(font.splitString('hello ', doc2),
                           [(0, b'hello ')])
         self.assertEquals(
             font.splitString(u'\u0410\u0411'.encode('UTF-8'), doc1),
             [(0, b'\x80\x81')])
         self.assertEquals(
             font.splitString(u'\u0412'.encode('UTF-8'), doc2),
             [(0, b'\x80')])
         font.addObjects(doc1)
         self.assertEquals(
             font.splitString(u'\u0413'.encode('UTF-8'), doc2),
             [(0, b'\x81')])
         font.addObjects(doc2)
     finally:
         rl_config.ttfAsciiReadable = ttfAsciiReadable
Ejemplo n.º 2
0
 def testAddObjects(self):
     "Test TTFont.addObjects"
     # Actually generate some subsets
     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
Ejemplo n.º 3
0
 def testParallelConstruction(self):
     "Test that TTFont can be used for different documents at the same time"
     doc1 = PDFDocument()
     doc2 = PDFDocument()
     font = TTFont("TestFont", "luxiserif.ttf")
     self.assertEquals(font.splitString("ab", doc1), [(0, "\0\1")])
     self.assertEquals(font.splitString("b", doc2), [(0, "\0")])
     font.addObjects(doc1)
     self.assertEquals(font.splitString("c", doc2), [(0, "\1")])
     font.addObjects(doc2)
Ejemplo n.º 4
0
 def testParallelConstruction(self):
     "Test that TTFont can be used for different documents at the same time"
     doc1 = PDFDocument()
     doc2 = PDFDocument()
     font = TTFont("TestFont", "luxiserif.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)
Ejemplo n.º 5
0
 def testSubsetInternalName(self):
     "Tests TTFont.getSubsetInternalName"
     doc = PDFDocument()
     font = TTFont("TestFont", "luxiserif.ttf")
     # Actually generate some subsets
     text = string.join(map(utf8, range(0, 513)), "")
     font.splitString(text, doc)
     self.assertRaises(IndexError, font.getSubsetInternalName, -1, doc)
     self.assertRaises(IndexError, font.getSubsetInternalName, 3, doc)
     self.assertEquals(font.getSubsetInternalName(0, doc), "/F1+0")
     self.assertEquals(font.getSubsetInternalName(1, doc), "/F1+1")
     self.assertEquals(font.getSubsetInternalName(2, doc), "/F1+2")
     self.assertEquals(doc.delayedFonts, [font])
Ejemplo n.º 6
0
 def testSubsetInternalName(self):
     "Tests TTFont.getSubsetInternalName"
     doc = PDFDocument()
     font = TTFont("Vera", "Vera.ttf")
     # Actually generate some subsets
     text = b"".join(utf8(i) for i in range(513))
     font.splitString(text, doc)
     self.assertRaises(IndexError, font.getSubsetInternalName, -1, doc)
     self.assertRaises(IndexError, font.getSubsetInternalName, 3, doc)
     self.assertEquals(font.getSubsetInternalName(0, doc), "/F1+0")
     self.assertEquals(font.getSubsetInternalName(1, doc), "/F1+1")
     self.assertEquals(font.getSubsetInternalName(2, doc), "/F1+2")
     self.assertEquals(doc.delayedFonts, [font])
Ejemplo n.º 7
0
 def no_longer_testAddObjectsResets(self):
     "Test that TTFont.addObjects resets the font"
     # Actually generate some subsets
     doc = PDFDocument()
     font = TTFont("Vera", "Vera.ttf")
     font.splitString('a', doc)  # create some subset
     doc = PDFDocument()
     font.addObjects(doc)
     self.assertEquals(font.frozen, 0)
     self.assertEquals(font.nextCode, 0)
     self.assertEquals(font.subsets, [])
     self.assertEquals(font.assignments, {})
     font.splitString('ba', doc)  # should work
Ejemplo n.º 8
0
 def testSubsetInternalName(self):
     "Tests TTFont.getSubsetInternalName"
     doc = PDFDocument()
     font = TTFont("Vera", "Vera.ttf")
     # Actually generate some subsets
     text = string.join(map(utf8, range(0, 513)), "")
     font.splitString(text, doc)
     self.assertRaises(IndexError, font.getSubsetInternalName, -1, doc)
     self.assertRaises(IndexError, font.getSubsetInternalName, 3, doc)
     self.assertEquals(font.getSubsetInternalName(0, doc), "/F1+0")
     self.assertEquals(font.getSubsetInternalName(1, doc), "/F1+1")
     self.assertEquals(font.getSubsetInternalName(2, doc), "/F1+2")
     self.assertEquals(doc.delayedFonts, [font])
Ejemplo n.º 9
0
 def no_longer_testAddObjectsResets(self):
     "Test that TTFont.addObjects resets the font"
     # Actually generate some subsets
     doc = PDFDocument()
     font = TTFont("Vera", "Vera.ttf")
     font.splitString('a', doc)            # create some subset
     doc = PDFDocument()
     font.addObjects(doc)
     self.assertEquals(font.frozen, 0)
     self.assertEquals(font.nextCode, 0)
     self.assertEquals(font.subsets, [])
     self.assertEquals(font.assignments, {})
     font.splitString('ba', doc)           # should work
Ejemplo n.º 10
0
    def testSplitString(self):
        "Tests TTFont.splitString"
        doc = PDFDocument()
        font = TTFont("TestFont", "luxiserif.ttf")
        text = string.join(map(utf8, range(0, 512)), "")
        allchars = string.join(map(chr, range(0, 256)), "")
        chunks = [(0, allchars), (1, allchars)]
        self.assertEquals(font.splitString(text, doc), chunks)
        # Do it twice
        self.assertEquals(font.splitString(text, doc), chunks)

        text = string.join(map(utf8, range(511, -1, -1)), "")
        allchars = string.join(map(chr, range(255, -1, -1)), "")
        chunks = [(1, allchars), (0, allchars)]
        self.assertEquals(font.splitString(text, doc), chunks)
Ejemplo n.º 11
0
 def testParallelConstruction(self):
     "Test that TTFont can be used for different documents at the same time"
     doc1 = PDFDocument()
     doc2 = PDFDocument()
     font = TTFont("TestFont", "luxiserif.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)
Ejemplo n.º 12
0
    def testSplitString(self):
        "Tests TTFont.splitString"
        doc = PDFDocument()
        font = TTFont("Vera", "Vera.ttf")
        text = string.join(map(utf8, xrange(0, 511)), "")
        allchars = string.join(map(chr, xrange(0, 256)), "")
        nospace = allchars[:32] + allchars[33:]
        chunks = [(0, allchars), (1, nospace)]
        self.assertEquals(font.splitString(text, doc), chunks)
        # Do it twice
        self.assertEquals(font.splitString(text, doc), chunks)

        text = string.join(map(utf8, range(510, -1, -1)), "")
        allchars = string.join(map(chr, range(255, -1, -1)), "")
        nospace = allchars[:223] + allchars[224:]
        chunks = [(1, nospace), (0, allchars)]
        self.assertEquals(font.splitString(text, doc), chunks)
Ejemplo n.º 13
0
    def testSplitString(self):
        "Tests TTFont.splitString"
        doc = PDFDocument()
        font = TTFont("Vera", "Vera.ttf")
        text = b"".join(utf8(i) for i in range(511))
        allchars = b"".join(int2Byte(i) for i in range(256))
        nospace = allchars[:32] + allchars[33:]
        chunks = [(0, allchars), (1, nospace)]
        self.assertEquals(font.splitString(text, doc), chunks)
        # Do it twice
        self.assertEquals(font.splitString(text, doc), chunks)

        text = b"".join(utf8(i) for i in range(510, -1, -1))
        allchars = b"".join(int2Byte(i) for i in range(255, -1, -1))
        nospace = allchars[:223] + allchars[224:]
        chunks = [(1, nospace), (0, allchars)]
        self.assertEquals(font.splitString(text, doc), chunks)
Ejemplo n.º 14
0
 def testParallelConstruction(self):
     "Test that TTFont can be used for different documents at the same time"
     ttfAsciiReadable = rl_config.ttfAsciiReadable
     try:
         rl_config.ttfAsciiReadable = 1
         doc1 = PDFDocument()
         doc2 = PDFDocument()
         font = TTFont("Vera", "Vera.ttf")
         self.assertEquals(font.splitString('hello ', doc1), [(0, b'hello ')])
         self.assertEquals(font.splitString('hello ', doc2), [(0, b'hello ')])
         self.assertEquals(font.splitString(u'\u0410\u0411'.encode('UTF-8'), doc1), [(0, b'\x80\x81')])
         self.assertEquals(font.splitString(u'\u0412'.encode('UTF-8'), doc2), [(0, b'\x80')])
         font.addObjects(doc1)
         self.assertEquals(font.splitString(u'\u0413'.encode('UTF-8'), doc2), [(0, b'\x81')])
         font.addObjects(doc2)
     finally:
         rl_config.ttfAsciiReadable = ttfAsciiReadable
Ejemplo n.º 15
0
    def testSplitString(self):
        "Tests TTFont.splitString"
        doc = PDFDocument()
        font = TTFont("Vera", "Vera.ttf")
        text = b"".join(utf8(i) for i in range(511))
        allchars = b"".join(int2Byte(i) for i in range(256))
        nospace = allchars[:32] + allchars[33:]
        chunks = [(0, allchars), (1, nospace)]
        self.assertEquals(font.splitString(text, doc), chunks)
        # Do it twice
        self.assertEquals(font.splitString(text, doc), chunks)

        text = b"".join(utf8(i) for i in range(510, -1, -1))
        allchars = b"".join(int2Byte(i) for i in range(255, -1, -1))
        nospace = allchars[:223] + allchars[224:]
        chunks = [(1, nospace), (0, allchars)]
        self.assertEquals(font.splitString(text, doc), chunks)
Ejemplo n.º 16
0
    def testSplitString(self):
        "Tests TTFont.splitString"
        doc = PDFDocument()
        font = TTFont("Vera", "Vera.ttf")
        text = string.join(map(utf8, xrange(0, 511)), "")
        allchars = string.join(map(chr, xrange(0, 256)), "")
        nospace = allchars[:32] + allchars[33:]
        chunks = [(0, allchars), (1, nospace)]
        self.assertEquals(font.splitString(text, doc), chunks)
        # Do it twice
        self.assertEquals(font.splitString(text, doc), chunks)

        text = string.join(map(utf8, range(510, -1, -1)), "")
        allchars = string.join(map(chr, range(255, -1, -1)), "")
        nospace = allchars[:223] + allchars[224:]
        chunks = [(1, nospace), (0, allchars)]
        self.assertEquals(font.splitString(text, doc), chunks)
Ejemplo n.º 17
0
    def testSplitString(self):
        "Tests TTFont.splitString"
        doc = PDFDocument()
        font = TTFont("Vera", "Vera.ttf")
        text = b"".join(utf8(i) for i in range(511))
        allchars = b"".join(int2Byte(i) for i in range(256))
        chunks = [(0, allchars[:0xa0] + b' ' + allchars[0xa0:])] + [
            (1,
             allchars[1:32] + allchars[33:]) if rl_config.reserveTTFNotdef else
            (1, allchars[:32] + allchars[33:-1])
        ]
        self.assertEqual(font.splitString(text, doc), chunks)
        # Do it twice
        self.assertEqual(font.splitString(text, doc), chunks)

        text = b"".join(utf8(i) for i in range(510, -1, -1))
        revver = lambda b: map(int2Byte, reversed(b))
        chunks = [(i[0], b"".join(revver(i[1]))) for i in reversed(chunks)]
        self.assertEqual(font.splitString(text, doc), chunks)
Ejemplo n.º 18
0
 def testAddObjects(self):
     "Test TTFont.addObjects"
     # Actually generate some subsets
     doc = PDFDocument()
     font = TTFont("TestFont", "luxiserif.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+LuxiSerif")
     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')
Ejemplo n.º 19
0
 def testAddObjects(self):
     "Test TTFont.addObjects"
     # Actually generate some subsets
     doc = PDFDocument()
     font = TTFont("TestFont", "luxiserif.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+LuxiSerif")
     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')
Ejemplo n.º 20
0
    def testSplitStringSpaces(self):
        # In order for justification (word spacing) to work, the space
        # glyph must have a code 32, and no other character should have
        # that code in any subset, or word spacing will be applied to it.

        doc = PDFDocument()
        font = TTFont("Vera", "Vera.ttf")
        text = string.join(map(utf8, range(512, -1, -1)), "")
        chunks = font.splitString(text, doc)
        state = font.state[doc]
        self.assertEquals(state.assignments[32], 32)
        self.assertEquals(state.subsets[0][32], 32)
        self.assertEquals(state.subsets[1][32], 32)
Ejemplo n.º 21
0
    def testSplitStringSpaces(self):
        # In order for justification (word spacing) to work, the space
        # glyph must have a code 32, and no other character should have
        # that code in any subset, or word spacing will be applied to it.

        doc = PDFDocument()
        font = TTFont("Vera", "Vera.ttf")
        text = b"".join(utf8(i) for i in range(512, -1, -1))
        chunks = font.splitString(text, doc)
        state = font.state[doc]
        self.assertEquals(state.assignments[32], 32)
        self.assertEquals(state.subsets[0][32], 32)
        self.assertEquals(state.subsets[1][32], 32)
Ejemplo n.º 22
0
 def testAddObjects(self):
     "Test TTFont.addObjects"
     # Actually generate some subsets
     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