reportlab/test/test_platypus_breaking.py
changeset 2664 c9faa3a99e93
parent 2660 c147aff8edae
child 2671 d076db57c478
equal deleted inserted replaced
2663:927cc273c5a5 2664:c9faa3a99e93
    47         apply(BaseDocTemplate.__init__, (self, filename), kw)
    47         apply(BaseDocTemplate.__init__, (self, filename), kw)
    48         template = PageTemplate('normal', [frame1, frame2, frame3, frame4], myMainPageFrame)
    48         template = PageTemplate('normal', [frame1, frame2, frame3, frame4], myMainPageFrame)
    49         self.addPageTemplates(template)
    49         self.addPageTemplates(template)
    50 
    50 
    51 
    51 
       
    52 _text1='''Furthermore, the fundamental error of regarding functional notions as
       
    53 categorial delimits a general convention regarding the forms of the
       
    54 grammar.  I suggested that these results would follow from the
       
    55 assumption that the descriptive power of the base component may remedy
       
    56 and, at the same time, eliminate a descriptive fact.  Thus a subset of
       
    57 English sentences interesting on quite independent grounds raises
       
    58 serious doubts about the ultimate standard that determines the accuracy
       
    59 of any proposed grammar.  Of course, the natural general principle that
       
    60 will subsume this case can be defined in such a way as to impose the
       
    61 strong generative capacity of the theory.  By combining adjunctions and
       
    62 certain deformations, the descriptive power of the base component is not
       
    63 subject to the levels of acceptability from fairly high (e.g. (99a)) to
       
    64 virtual gibberish (e.g. (98d)).
       
    65 '''
    52 def _test0(self):
    66 def _test0(self):
    53     "This makes one long multi-page paragraph."
    67     "This makes one long multi-page paragraph."
    54 
    68 
    55     # Build story.
    69     # Build story.
    56     story = []
    70     story = []
       
    71     a = story.append
       
    72 
    57 
    73 
    58     styleSheet = getSampleStyleSheet()
    74     styleSheet = getSampleStyleSheet()
    59     h1 = styleSheet['Heading1']
    75     h1 = styleSheet['Heading1']
    60     h1.pageBreakBefore = 1
    76     h1.pageBreakBefore = 1
    61     h1.keepWithNext = 1
    77     h1.keepWithNext = 1
    67     h3 = styleSheet['Heading3']
    83     h3 = styleSheet['Heading3']
    68     h3.backColor = colors.cyan
    84     h3.backColor = colors.cyan
    69     h3.keepWithNext = 1
    85     h3.keepWithNext = 1
    70 
    86 
    71     bt = styleSheet['BodyText']
    87     bt = styleSheet['BodyText']
    72 
    88     a(Paragraph("""
    73     story.append(Paragraph("""
       
    74         Subsequent pages test pageBreakBefore, frameBreakBefore and
    89         Subsequent pages test pageBreakBefore, frameBreakBefore and
    75         keepTogether attributes.  Generated at %s.  The number in brackets
    90         keepTogether attributes.  Generated at %s.  The number in brackets
    76         at the end of each paragraph is its position in the story. (%d)""" % (
    91         at the end of each paragraph is its position in the story. (%d)""" % (
    77             time.ctime(time.time()), len(story)), bt))
    92             time.ctime(time.time()), len(story)), bt))
    78 
    93 
    79     for i in range(10):
    94     for i in range(10):
    80         story.append(Paragraph('Heading 1 always starts a new page (%d)' % len(story), h1))
    95         a(Paragraph('Heading 1 always starts a new page (%d)' % len(story), h1))
    81         for j in range(3):
    96         for j in range(3):
    82             story.append(Paragraph('Heading1 paragraphs should always'
    97             a(Paragraph('Heading1 paragraphs should always'
    83                             'have a page break before.  Heading 2 on the other hand'
    98                             'have a page break before.  Heading 2 on the other hand'
    84                             'should always have a FRAME break before (%d)' % len(story), bt))
    99                             'should always have a FRAME break before (%d)' % len(story), bt))
    85             story.append(Paragraph('Heading 2 always starts a new frame (%d)' % len(story), h2))
   100             a(Paragraph('Heading 2 always starts a new frame (%d)' % len(story), h2))
    86             story.append(Paragraph('Heading1 paragraphs should always'
   101             a(Paragraph('Heading1 paragraphs should always'
    87                             'have a page break before.  Heading 2 on the other hand'
   102                             'have a page break before.  Heading 2 on the other hand'
    88                             'should always have a FRAME break before (%d)' % len(story), bt))
   103                             'should always have a FRAME break before (%d)' % len(story), bt))
    89             for j in range(3):
   104             for j in range(3):
    90                 story.append(Paragraph(randomText(theme=PYTHON, sentences=2)+' (%d)' % len(story), bt))
   105                 a(Paragraph(randomText(theme=PYTHON, sentences=2)+' (%d)' % len(story), bt))
    91                 story.append(Paragraph('I should never be at the bottom of a frame (%d)' % len(story), h3))
   106                 a(Paragraph('I should never be at the bottom of a frame (%d)' % len(story), h3))
    92                 story.append(Paragraph(randomText(theme=PYTHON, sentences=1)+' (%d)' % len(story), bt))
   107                 a(Paragraph(randomText(theme=PYTHON, sentences=1)+' (%d)' % len(story), bt))
       
   108 
       
   109     a(Paragraph('Now we do <br/> tests', h1))
       
   110     a(Paragraph('First off no br tags',h3))
       
   111     a(Paragraph(_text1,bt))
       
   112     a(Paragraph("<br/> after 'the' in line 4",h3))
       
   113     a(Paragraph(_text1.replace('forms of the','forms of the<br/>',1),bt))
       
   114     a(Paragraph("2*&lt;br/&gt; after 'the' in line 4",h3))
       
   115     a(Paragraph(_text1.replace('forms of the','forms of the<br/><br/>',1),bt))
       
   116     a(Paragraph("&lt;br/&gt; after 'I suggested ' in line 5",h3))
       
   117     a(Paragraph(_text1.replace('I suggested ','I suggested<br/>',1),bt))
       
   118     a(Paragraph("2*&lt;br/&gt; after 'I suggested ' in line 5",h3))
       
   119     a(Paragraph(_text1.replace('I suggested ','I suggested<br/><br/>',1),bt))
    93 
   120 
    94     doc = MyDocTemplate(outputfile('test_platypus_breaking.pdf'))
   121     doc = MyDocTemplate(outputfile('test_platypus_breaking.pdf'))
    95     doc.multiBuild(story)
   122     doc.multiBuild(story)
    96 
   123 
    97 
   124