src/reportlab/platypus/paraparser.py
author robin <robin@reportlab.com>
Fri, 23 Mar 2018 16:02:08 +0000
changeset 4389 61a7f0840d00
parent 4370 823a8c33ce43
child 4410 bd848827483f
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: 4315
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2017
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 433
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/paraparser.py
4252
fe660f227cac changes for release 3.3.0
robin
parents: 4249
diff changeset
     4
__version__='3.3.0'
3032
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 2964
diff changeset
     5
__doc__='''The parser used to process markup within paragraphs'''
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
     6
import string
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
     7
import re
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
     8
import sys
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
     9
import os
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    10
import copy
3187
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
    11
import base64
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
    12
from pprint import pprint as pp
4367
9960d82643bf remove ascii, cmp & xrange builtins abuse; version-->3.4.15
robin <robin@reportlab.com>
parents: 4330
diff changeset
    13
from reportlab import ascii
2693
3c61a57aecd1 missing import statement
andy
parents: 2670
diff changeset
    14
import unicodedata
279
e7d8b3631d5c Global sequencer put in the 'story builder'.
andy_robinson
parents: 267
diff changeset
    15
import reportlab.lib.sequencer
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
    16
518
5be3fcb26c78 Semantic Name changes
rgbecker
parents: 514
diff changeset
    17
from reportlab.lib.abag import ABag
4220
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    18
from reportlab.lib.utils import ImageReader, isPy3, annotateException, encode_label, asUnicode, asBytes, uniChr, isStr
248
c103b7a55e79 Color fixes; thanks to J Alet
rgbecker
parents: 238
diff changeset
    19
from reportlab.lib.colors import toColor, white, black, red, Color
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    20
from reportlab.lib.fonts import tt2ps, ps2tt
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
    21
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    22
from reportlab.lib.units import inch,mm,cm,pica
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: 4370
diff changeset
    23
from reportlab.rl_config import platypus_link_underline
3955
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    24
if isPy3:
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    25
    from html.parser import HTMLParser
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    26
    from html.entities import name2codepoint
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    27
else:
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    28
    from HTMLParser import HTMLParser
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    29
    from htmlentitydefs import name2codepoint
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    30
2410
f505ed647678 reportlab: add fix for <para/> and new test
rgbecker
parents: 2376
diff changeset
    31
_re_para = re.compile(r'^\s*<\s*para(?:\s+|>|/>)')
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    32
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    33
sizeDelta = 2       # amount to reduce font size by for super and sub script
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    34
subFraction = 0.5   # fraction of font size that a sub script should be lowered
4249
8fc7d11bdee0 add support for rml <sup>/<sub> rise and size attributes; version --> 3.2.17
robin
parents: 4220
diff changeset
    35
supFraction = 0.5 # fraction of font size that a super script should be raised
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    36
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
    37
DEFAULT_INDEX_NAME='_indexAdd'
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
    38
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    39
def _convnum(s, unit=1, allowRelative=True):
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    40
    if s[0] in ('+','-') and allowRelative:
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    41
        try:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    42
            return ('relative',int(s)*unit)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    43
        except ValueError:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    44
            return ('relative',float(s)*unit)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    45
    else:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    46
        try:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    47
            return int(s)*unit
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    48
        except ValueError:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    49
            return float(s)*unit
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    50
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: 4370
diff changeset
    51
def _num(s, unit=1, allowRelative=True,
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: 4370
diff changeset
    52
        _unit_map = {'i':inch,'in':inch,'pt':1,'cm':cm,'mm':mm,'pica':pica },
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: 4370
diff changeset
    53
        _re_unit = re.compile('^\s*(.*)(i|in|cm|mm|pt|pica)\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: 4370
diff changeset
    54
        ):
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    55
    """Convert a string like '10cm' to an int or float (in points).
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    56
       The default unit is point, but optionally you can use other
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    57
       default units like mm.
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    58
    """
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: 4370
diff changeset
    59
    m = _re_unit.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: 4370
diff changeset
    60
    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: 4370
diff changeset
    61
        unit = _unit_map[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: 4370
diff changeset
    62
        s = m.group(1)
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    63
    return _convnum(s,unit,allowRelative)
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    64
4220
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    65
def _int(s):
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    66
    try:
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    67
        return int(s)
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    68
    except:
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    69
        raise ValueError('cannot convert %r to int' % s)
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    70
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    71
def _bool(s):
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    72
    s = s.lower()
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    73
    if s in ('true','1','yes'):
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    74
        return True
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    75
    if s in ('false','0','no'):
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    76
        return False
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    77
    raise ValueError('cannot convert %r to bool value' % s)
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
    78
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    79
def _numpct(s,unit=1,allowRelative=False):
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    80
    if s.endswith('%'):
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    81
        return _PCT(_convnum(s[:-1],allowRelative=allowRelative))
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    82
    else:
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    83
        return _num(s,unit,allowRelative)
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    84
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4277
diff changeset
    85
class _PCT(float):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4277
diff changeset
    86
    def __new__(cls,v):
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4277
diff changeset
    87
        self = float.__new__(cls,v*0.01)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4277
diff changeset
    88
        self._normalizer = 1.0
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4277
diff changeset
    89
        self._value = v
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4277
diff changeset
    90
        return self
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    91
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    92
    def normalizedValue(self,normalizer):
4315
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4277
diff changeset
    93
        if not normalizer:
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4277
diff changeset
    94
            normaliser = self._normalizer
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4277
diff changeset
    95
        r = _PCT(normalizer*self._value)
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4277
diff changeset
    96
        r._value = self._value
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4277
diff changeset
    97
        r._normalizer = normalizer
7c65c6e52b13 fix paragraph splitting bug (reporters Olivia Zhang & Echo Bell); version-->3.3.31
robin <robin@reportlab.com>
parents: 4277
diff changeset
    98
        return r
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    99
4255
89ea1d46b4a0 make paraparser syntax errors real and fix <sup/sub> tags to have relative values; version-->3.3.1
robin
parents: 4252
diff changeset
   100
def fontSizeNormalize(frag,attr,default):
89ea1d46b4a0 make paraparser syntax errors real and fix <sup/sub> tags to have relative values; version-->3.3.1
robin
parents: 4252
diff changeset
   101
    if not hasattr(frag,attr): return default
89ea1d46b4a0 make paraparser syntax errors real and fix <sup/sub> tags to have relative values; version-->3.3.1
robin
parents: 4252
diff changeset
   102
    v = _numpct(getattr(frag,attr),allowRelative=True)
89ea1d46b4a0 make paraparser syntax errors real and fix <sup/sub> tags to have relative values; version-->3.3.1
robin
parents: 4252
diff changeset
   103
    return (v[1]+frag.fontSize) if isinstance(v,tuple) else v.normalizedValue(frag.fontSize) if isinstance(v,_PCT) else v
89ea1d46b4a0 make paraparser syntax errors real and fix <sup/sub> tags to have relative values; version-->3.3.1
robin
parents: 4252
diff changeset
   104
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: 4370
diff changeset
   105
class _ExValidate:
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: 4370
diff changeset
   106
    '''class for syntax checking attributes
4255
89ea1d46b4a0 make paraparser syntax errors real and fix <sup/sub> tags to have relative values; version-->3.3.1
robin
parents: 4252
diff changeset
   107
    '''
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: 4370
diff changeset
   108
    def __init__(self,tag,attr):
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: 4370
diff changeset
   109
        self.tag = tag
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: 4370
diff changeset
   110
        self.attr = attr
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: 4370
diff changeset
   111
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: 4370
diff changeset
   112
    def invalid(self,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: 4370
diff changeset
   113
        raise ValueError('<%s> invalid value %r for attribute %s' % (self.tag,s,self.attr))
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: 4370
diff changeset
   114
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: 4370
diff changeset
   115
    def validate(self, parser,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: 4370
diff changeset
   116
        raise ValueError('abstract method called')
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: 4370
diff changeset
   117
        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: 4370
diff changeset
   118
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: 4370
diff changeset
   119
    def __call__(self, parser, 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: 4370
diff changeset
   120
        try:
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: 4370
diff changeset
   121
            return self.validate(parser, 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: 4370
diff changeset
   122
        except:
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: 4370
diff changeset
   123
            self.invalid(s)
4255
89ea1d46b4a0 make paraparser syntax errors real and fix <sup/sub> tags to have relative values; version-->3.3.1
robin
parents: 4252
diff changeset
   124
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: 4370
diff changeset
   125
class _CheckSup(_ExValidate):
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: 4370
diff changeset
   126
    '''class for syntax checking <sup|sub> attributes
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: 4370
diff changeset
   127
    if the check succeeds then we always return the string for later evaluation'''
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: 4370
diff changeset
   128
    def validate(self,parser,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: 4370
diff changeset
   129
        self.fontSize = parser._stack[-1].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: 4370
diff changeset
   130
        fontSizeNormalize(self,self.attr,'')
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: 4370
diff changeset
   131
        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: 4370
diff changeset
   132
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: 4370
diff changeset
   133
    def __call__(self, parser, 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: 4370
diff changeset
   134
        setattr(self,self.attr,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: 4370
diff changeset
   135
        return _ExValidate.__call__(self,parser,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: 4370
diff changeset
   136
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: 4370
diff changeset
   137
_lineRepeats = dict(single=1,double=2,triple=3)
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: 4370
diff changeset
   138
_re_us_value = re.compile(r'^\s*(.*)\s*\*\s*(P|L|f|F)\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: 4370
diff changeset
   139
class _CheckUS(_ExValidate):
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: 4370
diff changeset
   140
    '''class for syntax checking <u|strike> width/offset attributes'''
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: 4370
diff changeset
   141
    def validate(self,parser,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: 4370
diff changeset
   142
        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: 4370
diff changeset
   143
        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: 4370
diff changeset
   144
            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: 4370
diff changeset
   145
            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: 4370
diff changeset
   146
                v = float(m.group(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: 4370
diff changeset
   147
                if m.group(2)=='P':
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: 4370
diff changeset
   148
                    return parser._stack[0].fontSize*v
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: 4370
diff changeset
   149
            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: 4370
diff changeset
   150
                _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: 4370
diff changeset
   151
        return s
4255
89ea1d46b4a0 make paraparser syntax errors real and fix <sup/sub> tags to have relative values; version-->3.3.1
robin
parents: 4252
diff changeset
   152
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   153
def _valignpc(s):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   154
    s = s.lower()
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   155
    if s in ('baseline','sub','super','top','text-top','middle','bottom','text-bottom'):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   156
        return s
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   157
    if s.endswith('%'):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   158
        n = _convnum(s[:-1])
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   159
        if isinstance(n,tuple):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   160
            n = n[1]
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   161
        return _PCT(n)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   162
    n = _num(s)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   163
    if isinstance(n,tuple):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   164
        n = n[1]
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   165
    return n
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   166
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   167
def _autoLeading(x):
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   168
    x = x.lower()
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   169
    if x in ('','min','max','off'):
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   170
        return x
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   171
    raise ValueError('Invalid autoLeading=%r' % x )
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   172
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   173
def _align(s):
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3723
diff changeset
   174
    s = s.lower()
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   175
    if s=='left': return TA_LEFT
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   176
    elif s=='right': return TA_RIGHT
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   177
    elif s=='justify': return TA_JUSTIFY
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   178
    elif s in ('centre','center'): return TA_CENTER
4136
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4130
diff changeset
   179
    else: raise ValueError('illegal alignment %r' % s)
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4130
diff changeset
   180
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4130
diff changeset
   181
def _bAnchor(s):
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4130
diff changeset
   182
    s = s.lower()
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4130
diff changeset
   183
    if not s in ('start','middle','end','numeric'):
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4130
diff changeset
   184
        raise ValueError('illegal bullet anchor %r' % s)
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4130
diff changeset
   185
    return s
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   186
4220
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   187
def _wordWrapConv(s):
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   188
    s = s.upper().strip()
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   189
    if not s: return None
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   190
    if s not in ('CJK','RTL','LTR'):
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   191
        raise ValueError('cannot convert wordWrap=%r' % s)
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   192
    return s
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   193
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   194
def _textTransformConv(s):
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   195
    s = s.lower().strip()
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   196
    if not s: return None
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   197
    if s not in ('uppercase','lowercase','capitalize','none'):
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   198
        raise ValueError('cannot convert wordWrap=%r' % s)
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   199
    return s
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   200
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   201
_paraAttrMap = {'font': ('fontName', None),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   202
                'face': ('fontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   203
                'fontsize': ('fontSize', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   204
                'size': ('fontSize', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   205
                'leading': ('leading', _num),
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   206
                'autoleading': ('autoLeading', _autoLeading),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   207
                'lindent': ('leftIndent', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   208
                'rindent': ('rightIndent', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   209
                'findent': ('firstLineIndent', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   210
                'align': ('alignment', _align),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   211
                'spaceb': ('spaceBefore', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   212
                'spacea': ('spaceAfter', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   213
                'bfont': ('bulletFontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   214
                'bfontsize': ('bulletFontSize',_num),
2860
3f14d66194c2 platypus: added bulletOffsetY inspired by haraldarminmassa@gmail.com
rgbecker
parents: 2857
diff changeset
   215
                'boffsety': ('bulletOffsetY',_num),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   216
                'bindent': ('bulletIndent',_num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   217
                'bcolor': ('bulletColor',toColor),
4136
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4130
diff changeset
   218
                'banchor': ('bulletAnchor',_bAnchor),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   219
                'color':('textColor',toColor),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   220
                'backcolor':('backColor',toColor),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   221
                'bgcolor':('backColor',toColor),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   222
                'bg':('backColor',toColor),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   223
                'fg': ('textColor',toColor),
4220
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   224
                'justifybreaks': ('justifyBreaks',_bool),
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   225
                'justifylastline': ('justifyLastLine',_int),
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   226
                'wordwrap': ('wordWrap',_wordWrapConv),
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   227
                'allowwidows': ('allowWidows',_bool),
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   228
                'alloworphans': ('allowOrphans',_bool),
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   229
                'splitlongwords': ('splitLongWords',_bool),
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   230
                'borderwidth': ('borderWidth',_num),
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   231
                'borderpadding': ('borderpadding',_num),
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   232
                'bordercolor': ('borderColor',toColor),
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   233
                'borderradius': ('borderRadius',_num),
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   234
                'texttransform':('textTransform',_textTransformConv),
c0e82d246798 add justifyBreaks & justifyLastLine ParagraphStyle attributes; version-->3.2.7
robin
parents: 4181
diff changeset
   235
                'enddots':('endDots',None),
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: 4370
diff changeset
   236
                'underlinewidth':('underlineWidth',_CheckUS('para','underlineWidth')),
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: 4370
diff changeset
   237
                'underlinecolor':('underlineColor',toColor),
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: 4370
diff changeset
   238
                'underlineoffset':('underlineOffset',_CheckUS('para','underlineOffset')),
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: 4370
diff changeset
   239
                'underlinegap':('underlineGap',_CheckUS('para','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: 4370
diff changeset
   240
                'strikewidth':('strikeWidth',_CheckUS('para','strikeWidth')),
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: 4370
diff changeset
   241
                'strikecolor':('strikeColor',toColor),
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: 4370
diff changeset
   242
                'strikeoffset':('strikeOffset',_CheckUS('para','strikeOffset')),
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: 4370
diff changeset
   243
                'strikegap':('strikeGap',_CheckUS('para','strikeGap')),
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4255
diff changeset
   244
                'spaceshrinkage':('spaceShrinkage',_num),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   245
                }
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   246
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   247
_bulletAttrMap = {
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   248
                'font': ('bulletFontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   249
                'face': ('bulletFontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   250
                'size': ('bulletFontSize',_num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   251
                'fontsize': ('bulletFontSize',_num),
2860
3f14d66194c2 platypus: added bulletOffsetY inspired by haraldarminmassa@gmail.com
rgbecker
parents: 2857
diff changeset
   252
                'offsety': ('bulletOffsetY',_num),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   253
                'indent': ('bulletIndent',_num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   254
                'color': ('bulletColor',toColor),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   255
                'fg': ('bulletColor',toColor),
4136
16f067cf3dae added rl_settings.decimalSymbol & support for simple bullet anchoring, version-->3.1.35
robin
parents: 4130
diff changeset
   256
                'anchor': ('bulletAnchor',_bAnchor),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   257
                }
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   258
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   259
#things which are valid font attributes
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   260
_fontAttrMap = {'size': ('fontSize', _num),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   261
                'face': ('fontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   262
                'name': ('fontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   263
                'fg':   ('textColor', toColor),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   264
                'color':('textColor', toColor),
2446
6b9268ab33c3 allow solid para background
andy
parents: 2410
diff changeset
   265
                'backcolor':('backColor',toColor),
6b9268ab33c3 allow solid para background
andy
parents: 2410
diff changeset
   266
                'bgcolor':('backColor',toColor),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   267
                }
3552
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   268
#things which are valid span attributes
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   269
_spanAttrMap = {'size': ('fontSize', _num),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   270
                'face': ('fontName', None),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   271
                'name': ('fontName', None),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   272
                'fg':   ('textColor', toColor),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   273
                'color':('textColor', toColor),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   274
                'backcolor':('backColor',toColor),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   275
                'bgcolor':('backColor',toColor),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   276
                'style': ('style',None),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   277
                }
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   278
#things which are valid font attributes
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   279
_linkAttrMap = {'size': ('fontSize', _num),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   280
                'face': ('fontName', None),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   281
                'name': ('fontName', None),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   282
                'fg':   ('textColor', toColor),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   283
                'color':('textColor', toColor),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   284
                'backcolor':('backColor',toColor),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   285
                'bgcolor':('backColor',toColor),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   286
                'dest': ('link', None),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   287
                'destination': ('link', None),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   288
                'target': ('link', None),
2594
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2585
diff changeset
   289
                'href': ('link', None),
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: 4370
diff changeset
   290
                'ucolor': ('underlineColor', toColor),
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: 4370
diff changeset
   291
                'uoffset': ('underlineOffset', _CheckUS('link','underlineOffset')),
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: 4370
diff changeset
   292
                'uwidth': ('underlineWidth', _CheckUS('link','underlineWidth')),
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: 4370
diff changeset
   293
                'ugap': ('underlineGap', _CheckUS('link','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: 4370
diff changeset
   294
                'underline': ('underline',_bool),
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: 4370
diff changeset
   295
                'ukind': ('underlineKind',None),
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   296
                }
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: 4370
diff changeset
   297
_anchorAttrMap = {
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   298
                'name': ('name', None),
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   299
                }
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   300
_imgAttrMap = {
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   301
                'src': ('src', None),
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
   302
                'width': ('width',_numpct),
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
   303
                'height':('height',_numpct),
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   304
                'valign':('valign',_valignpc),
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   305
                }
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   306
_indexAttrMap = {
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   307
                'name': ('name',None),
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   308
                'item': ('item',None),
3187
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
   309
                'offset': ('offset',None),
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
   310
                'format': ('format',None),
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   311
                }
4249
8fc7d11bdee0 add support for rml <sup>/<sub> rise and size attributes; version --> 3.2.17
robin
parents: 4220
diff changeset
   312
_supAttrMap = {
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: 4370
diff changeset
   313
                'rise': ('supr', _CheckSup('sup|sub','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: 4370
diff changeset
   314
                'size': ('sups', _CheckSup('sup|sub','size')),
4249
8fc7d11bdee0 add support for rml <sup>/<sub> rise and size attributes; version --> 3.2.17
robin
parents: 4220
diff changeset
   315
                }
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: 4370
diff changeset
   316
_uAttrMap = {
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: 4370
diff changeset
   317
            'color':('underlineColor', toColor),
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: 4370
diff changeset
   318
            'width':('underlineWidth', _CheckUS('underline','underlineWidth')),
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: 4370
diff changeset
   319
            'offset':('underlineOffset', _CheckUS('underline','underlineOffset')),
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: 4370
diff changeset
   320
            'gap':('underlineGap', _CheckUS('underline','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: 4370
diff changeset
   321
            'kind':('underlineKind',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: 4370
diff changeset
   322
            }
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: 4370
diff changeset
   323
_strikeAttrMap = {
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: 4370
diff changeset
   324
            'color':('strikeColor', toColor),
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: 4370
diff changeset
   325
            'width':('strikeWidth', _CheckUS('strike','strikeWidth')),
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: 4370
diff changeset
   326
            'offset':('strikeOffset', _CheckUS('strike','strikeOffset')),
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: 4370
diff changeset
   327
            'gap':('strikeGap', _CheckUS('strike','strikeGap')),
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: 4370
diff changeset
   328
            'kind':('strikeKind',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: 4370
diff changeset
   329
            }
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   330
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   331
def _addAttributeNames(m):
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
   332
    K = list(m.keys())
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   333
    for k in K:
1944
a50f8e3f93f8 laissez faire case
rgbecker
parents: 1940
diff changeset
   334
        n = m[k][0]
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   335
        if n not in m: m[n] = m[k]
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3723
diff changeset
   336
        n = n.lower()
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   337
        if n not in m: m[n] = m[k]
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   338
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   339
_addAttributeNames(_paraAttrMap)
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   340
_addAttributeNames(_fontAttrMap)
3552
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   341
_addAttributeNames(_spanAttrMap)
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   342
_addAttributeNames(_bulletAttrMap)
2747
46005202d9d0 paraparser: fix link/anchor attributes
rgbecker
parents: 2745
diff changeset
   343
_addAttributeNames(_anchorAttrMap)
46005202d9d0 paraparser: fix link/anchor attributes
rgbecker
parents: 2745
diff changeset
   344
_addAttributeNames(_linkAttrMap)
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   345
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   346
def _applyAttributes(obj, attr):
3723
99aa837b6703 second stage of port to Python 3.3; working hello world
rptlab
parents: 3721
diff changeset
   347
    for k, v in attr.items():
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   348
        if isinstance(v,(list,tuple)) and v[0]=='relative':
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   349
            if hasattr(obj, k):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   350
                v = v[1]+getattr(obj,k)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   351
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   352
                v = v[1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   353
        setattr(obj,k,v)
102
1818e7fa3738 Added clone method to ParaFrag
rgbecker
parents: 96
diff changeset
   354
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   355
#Named character entities intended to be supported from the special font
2200
be0cfccc662a Fixed up tabs and whitespace in all source files
andy_robinson
parents: 2053
diff changeset
   356
#with additions suggested by Christoph Zwerschke who also suggested the
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   357
#numeric entity names that follow.
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   358
greeks = {
3957
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   359
    'Aacute': u'\xc1',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   360
    'aacute': u'\xe1',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   361
    'Acirc': u'\xc2',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   362
    'acirc': u'\xe2',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   363
    'acute': u'\xb4',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   364
    'AElig': u'\xc6',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   365
    'aelig': u'\xe6',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   366
    'Agrave': u'\xc0',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   367
    'agrave': u'\xe0',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   368
    'alefsym': u'\u2135',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   369
    'Alpha': u'\u0391',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   370
    'alpha': u'\u03b1',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   371
    'and': u'\u2227',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   372
    'ang': u'\u2220',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   373
    'Aring': u'\xc5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   374
    'aring': u'\xe5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   375
    'asymp': u'\u2248',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   376
    'Atilde': u'\xc3',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   377
    'atilde': u'\xe3',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   378
    'Auml': u'\xc4',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   379
    'auml': u'\xe4',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   380
    'bdquo': u'\u201e',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   381
    'Beta': u'\u0392',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   382
    'beta': u'\u03b2',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   383
    'brvbar': u'\xa6',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   384
    'bull': u'\u2022',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   385
    'cap': u'\u2229',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   386
    'Ccedil': u'\xc7',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   387
    'ccedil': u'\xe7',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   388
    'cedil': u'\xb8',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   389
    'cent': u'\xa2',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   390
    'Chi': u'\u03a7',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   391
    'chi': u'\u03c7',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   392
    'circ': u'\u02c6',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   393
    'clubs': u'\u2663',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   394
    'cong': u'\u2245',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   395
    'copy': u'\xa9',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   396
    'crarr': u'\u21b5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   397
    'cup': u'\u222a',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   398
    'curren': u'\xa4',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   399
    'dagger': u'\u2020',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   400
    'Dagger': u'\u2021',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   401
    'darr': u'\u2193',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   402
    'dArr': u'\u21d3',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   403
    'deg': u'\xb0',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   404
    'delta': u'\u03b4',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   405
    'Delta': u'\u2206',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   406
    'diams': u'\u2666',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   407
    'divide': u'\xf7',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   408
    'Eacute': u'\xc9',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   409
    'eacute': u'\xe9',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   410
    'Ecirc': u'\xca',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   411
    'ecirc': u'\xea',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   412
    'Egrave': u'\xc8',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   413
    'egrave': u'\xe8',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   414
    'empty': u'\u2205',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   415
    'emsp': u'\u2003',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   416
    'ensp': u'\u2002',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   417
    'Epsilon': u'\u0395',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   418
    'epsilon': u'\u03b5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   419
    'epsiv': u'\u03b5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   420
    'equiv': u'\u2261',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   421
    'Eta': u'\u0397',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   422
    'eta': u'\u03b7',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   423
    'ETH': u'\xd0',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   424
    'eth': u'\xf0',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   425
    'Euml': u'\xcb',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   426
    'euml': u'\xeb',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   427
    'euro': u'\u20ac',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   428
    'exist': u'\u2203',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   429
    'fnof': u'\u0192',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   430
    'forall': u'\u2200',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   431
    'frac12': u'\xbd',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   432
    'frac14': u'\xbc',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   433
    'frac34': u'\xbe',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   434
    'frasl': u'\u2044',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   435
    'Gamma': u'\u0393',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   436
    'gamma': u'\u03b3',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   437
    'ge': u'\u2265',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   438
    'harr': u'\u2194',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   439
    'hArr': u'\u21d4',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   440
    'hearts': u'\u2665',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   441
    'hellip': u'\u2026',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   442
    'Iacute': u'\xcd',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   443
    'iacute': u'\xed',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   444
    'Icirc': u'\xce',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   445
    'icirc': u'\xee',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   446
    'iexcl': u'\xa1',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   447
    'Igrave': u'\xcc',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   448
    'igrave': u'\xec',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   449
    'image': u'\u2111',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   450
    'infin': u'\u221e',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   451
    'int': u'\u222b',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   452
    'Iota': u'\u0399',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   453
    'iota': u'\u03b9',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   454
    'iquest': u'\xbf',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   455
    'isin': u'\u2208',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   456
    'Iuml': u'\xcf',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   457
    'iuml': u'\xef',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   458
    'Kappa': u'\u039a',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   459
    'kappa': u'\u03ba',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   460
    'Lambda': u'\u039b',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   461
    'lambda': u'\u03bb',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   462
    'lang': u'\u2329',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   463
    'laquo': u'\xab',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   464
    'larr': u'\u2190',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   465
    'lArr': u'\u21d0',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   466
    'lceil': u'\uf8ee',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   467
    'ldquo': u'\u201c',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   468
    'le': u'\u2264',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   469
    'lfloor': u'\uf8f0',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   470
    'lowast': u'\u2217',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   471
    'loz': u'\u25ca',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   472
    'lrm': u'\u200e',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   473
    'lsaquo': u'\u2039',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   474
    'lsquo': u'\u2018',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   475
    'macr': u'\xaf',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   476
    'mdash': u'\u2014',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   477
    'micro': u'\xb5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   478
    'middot': u'\xb7',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   479
    'minus': u'\u2212',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   480
    'mu': u'\xb5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   481
    'Mu': u'\u039c',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   482
    'nabla': u'\u2207',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   483
    'nbsp': u'\xa0',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   484
    'ndash': u'\u2013',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   485
    'ne': u'\u2260',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   486
    'ni': u'\u220b',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   487
    'notin': u'\u2209',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   488
    'not': u'\xac',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   489
    'nsub': u'\u2284',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   490
    'Ntilde': u'\xd1',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   491
    'ntilde': u'\xf1',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   492
    'Nu': u'\u039d',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   493
    'nu': u'\u03bd',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   494
    'Oacute': u'\xd3',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   495
    'oacute': u'\xf3',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   496
    'Ocirc': u'\xd4',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   497
    'ocirc': u'\xf4',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   498
    'OElig': u'\u0152',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   499
    'oelig': u'\u0153',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   500
    'Ograve': u'\xd2',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   501
    'ograve': u'\xf2',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   502
    'oline': u'\uf8e5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   503
    'omega': u'\u03c9',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   504
    'Omega': u'\u2126',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   505
    'Omicron': u'\u039f',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   506
    'omicron': u'\u03bf',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   507
    'oplus': u'\u2295',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   508
    'ordf': u'\xaa',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   509
    'ordm': u'\xba',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   510
    'or': u'\u2228',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   511
    'Oslash': u'\xd8',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   512
    'oslash': u'\xf8',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   513
    'Otilde': u'\xd5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   514
    'otilde': u'\xf5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   515
    'otimes': u'\u2297',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   516
    'Ouml': u'\xd6',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   517
    'ouml': u'\xf6',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   518
    'para': u'\xb6',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   519
    'part': u'\u2202',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   520
    'permil': u'\u2030',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   521
    'perp': u'\u22a5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   522
    'phis': u'\u03c6',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   523
    'Phi': u'\u03a6',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   524
    'phi': u'\u03d5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   525
    'piv': u'\u03d6',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   526
    'Pi': u'\u03a0',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   527
    'pi': u'\u03c0',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   528
    'plusmn': u'\xb1',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   529
    'pound': u'\xa3',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   530
    'prime': u'\u2032',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   531
    'Prime': u'\u2033',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   532
    'prod': u'\u220f',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   533
    'prop': u'\u221d',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   534
    'Psi': u'\u03a8',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   535
    'psi': u'\u03c8',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   536
    'radic': u'\u221a',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   537
    'rang': u'\u232a',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   538
    'raquo': u'\xbb',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   539
    'rarr': u'\u2192',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   540
    'rArr': u'\u21d2',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   541
    'rceil': u'\uf8f9',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   542
    'rdquo': u'\u201d',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   543
    'real': u'\u211c',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   544
    'reg': u'\xae',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   545
    'rfloor': u'\uf8fb',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   546
    'Rho': u'\u03a1',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   547
    'rho': u'\u03c1',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   548
    'rlm': u'\u200f',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   549
    'rsaquo': u'\u203a',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   550
    'rsquo': u'\u2019',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   551
    'sbquo': u'\u201a',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   552
    'Scaron': u'\u0160',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   553
    'scaron': u'\u0161',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   554
    'sdot': u'\u22c5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   555
    'sect': u'\xa7',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   556
    'shy': u'\xad',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   557
    'sigmaf': u'\u03c2',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   558
    'sigmav': u'\u03c2',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   559
    'Sigma': u'\u03a3',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   560
    'sigma': u'\u03c3',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   561
    'sim': u'\u223c',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   562
    'spades': u'\u2660',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   563
    'sube': u'\u2286',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   564
    'sub': u'\u2282',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   565
    'sum': u'\u2211',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   566
    'sup1': u'\xb9',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   567
    'sup2': u'\xb2',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   568
    'sup3': u'\xb3',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   569
    'supe': u'\u2287',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   570
    'sup': u'\u2283',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   571
    'szlig': u'\xdf',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   572
    'Tau': u'\u03a4',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   573
    'tau': u'\u03c4',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   574
    'there4': u'\u2234',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   575
    'thetasym': u'\u03d1',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   576
    'thetav': u'\u03d1',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   577
    'Theta': u'\u0398',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   578
    'theta': u'\u03b8',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   579
    'thinsp': u'\u2009',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   580
    'THORN': u'\xde',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   581
    'thorn': u'\xfe',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   582
    'tilde': u'\u02dc',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   583
    'times': u'\xd7',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   584
    'trade': u'\uf8ea',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   585
    'Uacute': u'\xda',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   586
    'uacute': u'\xfa',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   587
    'uarr': u'\u2191',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   588
    'uArr': u'\u21d1',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   589
    'Ucirc': u'\xdb',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   590
    'ucirc': u'\xfb',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   591
    'Ugrave': u'\xd9',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   592
    'ugrave': u'\xf9',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   593
    'uml': u'\xa8',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   594
    'upsih': u'\u03d2',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   595
    'Upsilon': u'\u03a5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   596
    'upsilon': u'\u03c5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   597
    'Uuml': u'\xdc',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   598
    'uuml': u'\xfc',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   599
    'weierp': u'\u2118',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   600
    'Xi': u'\u039e',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   601
    'xi': u'\u03be',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   602
    'Yacute': u'\xdd',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   603
    'yacute': u'\xfd',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   604
    'yen': u'\xa5',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   605
    'yuml': u'\xff',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   606
    'Yuml': u'\u0178',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   607
    'Zeta': u'\u0396',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   608
    'zeta': u'\u03b6',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   609
    'zwj': u'\u200d',
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   610
    'zwnj': u'\u200c',
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   611
    }
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   612
4004
ebd460ef8d2f rename utils.py UniChr --> uniChr
robin
parents: 3994
diff changeset
   613
known_entities = dict([(k,uniChr(v)) for k,v in name2codepoint.items()])
3957
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   614
for k in greeks:
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   615
    if k not in known_entities:
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   616
        known_entities[k] = greeks[k]
3994
9c38aba205e1 paraparser.py: fix entityref handling
robin
parents: 3961
diff changeset
   617
f = isPy3 and asBytes or asUnicode
9c38aba205e1 paraparser.py: fix entityref handling
robin
parents: 3961
diff changeset
   618
K = list(known_entities.keys())
9c38aba205e1 paraparser.py: fix entityref handling
robin
parents: 3961
diff changeset
   619
for k in K:
9c38aba205e1 paraparser.py: fix entityref handling
robin
parents: 3961
diff changeset
   620
    known_entities[f(k)] = known_entities[k]
9c38aba205e1 paraparser.py: fix entityref handling
robin
parents: 3961
diff changeset
   621
del k, f, K
3957
c7cedb1dde29 paraparser.py: remove usage of pyRXPU, remove attempted optimization of texts
robin
parents: 3956
diff changeset
   622
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   623
#------------------------------------------------------------------------
518
5be3fcb26c78 Semantic Name changes
rgbecker
parents: 514
diff changeset
   624
class ParaFrag(ABag):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   625
    """class ParaFrag contains the intermediate representation of string
3961
8c5743bc6489 paraparser.py: remove reference to XMLParser
robin
parents: 3957
diff changeset
   626
    segments as they are being parsed by the ParaParser.
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   627
    fontname, fontSize, rise, textColor, cbDefn
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   628
    """
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   629
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   630
_greek2Utf8=None
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   631
def _greekConvert(data):
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   632
    global _greek2Utf8
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   633
    if not _greek2Utf8:
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   634
        from reportlab.pdfbase.rl_codecs import RL_Codecs
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   635
        import codecs
3812
22a7f2e7ad1f paraparser.py: remove unused local var
robin
parents: 3809
diff changeset
   636
        #our decoding map
22a7f2e7ad1f paraparser.py: remove unused local var
robin
parents: 3809
diff changeset
   637
        dm = codecs.make_identity_dict(range(32,256))
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
   638
        for k in range(0,32):
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   639
            dm[k] = None
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   640
        dm.update(RL_Codecs._RL_Codecs__rl_codecs_data['symbol'][0])
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   641
        _greek2Utf8 = {}
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
   642
        for k,v in dm.items():
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   643
            if not v:
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   644
                u = '\0'
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   645
            else:
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   646
                if isPy3:
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   647
                    u = chr(v)
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   648
                else:
3900
056aff5b1a58 paraparser.py: fix _greekConvert for 2.7
robin
parents: 3896
diff changeset
   649
                    u = unichr(v).encode('utf8')
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   650
            _greek2Utf8[chr(k)] = u
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   651
    return ''.join(map(_greek2Utf8.__getitem__,data))
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   652
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   653
#------------------------------------------------------------------
267
52a348f6c4c3 noted replication of XML markup comment between paraparser.py and paragraph.py
aaron_watters
parents: 266
diff changeset
   654
# !!! NOTE !!! THIS TEXT IS NOW REPLICATED IN PARAGRAPH.PY !!!
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   655
# The ParaFormatter will be able to format the following
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   656
# tags:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   657
#       < /b > - bold
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   658
#       < /i > - italics
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: 4370
diff changeset
   659
#       < 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: 4370
diff changeset
   660
#           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: 4370
diff changeset
   661
#           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: 4370
diff changeset
   662
#       < strike > < /strike > - strike through has the same parameters as underline
4249
8fc7d11bdee0 add support for rml <sup>/<sub> rise and size attributes; version --> 3.2.17
robin
parents: 4220
diff changeset
   663
#       < super [size="pts"] [rise="pts"]> < /super > - superscript
8fc7d11bdee0 add support for rml <sup>/<sub> rise and size attributes; version --> 3.2.17
robin
parents: 4220
diff changeset
   664
#       < sup ="pts"] [rise="pts"]> < /sup > - superscript
8fc7d11bdee0 add support for rml <sup>/<sub> rise and size attributes; version --> 3.2.17
robin
parents: 4220
diff changeset
   665
#       < sub ="pts"] [rise="pts"]> < /sub > - subscript
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   666
#       <font name=fontfamily/fontname color=colorname size=float>
3552
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   667
#        <span name=fontfamily/fontname color=colorname backcolor=colorname size=float style=stylename>
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   668
#       < bullet > </bullet> - bullet text (at head of para only)
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   669
#       <onDraw name=callable label="a label"/>
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   670
#       <index [name="callablecanvasattribute"] label="a label"/>
2670
3fdd642a7b76 minor cosmetic changes
rgbecker
parents: 2664
diff changeset
   671
#       <link>link text</link>
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: 4370
diff changeset
   672
#           attributes of 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: 4370
diff changeset
   673
#               size/fontSize/uwidth/uoffset=num
2670
3fdd642a7b76 minor cosmetic changes
rgbecker
parents: 2664
diff changeset
   674
#               name/face/fontName=name
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: 4370
diff changeset
   675
#               fg/textColor/color/ucolor=color
2670
3fdd642a7b76 minor cosmetic changes
rgbecker
parents: 2664
diff changeset
   676
#               backcolor/backColor/bgcolor=color
3fdd642a7b76 minor cosmetic changes
rgbecker
parents: 2664
diff changeset
   677
#               dest/destination/target/href/link=target
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: 4370
diff changeset
   678
#               underline=bool turn on underline
2745
0b44535fa1a5 paraparser/paragraph.py: fix comments
rgbecker
parents: 2744
diff changeset
   679
#       <a>anchor text</a>
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: 4370
diff changeset
   680
#           attributes of anchors
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   681
#               fontSize=num
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   682
#               fontName=name
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   683
#               fg/textColor/color=color
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   684
#               backcolor/backColor/bgcolor=color
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   685
#               href=href
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   686
#       <a name="anchorpoint"/>
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   687
#       <unichar name="unicode character name"/>
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   688
#       <unichar value="unicode code point"/>
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   689
#       <img src="path" width="1in" height="1in" valign="bottom"/>
3440
739ddbe7feab paaraparser/paragraph.py: add info re percentage in <img> for idea contributed by Roberto Alsina <ralsina@netmanagers.com.ar>
rgbecker
parents: 3434
diff changeset
   690
#               width="w%" --> fontSize*w/100   idea from Roberto Alsina
739ddbe7feab paaraparser/paragraph.py: add info re percentage in <img> for idea contributed by Roberto Alsina <ralsina@netmanagers.com.ar>
rgbecker
parents: 3434
diff changeset
   691
#               height="h%" --> linewidth*h/100 <ralsina@netmanagers.com.ar>
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   692
#       <greek> - </greek>
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   693
#
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   694
#       The whole may be surrounded by <para> </para> tags
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   695
#
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   696
# It will also be able to handle any MathML specified Greek characters.
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   697
#------------------------------------------------------------------
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
   698
class ParaParser(HTMLParser):
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   699
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   700
    #----------------------------------------------------------
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   701
    # First we will define all of the xml tag handler functions.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   702
    #
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   703
    # start_<tag>(attributes)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   704
    # end_<tag>()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   705
    #
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   706
    # While parsing the xml ParaFormatter will call these
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   707
    # functions to handle the string formatting tags.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   708
    # At the start of each tag the corresponding field will
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   709
    # be set to 1 and at the end tag the corresponding field will
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   710
    # be set to 0.  Then when handle_data is called the options
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   711
    # for that data will be aparent by the current settings.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   712
    #----------------------------------------------------------
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   713
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   714
    def __getattr__( self, attrName ):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   715
        """This way we can handle <TAG> the same way as <tag> (ignoring case)."""
2369
f3cc620c14ed paraparser.py: minor speedup
rgbecker
parents: 2368
diff changeset
   716
        if attrName!=attrName.lower() and attrName!="caseSensitive" and not self.caseSensitive and \
f3cc620c14ed paraparser.py: minor speedup
rgbecker
parents: 2368
diff changeset
   717
            (attrName.startswith("start_") or attrName.startswith("end_")):
f3cc620c14ed paraparser.py: minor speedup
rgbecker
parents: 2368
diff changeset
   718
                return getattr(self,attrName.lower())
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
   719
        raise AttributeError(attrName)
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   720
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   721
    #### bold
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   722
    def start_b( self, attributes ):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   723
        self._push('b',bold=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   724
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   725
    def end_b( self ):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   726
        self._pop('b')
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   727
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   728
    def start_strong( self, attributes ):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   729
        self._push('strong',bold=1)
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   730
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   731
    def end_strong( self ):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   732
        self._pop('strong')
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   733
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   734
    #### italics
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   735
    def start_i( self, attributes ):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   736
        self._push('i',italic=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   737
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   738
    def end_i( self ):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   739
        self._pop('i')
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   740
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   741
    def start_em( self, attributes ):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   742
        self._push('em', italic=1)
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   743
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   744
    def end_em( self ):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   745
        self._pop('em')
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   746
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: 4370
diff changeset
   747
    def _new_line(self,k):
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: 4370
diff changeset
   748
        frag = self._stack[-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: 4370
diff changeset
   749
        frag.us_lines = frag.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: 4370
diff changeset
   750
                    self.nlines,
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: 4370
diff changeset
   751
                    k,
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: 4370
diff changeset
   752
                    getattr(frag,k+'Color',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: 4370
diff changeset
   753
                    getattr(frag,k+'Width',self._defaultLineWidths[k]),
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: 4370
diff changeset
   754
                    getattr(frag,k+'Offset',self._defaultLineOffsets[k]),
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: 4370
diff changeset
   755
                    frag.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: 4370
diff changeset
   756
                    _lineRepeats[getattr(frag,k+'Kind','single')],
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: 4370
diff changeset
   757
                    getattr(frag,k+'Gap',self._defaultLineGaps[k]),
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: 4370
diff changeset
   758
                    )]
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: 4370
diff changeset
   759
        self.nlines += 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: 4370
diff changeset
   760
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   761
    #### underline
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   762
    def start_u( self, attributes ):
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: 4370
diff changeset
   763
        A = self.getAttributes(attributes,_uAttrMap)
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: 4370
diff changeset
   764
        self._push('u',**A)
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: 4370
diff changeset
   765
        self._new_line('underline')
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   766
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   767
    def end_u( self ):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   768
        self._pop('u')
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   769
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   770
    #### strike
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   771
    def start_strike( self, attributes ):
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: 4370
diff changeset
   772
        A = self.getAttributes(attributes,_strikeAttrMap)
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: 4370
diff changeset
   773
        self._push('strike',strike=1,**A)
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: 4370
diff changeset
   774
        self._new_line('strike')
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   775
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   776
    def end_strike( self ):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   777
        self._pop('strike')
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   778
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   779
    #### link
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: 4370
diff changeset
   780
    def _handle_link(self, tag, attributes):
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: 4370
diff changeset
   781
        A = self.getAttributes(attributes,_linkAttrMap)
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: 4370
diff changeset
   782
        underline = A.pop('underline',self._defaultLinkUnderline)
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: 4370
diff changeset
   783
        A['link'] = self._stack[-1].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: 4370
diff changeset
   784
                        self.nlinks,
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: 4370
diff changeset
   785
                        A.pop('link','').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: 4370
diff changeset
   786
                        )]
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: 4370
diff changeset
   787
        self.nlinks += 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: 4370
diff changeset
   788
        self._push(tag,**A)
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: 4370
diff changeset
   789
        if 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: 4370
diff changeset
   790
            self._new_line('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: 4370
diff changeset
   791
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: 4370
diff changeset
   792
    def start_link(self,attributes):
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: 4370
diff changeset
   793
        self._handle_link('link',attributes)
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   794
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   795
    def end_link(self):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   796
        if self._pop('link').link is None:
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   797
            raise ValueError('<link> has no target or href')
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   798
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   799
    #### anchor
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   800
    def start_a(self, attributes):
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: 4370
diff changeset
   801
        anchor = 'name' in attributes
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: 4370
diff changeset
   802
        if anchor:
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: 4370
diff changeset
   803
            A = self.getAttributes(attributes,_anchorAttrMap)
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: 4370
diff changeset
   804
            name = A.get('name',None)
2893
7432e06445ba paraparser.py: improved checking on <a> tag attributes
rgbecker
parents: 2861
diff changeset
   805
            name = name.strip()
7432e06445ba paraparser.py: improved checking on <a> tag attributes
rgbecker
parents: 2861
diff changeset
   806
            if not name:
7432e06445ba paraparser.py: improved checking on <a> tag attributes
rgbecker
parents: 2861
diff changeset
   807
                self._syntax_error('<a name="..."/> anchor variant requires non-blank name')
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   808
            if len(A)>1:
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   809
                self._syntax_error('<a name="..."/> anchor variant only allows name attribute')
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   810
                A = dict(name=A['name'])
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   811
            A['_selfClosingTag'] = 'anchor'
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: 4370
diff changeset
   812
            self._push('a',**A)
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   813
        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: 4370
diff changeset
   814
            self._handle_link('a',attributes)
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   815
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   816
    def end_a(self):
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   817
        frag = self._stack[-1]
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   818
        sct = getattr(frag,'_selfClosingTag','')
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   819
        if sct:
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   820
            if not (sct=='anchor' and frag.name):
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   821
                raise ValueError('Parser failure in <a/>')
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   822
            defn = frag.cbDefn = ABag()
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   823
            defn.label = defn.kind = 'anchor'
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   824
            defn.name = frag.name
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   825
            del frag.name, frag._selfClosingTag
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   826
            self.handle_data('')
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   827
            self._pop('a')
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   828
        else:
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   829
            if self._pop('a').link is None:
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   830
                raise ValueError('<link> has no href')
2742
8edd54153201 paraparser: allow <a> as alias for <link>
rgbecker
parents: 2694
diff changeset
   831
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   832
    def start_img(self,attributes):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   833
        A = self.getAttributes(attributes,_imgAttrMap)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   834
        if not A.get('src'):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   835
            self._syntax_error('<img> needs src attribute')
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   836
        A['_selfClosingTag'] = 'img'
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   837
        self._push('img',**A)
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   838
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   839
    def end_img(self):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   840
        frag = self._stack[-1]
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   841
        if not getattr(frag,'_selfClosingTag',''):
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   842
            raise ValueError('Parser failure in <img/>')
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   843
        defn = frag.cbDefn = ABag()
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   844
        defn.kind = 'img'
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   845
        defn.src = getattr(frag,'src',None)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   846
        defn.image = ImageReader(defn.src)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   847
        size = defn.image.getSize()
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   848
        defn.width = getattr(frag,'width',size[0])
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   849
        defn.height = getattr(frag,'height',size[1])
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   850
        defn.valign = getattr(frag,'valign','bottom')
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   851
        del frag._selfClosingTag
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   852
        self.handle_data('')
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   853
        self._pop('img')
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   854
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   855
    #### super script
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   856
    def start_super( self, attributes ):
4249
8fc7d11bdee0 add support for rml <sup>/<sub> rise and size attributes; version --> 3.2.17
robin
parents: 4220
diff changeset
   857
        A = self.getAttributes(attributes,_supAttrMap)
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: 4370
diff changeset
   858
        #A['sup']=1
4249
8fc7d11bdee0 add support for rml <sup>/<sub> rise and size attributes; version --> 3.2.17
robin
parents: 4220
diff changeset
   859
        self._push('super',**A)
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: 4370
diff changeset
   860
        frag = self._stack[-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: 4370
diff changeset
   861
        frag.rise += fontSizeNormalize(frag,'supr',frag.fontSize*supFraction)
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: 4370
diff changeset
   862
        frag.fontSize = fontSizeNormalize(frag,'sups',frag.fontSize-min(sizeDelta,0.2*frag.fontSize))
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   863
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   864
    def end_super( self ):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   865
        self._pop('super')
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   866
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: 4370
diff changeset
   867
    start_sup = start_super
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: 4370
diff changeset
   868
    end_sup = end_super
1736
dafc17db33d2 Attempt to use sup as well as super
rgbecker
parents: 1683
diff changeset
   869
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   870
    #### sub script
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   871
    def start_sub( self, attributes ):
4249
8fc7d11bdee0 add support for rml <sup>/<sub> rise and size attributes; version --> 3.2.17
robin
parents: 4220
diff changeset
   872
        A = self.getAttributes(attributes,_supAttrMap)
8fc7d11bdee0 add support for rml <sup>/<sub> rise and size attributes; version --> 3.2.17
robin
parents: 4220
diff changeset
   873
        self._push('sub',**A)
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: 4370
diff changeset
   874
        frag = self._stack[-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: 4370
diff changeset
   875
        frag.rise -= fontSizeNormalize(frag,'supr',frag.fontSize*subFraction)
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: 4370
diff changeset
   876
        frag.fontSize = fontSizeNormalize(frag,'sups',frag.fontSize-min(sizeDelta,0.2*frag.fontSize))
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   877
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   878
    def end_sub( self ):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   879
        self._pop('sub')
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   880
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   881
    #### greek script
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   882
    #### add symbol encoding
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   883
    def handle_charref(self, name):
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   884
        try:
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   885
            if name[0]=='x':
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   886
                n = int(name[1:],16)
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   887
            else:
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   888
                n = int(name)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   889
        except ValueError:
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   890
            self.unknown_charref(name)
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   891
            return
4004
ebd460ef8d2f rename utils.py UniChr --> uniChr
robin
parents: 3994
diff changeset
   892
        self.handle_data(uniChr(n))   #.encode('utf8'))
134
60e8e0aee073 Fixed syntax_error handling
rgbecker
parents: 133
diff changeset
   893
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   894
    def syntax_error(self,lineno,message):
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   895
        self._syntax_error(message)
134
60e8e0aee073 Fixed syntax_error handling
rgbecker
parents: 133
diff changeset
   896
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   897
    def _syntax_error(self,message):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   898
        if message[:10]=="attribute " and message[-17:]==" value not quoted": return
4255
89ea1d46b4a0 make paraparser syntax errors real and fix <sup/sub> tags to have relative values; version-->3.3.1
robin
parents: 4252
diff changeset
   899
        if self._crashOnError:
89ea1d46b4a0 make paraparser syntax errors real and fix <sup/sub> tags to have relative values; version-->3.3.1
robin
parents: 4252
diff changeset
   900
            raise ValueError('paraparser: syntax error: %s' % message)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   901
        self.errors.append(message)
134
60e8e0aee073 Fixed syntax_error handling
rgbecker
parents: 133
diff changeset
   902
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   903
    def start_greek(self, attr):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   904
        self._push('greek',greek=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   905
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   906
    def end_greek(self):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   907
        self._pop('greek')
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   908
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   909
    def start_unichar(self, attr):
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   910
        if 'name' in attr:
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   911
            if 'code' in attr:
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   912
                self._syntax_error('<unichar/> invalid with both name and code attributes')
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   913
            try:
3809
cbd390e6d557 paraparser.py: fix unichar
robin
parents: 3787
diff changeset
   914
                v = unicodedata.lookup(attr['name'])
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   915
            except KeyError:
4116
cf49463fc067 Fix a bunch of undefined names. Mostly typos or missing imports.
Matthew Duggan <mgithub@guarana.org>
parents: 4097
diff changeset
   916
                self._syntax_error('<unichar/> invalid name attribute\n"%s"' % ascii(attr['name']))
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   917
                v = '\0'
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   918
        elif 'code' in attr:
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   919
            try:
3937
f685e0de4282 paraparser.py:fix start_unichar for puython2
robin
parents: 3931
diff changeset
   920
                v = int(eval(attr['code']))
f685e0de4282 paraparser.py:fix start_unichar for puython2
robin
parents: 3931
diff changeset
   921
                v = chr(v) if isPy3 else unichr(v)
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   922
            except:
3809
cbd390e6d557 paraparser.py: fix unichar
robin
parents: 3787
diff changeset
   923
                self._syntax_error('<unichar/> invalid code attribute %s' % ascii(attr['code']))
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   924
                v = '\0'
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   925
        else:
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   926
            v = None
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   927
            if attr:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
   928
                self._syntax_error('<unichar/> invalid attribute %s' % list(attr.keys())[0])
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   929
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   930
        if v is not None:
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   931
            self.handle_data(v)
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   932
        self._push('unichar',_selfClosingTag='unichar')
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   933
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   934
    def end_unichar(self):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   935
        self._pop('unichar')
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   936
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   937
    def start_font(self,attr):
4129
1266500a2c22 paraparser.py: fix handling of fontName attributes in span/font; version-->3.1.29
robin
parents: 4116
diff changeset
   938
        A = self.getAttributes(attr,_spanAttrMap)
1266500a2c22 paraparser.py: fix handling of fontName attributes in span/font; version-->3.1.29
robin
parents: 4116
diff changeset
   939
        if 'fontName' in A:
1266500a2c22 paraparser.py: fix handling of fontName attributes in span/font; version-->3.1.29
robin
parents: 4116
diff changeset
   940
            A['fontName'], A['bold'], A['italic'] = ps2tt(A['fontName'])
4130
49161ce56cad paraparser.py: fix handling of fontName attributes in <font> tag
robin
parents: 4129
diff changeset
   941
        self._push('font',**A)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   942
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   943
    def end_font(self):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   944
        self._pop('font')
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   945
3552
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   946
    def start_span(self,attr):
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   947
        A = self.getAttributes(attr,_spanAttrMap)
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   948
        if 'style' in A:
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   949
            style = self.findSpanStyle(A.pop('style'))
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   950
            D = {}
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   951
            for k in 'fontName fontSize textColor backColor'.split():
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   952
                v = getattr(style,k,self)
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   953
                if v is self: continue
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   954
                D[k] = v
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   955
            D.update(A)
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   956
            A = D
4129
1266500a2c22 paraparser.py: fix handling of fontName attributes in span/font; version-->3.1.29
robin
parents: 4116
diff changeset
   957
        if 'fontName' in A:
1266500a2c22 paraparser.py: fix handling of fontName attributes in span/font; version-->3.1.29
robin
parents: 4116
diff changeset
   958
            A['fontName'], A['bold'], A['italic'] = ps2tt(A['fontName'])
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   959
        self._push('span',**A)
3552
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   960
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   961
    def end_span(self):
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   962
        self._pop('span')
3552
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   963
2663
927cc273c5a5 <br/> work in progress
andy
parents: 2646
diff changeset
   964
    def start_br(self, attr):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   965
        self._push('br',_selfClosingTag='br',lineBreak=True,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: 4370
diff changeset
   966
2663
927cc273c5a5 <br/> work in progress
andy
parents: 2646
diff changeset
   967
    def end_br(self):
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
   968
        #print('\nend_br called, %d frags in list' % len(self.fragList))
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   969
        frag = self._stack[-1]
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   970
        if not (frag._selfClosingTag=='br' and frag.lineBreak):
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   971
                raise ValueError('Parser failure in <br/>')
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   972
        del frag._selfClosingTag
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   973
        self.handle_data('')
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
   974
        self._pop('br')
2663
927cc273c5a5 <br/> work in progress
andy
parents: 2646
diff changeset
   975
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   976
    def _initial_frag(self,attr,attrMap,bullet=0):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   977
        style = self._style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   978
        if attr!={}:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   979
            style = copy.deepcopy(style)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   980
            _applyAttributes(style,self.getAttributes(attr,attrMap))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   981
            self._style = style
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   982
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   983
        # initialize semantic values
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   984
        frag = ParaFrag()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   985
        frag.rise = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   986
        frag.greek = 0
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: 4370
diff changeset
   987
        frag.link = []
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   988
        if bullet:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   989
            frag.fontName, frag.bold, frag.italic = ps2tt(style.bulletFontName)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   990
            frag.fontSize = style.bulletFontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   991
            frag.textColor = hasattr(style,'bulletColor') and style.bulletColor or style.textColor
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   992
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   993
            frag.fontName, frag.bold, frag.italic = ps2tt(style.fontName)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   994
            frag.fontSize = style.fontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   995
            frag.textColor = 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: 4370
diff changeset
   996
        frag.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: 4370
diff changeset
   997
        self.nlinks = self.nlines = 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: 4370
diff changeset
   998
        self._defaultLineWidths = dict(
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: 4370
diff changeset
   999
                                    underline = getattr(style,'underlineWidth',''),
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: 4370
diff changeset
  1000
                                    strike = getattr(style,'strikeWidth',''),
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: 4370
diff changeset
  1001
                                    )
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: 4370
diff changeset
  1002
        self._defaultLineOffsets = dict(
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: 4370
diff changeset
  1003
                                    underline = getattr(style,'underlineOffset',''),
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: 4370
diff changeset
  1004
                                    strike = getattr(style,'strikeOffset',''),
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: 4370
diff changeset
  1005
                                    )
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: 4370
diff changeset
  1006
        self._defaultLineGaps = dict(
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: 4370
diff changeset
  1007
                                    underline = getattr(style,'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: 4370
diff changeset
  1008
                                    strike = getattr(style,'strikeGap',''),
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: 4370
diff changeset
  1009
                                    )
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: 4370
diff changeset
  1010
        self._defaultLinkUnderline = getattr(style,'linkUnderline',platypus_link_underline)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1011
        return frag
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
  1012
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1013
    def start_para(self,attr):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
  1014
        frag = self._initial_frag(attr,_paraAttrMap)
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
  1015
        frag.__tag__ = 'para'
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
  1016
        self._stack = [frag]
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
  1017
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1018
    def end_para(self):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
  1019
        self._pop('para')
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
  1020
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1021
    def start_bullet(self,attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1022
        if hasattr(self,'bFragList'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1023
            self._syntax_error('only one <bullet> tag allowed')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1024
        self.bFragList = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1025
        frag = self._initial_frag(attr,_bulletAttrMap,1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1026
        frag.isBullet = 1
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
  1027
        frag.__tag__ = 'bullet'
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1028
        self._stack.append(frag)
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
  1029
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1030
    def end_bullet(self):
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
  1031
        self._pop('bullet')
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
  1032
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1033
    #---------------------------------------------------------------
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1034
    def start_seqdefault(self, attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1035
        try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1036
            default = attr['id']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1037
        except KeyError:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1038
            default = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1039
        self._seq.setDefaultCounter(default)
266
081154da1a78 Added Sequencer and associated XML tags
andy_robinson
parents: 253
diff changeset
  1040
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1041
    def end_seqdefault(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1042
        pass
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
  1043
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1044
    def start_seqreset(self, attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1045
        try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1046
            id = attr['id']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1047
        except KeyError:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1048
            id = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1049
        try:
2368
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1050
            base = int(attr['base'])
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1051
        except:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1052
            base=0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1053
        self._seq.reset(id, base)
266
081154da1a78 Added Sequencer and associated XML tags
andy_robinson
parents: 253
diff changeset
  1054
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1055
    def end_seqreset(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1056
        pass
744
2abd99baf95b Accepts seqdefault/seqDefault and seqreset/seqReset
andy_robinson
parents: 677
diff changeset
  1057
2368
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1058
    def start_seqchain(self, attr):
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1059
        try:
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1060
            order = attr['order']
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1061
        except KeyError:
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1062
            order = ''
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1063
        order = order.split()
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1064
        seq = self._seq
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1065
        for p,c in zip(order[:-1],order[1:]):
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1066
            seq.chain(p, c)
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1067
    end_seqchain = end_seqreset
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1068
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1069
    def start_seqformat(self, attr):
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1070
        try:
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1071
            id = attr['id']
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1072
        except KeyError:
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1073
            id = None
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1074
        try:
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1075
            value = attr['value']
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1076
        except KeyError:
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1077
            value = '1'
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1078
        self._seq.setFormat(id,value)
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1079
    end_seqformat = end_seqreset
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1080
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1081
    # AR hacking in aliases to allow the proper casing for RML.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1082
    # the above ones should be deprecated over time. 2001-03-22
2368
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1083
    start_seqDefault = start_seqdefault
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1084
    end_seqDefault = end_seqdefault
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1085
    start_seqReset = start_seqreset
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1086
    end_seqReset = end_seqreset
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1087
    start_seqChain = start_seqchain
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1088
    end_seqChain = end_seqchain
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1089
    start_seqFormat = start_seqformat
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
  1090
    end_seqFormat = end_seqformat
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
  1091
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1092
    def start_seq(self, attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1093
        #if it has a template, use that; otherwise try for id;
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1094
        #otherwise take default sequence
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
  1095
        if 'template' in attr:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1096
            templ = attr['template']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1097
            self.handle_data(templ % self._seq)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1098
            return
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
  1099
        elif 'id' in attr:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1100
            id = attr['id']
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
  1101
        else:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1102
            id = None
2694
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
  1103
        increment = attr.get('inc', None)
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
  1104
        if not increment:
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
  1105
            output = self._seq.nextf(id)
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
  1106
        else:
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
  1107
            #accepts "no" for do not increment, or an integer.
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
  1108
            #thus, 0 and 1 increment by the right amounts.
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
  1109
            if increment.lower() == 'no':
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
  1110
                output = self._seq.thisf(id)
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
  1111
            else:
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
  1112
                incr = int(increment)
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
  1113
                output = self._seq.thisf(id)
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
  1114
                self._seq.reset(id, self._seq._this() + incr)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1115
        self.handle_data(output)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
  1116
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1117
    def end_seq(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1118
        pass
266
081154da1a78 Added Sequencer and associated XML tags
andy_robinson
parents: 253
diff changeset
  1119
4059
9b48d0d9f137 paraparse.py: add ondraw=onDraw aliases
robin
parents: 4004
diff changeset
  1120
    def start_ondraw(self,attr):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1121
        defn = ABag()
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
  1122
        if 'name' in attr: defn.name = attr['name']
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1123
        else: self._syntax_error('<onDraw> needs at least a name attribute')
506
68bd275f16e2 Added onDraw tag to paragraphs
rgbecker
parents: 494
diff changeset
  1124
4277
838129322a55 really merge para-measure-fix; version-->3.3.11
robin
parents: 4255
diff changeset
  1125
        defn.label = attr.get('label',None)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1126
        defn.kind='onDraw'
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
  1127
        self._push('ondraw',cbDefn=defn)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1128
        self.handle_data('')
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
robin
parents: 4077
diff changeset
  1129
        self._pop('ondraw')
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: 4370
diff changeset
  1130
    start_onDraw=start_ondraw
4059
9b48d0d9f137 paraparse.py: add ondraw=onDraw aliases
robin
parents: 4004
diff changeset
  1131
    end_onDraw=end_ondraw=end_seq
3111
86a3158c50bd reportlab: improved support for onDraw and SimpleIndex
rgbecker
parents: 3032
diff changeset
  1132
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
  1133
    def start_index(self,attr):
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
  1134
        attr=self.getAttributes(attr,_indexAttrMap)
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
  1135
        defn = ABag()
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
  1136
        if 'item' in attr:
3187
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
  1137
            label = attr['item']
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
  1138
        else:
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
  1139
            self._syntax_error('<index> needs at least an item attribute')
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
  1140
        if 'name' in attr:
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
  1141
            name = attr['name']
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
  1142
        else:
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
  1143
            name = DEFAULT_INDEX_NAME
3187
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
  1144
        format = attr.get('format',None)
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
  1145
        if format is not None and format not in ('123','I','i','ABC','abc'):
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
  1146
            raise ValueError('index tag format is %r not valid 123 I i ABC or abc' % offset)
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
  1147
        offset = attr.get('offset',None)
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
  1148
        if offset is not None:
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
  1149
            try:
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
  1150
                offset = int(offset)
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
  1151
            except:
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
  1152
                raise ValueError('index tag offset is %r not an int' % offset)
3856
5316e8678dd9 paraparser.py: fix label encoding
robin
parents: 3826
diff changeset
  1153
        defn.label = encode_label((label,format,offset))
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
  1154
        defn.name = name
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
  1155
        defn.kind='index'
4097
1c2ebf285cb7 paraparser.py: force assertion of tag rather than value checking in end_<tag>
r