本文整理匯總了Python中reportlab.pdfbase.ttfonts.TTFont.splitString方法的典型用法代碼示例。如果您正苦於以下問題:Python TTFont.splitString方法的具體用法?Python TTFont.splitString怎麽用?Python TTFont.splitString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類reportlab.pdfbase.ttfonts.TTFont
的用法示例。
在下文中一共展示了TTFont.splitString方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testParallelConstruction
# 需要導入模塊: from reportlab.pdfbase.ttfonts import TTFont [as 別名]
# 或者: from reportlab.pdfbase.ttfonts.TTFont import splitString [as 別名]
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)
示例2: testParallelConstruction
# 需要導入模塊: from reportlab.pdfbase.ttfonts import TTFont [as 別名]
# 或者: from reportlab.pdfbase.ttfonts.TTFont import splitString [as 別名]
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)
示例3: no_longer_testAddObjectsResets
# 需要導入模塊: from reportlab.pdfbase.ttfonts import TTFont [as 別名]
# 或者: from reportlab.pdfbase.ttfonts.TTFont import splitString [as 別名]
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
示例4: testSubsetInternalName
# 需要導入模塊: from reportlab.pdfbase.ttfonts import TTFont [as 別名]
# 或者: from reportlab.pdfbase.ttfonts.TTFont import splitString [as 別名]
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])
示例5: testSubsetInternalName
# 需要導入模塊: from reportlab.pdfbase.ttfonts import TTFont [as 別名]
# 或者: from reportlab.pdfbase.ttfonts.TTFont import splitString [as 別名]
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])
示例6: testSplitString
# 需要導入模塊: from reportlab.pdfbase.ttfonts import TTFont [as 別名]
# 或者: from reportlab.pdfbase.ttfonts.TTFont import splitString [as 別名]
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)
示例7: testParallelConstruction
# 需要導入模塊: from reportlab.pdfbase.ttfonts import TTFont [as 別名]
# 或者: from reportlab.pdfbase.ttfonts.TTFont import splitString [as 別名]
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
示例8: testSplitString
# 需要導入模塊: from reportlab.pdfbase.ttfonts import TTFont [as 別名]
# 或者: from reportlab.pdfbase.ttfonts.TTFont import splitString [as 別名]
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)
示例9: testSplitString
# 需要導入模塊: from reportlab.pdfbase.ttfonts import TTFont [as 別名]
# 或者: from reportlab.pdfbase.ttfonts.TTFont import splitString [as 別名]
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)
示例10: testAddObjects
# 需要導入模塊: from reportlab.pdfbase.ttfonts import TTFont [as 別名]
# 或者: from reportlab.pdfbase.ttfonts.TTFont import splitString [as 別名]
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')
示例11: testSplitStringSpaces
# 需要導入模塊: from reportlab.pdfbase.ttfonts import TTFont [as 別名]
# 或者: from reportlab.pdfbase.ttfonts.TTFont import splitString [as 別名]
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)
示例12: testAddObjects
# 需要導入模塊: from reportlab.pdfbase.ttfonts import TTFont [as 別名]
# 或者: from reportlab.pdfbase.ttfonts.TTFont import splitString [as 別名]
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