src/reportlab/platypus/paraparser.py
author robin
Mon, 30 Dec 2013 21:13:16 +0000
branchpy33
changeset 3955 3dbd805c708c
parent 3954 44dbe56eb858
child 3956 486cc75f4cdb
permissions -rw-r--r--
paraparser.py: fix HTMLParser imports
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3617
ae5744e97c42 reportlab: copyright date changes
robin
parents: 3552
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2012
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 433
diff changeset
     2
#see license.txt for license details
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2321
diff changeset
     3
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/platypus/paraparser.py
2321
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
     4
__version__=''' $Id$ '''
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
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
    13
3187
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
    14
try:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
    15
    import pickle as pickle
3187
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
    16
except:
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
    17
    import pickle
2693
3c61a57aecd1 missing import statement
andy
parents: 2670
diff changeset
    18
import unicodedata
279
e7d8b3631d5c Global sequencer put in the 'story builder'.
andy_robinson
parents: 267
diff changeset
    19
import reportlab.lib.sequencer
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
    20
518
5be3fcb26c78 Semantic Name changes
rgbecker
parents: 514
diff changeset
    21
from reportlab.lib.abag import ABag
3896
7da4fe956715 paraparser.py: fix on uncode as early as possible
robin
parents: 3883
diff changeset
    22
from reportlab.lib.utils import ImageReader, isPy3, annotateException, encode_label, asUnicode
248
c103b7a55e79 Color fixes; thanks to J Alet
rgbecker
parents: 238
diff changeset
    23
from reportlab.lib.colors import toColor, white, black, red, Color
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    24
from reportlab.lib.fonts import tt2ps, ps2tt
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
    25
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
    26
from reportlab.lib.units import inch,mm,cm,pica
3955
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    27
if isPy3:
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    28
    from html.parser import HTMLParser
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    29
    from html.entities import name2codepoint
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    30
else:
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    31
    from HTMLParser import HTMLParser
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    32
    from htmlentitydefs import name2codepoint
3dbd805c708c paraparser.py: fix HTMLParser imports
robin
parents: 3954
diff changeset
    33
2410
f505ed647678 reportlab: add fix for <para/> and new test
rgbecker
parents: 2376
diff changeset
    34
_re_para = re.compile(r'^\s*<\s*para(?:\s+|>|/>)')
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    35
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    36
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
    37
subFraction = 0.5   # fraction of font size that a sub script should be lowered
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    38
superFraction = 0.5 # fraction of font size that a super script should be raised
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    39
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
    40
DEFAULT_INDEX_NAME='_indexAdd'
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
    41
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    42
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    43
def _convnum(s, unit=1, allowRelative=True):
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    44
    if s[0] in ('+','-') and allowRelative:
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    45
        try:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    46
            return ('relative',int(s)*unit)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    47
        except ValueError:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    48
            return ('relative',float(s)*unit)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    49
    else:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    50
        try:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    51
            return int(s)*unit
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    52
        except ValueError:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    53
            return float(s)*unit
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    54
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    55
def _num(s, unit=1, allowRelative=True):
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    56
    """Convert a string like '10cm' to an int or float (in points).
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    57
       The default unit is point, but optionally you can use other
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    58
       default units like mm.
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    59
    """
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    60
    if s.endswith('cm'):
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    61
        unit=cm
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    62
        s = s[:-2]
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    63
    if s.endswith('in'):
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    64
        unit=inch
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    65
        s = s[:-2]
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    66
    if s.endswith('pt'):
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    67
        unit=1
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    68
        s = s[:-2]
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    69
    if s.endswith('i'):
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    70
        unit=inch
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    71
        s = s[:-1]
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    72
    if s.endswith('mm'):
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    73
        unit=mm
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    74
        s = s[:-2]
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    75
    if s.endswith('pica'):
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    76
        unit=pica
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    77
        s = s[:-4]
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    78
    return _convnum(s,unit,allowRelative)
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    79
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    80
def _numpct(s,unit=1,allowRelative=False):
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    81
    if s.endswith('%'):
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    82
        return _PCT(_convnum(s[:-1],allowRelative=allowRelative))
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    83
    else:
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    84
        return _num(s,unit,allowRelative)
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    85
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    86
class _PCT:
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    87
    def __init__(self,v):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    88
        self._value = v*0.01
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    89
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    90
    def normalizedValue(self,normalizer):
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
    91
        normalizer = normalizer or getattr(self,'_normalizer')
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    92
        return normalizer*self._value
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    93
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    94
def _valignpc(s):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    95
    s = s.lower()
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    96
    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
    97
        return s
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    98
    if s.endswith('%'):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
    99
        n = _convnum(s[:-1])
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   100
        if isinstance(n,tuple):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   101
            n = n[1]
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   102
        return _PCT(n)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   103
    n = _num(s)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   104
    if isinstance(n,tuple):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   105
        n = n[1]
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   106
    return n
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   107
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   108
def _autoLeading(x):
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   109
    x = x.lower()
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   110
    if x in ('','min','max','off'):
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   111
        return x
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   112
    raise ValueError('Invalid autoLeading=%r' % x )
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   113
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   114
def _align(s):
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3723
diff changeset
   115
    s = s.lower()
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   116
    if s=='left': return TA_LEFT
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   117
    elif s=='right': return TA_RIGHT
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   118
    elif s=='justify': return TA_JUSTIFY
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   119
    elif s in ('centre','center'): return TA_CENTER
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   120
    else: raise ValueError
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   121
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   122
_paraAttrMap = {'font': ('fontName', None),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   123
                'face': ('fontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   124
                'fontsize': ('fontSize', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   125
                'size': ('fontSize', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   126
                'leading': ('leading', _num),
2836
66fb84201abe platypus: add support for autoLeading
rgbecker
parents: 2748
diff changeset
   127
                'autoleading': ('autoLeading', _autoLeading),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   128
                'lindent': ('leftIndent', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   129
                'rindent': ('rightIndent', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   130
                'findent': ('firstLineIndent', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   131
                'align': ('alignment', _align),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   132
                'spaceb': ('spaceBefore', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   133
                'spacea': ('spaceAfter', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   134
                'bfont': ('bulletFontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   135
                'bfontsize': ('bulletFontSize',_num),
2860
3f14d66194c2 platypus: added bulletOffsetY inspired by haraldarminmassa@gmail.com
rgbecker
parents: 2857
diff changeset
   136
                'boffsety': ('bulletOffsetY',_num),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   137
                'bindent': ('bulletIndent',_num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   138
                'bcolor': ('bulletColor',toColor),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   139
                'color':('textColor',toColor),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   140
                'backcolor':('backColor',toColor),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   141
                'bgcolor':('backColor',toColor),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   142
                'bg':('backColor',toColor),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   143
                'fg': ('textColor',toColor),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   144
                }
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   145
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   146
_bulletAttrMap = {
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   147
                'font': ('bulletFontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   148
                'face': ('bulletFontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   149
                'size': ('bulletFontSize',_num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   150
                'fontsize': ('bulletFontSize',_num),
2860
3f14d66194c2 platypus: added bulletOffsetY inspired by haraldarminmassa@gmail.com
rgbecker
parents: 2857
diff changeset
   151
                'offsety': ('bulletOffsetY',_num),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   152
                'indent': ('bulletIndent',_num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   153
                'color': ('bulletColor',toColor),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   154
                'fg': ('bulletColor',toColor),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   155
                }
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   156
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   157
#things which are valid font attributes
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   158
_fontAttrMap = {'size': ('fontSize', _num),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   159
                'face': ('fontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   160
                'name': ('fontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   161
                'fg':   ('textColor', toColor),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   162
                'color':('textColor', toColor),
2446
6b9268ab33c3 allow solid para background
andy
parents: 2410
diff changeset
   163
                'backcolor':('backColor',toColor),
6b9268ab33c3 allow solid para background
andy
parents: 2410
diff changeset
   164
                'bgcolor':('backColor',toColor),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   165
                }
3552
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   166
#things which are valid span attributes
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   167
_spanAttrMap = {'size': ('fontSize', _num),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   168
                'face': ('fontName', None),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   169
                'name': ('fontName', None),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   170
                'fg':   ('textColor', toColor),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   171
                'color':('textColor', toColor),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   172
                'backcolor':('backColor',toColor),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   173
                'bgcolor':('backColor',toColor),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   174
                'style': ('style',None),
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   175
                }
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   176
#things which are valid font attributes
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   177
_linkAttrMap = {'size': ('fontSize', _num),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   178
                'face': ('fontName', None),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   179
                'name': ('fontName', None),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   180
                'fg':   ('textColor', toColor),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   181
                'color':('textColor', toColor),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   182
                'backcolor':('backColor',toColor),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   183
                'bgcolor':('backColor',toColor),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   184
                'dest': ('link', None),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   185
                'destination': ('link', None),
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   186
                'target': ('link', None),
2594
746800f5caf9 reportlab: fix up links in paragraphs
rgbecker
parents: 2585
diff changeset
   187
                'href': ('link', None),
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   188
                }
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   189
_anchorAttrMap = {'fontSize': ('fontSize', _num),
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   190
                'fontName': ('fontName', None),
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   191
                'name': ('name', None),
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   192
                'fg':   ('textColor', toColor),
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   193
                'color':('textColor', toColor),
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   194
                'backcolor':('backColor',toColor),
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   195
                'bgcolor':('backColor',toColor),
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   196
                'href': ('href', None),
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   197
                }
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   198
_imgAttrMap = {
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   199
                'src': ('src', None),
3434
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
   200
                'width': ('width',_numpct),
3c14212cc997 platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents: 3368
diff changeset
   201
                'height':('height',_numpct),
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   202
                'valign':('valign',_valignpc),
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   203
                }
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   204
_indexAttrMap = {
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   205
                'name': ('name',None),
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   206
                'item': ('item',None),
3187
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
   207
                'offset': ('offset',None),
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
   208
                'format': ('format',None),
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   209
                }
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   210
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   211
def _addAttributeNames(m):
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
   212
    K = list(m.keys())
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   213
    for k in K:
1944
a50f8e3f93f8 laissez faire case
rgbecker
parents: 1940
diff changeset
   214
        n = m[k][0]
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   215
        if n not in m: m[n] = m[k]
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3723
diff changeset
   216
        n = n.lower()
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   217
        if n not in m: m[n] = m[k]
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   218
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   219
_addAttributeNames(_paraAttrMap)
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   220
_addAttributeNames(_fontAttrMap)
3552
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   221
_addAttributeNames(_spanAttrMap)
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   222
_addAttributeNames(_bulletAttrMap)
2747
46005202d9d0 paraparser: fix link/anchor attributes
rgbecker
parents: 2745
diff changeset
   223
_addAttributeNames(_anchorAttrMap)
46005202d9d0 paraparser: fix link/anchor attributes
rgbecker
parents: 2745
diff changeset
   224
_addAttributeNames(_linkAttrMap)
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   225
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   226
def _applyAttributes(obj, attr):
3723
99aa837b6703 second stage of port to Python 3.3; working hello world
rptlab
parents: 3721
diff changeset
   227
    for k, v in attr.items():
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   228
        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
   229
            if hasattr(obj, k):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   230
                v = v[1]+getattr(obj,k)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   231
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   232
                v = v[1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   233
        setattr(obj,k,v)
102
1818e7fa3738 Added clone method to ParaFrag
rgbecker
parents: 96
diff changeset
   234
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   235
#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
   236
#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
   237
#numeric entity names that follow.
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   238
greeks = {
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   239
    'Aacute': b'\xc3\x81',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   240
    'aacute': b'\xc3\xa1',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   241
    'Acirc': b'\xc3\x82',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   242
    'acirc': b'\xc3\xa2',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   243
    'acute': b'\xc2\xb4',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   244
    'AElig': b'\xc3\x86',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   245
    'aelig': b'\xc3\xa6',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   246
    'Agrave': b'\xc3\x80',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   247
    'agrave': b'\xc3\xa0',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   248
    'alefsym': b'\xe2\x84\xb5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   249
    'Alpha': b'\xce\x91',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   250
    'alpha': b'\xce\xb1',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   251
    'and': b'\xe2\x88\xa7',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   252
    'ang': b'\xe2\x88\xa0',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   253
    'Aring': b'\xc3\x85',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   254
    'aring': b'\xc3\xa5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   255
    'asymp': b'\xe2\x89\x88',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   256
    'Atilde': b'\xc3\x83',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   257
    'atilde': b'\xc3\xa3',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   258
    'Auml': b'\xc3\x84',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   259
    'auml': b'\xc3\xa4',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   260
    'bdquo': b'\xe2\x80\x9e',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   261
    'Beta': b'\xce\x92',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   262
    'beta': b'\xce\xb2',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   263
    'brvbar': b'\xc2\xa6',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   264
    'bull': b'\xe2\x80\xa2',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   265
    'cap': b'\xe2\x88\xa9',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   266
    'Ccedil': b'\xc3\x87',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   267
    'ccedil': b'\xc3\xa7',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   268
    'cedil': b'\xc2\xb8',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   269
    'cent': b'\xc2\xa2',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   270
    'Chi': b'\xce\xa7',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   271
    'chi': b'\xcf\x87',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   272
    'circ': b'\xcb\x86',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   273
    'clubs': b'\xe2\x99\xa3',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   274
    'cong': b'\xe2\x89\x85',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   275
    'copy': b'\xc2\xa9',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   276
    'crarr': b'\xe2\x86\xb5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   277
    'cup': b'\xe2\x88\xaa',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   278
    'curren': b'\xc2\xa4',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   279
    'dagger': b'\xe2\x80\xa0',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   280
    'Dagger': b'\xe2\x80\xa1',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   281
    'darr': b'\xe2\x86\x93',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   282
    'dArr': b'\xe2\x87\x93',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   283
    'deg': b'\xc2\xb0',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   284
    'delta': b'\xce\xb4',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   285
    'Delta': b'\xe2\x88\x86',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   286
    'diams': b'\xe2\x99\xa6',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   287
    'divide': b'\xc3\xb7',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   288
    'Eacute': b'\xc3\x89',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   289
    'eacute': b'\xc3\xa9',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   290
    'Ecirc': b'\xc3\x8a',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   291
    'ecirc': b'\xc3\xaa',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   292
    'Egrave': b'\xc3\x88',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   293
    'egrave': b'\xc3\xa8',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   294
    'empty': b'\xe2\x88\x85',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   295
    'emsp': b'\xe2\x80\x83',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   296
    'ensp': b'\xe2\x80\x82',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   297
    'Epsilon': b'\xce\x95',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   298
    'epsilon': b'\xce\xb5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   299
    'epsiv': b'\xce\xb5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   300
    'equiv': b'\xe2\x89\xa1',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   301
    'Eta': b'\xce\x97',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   302
    'eta': b'\xce\xb7',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   303
    'ETH': b'\xc3\x90',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   304
    'eth': b'\xc3\xb0',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   305
    'Euml': b'\xc3\x8b',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   306
    'euml': b'\xc3\xab',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   307
    'euro': b'\xe2\x82\xac',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   308
    'exist': b'\xe2\x88\x83',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   309
    'fnof': b'\xc6\x92',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   310
    'forall': b'\xe2\x88\x80',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   311
    'frac12': b'\xc2\xbd',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   312
    'frac14': b'\xc2\xbc',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   313
    'frac34': b'\xc2\xbe',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   314
    'frasl': b'\xe2\x81\x84',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   315
    'Gamma': b'\xce\x93',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   316
    'gamma': b'\xce\xb3',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   317
    'ge': b'\xe2\x89\xa5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   318
    'harr': b'\xe2\x86\x94',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   319
    'hArr': b'\xe2\x87\x94',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   320
    'hearts': b'\xe2\x99\xa5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   321
    'hellip': b'\xe2\x80\xa6',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   322
    'Iacute': b'\xc3\x8d',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   323
    'iacute': b'\xc3\xad',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   324
    'Icirc': b'\xc3\x8e',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   325
    'icirc': b'\xc3\xae',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   326
    'iexcl': b'\xc2\xa1',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   327
    'Igrave': b'\xc3\x8c',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   328
    'igrave': b'\xc3\xac',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   329
    'image': b'\xe2\x84\x91',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   330
    'infin': b'\xe2\x88\x9e',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   331
    'int': b'\xe2\x88\xab',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   332
    'Iota': b'\xce\x99',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   333
    'iota': b'\xce\xb9',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   334
    'iquest': b'\xc2\xbf',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   335
    'isin': b'\xe2\x88\x88',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   336
    'Iuml': b'\xc3\x8f',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   337
    'iuml': b'\xc3\xaf',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   338
    'Kappa': b'\xce\x9a',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   339
    'kappa': b'\xce\xba',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   340
    'Lambda': b'\xce\x9b',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   341
    'lambda': b'\xce\xbb',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   342
    'lang': b'\xe2\x8c\xa9',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   343
    'laquo': b'\xc2\xab',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   344
    'larr': b'\xe2\x86\x90',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   345
    'lArr': b'\xe2\x87\x90',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   346
    'lceil': b'\xef\xa3\xae',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   347
    'ldquo': b'\xe2\x80\x9c',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   348
    'le': b'\xe2\x89\xa4',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   349
    'lfloor': b'\xef\xa3\xb0',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   350
    'lowast': b'\xe2\x88\x97',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   351
    'loz': b'\xe2\x97\x8a',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   352
    'lrm': b'\xe2\x80\x8e',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   353
    'lsaquo': b'\xe2\x80\xb9',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   354
    'lsquo': b'\xe2\x80\x98',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   355
    'macr': b'\xc2\xaf',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   356
    'mdash': b'\xe2\x80\x94',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   357
    'micro': b'\xc2\xb5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   358
    'middot': b'\xc2\xb7',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   359
    'minus': b'\xe2\x88\x92',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   360
    'mu': b'\xc2\xb5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   361
    'Mu': b'\xce\x9c',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   362
    'nabla': b'\xe2\x88\x87',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   363
    'nbsp': b'\xc2\xa0',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   364
    'ndash': b'\xe2\x80\x93',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   365
    'ne': b'\xe2\x89\xa0',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   366
    'ni': b'\xe2\x88\x8b',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   367
    'notin': b'\xe2\x88\x89',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   368
    'not': b'\xc2\xac',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   369
    'nsub': b'\xe2\x8a\x84',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   370
    'Ntilde': b'\xc3\x91',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   371
    'ntilde': b'\xc3\xb1',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   372
    'Nu': b'\xce\x9d',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   373
    'nu': b'\xce\xbd',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   374
    'Oacute': b'\xc3\x93',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   375
    'oacute': b'\xc3\xb3',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   376
    'Ocirc': b'\xc3\x94',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   377
    'ocirc': b'\xc3\xb4',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   378
    'OElig': b'\xc5\x92',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   379
    'oelig': b'\xc5\x93',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   380
    'Ograve': b'\xc3\x92',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   381
    'ograve': b'\xc3\xb2',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   382
    'oline': b'\xef\xa3\xa5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   383
    'omega': b'\xcf\x89',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   384
    'Omega': b'\xe2\x84\xa6',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   385
    'Omicron': b'\xce\x9f',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   386
    'omicron': b'\xce\xbf',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   387
    'oplus': b'\xe2\x8a\x95',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   388
    'ordf': b'\xc2\xaa',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   389
    'ordm': b'\xc2\xba',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   390
    'or': b'\xe2\x88\xa8',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   391
    'Oslash': b'\xc3\x98',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   392
    'oslash': b'\xc3\xb8',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   393
    'Otilde': b'\xc3\x95',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   394
    'otilde': b'\xc3\xb5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   395
    'otimes': b'\xe2\x8a\x97',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   396
    'Ouml': b'\xc3\x96',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   397
    'ouml': b'\xc3\xb6',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   398
    'para': b'\xc2\xb6',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   399
    'part': b'\xe2\x88\x82',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   400
    'permil': b'\xe2\x80\xb0',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   401
    'perp': b'\xe2\x8a\xa5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   402
    'phis': b'\xcf\x86',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   403
    'Phi': b'\xce\xa6',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   404
    'phi': b'\xcf\x95',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   405
    'piv': b'\xcf\x96',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   406
    'Pi': b'\xce\xa0',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   407
    'pi': b'\xcf\x80',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   408
    'plusmn': b'\xc2\xb1',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   409
    'pound': b'\xc2\xa3',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   410
    'prime': b'\xe2\x80\xb2',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   411
    'Prime': b'\xe2\x80\xb3',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   412
    'prod': b'\xe2\x88\x8f',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   413
    'prop': b'\xe2\x88\x9d',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   414
    'Psi': b'\xce\xa8',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   415
    'psi': b'\xcf\x88',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   416
    'radic': b'\xe2\x88\x9a',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   417
    'rang': b'\xe2\x8c\xaa',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   418
    'raquo': b'\xc2\xbb',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   419
    'rarr': b'\xe2\x86\x92',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   420
    'rArr': b'\xe2\x87\x92',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   421
    'rceil': b'\xef\xa3\xb9',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   422
    'rdquo': b'\xe2\x80\x9d',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   423
    'real': b'\xe2\x84\x9c',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   424
    'reg': b'\xc2\xae',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   425
    'rfloor': b'\xef\xa3\xbb',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   426
    'Rho': b'\xce\xa1',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   427
    'rho': b'\xcf\x81',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   428
    'rlm': b'\xe2\x80\x8f',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   429
    'rsaquo': b'\xe2\x80\xba',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   430
    'rsquo': b'\xe2\x80\x99',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   431
    'sbquo': b'\xe2\x80\x9a',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   432
    'Scaron': b'\xc5\xa0',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   433
    'scaron': b'\xc5\xa1',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   434
    'sdot': b'\xe2\x8b\x85',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   435
    'sect': b'\xc2\xa7',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   436
    'shy': b'\xc2\xad',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   437
    'sigmaf': b'\xcf\x82',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   438
    'sigmav': b'\xcf\x82',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   439
    'Sigma': b'\xce\xa3',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   440
    'sigma': b'\xcf\x83',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   441
    'sim': b'\xe2\x88\xbc',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   442
    'spades': b'\xe2\x99\xa0',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   443
    'sube': b'\xe2\x8a\x86',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   444
    'sub': b'\xe2\x8a\x82',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   445
    'sum': b'\xe2\x88\x91',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   446
    'sup1': b'\xc2\xb9',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   447
    'sup2': b'\xc2\xb2',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   448
    'sup3': b'\xc2\xb3',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   449
    'supe': b'\xe2\x8a\x87',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   450
    'sup': b'\xe2\x8a\x83',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   451
    'szlig': b'\xc3\x9f',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   452
    'Tau': b'\xce\xa4',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   453
    'tau': b'\xcf\x84',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   454
    'there4': b'\xe2\x88\xb4',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   455
    'thetasym': b'\xcf\x91',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   456
    'thetav': b'\xcf\x91',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   457
    'Theta': b'\xce\x98',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   458
    'theta': b'\xce\xb8',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   459
    'thinsp': b'\xe2\x80\x89',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   460
    'THORN': b'\xc3\x9e',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   461
    'thorn': b'\xc3\xbe',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   462
    'tilde': b'\xcb\x9c',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   463
    'times': b'\xc3\x97',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   464
    'trade': b'\xef\xa3\xaa',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   465
    'Uacute': b'\xc3\x9a',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   466
    'uacute': b'\xc3\xba',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   467
    'uarr': b'\xe2\x86\x91',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   468
    'uArr': b'\xe2\x87\x91',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   469
    'Ucirc': b'\xc3\x9b',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   470
    'ucirc': b'\xc3\xbb',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   471
    'Ugrave': b'\xc3\x99',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   472
    'ugrave': b'\xc3\xb9',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   473
    'uml': b'\xc2\xa8',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   474
    'upsih': b'\xcf\x92',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   475
    'Upsilon': b'\xce\xa5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   476
    'upsilon': b'\xcf\x85',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   477
    'Uuml': b'\xc3\x9c',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   478
    'uuml': b'\xc3\xbc',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   479
    'weierp': b'\xe2\x84\x98',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   480
    'Xi': b'\xce\x9e',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   481
    'xi': b'\xce\xbe',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   482
    'Yacute': b'\xc3\x9d',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   483
    'yacute': b'\xc3\xbd',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   484
    'yen': b'\xc2\xa5',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   485
    'yuml': b'\xc3\xbf',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   486
    'Yuml': b'\xc5\xb8',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   487
    'Zeta': b'\xce\x96',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   488
    'zeta': b'\xce\xb6',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   489
    'zwj': b'\xe2\x80\x8d',
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   490
    'zwnj': b'\xe2\x80\x8c',
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   491
    }
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   492
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   493
#------------------------------------------------------------------------
518
5be3fcb26c78 Semantic Name changes
rgbecker
parents: 514
diff changeset
   494
class ParaFrag(ABag):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   495
    """class ParaFrag contains the intermediate representation of string
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   496
    segments as they are being parsed by the XMLParser.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   497
    fontname, fontSize, rise, textColor, cbDefn
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   498
    """
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   499
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   500
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   501
_greek2Utf8=None
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   502
def _greekConvert(data):
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   503
    global _greek2Utf8
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   504
    if not _greek2Utf8:
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   505
        from reportlab.pdfbase.rl_codecs import RL_Codecs
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   506
        import codecs
3812
22a7f2e7ad1f paraparser.py: remove unused local var
robin
parents: 3809
diff changeset
   507
        #our decoding map
22a7f2e7ad1f paraparser.py: remove unused local var
robin
parents: 3809
diff changeset
   508
        dm = codecs.make_identity_dict(range(32,256))
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
   509
        for k in range(0,32):
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   510
            dm[k] = None
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   511
        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
   512
        _greek2Utf8 = {}
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
   513
        for k,v in dm.items():
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   514
            if not v:
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   515
                u = '\0'
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   516
            else:
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   517
                if isPy3:
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   518
                    u = chr(v)
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   519
                else:
3900
056aff5b1a58 paraparser.py: fix _greekConvert for 2.7
robin
parents: 3896
diff changeset
   520
                    u = unichr(v).encode('utf8')
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   521
            _greek2Utf8[chr(k)] = u
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   522
    return ''.join(map(_greek2Utf8.__getitem__,data))
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   523
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   524
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   525
def ugeCB(name):
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   526
    '''undefined general entity handler'''
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   527
    try:
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   528
        return greeks[name]
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   529
    except:
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   530
        return ('&#38;'+name+';').encode('utf8')
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   531
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   532
try:
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   533
    import pyRXPU
3826
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   534
    _TRMAP = dict(
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   535
            caseInsensitive='CaseInsensitive',
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   536
            )
3826
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   537
    def makeParser(**kwds):
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   538
        d = dict(ErrorOnUnquotedAttributeValues=0,
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   539
                Validate=0,srcName='Paragraph text',
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   540
                ugeCB = ugeCB,
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   541
                )
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   542
        for k in kwds:
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   543
            if k in _TRMAP:
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   544
                d[_TRMAP[k]] = kwds[k]
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   545
        return pyRXPU.Parser(**d)
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   546
except ImportError:
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   547
    raise ImportError("pyRXPU not importable Alternate parser not yet implemented")
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
   548
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   549
#------------------------------------------------------------------
267
52a348f6c4c3 noted replication of XML markup comment between paraparser.py and paragraph.py
aaron_watters
parents: 266
diff changeset
   550
# !!! 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
   551
# The ParaFormatter will be able to format the following
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   552
# tags:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   553
#       < /b > - bold
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   554
#       < /i > - italics
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   555
#       < u > < /u > - underline
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   556
#       < strike > < /strike > - strike through
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   557
#       < super > < /super > - superscript
1736
dafc17db33d2 Attempt to use sup as well as super
rgbecker
parents: 1683
diff changeset
   558
#       < sup > < /sup > - superscript
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   559
#       < sub > < /sub > - subscript
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   560
#       <font name=fontfamily/fontname color=colorname size=float>
3552
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   561
#        <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
   562
#       < bullet > </bullet> - bullet text (at head of para only)
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   563
#       <onDraw name=callable label="a label"/>
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   564
#       <index [name="callablecanvasattribute"] label="a label"/>
2670
3fdd642a7b76 minor cosmetic changes
rgbecker
parents: 2664
diff changeset
   565
#       <link>link text</link>
3fdd642a7b76 minor cosmetic changes
rgbecker
parents: 2664
diff changeset
   566
#           attributes of links 
3fdd642a7b76 minor cosmetic changes
rgbecker
parents: 2664
diff changeset
   567
#               size/fontSize=num
3fdd642a7b76 minor cosmetic changes
rgbecker
parents: 2664
diff changeset
   568
#               name/face/fontName=name
3fdd642a7b76 minor cosmetic changes
rgbecker
parents: 2664
diff changeset
   569
#               fg/textColor/color=color
3fdd642a7b76 minor cosmetic changes
rgbecker
parents: 2664
diff changeset
   570
#               backcolor/backColor/bgcolor=color
3fdd642a7b76 minor cosmetic changes
rgbecker
parents: 2664
diff changeset
   571
#               dest/destination/target/href/link=target
2745
0b44535fa1a5 paraparser/paragraph.py: fix comments
rgbecker
parents: 2744
diff changeset
   572
#       <a>anchor text</a>
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   573
#           attributes of anchors 
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   574
#               fontSize=num
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   575
#               fontName=name
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   576
#               fg/textColor/color=color
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   577
#               backcolor/backColor/bgcolor=color
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   578
#               href=href
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   579
#       <a name="anchorpoint"/>
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   580
#       <unichar name="unicode character name"/>
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   581
#       <unichar value="unicode code point"/>
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   582
#       <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
   583
#               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
   584
#               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
   585
#       <greek> - </greek>
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   586
#
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   587
#       The whole may be surrounded by <para> </para> tags
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   588
#
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   589
# It will also be able to handle any MathML specified Greek characters.
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   590
#------------------------------------------------------------------
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
   591
class ParaParser(HTMLParser):
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   592
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   593
    #----------------------------------------------------------
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   594
    # 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
   595
    #
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   596
    # start_<tag>(attributes)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   597
    # end_<tag>()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   598
    #
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   599
    # 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
   600
    # 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
   601
    # 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
   602
    # 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
   603
    # 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
   604
    # 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
   605
    #----------------------------------------------------------
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   606
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   607
    def __getattr__( self, attrName ):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   608
        """This way we can handle <TAG> the same way as <tag> (ignoring case)."""
2369
f3cc620c14ed paraparser.py: minor speedup
rgbecker
parents: 2368
diff changeset
   609
        if attrName!=attrName.lower() and attrName!="caseSensitive" and not self.caseSensitive and \
f3cc620c14ed paraparser.py: minor speedup
rgbecker
parents: 2368
diff changeset
   610
            (attrName.startswith("start_") or attrName.startswith("end_")):
f3cc620c14ed paraparser.py: minor speedup
rgbecker
parents: 2368
diff changeset
   611
                return getattr(self,attrName.lower())
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
   612
        raise AttributeError(attrName)
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   613
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   614
    #### bold
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   615
    def start_b( self, attributes ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   616
        self._push(bold=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   617
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   618
    def end_b( self ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   619
        self._pop(bold=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   620
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   621
    def start_strong( self, attributes ):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   622
        self._push(bold=1)
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   623
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   624
    def end_strong( self ):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   625
        self._pop(bold=1)
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   626
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   627
    #### italics
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   628
    def start_i( self, attributes ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   629
        self._push(italic=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   630
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   631
    def end_i( self ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   632
        self._pop(italic=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   633
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   634
    def start_em( self, attributes ):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   635
        self._push(italic=1)
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   636
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   637
    def end_em( self ):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   638
        self._pop(italic=1)
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   639
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   640
    #### underline
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   641
    def start_u( self, attributes ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   642
        self._push(underline=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   643
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   644
    def end_u( self ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   645
        self._pop(underline=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   646
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   647
    #### strike
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   648
    def start_strike( self, attributes ):
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   649
        self._push(strike=1)
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   650
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   651
    def end_strike( self ):
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   652
        self._pop(strike=1)
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   653
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   654
    #### link
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   655
    def start_link(self, attributes):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   656
        self._push(**self.getAttributes(attributes,_linkAttrMap))
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   657
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   658
    def end_link(self):
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   659
        frag = self._stack[-1]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   660
        del self._stack[-1]
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   661
        assert frag.link!=None
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   662
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   663
    #### anchor
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   664
    def start_a(self, attributes):
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   665
        A = self.getAttributes(attributes,_anchorAttrMap)
2893
7432e06445ba paraparser.py: improved checking on <a> tag attributes
rgbecker
parents: 2861
diff changeset
   666
        name = A.get('name',None)
7432e06445ba paraparser.py: improved checking on <a> tag attributes
rgbecker
parents: 2861
diff changeset
   667
        if name is not None:
7432e06445ba paraparser.py: improved checking on <a> tag attributes
rgbecker
parents: 2861
diff changeset
   668
            name = name.strip()
7432e06445ba paraparser.py: improved checking on <a> tag attributes
rgbecker
parents: 2861
diff changeset
   669
            if not name:
7432e06445ba paraparser.py: improved checking on <a> tag attributes
rgbecker
parents: 2861
diff changeset
   670
                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
   671
            if len(A)>1:
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   672
                self._syntax_error('<a name="..."/> anchor variant only allows name attribute')
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   673
                A = dict(name=A['name'])
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   674
            A['_selfClosingTag'] = 'anchor'
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   675
        else:
2893
7432e06445ba paraparser.py: improved checking on <a> tag attributes
rgbecker
parents: 2861
diff changeset
   676
            href = A.get('href','').strip()
7432e06445ba paraparser.py: improved checking on <a> tag attributes
rgbecker
parents: 2861
diff changeset
   677
            A['link'] = href    #convert to our link form
3931
ceee76b69e7c fix href bug reported by bitbucket.kmouts
robin
parents: 3900
diff changeset
   678
            A.pop('href',None)
2744
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   679
        self._push(**A)
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   680
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   681
    def end_a(self):
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   682
        frag = self._stack[-1]
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   683
        sct = getattr(frag,'_selfClosingTag','')
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   684
        if sct:
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   685
            assert sct=='anchor' and frag.name,'Parser failure in <a/>'
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   686
            defn = frag.cbDefn = ABag()
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   687
            defn.label = defn.kind = 'anchor'
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   688
            defn.name = frag.name
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   689
            del frag.name, frag._selfClosingTag
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   690
            self.handle_data('')
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   691
            self._pop()
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   692
        else:
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   693
            del self._stack[-1]
9472eedb9702 reportlab/platypus: add two way <a> tag
rgbecker
parents: 2742
diff changeset
   694
            assert frag.link!=None
2742
8edd54153201 paraparser: allow <a> as alias for <link>
rgbecker
parents: 2694
diff changeset
   695
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   696
    def start_img(self,attributes):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   697
        A = self.getAttributes(attributes,_imgAttrMap)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   698
        if not A.get('src'):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   699
            self._syntax_error('<img> needs src attribute')
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   700
        A['_selfClosingTag'] = 'img'
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   701
        self._push(**A)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   702
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   703
    def end_img(self):
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   704
        frag = self._stack[-1]
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   705
        assert getattr(frag,'_selfClosingTag',''),'Parser failure in <img/>'
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   706
        defn = frag.cbDefn = ABag()
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   707
        defn.kind = 'img'
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   708
        defn.src = getattr(frag,'src',None)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   709
        defn.image = ImageReader(defn.src)
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   710
        size = defn.image.getSize()
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   711
        defn.width = getattr(frag,'width',size[0])
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   712
        defn.height = getattr(frag,'height',size[1])
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   713
        defn.valign = getattr(frag,'valign','bottom')
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   714
        del frag._selfClosingTag
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   715
        self.handle_data('')
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   716
        self._pop()
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
   717
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   718
    #### super script
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   719
    def start_super( self, attributes ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   720
        self._push(super=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   721
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   722
    def end_super( self ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   723
        self._pop(super=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   724
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   725
    start_sup = start_super
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   726
    end_sup = end_super
1736
dafc17db33d2 Attempt to use sup as well as super
rgbecker
parents: 1683
diff changeset
   727
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   728
    #### sub script
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   729
    def start_sub( self, attributes ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   730
        self._push(sub=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   731
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   732
    def end_sub( self ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   733
        self._pop(sub=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   734
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   735
    #### greek script
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   736
    #### add symbol encoding
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   737
    def handle_charref(self, name):
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   738
        try:
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   739
            if name[0]=='x':
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   740
                n = int(name[1:],16)
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   741
            else:
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   742
                n = int(name)
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   743
        except ValueError:
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   744
            self.unknown_charref(name)
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   745
            return
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
   746
        self.handle_data(chr(n))   #.encode('utf8'))
134
60e8e0aee073 Fixed syntax_error handling
rgbecker
parents: 133
diff changeset
   747
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   748
    def syntax_error(self,lineno,message):
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
   749
        self._syntax_error(message)
134
60e8e0aee073 Fixed syntax_error handling
rgbecker
parents: 133
diff changeset
   750
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   751
    def _syntax_error(self,message):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   752
        if message[:10]=="attribute " and message[-17:]==" value not quoted": return
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   753
        self.errors.append(message)
134
60e8e0aee073 Fixed syntax_error handling
rgbecker
parents: 133
diff changeset
   754
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   755
    def start_greek(self, attr):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   756
        self._push(greek=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   757
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   758
    def end_greek(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   759
        self._pop(greek=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   760
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   761
    def start_unichar(self, attr):
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   762
        if 'name' in attr:
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   763
            if 'code' in attr:
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   764
                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
   765
            try:
3809
cbd390e6d557 paraparser.py: fix unichar
robin
parents: 3787
diff changeset
   766
                v = unicodedata.lookup(attr['name'])
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   767
            except KeyError:
3809
cbd390e6d557 paraparser.py: fix unichar
robin
parents: 3787
diff changeset
   768
                self._syntax_error('<unichar/> invalid name attribute\n"%s"' % ascii(name))
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   769
                v = '\0'
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   770
        elif 'code' in attr:
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   771
            try:
3937
f685e0de4282 paraparser.py:fix start_unichar for puython2
robin
parents: 3931
diff changeset
   772
                v = int(eval(attr['code']))
f685e0de4282 paraparser.py:fix start_unichar for puython2
robin
parents: 3931
diff changeset
   773
                v = chr(v) if isPy3 else unichr(v)
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   774
            except:
3809
cbd390e6d557 paraparser.py: fix unichar
robin
parents: 3787
diff changeset
   775
                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
   776
                v = '\0'
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   777
        else:
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   778
            v = None
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   779
            if attr:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
   780
                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
   781
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   782
        if v is not None:
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   783
            self.handle_data(v)
2585
ee08fea4505b reportlab: added pound sign
rgbecker
parents: 2584
diff changeset
   784
        self._push(_selfClosingTag='unichar')
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   785
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   786
    def end_unichar(self):
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   787
        self._pop()
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
   788
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   789
    def start_font(self,attr):
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   790
        self._push(**self.getAttributes(attr,_fontAttrMap))
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   791
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   792
    def end_font(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   793
        self._pop()
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   794
3552
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   795
    def start_span(self,attr):
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   796
        A = self.getAttributes(attr,_spanAttrMap)
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   797
        if 'style' in A:
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   798
            style = self.findSpanStyle(A.pop('style'))
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   799
            D = {}
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   800
            for k in 'fontName fontSize textColor backColor'.split():
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   801
                v = getattr(style,k,self)
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   802
                if v is self: continue
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   803
                D[k] = v
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   804
            D.update(A)
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   805
            A = D
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   806
        self._push(**A)
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   807
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   808
    end_span = end_font
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
   809
2663
927cc273c5a5 <br/> work in progress
andy
parents: 2646
diff changeset
   810
    def start_br(self, attr):
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   811
        self._push(_selfClosingTag='br',lineBreak=True,text='')
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
   812
        
2663
927cc273c5a5 <br/> work in progress
andy
parents: 2646
diff changeset
   813
    def end_br(self):
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
   814
        #print('\nend_br called, %d frags in list' % len(self.fragList))
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   815
        frag = self._stack[-1]
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   816
        assert frag._selfClosingTag=='br' and frag.lineBreak,'Parser failure in <br/>'
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   817
        del frag._selfClosingTag
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
   818
        self._handled_text = False
2664
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   819
        self.handle_data('')
c9faa3a99e93 reportlab/platypus: <br/> tags now working
rgbecker
parents: 2663
diff changeset
   820
        self._pop()
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
   821
        
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
   822
2663
927cc273c5a5 <br/> work in progress
andy
parents: 2646
diff changeset
   823
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   824
    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
   825
        style = self._style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   826
        if attr!={}:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   827
            style = copy.deepcopy(style)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   828
            _applyAttributes(style,self.getAttributes(attr,attrMap))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   829
            self._style = style
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   830
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   831
        # initialize semantic values
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   832
        frag = ParaFrag()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   833
        frag.sub = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   834
        frag.super = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   835
        frag.rise = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   836
        frag.underline = 0
2644
e762ad1c8909 reportlab: add support for strike through
rgbecker
parents: 2594
diff changeset
   837
        frag.strike = 0
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   838
        frag.greek = 0
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
   839
        frag.link = None
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   840
        if bullet:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   841
            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
   842
            frag.fontSize = style.bulletFontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   843
            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
   844
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   845
            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
   846
            frag.fontSize = style.fontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   847
            frag.textColor = style.textColor
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   848
        return frag
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   849
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   850
    def start_para(self,attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   851
        self._stack = [self._initial_frag(attr,_paraAttrMap)]
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   852
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   853
    def end_para(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   854
        self._pop()
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   855
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   856
    def start_bullet(self,attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   857
        if hasattr(self,'bFragList'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   858
            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
   859
        self.bFragList = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   860
        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
   861
        frag.isBullet = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   862
        self._stack.append(frag)
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
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_bullet(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   865
        self._pop()
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   866
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   867
    #---------------------------------------------------------------
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   868
    def start_seqdefault(self, attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   869
        try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   870
            default = attr['id']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   871
        except KeyError:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   872
            default = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   873
        self._seq.setDefaultCounter(default)
266
081154da1a78 Added Sequencer and associated XML tags
andy_robinson
parents: 253
diff changeset
   874
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   875
    def end_seqdefault(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   876
        pass
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   877
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   878
    def start_seqreset(self, attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   879
        try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   880
            id = attr['id']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   881
        except KeyError:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   882
            id = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   883
        try:
2368
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   884
            base = int(attr['base'])
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   885
        except:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   886
            base=0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   887
        self._seq.reset(id, base)
266
081154da1a78 Added Sequencer and associated XML tags
andy_robinson
parents: 253
diff changeset
   888
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   889
    def end_seqreset(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   890
        pass
744
2abd99baf95b Accepts seqdefault/seqDefault and seqreset/seqReset
andy_robinson
parents: 677
diff changeset
   891
2368
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   892
    def start_seqchain(self, attr):
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   893
        try:
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   894
            order = attr['order']
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   895
        except KeyError:
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   896
            order = ''
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   897
        order = order.split()
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   898
        seq = self._seq
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   899
        for p,c in zip(order[:-1],order[1:]):
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   900
            seq.chain(p, c)
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   901
    end_seqchain = end_seqreset
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   902
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   903
    def start_seqformat(self, attr):
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   904
        try:
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   905
            id = attr['id']
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   906
        except KeyError:
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   907
            id = None
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   908
        try:
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   909
            value = attr['value']
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   910
        except KeyError:
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   911
            value = '1'
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   912
        self._seq.setFormat(id,value)
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   913
    end_seqformat = end_seqreset
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   914
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   915
    # 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
   916
    # the above ones should be deprecated over time. 2001-03-22
2368
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   917
    start_seqDefault = start_seqdefault
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   918
    end_seqDefault = end_seqdefault
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   919
    start_seqReset = start_seqreset
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   920
    end_seqReset = end_seqreset
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   921
    start_seqChain = start_seqchain
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   922
    end_seqChain = end_seqchain
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   923
    start_seqFormat = start_seqformat
791a362e9cae added seqchain/format tags
rgbecker
parents: 2341
diff changeset
   924
    end_seqFormat = end_seqformat
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   925
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   926
    def start_seq(self, attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   927
        #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
   928
        #otherwise take default sequence
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   929
        if 'template' in attr:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   930
            templ = attr['template']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   931
            self.handle_data(templ % self._seq)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   932
            return
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   933
        elif 'id' in attr:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   934
            id = attr['id']
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   935
        else:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   936
            id = None
2694
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
   937
        increment = attr.get('inc', None)
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
   938
        if not increment:
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
   939
            output = self._seq.nextf(id)
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
   940
        else:
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
   941
            #accepts "no" for do not increment, or an integer.
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
   942
            #thus, 0 and 1 increment by the right amounts.
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
   943
            if increment.lower() == 'no':
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
   944
                output = self._seq.thisf(id)
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
   945
            else:
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
   946
                incr = int(increment)
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
   947
                output = self._seq.thisf(id)
dd0ea6474ea0 fixes to crashing PTO trailer when empty, and numbering
andy
parents: 2693
diff changeset
   948
                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
   949
        self.handle_data(output)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   950
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   951
    def end_seq(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   952
        pass
266
081154da1a78 Added Sequencer and associated XML tags
andy_robinson
parents: 253
diff changeset
   953
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   954
    def start_onDraw(self,attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   955
        defn = ABag()
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   956
        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
   957
        else: self._syntax_error('<onDraw> needs at least a name attribute')
506
68bd275f16e2 Added onDraw tag to paragraphs
rgbecker
parents: 494
diff changeset
   958
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   959
        if 'label' in attr: defn.label = attr['label']
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   960
        defn.kind='onDraw'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   961
        self._push(cbDefn=defn)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   962
        self.handle_data('')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   963
        self._pop()
3111
86a3158c50bd reportlab: improved support for onDraw and SimpleIndex
rgbecker
parents: 3032
diff changeset
   964
    end_onDraw=end_seq
86a3158c50bd reportlab: improved support for onDraw and SimpleIndex
rgbecker
parents: 3032
diff changeset
   965
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   966
    def start_index(self,attr):
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   967
        attr=self.getAttributes(attr,_indexAttrMap)
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   968
        defn = ABag()
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   969
        if 'item' in attr:
3187
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
   970
            label = attr['item']
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   971
        else:
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   972
            self._syntax_error('<index> needs at least an item attribute')
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3188
diff changeset
   973
        if 'name' in attr:
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   974
            name = attr['name']
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   975
        else:
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   976
            name = DEFAULT_INDEX_NAME
3187
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
   977
        format = attr.get('format',None)
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
   978
        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
   979
            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
   980
        offset = attr.get('offset',None)
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
   981
        if offset is not None:
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
   982
            try:
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
   983
                offset = int(offset)
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
   984
            except:
2d5a6655556e tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents: 3165
diff changeset
   985
                raise ValueError('index tag offset is %r not an int' % offset)
3856
5316e8678dd9 paraparser.py: fix label encoding
robin
parents: 3826
diff changeset
   986
        defn.label = encode_label((label,format,offset))
3165
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   987
        defn.name = name
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   988
        defn.kind='index'
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   989
        self._push(cbDefn=defn)
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   990
        self.handle_data('')
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   991
        self._pop()
cbda9e7d0ee3 reportlab: new index support
rgbecker
parents: 3137
diff changeset
   992
    end_index=end_seq
2663
927cc273c5a5 <br/> work in progress
andy
parents: 2646
diff changeset
   993
3826
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   994
    def start_unknown(self,attr):
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   995
        pass
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   996
    end_unknown=end_seq
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
   997
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   998
    #---------------------------------------------------------------
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   999
    def _push(self,**attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1000
        frag = copy.copy(self._stack[-1])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1001
        _applyAttributes(frag,attr)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1002
        self._stack.append(frag)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
  1003
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1004
    def _pop(self,**kw):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1005
        frag = self._stack[-1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1006
        del self._stack[-1]
3723
99aa837b6703 second stage of port to Python 3.3; working hello world
rptlab
parents: 3721
diff changeset
  1007
        for k, v in kw.items():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1008
            assert getattr(frag,k)==v
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1009
        return frag
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
  1010
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1011
    def getAttributes(self,attr,attrMap):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1012
        A = {}
3723
99aa837b6703 second stage of port to Python 3.3; working hello world
rptlab
parents: 3721
diff changeset
  1013
        for k, v in attr.items():
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
  1014
            if not self.caseSensitive:
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3723
diff changeset
  1015
                k = k.lower()
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3656
diff changeset
  1016
            if k in list(attrMap.keys()):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1017
                j = attrMap[k]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1018
                func = j[1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1019
                try:
3931
ceee76b69e7c fix href bug reported by bitbucket.kmouts
robin
parents: 3900
diff changeset
  1020
                    A[j[0]] = v if func is None else func(v)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1021
                except:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1022
                    self._syntax_error('%s: invalid value %s'%(k,v))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1023
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1024
                self._syntax_error('invalid attribute name %s'%k)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1025
        return A
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
  1026
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1027
    #----------------------------------------------------------------
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
  1028
3826
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
  1029
    def __init__(self,verbose=0, caseSensitive=0, ignoreUnknownTags=1):
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1030
        HTMLParser.__init__(self)
3826
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
  1031
        self.verbose = verbose
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
  1032
        self.caseSensitive = caseSensitive
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
  1033
        self.ignoreUnknownTags = ignoreUnknownTags
266
081154da1a78 Added Sequencer and associated XML tags
andy_robinson
parents: 253
diff changeset
  1034
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1035
    def _iReset(self):
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1036
        self._handled_text = False
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1037
        self.fragList = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1038
        if hasattr(self, 'bFragList'): delattr(self,'bFragList')
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
  1039
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1040
    def _reset(self, style):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1041
        '''reset the parser'''
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
  1042
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1043
        # initialize list of string segments to empty
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1044
        self.errors = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1045
        self._style = style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1046
        self._iReset()
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
  1047
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1048
    #----------------------------------------------------------------
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1049
    def handle_data(self,data):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1050
        "Creates an intermediate representation of string segments."
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
  1051
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1052
        #The old parser would only 'see' a string after all entities had
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1053
        #been processed.  Thus, 'Hello &trade; World' would emerge as one
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1054
        #fragment.    HTMLParser processes these separately.  We want to ensure
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1055
        #that successive calls like this are concatenated, to prevent too many
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1056
        #fragments being created.
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1057
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1058
        #print("\n called handle_data('%s')" % data)
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1059
        #print('handle_data("%s")' % data)
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1060
        if self._handled_text:
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1061
            #print('handle_more_data("%s")' % data)
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1062
            self.handle_more_data(data)
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1063
            return
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1064
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1065
        frag = copy.copy(self._stack[-1])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1066
        if hasattr(frag,'cbDefn'):
2857
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
  1067
            kind = frag.cbDefn.kind
487dc2450eec reprotlab: inline images horizontal positioning OK
rgbecker
parents: 2836
diff changeset
  1068
            if data: self._syntax_error('Only empty <%s> tag allowed' % kind)
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
  1069
        elif hasattr(frag,'_selfClosingTag'):
2663
927cc273c5a5 <br/> work in progress
andy
parents: 2646
diff changeset
  1070
            if data!='': self._syntax_error('No content allowed in %s tag' % frag._selfClosingTag)
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
  1071
            return
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1072
        else:
1736
dafc17db33d2 Attempt to use sup as well as super
rgbecker
parents: 1683
diff changeset
  1073
            # if sub and super are both on they will cancel each other out
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1074
            if frag.sub == 1 and frag.super == 1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1075
                frag.sub = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1076
                frag.super = 0
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
  1077
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1078
            if frag.sub:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1079
                frag.rise = -frag.fontSize*subFraction
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1080
                frag.fontSize = max(frag.fontSize-sizeDelta,3)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1081
            elif frag.super:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1082
                frag.rise = frag.fontSize*superFraction
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1083
                frag.fontSize = max(frag.fontSize-sizeDelta,3)
112
1d4892961fdb Added rise attribute
rgbecker
parents: 102
diff changeset
  1084
2584
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
  1085
            if frag.greek:
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
  1086
                frag.fontName = 'symbol'
0fed2bd8ef90 reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents: 2575
diff changeset
  1087
                data = _greekConvert(data)
514
3784fe357a72 Slight optimisation in handle_data for cbdefn frags
rgbecker
parents: 508
diff changeset
  1088
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1089
        # bold, italic, and underline
2861
2096955de8cf platypus: autoLeading vertical pos improvement
rgbecker
parents: 2860
diff changeset
  1090
        frag.fontName = tt2ps(frag.fontName,frag.bold,frag.italic)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
  1091
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1092
        #save our data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1093
        frag.text = data
514
3784fe357a72 Slight optimisation in handle_data for cbdefn frags
rgbecker
parents: 508
diff changeset
  1094
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1095
        if hasattr(frag,'isBullet'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1096
            delattr(frag,'isBullet')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1097
            self.bFragList.append(frag)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1098
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1099
            self.fragList.append(frag)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
  1100
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1101
        #Set this if we just processed sme text, but not if it was a br tag.
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1102
        #Ugly, but seems necessary to get pyRXP and HTMLParser working the
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1103
        #same way.
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1104
        if not hasattr(frag, 'lineBreak'):
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1105
            self._handled_text = True
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1106
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1107
    def handle_cdata(self,data):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1108
        self.handle_data(data)
211
52541f1643b6 CDATA handler added
rgbecker
parents: 209
diff changeset
  1109
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1110
    def _setup_for_parse(self,style):
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1111
        self._seq = reportlab.lib.sequencer.getSequencer()
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1112
        self._reset(style)  # reinitialise the parser
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1113
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1114
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1115
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1116
    def old_parse(self, text, style):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1117
        """Given a formatted string will return a list of
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1118
        ParaFrag objects with their calculated widths.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1119
        If errors occur None will be returned and the
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1120
        self.errors holds a list of the error messages.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1121
        """
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1122
        self._setup_for_parse(style)
3896
7da4fe956715 paraparser.py: fix on uncode as early as possible
robin
parents: 3883
diff changeset
  1123
        text = asUnicode(text)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1124
        if not(len(text)>=6 and text[0]=='<' and _re_para.match(text)):
3896
7da4fe956715 paraparser.py: fix on uncode as early as possible
robin
parents: 3883
diff changeset
  1125
            text = u"<para>"+text+u"</para>"
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
  1126
        try:
3826
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
  1127
            tt = makeParser(caseInsensitive=not self.caseSensitive)(text)
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1128
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1129
            #from pprint import pprint
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1130
            #pprint(tt)
3883
ef5b12e5f4e2 paraparser.py: remove 3 only execption code
robin
parents: 3856
diff changeset
  1131
        except:
ef5b12e5f4e2 paraparser.py: remove 3 only execption code
robin
parents: 3856
diff changeset
  1132
            annotateException('paragraph text %s caused exception' % ascii(text))
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
  1133
        self._tt_start(tt)
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1134
        return self._complete_parse()
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1135
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1136
    def _complete_parse(self):
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1137
        "Reset after parsing, to be ready for next paragraph"
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1138
        del self._seq
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1139
        style = self._style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1140
        del self._style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1141
        if len(self.errors)==0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1142
            fragList = self.fragList
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1143
            bFragList = hasattr(self,'bFragList') and self.bFragList or None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1144
            self._iReset()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1145
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1146
            fragList = bFragList = None
2575
0cba68b93555 reportlab-utf8 moved to trunk
rgbecker
parents: 2446
diff changeset
  1147
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
  1148
        return style, fragList, bFragList
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
  1149
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
  1150
    def _tt_handle(self,tt):
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1151
        "Iterate through a pre-parsed tuple tree (e.g. from pyRXP)"
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1152
        #import pprint
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1153
        #pprint.pprint(tt)
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1154
        #find the corresponding start_tagname and end_tagname methods.
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1155
        #These must be defined.
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1156
        tag = tt[0]
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1157
        try:
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1158
            start = getattr(self,'start_'+tag)
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1159
            end = getattr(self,'end_'+tag)
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1160
        except AttributeError:
3826
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
  1161
            if not self.ignoreUnknownTags:
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
  1162
                raise ValueError('Invalid tag "%s"' % tag)
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
  1163
            start = self.start_unknown
02f216b6e38e paraparser.py: support old behaviours eg ignore unknown tags etc etc
robin
parents: 3812
diff changeset
  1164
            end = self.end_unknown
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1165
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1166
        #call the start_tagname method
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1167
        start(tt[1] or {})
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1168
        self._handled_text = False
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1169
        #if tree node has any children, they will either be further nodes,
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1170
        #or text.  Accordingly, call either this function, or handle_data.
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1171
        C = tt[2]
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1172
        if C:
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1173
            M = self._tt_handlers
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1174
            for c in C:
3731
b233dd0577ff another round of changes mostly type related
rptlab
parents: 3723
diff changeset
  1175
                M[isinstance(c,(list,tuple))](c)
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1176
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1177
        #call the end_tagname method
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1178
        end()
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1179
        self._handled_text = False
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1180
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
  1181
    def _tt_start(self,tt):
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
  1182
        self._tt_handlers = self.handle_data,self._tt_handle
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
  1183
        self._tt_handle(tt)
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
  1184
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1185
    def tt_parse(self,tt,style):
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1186
        '''parse from tupletree form'''
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1187
        self._setup_for_parse(style)
3787
8f9be6d6f75c convert paraparser to use pyRXP directly (or any TT producer)
robin
parents: 3731
diff changeset
  1188
        self._tt_start(tt)
2376
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1189
        return self._complete_parse()
7e70411a7236 flowables.py: minor change to PTOContainer
rgbecker
parents: 2369
diff changeset
  1190
3552
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
  1191
    def findSpanStyle(self,style):
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
  1192
        raise ValueError('findSpanStyle not implemented in this parser')
20ecbcc53c15 paraparser.py add support for <span style=stylename>
rgbecker
parents: 3440
diff changeset
  1193
3954
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1194
44dbe56eb858 first attempt at HTMLParser-based paraparser
Andy Robinson <andy@reportlab.com>
parents: 3937
diff changeset
  1195