180 # Build story. |
180 # Build story. |
181 story = [] |
181 story = [] |
182 styleSheet = getSampleStyleSheet() |
182 styleSheet = getSampleStyleSheet() |
183 h3 = styleSheet['Heading3'] |
183 h3 = styleSheet['Heading3'] |
184 bt = styleSheet['BodyText'] |
184 bt = styleSheet['BodyText'] |
185 text = '''If you imagine that the box of X's tothe left is |
185 text = b'''If you imagine that the box of X's to the left is |
186 an image, what I want to be able to do is flow a |
186 an image, what I want to be able to do is flow a |
187 series of paragraphs around the image |
187 series of paragraphs around the image |
188 so that once the bottom of the image is reached, then text will flow back to the |
188 so that once the bottom of the image is reached, then text will flow back to the |
189 left margin. I know that it would be possible to something like this |
189 left margin. I know that it would be possible to something like this |
190 using tables, but I can't see how to have a generic solution. |
190 using tables, but I can't see how to have a generic solution. |
337 normal.fontName = "Helvetica" |
337 normal.fontName = "Helvetica" |
338 normal.fontSize = 12 |
338 normal.fontSize = 12 |
339 normal.leading = 16 |
339 normal.leading = 16 |
340 normal.alignment = TA_JUSTIFY |
340 normal.alignment = TA_JUSTIFY |
341 |
341 |
342 text = "Bedauerlicherweise ist ein Donaudampfschiffkapit\xc3\xa4n auch <font color='red'>nur</font> <font color='green'>ein</font> Dampfschiffkapit\xc3\xa4n." |
342 text = b"Bedauerlicherweise ist ein Donaudampfschiffkapit\xc3\xa4n auch <font color='red'>nur</font> <font color='green'>ein</font> Dampfschiffkapit\xc3\xa4n." |
343 tagFormat = '%s' |
343 tagFormat = '%s' |
344 # strange behaviour when using next code line |
344 # strange behaviour when using next code line |
345 # (same for '<a href="http://www.reportlab.org">%s</a>' |
345 # (same for '<a href="http://www.reportlab.org">%s</a>' |
346 tagFormat = '<font color="red">%s</font>' |
346 tagFormat = '<font color="red">%s</font>' |
347 |
347 |
348 #text = " ".join([tagFormat % w for w in text.split()]) |
348 #text = " ".join([tagFormat % w for w in text.split()]) |
349 |
349 |
350 story = [Paragraph((text + " ") * 3, style=normal)] |
350 story = [Paragraph((text.decode('utf8') + u" ") * 3, style=normal)] |
351 |
351 |
352 from reportlab.lib import pagesizes |
352 from reportlab.lib import pagesizes |
353 PAGESIZE = pagesizes.landscape(pagesizes.A4) |
353 PAGESIZE = pagesizes.landscape(pagesizes.A4) |
354 |
354 |
355 doc = TwoFrameDocTemplate(outputfile('test_paragraphs_splitframe.pdf'), pagesize=PAGESIZE) |
355 doc = TwoFrameDocTemplate(outputfile('test_paragraphs_splitframe.pdf'), pagesize=PAGESIZE) |
796 a(Paragraph('Paragraph Flowing', bold)) |
796 a(Paragraph('Paragraph Flowing', bold)) |
797 a(Paragraph(brText, normal)) |
797 a(Paragraph(brText, normal)) |
798 doc = MyDocTemplate(outputfile('test_platypus_paragraphs_para_br_flowing.pdf')) |
798 doc = MyDocTemplate(outputfile('test_platypus_paragraphs_para_br_flowing.pdf')) |
799 doc.build(story) |
799 doc.build(story) |
800 |
800 |
|
801 def testParaNBSP(self): |
|
802 from reportlab.platypus import BaseDocTemplate, PageTemplate, Frame, PageBegin |
|
803 from reportlab.lib.units import inch |
|
804 class MyDocTemplate(BaseDocTemplate): |
|
805 _invalidInitArgs = ('pageTemplates',) |
|
806 |
|
807 def __init__(self, filename, **kw): |
|
808 self.allowSplitting = 0 |
|
809 BaseDocTemplate.__init__(self, filename, **kw) |
|
810 self.addPageTemplates( |
|
811 [ |
|
812 PageTemplate('normal', |
|
813 [ |
|
814 Frame(inch, 4.845*inch, 3*inch, 3.645*inch, id='first',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red")), |
|
815 Frame(4.27*inch, 4.845*inch, 3*inch, 3.645*inch, id='second',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red")), |
|
816 Frame(inch, inch, 3*inch, 3.645*inch, id='third',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red")), |
|
817 Frame(4.27*inch, inch, 3*inch, 3.645*inch, id='fourth',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red")) |
|
818 ], |
|
819 ), |
|
820 ]) |
|
821 styleSheet = getSampleStyleSheet() |
|
822 normal = ParagraphStyle(name='normal',fontName='Helvetica',fontSize=10,leading=12,parent=styleSheet['Normal']) |
|
823 bold = ParagraphStyle(name='bold',fontName='Helvetica-Bold',fontSize=12,leading=14.4,parent=normal) |
|
824 story =[] |
|
825 a = story.append |
|
826 a(Paragraph('Paragraph Hard Space Handling', bold)) |
|
827 a(Paragraph(''' <span backcolor="pink">ABCDEFGHI</span> ''', normal)) |
|
828 a(Paragraph(''' <span backcolor="palegreen"> ABCDEFGHI </span> ''', normal)) |
|
829 doc = MyDocTemplate(outputfile('test_platypus_paragraphs_nbsp.pdf')) |
|
830 doc.build(story) |
|
831 |
801 #noruntests |
832 #noruntests |
802 def makeSuite(): |
833 def makeSuite(): |
803 return makeSuiteForClasses(ParagraphCorners,SplitFrameParagraphTest,FragmentTestCase, ParagraphSplitTestCase, ULTestCase, JustifyTestCase, |
834 return makeSuiteForClasses(ParagraphCorners,SplitFrameParagraphTest,FragmentTestCase, ParagraphSplitTestCase, ULTestCase, JustifyTestCase, |
804 AutoLeadingTestCase) |
835 AutoLeadingTestCase) |
805 |
836 |