tests/test_platypus_paragraphs.py
author robin
Thu, 10 Oct 2013 15:06:34 +0100
branchpy33
changeset 3931 ceee76b69e7c
parent 3807 55af72526d90
child 4036 f7d6d36cc44c
permissions -rw-r--r--
fix href bug reported by bitbucket.kmouts
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3617
ae5744e97c42 reportlab: copyright date changes
robin
parents: 3564
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2012
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 for the reportlab.platypus.paragraphs module.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
     4
"""
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
     5
__version__=''' $Id$ '''
2987
711910106e3a tests: more changes to testsFolder and friends
rgbecker
parents: 2984
diff changeset
     6
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
2984
c63f149d55aa tests.utils --> reportlab.lib.testutils
rgbecker
parents: 2966
diff changeset
     7
setOutDir(__name__)
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
     8
import sys, os, unittest
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
     9
from operator import truth
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    10
from reportlab.pdfbase.pdfmetrics import stringWidth, registerFont, registerFontFamily
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    11
from reportlab.pdfbase.ttfonts import TTFont
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    12
from reportlab.platypus.paraparser import ParaParser
3564
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
    13
from reportlab.platypus.flowables import Flowable, DocAssert
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    14
from reportlab.lib.colors import Color
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    15
from reportlab.lib.units import cm
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    16
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
    17
from reportlab.lib.utils import _className
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    18
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    19
from reportlab.platypus.paragraph import Paragraph
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    20
from reportlab.platypus.xpreformatted import XPreformatted
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    21
from reportlab.platypus.frames import Frame, ShowBoundaryValue
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    22
from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate, PageBreak, NextPageTemplate
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    23
from reportlab.platypus import tableofcontents
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    24
from reportlab.platypus.tableofcontents import TableOfContents
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    25
from reportlab.platypus.tables import TableStyle, Table
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    26
from reportlab.platypus.paragraph import *
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    27
from reportlab.platypus.paragraph import _getFragWords
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    28
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    29
def myMainPageFrame(canvas, doc):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    30
    "The page frame used for all PDF documents."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    31
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    32
    canvas.saveState()
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
    canvas.rect(2.5*cm, 2.5*cm, 15*cm, 25*cm)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    35
    canvas.setFont('Times-Roman', 12)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    36
    pageNumber = canvas.getPageNumber()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    37
    canvas.drawString(10*cm, cm, str(pageNumber))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    38
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    39
    canvas.restoreState()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    40
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    41
class MyDocTemplate(BaseDocTemplate):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    42
    _invalidInitArgs = ('pageTemplates',)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    43
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    44
    def __init__(self, filename, **kw):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    45
        frame1 = Frame(2.5*cm, 2.5*cm, 15*cm, 25*cm, id='F1')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    46
        frame2 = Frame(2.5*cm, 2.5*cm, 310, 25*cm, id='F2')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    47
        self.allowSplitting = 0
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3320
diff changeset
    48
        BaseDocTemplate.__init__(self, filename, **kw)
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    49
        template = PageTemplate('normal', [frame1], myMainPageFrame)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    50
        template1 = PageTemplate('special', [frame2], myMainPageFrame)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    51
        self.addPageTemplates([template,template1])
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    52
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    53
class ParagraphCorners(unittest.TestCase):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    54
    "some corner cases which should parse"
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    55
    def check(self,text,bt = getSampleStyleSheet()['BodyText']):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    56
        try:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    57
            P = Paragraph(text,style=bt)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    58
        except:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    59
            raise AssertionError("'%s' should parse"%text)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    60
            
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    61
    def test0(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    62
        self.check('<para />')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    63
        self.check('<para/>')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    64
        self.check('\t\t\t\n\n\n<para />')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    65
        self.check('\t\t\t\n\n\n<para/>')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    66
        self.check('<para\t\t\t\t/>')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    67
        self.check('<para></para>')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    68
        self.check('<para>      </para>')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    69
        self.check('\t\t\n\t\t\t   <para>      </para>')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    70
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    71
    def test1(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    72
        "This makes several special paragraphs."
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
        # Build story.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    75
        story = []
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    76
        styleSheet = getSampleStyleSheet()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    77
        bt = styleSheet['BodyText']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    78
        btN = ParagraphStyle('BodyTextTTNone',parent=bt,textTransform='none')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    79
        btL = ParagraphStyle('BodyTextTTLower',parent=bt,textTransform='lowercase')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    80
        btU = ParagraphStyle('BodyTextTTUpper',parent=bt,textTransform='uppercase')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    81
        btC = ParagraphStyle('BodyTextTTCapitalize',parent=bt,textTransform='capitalize')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    82
        story.append(Paragraph('''This should be ORDINARY text.''',style=bt))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    83
        story.append(Paragraph('''This should be ORDINARY text.''',style=btN))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    84
        story.append(Paragraph('''This should be LOWER text.''',style=btL))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    85
        story.append(Paragraph('''This should be upper text.''',style=btU))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    86
        story.append(Paragraph('''This should be cAPITALIZED text.''',style=btC))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    87
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    88
        story.append(Paragraph('''T<i>hi</i>s shoul<font color="red">d b</font>e <b>ORDINARY</b> text.''',style=bt))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    89
        story.append(Paragraph('''T<i>hi</i>s shoul<font color="red">d b</font>e <b>ORDINARY</b> text.''',style=btN))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    90
        story.append(Paragraph('''T<i>hi</i>s shoul<font color="red">d b</font>e <b>LOWER</b> text.''',style=btL))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    91
        story.append(Paragraph('''T<i>hi</i>s shoul<font color="red">d b</font>e <b>upper</b> text.''',style=btU))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    92
        story.append(Paragraph('''T<i>hi</i>s shoul<font color="red">d b</font>e <b>cAPITALIZED</b> text.''',style=btC))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    93
        doc = MyDocTemplate(outputfile('test_platypus_specialparagraphs.pdf'))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    94
        doc.multiBuild(story)
3191
07560dd4d3d0 test_platypus_paragraphs.py: add in Volker's crashing CJK split as a test
rgbecker
parents: 2987
diff changeset
    95
07560dd4d3d0 test_platypus_paragraphs.py: add in Volker's crashing CJK split as a test
rgbecker
parents: 2987
diff changeset
    96
    def test2(self):
07560dd4d3d0 test_platypus_paragraphs.py: add in Volker's crashing CJK split as a test
rgbecker
parents: 2987
diff changeset
    97
        '''CJK splitting in multi-frag case'''
07560dd4d3d0 test_platypus_paragraphs.py: add in Volker's crashing CJK split as a test
rgbecker
parents: 2987
diff changeset
    98
        style = ParagraphStyle('test', wordWrap = 'CJK')
07560dd4d3d0 test_platypus_paragraphs.py: add in Volker's crashing CJK split as a test
rgbecker
parents: 2987
diff changeset
    99
        p = Paragraph('bla <i>blub</i> '*130 , style)
07560dd4d3d0 test_platypus_paragraphs.py: add in Volker's crashing CJK split as a test
rgbecker
parents: 2987
diff changeset
   100
        aW,aH=439.275590551,121.88976378
07560dd4d3d0 test_platypus_paragraphs.py: add in Volker's crashing CJK split as a test
rgbecker
parents: 2987
diff changeset
   101
        w,h=p.wrap(aW,aH)
07560dd4d3d0 test_platypus_paragraphs.py: add in Volker's crashing CJK split as a test
rgbecker
parents: 2987
diff changeset
   102
        S=p.split(aW,aH)
3197
f4cef2b94b59 test_platypus_paragraphs.py: fix CJK splitting test
rgbecker
parents: 3191
diff changeset
   103
        assert len(S)==2, 'Multi frag CJK splitting failed'
3191
07560dd4d3d0 test_platypus_paragraphs.py: add in Volker's crashing CJK split as a test
rgbecker
parents: 2987
diff changeset
   104
        w0,h0=S[0].wrap(aW,aH)
07560dd4d3d0 test_platypus_paragraphs.py: add in Volker's crashing CJK split as a test
rgbecker
parents: 2987
diff changeset
   105
        assert h0<=aH,'Multi-frag CJK split[0] has wrong height %s >= available %s' % (H0,aH)
07560dd4d3d0 test_platypus_paragraphs.py: add in Volker's crashing CJK split as a test
rgbecker
parents: 2987
diff changeset
   106
        w1,h1=S[1].wrap(aW,aH)
07560dd4d3d0 test_platypus_paragraphs.py: add in Volker's crashing CJK split as a test
rgbecker
parents: 2987
diff changeset
   107
        assert h0+h1==h, 'Multi-frag-CJK split[0].height(%s)+split[1].height(%s) don\'t add to original %s' % (h0,h1,h)
3492
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   108
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   109
    def test3(self):
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   110
        '''compare CJK splitting in some edge cases'''
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   111
        from reportlab.pdfgen.canvas import Canvas
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   112
        from reportlab.platypus.paragraph import Paragraph
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   113
        from reportlab.lib.styles import ParagraphStyle
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   114
        from reportlab.pdfbase import pdfmetrics
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   115
        from reportlab.lib.enums import TA_LEFT
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   116
        sty = ParagraphStyle('A')
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   117
        sty.fontSize = 15
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   118
        sty.leading = sty.fontSize*1.2
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   119
        sty.fontName = 'Courier'
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   120
        sty.alignment = TA_LEFT
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   121
        sty.wordWrap = 'CJK'
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   122
        p0=Paragraph('ABCDEFGHIJKL]N',sty)
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   123
        p1=Paragraph('AB<font color="red">C</font>DEFGHIJKL]N',sty)
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   124
        canv = Canvas('test_platypus_paragraph_cjk3.pdf')
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   125
        ix = len(canv._code)
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   126
        aW = pdfmetrics.stringWidth('ABCD','Courier',15)
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   127
        w,h=p0.wrap(aW,1000000)
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   128
        y = canv._pagesize[1]-72-h
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   129
        p0.drawOn(canv,72,y)
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   130
        w,h=p1.wrap(aW,1000000)
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   131
        y -= h+10
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   132
        p1.drawOn(canv,72,y)
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   133
        w,h=p0.wrap(aW*0.25-2,1000000)
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   134
        y -= h+10
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   135
        p0.drawOn(canv,72,y)
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   136
        w,h=p1.wrap(aW/4.-2,1000000)
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   137
        y -= h+10
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   138
        p1.drawOn(canv,72,y)
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   139
        assert canv._code[ix:]==['q', '1 0 0 1 72 697.8898 cm', 'q', '0 0 0 rg', 'BT 1 0 0 1 0 57 Tm /F2 15 Tf 18 TL (ABCD) Tj T* (EFGH) Tj T* (IJKL]) Tj T* (N) Tj T* ET', 'Q', 'Q', 'q', '1 0 0 1 72 615.8898 cm', 'q', 'BT 1 0 0 1 0 57 Tm 18 TL /F2 15 Tf 0 0 0 rg (AB) Tj 1 0 0 rg (C) Tj 0 0 0 rg (D) Tj T* (EFGH) Tj T* (IJKL]) Tj T* (N) Tj T* ET', 'Q', 'Q', 'q', '1 0 0 1 72 353.8898 cm', 'q', '0 0 0 rg', 'BT 1 0 0 1 0 237 Tm /F2 15 Tf 18 TL (A) Tj T* (B) Tj T* (C) Tj T* (D) Tj T* (E) Tj T* (F) Tj T* (G) Tj T* (H) Tj T* (I) Tj T* (J) Tj T* (K) Tj T* (L) Tj T* (]) Tj T* (N) Tj T* ET', 'Q', 'Q', 'q', '1 0 0 1 72 91.88976 cm', 'q', 'BT 1 0 0 1 0 237 Tm 18 TL /F2 15 Tf 0 0 0 rg (A) Tj T* (B) Tj T* 1 0 0 rg (C) Tj T* 0 0 0 rg (D) Tj T* (E) Tj T* (F) Tj T* (G) Tj T* (H) Tj T* (I) Tj T* (J) Tj T* (K) Tj T* (L) Tj T* (]) Tj T* (N) Tj T* ET', 'Q', 'Q']
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   140
        canv.showPage()
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3439
diff changeset
   141
        canv.save()
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   142
        
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   143
class ParagraphSplitTestCase(unittest.TestCase):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   144
    "Test multi-page splitting of paragraphs (eyeball-test)."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   145
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   146
    def test0(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   147
        "This makes one long multi-page paragraph."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   148
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   149
        # Build story.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   150
        story = []
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   151
        styleSheet = getSampleStyleSheet()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   152
        bt = styleSheet['BodyText']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   153
        text = '''If you imagine that the box of X's tothe left is
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   154
an image, what I want to be able to do is flow a
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   155
series of paragraphs around the image
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   156
so that once the bottom of the image is reached, then text will flow back to the
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   157
left margin. I know that it would be possible to something like this
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   158
using tables, but I can't see how to have a generic solution.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   159
There are two examples of this in the demonstration section of the reportlab
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   160
site.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   161
If you look at the "minimal" euro python conference brochure, at the end of the
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   162
timetable section (page 8), there are adverts for "AdSu" and "O'Reilly". I can
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   163
see how the AdSu one might be done generically, but the O'Reilly, unsure...
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   164
I guess I'm hoping that I've missed something, and that
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   165
it's actually easy to do using platypus.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   166
'''
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   167
        from reportlab.platypus.flowables import ParagraphAndImage, Image
2987
711910106e3a tests: more changes to testsFolder and friends
rgbecker
parents: 2984
diff changeset
   168
        from reportlab.lib.testutils import testsFolder
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
   169
        gif = os.path.join(testsFolder,'pythonpowered.gif')
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   170
        story.append(ParagraphAndImage(Paragraph(text,bt),Image(gif)))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   171
        phrase = 'This should be a paragraph spanning at least three pages. '
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   172
        description = ''.join([('%d: '%i)+phrase for i in range(250)])
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   173
        story.append(ParagraphAndImage(Paragraph(description, bt),Image(gif),side='left'))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   174
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   175
        doc = MyDocTemplate(outputfile('test_platypus_paragraphandimage.pdf'))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   176
        doc.multiBuild(story)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   177
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   178
    def test1(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   179
        "This makes one long multi-page paragraph."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   180
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   181
        # Build story.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   182
        story = []
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   183
        styleSheet = getSampleStyleSheet()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   184
        h3 = styleSheet['Heading3']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   185
        bt = styleSheet['BodyText']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   186
        text = '''If you imagine that the box of X's tothe left is
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   187
an image, what I want to be able to do is flow a
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   188
series of paragraphs around the image
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   189
so that once the bottom of the image is reached, then text will flow back to the
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   190
left margin. I know that it would be possible to something like this
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   191
using tables, but I can't see how to have a generic solution.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   192
There are two examples of this in the demonstration section of the reportlab
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   193
site.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   194
If you look at the "minimal" euro python conference brochure, at the end of the
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   195
timetable section (page 8), there are adverts for "AdSu" and "O'Reilly". I can
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   196
see how the AdSu one might be done generically, but the O'Reilly, unsure...
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   197
I guess I'm hoping that I've missed something, and that
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   198
it's actually easy to do using platypus.We can do greek letters <greek>mDngG</greek>. This should be a
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   199
u with a dieresis on top &lt;unichar code=0xfc/&gt;="<unichar code="0xfc"/>" and this &amp;#xfc;="&#xfc;" and this \\xc3\\xbc="\xc3\xbc". On the other hand this
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   200
should be a pound sign &amp;pound;="&pound;" and this an alpha &amp;alpha;="&alpha;". You can have links in the page <link href="http://www.reportlab.com" color="blue">ReportLab</link> &amp; <a href="http://www.reportlab.org" color="green">ReportLab.org</a>.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   201
Use scheme "pdf:" to indicate an external PDF link, "http:", "https:" to indicate an external link eg something to open in
3931
ceee76b69e7c fix href bug reported by bitbucket.kmouts
robin
parents: 3807
diff changeset
   202
your browser. If an internal link begins with something that looks like a scheme, precede with "document:". Empty hrefs should be allowed ie <a href="">&lt;a href=""&gt;test&lt;/a&gt;</a> should be allowed. <strike>This text should have a strike through it.</strike>
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   203
'''
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   204
        from reportlab.platypus.flowables import ImageAndFlowables, Image
2987
711910106e3a tests: more changes to testsFolder and friends
rgbecker
parents: 2984
diff changeset
   205
        from reportlab.lib.testutils import testsFolder
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
   206
        gif = os.path.join(testsFolder,'pythonpowered.gif')
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   207
        heading = Paragraph('This is a heading',h3)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   208
        story.append(ImageAndFlowables(Image(gif),[heading,Paragraph(text,bt)]))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   209
        phrase = 'This should be a paragraph spanning at least three pages. '
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   210
        description = ''.join([('%d: '%i)+phrase for i in range(250)])
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   211
        story.append(ImageAndFlowables(Image(gif),[heading,Paragraph(description, bt)],imageSide='left'))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   212
        story.append(NextPageTemplate('special'))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   213
        story.append(PageBreak())
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   214
        VERA = ('Vera','VeraBd','VeraIt','VeraBI')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   215
        for v in VERA:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   216
            registerFont(TTFont(v,v+'.ttf'))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   217
        registerFontFamily(*(VERA[:1]+VERA))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   218
        story.append(ImageAndFlowables(
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   219
                        Image(gif,width=280,height=120),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   220
                        Paragraph('''<font name="Vera">The <b>concept</b> of an <i>integrated</i> one <b><i>box</i></b> solution for <i><b>advanced</b></i> voice and
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   221
data applications began with the introduction of the IMACS. The
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   222
IMACS 200 carries on that tradition with an integrated solution
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   223
optimized for smaller port size applications that the IMACS could not
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   224
economically address. An array of the most popular interfaces and
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   225
features from the IMACS has been bundled into a small 2U chassis
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   226
providing the ultimate in ease of installation.</font>''',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   227
                        style=ParagraphStyle(
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   228
                                name="base",
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   229
                                fontName="Helvetica",
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   230
                                leading=12,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   231
                                leftIndent=0,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   232
                                firstLineIndent=0,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   233
                                spaceBefore = 9.5,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   234
                                fontSize=9.5,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   235
                                )
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   236
                            ),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   237
                    imageSide='left',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   238
                    )
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   239
                )
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   240
        story.append(ImageAndFlowables(
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   241
                        Image(gif,width=240,height=120),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   242
                        Paragraph('''The concept of an integrated one box solution for advanced voice and
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   243
data applications began with the introduction of the IMACS. The
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   244
IMACS 200 carries on that tradition with an integrated solution
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   245
optimized for smaller port size applications that the IMACS could not
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   246
economically address. An array of the most popular interfaces and
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   247
features from the IMACS has been bundled into a small 2U chassis
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   248
providing the ultimate in ease of installation.''',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   249
                        style=ParagraphStyle(
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   250
                                name="base",
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   251
                                fontName="Helvetica",
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   252
                                leading=12,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   253
                                leftIndent=0,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   254
                                firstLineIndent=0,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   255
                                spaceBefore = 9.5,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   256
                                fontSize=9.5,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   257
                                )
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   258
                            ),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   259
                    imageSide='left',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   260
                    )
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   261
                )
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   262
3320
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   263
        story.append(PageBreak())
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   264
        story.append(Paragraph('Image larger than the frame',h3))
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   265
        story.append(ImageAndFlowables(
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   266
                        Image(gif,width=6*110,height=6*44),
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   267
                        Paragraph('''The concept of an integrated one box solution for advanced voice and
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   268
data applications began with the introduction of the IMACS. The
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   269
IMACS 200 carries on that tradition with an integrated solution
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   270
optimized for smaller port size applications that the IMACS could not
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   271
economically address. An array of the most popular interfaces and
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   272
features from the IMACS has been bundled into a small 2U chassis
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   273
providing the ultimate in ease of installation.''',
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   274
                        style=ParagraphStyle(
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   275
                                name="base",
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   276
                                fontName="Helvetica",
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   277
                                leading=12,
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   278
                                leftIndent=0,
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   279
                                firstLineIndent=0,
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   280
                                spaceBefore = 9.5,
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   281
                                fontSize=9.5,
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   282
                                )
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   283
                            ),
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   284
                    imageSide='left',
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   285
                    )
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   286
                )
d49ef1795c27 test_platypus_paragraphs.py: add overlarge test to ImageAndFlowables tests
rgbecker
parents: 3197
diff changeset
   287
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   288
        
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   289
        doc = MyDocTemplate(outputfile('test_platypus_imageandflowables.pdf'),showBoundary=1)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   290
        doc.multiBuild(story)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   291
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   292
class TwoFrameDocTemplate(BaseDocTemplate):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   293
    "Define a simple document with two frames per page."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   294
    
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   295
    def __init__(self, filename, **kw):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   296
        m = 2*cm
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   297
        from reportlab.lib import pagesizes
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   298
        PAGESIZE = pagesizes.landscape(pagesizes.A4)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   299
        cw, ch = (PAGESIZE[0]-2*m)/2., (PAGESIZE[1]-2*m)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   300
        ch -= 14*cm
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   301
        f1 = Frame(m, m+0.5*cm, cw-0.75*cm, ch-1*cm, id='F1', 
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   302
            leftPadding=0, topPadding=0, rightPadding=0, bottomPadding=0,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   303
            showBoundary=True
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   304
        )
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   305
        f2 = Frame(cw+2.7*cm, m+0.5*cm, cw-0.75*cm, ch-1*cm, id='F2', 
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   306
            leftPadding=0, topPadding=0, rightPadding=0, bottomPadding=0,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   307
            showBoundary=True
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   308
        )
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3320
diff changeset
   309
        BaseDocTemplate.__init__(self, filename, **kw)
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   310
        template = PageTemplate('template', [f1, f2])
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   311
        self.addPageTemplates(template)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   312
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   313
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   314
class SplitFrameParagraphTest(unittest.TestCase):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   315
    "Test paragraph split over two frames."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   316
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   317
    def test(self):    
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   318
        stylesheet = getSampleStyleSheet()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   319
        normal = stylesheet['BodyText']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   320
        normal.fontName = "Helvetica"
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   321
        normal.fontSize = 12
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   322
        normal.leading = 16
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   323
        normal.alignment = TA_JUSTIFY
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   324
    
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   325
        text = "Bedauerlicherweise ist ein Donaudampfschiffkapit\xc3\xa4n auch <font color='red'>nur</font> <font color='green'>ein</font> Dampfschiffkapit\xc3\xa4n."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   326
        tagFormat = '%s'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   327
        # strange behaviour when using next code line
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   328
        # (same for '<a href="http://www.reportlab.org">%s</a>'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   329
        tagFormat = '<font color="red">%s</font>'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   330
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   331
        #text = " ".join([tagFormat % w for w in text.split()])
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   332
        
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   333
        story = [Paragraph((text + " ") * 3, style=normal)]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   334
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   335
        from reportlab.lib import pagesizes
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   336
        PAGESIZE = pagesizes.landscape(pagesizes.A4)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   337
        
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   338
        doc = TwoFrameDocTemplate(outputfile('test_paragraphs_splitframe.pdf'), pagesize=PAGESIZE)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   339
        doc.build(story)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   340
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   341
class FragmentTestCase(unittest.TestCase):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   342
    "Test fragmentation of paragraphs."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   343
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   344
    def test0(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   345
        "Test empty paragraph."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   346
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   347
        styleSheet = getSampleStyleSheet()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   348
        B = styleSheet['BodyText']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   349
        text = ''
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   350
        P = Paragraph(text, B)
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   351
        frags = [f.text for f in P.frags]
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   352
        assert frags == []
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   353
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   354
    def test1(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   355
        "Test simple paragraph."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   356
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   357
        styleSheet = getSampleStyleSheet()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   358
        B = styleSheet['BodyText']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   359
        text = "X<font name=Courier>Y</font>Z"
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   360
        P = Paragraph(text, B)
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   361
        frags = [f.text for f in P.frags]
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   362
        assert frags == ['X', 'Y', 'Z']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   363
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   364
class ULTestCase(unittest.TestCase):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   365
    "Test underlining and overstriking of paragraphs."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   366
    def testUl(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   367
        from reportlab.platypus import BaseDocTemplate, PageTemplate, Frame, PageBegin
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   368
        from reportlab.lib.units import inch
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   369
        from reportlab.platypus.flowables import AnchorFlowable
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   370
        class MyDocTemplate(BaseDocTemplate):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   371
            _invalidInitArgs = ('pageTemplates',)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   372
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   373
            def __init__(self, filename, **kw):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   374
                self.allowSplitting = 0
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   375
                kw['showBoundary']=1
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   376
                BaseDocTemplate.__init__(self, filename, **kw)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   377
                self.addPageTemplates(
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   378
                        [
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   379
                        PageTemplate('normal',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   380
                                [Frame(inch, inch, 6.27*inch, 9.69*inch, id='first',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red"))],
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   381
                                ),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   382
                        ])
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   383
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   384
        styleSheet = getSampleStyleSheet()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   385
        normal = ParagraphStyle(name='normal',fontName='Times-Roman',fontSize=12,leading=1.2*12,parent=styleSheet['Normal'])
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   386
        normal_sp = ParagraphStyle(name='normal_sp',parent=normal,alignment=TA_JUSTIFY,spaceBefore=12)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   387
        normal_just = ParagraphStyle(name='normal_just',parent=normal,alignment=TA_JUSTIFY)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   388
        normal_right = ParagraphStyle(name='normal_right',parent=normal,alignment=TA_RIGHT)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   389
        normal_center = ParagraphStyle(name='normal_center',parent=normal,alignment=TA_CENTER)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   390
        normal_indent = ParagraphStyle(name='normal_indent',firstLineIndent=0.5*inch,parent=normal)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   391
        normal_indent_lv_2 = ParagraphStyle(name='normal_indent_lv_2',firstLineIndent=1.0*inch,parent=normal)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   392
        texts = ['''Furthermore, a subset of <font size="14">English sentences</font> interesting on quite
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   393
independent grounds is not quite equivalent to a stipulation to place
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   394
the constructions into these various categories.''',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   395
        '''We will bring evidence in favor of
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   396
The following thesis:  most of the methodological work in modern
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   397
linguistics can be defined in such a way as to impose problems of
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   398
phonemic and morphological analysis.''']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   399
        story =[]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   400
        a = story.append
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   401
        a(Paragraph("This should &lt;a href=\"#theEnd\" color=\"blue\"&gt;<a href=\"#theEnd\" color=\"blue\">jump</a>&lt;/a&gt; jump to the end!",style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   402
        a(XPreformatted("This should &lt;a href=\"#theEnd\" color=\"blue\"&gt;<a href=\"#theEnd\" color=\"blue\">jump</a>&lt;/a&gt; jump to the end!",style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   403
        a(Paragraph("<a href=\"#theEnd\"><u><font color=\"blue\">ditto</font></u></a>",style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   404
        a(XPreformatted("<a href=\"#theEnd\"><u><font color=\"blue\">ditto</font></u></a>",style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   405
        a(Paragraph("This <font color='CMYKColor(0,0.6,0.94,0)'>should</font> &lt;a href=\"#thePenultimate\" color=\"blue\"&gt;<a href=\"#thePenultimate\" color=\"blue\">jump</a>&lt;/a&gt; jump to the penultimate page!",style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   406
        a(Paragraph("This should &lt;a href=\"#theThird\" color=\"blue\"&gt;<a href=\"#theThird\" color=\"blue\">jump</a>&lt;/a&gt; jump to a justified para!",style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   407
        a(Paragraph("This should &lt;a href=\"#theFourth\" color=\"blue\"&gt;<a href=\"#theFourth\" color=\"blue\">jump</a>&lt;/a&gt; jump to an indented para!",style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   408
        for mode in (0,1):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   409
            text0 = texts[0]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   410
            text1 = texts[1]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   411
            if mode:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   412
                text0 = text0.replace('English sentences','<b>English sentences</b>').replace('quite equivalent','<i>quite equivalent</i>')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   413
                text1 = text1.replace('the methodological work','<b>the methodological work</b>').replace('to impose problems','<i>to impose problems</i>')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   414
            for t in ('u','strike'):
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   415
                for n in range(6):
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   416
                    for s in (normal,normal_center,normal_right,normal_just,normal_indent, normal_indent_lv_2):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   417
                        for autoLeading in ('','min','max'):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   418
                            if n==4 and s==normal_center and t=='strike' and mode==1:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   419
                                a(Paragraph("<font color=green>The second jump at the beginning should come here &lt;a name=\"thePenultimate\"/&gt;<a name=\"thePenultimate\"/>!</font>",style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   420
                            elif n==4 and s==normal_just and t=='strike' and mode==1:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   421
                                a(Paragraph("<font color=green>The third jump at the beginning should come just below here to a paragraph with just an a tag in it!</font>",style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   422
                                a(Paragraph("<a name=\"theThird\"/>",style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   423
                            elif n==4 and s==normal_indent and t=='strike' and mode==1:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   424
                                a(Paragraph("<font color=green>The fourth jump at the beginning should come just below here!</font>",style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   425
                                a(AnchorFlowable('theFourth'))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   426
                            a(Paragraph('n=%d style=%s(autoLeading=%s) tag=%s'%(n,s.name,autoLeading,t),style=normal_sp))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   427
                            a(Paragraph('<para autoleading="%s">%s<%s>%s</%s>. %s <%s>%s</%s>. %s</para>' % (
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   428
                            autoLeading,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   429
                            (s==normal_indent_lv_2 and '<seq id="document" inc="no"/>.<seq id="document_lv_2"/>' or ''),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   430
                            t,' '.join((n+1)*['A']),t,text0,t,' '.join((n+1)*['A']),t,text1),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   431
                            style=s))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   432
        a(Paragraph("The jump at the beginning should come here &lt;a name=\"theEnd\"/&gt;<a name=\"theEnd\"/>!",style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   433
        doc = MyDocTemplate(outputfile('test_platypus_paragraphs_ul.pdf'))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   434
        doc.build(story)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   435
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   436
class AutoLeadingTestCase(unittest.TestCase):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   437
    "Test underlining and overstriking of paragraphs."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   438
    def testAutoLeading(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   439
        from reportlab.platypus import BaseDocTemplate, PageTemplate, Frame, PageBegin
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   440
        from reportlab.lib.units import inch
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   441
        from reportlab.platypus.flowables import AnchorFlowable
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   442
        class MyDocTemplate(BaseDocTemplate):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   443
            _invalidInitArgs = ('pageTemplates',)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   444
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   445
            def __init__(self, filename, **kw):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   446
                self.allowSplitting = 0
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   447
                kw['showBoundary']=1
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   448
                BaseDocTemplate.__init__(self, filename, **kw)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   449
                self.addPageTemplates(
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   450
                        [
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   451
                        PageTemplate('normal',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   452
                                [Frame(inch, inch, 6.27*inch, 9.69*inch, id='first',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red"))],
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   453
                                ),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   454
                        ])
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   455
2987
711910106e3a tests: more changes to testsFolder and friends
rgbecker
parents: 2984
diff changeset
   456
        from reportlab.lib.testutils import testsFolder
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   457
        styleSheet = getSampleStyleSheet()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   458
        normal = ParagraphStyle(name='normal',fontName='Times-Roman',fontSize=12,leading=1.2*12,parent=styleSheet['Normal'])
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   459
        normal_sp = ParagraphStyle(name='normal_sp',parent=normal,alignment=TA_JUSTIFY,spaceBefore=12)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   460
        texts = ['''Furthermore, a subset of <font size="14">English sentences</font> interesting on quite
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   461
independent grounds is not quite equivalent to a stipulation to place
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
   462
<font color="blue">the constructions <img src="%(testsFolder)s/../docs/images/testimg.gif"/> into these various categories.</font>'''%dict(testsFolder=testsFolder),
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   463
        '''We will bring <font size="18">Ugly Things</font> in favor of
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   464
The following thesis:  most of the methodological work in Modern
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
   465
Linguistics can be <img src="%(testsFolder)s/../docs/images/testimg.gif" valign="baseline" /> defined in such <img src="%(testsFolder)s/../docs/images/testimg.gif" valign="10" /> a way as to impose problems of
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
   466
phonemic and <u>morphological <img src="%(testsFolder)s/../docs/images/testimg.gif" valign="top"/> </u> analysis.'''%dict(testsFolder=testsFolder)]
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   467
        story =[]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   468
        a = story.append
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   469
        t = 'u'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   470
        n = 1
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   471
        for s in (normal,normal_sp):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   472
            for autoLeading in ('','min','max'):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   473
                a(Paragraph('style=%s(autoLeading=%s)'%(s.name,autoLeading),style=normal_sp))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   474
                a(Paragraph('<para autoleading="%s"><%s>%s</%s>. %s <%s>%s</%s>. %s</para>' % (
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   475
                            autoLeading,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   476
                            t,' '.join((n+1)*['A']),t,texts[0],t,' '.join((n+1)*['A']),t,texts[1]),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   477
                            style=s))
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
   478
        a(Paragraph('''<img src="%(testsFolder)s/../docs/images/testimg.gif" valign="top"/> image is very first thing in the line.'''%dict(testsFolder=testsFolder), style=normal))
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   479
        a(Paragraph('some text.... some more.... some text.... some more....', normal))
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
   480
        a(Paragraph('<img src="%(testsFolder)s/../docs/images/testimg.gif" width="0.57in" height="0.19in" /> some text <br /> '%dict(testsFolder=testsFolder), normal))
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   481
        a(Paragraph('some text.... some more.... some text.... some more....', normal))
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
   482
        a(Paragraph('<img src="%(testsFolder)s/../docs/images/testimg.gif" width="0.57in" height="0.19in" /> <br /> '%dict(testsFolder=testsFolder), normal))
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   483
        a(Paragraph('some text.... some more.... some text.... some more....', normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   484
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   485
        #Volker Haas' valign tests
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   486
        fmt = '''<font color="red">%(valign)s</font>: Furthermore, a <u>subset</u> <strike>of</strike> <font size="14">English sentences</font> interesting on quite
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
   487
independent grounds is not quite equivalent to a stipulation to place <img src="%(testsFolder)s/../docs/images/redsquare.png" width="0.5in" height="0.5in" valign="%(valign)s"/>
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   488
the constructions into these <u>various</u> categories. We will bring <font size="18">Ugly Things</font> in favor of
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   489
The following thesis:  most of the methodological work in Modern
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   490
Linguistics can be defined in such a way as to impose problems of
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   491
phonemic and <u>morphological</u> <strike>analysis</strike>.'''
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   492
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   493
        p_style= ParagraphStyle('Normal')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   494
        p_style.autoLeading = 'max'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   495
        for valign in (
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   496
                'baseline',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   497
                'sub',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   498
                'super',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   499
                'top',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   500
                'text-top',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   501
                'middle',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   502
                'bottom',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   503
                'text-bottom',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   504
                '0%',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   505
                '2in',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   506
                ):
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
   507
            a(Paragraph(fmt % dict(valign=valign,testsFolder=testsFolder),p_style))
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
   508
            a(XPreformatted(fmt % dict(valign=valign,testsFolder=testsFolder),p_style))
3439
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   509
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   510
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   511
        a(Paragraph('<br/><b>Some Paragraph tests of &lt;img width="x%" height="x%"</b>...', normal))
3435
31d0d9bb877a platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3371
diff changeset
   512
        a(Paragraph('H=10%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="0.57in" height="10%%" />'%dict(testsFolder=testsFolder), normal))
31d0d9bb877a platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3371
diff changeset
   513
        a(Paragraph('H=50%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="0.57in" height="50%%" />'%dict(testsFolder=testsFolder), normal))
31d0d9bb877a platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3371
diff changeset
   514
        a(Paragraph('H=100%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="0.57in" height="100%%" />'%dict(testsFolder=testsFolder), normal))
31d0d9bb877a platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3371
diff changeset
   515
        a(Paragraph('H=100%% W=10%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="10%%" height="100%%" />'%dict(testsFolder=testsFolder), normal))
31d0d9bb877a platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3371
diff changeset
   516
        a(Paragraph('H=100%% W=50%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="50%%" height="100%%" />'%dict(testsFolder=testsFolder), normal))
3439
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   517
        a(Paragraph('H=50%% W=50%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="50%%" height="50%%" />'%dict(testsFolder=testsFolder), normal))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   518
        a(Paragraph('<br/><b>Some XPreformatted tests of &lt;img width="x%" height="x%"</b>...', normal))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   519
        a(XPreformatted('H=10%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="0.57in" height="10%%" />'%dict(testsFolder=testsFolder), normal))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   520
        a(XPreformatted('H=50%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="0.57in" height="50%%" />'%dict(testsFolder=testsFolder), normal))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   521
        a(XPreformatted('H=100%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="0.57in" height="100%%" />'%dict(testsFolder=testsFolder), normal))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   522
        a(XPreformatted('H=100%% W=10%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="10%%" height="100%%" />'%dict(testsFolder=testsFolder), normal))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   523
        a(XPreformatted('H=100%% W=50%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="50%%" height="100%%" />'%dict(testsFolder=testsFolder), normal))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   524
        a(XPreformatted('H=50%% W=50%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="50%%" height="50%%" />'%dict(testsFolder=testsFolder), normal))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   525
        a(Paragraph('<br/><b>Some CJK Paragraph tests of &lt;img width="x%" height="x%"</b>...', normal))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   526
        normalCJK = ParagraphStyle('normalCJK', parent=normal, wordWrap = 'CJK')
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   527
        a(Paragraph('H=10%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="0.57in" height="10%%" />'%dict(testsFolder=testsFolder), normalCJK))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   528
        a(Paragraph('H=50%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="0.57in" height="50%%" />'%dict(testsFolder=testsFolder), normalCJK))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   529
        a(Paragraph('H=100%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="0.57in" height="100%%" />'%dict(testsFolder=testsFolder), normalCJK))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   530
        a(Paragraph('H=100%% W=10%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="10%%" height="100%%" />'%dict(testsFolder=testsFolder), normalCJK))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   531
        a(Paragraph('H=100%% W=50%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="50%%" height="100%%" />'%dict(testsFolder=testsFolder), normalCJK))
dc7b50400f12 test_platypus_paragraphs.py: add more tests of percentaged width/height img tags
rgbecker
parents: 3435
diff changeset
   532
        a(Paragraph('H=50%% W=50%% <img src="%(testsFolder)s/../docs/images/testimg.gif" width="50%%" height="50%%" />'%dict(testsFolder=testsFolder), normalCJK))
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   533
        doc = MyDocTemplate(outputfile('test_platypus_paragraphs_autoleading.pdf'))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   534
        doc.build(story)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   535
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   536
class JustifyTestCase(unittest.TestCase):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   537
    "Test justification of paragraphs."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   538
    def testUl(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   539
        from reportlab.platypus import BaseDocTemplate, PageTemplate, Frame, PageBegin
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   540
        from reportlab.lib.units import inch
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   541
        class MyDocTemplate(BaseDocTemplate):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   542
            _invalidInitArgs = ('pageTemplates',)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   543
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   544
            def __init__(self, filename, **kw):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   545
                self.allowSplitting = 0
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   546
                BaseDocTemplate.__init__(self, filename, **kw)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   547
                self.addPageTemplates(
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   548
                        [
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   549
                        PageTemplate('normal',
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   550
                                [Frame(inch, inch, 6.27*inch, 9.69*inch, id='first',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red"))],
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   551
                                ),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   552
                        ])
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   553
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   554
        styleSheet = getSampleStyleSheet()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   555
        normal = ParagraphStyle(name='normal',fontName='Times-Roman',fontSize=12,leading=1.2*12,parent=styleSheet['Normal'])
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   556
        normal_just = ParagraphStyle(name='normal_just',parent=normal,alignment=TA_JUSTIFY,spaceAfter=12)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   557
        text0 = '''Furthermore, a subset of English sentences interesting on quite
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   558
independent grounds is not quite equivalent to a stipulation to place
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   559
the constructions into these various categories. We will bring evidence in favor of
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   560
The following thesis:  most of the methodological work in modern
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   561
linguistics can be defined in such a way as to impose problems of
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   562
phonemic and morphological analysis.'''
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   563
        story =[]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   564
        a = story.append
3371
24dcc0cb4727 test_platypus_paragraphs: add hard spaces case
rgbecker
parents: 3326
diff changeset
   565
        for mode in (0,1,2,3,4):
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   566
            text = text0
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   567
            if mode==1:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   568
                text = text.replace('English sentences','<b>English sentences</b>').replace('quite equivalent','<i>quite equivalent</i>')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   569
                text = text.replace('the methodological work','<b>the methodological work</b>').replace('to impose problems','<i>to impose problems</i>')
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   570
                a(Paragraph('Justified paragraph in normal/bold/italic font',style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   571
            elif mode==2:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   572
                text = '<b>%s</b>' % text
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   573
                a(Paragraph('Justified paragraph in bold font',style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   574
            elif mode==3:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   575
                text = '<i>%s</i>' % text
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   576
                a(Paragraph('Justified paragraph in italic font',style=normal))
3371
24dcc0cb4727 test_platypus_paragraphs: add hard spaces case
rgbecker
parents: 3326
diff changeset
   577
            elif mode==4:
24dcc0cb4727 test_platypus_paragraphs: add hard spaces case
rgbecker
parents: 3326
diff changeset
   578
                text = text.replace('English ','English&nbsp;').replace('quite ','quite&nbsp;')
24dcc0cb4727 test_platypus_paragraphs: add hard spaces case
rgbecker
parents: 3326
diff changeset
   579
                text = text.replace(' methodological','&nbsp;methodological').replace(' impose','&nbsp;impose')
3807
55af72526d90 fix tests
robin
parents: 3800
diff changeset
   580
                a(Paragraph('Justified paragraph in normal font &amp; some hard spaces',style=normal))
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   581
            else:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   582
                a(Paragraph('Justified paragraph in normal font',style=normal))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   583
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   584
            a(Paragraph(text,style=normal_just))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   585
        doc = MyDocTemplate(outputfile('test_platypus_paragraphs_just.pdf'))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   586
        doc.build(story)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   587
3564
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   588
    def testAutoPageTemplate(self):
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   589
        from reportlab.platypus import BaseDocTemplate, PageTemplate, Frame, PageBegin
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   590
        from reportlab.lib.units import inch
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   591
        class onPage:
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   592
            def __init__(self,label):
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   593
                self.label = label
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   594
            def __call__(self,canv,doc):
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   595
                canv.drawString(72,72,'This is pageTemplate(%s)' % (self.label,))
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   596
        class MyDocTemplate(BaseDocTemplate):
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   597
            _invalidInitArgs = ('pageTemplates',)
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   598
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   599
            def __init__(self, filename, **kw):
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   600
                self.allowSplitting = 0
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   601
                BaseDocTemplate.__init__(self, filename, **kw)
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   602
                self.addPageTemplates(
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   603
                        [
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   604
                        PageTemplate('normal',
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   605
                                [Frame(inch, inch, 6.27*inch, 9.69*inch, id='first',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red"))],
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   606
                                onPage = onPage('normal'),
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   607
                                ),
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   608
                        PageTemplate('auto',
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   609
                                [Frame(inch, inch, 6.27*inch, 9.69*inch, id='first',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red"))],
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   610
                                onPage = onPage('auto'),
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   611
                                autoNextPageTemplate = 'autoFollow',
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   612
                                ),
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   613
                        PageTemplate('autoFollow',
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   614
                                [Frame(inch, inch, 6.27*inch, 9.69*inch, id='first',topPadding=0,rightPadding=0,leftPadding=0,bottomPadding=0,showBoundary=ShowBoundaryValue(color="red"))],
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   615
                                onPage = onPage('autoFollow'),
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   616
                                ),
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   617
                        ])
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   618
        styleSheet = getSampleStyleSheet()
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   619
        normal = ParagraphStyle(name='normal',fontName='Times-Roman',fontSize=12,leading=1.2*12,parent=styleSheet['Normal'])
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   620
        story =[]
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   621
        a = story.append
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   622
        a(Paragraph('should be on page template normal', normal))
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   623
        a(NextPageTemplate('auto'))
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   624
        a(PageBreak())
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   625
        a(Paragraph('should be on page template auto', normal))
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   626
        a(PageBreak())
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   627
        a(DocAssert('doc.pageTemplate.id=="autoFollow"','expected doc.pageTemplate.id=="autoFollow"'))
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   628
        a(Paragraph('should be on page template autoFollow 1', normal))
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   629
        a(PageBreak())
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   630
        a(Paragraph('should be on page template autoFollow 2', normal))
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   631
        doc = MyDocTemplate(outputfile('test_platypus_paragraphs_AutoNextPageTemplate.pdf'))
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   632
        doc.build(story)
fd1f9e74eac2 test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents: 3492
diff changeset
   633
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   634
#noruntests
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   635
def makeSuite():
3371
24dcc0cb4727 test_platypus_paragraphs: add hard spaces case
rgbecker
parents: 3326
diff changeset
   636
    return makeSuiteForClasses(ParagraphCorners,SplitFrameParagraphTest,FragmentTestCase, ParagraphSplitTestCase, ULTestCase, JustifyTestCase,
24dcc0cb4727 test_platypus_paragraphs: add hard spaces case
rgbecker
parents: 3326
diff changeset
   637
            AutoLeadingTestCase)
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   638
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   639
#noruntests
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   640
if __name__ == "__main__":
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   641
    unittest.TextTestRunner().run(makeSuite())
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   642
    printLocation()