author | rgbecker |
Fri, 26 Jan 2007 12:46:22 +0000 | |
changeset 2742 | 8edd54153201 |
parent 2735 | 70cf084e5811 |
child 2744 | 9472eedb9702 |
permissions | -rw-r--r-- |
2332 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2004 |
817 | 2 |
#see license.txt for license details |
2332 | 3 |
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/test/test_platypus_paragraphs.py |
646 | 4 |
"""Tests for the reportlab.platypus.paragraphs module. |
5 |
""" |
|
6 |
||
2267 | 7 |
import sys, os |
639 | 8 |
from string import split, strip, join, whitespace |
9 |
from operator import truth |
|
10 |
from types import StringType, ListType |
|
11 |
||
12 |
from reportlab.test import unittest |
|
2708 | 13 |
from reportlab.test.utils import makeSuiteForClasses, outputfile, printLocation, outputfile |
1667
dfe2f821f4e2
Slightly refactored test suite to do the same thing with less code.
dinu_gherman
parents:
1440
diff
changeset
|
14 |
|
639 | 15 |
from reportlab.pdfbase.pdfmetrics import stringWidth |
16 |
from reportlab.platypus.paraparser import ParaParser |
|
17 |
from reportlab.platypus.flowables import Flowable |
|
18 |
from reportlab.lib.colors import Color |
|
686 | 19 |
from reportlab.lib.units import cm |
639 | 20 |
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY |
21 |
from reportlab.lib.utils import _className |
|
22 |
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle |
|
686 | 23 |
from reportlab.platypus.paragraph import Paragraph |
2735
70cf084e5811
reportlab: fix justification space counting bug and improve tests
rgbecker
parents:
2733
diff
changeset
|
24 |
from reportlab.platypus.frames import Frame, ShowBoundaryValue |
2662 | 25 |
from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate, PageBreak, NextPageTemplate |
753 | 26 |
from reportlab.platypus import tableofcontents |
1440
243d35446390
Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents:
817
diff
changeset
|
27 |
from reportlab.platypus.tableofcontents import TableOfContents |
686 | 28 |
from reportlab.platypus.tables import TableStyle, Table |
639 | 29 |
from reportlab.platypus.paragraph import * |
30 |
from reportlab.platypus.paragraph import _getFragWords |
|
31 |
||
686 | 32 |
def myMainPageFrame(canvas, doc): |
33 |
"The page frame used for all PDF documents." |
|
1683 | 34 |
|
686 | 35 |
canvas.saveState() |
36 |
||
37 |
canvas.rect(2.5*cm, 2.5*cm, 15*cm, 25*cm) |
|
38 |
canvas.setFont('Times-Roman', 12) |
|
39 |
pageNumber = canvas.getPageNumber() |
|
40 |
canvas.drawString(10*cm, cm, str(pageNumber)) |
|
41 |
||
42 |
canvas.restoreState() |
|
1683 | 43 |
|
686 | 44 |
class MyDocTemplate(BaseDocTemplate): |
45 |
_invalidInitArgs = ('pageTemplates',) |
|
1683 | 46 |
|
686 | 47 |
def __init__(self, filename, **kw): |
48 |
frame1 = Frame(2.5*cm, 2.5*cm, 15*cm, 25*cm, id='F1') |
|
2662 | 49 |
frame2 = Frame(2.5*cm, 2.5*cm, 310, 25*cm, id='F2') |
686 | 50 |
self.allowSplitting = 0 |
51 |
apply(BaseDocTemplate.__init__, (self, filename), kw) |
|
52 |
template = PageTemplate('normal', [frame1], myMainPageFrame) |
|
2662 | 53 |
template1 = PageTemplate('special', [frame2], myMainPageFrame) |
54 |
self.addPageTemplates([template,template1]) |
|
686 | 55 |
|
2410 | 56 |
class ParagraphCorners(unittest.TestCase): |
57 |
"some corner cases which should parse" |
|
58 |
def check(text,bt = getSampleStyleSheet()['BodyText']): |
|
59 |
try: |
|
60 |
P = Paragraph(text,st) |
|
61 |
except: |
|
62 |
raise AssertionError("'%s' should parse"%text) |
|
63 |
||
64 |
def test0(self): |
|
65 |
self.check('<para />') |
|
66 |
self.check('<para/>') |
|
67 |
self.check('\t\t\t\n\n\n<para />') |
|
68 |
self.check('\t\t\t\n\n\n<para/>') |
|
69 |
self.check('<para\t\t\t\t/>') |
|
70 |
self.check('<para></para>') |
|
71 |
self.check('<para> </para>') |
|
72 |
self.check('\t\t\n\t\t\t <para> </para>') |
|
73 |
||
686 | 74 |
class ParagraphSplitTestCase(unittest.TestCase): |
75 |
"Test multi-page splitting of paragraphs (eyeball-test)." |
|
1683 | 76 |
|
1667
dfe2f821f4e2
Slightly refactored test suite to do the same thing with less code.
dinu_gherman
parents:
1440
diff
changeset
|
77 |
def test0(self): |
686 | 78 |
"This makes one long multi-page paragraph." |
79 |
||
80 |
# Build story. |
|
81 |
story = [] |
|
82 |
styleSheet = getSampleStyleSheet() |
|
83 |
bt = styleSheet['BodyText'] |
|
1767 | 84 |
text = '''If you imagine that the box of X's tothe left is |
85 |
an image, what I want to be able to do is flow a |
|
86 |
series of paragraphs around the image |
|
87 |
so that once the bottom of the image is reached, then text will flow back to the |
|
88 |
left margin. I know that it would be possible to something like this |
|
89 |
using tables, but I can't see how to have a generic solution. |
|
1771 | 90 |
There are two examples of this in the demonstration section of the reportlab |
1767 | 91 |
site. |
1771 | 92 |
If you look at the "minimal" euro python conference brochure, at the end of the |
93 |
timetable section (page 8), there are adverts for "AdSu" and "O'Reilly". I can |
|
1767 | 94 |
see how the AdSu one might be done generically, but the O'Reilly, unsure... |
95 |
I guess I'm hoping that I've missed something, and that |
|
96 |
it's actually easy to do using platypus. |
|
97 |
''' |
|
98 |
from reportlab.platypus.flowables import ParagraphAndImage, Image |
|
2250 | 99 |
from reportlab.lib.utils import _RL_DIR |
100 |
gif = os.path.join(_RL_DIR,'test','pythonpowered.gif') |
|
101 |
story.append(ParagraphAndImage(Paragraph(text,bt),Image(gif))) |
|
686 | 102 |
phrase = 'This should be a paragraph spanning at least three pages. ' |
2561 | 103 |
description = ''.join([('%d: '%i)+phrase for i in xrange(250)]) |
2557
d84c18fb377f
added _offsets handling to paragraph for flow around on left side
rgbecker
parents:
2505
diff
changeset
|
104 |
story.append(ParagraphAndImage(Paragraph(description, bt),Image(gif),side='left')) |
686 | 105 |
|
2561 | 106 |
doc = MyDocTemplate(outputfile('test_platypus_paragraphandimage.pdf')) |
107 |
doc.multiBuild(story) |
|
108 |
||
109 |
def test1(self): |
|
110 |
"This makes one long multi-page paragraph." |
|
111 |
||
112 |
# Build story. |
|
113 |
story = [] |
|
114 |
styleSheet = getSampleStyleSheet() |
|
115 |
h3 = styleSheet['Heading3'] |
|
116 |
bt = styleSheet['BodyText'] |
|
117 |
text = '''If you imagine that the box of X's tothe left is |
|
118 |
an image, what I want to be able to do is flow a |
|
119 |
series of paragraphs around the image |
|
120 |
so that once the bottom of the image is reached, then text will flow back to the |
|
121 |
left margin. I know that it would be possible to something like this |
|
122 |
using tables, but I can't see how to have a generic solution. |
|
123 |
There are two examples of this in the demonstration section of the reportlab |
|
124 |
site. |
|
125 |
If you look at the "minimal" euro python conference brochure, at the end of the |
|
126 |
timetable section (page 8), there are adverts for "AdSu" and "O'Reilly". I can |
|
127 |
see how the AdSu one might be done generically, but the O'Reilly, unsure... |
|
128 |
I guess I'm hoping that I've missed something, and that |
|
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2562
diff
changeset
|
129 |
it's actually easy to do using platypus.We can do greek letters <greek>mDngG</greek>. This should be a |
2594 | 130 |
u with a dieresis on top <unichar code=0xfc/>="<unichar code=0xfc/>" and this &#xfc;="ü" and this \\xc3\\xbc="\xc3\xbc". On the other hand this |
2742 | 131 |
should be a pound sign &pound;="£" and this an alpha &alpha;="α". You can have links in the page <link href=http://www.reportlab.com color=blue>ReportLab</link> & <a href=http://www.reportlab.org color=green>ReportLab.org</a>. |
2594 | 132 |
Use scheme "pdf:" to indicate an external PDF link, "http:", "https:" to indicate an external link eg something to open in |
2644 | 133 |
your browser. If an internal link begins with something that looks like a scheme, precede with "document:". <strike>This text should have a strike through it.</strike> |
2561 | 134 |
''' |
2562 | 135 |
from reportlab.platypus.flowables import ImageAndFlowables, Image |
2561 | 136 |
from reportlab.lib.utils import _RL_DIR |
137 |
gif = os.path.join(_RL_DIR,'test','pythonpowered.gif') |
|
138 |
heading = Paragraph('This is a heading',h3) |
|
2562 | 139 |
story.append(ImageAndFlowables(Image(gif),[heading,Paragraph(text,bt)])) |
2561 | 140 |
phrase = 'This should be a paragraph spanning at least three pages. ' |
141 |
description = ''.join([('%d: '%i)+phrase for i in xrange(250)]) |
|
2562 | 142 |
story.append(ImageAndFlowables(Image(gif),[heading,Paragraph(description, bt)],imageSide='left')) |
2662 | 143 |
story.append(NextPageTemplate('special')) |
144 |
story.append(PageBreak()) |
|
145 |
story.append(ImageAndFlowables( |
|
146 |
Image(gif,width=280,height=120), |
|
147 |
Paragraph('''The concept of an integrated one box solution for advanced voice and |
|
148 |
data applications began with the introduction of the IMACS. The |
|
149 |
IMACS 200 carries on that tradition with an integrated solution |
|
150 |
optimized for smaller port size applications that the IMACS could not |
|
151 |
economically address. An array of the most popular interfaces and |
|
152 |
features from the IMACS has been bundled into a small 2U chassis |
|
153 |
providing the ultimate in ease of installation.''', |
|
154 |
style=ParagraphStyle( |
|
155 |
name="base", |
|
156 |
fontName="Helvetica", |
|
157 |
leading=12, |
|
158 |
leftIndent=0, |
|
159 |
firstLineIndent=0, |
|
160 |
spaceBefore = 9.5, |
|
161 |
fontSize=9.5, |
|
162 |
) |
|
163 |
), |
|
164 |
imageSide='left', |
|
165 |
) |
|
166 |
) |
|
167 |
story.append(ImageAndFlowables( |
|
168 |
Image(gif,width=240,height=120), |
|
169 |
Paragraph('''The concept of an integrated one box solution for advanced voice and |
|
170 |
data applications began with the introduction of the IMACS. The |
|
171 |
IMACS 200 carries on that tradition with an integrated solution |
|
172 |
optimized for smaller port size applications that the IMACS could not |
|
173 |
economically address. An array of the most popular interfaces and |
|
174 |
features from the IMACS has been bundled into a small 2U chassis |
|
175 |
providing the ultimate in ease of installation.''', |
|
176 |
style=ParagraphStyle( |
|
177 |
name="base", |
|
178 |
fontName="Helvetica", |
|
179 |
leading=12, |
|
180 |
leftIndent=0, |
|
181 |
firstLineIndent=0, |
|
182 |
spaceBefore = 9.5, |
|
183 |
fontSize=9.5, |
|
184 |
) |
|
185 |
), |
|
186 |
imageSide='left', |
|
187 |
) |
|
188 |
) |
|
2561 | 189 |
|
2662 | 190 |
|
191 |
doc = MyDocTemplate(outputfile('test_platypus_imageandflowables.pdf'),showBoundary=1) |
|
1440
243d35446390
Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents:
817
diff
changeset
|
192 |
doc.multiBuild(story) |
686 | 193 |
|
639 | 194 |
class FragmentTestCase(unittest.TestCase): |
195 |
"Test fragmentation of paragraphs." |
|
1683 | 196 |
|
1667
dfe2f821f4e2
Slightly refactored test suite to do the same thing with less code.
dinu_gherman
parents:
1440
diff
changeset
|
197 |
def test0(self): |
639 | 198 |
"Test empty paragraph." |
199 |
||
200 |
styleSheet = getSampleStyleSheet() |
|
201 |
B = styleSheet['BodyText'] |
|
202 |
text = '' |
|
203 |
P = Paragraph(text, B) |
|
204 |
frags = map(lambda f:f.text, P.frags) |
|
205 |
assert frags == [] |
|
206 |
||
1667
dfe2f821f4e2
Slightly refactored test suite to do the same thing with less code.
dinu_gherman
parents:
1440
diff
changeset
|
207 |
def test1(self): |
639 | 208 |
"Test simple paragraph." |
209 |
||
210 |
styleSheet = getSampleStyleSheet() |
|
211 |
B = styleSheet['BodyText'] |
|
212 |
text = "X<font name=Courier>Y</font>Z" |
|
213 |
P = Paragraph(text, B) |
|
214 |
frags = map(lambda f:f.text, P.frags) |
|
215 |
assert frags == ['X', 'Y', 'Z'] |
|
216 |
||
2733
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
217 |
class ULTestCase(unittest.TestCase): |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
218 |
"Test underlining and overstriking of paragraphs." |
2708 | 219 |
def testUl(self): |
220 |
from reportlab.platypus import BaseDocTemplate, PageTemplate, Frame, PageBegin |
|
221 |
from reportlab.lib.units import inch |
|
222 |
class MyDocTemplate(BaseDocTemplate): |
|
223 |
_invalidInitArgs = ('pageTemplates',) |
|
224 |
||
225 |
def __init__(self, filename, **kw): |
|
226 |
self.allowSplitting = 0 |
|
227 |
kw['showBoundary']=1 |
|
228 |
BaseDocTemplate.__init__(self, filename, **kw) |
|
229 |
self.addPageTemplates( |
|
230 |
[ |
|
231 |
PageTemplate('normal', |
|
2735
70cf084e5811
reportlab: fix justification space counting bug and improve tests
rgbecker
parents:
2733
diff
changeset
|
232 |
[Frame(inch, inch, 6.27*inch, 9.69*inch, id='first',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red"))], |
2708 | 233 |
), |
234 |
]) |
|
235 |
||
236 |
styleSheet = getSampleStyleSheet() |
|
237 |
normal = ParagraphStyle(name='normal',fontName='Times-Roman',fontSize=12,leading=1.2*12,parent=styleSheet['Normal']) |
|
2733
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
238 |
normal_sp = ParagraphStyle(name='normal_sp',parent=normal,alignment=TA_JUSTIFY,spaceBefore=12) |
2708 | 239 |
normal_just = ParagraphStyle(name='normal_just',parent=normal,alignment=TA_JUSTIFY) |
2733
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
240 |
normal_right = ParagraphStyle(name='normal_right',parent=normal,alignment=TA_RIGHT) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
241 |
normal_center = ParagraphStyle(name='normal_center',parent=normal,alignment=TA_CENTER) |
2708 | 242 |
normal_indent = ParagraphStyle(name='normal_indent',firstLineIndent=0.5*inch,parent=normal) |
2733
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
243 |
normal_indent_lv_2 = ParagraphStyle(name='normal_indent_lv_2',firstLineIndent=1.0*inch,parent=normal) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
244 |
texts = ['''Furthermore, a subset of English sentences interesting on quite |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
245 |
independent grounds is not quite equivalent to a stipulation to place |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
246 |
the constructions into these various categories.''', |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
247 |
'''We will bring evidence in favor of |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
248 |
The following thesis: most of the methodological work in modern |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
249 |
linguistics can be defined in such a way as to impose problems of |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
250 |
phonemic and morphological analysis.'''] |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
251 |
story =[] |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
252 |
a = story.append |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
253 |
for mode in (0,1): |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
254 |
text0 = texts[0] |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
255 |
text1 = texts[1] |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
256 |
if mode: |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
257 |
text0 = text0.replace('English sentences','<b>English sentences</b>').replace('quite equivalent','<i>quite equivalent</i>') |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
258 |
text1 = text1.replace('the methodological work','<b>the methodological work</b>').replace('to impose problems','<i>to impose problems</i>') |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
259 |
for t in ('u','strike'): |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
260 |
for n in xrange(6): |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
261 |
for s in (normal,normal_center,normal_right,normal_just,normal_indent, normal_indent_lv_2): |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
262 |
a(Paragraph('n=%d style=%s tag=%s'%(n,s.name,t),style=normal_sp)) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
263 |
a(Paragraph('%s<%s>%s</%s>. %s <%s>%s</%s>. %s' % ( |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
264 |
(s==normal_indent_lv_2 and '<seq id="document" inc="no"/>.<seq id="document_lv_2"/>' or ''), |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
265 |
t,' '.join((n+1)*['A']),t,text0,t,' '.join((n+1)*['A']),t,text1), |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
266 |
style=s)) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
267 |
doc = MyDocTemplate(outputfile('test_platypus_paragraphs_ul.pdf')) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
268 |
doc.build(story) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
269 |
|
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
270 |
class JustifyTestCase(unittest.TestCase): |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
271 |
"Test justification of paragraphs." |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
272 |
def testUl(self): |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
273 |
from reportlab.platypus import BaseDocTemplate, PageTemplate, Frame, PageBegin |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
274 |
from reportlab.lib.units import inch |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
275 |
class MyDocTemplate(BaseDocTemplate): |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
276 |
_invalidInitArgs = ('pageTemplates',) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
277 |
|
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
278 |
def __init__(self, filename, **kw): |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
279 |
self.allowSplitting = 0 |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
280 |
BaseDocTemplate.__init__(self, filename, **kw) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
281 |
self.addPageTemplates( |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
282 |
[ |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
283 |
PageTemplate('normal', |
2735
70cf084e5811
reportlab: fix justification space counting bug and improve tests
rgbecker
parents:
2733
diff
changeset
|
284 |
[Frame(inch, inch, 6.27*inch, 9.69*inch, id='first',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red"))], |
2733
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
285 |
), |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
286 |
]) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
287 |
|
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
288 |
styleSheet = getSampleStyleSheet() |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
289 |
normal = ParagraphStyle(name='normal',fontName='Times-Roman',fontSize=12,leading=1.2*12,parent=styleSheet['Normal']) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
290 |
normal_sp = ParagraphStyle(name='normal_sp',parent=normal,alignment=TA_JUSTIFY,spaceBefore=12) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
291 |
normal_just = ParagraphStyle(name='normal_just',parent=normal,alignment=TA_JUSTIFY,spaceAfter=12) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
292 |
normal_right = ParagraphStyle(name='normal_right',parent=normal,alignment=TA_RIGHT) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
293 |
normal_center = ParagraphStyle(name='normal_center',parent=normal,alignment=TA_CENTER) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
294 |
normal_indent = ParagraphStyle(name='normal_indent',firstLineIndent=0.5*inch,parent=normal) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
295 |
normal_indent_lv_2 = ParagraphStyle(name='normal_indent_lv_2',firstLineIndent=1.0*inch,parent=normal) |
2708 | 296 |
text0 = '''Furthermore, a subset of English sentences interesting on quite |
297 |
independent grounds is not quite equivalent to a stipulation to place |
|
2733
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
298 |
the constructions into these various categories. We will bring evidence in favor of |
2708 | 299 |
The following thesis: most of the methodological work in modern |
300 |
linguistics can be defined in such a way as to impose problems of |
|
301 |
phonemic and morphological analysis.''' |
|
302 |
story =[] |
|
303 |
a = story.append |
|
2733
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
304 |
for mode in (0,1,2,3): |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
305 |
text = text0 |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
306 |
if mode==1: |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
307 |
text = text.replace('English sentences','<b>English sentences</b>').replace('quite equivalent','<i>quite equivalent</i>') |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
308 |
text = text.replace('the methodological work','<b>the methodological work</b>').replace('to impose problems','<i>to impose problems</i>') |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
309 |
a(Paragraph('Justified paragraph in normal/bold/italic font',style=normal)) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
310 |
elif mode==2: |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
311 |
text = '<b>%s</b>' % text |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
312 |
a(Paragraph('Justified paragraph in bold font',style=normal)) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
313 |
elif mode==3: |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
314 |
text = '<i>%s</i>' % text |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
315 |
a(Paragraph('Justified paragraph in italic font',style=normal)) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
316 |
else: |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
317 |
a(Paragraph('Justified paragraph in normal font',style=normal)) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
318 |
|
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
319 |
a(Paragraph(text,style=normal_just)) |
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
320 |
doc = MyDocTemplate(outputfile('test_platypus_paragraphs_just.pdf')) |
2708 | 321 |
doc.build(story) |
639 | 322 |
|
1667
dfe2f821f4e2
Slightly refactored test suite to do the same thing with less code.
dinu_gherman
parents:
1440
diff
changeset
|
323 |
#noruntests |
639 | 324 |
def makeSuite(): |
2733
5395da969892
test_platypus_paragraphs.py: add tests for justification
rgbecker
parents:
2708
diff
changeset
|
325 |
return makeSuiteForClasses(FragmentTestCase, ParagraphSplitTestCase, ULTestCase, JustifyTestCase) |
639 | 326 |
|
763 | 327 |
#noruntests |
639 | 328 |
if __name__ == "__main__": |
329 |
unittest.TextTestRunner().run(makeSuite()) |
|
2505
0859d48c2558
reportlab/test: fix so individual tests print output folder location
rgbecker
parents:
2410
diff
changeset
|
330 |
printLocation() |