reportlab/platypus/paragraph.py
author rgbecker
Fri, 21 Jul 2006 12:44:40 +0000
changeset 2664 c9faa3a99e93
parent 2663 927cc273c5a5
child 2670 3fdd642a7b76
permissions -rw-r--r--
reportlab/platypus: <br/> tags now working
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2321
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2004
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 488
diff changeset
     2
#see license.txt for license details
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2321
diff changeset
     3
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/platypus/paragraph.py
2321
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2211
diff changeset
     4
__version__=''' $Id$ '''
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
     5
from string import join, whitespace, find
539
14dd200244e2 Layout fixes; the text objects needed moves before & after and the bullet width
rgbecker
parents: 534
diff changeset
     6
from operator import truth
438
fa5d480207bc Preparing for cleanup
rgbecker
parents: 434
diff changeset
     7
from types import StringType, ListType
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
     8
from reportlab.pdfbase.pdfmetrics import stringWidth, getFont
518
5be3fcb26c78 Semantic Name changes
rgbecker
parents: 516
diff changeset
     9
from reportlab.platypus.paraparser import ParaParser
279
e7d8b3631d5c Global sequencer put in the 'story builder'.
andy_robinson
parents: 268
diff changeset
    10
from reportlab.platypus.flowables import Flowable
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
    11
from reportlab.lib.colors import Color
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
    12
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
449
1ba0d6fb0f9e XPreformatted fixed empty lines and leading space
rgbecker
parents: 438
diff changeset
    13
from reportlab.lib.utils import _className
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    14
from reportlab.lib.textsplit import wordSplit
212
b04e22acb4fa Splitting changes
rgbecker
parents: 208
diff changeset
    15
from copy import deepcopy
518
5be3fcb26c78 Semantic Name changes
rgbecker
parents: 516
diff changeset
    16
from reportlab.lib.abag import ABag
2594
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
    17
import re
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    18
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    19
#on UTF8 branch, split and strip must be unicode-safe!
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    20
def split(text, delim=' '):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    21
    if type(text) is str: text = text.decode('utf8')
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    22
    if type(delim) is str: delim = delim.decode('utf8')
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    23
    return [uword.encode('utf8') for uword in text.split(delim)]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    24
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    25
def strip(text):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    26
    if type(text) is str: text = text.decode('utf8')
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    27
    return text.strip().encode('utf8')
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    28
518
5be3fcb26c78 Semantic Name changes
rgbecker
parents: 516
diff changeset
    29
class ParaLines(ABag):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    30
    """
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    31
    class ParaLines contains the broken into lines representation of Paragraphs
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    32
        kind=0  Simple
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    33
        fontName, fontSize, textColor apply to whole Paragraph
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    34
        lines   [(extraSpace1,words1),....,(extraspaceN,wordsN)]
521
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
    35
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
    36
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    37
        kind==1 Complex
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    38
        lines   [FragLine1,...,FragLineN]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    39
    """
521
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
    40
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
    41
class FragLine(ABag):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    42
    """class FragLine contains a styled line (ie a line with more than one style)
521
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
    43
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    44
    extraSpace  unused space for justification only
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    45
    wordCount   1+spaces in line for justification purposes
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    46
    words       [ParaFrags] style text lumps to be concatenated together
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    47
    fontSize    maximum fontSize seen on the line; not used at present,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    48
                but could be used for line spacing.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    49
    """
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
    50
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
    51
#our one and only parser
268
8414113fa500 more documentation changes
aaron_watters
parents: 253
diff changeset
    52
# XXXXX if the parser has any internal state using only one is probably a BAD idea!
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
    53
_parser=ParaParser()
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
    54
539
14dd200244e2 Layout fixes; the text objects needed moves before & after and the bullet width
rgbecker
parents: 534
diff changeset
    55
def _lineClean(L):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    56
    return join(filter(truth,split(strip(L))))
539
14dd200244e2 Layout fixes; the text objects needed moves before & after and the bullet width
rgbecker
parents: 534
diff changeset
    57
438
fa5d480207bc Preparing for cleanup
rgbecker
parents: 434
diff changeset
    58
def cleanBlockQuotedText(text,joiner=' '):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    59
    """This is an internal utility which takes triple-
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    60
    quoted text form within the document and returns
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    61
    (hopefully) the paragraph the user intended originally."""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    62
    L=filter(truth,map(_lineClean, split(text, '\n')))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    63
    return join(L, joiner)
539
14dd200244e2 Layout fixes; the text objects needed moves before & after and the bullet width
rgbecker
parents: 534
diff changeset
    64
14dd200244e2 Layout fixes; the text objects needed moves before & after and the bullet width
rgbecker
parents: 534
diff changeset
    65
def setXPos(tx,dx):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    66
    if dx>1e-6 or dx<-1e-6:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    67
        tx.setXPos(dx)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
    68
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
    69
def _leftDrawParaLine( tx, offset, extraspace, words, last=0):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    70
    setXPos(tx,offset)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    71
    tx._textOut(join(words),1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    72
    setXPos(tx,-offset)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
    73
    return offset
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
    74
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
    75
def _centerDrawParaLine( tx, offset, extraspace, words, last=0):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    76
    m = offset + 0.5 * extraspace
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    77
    setXPos(tx,m)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    78
    tx._textOut(join(words),1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    79
    setXPos(tx,-m)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
    80
    return m
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
    81
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
    82
def _rightDrawParaLine( tx, offset, extraspace, words, last=0):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    83
    m = offset + extraspace
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    84
    setXPos(tx,m)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    85
    tx._textOut(join(words),1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    86
    setXPos(tx,-m)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
    87
    return m
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
    88
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
    89
def _justifyDrawParaLine( tx, offset, extraspace, words, last=0):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    90
    setXPos(tx,offset)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    91
    text  = join(words)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    92
    if last:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    93
        #last one, left align
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    94
        tx._textOut(text,1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    95
    else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    96
        nSpaces = len(words)-1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    97
        if nSpaces:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    98
            tx.setWordSpace(extraspace / float(nSpaces))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    99
            tx._textOut(text,1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   100
            tx.setWordSpace(0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   101
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   102
            tx._textOut(text,1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   103
    setXPos(tx,-offset)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   104
    return offset
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   105
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   106
def _putFragLine(tx,words):
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   107
    cur_x = 0
2456
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   108
    xtraState = tx.XtraState
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   109
    for f in words:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   110
        if hasattr(f,'cbDefn'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   111
            func = getattr(tx._canvas,f.cbDefn.name,None)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   112
            if not func:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   113
                raise AttributeError, "Missing %s callback attribute '%s'" % (f.cbDefn.kind,f.cbDefn.name)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   114
            func(tx._canvas,f.cbDefn.kind,f.cbDefn.label)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   115
            if f is words[-1]: tx._textOut('',1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   116
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   117
            if (tx._fontname,tx._fontsize)!=(f.fontName,f.fontSize):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   118
                tx._setFont(f.fontName, f.fontSize)
2456
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   119
            if xtraState.textColor!=f.textColor:
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   120
                xtraState.textColor = f.textColor
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   121
                tx.setFillColor(f.textColor)
2456
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   122
            if xtraState.rise!=f.rise:
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   123
                xtraState.rise=f.rise
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   124
                tx.setRise(f.rise)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   125
            tx._textOut(f.text,f is words[-1])  # cheap textOut
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   126
            txtlen = tx._canvas.stringWidth(f.text, tx._fontname, tx._fontsize)
2456
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   127
            if not xtraState.underline and f.underline:
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   128
                xtraState.underline = 1
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   129
                xtraState.underline_x = cur_x
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   130
                xtraState.underlineColor = f.textColor
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   131
            elif xtraState.underline:
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   132
                if not f.underline:
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   133
                    xtraState.underline = 0
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   134
                    spacelen = tx._canvas.stringWidth(' ', tx._fontname, tx._fontsize)
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   135
                    xtraState.underlines.append( (xtraState.underline_x, cur_x-spacelen, xtraState.underlineColor) )
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   136
                    xtraState.underlineColor = None
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   137
                elif xtraState.textColor!=xtraState.underlineColor:
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   138
                    xtraState.underlines.append( (xtraState.underline_x, cur_x, xtraState.underlineColor) )
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   139
                    xtraState.underlineColor = xtraState.textColor
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   140
                    xtraState.underline_x = cur_x
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   141
            if not xtraState.strike and f.strike:
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   142
                xtraState.strike = 1
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   143
                xtraState.strike_x = cur_x
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   144
                xtraState.strikeColor = f.textColor
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   145
            elif xtraState.strike:
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   146
                if not f.strike:
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   147
                    xtraState.strike = 0
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   148
                    spacelen = tx._canvas.stringWidth(' ', tx._fontname, tx._fontsize)
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   149
                    xtraState.strikes.append( (xtraState.strike_x, cur_x-spacelen, xtraState.strikeColor) )
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   150
                    xtraState.strikeColor = None
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   151
                elif xtraState.textColor!=xtraState.strikeColor:
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   152
                    xtraState.strikes.append( (xtraState.strike_x, cur_x, xtraState.strikeColor) )
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   153
                    xtraState.strikeColor = xtraState.textColor
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   154
                    xtraState.strike_x = cur_x
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   155
            if not xtraState.link and f.link:
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   156
                xtraState.link = f.link
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   157
                xtraState.link_x = cur_x
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   158
            elif xtraState.link and f.link is not xtraState.link:
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   159
                    spacelen = tx._canvas.stringWidth(' ', tx._fontname, tx._fontsize)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   160
                    xtraState.links.append( (xtraState.link_x, cur_x-spacelen, xtraState.link) )
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   161
                    xtraState.link = None
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   162
            cur_x += txtlen
2456
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   163
    if xtraState.underline:
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   164
        xtraState.underlines.append( (xtraState.underline_x, cur_x, xtraState.underlineColor) )
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   165
    if xtraState.strike:
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   166
        xtraState.strikes.append( (xtraState.strike_x, cur_x, xtraState.strikeColor) )
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   167
    if xtraState.link:
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   168
        xtraState.links.append( (xtraState.link_x, cur_x, xtraState.link) )
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   169
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   170
def _leftDrawParaLineX( tx, offset, line, last=0):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   171
    setXPos(tx,offset)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   172
    _putFragLine(tx, line.words)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   173
    setXPos(tx,-offset)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   174
    return offset
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   175
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   176
def _centerDrawParaLineX( tx, offset, line, last=0):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   177
    m = offset+0.5*line.extraSpace
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   178
    setXPos(tx,m)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   179
    _putFragLine(tx, line.words)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   180
    setXPos(tx,-m)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   181
    return m
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   182
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   183
def _rightDrawParaLineX( tx, offset, line, last=0):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   184
    m = offset+line.extraSpace
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   185
    setXPos(tx,m)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   186
    _putFragLine(tx, line.words)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   187
    setXPos(tx,-m)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   188
    return m
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   189
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   190
def _justifyDrawParaLineX( tx, offset, line, last=0):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   191
    setXPos(tx,offset)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   192
    if last:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   193
        #last one, left align
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   194
        _putFragLine(tx, line.words)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   195
    else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   196
        nSpaces = line.wordCount - 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   197
        if nSpaces:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   198
            tx.setWordSpace(line.extraSpace / float(nSpaces))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   199
            _putFragLine(tx, line.words)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   200
            tx.setWordSpace(0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   201
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   202
            _putFragLine(tx, line.words)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   203
    setXPos(tx,-offset)
2183
324abf21b7e5 Fix missing return
rgbecker
parents: 2182
diff changeset
   204
    return offset
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   205
1373
df3383c5f8bc Added accelerated _sameFrag
rgbecker
parents: 1160
diff changeset
   206
try:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   207
    from _rl_accel import _sameFrag
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   208
except ImportError:
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   209
    try:
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   210
        from reportlab.lib._rl_accel import _sameFrag
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   211
    except ImportError:
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   212
        #if you modify this you need to modify _rl_accel RGB
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   213
        def _sameFrag(f,g):
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   214
            'returns 1 if two ParaFrags map out the same'
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   215
            if (hasattr(f,'cbDefn') or hasattr(g,'cbDefn')
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   216
                    or hasattr(f,'lineBreak') or hasattr(g,'lineBreak')): return 0
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   217
            for a in ('fontName', 'fontSize', 'textColor', 'rise', 'underline', 'strike', 'link'):
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   218
                if getattr(f,a)!=getattr(g,a): return 0
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   219
            return 1
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   220
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   221
def _getFragWords(frags):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   222
    ''' given a Parafrag list return a list of fragwords
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   223
        [[size, (f00,w00), ..., (f0n,w0n)],....,[size, (fm0,wm0), ..., (f0n,wmn)]]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   224
        each pair f,w represents a style and some string
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   225
        each sublist represents a word
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   226
    '''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   227
    R = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   228
    W = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   229
    n = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   230
    for f in frags:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   231
        text = f.text
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   232
        #del f.text # we can't do this until we sort out splitting
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   233
                    # of paragraphs
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   234
        if text!='':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   235
            S = split(text)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   236
            if S==[]: S = ['']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   237
            if W!=[] and text[0] in whitespace:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   238
                W.insert(0,n)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   239
                R.append(W)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   240
                W = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   241
                n = 0
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   242
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   243
            for w in S[:-1]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   244
                W.append((f,w))
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   245
                n += stringWidth(w, f.fontName, f.fontSize)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   246
                W.insert(0,n)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   247
                R.append(W)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   248
                W = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   249
                n = 0
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   250
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   251
            w = S[-1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   252
            W.append((f,w))
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   253
            n += stringWidth(w, f.fontName, f.fontSize)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   254
            if text[-1] in whitespace:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   255
                W.insert(0,n)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   256
                R.append(W)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   257
                W = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   258
                n = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   259
        elif hasattr(f,'cbDefn'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   260
            W.append((f,''))
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   261
        elif hasattr(f, 'lineBreak'):
2663
927cc273c5a5 <br/> work in progress
andy
parents: 2646
diff changeset
   262
            #pass the frag through.  The line breaker will scan for it.
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   263
            if W!=[]:
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   264
                W.insert(0,n)
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   265
                R.append(W)
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   266
                W = []
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   267
                n = 0
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   268
            R.append([0,(f,'')])
508
37dc6fc3fa65 More <onDraw> hacks
rgbecker
parents: 506
diff changeset
   269
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   270
    if W!=[]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   271
        W.insert(0,n)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   272
        R.append(W)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   273
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   274
    return R
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   275
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   276
def _split_blParaSimple(blPara,start,stop):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   277
    f = blPara.clone()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   278
    for a in ('lines', 'kind', 'text'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   279
        if hasattr(f,a): delattr(f,a)
212
b04e22acb4fa Splitting changes
rgbecker
parents: 208
diff changeset
   280
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   281
    f.words = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   282
    for l in blPara.lines[start:stop]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   283
        for w in l[1]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   284
            f.words.append(w)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   285
    return [f]
212
b04e22acb4fa Splitting changes
rgbecker
parents: 208
diff changeset
   286
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   287
def _split_blParaHard(blPara,start,stop):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   288
    f = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   289
    lines = blPara.lines[start:stop]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   290
    for l in lines:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   291
        for w in l.words:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   292
            f.append(w)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   293
        if l is not lines[-1]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   294
            i = len(f)-1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   295
            while hasattr(f[i],'cbDefn'): i = i-1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   296
            g = f[i]
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   297
            if g.text and g.text[-1]!=' ': g.text += ' '
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   298
    return f
212
b04e22acb4fa Splitting changes
rgbecker
parents: 208
diff changeset
   299
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 221
diff changeset
   300
def _drawBullet(canvas, offset, cur_y, bulletText, style):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   301
    '''draw a bullet text could be a simple string or a frag list'''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   302
    tx2 = canvas.beginText(style.bulletIndent, cur_y)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   303
    tx2.setFont(style.bulletFontName, style.bulletFontSize)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   304
    tx2.setFillColor(hasattr(style,'bulletColor') and style.bulletColor or style.textColor)
2646
d177c247184a platypus: eliminate StringType usages and cp1252 usage
rgbecker
parents: 2644
diff changeset
   305
    if isinstance(bulletText,basestring):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   306
        tx2.textOut(bulletText)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   307
    else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   308
        for f in bulletText:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   309
            tx2.setFont(f.fontName, f.fontSize)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   310
            tx2.setFillColor(f.textColor)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   311
            tx2.textOut(f.text)
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 221
diff changeset
   312
2366
7dd247980b7d minor twitching on Indenter
rgbecker
parents: 2341
diff changeset
   313
    canvas.drawText(tx2)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   314
    #AR making definition lists a bit less ugly
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   315
    #bulletEnd = tx2.getX()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   316
    bulletEnd = tx2.getX() + style.bulletFontSize * 0.6
2366
7dd247980b7d minor twitching on Indenter
rgbecker
parents: 2341
diff changeset
   317
    offset = max(offset,bulletEnd - style.leftIndent)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   318
    return offset
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 221
diff changeset
   319
438
fa5d480207bc Preparing for cleanup
rgbecker
parents: 434
diff changeset
   320
def _handleBulletWidth(bulletText,style,maxWidths):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   321
    '''work out bullet width and adjust maxWidths[0] if neccessary
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   322
    '''
2646
d177c247184a platypus: eliminate StringType usages and cp1252 usage
rgbecker
parents: 2644
diff changeset
   323
    if bulletText!=None:
d177c247184a platypus: eliminate StringType usages and cp1252 usage
rgbecker
parents: 2644
diff changeset
   324
        if isinstance(bulletText,basestring):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   325
            bulletWidth = stringWidth( bulletText, style.bulletFontName, style.bulletFontSize)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   326
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   327
            #it's a list of fragments
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   328
            bulletWidth = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   329
            for f in bulletText:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   330
                bulletWidth = bulletWidth + stringWidth(f.text, f.fontName, f.fontSize)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   331
        bulletRight = style.bulletIndent + bulletWidth + 0.6 * style.bulletFontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   332
        indent = style.leftIndent+style.firstLineIndent
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   333
        if bulletRight > indent:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   334
            #..then it overruns, and we have less space available on line 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   335
            maxWidths[0] = maxWidths[0] - (bulletRight - indent)
438
fa5d480207bc Preparing for cleanup
rgbecker
parents: 434
diff changeset
   336
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   337
def splitLines0(frags,widths):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   338
    '''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   339
    given a list of ParaFrags we return a list of ParaLines
549
f9e66c978f3a Start on new simpler line splitter
rgbecker
parents: 547
diff changeset
   340
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   341
    each ParaLine has
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   342
    1)  ExtraSpace
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   343
    2)  blankCount
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   344
    3)  [textDefns....]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   345
        each text definition is a (ParaFrag, start, limit) triplet
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   346
    '''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   347
    #initialise the algorithm
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   348
    lines   = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   349
    lineNum = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   350
    maxW    = widths[lineNum]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   351
    i       = -1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   352
    l       = len(frags)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   353
    lim     = start = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   354
    while 1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   355
        #find a non whitespace character
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   356
        while i<l:
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   357
            while start<lim and text[start]==' ': start += 1
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   358
            if start==lim:
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   359
                i += 1
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   360
                if i==l: break
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   361
                start = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   362
                f = frags[i]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   363
                text = f.text
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   364
                lim = len(text)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   365
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   366
                break   # we found one
551
21b8a2cb8c8b Hack to fix Dinu's problem
rgbecker
parents: 549
diff changeset
   367
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   368
        if start==lim: break    #if we didn't find one we are done
551
21b8a2cb8c8b Hack to fix Dinu's problem
rgbecker
parents: 549
diff changeset
   369
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   370
        #start of a line
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   371
        g       = (None,None,None)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   372
        line    = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   373
        cLen    = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   374
        nSpaces = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   375
        while cLen<maxW:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   376
            j = find(text,' ',start)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   377
            if j<0: j==lim
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   378
            w = stringWidth(text[start:j],f.fontName,f.fontSize)
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   379
            cLen += w
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   380
            if cLen>maxW and line!=[]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   381
                cLen = cLen-w
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   382
                #this is the end of the line
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   383
                while g.text[lim]==' ':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   384
                    lim = lim - 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   385
                    nSpaces = nSpaces-1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   386
                break
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   387
            if j<0: j = lim
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   388
            if g[0] is f: g[2] = j  #extend
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   389
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   390
                g = (f,start,j)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   391
                line.append(g)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   392
            if j==lim:
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   393
                i += 1
549
f9e66c978f3a Start on new simpler line splitter
rgbecker
parents: 547
diff changeset
   394
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   395
def _do_under_line(i, t_off, tx, lm=-0.125):
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   396
    y = tx.XtraState.cur_y - i*tx.XtraState.style.leading + lm*tx.XtraState.f.fontSize
2211
7d7e9b66a4b6 Fix to <u> from Ulrich Screiner
rgbecker
parents: 2200
diff changeset
   397
    text = join(tx.XtraState.lines[i][1])
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   398
    textlen = tx._canvas.stringWidth(text, tx._fontname, tx._fontsize)
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   399
    tx._canvas.line(t_off, y, t_off+textlen, y)
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   400
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   401
2594
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   402
_scheme_re = re.compile('^[a-zA-Z][-+a-zA-Z0-9]+$')
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   403
def _doLink(tx,link,rect):
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   404
    if type(link) is unicode:
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   405
        link = unicode.encode('utf8')
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   406
    parts = link.split(':',1)
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   407
    scheme = len(parts)==2 and parts[0].lower() or ''
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   408
    if _scheme_re.match(scheme) and scheme!='document':
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   409
        kind=scheme.lower()=='pdf' and 'GoToR' or 'URI'
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   410
        if kind=='GoToR': link = parts[1]
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   411
        tx._canvas.linkURL(link, rect, relative=1, kind=kind)
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   412
    else:
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   413
        tx._canvas.linkRect("", scheme!='document' and link or parts[1], rect, relative=1)
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   414
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   415
def _do_link_line(i, t_off, tx):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   416
    xs = tx.XtraState
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   417
    leading = xs.style.leading
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   418
    y = xs.cur_y - i*leading - xs.f.fontSize/8.0 # 8.0 factor copied from para.py
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   419
    text = join(xs.lines[i][1])
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   420
    textlen = tx._canvas.stringWidth(text, tx._fontname, tx._fontsize)
2594
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   421
    _doLink(tx, xs.link, (t_off, y, t_off+textlen, y+leading))
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   422
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   423
def _do_post_text(i, t_off, tx):
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   424
    xs = tx.XtraState
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   425
    leading = xs.style.leading
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   426
    ff = 0.125*xs.f.fontSize
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   427
    y0 = xs.cur_y - i*leading
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   428
    y = y0 - ff
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   429
    ulc = None
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   430
    for x1,x2,c in xs.underlines:
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   431
        if c!=ulc:
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   432
            tx._canvas.setStrokeColor(c)
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   433
            ulc = c
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   434
        tx._canvas.line(t_off+x1, y, t_off+x2, y)
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   435
    xs.underlines = []
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   436
    xs.underline=0
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   437
    xs.underlineColor=None
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   438
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   439
    ys = y0 + 2*ff
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   440
    ulc = None
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   441
    for x1,x2,c in xs.strikes:
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   442
        if c!=ulc:
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   443
            tx._canvas.setStrokeColor(c)
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   444
            ulc = c
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   445
        tx._canvas.line(t_off+x1, ys, t_off+x2, ys)
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   446
    xs.strikes = []
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   447
    xs.strike=0
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   448
    xs.strikeColor=None
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   449
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   450
    yl = y + leading
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   451
    for x1,x2,link in xs.links:
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   452
        tx._canvas.line(t_off+x1, y, t_off+x2, y)
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   453
        _doLink(tx, link, (t_off+x1, y, t_off+x2, yl))
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   454
    xs.links = []
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   455
    xs.link=None
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   456
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   457
class Paragraph(Flowable):
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
   458
    """ Paragraph(text, style, bulletText=None, caseSensitive=1)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   459
        text a string of stuff to go into the paragraph.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   460
        style is a style definition as in reportlab.lib.styles.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   461
        bulletText is an optional bullet defintion.
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
   462
        caseSensitive set this to 0 if you want the markup tags and their attributes to be case-insensitive.
316
e15cf6a28eb8 Documentation fixes
rgbecker
parents: 302
diff changeset
   463
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   464
        This class is a flowable that can format a block of text
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   465
        into a paragraph with a given style.
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   466
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   467
        The paragraph Text can contain XML-like markup including the tags:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   468
        <b> ... </b> - bold
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   469
        <i> ... </i> - italics
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   470
        <u> ... </u> - underline
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   471
        <strike> ... </strike> - strike through
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   472
        <super> ... </super> - superscript
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   473
        <sub> ... </sub> - subscript
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   474
        <font name=fontfamily/fontname color=colorname size=float>
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   475
        <onDraw name=callable label="a label">
268
8414113fa500 more documentation changes
aaron_watters
parents: 253
diff changeset
   476
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   477
        The whole may be surrounded by <para> </para> tags
268
8414113fa500 more documentation changes
aaron_watters
parents: 253
diff changeset
   478
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   479
        It will also be able to handle any MathML specified Greek characters.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   480
    """
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   481
    def __init__(self, text, style, bulletText = None, frags=None, caseSensitive=1, encoding='utf8'):
2200
be0cfccc662a Fixed up tabs and whitespace in all source files
andy_robinson
parents: 2183
diff changeset
   482
        self.caseSensitive = caseSensitive
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   483
        self.encoding = encoding
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   484
        self._setup(text, style, bulletText, frags, cleanBlockQuotedText)
438
fa5d480207bc Preparing for cleanup
rgbecker
parents: 434
diff changeset
   485
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   486
    def __repr__(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   487
        import string
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   488
        n = self.__class__.__name__
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   489
        L = [n+"("]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   490
        keys = self.__dict__.keys()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   491
        for k in keys:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   492
            v = getattr(self, k)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   493
            rk = repr(k)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   494
            rv = repr(v)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   495
            rk = "  "+string.replace(rk, "\n", "\n  ")
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   496
            rv = "    "+string.replace(rv, "\n", "\n    ")
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   497
            L.append(rk)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   498
            L.append(rv)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   499
        L.append(") #"+n)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   500
        return string.join(L, "\n")
541
33de80b3655c added __repr__s and enhanced exception messages for debugging
aaron_watters
parents: 540
diff changeset
   501
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   502
    def _setup(self, text, style, bulletText, frags, cleaner):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   503
        if frags is None:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   504
            text = cleaner(text)
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
   505
            _parser.caseSensitive = self.caseSensitive
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   506
            style, frags, bulletTextFrags = _parser.parse(text,style)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   507
            if frags is None:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   508
                raise "xml parser error (%s) in paragraph beginning\n'%s'"\
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   509
                    % (_parser.errors[0],text[:min(30,len(text))])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   510
            if bulletTextFrags: bulletText = bulletTextFrags
279
e7d8b3631d5c Global sequencer put in the 'story builder'.
andy_robinson
parents: 268
diff changeset
   511
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   512
        #AR hack
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   513
        self.text = text
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   514
        self.frags = frags
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   515
        self.style = style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   516
        self.bulletText = bulletText
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   517
        self.debug = 0  #turn this on to see a pretty one with all the margins etc.
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   518
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   519
    def wrap(self, availWidth, availHeight):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   520
        # work out widths array for breaking
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   521
        self.width = availWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   522
        leftIndent = self.style.leftIndent
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   523
        first_line_width = availWidth - (leftIndent+self.style.firstLineIndent) - self.style.rightIndent
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   524
        later_widths = availWidth - leftIndent - self.style.rightIndent
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   525
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   526
        if self.style.wordWrap == 'CJK':
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   527
            #use Asian text wrap algorithm to break characters
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   528
            self.blPara = self.breakLinesCJK([first_line_width, later_widths])
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   529
        else:
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   530
            self.blPara = self.breakLines([first_line_width, later_widths])
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   531
        self.height = len(self.blPara.lines) * self.style.leading
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   532
        return (self.width, self.height)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   533
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   534
    def minWidth(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   535
        'Attempt to determine a minimum sensible width'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   536
        frags = self.frags
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   537
        nFrags= len(frags)
2467
5630a2b21a90 tables.py, paragraph.py: Gary Poster's layout improvement patch
rgbecker
parents: 2456
diff changeset
   538
        if not nFrags: return 0
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   539
        if nFrags==1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   540
            f = frags[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   541
            fS = f.fontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   542
            fN = f.fontName
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   543
            words = hasattr(f,'text') and split(f.text, ' ') or f.words
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   544
            func = lambda w, fS=fS, fN=fN: stringWidth(w,fN,fS)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   545
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   546
            words = _getFragWords(frags)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   547
            func  = lambda x: x[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   548
        return max(map(func,words))
954
bf9f434cb08a added minWidth method to Flowable, Paragraph
rgbecker
parents: 938
diff changeset
   549
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   550
    def _get_split_blParaFunc(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   551
        return self.blPara.kind==0 and _split_blParaSimple or _split_blParaHard
438
fa5d480207bc Preparing for cleanup
rgbecker
parents: 434
diff changeset
   552
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   553
    def split(self,availWidth, availHeight):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   554
        if len(self.frags)<=0: return []
212
b04e22acb4fa Splitting changes
rgbecker
parents: 208
diff changeset
   555
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   556
        #the split information is all inside self.blPara
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   557
        if not hasattr(self,'blPara'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   558
            self.wrap(availWidth,availHeight)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   559
        blPara = self.blPara
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   560
        style = self.style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   561
        leading = style.leading
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   562
        lines = blPara.lines
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   563
        n = len(lines)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   564
        s = int(availHeight/leading)
1737
a0ff4a2ac29e Fixed splitting bug
rgbecker
parents: 1683
diff changeset
   565
        if s<=1:
a0ff4a2ac29e Fixed splitting bug
rgbecker
parents: 1683
diff changeset
   566
            del self.blPara
a0ff4a2ac29e Fixed splitting bug
rgbecker
parents: 1683
diff changeset
   567
            return []
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   568
        if n<=s: return [self]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   569
        func = self._get_split_blParaFunc()
212
b04e22acb4fa Splitting changes
rgbecker
parents: 208
diff changeset
   570
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   571
        P1=self.__class__(None,style,bulletText=self.bulletText,frags=func(blPara,0,s))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   572
        #this is a major hack
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   573
        P1.blPara = ParaLines(kind=1,lines=blPara.lines[0:s],aH=availHeight,aW=availWidth)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   574
        P1._JustifyLast = 1
2529
dced304f8584 flowables.py: keepInFrame now truncates etc properly, doctemplate.py: fix handle_frameEnd
rgbecker
parents: 2467
diff changeset
   575
        P1._splitpara = 1
2561
a2409b6627e6 reportlab: added FlowablesAndImage
rgbecker
parents: 2557
diff changeset
   576
        P1.height = s*leading
a2409b6627e6 reportlab: added FlowablesAndImage
rgbecker
parents: 2557
diff changeset
   577
        P1.width = availWidth
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   578
        if style.firstLineIndent != 0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   579
            style = deepcopy(style)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   580
            style.firstLineIndent = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   581
        P2=self.__class__(None,style,bulletText=None,frags=func(blPara,s,n))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   582
        return [P1,P2]
212
b04e22acb4fa Splitting changes
rgbecker
parents: 208
diff changeset
   583
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   584
    def draw(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   585
        #call another method for historical reasons.  Besides, I
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   586
        #suspect I will be playing with alternate drawing routines
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   587
        #so not doing it here makes it easier to switch.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   588
        self.drawPara(self.debug)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   589
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   590
    def breakLines(self, width):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   591
        """
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   592
        Returns a broken line structure. There are two cases
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   593
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   594
        A) For the simple case of a single formatting input fragment the output is
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   595
            A fragment specifier with
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   596
                kind = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   597
                fontName, fontSize, leading, textColor
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   598
                lines=  A list of lines
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   599
                        Each line has two items.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   600
                        1) unused width in points
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   601
                        2) word list
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   602
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   603
        B) When there is more than one input formatting fragment the output is
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   604
            A fragment specifier with
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   605
                kind = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   606
                lines=  A list of fragments each having fields
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   607
                            extraspace (needed for justified)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   608
                            fontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   609
                            words=word list
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   610
                                each word is itself a fragment with
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   611
                                various settings
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   612
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   613
        This structure can be used to easily draw paragraphs with the various alignments.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   614
        You can supply either a single width or a list of widths; the latter will have its
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   615
        last item repeated until necessary. A 2-element list is useful when there is a
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   616
        different first line indent; a longer list could be created to facilitate custom wraps
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   617
        around irregular objects."""
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   618
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   619
        if type(width) <> ListType: maxWidths = [width]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   620
        else: maxWidths = width
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   621
        lines = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   622
        lineno = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   623
        style = self.style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   624
        fFontSize = float(style.fontSize)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   625
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   626
        #for bullets, work out width and ensure we wrap the right amount onto line one
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   627
        _handleBulletWidth(self.bulletText,style,maxWidths)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   628
2366
7dd247980b7d minor twitching on Indenter
rgbecker
parents: 2341
diff changeset
   629
        maxWidth = maxWidths[0]
539
14dd200244e2 Layout fixes; the text objects needed moves before & after and the bullet width
rgbecker
parents: 534
diff changeset
   630
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   631
        self.height = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   632
        frags = self.frags
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   633
        nFrags= len(frags)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   634
        if nFrags==1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   635
            f = frags[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   636
            fontSize = f.fontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   637
            fontName = f.fontName
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   638
            words = hasattr(f,'text') and split(f.text, ' ') or f.words
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   639
            spaceWidth = stringWidth(' ', fontName, fontSize, self.encoding)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   640
            cLine = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   641
            currentWidth = - spaceWidth   # hack to get around extra space for word 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   642
            for word in words:
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   643
                #this underscores my feeling that Unicode throughout would be easier!
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   644
                wordWidth = stringWidth(word, fontName, fontSize, self.encoding)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   645
                newWidth = currentWidth + spaceWidth + wordWidth
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   646
                if newWidth <= maxWidth or len(cLine) == 0:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   647
                    # fit one more on this line
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   648
                    cLine.append(word)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   649
                    currentWidth = newWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   650
                else:
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   651
                    if currentWidth > self.width: self.width = currentWidth
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   652
                    #end of line
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   653
                    lines.append((maxWidth - currentWidth, cLine))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   654
                    cLine = [word]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   655
                    currentWidth = wordWidth
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   656
                    lineno += 1
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   657
                    try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   658
                        maxWidth = maxWidths[lineno]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   659
                    except IndexError:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   660
                        maxWidth = maxWidths[-1]  # use the last one
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   661
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   662
            #deal with any leftovers on the final line
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   663
            if cLine!=[]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   664
                if currentWidth>self.width: self.width = currentWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   665
                lines.append((maxWidth - currentWidth, cLine))
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   666
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   667
            return f.clone(kind=0, lines=lines)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   668
        elif nFrags<=0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   669
            return ParaLines(kind=0, fontSize=style.fontSize, fontName=style.fontName,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   670
                            textColor=style.textColor, lines=[])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   671
        else:
2529
dced304f8584 flowables.py: keepInFrame now truncates etc properly, doctemplate.py: fix handle_frameEnd
rgbecker
parents: 2467
diff changeset
   672
            if hasattr(self,'blPara') and getattr(self,'_splitpara',0):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   673
                #NB this is an utter hack that awaits the proper information
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   674
                #preserving splitting algorithm
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   675
                return self.blPara
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   676
            n = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   677
            nSp = 0
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   678
            lineBreakPrev = False
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   679
            for w in _getFragWords(frags):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   680
                spaceWidth = stringWidth(' ',w[-1][0].fontName, w[-1][0].fontSize)
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   681
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   682
                if n==0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   683
                    currentWidth = -spaceWidth   # hack to get around extra space for word 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   684
                    words = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   685
                    maxSize = 0
496
bb47cf5c2739 Layout error fixes
rgbecker
parents: 494
diff changeset
   686
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   687
                wordWidth = w[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   688
                f = w[1][0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   689
                if wordWidth>0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   690
                    newWidth = currentWidth + spaceWidth + wordWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   691
                else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   692
                    newWidth = currentWidth
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   693
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   694
                #text to see if this frag is a line break. If it is and we will only act on it
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   695
                #if the current width is non-negative or the previous thing was a deliberate lineBreak
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   696
                lineBreak = hasattr(f,'lineBreak')
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   697
                endLine = (newWidth>maxWidth and n>0) or (lineBreak and (currentWidth>0 or lineBreakPrev))
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   698
                if not endLine:
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   699
                    lineBreakPrev = lineBreak
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   700
                    if lineBreak: continue      #throw it away
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   701
                    n += 1
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   702
                    maxSize = max(maxSize,f.fontSize)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   703
                    nText = w[1][1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   704
                    if words==[]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   705
                        g = f.clone()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   706
                        words = [g]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   707
                        g.text = nText
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   708
                    elif not _sameFrag(g,f):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   709
                        if currentWidth>0 and ((nText!='' and nText[0]!=' ') or hasattr(f,'cbDefn')):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   710
                            if hasattr(g,'cbDefn'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   711
                                i = len(words)-1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   712
                                while hasattr(words[i],'cbDefn'): i = i-1
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   713
                                words[i].text += ' '
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   714
                            else:
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   715
                                g.text += ' '
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   716
                            nSp += 1
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   717
                        g = f.clone()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   718
                        words.append(g)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   719
                        g.text = nText
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   720
                    else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   721
                        if nText!='' and nText[0]!=' ':
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   722
                            g.text += ' ' + nText
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   723
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   724
                    for i in w[2:]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   725
                        g = i[0].clone()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   726
                        g.text=i[1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   727
                        words.append(g)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   728
                        maxSize = max(maxSize,g.fontSize)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   729
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   730
                    currentWidth = newWidth
2663
927cc273c5a5 <br/> work in progress
andy
parents: 2646
diff changeset
   731
                else:  #either it won't fit, or it's a lineBreak tag
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   732
                    if lineBreak and not len(words):
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   733
                        g = f.clone()
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   734
                        del g.lineBreak
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   735
                        words.append(g)
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   736
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   737
                    if currentWidth>self.width: self.width = currentWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   738
                    #end of line
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   739
                    lines.append(FragLine(extraSpace=(maxWidth - currentWidth),wordCount=n,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   740
                                        words=words, fontSize=maxSize))
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   741
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   742
                    #start new line
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   743
                    lineno += 1
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   744
                    try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   745
                        maxWidth = maxWidths[lineno]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   746
                    except IndexError:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   747
                        maxWidth = maxWidths[-1]  # use the last one
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   748
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   749
                    lineBreakPrev = lineBreak
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   750
                    if lineBreak:
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   751
                        n = 0
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   752
                        continue
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   753
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   754
                    currentWidth = wordWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   755
                    n = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   756
                    maxSize = f.fontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   757
                    g = f.clone()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   758
                    words = [g]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   759
                    g.text = w[1][1]
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   760
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   761
                    for i in w[2:]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   762
                        g = i[0].clone()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   763
                        g.text=i[1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   764
                        words.append(g)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   765
                        maxSize = max(maxSize,g.fontSize)
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   766
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   767
            #deal with any leftovers on the final line
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   768
            if words<>[]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   769
                if currentWidth>self.width: self.width = currentWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   770
                lines.append(ParaLines(extraSpace=(maxWidth - currentWidth),wordCount=n,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   771
                                    words=words, fontSize=maxSize))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   772
            return ParaLines(kind=1, lines=lines)
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   773
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   774
        return lines
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   775
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   776
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   777
    def breakLinesCJK(self, width):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   778
        """Initially, the dumbest possible wrapping algorithm.
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   779
        Cannot handle font variations."""
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   780
2598
2dfd3107217c paragraph: fix misuse of style before setting in cjk breaklines
rgbecker
parents: 2594
diff changeset
   781
        style = self.style
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   782
        #for now we only handle one fragment.  Need to generalize this quickly.
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   783
        if len(self.frags) > 1:
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   784
            raise ValueError('CJK Wordwrap can only handle one fragment per paragraph for now')
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   785
        elif len(self.frags) == 0:
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   786
            return ParaLines(kind=0, fontSize=style.fontSize, fontName=style.fontName,
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   787
                            textColor=style.textColor, lines=[])
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   788
        f = self.frags[0]
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   789
        if 1 and hasattr(self,'blPara') and getattr(self,'_splitpara',0):
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   790
            #NB this is an utter hack that awaits the proper information
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   791
            #preserving splitting algorithm
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   792
            return f.clone(kind=0, lines=self.blPara.lines)
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   793
        if type(width)!=ListType: maxWidths = [width]
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   794
        else: maxWidths = width
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   795
        lines = []
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   796
        lineno = 0
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   797
        fFontSize = float(style.fontSize)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   798
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   799
        #for bullets, work out width and ensure we wrap the right amount onto line one
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   800
        _handleBulletWidth(self.bulletText, style, maxWidths)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   801
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   802
        maxWidth = maxWidths[0]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   803
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   804
        self.height = 0
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   805
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   806
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   807
        f = self.frags[0]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   808
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   809
        if hasattr(f,'text'):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   810
            text = f.text
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   811
        else:
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   812
            text = ''.join(getattr(f,'words',[]))
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   813
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   814
        from reportlab.lib.textsplit import wordSplit
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   815
        lines = wordSplit(text, maxWidths[0], f.fontName, f.fontSize)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   816
        #the paragraph drawing routine assumes multiple frags per line, so we need an
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   817
        #extra list like this
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   818
        #  [space, [text]]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   819
        #
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   820
        wrappedLines = [(sp, [line]) for (sp, line) in lines]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   821
        return f.clone(kind=0, lines=wrappedLines)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   822
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   823
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   824
    def beginText(self, x, y):
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   825
        return self.canv.beginText(x, y)
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   826
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   827
    def drawPara(self,debug=0):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   828
        """Draws a paragraph according to the given style.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   829
        Returns the final y position at the bottom. Not safe for
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   830
        paragraphs without spaces e.g. Japanese; wrapping
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   831
        algorithm will go infinite."""
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   832
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   833
        #stash the key facts locally for speed
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   834
        canvas = self.canv
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   835
        style = self.style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   836
        blPara = self.blPara
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   837
        lines = blPara.lines
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   838
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   839
        #work out the origin for line 1
2182
a8b905569feb Underline alignment fix from Marc Stober
rgbecker
parents: 2172
diff changeset
   840
        leftIndent = style.leftIndent
a8b905569feb Underline alignment fix from Marc Stober
rgbecker
parents: 2172
diff changeset
   841
        cur_x = leftIndent
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   842
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   843
        #if has a background, draw it
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   844
        if style.backColor:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   845
            canvas.saveState()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   846
            canvas.setFillColor(style.backColor)
2182
a8b905569feb Underline alignment fix from Marc Stober
rgbecker
parents: 2172
diff changeset
   847
            canvas.rect(leftIndent,
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   848
                        0,
2367
ff834913c5e2 fix backcolour bug
rgbecker
parents: 2366
diff changeset
   849
                        self.width - (leftIndent+style.rightIndent),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   850
                        self.height,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   851
                        fill=1,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   852
                        stroke=0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   853
            canvas.restoreState()
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   854
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   855
        if debug:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   856
            # This boxes and shades stuff to show how the paragraph
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   857
            # uses its space.  Useful for self-documentation so
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   858
            # the debug code stays!
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   859
            # box the lot
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   860
            canvas.rect(0, 0, self.width, self.height)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   861
            #left and right margins
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   862
            canvas.saveState()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   863
            canvas.setFillColor(Color(0.9,0.9,0.9))
2182
a8b905569feb Underline alignment fix from Marc Stober
rgbecker
parents: 2172
diff changeset
   864
            canvas.rect(0, 0, leftIndent, self.height)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   865
            canvas.rect(self.width - style.rightIndent, 0, style.rightIndent, self.height)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   866
            # shade above and below
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   867
            canvas.setFillColor(Color(1.0,1.0,0.0))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   868
            canvas.restoreState()
2182
a8b905569feb Underline alignment fix from Marc Stober
rgbecker
parents: 2172
diff changeset
   869
            #self.drawLine(x + leftIndent, y, x + leftIndent, cur_y)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   870
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   871
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   872
        nLines = len(lines)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   873
        bulletText = self.bulletText
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   874
        if nLines > 0:
2557
d84c18fb377f added _offsets handling to paragraph for flow around on left side
rgbecker
parents: 2529
diff changeset
   875
            _offsets = getattr(self,'_offsets',[0])
d84c18fb377f added _offsets handling to paragraph for flow around on left side
rgbecker
parents: 2529
diff changeset
   876
            _offsets += (nLines-len(_offsets))*[_offsets[-1]]
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   877
            canvas.saveState()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   878
            #canvas.addLiteral('%% %s.drawPara' % _className(self))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   879
            alignment = style.alignment
2557
d84c18fb377f added _offsets handling to paragraph for flow around on left side
rgbecker
parents: 2529
diff changeset
   880
            offset = style.firstLineIndent+_offsets[0]
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   881
            lim = nLines-1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   882
            noJustifyLast = not (hasattr(self,'_JustifyLast') and self._JustifyLast)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   883
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   884
            if blPara.kind==0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   885
                if alignment == TA_LEFT:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   886
                    dpl = _leftDrawParaLine
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   887
                elif alignment == TA_CENTER:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   888
                    dpl = _centerDrawParaLine
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   889
                elif self.style.alignment == TA_RIGHT:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   890
                    dpl = _rightDrawParaLine
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   891
                elif self.style.alignment == TA_JUSTIFY:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   892
                    dpl = _justifyDrawParaLine
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   893
                f = blPara
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   894
                cur_y = self.height - f.fontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   895
                if bulletText <> None:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   896
                    offset = _drawBullet(canvas,offset,cur_y,bulletText,style)
212
b04e22acb4fa Splitting changes
rgbecker
parents: 208
diff changeset
   897
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   898
                #set up the font etc.
2400
f47d5c6d8fcd paragraph.py: use canvas.setFillColor
rgbecker
parents: 2367
diff changeset
   899
                canvas.setFillColor(f.textColor)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   900
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   901
                tx = self.beginText(cur_x, cur_y)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   902
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   903
                #now the font for the rest of the paragraph
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   904
                tx.setFont(f.fontName, f.fontSize, style.leading)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   905
                t_off = dpl( tx, offset, lines[0][0], lines[0][1], noJustifyLast and nLines==1)
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   906
                if f.underline or f.link or f.strike:
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   907
                    xs = tx.XtraState=ABag()
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   908
                    xs.cur_y = cur_y
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   909
                    xs.f = f
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   910
                    xs.style = style
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   911
                    xs.lines = lines
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   912
                    xs.underlines=[]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   913
                    xs.underlineColor=None
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   914
                    xs.strikes=[]
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   915
                    xs.strikeColor=None
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   916
                    xs.links=[]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   917
                    xs.link=f.link
2456
afa6ef178273 paragraph.py: added proper undeerline color
rgbecker
parents: 2445
diff changeset
   918
                    canvas.setStrokeColor(f.textColor)
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   919
                    if f.underline: _do_under_line(0, t_off+leftIndent, tx)
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   920
                    if f.strike: _do_under_line(0, t_off+leftIndent, tx, lm=0.125)
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   921
                    if f.link: _do_link_line(0, t_off+leftIndent, tx)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   922
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   923
                    #now the middle of the paragraph, aligned with the left margin which is our origin.
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   924
                    for i in xrange(1, nLines):
2557
d84c18fb377f added _offsets handling to paragraph for flow around on left side
rgbecker
parents: 2529
diff changeset
   925
                        t_off = dpl( tx, _offsets[i], lines[i][0], lines[i][1], noJustifyLast and i==lim)
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   926
                        if f.underline: _do_under_line(i, t_off+leftIndent, tx)
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   927
                        if f.strike: _do_under_line(i, t_off+leftIndent, tx, lm=0.125)
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   928
                        if f.link: _do_link_line(i, t_off+leftIndent, tx)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   929
                else:
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   930
                    for i in xrange(1, nLines):
2557
d84c18fb377f added _offsets handling to paragraph for flow around on left side
rgbecker
parents: 2529
diff changeset
   931
                        dpl( tx, _offsets[i], lines[i][0], lines[i][1], noJustifyLast and i==lim)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   932
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   933
                f = lines[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   934
                cur_y = self.height - f.fontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   935
                # default?
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   936
                dpl = _leftDrawParaLineX
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   937
                if bulletText <> None:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   938
                    offset = _drawBullet(canvas,offset,cur_y,bulletText,style)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   939
                if alignment == TA_LEFT:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   940
                    dpl = _leftDrawParaLineX
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   941
                elif alignment == TA_CENTER:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   942
                    dpl = _centerDrawParaLineX
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   943
                elif self.style.alignment == TA_RIGHT:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   944
                    dpl = _rightDrawParaLineX
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   945
                elif self.style.alignment == TA_JUSTIFY:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   946
                    dpl = _justifyDrawParaLineX
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   947
                else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   948
                    raise ValueError, "bad align %s" % repr(alignment)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   949
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   950
                #set up the font etc.
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   951
                tx = self.beginText(cur_x, cur_y)
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   952
                xs = tx.XtraState=ABag()
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   953
                xs.textColor=None
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   954
                xs.rise=0
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   955
                xs.underline=0
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   956
                xs.underlines=[]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   957
                xs.underlineColor=None
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   958
                xs.strike=0
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   959
                xs.strikes=[]
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   960
                xs.strikeColor=None
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   961
                xs.links=[]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   962
                xs.link=None
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   963
                tx.setLeading(style.leading)
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   964
                xs.cur_y = cur_y
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   965
                xs.f = f
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   966
                xs.style = style
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   967
                #f = lines[0].words[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   968
                #tx._setFont(f.fontName, f.fontSize)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   969
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   970
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   971
                tx._fontname,tx._fontsize = None, None
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   972
                t_off = dpl( tx, offset, lines[0], noJustifyLast and nLines==1)
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   973
                _do_post_text(0, t_off+leftIndent, tx)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   974
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   975
                #now the middle of the paragraph, aligned with the left margin which is our origin.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   976
                for i in range(1, nLines):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   977
                    f = lines[i]
2557
d84c18fb377f added _offsets handling to paragraph for flow around on left side
rgbecker
parents: 2529
diff changeset
   978
                    t_off = dpl( tx, _offsets[i], f, noJustifyLast and i==lim)
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   979
                    _do_post_text(i, t_off+leftIndent, tx)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   980
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   981
            canvas.drawText(tx)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   982
            canvas.restoreState()
284
eabeb5f4e851 Added UserDocTemplate class, and paragraph.getPlainText()
andy_robinson
parents: 279
diff changeset
   983
2172
2740f571bd24 Fixes to cope with rml2pdf weirds
rgbecker
parents: 1992
diff changeset
   984
    def getPlainText(self,identify=None):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   985
        """Convenience function for templates which want access
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   986
        to the raw text, without XML tags. """
2172
2740f571bd24 Fixes to cope with rml2pdf weirds
rgbecker
parents: 1992
diff changeset
   987
        frags = getattr(self,'frags',None)
2740f571bd24 Fixes to cope with rml2pdf weirds
rgbecker
parents: 1992
diff changeset
   988
        if frags:
2740f571bd24 Fixes to cope with rml2pdf weirds
rgbecker
parents: 1992
diff changeset
   989
            plains = []
2740f571bd24 Fixes to cope with rml2pdf weirds
rgbecker
parents: 1992
diff changeset
   990
            for frag in frags:
2445
5e52f2209426 minor fix to allow getPlaintext on more paragraphs
andy
parents: 2400
diff changeset
   991
                if hasattr(frag, 'text'):
5e52f2209426 minor fix to allow getPlaintext on more paragraphs
andy
parents: 2400
diff changeset
   992
                    plains.append(frag.text)
2172
2740f571bd24 Fixes to cope with rml2pdf weirds
rgbecker
parents: 1992
diff changeset
   993
            return join(plains, '')
2740f571bd24 Fixes to cope with rml2pdf weirds
rgbecker
parents: 1992
diff changeset
   994
        elif identify:
2740f571bd24 Fixes to cope with rml2pdf weirds
rgbecker
parents: 1992
diff changeset
   995
            text = getattr(self,'text',None)
2740f571bd24 Fixes to cope with rml2pdf weirds
rgbecker
parents: 1992
diff changeset
   996
            if text is None: text = repr(self)
2740f571bd24 Fixes to cope with rml2pdf weirds
rgbecker
parents: 1992
diff changeset
   997
            return text
2740f571bd24 Fixes to cope with rml2pdf weirds
rgbecker
parents: 1992
diff changeset
   998
        else:
2740f571bd24 Fixes to cope with rml2pdf weirds
rgbecker
parents: 1992
diff changeset
   999
            return ''
302
960659f9cb5c Fixes to splitting code
rgbecker
parents: 284
diff changeset
  1000
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1001
    def getActualLineWidths0(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1002
        """Convenience function; tells you how wide each line
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1003
        actually is.  For justified styles, this will be
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1004
        the same as the wrap width; for others it might be
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1005
        useful for seeing if paragraphs will fit in spaces."""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1006
        assert hasattr(self, 'width'), "Cannot call this method before wrap()"
1752
0bdc6bd413ad Attempt at fixing getActualLineWidths0
rgbecker
parents: 1737
diff changeset
  1007
        if self.blPara.kind:
0bdc6bd413ad Attempt at fixing getActualLineWidths0
rgbecker
parents: 1737
diff changeset
  1008
            func = lambda frag, w=self.width: w - frag.extraSpace
0bdc6bd413ad Attempt at fixing getActualLineWidths0
rgbecker
parents: 1737
diff changeset
  1009
        else:
0bdc6bd413ad Attempt at fixing getActualLineWidths0
rgbecker
parents: 1737
diff changeset
  1010
            func = lambda frag, w=self.width: w - frag[0]
0bdc6bd413ad Attempt at fixing getActualLineWidths0
rgbecker
parents: 1737
diff changeset
  1011
        return map(func,self.blPara.lines)
497
63f575fc1170 Added experimental method getActualLineWidths0
andy_robinson
parents: 496
diff changeset
  1012
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1013
if __name__=='__main__':    #NORUNTESTS
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1014
    def dumpParagraphLines(P):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1015
        print 'dumpParagraphLines(<Paragraph @ %d>)' % id(P)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1016
        lines = P.blPara.lines
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1017
        n =len(lines)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1018
        for l in range(n):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1019
            line = lines[l]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1020
            if hasattr(line,'words'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1021
                words = line.words
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1022
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1023
                words = line[1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1024
            nwords = len(words)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1025
            print 'line%d: %d(%s)\n  ' % (l,nwords,str(getattr(line,'wordCount','Unknown'))),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1026
            for w in range(nwords):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1027
                print "%d:'%s'"%(w,getattr(words[w],'text',words[w])),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1028
            print
302
960659f9cb5c Fixes to splitting code
rgbecker
parents: 284
diff changeset
  1029
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1030
    def dumpParagraphFrags(P):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1031
        print 'dumpParagraphFrags(<Paragraph @ %d>) minWidth() = %.2f' % (id(P), P.minWidth())
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1032
        frags = P.frags
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1033
        n =len(frags)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1034
        for l in range(n):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1035
            print "frag%d: '%s'" % (l, frags[l].text)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
  1036
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1037
        l = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1038
        cum = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1039
        for W in _getFragWords(frags):
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
  1040
            cum += W[0]
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1041
            print "fragword%d: cum=%3d size=%d" % (l, cum, W[0]),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1042
            for w in W[1:]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1043
                print "'%s'" % w[1],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1044
            print
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
  1045
            l += 1
434
257af3109bf4 Various brutal changes to paragraph, canvas and textobject for speed/size
rgbecker
parents: 383
diff changeset
  1046
954
bf9f434cb08a added minWidth method to Flowable, Paragraph
rgbecker
parents: 938
diff changeset
  1047
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1048
    from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1049
    import sys
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1050
    TESTS = sys.argv[1:]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1051
    if TESTS==[]: TESTS=['4']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1052
    def flagged(i,TESTS=TESTS):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1053
        return 'all' in TESTS or '*' in TESTS or str(i) in TESTS
954
bf9f434cb08a added minWidth method to Flowable, Paragraph
rgbecker
parents: 938
diff changeset
  1054
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1055
    styleSheet = getSampleStyleSheet()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1056
    B = styleSheet['BodyText']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1057
    style = ParagraphStyle("discussiontext", parent=B)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1058
    style.fontName= 'Helvetica'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1059
    if flagged(1):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1060
        text='''The <font name=courier color=green>CMYK</font> or subtractive method follows the way a printer
302
960659f9cb5c Fixes to splitting code
rgbecker
parents: 284
diff changeset
  1061
mixes three pigments (cyan, magenta, and yellow) to form colors.
960659f9cb5c Fixes to splitting code
rgbecker
parents: 284
diff changeset
  1062
Because mixing chemicals is more difficult than combining light there
960659f9cb5c Fixes to splitting code
rgbecker
parents: 284
diff changeset
  1063
is a fourth parameter for darkness.  For example a chemical
960659f9cb5c Fixes to splitting code
rgbecker
parents: 284
diff changeset
  1064
combination of the <font name=courier color=green>CMY</font> pigments generally never makes a perfect
960659f9cb5c Fixes to splitting code
rgbecker
parents: 284
diff changeset
  1065
black -- instead producing a muddy color -- so, to get black printers
960659f9cb5c Fixes to splitting code
rgbecker
parents: 284
diff changeset
  1066
don't use the <font name=courier color=green>CMY</font> pigments but use a direct black ink.  Because
960659f9cb5c Fixes to splitting code
rgbecker
parents: 284
diff changeset
  1067
<font name=courier color=green>CMYK</font> maps more directly to the way printer hardware works it may
434
257af3109bf4 Various brutal changes to paragraph, canvas and textobject for speed/size
rgbecker
parents: 383
diff changeset
  1068
be the case that &amp;| &amp; | colors specified in <font name=courier color=green>CMYK</font> will provide better fidelity
302
960659f9cb5c Fixes to splitting code
rgbecker
parents: 284
diff changeset
  1069
and better control when printed.
960659f9cb5c Fixes to splitting code
rgbecker
parents: 284
diff changeset
  1070
'''
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1071
        P=Paragraph(text,style)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1072
        dumpParagraphFrags(P)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1073
        aW, aH = 456.0, 42.8
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1074
        w,h = P.wrap(aW, aH)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1075
        dumpParagraphLines(P)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1076
        S = P.split(aW,aH)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1077
        for s in S:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1078
            s.wrap(aW,aH)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1079
            dumpParagraphLines(s)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1080
            aH = 500
488
a270e8b45200 Added J Alet's bug case
rgbecker
parents: 471
diff changeset
  1081
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1082
    if flagged(2):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1083
        P=Paragraph("""Price<super><font color="red">*</font></super>""", styleSheet['Normal'])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1084
        dumpParagraphFrags(P)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1085
        w,h = P.wrap(24, 200)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1086
        dumpParagraphLines(P)
521
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
  1087
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1088
    if flagged(3):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1089
        text = """Dieses Kapitel bietet eine schnelle <b><font color=red>Programme :: starten</font></b>
521
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
  1090
<onDraw name=myIndex label="Programme :: starten">
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
  1091
<b><font color=red>Eingabeaufforderung :: (&gt;&gt;&gt;)</font></b>
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
  1092
<onDraw name=myIndex label="Eingabeaufforderung :: (&gt;&gt;&gt;)">
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
  1093
<b><font color=red>&gt;&gt;&gt; (Eingabeaufforderung)</font></b>
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
  1094
<onDraw name=myIndex label="&gt;&gt;&gt; (Eingabeaufforderung)">
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
  1095
Einf&#xfc;hrung in Python <b><font color=red>Python :: Einf&#xfc;hrung</font></b>
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
  1096
<onDraw name=myIndex label="Python :: Einf&#xfc;hrung">.
521
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
  1097
Das Ziel ist, die grundlegenden Eigenschaften von Python darzustellen, ohne
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
  1098
sich zu sehr in speziellen Regeln oder Details zu verstricken. Dazu behandelt
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
  1099
dieses Kapitel kurz die wesentlichen Konzepte wie Variablen, Ausdr&#xfc;cke,
521
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
  1100
Kontrollfluss, Funktionen sowie Ein- und Ausgabe. Es erhebt nicht den Anspruch,
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
  1101
umfassend zu sein."""
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1102
        P=Paragraph(text, styleSheet['Code'])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1103
        dumpParagraphFrags(P)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1104
        w,h = P.wrap(6*72, 9.7*72)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1105
        dumpParagraphLines(P)
551
21b8a2cb8c8b Hack to fix Dinu's problem
rgbecker
parents: 549
diff changeset
  1106
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1107
    if flagged(4):
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
  1108
        text='''Die eingebaute Funktion <font name=Courier>range(i, j [, stride])</font><onDraw name=myIndex label="eingebaute Funktionen::range()"><onDraw name=myIndex label="range() (Funktion)"><onDraw name=myIndex label="Funktionen::range()"> erzeugt eine Liste von Ganzzahlen und f&#xfc;llt sie mit Werten <font name=Courier>k</font>, f&#xfc;r die gilt: <font name=Courier>i &lt;= k &lt; j</font>. Man kann auch eine optionale Schrittweite angeben. Die eingebaute Funktion <font name=Courier>xrange()</font><onDraw name=myIndex label="eingebaute Funktionen::xrange()"><onDraw name=myIndex label="xrange() (Funktion)"><onDraw name=myIndex label="Funktionen::xrange()"> erf&#xfc;llt einen &#xe4;hnlichen Zweck, gibt aber eine unver&#xe4;nderliche Sequenz vom Typ <font name=Courier>XRangeType</font><onDraw name=myIndex label="XRangeType"> zur&#xfc;ck. Anstatt alle Werte in der Liste abzuspeichern, berechnet diese Liste ihre Werte, wann immer sie angefordert werden. Das ist sehr viel speicherschonender, wenn mit sehr langen Listen von Ganzzahlen gearbeitet wird. <font name=Courier>XRangeType</font> kennt eine einzige Methode, <font name=Courier>s.tolist()</font><onDraw name=myIndex label="XRangeType::tolist() (Methode)"><onDraw name=myIndex label="s.tolist() (Methode)"><onDraw name=myIndex label="Methoden::s.tolist()">, die seine Werte in eine Liste umwandelt.'''
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1109
        aW = 420
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1110
        aH = 64.4
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1111
        P=Paragraph(text, B)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1112
        dumpParagraphFrags(P)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1113
        w,h = P.wrap(aW,aH)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1114
        print 'After initial wrap',w,h
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1115
        dumpParagraphLines(P)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1116
        S = P.split(aW,aH)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1117
        dumpParagraphFrags(S[0])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1118
        w0,h0 = S[0].wrap(aW,aH)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1119
        print 'After split wrap',w0,h0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1120
        dumpParagraphLines(S[0])
683
fbd2b18742a5 Added test 5
rgbecker
parents: 681
diff changeset
  1121
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1122
    if flagged(5):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1123
        text = '<para> %s <![CDATA[</font></b>& %s < >]]></para>' % (chr(163),chr(163))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1124
        P=Paragraph(text, styleSheet['Code'])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1125
        dumpParagraphFrags(P)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1126
        w,h = P.wrap(6*72, 9.7*72)
1737
a0ff4a2ac29e Fixed splitting bug
rgbecker
parents: 1683
diff changeset
  1127
        dumpParagraphLines(P)
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
  1128
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
  1129
    if flagged(6):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
  1130
        for text in ['''Here comes <FONT FACE="Helvetica" SIZE="14pt">Helvetica 14</FONT> with <STRONG>strong</STRONG> <EM>emphasis</EM>.''',
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
  1131
                     '''Here comes <font face="Helvetica" size="14pt">Helvetica 14</font> with <Strong>strong</Strong> <em>emphasis</em>.''',
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
  1132
                     '''Here comes <font face="Courier" size="3cm">Courier 3cm</font> and normal again.''',
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
  1133
                     ]:
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
  1134
            P=Paragraph(text, styleSheet['Normal'], caseSensitive=0)
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
  1135
            dumpParagraphFrags(P)
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
  1136
            w,h = P.wrap(6*72, 9.7*72)
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
  1137
            dumpParagraphLines(P)
2200
be0cfccc662a Fixed up tabs and whitespace in all source files
andy_robinson
parents: 2183
diff changeset
  1138
1945
1360994d86d7 added testcase
rgbecker
parents: 1940
diff changeset
  1139
    if flagged(7):
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
  1140
        text = """<para align="CENTER" fontSize="24" leading="30"><b>Generated by:</b>Dilbert</para>"""
1945
1360994d86d7 added testcase
rgbecker
parents: 1940
diff changeset
  1141
        P=Paragraph(text, styleSheet['Code'])
1360994d86d7 added testcase
rgbecker
parents: 1940
diff changeset
  1142
        dumpParagraphFrags(P)
1360994d86d7 added testcase
rgbecker
parents: 1940
diff changeset
  1143
        w,h = P.wrap(6*72, 9.7*72)
1360994d86d7 added testcase
rgbecker
parents: 1940
diff changeset
  1144
        dumpParagraphLines(P)