1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#Copyright ReportLab Europe Ltd. 2000-2004
#see license.txt for license details
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/test/test_paragraphs.py
# tests some paragraph styles
import unittest
from utils import makeSuiteForClasses, outputfile, printLocation
from reportlab.platypus import Paragraph, SimpleDocTemplate, XBox, Indenter, XPreformatted
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.units import inch
from reportlab.lib.colors import red, black, navy, white, green
from reportlab.lib.randomtext import randomText
from reportlab.rl_config import defaultPageSize
from wordaxe.rl.styles import getSampleStyleSheet, ParagraphStyle
from wordaxe.rl.NewParagraph import Paragraph
(PAGE_WIDTH, PAGE_HEIGHT) = defaultPageSize
try:
import wordaxe
from wordaxe.rl.paragraph import Paragraph
from wordaxe.DCWHyphenator import DCWHyphenator
wordaxe.hyphRegistry['DE'] = DCWHyphenator('DE', 5)
except ImportError:
print "could not import wordaxe - try to continue WITHOUT hyphenation!"
def myFirstPage(canvas, doc):
canvas.saveState()
canvas.setStrokeColor(red)
canvas.setLineWidth(5)
canvas.line(66,72,66,PAGE_HEIGHT-72)
canvas.setFont('Times-Bold',24)
canvas.drawString(108, PAGE_HEIGHT-54, "TESTING NBSP")
canvas.setFont('Times-Roman',12)
canvas.drawString(4 * inch, 0.75 * inch, "First Page")
canvas.restoreState()
def myLaterPages(canvas, doc):
canvas.saveState()
canvas.setStrokeColor(red)
canvas.setLineWidth(5)
canvas.line(66,72,66,PAGE_HEIGHT-72)
canvas.setFont('Times-Roman',12)
canvas.drawString(4 * inch, 0.75 * inch, "Page %d" % doc.page)
canvas.restoreState()
class NBSPTestCase(unittest.TestCase):
"Test NBSP (eyeball-test)."
def test0(self):
"""Test...
The story should contain...
Features to be visually confirmed by a human being are:
1. ...
2. ...
3. ...
"""
story = []
#need a style
styNormal = ParagraphStyle('normal')
### The next two lines are important for hyphenation
styNormal.language = 'DE'
styNormal.hyphenation = True
text = "Dr. Müller-Lüdenscheid aus Hohenlimburg sagt: 'Hohenlimburg statt Hagen'!";
text = [ ("*"*i + " " + text) for i in range(40)]
story.append(
Paragraph(" ".join(text), styNormal))
template = SimpleDocTemplate(outputfile('test_nbsp.pdf'),
showBoundary=1)
template.build(story,
onFirstPage=myFirstPage, onLaterPages=myLaterPages)
def makeSuite():
return makeSuiteForClasses(NBSPTestCase)
#noruntests
if __name__ == "__main__":
unittest.TextTestRunner().run(makeSuite())
printLocation()
|