src/reportlab/platypus/paragraph.py
author robin <robin@reportlab.com>
Fri, 23 Mar 2018 16:02:08 +0000
changeset 4389 61a7f0840d00
parent 4387 c9accf85d669
child 4409 e1546608f841
permissions -rw-r--r--
more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4330
617ffa6bbdc8 changes for release 3.4.0
robin <robin@reportlab.com>
parents: 4316
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2017
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 488
diff changeset
     2
#see license.txt for license details
4370
823a8c33ce43 fix history urls contribution by Ben Weiner <ben@readingtype.org.uk>; version-->3.4.17
robin <robin@reportlab.com>
parents: 4367
diff changeset
     3
#history https://bitbucket.org/rptlab/reportlab/history-node/tip/src/reportlab/platypus/paragraph.py
4252
fe660f227cac changes for release 3.3.0
robin
parents: 4231
diff changeset
     4
__version__='3.3.0'
3032
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 3031
diff changeset
     5
__doc__='''The standard paragraph implementation'''
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3721
diff changeset
     6
from string import whitespace
539
14dd200244e2 Layout fixes; the text objects needed moves before & after and the bullet width
rgbecker
parents: 534
diff changeset
     7
from operator import truth
3547
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
     8
from unicodedata import category
2883
212d93981b3c paragraph.py: use proper ascent/descent info
rgbecker
parents: 2882
diff changeset
     9
from reportlab.pdfbase.pdfmetrics import stringWidth, getFont, getAscentDescent
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    10
from reportlab.platypus.paraparser import ParaParser, _PCT, _num as _parser_num, _re_us_value
279
e7d8b3631d5c Global sequencer put in the 'story builder'.
andy_robinson
parents: 268
diff changeset
    11
from reportlab.platypus.flowables import Flowable
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
    12
from reportlab.lib.colors import Color
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
    13
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
3042
2ae512e69843 Implemented variable padding for platypus paragraphs.
jonas
parents: 3032
diff changeset
    14
from reportlab.lib.geomutils import normalizeTRBL
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
    15
from reportlab.lib.textsplit import wordSplit, ALL_CANNOT_START
212
b04e22acb4fa Splitting changes
rgbecker
parents: 208
diff changeset
    16
from copy import deepcopy
518
5be3fcb26c78 Semantic Name changes
rgbecker
parents: 516
diff changeset
    17
from reportlab.lib.abag import ABag
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    18
from reportlab.rl_config import platypus_link_underline, decimalSymbol, _FUZZ, paraFontSizeHeightOffset, \
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    19
                                strikeGap, underlineGap
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    20
from reportlab.lib.utils import _className, isBytes, unicodeT, bytesT, isStr
3781
df8b57380768 import from reportlab.lib.lib.rl_accel
robin
parents: 3761
diff changeset
    21
from reportlab.lib.rl_accel import sameFrag
4367
9960d82643bf remove ascii, cmp & xrange builtins abuse; version-->3.4.15
robin <robin@reportlab.com>
parents: 4342
diff changeset
    22
from reportlab import xrange
2594
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
    23
import re
4135
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
    24
from types import MethodType
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    25
3799
9e42094b0298 paragraph.py: move towards no decoding/encoding
robin
parents: 3781
diff changeset
    26
#on UTF8/py33 branch, split and strip must be unicode-safe!
3022
4bbfeb0709ea reportlab: add Dirk Holtwick inspired split to paragraph.py
rgbecker
parents: 3003
diff changeset
    27
#thanks to Dirk Holtwick for helpful discussions/insight
4bbfeb0709ea reportlab: add Dirk Holtwick inspired split to paragraph.py
rgbecker
parents: 3003
diff changeset
    28
#on this one
3493
cff04ae591d7 paragraph.py: fix up some special cases for whitespace
rgbecker
parents: 3492
diff changeset
    29
_wsc = ''.join((
3761
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    30
    u'\u0009',  # HORIZONTAL TABULATION
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    31
    u'\u000A',  # LINE FEED
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    32
    u'\u000B',  # VERTICAL TABULATION
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    33
    u'\u000C',  # FORM FEED
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    34
    u'\u000D',  # CARRIAGE RETURN
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    35
    u'\u001C',  # FILE SEPARATOR
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    36
    u'\u001D',  # GROUP SEPARATOR
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    37
    u'\u001E',  # RECORD SEPARATOR
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    38
    u'\u001F',  # UNIT SEPARATOR
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    39
    u'\u0020',  # SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    40
    u'\u0085',  # NEXT LINE
3022
4bbfeb0709ea reportlab: add Dirk Holtwick inspired split to paragraph.py
rgbecker
parents: 3003
diff changeset
    41
    #u'\u00A0', # NO-BREAK SPACE
3761
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    42
    u'\u1680',  # OGHAM SPACE MARK
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    43
    u'\u2000',  # EN QUAD
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    44
    u'\u2001',  # EM QUAD
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    45
    u'\u2002',  # EN SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    46
    u'\u2003',  # EM SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    47
    u'\u2004',  # THREE-PER-EM SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    48
    u'\u2005',  # FOUR-PER-EM SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    49
    u'\u2006',  # SIX-PER-EM SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    50
    u'\u2007',  # FIGURE SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    51
    u'\u2008',  # PUNCTUATION SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    52
    u'\u2009',  # THIN SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    53
    u'\u200A',  # HAIR SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    54
    u'\u200B',  # ZERO WIDTH SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    55
    u'\u2028',  # LINE SEPARATOR
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    56
    u'\u2029',  # PARAGRAPH SEPARATOR
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    57
    u'\u202F',  # NARROW NO-BREAK SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    58
    u'\u205F',  # MEDIUM MATHEMATICAL SPACE
7c6245b62827 paragraph.py: python-3.3 allows u prefix
robin
parents: 3759
diff changeset
    59
    u'\u3000',  # IDEOGRAPHIC SPACE
3493
cff04ae591d7 paragraph.py: fix up some special cases for whitespace
rgbecker
parents: 3492
diff changeset
    60
    ))
cff04ae591d7 paragraph.py: fix up some special cases for whitespace
rgbecker
parents: 3492
diff changeset
    61
_wsc_re_split=re.compile('[%s]+'% re.escape(_wsc)).split
4135
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
    62
_wsc_end_search=re.compile('[%s]+$'% re.escape(_wsc)).search
3022
4bbfeb0709ea reportlab: add Dirk Holtwick inspired split to paragraph.py
rgbecker
parents: 3003
diff changeset
    63
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    64
def _usConv(s, vMap, default=None):
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    65
    '''convert a strike/underline distance to a number'''
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    66
    if isStr(s):
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    67
        s = s.strip()
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    68
        if s:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    69
            m = _re_us_value.match(s)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    70
            if m:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    71
                return float(m.group(1))*vMap[m.group(2)]
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    72
            else:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    73
                return _parser_num(s,allowRelative=False)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    74
        elif default:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    75
            return default
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    76
    return s
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
    77
2898
71cc316046ff paragraph.py: fix longstanding split bug
rgbecker
parents: 2894
diff changeset
    78
def split(text, delim=None):
3835
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3799
diff changeset
    79
    if isBytes(text): text = text.decode('utf8')
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3799
diff changeset
    80
    if delim is not None and isBytes(delim): delim = delim.decode('utf8')
3882
a74c1b4f7940 paragraph.py: fix 3.3 only code
robin
parents: 3835
diff changeset
    81
    return [uword for uword in (_wsc_re_split(text) if delim is None and u'\xa0' in text else text.split(delim))]
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    82
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    83
def strip(text):
3835
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3799
diff changeset
    84
    if isBytes(text): text = text.decode('utf8')
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3721
diff changeset
    85
    return text.strip(_wsc)
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
    86
518
5be3fcb26c78 Semantic Name changes
rgbecker
parents: 516
diff changeset
    87
class ParaLines(ABag):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    88
    """
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    89
    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
    90
        kind=0  Simple
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    91
        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
    92
        lines   [(extraSpace1,words1),....,(extraspaceN,wordsN)]
521
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
    93
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    94
        kind==1 Complex
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    95
        lines   [FragLine1,...,FragLineN]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
    96
    """
521
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
    97
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
    98
class FragLine(ABag):
3031
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 3027
diff changeset
    99
    """
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 3027
diff changeset
   100
    class FragLine contains a styled line (ie a line with more than one style)::
521
e09fc89a6bb3 Cosmetic changes
rgbecker
parents: 519
diff changeset
   101
3031
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 3027
diff changeset
   102
        extraSpace  unused space for justification only
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 3027
diff changeset
   103
        wordCount   1+spaces in line for justification purposes
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 3027
diff changeset
   104
        words       [ParaFrags] style text lumps to be concatenated together
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 3027
diff changeset
   105
        fontSize    maximum fontSize seen on the line; not used at present,
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 3027
diff changeset
   106
                    but could be used for line spacing.
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   107
    """
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   108
539
14dd200244e2 Layout fixes; the text objects needed moves before & after and the bullet width
rgbecker
parents: 534
diff changeset
   109
def _lineClean(L):
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3721
diff changeset
   110
    return ' '.join(list(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
   111
438
fa5d480207bc Preparing for cleanup
rgbecker
parents: 434
diff changeset
   112
def cleanBlockQuotedText(text,joiner=' '):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   113
    """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
   114
    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
   115
    (hopefully) the paragraph the user intended originally."""
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
   116
    L=list(filter(truth,list(map(_lineClean, split(text, '\n')))))
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3721
diff changeset
   117
    return joiner.join(L)
539
14dd200244e2 Layout fixes; the text objects needed moves before & after and the bullet width
rgbecker
parents: 534
diff changeset
   118
14dd200244e2 Layout fixes; the text objects needed moves before & after and the bullet width
rgbecker
parents: 534
diff changeset
   119
def setXPos(tx,dx):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   120
    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
   121
        tx.setXPos(dx)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   122
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   123
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
   124
    setXPos(tx,offset)
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3721
diff changeset
   125
    tx._textOut(' '.join(words),1)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   126
    setXPos(tx,-offset)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   127
    return offset
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   128
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   129
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
   130
    m = offset + 0.5 * extraspace
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   131
    setXPos(tx,m)
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3721
diff changeset
   132
    tx._textOut(' '.join(words),1)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   133
    setXPos(tx,-m)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   134
    return m
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   135
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   136
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
   137
    m = offset + extraspace
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   138
    setXPos(tx,m)
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3721
diff changeset
   139
    tx._textOut(' '.join(words),1)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   140
    setXPos(tx,-m)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   141
    return m
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   142
3373
127aed2a021d paragraph.py: fixup for nbsp
rgbecker
parents: 3326
diff changeset
   143
def _nbspCount(w):
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
   144
    if isBytes(w):
3835
8e35c471e0ee various: attempt to be more consistent about isStr
robin
parents: 3799
diff changeset
   145
        return w.count(b'\xc2\xa0')
3373
127aed2a021d paragraph.py: fixup for nbsp
rgbecker
parents: 3326
diff changeset
   146
    else:
3888
3e3e5ba4bfcc paragraph.py: fix another 3 only failure
robin
parents: 3882
diff changeset
   147
        return w.count(u'\xa0')
3373
127aed2a021d paragraph.py: fixup for nbsp
rgbecker
parents: 3326
diff changeset
   148
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   149
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
   150
    setXPos(tx,offset)
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3721
diff changeset
   151
    text  = ' '.join(words)
3373
127aed2a021d paragraph.py: fixup for nbsp
rgbecker
parents: 3326
diff changeset
   152
    if last or extraspace<=1e-8:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   153
        #last one, left align
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   154
        tx._textOut(text,1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   155
    else:
3373
127aed2a021d paragraph.py: fixup for nbsp
rgbecker
parents: 3326
diff changeset
   156
        nSpaces = len(words)+sum([_nbspCount(w) for w in words])-1
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   157
        if nSpaces:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   158
            tx.setWordSpace(extraspace / float(nSpaces))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   159
            tx._textOut(text,1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   160
            tx.setWordSpace(0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   161
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   162
            tx._textOut(text,1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   163
    setXPos(tx,-offset)
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   164
    return offset
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   165
2863
63a40c330032 paragraph.py: restore & fix the attempt at ascent/descent auto leading
rgbecker
parents: 2862
diff changeset
   166
def imgVRange(h,va,fontSize):
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   167
    '''return bottom,top offsets relative to baseline(0)'''
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   168
    if va=='baseline':
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   169
        iyo = 0
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   170
    elif va in ('text-top','top'):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   171
        iyo = fontSize-h
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   172
    elif va=='middle':
2863
63a40c330032 paragraph.py: restore & fix the attempt at ascent/descent auto leading
rgbecker
parents: 2862
diff changeset
   173
        iyo = fontSize - (1.2*fontSize+h)*0.5
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   174
    elif va in ('text-bottom','bottom'):
2863
63a40c330032 paragraph.py: restore & fix the attempt at ascent/descent auto leading
rgbecker
parents: 2862
diff changeset
   175
        iyo = fontSize - 1.2*fontSize
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   176
    elif va=='super':
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   177
        iyo = 0.5*fontSize
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   178
    elif va=='sub':
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   179
        iyo = -0.5*fontSize
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   180
    elif hasattr(va,'normalizedValue'):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   181
        iyo = va.normalizedValue(fontSize)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   182
    else:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   183
        iyo = va
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   184
    return iyo,iyo+h
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   185
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3373
diff changeset
   186
def imgNormV(v,nv):
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3373
diff changeset
   187
    if hasattr(v,'normalizedValue'):
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3373
diff changeset
   188
        return v.normalizedValue(nv)
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3373
diff changeset
   189
    else:
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3373
diff changeset
   190
        return v
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3373
diff changeset
   191
3575
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   192
def _getDotsInfo(style):
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   193
    dots = style.endDots
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   194
    if isStr(dots):
3575
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   195
        text = dots
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   196
        fontName = style.fontName
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   197
        fontSize = style.fontSize
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   198
        textColor = style.textColor
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   199
        backColor = style.backColor
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   200
        dy = 0
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   201
    else:
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   202
        text = getattr(dots,'text','.')
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   203
        fontName = getattr(dots,'fontName',style.fontName)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   204
        fontSize = getattr(dots,'fontSize',style.fontSize)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   205
        textColor = getattr(dots,'textColor',style.textColor)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   206
        backColor = getattr(dots,'backColor',style.backColor)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   207
        dy = getattr(dots,'dy',0)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   208
    return text,fontName,fontSize,textColor,backColor,dy
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   209
2881
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   210
_56=5./6
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   211
_16=1./6
3575
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   212
def _putFragLine(cur_x, tx, line, last, pKind):
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2791
diff changeset
   213
    xs = tx.XtraState
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2791
diff changeset
   214
    cur_y = xs.cur_y
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   215
    x0 = tx._x0
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2791
diff changeset
   216
    autoLeading = xs.autoLeading
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2791
diff changeset
   217
    leading = xs.leading
2910
5522f685b679 paragraph.py: fix leftIndent problem
rgbecker
parents: 2901
diff changeset
   218
    cur_x += xs.leftIndent
2881
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   219
    dal = autoLeading in ('min','max')
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   220
    if dal:
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   221
        if autoLeading=='max':
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   222
            ascent = max(_56*leading,line.ascent)
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   223
            descent = max(_16*leading,-line.descent)
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   224
        else:
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   225
            ascent = line.ascent
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   226
            descent = -line.descent
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   227
        leading = ascent+descent
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   228
    if tx._leading!=leading:
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2791
diff changeset
   229
        tx.setLeading(leading)
2881
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   230
    if dal:
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   231
        olb = tx._olb
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   232
        if olb is not None:
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   233
            xcy = olb-ascent
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   234
            if tx._oleading!=leading:
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   235
                cur_y += leading - tx._oleading
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   236
            if abs(xcy-cur_y)>1e-8:
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   237
                cur_y = xcy
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   238
                tx.setTextOrigin(x0,cur_y)
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   239
                xs.cur_y = cur_y
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   240
        tx._olb = cur_y - descent
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   241
        tx._oleading = leading
2708
13619490e003 paragraph.py: fix underlining position errors
rgbecker
parents: 2681
diff changeset
   242
    ws = getattr(tx,'_wordSpace',0)
13619490e003 paragraph.py: fix underlining position errors
rgbecker
parents: 2681
diff changeset
   243
    nSpaces = 0
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2791
diff changeset
   244
    words = line.words
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   245
    AL = []
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   246
    LL = []
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   247
    us_lines = xs.us_lines
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   248
    links = xs.links
4135
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   249
    for i, f in enumerate(words):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   250
        if hasattr(f,'cbDefn'):
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   251
            cbDefn = f.cbDefn
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   252
            kind = cbDefn.kind
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   253
            if kind=='img':
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   254
                #draw image cbDefn,cur_y,cur_x
2871
afd057e790cb paragraph.py: attempt to fix problem when inline img is first in line
rgbecker
parents: 2865
diff changeset
   255
                txfs = tx._fontsize
afd057e790cb paragraph.py: attempt to fix problem when inline img is first in line
rgbecker
parents: 2865
diff changeset
   256
                if txfs is None:
afd057e790cb paragraph.py: attempt to fix problem when inline img is first in line
rgbecker
parents: 2865
diff changeset
   257
                    txfs = xs.style.fontSize
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   258
                w = imgNormV(cbDefn.width,xs.paraWidth)
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3373
diff changeset
   259
                h = imgNormV(cbDefn.height,txfs)
2871
afd057e790cb paragraph.py: attempt to fix problem when inline img is first in line
rgbecker
parents: 2865
diff changeset
   260
                iy0,iy1 = imgVRange(h,cbDefn.valign,txfs)
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   261
                cur_x_s = cur_x + nSpaces*ws
2894
78cd38a39719 paragraph.py: add auto mask for inline images
rgbecker
parents: 2892
diff changeset
   262
                tx._canvas.drawImage(cbDefn.image,cur_x_s,cur_y+iy0,w,h,mask='auto')
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   263
                cur_x += w
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   264
                cur_x_s += w
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   265
                setXPos(tx,cur_x_s-tx._x0)
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2735
diff changeset
   266
            else:
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   267
                name = cbDefn.name
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   268
                if kind=='anchor':
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   269
                    tx._canvas.bookmarkHorizontal(name,cur_x,cur_y+leading)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   270
                else:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   271
                    func = getattr(tx._canvas,name,None)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   272
                    if not func:
2892
131b417f9845 paragraph: improved <a> syntax checks and better test
rgbecker
parents: 2888
diff changeset
   273
                        raise AttributeError("Missing %s callback attribute '%s'" % (kind,name))
3048
3ff2383916b9 Renamed setencrypt to setEncrypt to follow naming convention.
jonas
parents: 3042
diff changeset
   274
                    tx._canvas._curr_tx_info=dict(tx=tx,cur_x=cur_x,cur_y=cur_y,leading=leading,xs=tx.XtraState)
3ff2383916b9 Renamed setencrypt to setEncrypt to follow naming convention.
jonas
parents: 3042
diff changeset
   275
                    try:
4231
7c45177d8a77 onDraw tag doesn't require a label
robin
parents: 4220
diff changeset
   276
                        func(tx._canvas,kind,getattr(cbDefn,'label',None))
3048
3ff2383916b9 Renamed setencrypt to setEncrypt to follow naming convention.
jonas
parents: 3042
diff changeset
   277
                    finally:
3ff2383916b9 Renamed setencrypt to setEncrypt to follow naming convention.
jonas
parents: 3042
diff changeset
   278
                        del tx._canvas._curr_tx_info
2750
05229265aff3 reportlab: fix special case <a> tag problem, add AnchorFlowable class
rgbecker
parents: 2745
diff changeset
   279
            if f is words[-1]:
05229265aff3 reportlab: fix special case <a> tag problem, add AnchorFlowable class
rgbecker
parents: 2745
diff changeset
   280
                if not tx._fontname:
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2791
diff changeset
   281
                    tx.setFont(xs.style.fontName,xs.style.fontSize)
3322
e27df3a204a1 pargraph.py: all eol cbDefns should do textOut('',1)
rgbecker
parents: 3192
diff changeset
   282
                tx._textOut('',1)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   283
        else:
2708
13619490e003 paragraph.py: fix underlining position errors
rgbecker
parents: 2681
diff changeset
   284
            cur_x_s = cur_x + nSpaces*ws
4135
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   285
            end_x = cur_x_s
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   286
            fontSize = f.fontSize
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   287
            textColor = f.textColor
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   288
            rise = f.rise
4135
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   289
            if i > 0:
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   290
                end_x = cur_x_s - _trailingSpaceLength(words[i-1].text, tx)
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   291
            if (tx._fontname,tx._fontsize)!=(f.fontName,fontSize):
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   292
                tx._setFont(f.fontName, fontSize)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   293
            if xs.textColor!=textColor:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   294
                xs.textColor = textColor
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   295
                tx.setFillColor(textColor)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   296
            if xs.rise!=rise:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   297
                xs.rise=rise
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   298
                tx.setRise(rise)
2708
13619490e003 paragraph.py: fix underlining position errors
rgbecker
parents: 2681
diff changeset
   299
            text = f.text
13619490e003 paragraph.py: fix underlining position errors
rgbecker
parents: 2681
diff changeset
   300
            tx._textOut(text,f is words[-1])    # cheap textOut
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   301
            if LL != f.us_lines:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   302
                S = set(LL)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   303
                NS = set(f.us_lines)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   304
                nL = NS - S #new lines
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   305
                eL = S - NS #ending lines
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   306
                for l in eL:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   307
                    us_lines[l] = us_lines[l],end_x
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   308
                for l in nL:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   309
                    us_lines[l] = (l,fontSize,textColor,cur_x),fontSize
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   310
                LL = f.us_lines
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   311
            if LL:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   312
                for l in LL:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   313
                    l0, fsmax = us_lines[l]
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   314
                    if fontSize>fsmax:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   315
                        us_lines[l] = l0, fontSize
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   316
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   317
            nlo = rise - 0.2*fontSize
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   318
            nhi = rise + fontSize
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   319
            if AL != f.link:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   320
                S = set(AL)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   321
                NS = set(f.link)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   322
                nL = NS - S #new linkis
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   323
                eL = S - NS #ending links
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   324
                for l in eL:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   325
                    links[l] = links[l],end_x
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   326
                for l in nL:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   327
                    links[l] = (l,cur_x),nlo,nhi
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   328
                AL = f.link
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   329
            if AL:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   330
                for l in AL:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   331
                    l0, lo, hi = links[l]
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   332
                    if nlo<lo or nhi>hi:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   333
                        links[l] = l0,min(nlo,lo),max(nhi,hi)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   334
3476
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   335
            bg = getattr(f,'backColor',None)
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   336
            if bg and not xs.backColor:
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   337
                xs.backColor = bg
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   338
                xs.backColor_x = cur_x_s
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   339
            elif xs.backColor:
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   340
                if not bg:
4135
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   341
                    xs.backColors.append( (xs.backColor_x, end_x, xs.backColor) )
3476
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   342
                    xs.backColor = None
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   343
                elif f.backColor!=xs.backColor or xs.textColor!=xs.backColor:
4135
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   344
                    xs.backColors.append( (xs.backColor_x, end_x, xs.backColor) )
3476
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   345
                    xs.backColor = bg
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   346
                    xs.backColor_x = cur_x_s
2708
13619490e003 paragraph.py: fix underlining position errors
rgbecker
parents: 2681
diff changeset
   347
            txtlen = tx._canvas.stringWidth(text, tx._fontname, tx._fontsize)
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   348
            cur_x += txtlen
3373
127aed2a021d paragraph.py: fixup for nbsp
rgbecker
parents: 3326
diff changeset
   349
            nSpaces += text.count(' ')+_nbspCount(text)
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   350
2708
13619490e003 paragraph.py: fix underlining position errors
rgbecker
parents: 2681
diff changeset
   351
    cur_x_s = cur_x+(nSpaces-1)*ws
3575
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   352
    if last and pKind!='right' and xs.style.endDots:
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   353
        _do_dots_frag(cur_x,cur_x_s,line.maxWidth,xs,tx)
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   354
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   355
    if LL:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   356
        for l in LL:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   357
            us_lines[l] = us_lines[l], cur_x_s
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   358
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   359
    if AL:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   360
        for l in AL:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   361
            links[l] = links[l], cur_x_s
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   362
3476
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   363
    if xs.backColor:
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   364
        xs.backColors.append( (xs.backColor_x, cur_x_s, xs.backColor) )
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   365
    if tx._x0!=x0:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   366
        setXPos(tx,x0-tx._x0)
4135
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   367
3575
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   368
def _do_dots_frag(cur_x, cur_x_s, maxWidth, xs, tx):
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   369
    text,fontName,fontSize,textColor,backColor,dy = _getDotsInfo(xs.style)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   370
    txtlen = tx._canvas.stringWidth(text, fontName, fontSize)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   371
    if cur_x_s+txtlen<=maxWidth:
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   372
        if tx._fontname!=fontName or tx._fontsize!=fontSize:
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   373
            tx.setFont(fontName,fontSize)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   374
        maxWidth += getattr(tx,'_dotsOffsetX',tx._x0)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   375
        tx.setTextOrigin(0,xs.cur_y+dy)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   376
        setXPos(tx,cur_x_s-cur_x)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   377
        n = int((maxWidth-cur_x_s)/txtlen)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   378
        setXPos(tx,maxWidth - txtlen*n)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   379
        if xs.textColor!=textColor:
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   380
            tx.setFillColor(textColor)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   381
        if backColor: xs.backColors.append((cur_x,maxWidth,backColor))
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   382
        tx._textOut(n*text,1)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   383
        if dy: tx.setTextOrigin(tx._x0,xs.cur_y-dy)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   384
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   385
def _leftDrawParaLineX( tx, offset, line, last=0):
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   386
    extraSpace = line.extraSpace
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   387
    simple = extraSpace>-1e-8 or getattr(line,'preformatted',False)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   388
    if not simple:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   389
        nSpaces = line.wordCount+sum([_nbspCount(w.text) for w in line.words if not hasattr(w,'cbDefn')])-1
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   390
        simple = not nSpaces
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   391
    if simple:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   392
        setXPos(tx,offset)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   393
        _putFragLine(offset, tx, line, last, 'left')
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   394
    else:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   395
        tx.setWordSpace(extraSpace / float(nSpaces))
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   396
        _putFragLine(offset, tx, line, last, 'left')
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   397
        tx.setWordSpace(0)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   398
    setXPos(tx,-offset)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   399
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   400
def _centerDrawParaLineX( tx, offset, line, last=0):
3575
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   401
    tx._dotsOffsetX = offset + tx._x0
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   402
    try:
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   403
        extraSpace = line.extraSpace
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   404
        simple = extraSpace>-1e-8 or getattr(line,'preformatted',False)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   405
        if not simple:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   406
            nSpaces = line.wordCount+sum([_nbspCount(w.text) for w in line.words if not hasattr(w,'cbDefn')])-1
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   407
            simple = not nSpaces
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   408
        if simple:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   409
            m = offset+0.5*line.extraSpace
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   410
            setXPos(tx,m)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   411
            _putFragLine(m, tx, line, last,'center')
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   412
        else:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   413
            m = offset
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   414
            tx.setWordSpace(extraSpace / float(nSpaces))
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   415
            _putFragLine(m, tx, line, last, 'center')
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   416
            tx.setWordSpace(0)
3575
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   417
        setXPos(tx,-m)
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   418
    finally:
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   419
        del tx._dotsOffsetX
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   420
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   421
def _rightDrawParaLineX( tx, offset, line, last=0):
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   422
    extraSpace = line.extraSpace
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   423
    simple = extraSpace>-1e-8 or getattr(line,'preformatted',False)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   424
    if not simple:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   425
        nSpaces = line.wordCount+sum([_nbspCount(w.text) for w in line.words if not hasattr(w,'cbDefn')])-1
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   426
        simple = not nSpaces
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   427
    if simple:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   428
        m = offset+line.extraSpace
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   429
        setXPos(tx,m)
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   430
        _putFragLine(m,tx, line, last, 'right')
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   431
    else:
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   432
        m = offset
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   433
        tx.setWordSpace(extraSpace / float(nSpaces))
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   434
        _putFragLine(m, tx, line, last, 'right')
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   435
        tx.setWordSpace(0)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   436
    setXPos(tx,-m)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   437
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   438
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
   439
    setXPos(tx,offset)
2840
69e2c8b05684 reportlab: fixes to paragraph <br/> tag
rgbecker
parents: 2836
diff changeset
   440
    extraSpace = line.extraSpace
3373
127aed2a021d paragraph.py: fixup for nbsp
rgbecker
parents: 3326
diff changeset
   441
    simple = last or abs(extraSpace)<=1e-8 or line.lineBreak
127aed2a021d paragraph.py: fixup for nbsp
rgbecker
parents: 3326
diff changeset
   442
    if not simple:
127aed2a021d paragraph.py: fixup for nbsp
rgbecker
parents: 3326
diff changeset
   443
        nSpaces = line.wordCount+sum([_nbspCount(w.text) for w in line.words if not hasattr(w,'cbDefn')])-1
127aed2a021d paragraph.py: fixup for nbsp
rgbecker
parents: 3326
diff changeset
   444
        simple = not nSpaces
127aed2a021d paragraph.py: fixup for nbsp
rgbecker
parents: 3326
diff changeset
   445
    if not simple:
2840
69e2c8b05684 reportlab: fixes to paragraph <br/> tag
rgbecker
parents: 2836
diff changeset
   446
        tx.setWordSpace(extraSpace / float(nSpaces))
3575
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   447
        _putFragLine(offset, tx, line, last, 'justify')
2840
69e2c8b05684 reportlab: fixes to paragraph <br/> tag
rgbecker
parents: 2836
diff changeset
   448
        tx.setWordSpace(0)
3373
127aed2a021d paragraph.py: fixup for nbsp
rgbecker
parents: 3326
diff changeset
   449
    else:
3575
6821eb805106 reportlab: added support for endDots in paragraphs styles
rgbecker
parents: 3559
diff changeset
   450
        _putFragLine(offset, tx, line, last, 'justify') #no space modification
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   451
    setXPos(tx,-offset)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   452
4135
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   453
def _trailingSpaceLength(text, tx):
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   454
    ws = _wsc_end_search(text)
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   455
    return tx._canvas.stringWidth(ws.group(), tx._fontname, tx._fontsize) if ws else 0
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   456
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   457
class _HSWord(list):
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   458
    pass
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   459
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   460
class _SplitList(list):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   461
    pass
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   462
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   463
class _SplitListLast(_SplitList):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   464
    pass
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   465
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   466
class _HSSplitList(_HSWord):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   467
    pass
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   468
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   469
def _processed_frags(frags):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   470
    try:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   471
        return isinstance(frags[0][0],(float,int))
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   472
    except:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   473
        return False
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   474
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   475
_FK_TEXT = 0
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   476
_FK_IMG = 1
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   477
_FK_APPEND = 2
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   478
_FK_BREAK = 3
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   479
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3373
diff changeset
   480
def _getFragWords(frags,maxWidth=None):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   481
    ''' 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
   482
        [[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
   483
        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
   484
        each sublist represents a word
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   485
    '''
4316
14c18006410a fix bug in _getFragWords
robin <robin@reportlab.com>
parents: 4315
diff changeset
   486
    def _rescaleFrag(f):
14c18006410a fix bug in _getFragWords
robin <robin@reportlab.com>
parents: 4315
diff changeset
   487
        w = f[0]
14c18006410a fix bug in _getFragWords
robin <robin@reportlab.com>
parents: 4315
diff changeset
   488
        if isinstance(w,_PCT):
14c18006410a fix bug in _getFragWords
robin <robin@reportlab.com>
parents: 4315
diff changeset
   489
            if w._normalizer!=maxWidth:
14c18006410a fix bug in _getFragWords
robin <robin@reportlab.com>
parents: 4315
diff changeset
   490
                w._normalizer = maxWidth
14c18006410a fix bug in _getFragWords
robin <robin@reportlab.com>
parents: 4315
diff changeset
   491
                w = w.normalizedValue(maxWidth)
14c18006410a fix bug in _getFragWords
robin <robin@reportlab.com>
parents: 4315
diff changeset
   492
                f[0] = w
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   493
    R = []
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   494
    R_append = R.append
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   495
    if _processed_frags(frags):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   496
        i = 0
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   497
        n = len(frags)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   498
        while i<n:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   499
            f = frags[i]
4316
14c18006410a fix bug in _getFragWords
robin <robin@reportlab.com>
parents: 4315
diff changeset
   500
            _rescaleFrag(f)
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   501
            if isinstance(f,(_SplitList,_HSSplitList,_SplitListLast)):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   502
                #we need to re-join these to make a single word
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   503
                W = [0]
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   504
                while True:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   505
                    W[0] += f[0]
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   506
                    W.extend(f[1:])
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   507
                    if isinstance(f,(_SplitListLast,_HSSplitList)):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   508
                        break
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   509
                    i += 1
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   510
                    if i==n: break  #exceptional case when a split paragraph split in the middle of such a sequence
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   511
                    f = frags[i]
4316
14c18006410a fix bug in _getFragWords
robin <robin@reportlab.com>
parents: 4315
diff changeset
   512
                    _rescaleFrag(f)
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   513
                if isinstance(f,_HSSplitList):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   514
                    f = _HSWord(W)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   515
                else:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   516
                    f = W
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   517
            R_append(f)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   518
            i += 1
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   519
    else:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   520
        W = []
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   521
        hangingSpace = False
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   522
        n = 0
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   523
        hangingStrip = True
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   524
        for f in frags:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   525
            text = f.text
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   526
            if text!='':
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   527
                f._fkind = _FK_TEXT
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   528
                if hangingStrip:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   529
                    text = text.lstrip()
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   530
                    if not text: continue
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   531
                    hangingStrip = False
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   532
                S = split(text)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   533
                if text[0] in whitespace:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   534
                    if W:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   535
                        W.insert(0,n)   #end preceding word
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   536
                        R_append(W)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   537
                        whs = hangingSpace
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   538
                        W = []
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   539
                        hangingSpace = False
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   540
                        n = 0
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   541
                    else:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   542
                        whs = R and isinstance(R[-1],_HSWord)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   543
                    if not whs:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   544
                        S.insert(0,'')
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   545
                    elif not S:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   546
                        continue
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   547
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   548
                for w in S[:-1]:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   549
                    W.append((f,w))
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   550
                    n += stringWidth(w, f.fontName, f.fontSize)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   551
                    W.insert(0,n)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   552
                    R_append(_HSWord(W))
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   553
                    W = []
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   554
                    n = 0
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   555
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   556
                hangingSpace = False
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   557
                w = S[-1]
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   558
                W.append((f,w))
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   559
                n += stringWidth(w, f.fontName, f.fontSize)
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   560
                if text and text[-1] in whitespace:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   561
                    W.insert(0,n)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   562
                    R_append(_HSWord(W))
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   563
                    W = []
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   564
                    n = 0
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   565
            elif hasattr(f,'cbDefn'):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   566
                cb = f.cbDefn
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   567
                w = getattr(cb,'width',0)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   568
                if w:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   569
                    if hasattr(w,'normalizedValue'):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   570
                        w._normalizer = maxWidth
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   571
                        w = w.normalizedValue(maxWidth)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   572
                    if W:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   573
                        W.insert(0,n)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   574
                        R_append(_HSWord(W) if hangingSpace else W)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   575
                        W = []
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   576
                        hangingSpace = False
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   577
                        n = 0
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   578
                    f._fkind = _FK_IMG
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   579
                    R_append([w,(f,'')])
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   580
                    hangingStrip = False
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   581
                else:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   582
                    f._fkind = _FK_APPEND
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   583
                    if not W and R and isinstance(R[-1],_HSWord):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   584
                        R[-1].append((f,''))
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   585
                    else:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   586
                        W.append((f,''))
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   587
            elif hasattr(f, 'lineBreak'):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   588
                #pass the frag through.  The line breaker will scan for it.
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   589
                if W:
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   590
                    W.insert(0,n)
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   591
                    R_append(W)
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   592
                    W = []
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2841
diff changeset
   593
                    n = 0
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   594
                    hangingSpace = False
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   595
                f._fkind = _FK_BREAK
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   596
                R_append([0,(f,'')])
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   597
                hangingStrip = True
508
37dc6fc3fa65 More <onDraw> hacks
rgbecker
parents: 506
diff changeset
   598
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   599
        if W:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   600
            W.insert(0,n)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   601
            R_append(W)
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   602
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   603
    return R
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
   604
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   605
def _fragWordIter(w):
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   606
    for f, s in w[1:]:
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   607
        if hasattr(f,'cbDefn'):
4272
a3e48855dd48 fix AttributeError reported by Kay Schluehr bitbucket issue #81, version-->3.3.8
robin
parents: 4252
diff changeset
   608
            yield f, getattr(f,'width',0), s
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   609
        elif s:
3929
b8175c55af71 paragraph.py: fix bug in _fragWordIter (transplant from 3772 with changes)
robin
parents: 3921
diff changeset
   610
            if isBytes(s):
b8175c55af71 paragraph.py: fix bug in _fragWordIter (transplant from 3772 with changes)
robin
parents: 3921
diff changeset
   611
                s = s.decode('utf8')    #only encoding allowed
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   612
            for c in s:
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   613
                yield f, stringWidth(c,f.fontName, f.fontSize), c
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   614
        else:
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   615
            yield f, 0, s
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   616
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   617
def _splitFragWord(w,maxWidth,maxWidths,lineno):
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   618
    '''given a frag word, w, as returned by getFragWords
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   619
    split it into frag words that fit in lines of length
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   620
    maxWidth
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   621
    maxWidths[lineno+1]
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   622
    .....
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   623
    maxWidths[lineno+n]
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   624
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   625
    return the new word list which is either 
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   626
    _SplitList....._SPlitList or
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   627
    _splitList....._HSSplitList if the word is hanging space.
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   628
    '''
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   629
    R = []
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   630
    maxlineno = len(maxWidths)-1
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   631
    W = []
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   632
    lineWidth = 0
4046
aed0e2af4546 paragraph: fix _splitWord for unicode/bytes bug reported by Anders Hammarquist & add a test
robin
parents: 4035
diff changeset
   633
    fragText = u''
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   634
    wordWidth = 0
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   635
    f = w[1][0]
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   636
    for g,cw,c in _fragWordIter(w):
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   637
        newLineWidth = lineWidth+cw
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   638
        tooLong = newLineWidth>maxWidth
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   639
        if g is not f or tooLong:
3739
970f6cb12b90 fix bug in _splitFragWord and use splitLongWords
robin
parents: 3737
diff changeset
   640
            f = f.clone()
970f6cb12b90 fix bug in _splitFragWord and use splitLongWords
robin
parents: 3737
diff changeset
   641
            if hasattr(f,'text'):
970f6cb12b90 fix bug in _splitFragWord and use splitLongWords
robin
parents: 3737
diff changeset
   642
                f.text = fragText
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   643
            W.append((f,fragText))
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   644
            if tooLong:
3739
970f6cb12b90 fix bug in _splitFragWord and use splitLongWords
robin
parents: 3737
diff changeset
   645
                W = _SplitList([wordWidth]+W)
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   646
                R.append(W)
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   647
                lineno += 1
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   648
                maxWidth = maxWidths[min(maxlineno,lineno)]
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   649
                W = []
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   650
                newLineWidth = cw
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   651
                wordWidth = 0
4046
aed0e2af4546 paragraph: fix _splitWord for unicode/bytes bug reported by Anders Hammarquist & add a test
robin
parents: 4035
diff changeset
   652
            fragText = u''
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   653
            f = g
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   654
        wordWidth += cw
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   655
        fragText += c
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   656
        lineWidth = newLineWidth
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   657
    W.append((f,fragText))
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
   658
    W = _HSSplitList([wordWidth]+W) if isinstance(w,_HSWord) else _SplitListLast([wordWidth]+W)
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4272
diff changeset
   659
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   660
    R.append(W)
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   661
    return R
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   662
4046
aed0e2af4546 paragraph: fix _splitWord for unicode/bytes bug reported by Anders Hammarquist & add a test
robin
parents: 4035
diff changeset
   663
class _SplitText(unicodeT):
3739
970f6cb12b90 fix bug in _splitFragWord and use splitLongWords
robin
parents: 3737
diff changeset
   664
    pass
970f6cb12b90 fix bug in _splitFragWord and use splitLongWords
robin
parents: 3737
diff changeset
   665
4046
aed0e2af4546 paragraph: fix _splitWord for unicode/bytes bug reported by Anders Hammarquist & add a test
robin
parents: 4035
diff changeset
   666
def _splitWord(w,maxWidth,maxWidths,lineno,fontName,fontSize,encoding='utf8'):
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   667
    '''
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   668
    split w into words that fit in lines of length
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   669
    maxWidth
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   670
    maxWidths[lineno+1]
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   671
    .....
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   672
    maxWidths[lineno+n]
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   673
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   674
    then push those new words onto words
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   675
    '''
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   676
    #TODO fix this to use binary search for the split points
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   677
    R = []
4280
7f3365bf11f2 fix issue reported by Yitzchak Scott-Thoennes <sthoenna@gmail.com>, version-->3.3.14
robin
parents: 4277
diff changeset
   678
    aR = R.append
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   679
    maxlineno = len(maxWidths)-1
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   680
    lineWidth = 0
3930
950841932d03 paragraph.py: fix encoding issue in _splitWord (transplant from 3774 with changes)
robin
parents: 3929
diff changeset
   681
    wordText = u''
950841932d03 paragraph.py: fix encoding issue in _splitWord (transplant from 3774 with changes)
robin
parents: 3929
diff changeset
   682
    if isBytes(w):
4046
aed0e2af4546 paragraph: fix _splitWord for unicode/bytes bug reported by Anders Hammarquist & add a test
robin
parents: 4035
diff changeset
   683
        w = w.decode(encoding)
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   684
    for c in w:
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   685
        cw = stringWidth(c,fontName,fontSize,encoding)
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   686
        newLineWidth = lineWidth+cw
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   687
        if newLineWidth>maxWidth:
4280
7f3365bf11f2 fix issue reported by Yitzchak Scott-Thoennes <sthoenna@gmail.com>, version-->3.3.14
robin
parents: 4277
diff changeset
   688
            aR(_SplitText(wordText))
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   689
            lineno += 1
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   690
            maxWidth = maxWidths[min(maxlineno,lineno)]
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   691
            newLineWidth = cw
4046
aed0e2af4546 paragraph: fix _splitWord for unicode/bytes bug reported by Anders Hammarquist & add a test
robin
parents: 4035
diff changeset
   692
            wordText = u''
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   693
        wordText += c
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   694
        lineWidth = newLineWidth
4280
7f3365bf11f2 fix issue reported by Yitzchak Scott-Thoennes <sthoenna@gmail.com>, version-->3.3.14
robin
parents: 4277
diff changeset
   695
    aR(_SplitText(wordText))
7f3365bf11f2 fix issue reported by Yitzchak Scott-Thoennes <sthoenna@gmail.com>, version-->3.3.14
robin
parents: 4277
diff changeset
   696
    if not R[0]: del R[0]   #delete in special case
3737
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   697
    return R
610ffa01744e first try at word splitting
robin
parents: 3731
diff changeset
   698
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   699
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
   700
    f = blPara.clone()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   701
    for a in ('lines', 'kind', 'text'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   702
        if hasattr(f,a): delattr(f,a)
212
b04e22acb4fa Splitting changes
rgbecker
parents: 208
diff changeset
   703
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   704
    f.words = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   705
    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
   706
        for w in l[1]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   707
            f.words.append(w)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   708
    return [f]
212
b04e22acb4fa Splitting changes
rgbecker
parents: 208
diff changeset
   709
532
fa0a46295460 Added a text background color attribute
andy_robinson
parents: 529
diff changeset
   710
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
   711
    f = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   712
    lines = blPara.lines[start:stop]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   713
    for l in lines:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   714
        for w in l.words:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   715
            f.append(w)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   716
        if l is not lines[-1]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   717
            i = len(f)-1
2886
7c66d24b6845 paragraph.py: fix some bugs in paragraph and bring xpreformatted nearer
rgbecker
parents: 2884
diff changeset
   718
            while i>=0 and hasattr(f[i],'cbDefn') and not getattr(f[i].cbDefn,'width',0): i -= 1
7c66d24b6845 paragraph.py: fix some bugs in paragraph and bring xpreformatted nearer
rgbecker
parents: 2884
diff changeset
   719
            if i>=0:
7c66d24b6845 paragraph.py: fix some bugs in paragraph and bring xpreformatted nearer
rgbecker
parents: 2884
diff changeset
   720
                g = f[i]
7c66d24b6845 paragraph.py: fix some bugs in paragraph and bring xpreformatted nearer
rgbecker
parents: 2884
diff changeset
   721
                if not g.text: g.text = ' '
7c66d24b6845 paragraph.py: fix some bugs in paragraph and bring xpreformatted nearer
rgbecker
parents: 2884
diff changeset
   722
                elif g.text[-1]!=' ': g.text += ' '
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   723
    return f
212
b04e22acb4fa Splitting changes
rgbecker
parents: 208
diff changeset
   724
4094
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   725
def _drawBullet(canvas, offset, cur_y, bulletText, style, rtl):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   726
    '''draw a bullet text could be a simple string or a frag list'''
4136
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   727
    bulletAnchor = style.bulletAnchor
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   728
    if rtl or style.bulletAnchor!='start':
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   729
        numeric = bulletAnchor=='numeric'
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   730
        if isStr(bulletText):
4136
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   731
            t =  bulletText
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   732
            q = numeric and decimalSymbol in t
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   733
            if q: t = t[:t.index(decimalSymbol)]
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   734
            bulletWidth = stringWidth(t, style.bulletFontName, style.bulletFontSize)
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   735
            if q: bulletWidth += 0.5 * stringWidth(decimalSymbol, style.bulletFontName, style.bulletFontSize)
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   736
        else:
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   737
            #it's a list of fragments
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   738
            bulletWidth = 0
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   739
            for f in bulletText:
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   740
                t = f.text
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   741
                q = numeric and decimalSymbol in t
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   742
                if q:
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   743
                    t = t[:t.index(decimalSymbol)]
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   744
                    bulletWidth += 0.5 * stringWidth(decimalSymbol, f.fontName, f.fontSize)
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   745
                bulletWidth += stringWidth(t, f.fontName, f.fontSize)
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   746
                if q:
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   747
                    break
4094
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   748
    else:
4136
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   749
        bulletWidth = 0
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   750
    if bulletAnchor=='middle': bulletWidth *= 0.5
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   751
    cur_y += getattr(style,"bulletOffsetY",0)
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   752
    if not rtl:
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   753
        tx2 = canvas.beginText(style.bulletIndent-bulletWidth,cur_y)
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   754
    else:
4094
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   755
        width = rtl[0]
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   756
        bulletStart = width+style.rightIndent-(style.bulletIndent+bulletWidth)
4136
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   757
        tx2 = canvas.beginText(bulletStart, cur_y)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   758
    tx2.setFont(style.bulletFontName, style.bulletFontSize)
4136
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   759
    tx2.setFillColor(getattr(style,'bulletColor',style.textColor))
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   760
    if isStr(bulletText):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   761
        tx2.textOut(bulletText)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   762
    else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   763
        for f in bulletText:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   764
            tx2.setFont(f.fontName, f.fontSize)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   765
            tx2.setFillColor(f.textColor)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   766
            tx2.textOut(f.text)
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 221
diff changeset
   767
2366
7dd247980b7d minor twitching on Indenter
rgbecker
parents: 2341
diff changeset
   768
    canvas.drawText(tx2)
4094
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   769
    if not rtl:
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   770
        #AR making definition lists a bit less ugly
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   771
        #bulletEnd = tx2.getX()
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   772
        bulletEnd = tx2.getX() + style.bulletFontSize * 0.6
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   773
        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
   774
    return offset
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 221
diff changeset
   775
438
fa5d480207bc Preparing for cleanup
rgbecker
parents: 434
diff changeset
   776
def _handleBulletWidth(bulletText,style,maxWidths):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   777
    '''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
   778
    '''
2899
bdcad3b5bf68 attempt to fix offset problems with images
rgbecker
parents: 2898
diff changeset
   779
    if bulletText:
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   780
        if isStr(bulletText):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   781
            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
   782
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   783
            #it's a list of fragments
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   784
            bulletWidth = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   785
            for f in bulletText:
4136
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4135
diff changeset
   786
                bulletWidth += stringWidth(f.text, f.fontName, f.fontSize)
4094
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   787
        bulletLen = style.bulletIndent + bulletWidth + 0.6 * style.bulletFontSize
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   788
        if style.wordWrap=='RTL':
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   789
            indent = style.rightIndent+style.firstLineIndent
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   790
        else:
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   791
            indent = style.leftIndent+style.firstLineIndent
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   792
        if bulletLen > indent:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   793
            #..then it overruns, and we have less space available on line 1
4094
186f3923093a transfrred rtl-support changes to default, version --> 3.1.13
robin
parents: 4067
diff changeset
   794
            maxWidths[0] -= (bulletLen - indent)
438
fa5d480207bc Preparing for cleanup
rgbecker
parents: 434
diff changeset
   795
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   796
def splitLines0(frags,widths):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   797
    '''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   798
    given a list of ParaFrags we return a list of ParaLines
549
f9e66c978f3a Start on new simpler line splitter
rgbecker
parents: 547
diff changeset
   799
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   800
    each ParaLine has
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   801
    1)  ExtraSpace
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   802
    2)  blankCount
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   803
    3)  [textDefns....]
3031
6f90e7668adb docstrings cleaned up for epydoc
tim
parents: 3027
diff changeset
   804
    each text definition is a (ParaFrag, start, limit) triplet
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   805
    '''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   806
    #initialise the algorithm
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   807
    lines   = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   808
    lineNum = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   809
    maxW    = widths[lineNum]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   810
    i       = -1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   811
    l       = len(frags)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   812
    lim     = start = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   813
    while 1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   814
        #find a non whitespace character
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   815
        while i<l:
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   816
            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
   817
            if start==lim:
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   818
                i += 1
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   819
                if i==l: break
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   820
                start = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   821
                f = frags[i]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   822
                text = f.text
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   823
                lim = len(text)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   824
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   825
                break   # we found one
551
21b8a2cb8c8b Hack to fix Dinu's problem
rgbecker
parents: 549
diff changeset
   826
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   827
        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
   828
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   829
        #start of a line
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   830
        g       = (None,None,None)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   831
        line    = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   832
        cLen    = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   833
        nSpaces = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   834
        while cLen<maxW:
2881
41b10eb435c1 paragraph.py: fix autoLeading
rgbecker
parents: 2877
diff changeset
   835
            j = text.find(' ',start)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   836
            if j<0: j==lim
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   837
            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
   838
            cLen += w
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   839
            if cLen>maxW and line!=[]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   840
                cLen = cLen-w
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   841
                #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
   842
                while g.text[lim]==' ':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   843
                    lim = lim - 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   844
                    nSpaces = nSpaces-1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   845
                break
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   846
            if j<0: j = lim
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   847
            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
   848
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   849
                g = (f,start,j)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   850
                line.append(g)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
   851
            if j==lim:
2593
3adaab508968 reportlab: minor fixes to platypus, tests and fix jap splitting bug
rgbecker
parents: 2584
diff changeset
   852
                i += 1
549
f9e66c978f3a Start on new simpler line splitter
rgbecker
parents: 547
diff changeset
   853
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   854
def _do_line(tx, x1, y1, x2, y2, nlw, nsc):
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   855
    canv = tx._canvas
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   856
    olw = canv._lineWidth
4135
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   857
    if nlw!=olw:
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   858
        canv.setLineWidth(nlw)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   859
    osc = canv._strokeColorObj
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   860
    if nsc!=osc:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   861
        canv.setStrokeColor(nsc)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   862
    canv.line(x1, y1, x2, y2)
4135
226667ad6b1f Viktoras Agejevas' proportional underlining patch (slightly modified); version -->3.1.34
robin
parents: 4098
diff changeset
   863
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   864
def _do_under_line(i, x1, ws, tx, us_lines):
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   865
    xs = tx.XtraState
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   866
    style = xs.style
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   867
    y0 = xs.cur_y - i*style.leading
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   868
    f = xs.f
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   869
    fs = f.fontSize
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   870
    tc = f.textColor
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   871
    values = dict(L=fs,F=fs,f=fs)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   872
    dw = tx._defaultLineWidth
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   873
    x2 = x1 + tx._canvas.stringWidth(' '.join(tx.XtraState.lines[i][1]), tx._fontname, fs)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   874
    for n,k,c,w,o,r,m,g in us_lines:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   875
        underline = k=='underline'
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   876
        lw = _usConv(w,values,default=tx._defaultLineWidth)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   877
        lg = _usConv(g,values,default=1)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   878
        dy = lg+lw
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   879
        if not underline: dy = -dy
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   880
        y = y0 + r + _usConv(('-0.125*L' if underline else '0.25*L') if o=='' else o,values)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   881
        if not c: c = tc
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   882
        while m>0:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   883
            tx._do_line(x1, y, x2, y, lw, c)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   884
            y -= dy
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   885
            m -= 1
1915
5a94ea499657 Added in Ury Marshak's underlining stuff hacked for <2.2
rgbecker
parents: 1752
diff changeset
   886
2594
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   887
_scheme_re = re.compile('^[a-zA-Z][-+a-zA-Z0-9]+$')
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   888
def _doLink(tx,link,rect):
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   889
    parts = link.split(':',1)
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   890
    scheme = len(parts)==2 and parts[0].lower() or ''
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   891
    if _scheme_re.match(scheme) and scheme!='document':
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   892
        kind=scheme.lower()=='pdf' and 'GoToR' or 'URI'
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   893
        if kind=='GoToR': link = parts[1]
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   894
        tx._canvas.linkURL(link, rect, relative=1, kind=kind)
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   895
    else:
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   896
        if not link: return
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2735
diff changeset
   897
        if link[0]=='#':
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2735
diff changeset
   898
            link = link[1:]
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2735
diff changeset
   899
            scheme=''
2594
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2593
diff changeset
   900
        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
   901
2708
13619490e003 paragraph.py: fix underlining position errors
rgbecker
parents: 2681
diff changeset
   902
def _do_link_line(i, t_off, ws, tx):
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   903
    xs = tx.XtraState
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   904
    leading = xs.style.leading
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   905
    y = xs.cur_y - i*leading - xs.f.fontSize/8.0 # 8.0 factor copied from para.py
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3721
diff changeset
   906
    text = ' '.join(xs.lines[i][1])
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   907
    textlen = tx._canvas.stringWidth(text, tx._fontname, tx._fontsize)
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   908
    for n, link in xs.link:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   909
        _doLink(tx, link, (t_off, y, t_off+textlen, y+leading))
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   910
2899
bdcad3b5bf68 attempt to fix offset problems with images
rgbecker
parents: 2898
diff changeset
   911
def _do_post_text(tx):
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   912
    xs = tx.XtraState
4387
c9accf85d669 fix issue 136 reported by lostbard @ bitbucket.org; version --> 3.4.28
robin <robin@reportlab.com>
parents: 4386
diff changeset
   913
    y0 = xs.cur_y
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2791
diff changeset
   914
    f = xs.f
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   915
    leading = xs.style.leading
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   916
    autoLeading = xs.autoLeading
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   917
    fontSize = f.fontSize
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2791
diff changeset
   918
    if autoLeading=='max':
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   919
        leading = max(leading,1.2*fontSize)
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2791
diff changeset
   920
    elif autoLeading=='min':
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   921
        leading = 1.2*fontSize
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   922
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   923
    if xs.backColors:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   924
        yl = y0 + fontSize
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   925
        ydesc = yl - leading
4387
c9accf85d669 fix issue 136 reported by lostbard @ bitbucket.org; version --> 3.4.28
robin <robin@reportlab.com>
parents: 4386
diff changeset
   926
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   927
        for x1,x2,c in xs.backColors:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   928
            tx._canvas.setFillColor(c)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   929
            tx._canvas.rect(x1,ydesc,x2-x1,leading,stroke=0,fill=1)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   930
        xs.backColors=[]
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   931
        xs.backColor=None
4387
c9accf85d669 fix issue 136 reported by lostbard @ bitbucket.org; version --> 3.4.28
robin <robin@reportlab.com>
parents: 4386
diff changeset
   932
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   933
    for (((n,link),x1),lo,hi),x2 in sorted(xs.links.values()):
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   934
        _doLink(tx, link, (x1, y0+lo, x2, y0+hi))
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   935
    xs.links = {}
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
   936
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   937
    if xs.us_lines:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   938
        #print 'lines'
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   939
        dw = tx._defaultLineWidth
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   940
        values = dict(L=fontSize)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   941
        for (((n,k,c,w,o,r,m,g),fs,tc,x1),fsmax),x2 in sorted(xs.us_lines.values()):
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   942
            underline = k=='underline'
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   943
            values['f'] = fs
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   944
            values['F'] = fsmax
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   945
            lw = _usConv(w,values,default=tx._defaultLineWidth)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   946
            lg = _usConv(g,values,default=1)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   947
            dy = lg+lw
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   948
            if not underline: dy = -dy
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   949
            y = y0 + r + _usConv(o if o!='' else ('-0.125*L' if underline else '0.25*L'),values)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   950
            #print 'n=%s k=%s x1=%s x2=%s r=%s c=%s w=%r o=%r fs=%r tc=%s y=%s lW=%r offs=%r' % (n,k,x1,x2,r,(c.hexval() if c else ''),w,o,fs,tc.hexval(),y,lW,y-y0-r)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   951
            if not c: c = tc
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   952
            while m>0:
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   953
                tx._do_line(x1, y, x2, y, lw, c)
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   954
                y -= dy
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   955
                m -= 1
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
   956
        xs.us_lines = {}
3476
0d4b3cfbbd04 paragraph.py: add in support for backColor in <font> tag
rgbecker
parents: 3440
diff changeset
   957
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2791
diff changeset
   958
    xs.cur_y -= leading
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2561
diff changeset
   959
2936
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   960
def textTransformFrags(frags,style):
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   961
    tt = style.textTransform
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   962
    if tt:
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   963
        tt=tt.lower()
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   964
        if tt=='lowercase':
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
   965
            tt = unicodeT.lower
2936
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   966
        elif tt=='uppercase':
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
   967
            tt = unicodeT.upper
2936
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   968
        elif  tt=='capitalize':
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
   969
            tt = unicodeT.title
2936
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   970
        elif tt=='none':
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   971
            return
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   972
        else:
3559
fb200750d086 paragraph.py: remove unwanted code
rgbecker
parents: 3555
diff changeset
   973
            raise ValueError('ParaStyle.textTransform value %r is invalid' % style.textTransform)
2936
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   974
        n = len(frags)
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   975
        if n==1:
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   976
            #single fragment the easy case
3799
9e42094b0298 paragraph.py: move towards no decoding/encoding
robin
parents: 3781
diff changeset
   977
            frags[0].text = tt(frags[0].text)
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
   978
        elif tt is unicodeT.title:
2936
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   979
            pb = True
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   980
            for f in frags:
3799
9e42094b0298 paragraph.py: move towards no decoding/encoding
robin
parents: 3781
diff changeset
   981
                u = f.text
9e42094b0298 paragraph.py: move towards no decoding/encoding
robin
parents: 3781
diff changeset
   982
                if not u: continue
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
   983
                if u.startswith(u' ') or pb:
2936
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   984
                    u = tt(u)
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   985
                else:
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
   986
                    i = u.find(u' ')
2936
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   987
                    if i>=0:
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   988
                        u = u[:i]+tt(u[i:])
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
   989
                pb = u.endswith(u' ')
3799
9e42094b0298 paragraph.py: move towards no decoding/encoding
robin
parents: 3781
diff changeset
   990
                f.text = u
2936
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   991
        else:
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   992
            for f in frags:
3799
9e42094b0298 paragraph.py: move towards no decoding/encoding
robin
parents: 3781
diff changeset
   993
                u = f.text
9e42094b0298 paragraph.py: move towards no decoding/encoding
robin
parents: 3781
diff changeset
   994
                if not u: continue
9e42094b0298 paragraph.py: move towards no decoding/encoding
robin
parents: 3781
diff changeset
   995
                f.text = tt(u)
2936
97860052e0fc paragraph.py: make textTransformFrags externall callable
rgbecker
parents: 2935
diff changeset
   996
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
   997
class cjkU(unicodeT):
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
   998
    '''simple class to hold the frag corresponding to a str'''
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
   999
    def __new__(cls,value,frag,encoding):
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
  1000
        self = unicodeT.__new__(cls,value)
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1001
        self._frag = frag
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1002
        if hasattr(frag,'cbDefn'):
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1003
            w = getattr(frag.cbDefn,'width',0)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1004
            self._width = w
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1005
        else:
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1006
            self._width = stringWidth(value,frag.fontName,frag.fontSize)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1007
        return self
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1008
    frag = property(lambda self: self._frag)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1009
    width = property(lambda self: self._width)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1010
3624
c85cbc87b630 paragraph.py: fix CJK + endDots
rgbecker
parents: 3617
diff changeset
  1011
def makeCJKParaLine(U,maxWidth,widthUsed,extraSpace,lineBreak,calcBounds):
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1012
    words = []
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1013
    CW = []
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1014
    f0 = FragLine()
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1015
    maxSize = maxAscent = minDescent = 0
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1016
    for u in U:
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1017
        f = u.frag
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1018
        fontSize = f.fontSize
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1019
        if calcBounds:
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1020
            cbDefn = getattr(f,'cbDefn',None)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1021
            if getattr(cbDefn,'width',0):
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3373
diff changeset
  1022
                descent, ascent = imgVRange(imgNormV(cbDefn.height,fontSize),cbDefn.valign,fontSize)
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1023
            else:
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1024
                ascent, descent = getAscentDescent(f.fontName,fontSize)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1025
        else:
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1026
            ascent, descent = getAscentDescent(f.fontName,fontSize)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1027
        maxSize = max(maxSize,fontSize)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1028
        maxAscent = max(maxAscent,ascent)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1029
        minDescent = min(minDescent,descent)
3781
df8b57380768 import from reportlab.lib.lib.rl_accel
robin
parents: 3761
diff changeset
  1030
        if not sameFrag(f0,f):
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1031
            f0=f0.clone()
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
  1032
            f0.text = u''.join(CW)
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1033
            words.append(f0)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1034
            CW = []
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1035
            f0 = f
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1036
        CW.append(u)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1037
    if CW:
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1038
        f0=f0.clone()
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
  1039
        f0.text = u''.join(CW)
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1040
        words.append(f0)
3624
c85cbc87b630 paragraph.py: fix CJK + endDots
rgbecker
parents: 3617
diff changeset
  1041
    return FragLine(kind=1,extraSpace=extraSpace,wordCount=1,words=words[1:],fontSize=maxSize,ascent=maxAscent,descent=minDescent,maxWidth=maxWidth,currentWidth=widthUsed,lineBreak=lineBreak)
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1042
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1043
def cjkFragSplit(frags, maxWidths, calcBounds, encoding='utf8'):
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1044
    '''This attempts to be wordSplit for frags using the dumb algorithm'''
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1045
    U = []  #get a list of single glyphs with their widths etc etc
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1046
    for f in frags:
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1047
        text = f.text
3921
4fab94274861 paragraph.py: fix some things that used to be unicode etc etc
robin
parents: 3888
diff changeset
  1048
        if isBytes(text):
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1049
            text = text.decode(encoding)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1050
        if text:
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1051
            U.extend([cjkU(t,f,encoding) for t in text])
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1052
        else:
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1053
            U.append(cjkU(text,f,encoding))
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1054
    lines = []
3156
b696c4ce59a8 paragraph.py: attempt to fix up the br tag for CJK
rgbecker
parents: 3154
diff changeset
  1055
    i = widthUsed = lineStartPos = 0
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1056
    maxWidth = maxWidths[0]
3156
b696c4ce59a8 paragraph.py: attempt to fix up the br tag for CJK
rgbecker
parents: 3154
diff changeset
  1057
    nU = len(U)
b696c4ce59a8 paragraph.py: attempt to fix up the br tag for CJK
rgbecker
parents: 3154
diff changeset
  1058
    while i<nU:
b696c4ce59a8 paragraph.py: attempt to fix up the br tag for CJK
rgbecker
parents: 3154
diff changeset
  1059
        u = U[i]
b696c4ce59a8 paragraph.py: attempt to fix up the br tag for CJK
rgbecker
parents: 3154
diff changeset
  1060
        i += 1
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1061
        w = u.width
3438
3cac4523a459 paragraph.py: fix cjk breaking for <img width='x%'
rgbecker
parents: 3434
diff changeset
  1062
        if hasattr(w,'normalizedValue'):
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3373
diff changeset
  1063
            w._normalizer = maxWidth
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4313
diff changeset
  1064
            w = w.normalizedValue(maxWidth)
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1065
        widthUsed += w
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1066
        lineBreak = hasattr(u.frag,'lineBreak')
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1067
        endLine = (widthUsed>maxWidth + _FUZZ and widthUsed>0) or lineBreak
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1068
        if endLine:
3156
b696c4ce59a8 paragraph.py: attempt to fix up the br tag for CJK
rgbecker
parents: 3154
diff changeset
  1069
            extraSpace = maxWidth - widthUsed
b696c4ce59a8 paragraph.py: attempt to fix up the br tag for CJK
rgbecker
parents: 3154
diff changeset
  1070
            if not lineBreak:
3547
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1071
                if ord(u)<0x3000:
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1072
                    # we appear to be inside a non-Asian script section.
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1073
                    # (this is a very crude test but quick to compute).
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1074
                    # This is likely to be quite rare so the speed of the
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1075
                    # code below is hopefully not a big issue.  The main
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1076
                    # situation requiring this is that a document title
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1077
                    # with an english product name in it got cut.
3559
fb200750d086 paragraph.py: remove unwanted code
rgbecker
parents: 3555
diff changeset
  1078
fb200750d086 paragraph.py: remove unwanted code
rgbecker
parents: 3555
diff changeset
  1079
fb200750d086 paragraph.py: remove unwanted code
rgbecker
parents: 3555
diff changeset
  1080
                    # we count back and look for
3547
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1081
                    #  - a space-like character
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1082
                    #  - reversion to Kanji (which would be a good split point)
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1083
                    #  - in the worst case, roughly half way back along the line
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1084
                    limitCheck = (lineStartPos+i)>>1        #(arbitrary taste issue)
4156
e71d19a8699c modify backColor layout behaviour, fix single span backColor, bump to 3.1.43
robin
parents: 4136
diff changeset
  1085
                    for j in xrange(i-1,limitCheck,-1):
3547
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1086
                        uj = U[j]
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1087
                        if uj and category(uj)=='Zs' or ord(uj)>=0x3000:
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1088
                            k = j+1
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1089
                            if k<i:
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1090
                                j = k+1
4156
e71d19a8699c modify backColor layout behaviour, fix single span backColor, bump to 3.1.43
robin
parents: 4136
diff changeset
  1091
                                extraSpace += sum(U[ii].width for ii in xrange(j,i))
3547
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1092
                                w = U[k].width
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1093
                                u = U[k]
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1094
                                i = j
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1095
                                break
6d9cf43ebf9d western character modificaton for CJK splitting
rgbecker
parents: 3540
diff changeset
  1096
3492
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3489
diff changeset
  1097
                #we are pushing this character back, but
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3489
diff changeset
  1098
                #the most important of the Japanese typography rules
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3489
diff changeset
  1099
                #if this character cannot start a line, wrap it up to this line so it hangs
3156
b696c4ce59a8 paragraph.py: attempt to fix up the br tag for CJK
rgbecker
parents: 3154
diff changeset
  1100
                #in the right margin. We won't do two or more though - that's unlikely and
b696c4ce59a8 paragraph.py: attempt to fix up the br tag for CJK
rgbecker
parents: 3154
diff changeset
  1101
                #would result in growing ugliness.
3489
5a3b2a822a33 paragraph.py: improve cjk frag splitting
rgbecker
parents: 3476
diff changeset
  1102
                #and increase the extra space
5a3b2a822a33 paragraph.py: improve cjk frag splitting
rgbecker
parents: 3476
diff changeset
  1103
                #bug fix contributed by Alexander Vasilenko <alexs.vasilenko@gmail.com>
3492
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3489
diff changeset
  1104
                if u not in ALL_CANNOT_START and i>lineStartPos+1:
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3489
diff changeset
  1105
                    #otherwise we need to push the character back
9f7288085d44 reportlab: fix support for cjk splitting
rgbecker
parents: 3489
diff changeset
  1106
                    #the i>lineStart+1 condition ensures progress
3489
5a3b2a822a33 paragraph.py: improve cjk frag splitting
rgbecker
parents: 3476
diff changeset
  1107
                    i -= 1
5a3b2a822a33 paragraph.py: improve cjk frag splitting
rgbecker
parents: 3476
diff changeset
  1108
                    extraSpace += w
3624
c85cbc87b630 paragraph.py: fix CJK + endDots
rgbecker
parents: 3617
diff changeset
  1109
            lines.append(makeCJKParaLine(U[lineStartPos:i],maxWidth,widthUsed,extraSpace,lineBreak,calcBounds))
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1110
            try:
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1111
                maxWidth = maxWidths[len(lines)]
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1112
            except IndexError:
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1113
                maxWidth = maxWidths[-1]  # use the last one
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1114
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1115
            lineStartPos = i
3489
5a3b2a822a33 paragraph.py: improve cjk frag splitting
rgbecker
parents: 3476
diff changeset
  1116
            widthUsed = 0
3156
b696c4ce59a8 paragraph.py: attempt to fix up the br tag for CJK
rgbecker
parents: 3154
diff changeset
  1117
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1118
    #any characters left?
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1119
    if widthUsed > 0:
3624
c85cbc87b630 paragraph.py: fix CJK + endDots
rgbecker
parents: 3617
diff changeset
  1120
        lines.append(makeCJKParaLine(U[lineStartPos:],maxWidth,widthUsed,maxWidth-widthUsed,False,calcBounds))
2940
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1121
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1122
    return ParaLines(kind=1,lines=lines)
a0e54b5117ce reportlab: add multi-frag cjk
rgbecker
parents: 2938
diff changeset
  1123
131
72cb089e6fda Removed from layout.py
rgbecker
parents:
diff changeset
  1124
class Paragraph(Flowable):
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
  1125
    """ 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
  1126
        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
  1127
        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
  1128
        bulletText is an optional bullet defintion.
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1915
diff changeset
  1129
        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
  1130
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1131
        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
  1132
        into a paragraph with a given style.
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
  1133
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1134
        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
  1135
        <b> ... </b> - bold
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
  1136
        < u [color="red"] [width="pts"] [offset="pts"]> < /u > - underline
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
  1137
            width and offset can be empty meaning use existing canvas line width
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
  1138
            or with an f/F suffix regarded as a fraction of the font size
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4387
diff changeset
  1139
        < strike > < /strike > - strike through has the same parameters as underline
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1140
        <i> ... </i> - italics
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1141
        <u> ... </u> - underline
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2598
diff changeset
  1142
        <strike> ... </strike> - strike through
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1143
        <super> ... </super> - superscript
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1144
        <sub> ... </sub> - subscript
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1398
diff changeset
  1145
        <font name=fontfamily/fontname color=colorname s