tests/test_platypus_breaking.py
author robin <robin@reportlab.com>
Tue, 07 Mar 2017 10:00:34 +0000
changeset 4330 617ffa6bbdc8
parent 4277 838129322a55
child 4336 d39c63b164bc
permissions -rw-r--r--
changes for release 3.4.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4330
617ffa6bbdc8 changes for release 3.4.0
robin <robin@reportlab.com>
parents: 4277
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2017
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
     2
#see license.txt for license details
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
     3
"""Tests pageBreakBefore, frameBreakBefore, keepWithNext...
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
     4
"""
4252
fe660f227cac changes for release 3.3.0
robin
parents: 4218
diff changeset
     5
__version__='3.3.0'
2984
c63f149d55aa tests.utils --> reportlab.lib.testutils
rgbecker
parents: 2967
diff changeset
     6
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
c63f149d55aa tests.utils --> reportlab.lib.testutils
rgbecker
parents: 2967
diff changeset
     7
setOutDir(__name__)
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
     8
import sys, os, time, re
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
     9
from operator import truth
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
    10
import unittest
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    11
from reportlab.platypus.flowables import Flowable
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    12
from reportlab.lib import colors
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    13
from reportlab.lib.units import cm
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    14
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    15
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    16
from reportlab.platypus.paragraph import Paragraph
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    17
from reportlab.platypus.frames import Frame
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    18
from reportlab.lib.randomtext import randomText, PYTHON
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    19
from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate, Indenter, SimpleDocTemplate
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    20
from reportlab.platypus.paragraph import *
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
    21
from reportlab.pdfgen.canvas import Canvas
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
    22
from reportlab.rl_config import invariant, paraFontSizeHeightOffset
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
    23
from reportlab.pdfbase.pdfmetrics import stringWidth
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    24
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    25
def myMainPageFrame(canvas, doc):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    26
    "The page frame used for all PDF documents."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    27
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    28
    canvas.saveState()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    29
    canvas.setFont('Times-Roman', 12)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    30
    pageNumber = canvas.getPageNumber()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    31
    canvas.drawString(10*cm, cm, str(pageNumber))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    32
    canvas.restoreState()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    33
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    34
class MyDocTemplate(BaseDocTemplate):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    35
    _invalidInitArgs = ('pageTemplates',)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    36
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    37
    def __init__(self, filename, **kw):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    38
        frame1 = Frame(2.5*cm, 15.5*cm, 6*cm, 10*cm, id='F1')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    39
        frame2 = Frame(11.5*cm, 15.5*cm, 6*cm, 10*cm, id='F2')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    40
        frame3 = Frame(2.5*cm, 2.5*cm, 6*cm, 10*cm, id='F3')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    41
        frame4 = Frame(11.5*cm, 2.5*cm, 6*cm, 10*cm, id='F4')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    42
        self.allowSplitting = 0
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    43
        self.showBoundary = 1
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3160
diff changeset
    44
        BaseDocTemplate.__init__(self, filename, **kw)
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    45
        template = PageTemplate('normal', [frame1, frame2, frame3, frame4], myMainPageFrame)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    46
        self.addPageTemplates(template)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    47
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    48
_text1='''Furthermore, the fundamental error of regarding functional notions as
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    49
categorial delimits a general convention regarding the forms of the
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    50
grammar.  I suggested that these results would follow from the
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    51
assumption that the descriptive power of the base component may remedy
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    52
and, at the same time, eliminate a descriptive fact.  Thus a subset of
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    53
English sentences interesting on quite independent grounds raises
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    54
serious doubts about the ultimate standard that determines the accuracy
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    55
of any proposed grammar.  Of course, the natural general principle that
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    56
will subsume this case can be defined in such a way as to impose the
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    57
strong generative capacity of the theory.  By combining adjunctions and
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    58
certain deformations, the descriptive power of the base component is not
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    59
subject to the levels of acceptability from fairly high (e.g. (99a)) to
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    60
virtual gibberish (e.g. (98d)).
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    61
'''
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    62
def _test0(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    63
    "This makes one long multi-page paragraph."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    64
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    65
    # Build story.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    66
    story = []
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    67
    a = story.append
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    68
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    69
    styleSheet = getSampleStyleSheet()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    70
    h1 = styleSheet['Heading1']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    71
    h1.pageBreakBefore = 1
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    72
    h1.keepWithNext = 1
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    73
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    74
    h2 = styleSheet['Heading2']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    75
    h2.frameBreakBefore = 1
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    76
    h2.keepWithNext = 1
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    77
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    78
    h3 = styleSheet['Heading3']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    79
    h3.backColor = colors.cyan
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    80
    h3.keepWithNext = 1
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    81
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    82
    bt = styleSheet['BodyText']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    83
    btj = ParagraphStyle('bodyText1j',parent=bt,alignment=TA_JUSTIFY)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    84
    btr = ParagraphStyle('bodyText1r',parent=bt,alignment=TA_RIGHT)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    85
    btc = ParagraphStyle('bodyText1c',parent=bt,alignment=TA_CENTER)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    86
    a(Paragraph("""
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    87
        <a name='top'/>Subsequent pages test pageBreakBefore, frameBreakBefore and
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    88
        keepTogether attributes.  Generated at %s.  The number in brackets
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    89
        at the end of each paragraph is its position in the story. (%d)""" % (
4218
10f8064ef68b allow invariance in tests/manuals
robin
parents: 3855
diff changeset
    90
            time.ctime(946684800.0 if invariant else time.time()), len(story)), bt))
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    91
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
    92
    for i in range(10):
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    93
        a(Paragraph('Heading 1 always starts a new page (%d)' % len(story), h1))
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
    94
        for j in range(3):
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    95
            a(Paragraph('Heading1 paragraphs should always'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    96
                            'have a page break before.  Heading 2 on the other hand'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    97
                            'should always have a FRAME break before (%d)' % len(story), bt))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    98
            a(Paragraph('Heading 2 always starts a new frame (%d)' % len(story), h2))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    99
            a(Paragraph('Heading1 paragraphs should always'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   100
                            'have a page break before.  Heading 2 on the other hand'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   101
                            'should always have a FRAME break before (%d)' % len(story), bt))
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   102
            for j in range(3):
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   103
                a(Paragraph(randomText(theme=PYTHON, sentences=2)+' (%d)' % len(story), bt))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   104
                a(Paragraph('I should never be at the bottom of a frame (%d)' % len(story), h3))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   105
                a(Paragraph(randomText(theme=PYTHON, sentences=1)+' (%d)' % len(story), bt))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   106
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   107
    for align,bts in [('left',bt),('JUSTIFIED',btj),('RIGHT',btr),('CENTER',btc)]:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   108
        a(Paragraph('Now we do &lt;br/&gt; tests(align=%s)' % align, h1))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   109
        a(Paragraph('First off no br tags',h3))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   110
        a(Paragraph(_text1,bts))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   111
        a(Paragraph("&lt;br/&gt; after 'the' in line 4",h3))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   112
        a(Paragraph(_text1.replace('forms of the','forms of the<br/>',1),bts))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   113
        a(Paragraph("2*&lt;br/&gt; after 'the' in line 4",h3))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   114
        a(Paragraph(_text1.replace('forms of the','forms of the<br/><br/>',1),bts))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   115
        a(Paragraph("&lt;br/&gt; after 'I suggested ' in line 5",h3))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   116
        a(Paragraph(_text1.replace('I suggested ','I suggested<br/>',1),bts))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   117
        a(Paragraph("2*&lt;br/&gt; after 'I suggested ' in line 5",h3))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   118
        a(Paragraph(_text1.replace('I suggested ','I suggested<br/><br/>',1),bts))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   119
        a(Paragraph("&lt;br/&gt; at the end of the paragraph!",h3))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   120
        a(Paragraph("""text one<br/>text two<br/>""",bts))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   121
        a(Paragraph("Border with &lt;br/&gt; at the end of the paragraph!",h3))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   122
        bt1 = ParagraphStyle('bodyText1',bts)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   123
        bt1.borderWidth = 0.5
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   124
        bt1.borderColor = colors.toColor('red')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   125
        bt1.backColor = colors.pink
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   126
        bt1.borderRadius = 2
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   127
        bt1.borderPadding = 3
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   128
        a(Paragraph("""text one<br/>text two<br/>""",bt1))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   129
        a(Paragraph("Border no &lt;br/&gt; at the end of the paragraph!",h3))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   130
        bt1 = ParagraphStyle('bodyText1',bts)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   131
        bt1.borderWidth = 0.5
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   132
        bt1.borderColor = colors.toColor('red')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   133
        bt1.backColor = colors.pink
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   134
        bt1.borderRadius = 2
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   135
        bt1.borderPadding = 3
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   136
        a(Paragraph("""text one<br/>text two""",bt1))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   137
        a(Paragraph("Different border style!",h3))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   138
        bt2 = ParagraphStyle('bodyText1',bt1)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   139
        bt2.borderWidth = 1.5
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   140
        bt2.borderColor = colors.toColor('blue')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   141
        bt2.backColor = colors.gray
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   142
        bt2.borderRadius = 3
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   143
        bt2.borderPadding = 3
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   144
        a(Paragraph("""text one<br/>text two<br/>""",bt2))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   145
    for i in 0, 1, 2:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   146
        P = Paragraph("""This is a paragraph with <font color='blue'><a href='#top'>with an incredibly
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   147
long and boring link in side of it that
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   148
contains lots and lots of stupidly boring and worthless information.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   149
So that we can split the link and see if we get problems like Dinu's.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   150
I hope we don't, but you never do Know.</a></font>""",bt)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   151
        a(P)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   152
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   153
    doc = MyDocTemplate(outputfile('test_platypus_breaking.pdf'))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   154
    doc.multiBuild(story)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   155
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   156
class BreakingTestCase(unittest.TestCase):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   157
    "Test multi-page splitting of paragraphs (eyeball-test)."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   158
    def test0(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   159
        _test0(self)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   160
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   161
    def test1(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   162
        '''Ilpo Nyyss\xf6nen posted this broken test'''
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   163
        normalStyle = ParagraphStyle(name = 'normal')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   164
        keepStyle = ParagraphStyle(name = 'keep', keepWithNext = True)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   165
        content = [
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   166
            Paragraph("line 1", keepStyle),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   167
            Indenter(left = 1 * cm),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   168
            Paragraph("line 2", normalStyle),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   169
            ]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   170
        doc = SimpleDocTemplate(outputfile('test_platypus_breaking1.pdf'))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   171
        doc.build(content)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   172
3124
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   173
    def test2(self):
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   174
        sty = ParagraphStyle(name = 'normal')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   175
        sty.fontName = 'Times-Roman'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   176
        sty.fontSize = 10
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   177
        sty.leading = 12
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   178
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   179
        p = Paragraph('one two three',sty)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   180
        p.wrap(20,36)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   181
        self.assertEqual(len(p.split(20,24)),2) #widows allowed
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   182
        self.assertEqual(len(p.split(20,16)),0) #orphans disallowed
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   183
        p.allowWidows = 0
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   184
        self.assertEqual(len(p.split(20,24)),0) #widows disallowed
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   185
        p.allowOrphans = 1
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   186
        self.assertEqual(len(p.split(20,16)),2) #orphans allowed
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   187
3124
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   188
    def test3(self):
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   189
        aW=307
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   190
        styleSheet = getSampleStyleSheet()
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   191
        bt = styleSheet['BodyText']
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   192
        btj = ParagraphStyle('bodyText1j',parent=bt,alignment=TA_JUSTIFY)
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   193
        p=Paragraph("""<a name='top'/>Subsequent pages test pageBreakBefore, frameBreakBefore and
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   194
                keepTogether attributes.  Generated at 1111. The number in brackets
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   195
                at the end of each paragraph is its position in the story. llllllllllllllllllllllllll 
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   196
                bbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccc ddddddddddddddddddddd eeeeyyy""",btj)
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   197
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   198
        w,h=p.wrap(aW,1000)
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   199
        canv=Canvas('test_platypus_paragraph_just.pdf',pagesize=(aW,h))
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   200
        i=len(canv._code)
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   201
        p.drawOn(canv,0,0)
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   202
        ParaCode=canv._code[i:]
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   203
        canv.saveState()
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   204
        canv.setLineWidth(0)
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   205
        canv.setStrokeColorRGB(1,0,0)
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   206
        canv.rect(0,0,aW,h)
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   207
        canv.restoreState()
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   208
        canv.showPage()
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   209
        canv.save()
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   210
        x = paraFontSizeHeightOffset and '50' or '53.17'
3369
34942d4dbcfa reportlab: new base font mechanism more fully applied
rgbecker
parents: 3326
diff changeset
   211
        good = ['q', '1 0 0 1 0 0 cm', 'q', 'BT 1 0 0 1 0 '+x+' Tm 3.59 Tw 12 TL /F1 10 Tf 0 0 0 rg (Subsequent pages test pageBreakBefore, frameBreakBefore and) Tj T* 0 Tw .23 Tw (keepTogether attributes. Generated at 1111. The number in brackets) Tj T* 0 Tw .299167 Tw (at the end of each paragraph is its position in the story. llllllllllllllllllllllllll) Tj T* 0 Tw 66.9 Tw (bbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccc) Tj T* 0 Tw (ddddddddddddddddddddd eeeeyyy) Tj T* ET', 'Q', 'Q']
3160
3c34cc4aece0 tests: add paraFontSizeHeightOffset check and autocropmarks stuff
rgbecker
parents: 3124
diff changeset
   212
        ok= ParaCode==good
3c34cc4aece0 tests: add paraFontSizeHeightOffset check and autocropmarks stuff
rgbecker
parents: 3124
diff changeset
   213
        assert ok, "\nParaCode=%r\nexpected=%r" % (ParaCode,good)
3124
0ec012e69bc6 reportlab: try to fix wordcounting bug in complex paragraphs
rgbecker
parents: 2984
diff changeset
   214
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   215
    def test4(self):
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   216
        styleSheet = getSampleStyleSheet()
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   217
        bt = styleSheet['BodyText']
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   218
        bfn = bt.fontName = 'Helvetica'
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   219
        bfs = bt.fontSize
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   220
        bfl = bt.leading
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   221
        canv=Canvas(outputfile('test_platypus_paragraph_line_lengths.pdf'))
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   222
        canv.setFont('Courier',bfs,bfl)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   223
        pageWidth, pageHeight = canv._pagesize
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   224
        y = pageHeight - 15
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   225
        x = stringWidth('999: ','Courier',bfs) + 5
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   226
        aW = int(pageWidth)-2*x
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   227
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   228
        def doPara(x,text,wc,ns,n,hrep=' ',crep=' ',hdw=0,cdw=0):
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   229
            if '{H}' in text:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   230
                text = text.replace('{H}',hrep)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   231
                wc += hdw
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   232
            if '{C}' in text:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   233
                text = text.replace('{C}',crep)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   234
                wc += cdw
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   235
            p = Paragraph(text,bt)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   236
            w,h = p.wrap(aW,1000)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   237
            annotations[:] = []
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   238
            if measuring:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   239
                ends[:] = []
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   240
            p.drawOn(canv,x,y-h)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   241
            canv.saveState()
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   242
            canv.setLineWidth(0.1)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   243
            canv.setStrokeColorRGB(1,0,0)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   244
            canv.rect(x,y-h,wc,h)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   245
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   246
            if n is not None:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   247
                canv.setFillColorRGB(0,1,0)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   248
                canv.drawRightString(x,y-h,'%3d: ' % n)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   249
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   250
            if annotations:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   251
                canv.setLineWidth(0.1)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   252
                canv.setStrokeColorRGB(0,1,0)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   253
                canv.setFillColorRGB(0,0,1)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   254
                canv.setFont('Helvetica',0.2)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   255
                for info in annotations:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   256
                    cur_x = info['cur_x']+x
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   257
                    cur_y = info['cur_y']+y-h
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   258
                    canv.drawCentredString(cur_x, cur_y+0.3,'%.2f' % (cur_x-x))
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   259
                    canv.line(cur_x,cur_y,cur_x,cur_y+0.299)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   260
            if measuring:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   261
                if not ends:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   262
                    errors.append('Paragraph measurement failure no ends found for %s\n%r' % (ns,text))
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   263
                elif len(ends)>1:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   264
                    errors.append('Paragraph measurement failure no len(ends)==%d for %s\n%r' % (len(ends),ns,text))
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   265
                else:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   266
                    cur_x = ends[0]['cur_x']
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   267
                    adiff = abs(wc-cur_x)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   268
                    length_errors.append(adiff)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   269
                    if adiff>1e-8:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   270
                        errors.append('Paragraph measurement error wc=%.4f measured=%.4f for %s\n%r' % (wc,cur_x,ns,text))
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   271
            canv.restoreState()
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   272
            return h
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   273
        swc = lambda t: stringWidth(t,'Courier',bfs)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   274
        swcbo = lambda t: stringWidth(t,'Courier-BoldOblique',bfs)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   275
        swh = lambda t: stringWidth(t,'Helvetica',bfs)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   276
        swhbo = lambda t: stringWidth(t,'Helvetica-BoldOblique',bfs)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   277
        swt = lambda t: stringWidth(t,'Times-Roman',bfs)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   278
        swtb = lambda t: stringWidth(t,'Times-Bold',bfs)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   279
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   280
        apat = re.compile("(<a\\s+name='a\\d+'/>)")
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   281
        argv = sys.argv[1:]
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   282
        data = (
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   283
            (0,"<span fontName='Courier'>Hello{C}</span> World.", swc('Hello ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   284
            (1,"<span fontName='Courier'>Hello</span>{H}World.", swc('Hello')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   285
            (2," <a name='a2'/><span fontName='Courier'>Hello{C}</span> World.", swc('Hello ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   286
            (3," <a name='a3'/><span fontName='Courier'>Hello</span>{H}World.", swc('Hello')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   287
            (4,"<span fontName='Courier'><a name='a4'/>Hello{C}</span> World.", swc('Hello ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   288
            (5,"<span fontName='Courier'><a name='a5'/>Hello</span>{H}World.", swc('Hello')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   289
            (6,"<span fontName='Courier'>Hello<a name='a6'/>{C}</span> World.", swc('Hello ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   290
            (7,"<span fontName='Courier'>Hello<a name='a7'/></span>{H}World.", swc('Hello')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   291
            (8,"<span fontName='Courier'>Hello{C}<a name='a8'/></span> World.", swc('Hello ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   292
            (9,"<span fontName='Courier'>Hello</span><a name='a9'/>{H}World.", swc('Hello')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   293
            (10,"<span fontName='Courier'>Hello{C}</span> <a name='a10'/>World.", swc('Hello ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   294
            (11,"<span fontName='Courier'>Hello</span>{H}<a name='a11'/>World.", swc('Hello')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   295
            (12,"<span fontName='Courier'>Hello{C}</span> World. <a name='a12'/>", swc('Hello ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   296
            (13,"<span fontName='Courier'>Hello</span>{H}World. <a name='a13'/>", swc('Hello')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   297
            (14," <a name='a2'/> <span fontName='Courier'>Hello{C}</span> World.", swc('Hello ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   298
            (15," <a name='a3'/> <span fontName='Courier'>Hello</span>{H}World.", swc('Hello')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   299
            (16," <a name='a2'/> <span fontName='Courier'>Hello{C}<a name='b'/> </span> <a name='b'/> World.", swc('Hello ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   300
            (17," <a name='a3'/> <span fontName='Courier'>Hello</span>{H}<a name='b'/> World.", swc('Hello')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   301
            (30,"<span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span>{C}</span> World.", swt('l')+swtb('lo')+swc('He ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   302
            (31,"<span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span></span>{H}World.", swt('l')+swtb('lo')+swc('He')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   303
            (32," <a name='a2'/><span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span>{C}</span> World.", swt('l')+swtb('lo')+swc('He ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   304
            (33," <a name='a3'/><span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span></span>{H}World.", swt('l')+swtb('lo')+swc('He')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   305
            (34,"<span fontName='Courier'><a name='a4'/>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span> </span> World.", swt('l')+swtb('lo')+swc('He ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   306
            (35,"<span fontName='Courier'><a name='a5'/>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span></span>{H}World.", swt('l')+swtb('lo')+swc('He')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   307
            (36,"<span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span><a name='a6'/> </span> World.", swt('l')+swtb('lo')+swc('He ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   308
            (37,"<span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span><a name='a7'/></span>{H}World.", swt('l')+swtb('lo')+swc('He')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   309
            (38,"<span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span>{C}<a name='a8'/></span> World.", swt('l')+swtb('lo')+swc('He ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   310
            (39,"<span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span></span><a name='a9'/>{H}World.", swt('l')+swtb('lo')+swc('He')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   311
            (40,"<span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span>{C}</span> <a name='a10'/>World.", swt('l')+swtb('lo')+swc('He ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   312
            (41,"<span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span></span>{H}<a name='a11'/>World.", swt('l')+swtb('lo')+swc('He')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   313
            (42,"<span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span>{C}</span> World. <a name='a12'/>", swt('l')+swtb('lo')+swc('He ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   314
            (43,"<span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span></span> World.{H}<a name='a13'/>", swt('l')+swtb('lo')+swc('He')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   315
            (44," <a name='a2'/> <span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span>{C}</span> World.", swt('l')+swtb('lo')+swc('He ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   316
            (45," <a name='a3'/> <span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span></span>{H}World.", swt('l')+swtb('lo')+swc('He')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   317
            (46," <a name='a2'/> <span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span>{C}<a name='b'/> </span> <a name='b'/> World.", swt('l')+swtb('lo')+swc('He ')+swh('World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   318
            (47," <a name='a3'/> <span fontName='Courier'>He<span face='Times-Roman' color='red'>l</span><span face='Times-Bold' color='orange'>lo</span></span>{H}<a name='b'/> World.", swt('l')+swtb('lo')+swc('He')+swh(' World.')),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   319
            )
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   320
        _exceptions = {
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   321
                1:  {
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   322
                    8: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   323
                    12: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   324
                    13: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   325
                    14: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   326
                    15: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   327
                    16: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   328
                    17: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   329
                    38: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   330
                    42: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   331
                    43: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   332
                    44: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   333
                    45: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   334
                    46: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   335
                    47: swh(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   336
                    },
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   337
                }
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   338
        def gex(n,v):
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   339
            return _exceptions[1].get(v,0)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   340
        x1 = x + max(_tmp[2] for _tmp in data) + 5
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   341
        x2 = x1 + max(_tmp[2]+10+gex(1,_tmp[0]) for _tmp in data) + 5
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   342
        x3 = x2 + max(_tmp[2]+10+gex(2,_tmp[0]) for _tmp in data) + 5
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   343
        x4 = x3 + max(_tmp[2]+20+gex(3,_tmp[0]) for _tmp in data) + 5
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   344
        annotations = []
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   345
        ends = []
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   346
        errors = []
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   347
        measuring = True
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   348
        length_errors = []
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   349
        def _onDrawFunc(canv,name,label):
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   350
            if measuring and label=='end':
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   351
                ends.append(canv._curr_tx_info)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   352
            annotations.append(canv._curr_tx_info)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   353
        canv._onDrawFunc = _onDrawFunc
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   354
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   355
        rep0 = '<ondraw name="_onDrawFunc"/>\\1'
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   356
        for n,text,wc in data:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   357
            if argv and str(n) not in argv: continue
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   358
            text0 = (apat.sub(rep0,text) if rep0 else text)+('<ondraw name="_onDrawFunc" label="end"/>' if measuring else '')
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   359
            ns = str(n)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   360
            h = doPara(x,text0,wc,ns,n)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   361
            if '<a' in text:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   362
                text1 = apat.sub('<img width="10" height="5" src="pythonpowered.gif"/>',text0)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   363
                doPara(x1,text1,wc+10+gex(1,n),ns+'.11',None)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   364
                text2 = apat.sub('\\1<img width="10" height="5" src="pythonpowered.gif"/>',text0)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   365
                doPara(x2,text1,wc+10+gex(2,n),ns+'.12',None)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   366
                text3 = apat.sub('\\1<img width="10" height="5" src="pythonpowered.gif"/><img width="10" height="5" src="pythonpowered.gif"/>\\1',text0)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   367
                doPara(x3,text3,wc+20+gex(3,n),ns+'.13',None)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   368
                doPara(x4,text3,wc+20+gex(3,n),ns+'.14',None,
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   369
                        hrep='<span face="Courier-BoldOblique"> </span>',
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   370
                        crep='<span face="Helvetica-BoldOblique"> </span>',
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   371
                        hdw = swcbo(' ') - swhbo(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   372
                        cdw = swhbo(' ') - swcbo(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   373
                        )
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   374
            else:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   375
                doPara(x1,text0,wc,ns+'.21',None,
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   376
                        hrep='<span face="Courier-BoldOblique"> </span>',
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   377
                        crep='<span face="Helvetica-BoldOblique"> </span>',
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   378
                        hdw = swcbo(' ') - swhbo(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   379
                        cdw = swhbo(' ') - swcbo(' '),
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   380
                        )
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   381
            y -= h+1
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   382
        canv.showPage()
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   383
        canv.save()
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   384
        if errors:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   385
            raise ValueError('\n'.join(errors))
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4252
diff changeset
   386
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   387
def makeSuite():
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   388
    return makeSuiteForClasses(BreakingTestCase)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   389
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   390
#noruntests
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   391
if __name__ == "__main__": #NORUNTESTS
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   392
    if 'debug' in sys.argv:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   393
        _test0(None)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   394
    else:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   395
        unittest.TextTestRunner().run(makeSuite())
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   396
        printLocation()