reportlab/platypus/paraparser.py
author andy
Mon, 14 Jun 2004 16:41:25 +0000
changeset 2321 3454f5b41760
parent 2200 be0cfccc662a
child 2332 2a7ab4405e18
permissions -rw-r--r--
Unicode and UTF8 support changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 433
diff changeset
     1
#copyright ReportLab Inc. 2000
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 433
diff changeset
     2
#see license.txt for license details
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 433
diff changeset
     3
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/paraparser.py?cvsroot=reportlab
2200
be0cfccc662a Fixed up tabs and whitespace in all source files
andy_robinson
parents: 2053
diff changeset
     4
#$Header: /tmp/reportlab/reportlab/platypus/paraparser.py,v 1.54 2004/01/20 22:50:32 andy_robinson Exp $
2321
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
     5
__version__=''' $Id$ '''
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
2321
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
     8
from types import TupleType, UnicodeType, StringType
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
     9
import sys
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    10
import os
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    11
import copy
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    12
279
e7d8b3631d5c Global sequencer put in the 'story builder'.
andy_robinson
parents: 267
diff changeset
    13
import reportlab.lib.sequencer
518
5be3fcb26c78 Semantic Name changes
rgbecker
parents: 514
diff changeset
    14
from reportlab.lib.abag import ABag
1160
2cb58079d830 Removed Aaron's rather thoughtless hacks
rgbecker
parents: 1156
diff changeset
    15
209
f46e0d4d113b made size alias of fontsize for <para>
rgbecker
parents: 192
diff changeset
    16
try:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    17
    from reportlab.lib import xmllib
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    18
    _xmllib_newStyle = 1
2053
2a962a30dc46 Removed checkImportError
rgbecker
parents: 1944
diff changeset
    19
except ImportError:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    20
    import xmllib
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    21
    _xmllib_newStyle = 0
209
f46e0d4d113b made size alias of fontsize for <para>
rgbecker
parents: 192
diff changeset
    22
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    23
248
c103b7a55e79 Color fixes; thanks to J Alet
rgbecker
parents: 238
diff changeset
    24
from reportlab.lib.colors import toColor, white, black, red, Color
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    25
from reportlab.lib.fonts import tt2ps, ps2tt
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
    26
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
    27
from reportlab.lib.units import inch,mm,cm,pica
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
    28
_re_para = re.compile('^\\s*<\\s*para(\\s+|>)')
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
    29
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    30
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
    31
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
    32
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
    33
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    34
def _num(s, unit=1):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    35
    """Convert a string like '10cm' to an int or float (in points).
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    36
       The default unit is point, but optionally you can use other
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    37
       default units like mm.
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    38
    """
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    39
    if s[-2:]=='cm':
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    40
        unit=cm
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    41
        s = s[:-2]
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    42
    if s[-2:]=='in':
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    43
        unit=inch
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    44
        s = s[:-2]
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    45
    if s[-2:]=='pt':
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    46
        unit=1
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    47
        s = s[:-2]
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    48
    if s[-1:]=='i':
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    49
        unit=inch
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    50
        s = s[:-1]
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    51
    if s[-2:]=='mm':
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    52
        unit=mm
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    53
        s = s[:-2]
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    54
    if s[-4:]=='pica':
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    55
        unit=pica
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    56
        s = s[:-4]
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    57
    if s[0] in ['+','-']:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    58
        try:
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    59
            return ('relative',int(s)*unit)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    60
        except ValueError:
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    61
            return ('relative',float(s)*unit)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    62
    else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    63
        try:
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    64
            return int(s)*unit
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    65
        except ValueError:
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    66
            return float(s)*unit
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
    67
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
    68
def _align(s):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    69
    s = string.lower(s)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    70
    if s=='left': return TA_LEFT
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    71
    elif s=='right': return TA_RIGHT
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    72
    elif s=='justify': return TA_JUSTIFY
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    73
    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
    74
    else: raise ValueError
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
    75
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
    76
_paraAttrMap = {'font': ('fontName', None),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    77
                'face': ('fontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    78
                'fontsize': ('fontSize', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    79
                'size': ('fontSize', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    80
                'leading': ('leading', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    81
                'lindent': ('leftIndent', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    82
                'rindent': ('rightIndent', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    83
                'findent': ('firstLineIndent', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    84
                'align': ('alignment', _align),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    85
                'spaceb': ('spaceBefore', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    86
                'spacea': ('spaceAfter', _num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    87
                'bfont': ('bulletFontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    88
                'bfontsize': ('bulletFontSize',_num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    89
                'bindent': ('bulletIndent',_num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    90
                'bcolor': ('bulletColor',toColor),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    91
                'color':('textColor',toColor),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    92
                'backcolor':('backColor',toColor),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    93
                'bgcolor':('backColor',toColor),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    94
                'bg':('backColor',toColor),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    95
                'fg': ('textColor',toColor),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
    96
                }
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
    97
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
    98
_bulletAttrMap = {
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
    99
                'font': ('bulletFontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   100
                'face': ('bulletFontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   101
                'size': ('bulletFontSize',_num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   102
                'fontsize': ('bulletFontSize',_num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   103
                'indent': ('bulletIndent',_num),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   104
                'color': ('bulletColor',toColor),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   105
                'fg': ('bulletColor',toColor),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   106
                }
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   107
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   108
#things which are valid font attributes
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   109
_fontAttrMap = {'size': ('fontSize', _num),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   110
                'face': ('fontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   111
                'name': ('fontName', None),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   112
                'fg':   ('textColor', toColor),
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   113
                'color':('textColor', toColor),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   114
                }
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   115
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   116
def _addAttributeNames(m):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   117
    K = m.keys()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   118
    for k in K:
1944
a50f8e3f93f8 laissez faire case
rgbecker
parents: 1940
diff changeset
   119
        n = m[k][0]
a50f8e3f93f8 laissez faire case
rgbecker
parents: 1940
diff changeset
   120
        if not m.has_key(n): m[n] = m[k]
a50f8e3f93f8 laissez faire case
rgbecker
parents: 1940
diff changeset
   121
        n = string.lower(n)
a50f8e3f93f8 laissez faire case
rgbecker
parents: 1940
diff changeset
   122
        if not m.has_key(n): m[n] = m[k]
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   123
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   124
_addAttributeNames(_paraAttrMap)
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   125
_addAttributeNames(_fontAttrMap)
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   126
_addAttributeNames(_bulletAttrMap)
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   127
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   128
def _applyAttributes(obj, attr):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   129
    for k, v in attr.items():
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   130
        if type(v) is TupleType and v[0]=='relative':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   131
            #AR 20/5/2000 - remove 1.5.2-ism
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   132
            #v = v[1]+getattr(obj,k,0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   133
            if hasattr(obj, k):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   134
                v = v[1]+getattr(obj,k)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   135
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   136
                v = v[1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   137
        setattr(obj,k,v)
102
1818e7fa3738 Added clone method to ParaFrag
rgbecker
parents: 96
diff changeset
   138
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   139
#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
   140
#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
   141
#numeric entity names that follow.
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   142
greeks = {
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   143
    'Alpha': 'A',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   144
    'Beta': 'B',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   145
    'Chi': 'C',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   146
    'Delta': 'D',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   147
    'Epsilon': 'E',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   148
    'Eta': 'H',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   149
    'Gamma': 'G',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   150
    'Iota': 'I',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   151
    'Kappa': 'K',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   152
    'Lambda': 'L',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   153
    'Mu': 'M',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   154
    'Nu': 'N',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   155
    'Omega': 'W',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   156
    'Omicron': 'O',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   157
    'Phi': 'F',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   158
    'Pi': 'P',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   159
    'Psi': 'Y',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   160
    'Rho': 'R',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   161
    'Sigma': 'S',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   162
    'Tau': 'T',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   163
    'Theta': 'Q',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   164
    'Upsilon': 'U',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   165
    'Xi': 'X',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   166
    'Zeta': 'Z',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   167
    'alefsym': '\xc0',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   168
    'alpha': 'a',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   169
    'and': '\xd9',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   170
    'ang': '\xd0',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   171
    'asymp': '\xbb',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   172
    'beta': 'b',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   173
    'bull': '\xb7',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   174
    'cap': '\xc7',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   175
    'chi': 'c',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   176
    'clubs': '\xa7',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   177
    'cong': '@',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   178
    'cup': '\xc8',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   179
    'dArr': '\xdf',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   180
    'darr': '\xaf',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   181
    'delta': 'd',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   182
    'diams': '\xa8',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   183
    'empty': '\xc6',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   184
    'epsilon': 'e',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   185
    'epsiv': 'e',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   186
    'equiv': '\xba',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   187
    'eta': 'h',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   188
    'euro': '\xa0',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   189
    'exist': '$',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   190
    'forall': '"',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   191
    'frasl': '\xa4',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   192
    'gamma': 'g',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   193
    'ge': '\xb3',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   194
    'hArr': '\xdb',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   195
    'harr': '\xab',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   196
    'hearts': '\xa9',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   197
    'hellip': '\xbc',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   198
    'image': '\xc1',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   199
    'infin': '\xa5',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   200
    'int': '\xf2',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   201
    'iota': 'i',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   202
    'isin': '\xce',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   203
    'kappa': 'k',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   204
    'lArr': '\xdc',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   205
    'lambda': 'l',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   206
    'lang': '\xe1',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   207
    'larr': '\xac',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   208
    'lceil': '\xe9',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   209
    'le': '\xa3',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   210
    'lfloor': '\xeb',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   211
    'lowast': '*',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   212
    'loz': '\xe0',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   213
    'minus': '-',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   214
    'mu': 'm',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   215
    'nabla': '\xd1',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   216
    'ne': '\xb9',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   217
    'ni': "'",
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   218
    'notin': '\xcf',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   219
    'nsub': '\xcb',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   220
    'nu': 'n',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   221
    'oline': '`',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   222
    'omega': 'w',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   223
    'omicron': 'o',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   224
    'oplus': '\xc5',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   225
    'or': '\xda',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   226
    'otimes': '\xc4',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   227
    'part': '\xb6',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   228
    'perp': '^',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   229
    'phi': 'j',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   230
    'phis': 'f',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   231
    'pi': 'p',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   232
    'piv': 'v',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   233
    'prime': '\xa2',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   234
    'prod': '\xd5',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   235
    'prop': '\xb5',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   236
    'psi': 'y',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   237
    'rArr': '\xde',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   238
    'radic': '\xd6',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   239
    'rang': '\xf1',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   240
    'rarr': '\xae',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   241
    'rceil': '\xf9',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   242
    'real': '\xc2',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   243
    'rfloor': '\xfb',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   244
    'rho': 'r',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   245
    'sdot': '\xd7',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   246
    'sigma': 's',
1932
4251a2dc4b10 Final fixes to special charrefs
rgbecker
parents: 1931
diff changeset
   247
    'sigmaf': 'V',
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   248
    'sigmav': 'V',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   249
    'sim': '~',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   250
    'spades': '\xaa',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   251
    'sub': '\xcc',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   252
    'sube': '\xcd',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   253
    'sum': '\xe5',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   254
    'sup': '\xc9',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   255
    'supe': '\xca',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   256
    'tau': 't',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   257
    'there4': '\\',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   258
    'theta': 'q',
1932
4251a2dc4b10 Final fixes to special charrefs
rgbecker
parents: 1931
diff changeset
   259
    'thetasym': 'J',
4251a2dc4b10 Final fixes to special charrefs
rgbecker
parents: 1931
diff changeset
   260
    'thetav': 'J',
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   261
    'trade': '\xe4',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   262
    'uArr': '\xdd',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   263
    'uarr': '\xad',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   264
    'upsih': '\xa1',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   265
    'upsilon': 'u',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   266
    'weierp': '\xc3',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   267
    'xi': 'x',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   268
    'zeta': 'z',
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   269
    }
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   270
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   271
# mapping of xml character entities to symbol encoding
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   272
symenc = {
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   273
    # greek letters
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   274
    913:'A', # Alpha
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   275
    914:'B', # Beta
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   276
    915:'G', # Gamma
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   277
    916:'D', # Delta
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   278
    917:'E', # Epsilon
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   279
    918:'Z', # Zeta
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   280
    919:'H', # Eta
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   281
    920:'Q', # Theta
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   282
    921:'I', # Iota
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   283
    922:'K', # Kappa
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   284
    923:'L', # Lambda
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   285
    924:'M', # Mu
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   286
    925:'N', # Nu
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   287
    926:'X', # Xi
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   288
    927:'O', # Omicron
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   289
    928:'P', # Pi
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   290
    929:'R', # Rho
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   291
    931:'S', # Sigma
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   292
    932:'T', # Tau
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   293
    933:'U', # Upsilon
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   294
    934:'F', # Phi
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   295
    935:'C', # Chi
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   296
    936:'Y', # Psi
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   297
    937:'W', # Omega
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   298
    945:'a', # alpha
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   299
    946:'b', # beta
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   300
    947:'g', # gamma
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   301
    948:'d', # delta
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   302
    949:'e', # epsilon
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   303
    950:'z', # zeta
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   304
    951:'h', # eta
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   305
    952:'q', # theta
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   306
    953:'i', # iota
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   307
    954:'k', # kappa
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   308
    955:'l', # lambda
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   309
    956:'m', # mu
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   310
    957:'n', # nu
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   311
    958:'x', # xi
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   312
    959:'o', # omicron
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   313
    960:'p', # pi
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   314
    961:'r', # rho
1932
4251a2dc4b10 Final fixes to special charrefs
rgbecker
parents: 1931
diff changeset
   315
    962:'V', # sigmaf
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   316
    963:'s', # sigma
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   317
    964:'t', # tau
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   318
    965:'u', # upsilon
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   319
    966:'j', # phi
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   320
    967:'c', # chi
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   321
    968:'y', # psi
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   322
    969:'w', # omega
1932
4251a2dc4b10 Final fixes to special charrefs
rgbecker
parents: 1931
diff changeset
   323
    977:'J', # thetasym
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   324
    978:'\241', # upsih
1932
4251a2dc4b10 Final fixes to special charrefs
rgbecker
parents: 1931
diff changeset
   325
    981:'f', # phis
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   326
    982:'v', # piv
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   327
    # mathematical symbols
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   328
    8704:'"', # forall
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   329
    8706:'\266', # part
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   330
    8707:'$', # exist
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   331
    8709:'\306', # empty
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   332
    8711:'\321', # nabla
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   333
    8712:'\316', # isin
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   334
    8713:'\317', # notin
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   335
    8715:'\'', # ni
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   336
    8719:'\325', # prod
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   337
    8721:'\345', # sum
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   338
    8722:'-', # minus
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   339
    8727:'*', # lowast
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   340
    8730:'\326', # radic
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   341
    8733:'\265', # prop
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   342
    8734:'\245', # infin
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   343
    8736:'\320', # ang
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   344
    8869:'\331', # and
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   345
    8870:'\332', # or
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   346
    8745:'\307', # cap
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   347
    8746:'\310', # cup
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   348
    8747:'\362', # int
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   349
    8756:'\\', # there4
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   350
    8764:'~', # sim
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   351
    8773:'@', # cong
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   352
    8776:'\273', #asymp
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   353
    8800:'\271', # ne
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   354
    8801:'\272', # equiv
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   355
    8804:'\243', # le
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   356
    8805:'\263', # ge
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   357
    8834:'\314', # sub
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   358
    8835:'\311', # sup
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   359
    8836:'\313', # nsub
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   360
    8838:'\315', # sube
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   361
    8839:'\312', # supe
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   362
    8853:'\305', # oplus
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   363
    8855:'\304', # otimes
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   364
    8869:'^', # perp
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   365
    8901:'\327', # sdot
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   366
    9674:'\340', # loz
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   367
    # technical symbols
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   368
    8968:'\351', # lceil
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   369
    8969:'\371', # rceil
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   370
    8970:'\353', # lfloor
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   371
    8971:'\373', # rfloor
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   372
    9001:'\341', # lang
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   373
    9002:'\361', # rang
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   374
    # arrow symbols
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   375
    8592:'\254', # larr
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   376
    8593:'\255', # uarr
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   377
    8594:'\256', # rarr
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   378
    8595:'\257', # darr
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   379
    8596:'\253', # harr
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   380
    8656:'\334', # lArr
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   381
    8657:'\335', # uArr
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   382
    8658:'\336', # rArr
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   383
    8659:'\337', # dArr
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   384
    8660:'\333', # hArr
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   385
    # divers symbols
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   386
    8226:'\267', # bull
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   387
    8230:'\274', # hellip
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   388
    8242:'\242', # prime
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   389
    8254:'`', # oline
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   390
    8260:'\244', # frasl
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   391
    8472:'\303', # weierp
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   392
    8465:'\301', # image
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   393
    8476:'\302', # real
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   394
    8482:'\344', # trade
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   395
    8364:'\240', # euro
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   396
    8501:'\300', # alefsym
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   397
    9824:'\252', # spades
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   398
    9827:'\247', # clubs
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   399
    9829:'\251', # hearts
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   400
    9830:'\250' # diams
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   401
    }
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   402
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   403
#------------------------------------------------------------------------
518
5be3fcb26c78 Semantic Name changes
rgbecker
parents: 514
diff changeset
   404
class ParaFrag(ABag):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   405
    """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
   406
    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
   407
    fontname, fontSize, rise, textColor, cbDefn
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   408
    """
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   409
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   410
#------------------------------------------------------------------
267
52a348f6c4c3 noted replication of XML markup comment between paraparser.py and paragraph.py
aaron_watters
parents: 266
diff changeset
   411
# !!! NOTE !!! THIS TEXT IS NOW REPLICATED IN PARAGRAPH.PY !!!
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   412
# The ParaFormatter will be able to format the following xml
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   413
# tags:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   414
#       < /b > - bold
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   415
#       < /i > - italics
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   416
#       < u > < /u > - underline
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   417
#       < super > < /super > - superscript
1736
dafc17db33d2 Attempt to use sup as well as super
rgbecker
parents: 1683
diff changeset
   418
#       < sup > < /sup > - superscript
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   419
#       < sub > < /sub > - subscript
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   420
#       <font name=fontfamily/fontname color=colorname size=float>
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   421
#       < bullet > </bullet> - bullet text (at head of para only)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   422
#       <onDraw name=callable label="a label">
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   423
#
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   424
#       The whole may be surrounded by <para> </para> tags
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   425
#
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   426
# It will also be able to handle any MathML specified Greek characters.
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   427
#------------------------------------------------------------------
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   428
class ParaParser(xmllib.XMLParser):
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   429
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   430
    #----------------------------------------------------------
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   431
    # 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
   432
    #
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   433
    # start_<tag>(attributes)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   434
    # end_<tag>()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   435
    #
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   436
    # 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
   437
    # 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
   438
    # 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
   439
    # 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
   440
    # 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
   441
    # 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
   442
    #----------------------------------------------------------
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   443
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   444
    def __getattr__( self, attrName ):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   445
        """This way we can handle <TAG> the same way as <tag> (ignoring case)."""
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   446
        if attrName != attrName.lower() and attrName!="caseSensitive" and not self.caseSensitive:
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   447
            if attrName[:6]=="start_":
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   448
                return eval ("self."+attrName.lower())
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   449
            if attrName[:4]=="end_":
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   450
                return eval ("self."+attrName.lower())
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   451
        raise AttributeError, attrName
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   452
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   453
    #### bold
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   454
    def start_b( self, attributes ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   455
        self._push(bold=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   456
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   457
    def end_b( self ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   458
        self._pop(bold=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   459
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   460
    def start_strong( self, attributes ):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   461
        self._push(bold=1)
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   462
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   463
    def end_strong( self ):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   464
        self._pop(bold=1)
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   465
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   466
    #### italics
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   467
    def start_i( self, attributes ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   468
        self._push(italic=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   469
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   470
    def end_i( self ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   471
        self._pop(italic=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   472
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   473
    def start_em( self, attributes ):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   474
        self._push(italic=1)
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   475
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   476
    def end_em( self ):
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   477
        self._pop(italic=1)
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   478
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   479
    #### underline
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   480
    def start_u( self, attributes ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   481
        self._push(underline=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   482
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   483
    def end_u( self ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   484
        self._pop(underline=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   485
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   486
    #### super script
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   487
    def start_super( self, attributes ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   488
        self._push(super=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   489
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   490
    def end_super( self ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   491
        self._pop(super=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   492
1736
dafc17db33d2 Attempt to use sup as well as super
rgbecker
parents: 1683
diff changeset
   493
    if _xmllib_newStyle:
dafc17db33d2 Attempt to use sup as well as super
rgbecker
parents: 1683
diff changeset
   494
        start_sup = start_super
dafc17db33d2 Attempt to use sup as well as super
rgbecker
parents: 1683
diff changeset
   495
        end_sup = end_super
dafc17db33d2 Attempt to use sup as well as super
rgbecker
parents: 1683
diff changeset
   496
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   497
    #### sub script
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   498
    def start_sub( self, attributes ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   499
        self._push(sub=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   500
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   501
    def end_sub( self ):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   502
        self._pop(sub=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   503
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   504
    #### greek script
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   505
    if _xmllib_newStyle:
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   506
        #### add symbol encoding
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   507
        def handle_charref(self, name):
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   508
            try:
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   509
                if name[0] == 'x':
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   510
                    n = string.atoi(name[1:], 16)
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   511
                else:
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   512
                    n = string.atoi(name)
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   513
            except string.atoi_error:
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   514
                self.unknown_charref(name)
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   515
                return
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   516
            if 0 <=n<=255:
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   517
                self.handle_data(chr(n))
1932
4251a2dc4b10 Final fixes to special charrefs
rgbecker
parents: 1931
diff changeset
   518
            elif symenc.has_key(n):
4251a2dc4b10 Final fixes to special charrefs
rgbecker
parents: 1931
diff changeset
   519
                self._push(greek=1)
4251a2dc4b10 Final fixes to special charrefs
rgbecker
parents: 1931
diff changeset
   520
                self.handle_data(symenc[n])
4251a2dc4b10 Final fixes to special charrefs
rgbecker
parents: 1931
diff changeset
   521
                self._pop(greek=1)
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   522
            else:
1932
4251a2dc4b10 Final fixes to special charrefs
rgbecker
parents: 1931
diff changeset
   523
                self.unknown_charref(name)
1931
784fce255e2d Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents: 1736
diff changeset
   524
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   525
        def handle_entityref(self,name):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   526
            if greeks.has_key(name):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   527
                self._push(greek=1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   528
                self.handle_data(greeks[name])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   529
                self._pop(greek=1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   530
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   531
                xmllib.XMLParser.handle_entityref(self,name)
134
60e8e0aee073 Fixed syntax_error handling
rgbecker
parents: 133
diff changeset
   532
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   533
        def syntax_error(self,lineno,message):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   534
            self._syntax_error(message)
134
60e8e0aee073 Fixed syntax_error handling
rgbecker
parents: 133
diff changeset
   535
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   536
    else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   537
        def start_greekLetter(self, attributes,letter):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   538
            self._push(greek=1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   539
            self.handle_data(letter)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   540
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   541
        def syntax_error(self,message):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   542
            self._syntax_error(message)
134
60e8e0aee073 Fixed syntax_error handling
rgbecker
parents: 133
diff changeset
   543
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   544
    def _syntax_error(self,message):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   545
        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
   546
        self.errors.append(message)
134
60e8e0aee073 Fixed syntax_error handling
rgbecker
parents: 133
diff changeset
   547
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   548
    def start_greek(self, attributes):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   549
        self._push(greek=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   550
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   551
    def end_greek(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   552
        self._pop(greek=1)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   553
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   554
    def start_font(self,attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   555
        apply(self._push,(),self.getAttributes(attr,_fontAttrMap))
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   556
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   557
    def end_font(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   558
        self._pop()
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   559
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   560
    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
   561
        style = self._style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   562
        if attr!={}:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   563
            style = copy.deepcopy(style)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   564
            _applyAttributes(style,self.getAttributes(attr,attrMap))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   565
            self._style = style
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   566
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   567
        # initialize semantic values
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   568
        frag = ParaFrag()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   569
        frag.sub = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   570
        frag.super = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   571
        frag.rise = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   572
        frag.underline = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   573
        frag.greek = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   574
        if bullet:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   575
            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
   576
            frag.fontSize = style.bulletFontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   577
            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
   578
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   579
            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
   580
            frag.fontSize = style.fontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   581
            frag.textColor = style.textColor
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   582
        return frag
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   583
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   584
    def start_para(self,attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   585
        self._stack = [self._initial_frag(attr,_paraAttrMap)]
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   586
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   587
    def end_para(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   588
        self._pop()
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   589
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   590
    def start_bullet(self,attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   591
        if hasattr(self,'bFragList'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   592
            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
   593
        self.bFragList = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   594
        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
   595
        frag.isBullet = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   596
        self._stack.append(frag)
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   597
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   598
    def end_bullet(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   599
        self._pop()
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   600
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   601
    #---------------------------------------------------------------
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   602
    def start_seqdefault(self, attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   603
        try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   604
            default = attr['id']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   605
        except KeyError:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   606
            default = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   607
        self._seq.setDefaultCounter(default)
266
081154da1a78 Added Sequencer and associated XML tags
andy_robinson
parents: 253
diff changeset
   608
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   609
    def end_seqdefault(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   610
        pass
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   611
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   612
    def start_seqreset(self, attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   613
        try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   614
            id = attr['id']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   615
        except KeyError:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   616
            id = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   617
        try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   618
            base = math.atoi(attr['base'])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   619
        except:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   620
            base=0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   621
        self._seq.reset(id, base)
266
081154da1a78 Added Sequencer and associated XML tags
andy_robinson
parents: 253
diff changeset
   622
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   623
    def end_seqreset(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   624
        pass
744
2abd99baf95b Accepts seqdefault/seqDefault and seqreset/seqReset
andy_robinson
parents: 677
diff changeset
   625
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   626
    # 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
   627
    # the above ones should be deprecated over time. 2001-03-22
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   628
    def start_seqDefault(self, attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   629
        self.start_seqdefault(attr)
744
2abd99baf95b Accepts seqdefault/seqDefault and seqreset/seqReset
andy_robinson
parents: 677
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_seqDefault(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   632
        self.end_seqdefault()
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   633
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   634
    def start_seqReset(self, attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   635
        self.start_seqreset(attr)
744
2abd99baf95b Accepts seqdefault/seqDefault and seqreset/seqReset
andy_robinson
parents: 677
diff changeset
   636
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   637
    def end_seqReset(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   638
        self.end_seqreset()
744
2abd99baf95b Accepts seqdefault/seqDefault and seqreset/seqReset
andy_robinson
parents: 677
diff changeset
   639
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   640
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   641
    def start_seq(self, attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   642
        #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
   643
        #otherwise take default sequence
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   644
        if attr.has_key('template'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   645
            templ = attr['template']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   646
            self.handle_data(templ % self._seq)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   647
            return
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   648
        elif attr.has_key('id'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   649
            id = attr['id']
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   650
        else:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   651
            id = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   652
        output = self._seq.nextf(id)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   653
        self.handle_data(output)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   654
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   655
    def end_seq(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   656
        pass
266
081154da1a78 Added Sequencer and associated XML tags
andy_robinson
parents: 253
diff changeset
   657
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   658
    def start_onDraw(self,attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   659
        defn = ABag()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   660
        if attr.has_key('name'): defn.name = attr['name']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   661
        else: self._syntax_error('<onDraw> needs at least a name attribute')
506
68bd275f16e2 Added onDraw tag to paragraphs
rgbecker
parents: 494
diff changeset
   662
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   663
        if attr.has_key('label'): defn.label = attr['label']
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   664
        defn.kind='onDraw'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   665
        self._push(cbDefn=defn)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   666
        self.handle_data('')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   667
        self._pop()
506
68bd275f16e2 Added onDraw tag to paragraphs
rgbecker
parents: 494
diff changeset
   668
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   669
    #---------------------------------------------------------------
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   670
    def _push(self,**attr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   671
        frag = copy.copy(self._stack[-1])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   672
        _applyAttributes(frag,attr)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   673
        self._stack.append(frag)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   674
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   675
    def _pop(self,**kw):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   676
        frag = self._stack[-1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   677
        del self._stack[-1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   678
        for k, v in kw.items():
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   679
            assert getattr(frag,k)==v
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   680
        return frag
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   681
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   682
    def getAttributes(self,attr,attrMap):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   683
        A = {}
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   684
        for k, v in attr.items():
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   685
            if not self.caseSensitive:
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   686
                k = string.lower(k)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   687
            if k in attrMap.keys():
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   688
                j = attrMap[k]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   689
                func = j[1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   690
                try:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   691
                    A[j[0]] = (func is None) and v or apply(func,(v,))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   692
                except:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   693
                    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
   694
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   695
                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
   696
        return A
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 115
diff changeset
   697
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   698
    #----------------------------------------------------------------
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   699
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   700
    def __init__(self,verbose=0):
1944
a50f8e3f93f8 laissez faire case
rgbecker
parents: 1940
diff changeset
   701
        self.caseSensitive = 0
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   702
        if _xmllib_newStyle:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   703
            xmllib.XMLParser.__init__(self,verbose=verbose)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   704
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   705
            xmllib.XMLParser.__init__(self)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   706
            # set up handlers for various tags
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   707
            self.elements = {'b': (self.start_b, self.end_b),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   708
                             'strong':  (self.start_b, self.end_b),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   709
                             'u': (self.start_u, self.end_u),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   710
                             'i': (self.start_i, self.end_i),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   711
                             'em': (self.start_i, self.end_i),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   712
                             'super': (self.start_super, self.end_super),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   713
                             'sup': (self.start_super, self.end_super),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   714
                             'sub': (self.start_sub, self.end_sub),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   715
                             'font': (self.start_font, self.end_font),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   716
                             'greek': (self.start_greek, self.end_greek),
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   717
                             'para': (self.start_para, self.end_para),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   718
                            }
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   719
132
8a9576d734b9 Fix for 1.5.2 xmllib + <para>
rgbecker
parents: 129
diff changeset
   720
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   721
            # automatically add handlers for all of the greek characters
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   722
            for item in greeks.keys():
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   723
                self.elements[item] = (lambda attr,self=self,letter=greeks[item]:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   724
                    self.start_greekLetter(attr,letter), self.end_greek)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   725
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   726
            # set up dictionary for greek characters, this is a class variable
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   727
            self.entitydefs = self.entitydefs.copy()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   728
            for item in greeks.keys():
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   729
                self.entitydefs[item] = '<%s/>' % item
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   730
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   731
266
081154da1a78 Added Sequencer and associated XML tags
andy_robinson
parents: 253
diff changeset
   732
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   733
    def _iReset(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   734
        self.fragList = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   735
        if hasattr(self, 'bFragList'): delattr(self,'bFragList')
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   736
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   737
    def _reset(self, style):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   738
        '''reset the parser'''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   739
        xmllib.XMLParser.reset(self)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   740
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   741
        # 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
   742
        self.errors = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   743
        self._style = style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   744
        self._iReset()
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   745
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   746
    #----------------------------------------------------------------
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   747
    def handle_data(self,data):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   748
        "Creates an intermediate representation of string segments."
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   749
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   750
        frag = copy.copy(self._stack[-1])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   751
        if hasattr(frag,'cbDefn'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   752
            if data!='': syntax_error('Only <onDraw> tag allowed')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   753
        else:
1736
dafc17db33d2 Attempt to use sup as well as super
rgbecker
parents: 1683
diff changeset
   754
            # 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
   755
            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
   756
                frag.sub = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   757
                frag.super = 0
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   758
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   759
            if frag.sub:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   760
                frag.rise = -frag.fontSize*subFraction
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   761
                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
   762
            elif frag.super:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   763
                frag.rise = frag.fontSize*superFraction
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   764
                frag.fontSize = max(frag.fontSize-sizeDelta,3)
112
1d4892961fdb Added rise attribute
rgbecker
parents: 102
diff changeset
   765
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   766
            if frag.greek: frag.fontName = 'symbol'
514
3784fe357a72 Slight optimisation in handle_data for cbdefn frags
rgbecker
parents: 508
diff changeset
   767
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   768
        # bold, italic, and underline
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   769
        x = frag.fontName = tt2ps(frag.fontName,frag.bold,frag.italic)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   770
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   771
        #save our data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   772
        frag.text = data
514
3784fe357a72 Slight optimisation in handle_data for cbdefn frags
rgbecker
parents: 508
diff changeset
   773
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   774
        if hasattr(frag,'isBullet'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   775
            delattr(frag,'isBullet')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   776
            self.bFragList.append(frag)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   777
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   778
            self.fragList.append(frag)
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   779
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   780
    def handle_cdata(self,data):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   781
        self.handle_data(data)
211
52541f1643b6 CDATA handler added
rgbecker
parents: 209
diff changeset
   782
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   783
    #----------------------------------------------------------------
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   784
    def parse(self, text, style):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   785
        """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
   786
        ParaFrag objects with their calculated widths.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   787
        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
   788
        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
   789
        """
2321
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   790
        # AR 20040612 - when we feed Unicode strings in, sgmlop
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   791
        # tries to coerce to ASCII.  Must intercept, coerce to
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   792
        # any 8-bit encoding which defines most of 256 points,
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   793
        # and revert at end.  Yuk.  Preliminary step prior to
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   794
        # removal of parser altogether.
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   795
        enc = 'cp1252' #our legacy default
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   796
        if type(text) is UnicodeType:
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   797
            UNI = 1
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   798
            text = text.encode(enc)
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   799
        else:
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   800
            UNI = 0
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   801
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   802
        self._seq = reportlab.lib.sequencer.getSequencer()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   803
        self._reset(style)  # reinitialise the parser
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   804
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   805
        # the xmlparser requires that all text be surrounded by xml
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   806
        # tags, therefore we must throw some unused flags around the
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   807
        # given string
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   808
        if not(len(text)>=6 and text[0]=='<' and _re_para.match(text)):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   809
            text = "<para>"+text+"</para>"
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   810
        self.feed(text)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   811
        self.close()    # force parsing to complete
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   812
        del self._seq
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   813
        style = self._style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   814
        del self._style
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   815
        if len(self.errors)==0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   816
            fragList = self.fragList
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   817
            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
   818
            self._iReset()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   819
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   820
            fragList = bFragList = None
2321
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   821
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   822
        if UNI:
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   823
            #reconvert to unicode
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   824
            if fragList:
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   825
                for frag in fragList:
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   826
                    frag.text = unicode(frag.text, enc)
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   827
            if bFragList:
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   828
                for frag in bFragList:
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   829
                    frag.text = unicode(frag.text, enc)
3454f5b41760 Unicode and UTF8 support changes
andy
parents: 2200
diff changeset
   830
            
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   831
        return style, fragList, bFragList
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   832
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   833
if __name__=='__main__':
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   834
    from reportlab.platypus import cleanBlockQuotedText
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   835
    _parser=ParaParser()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   836
    def check_text(text,p=_parser):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   837
        print '##########'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   838
        text = cleanBlockQuotedText(text)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   839
        l,rv,bv = p.parse(text,style)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   840
        if rv is None:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   841
            for l in _parser.errors:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   842
                print l
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   843
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   844
            print 'ParaStyle', l.fontName,l.fontSize,l.textColor
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   845
            for l in rv:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   846
                print l.fontName,l.fontSize,l.textColor,l.bold, l.rise, '|%s|'%l.text[:25],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   847
                if hasattr(l,'cbDefn'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   848
                    print 'cbDefn',l.cbDefn.name,l.cbDefn.label,l.cbDefn.kind
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   849
                else: print
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   850
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   851
    style=ParaFrag()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   852
    style.fontName='Times-Roman'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   853
    style.fontSize = 12
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   854
    style.textColor = black
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   855
    style.bulletFontName = black
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   856
    style.bulletFontName='Times-Roman'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   857
    style.bulletFontSize=12
96
2a9cca4c5cf0 Beginnings of a paragraph parser
rgbecker
parents:
diff changeset
   858
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   859
    text='''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   860
    <b><i><greek>a</greek>D</i></b>&beta;
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   861
    <font name="helvetica" size="15" color=green>
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   862
    Tell me, O muse, of that ingenious hero who travelled far and wide
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   863
    after</font> he had sacked the famous town of Troy. Many cities did he visit,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   864
    and many were the nations with whose manners and customs he was acquainted;
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   865
    moreover he suffered much by sea while trying to save his own life
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   866
    and bring his men safely home; but do what he might he could not save
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   867
    his men, for they perished through their own sheer folly in eating
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   868
    the cattle of the Sun-god Hyperion; so the god prevented them from
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   869
    ever reaching home. Tell me, too, about all these things, O daughter
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   870
    of Jove, from whatsoever source you<super>1</super> may know them.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   871
    '''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   872
    check_text(text)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   873
    check_text('<para> </para>')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   874
    check_text('<para font="times-bold" size=24 leading=28.8 spaceAfter=72>ReportLab -- Reporting for the Internet Age</para>')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   875
    check_text('''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   876
    <font color=red>&tau;</font>Tell me, O muse, of that ingenious hero who travelled far and wide
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   877
    after he had sacked the famous town of Troy. Many cities did he visit,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   878
    and many were the nations with whose manners and customs he was acquainted;
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   879
    moreover he suffered much by sea while trying to save his own life
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   880
    and bring his men safely home; but do what he might he could not save
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   881
    his men, for they perished through their own sheer folly in eating
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   882
    the cattle of the Sun-god Hyperion; so the god prevented them from
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   883
    ever reaching home. Tell me, too, about all these things, O daughter
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   884
    of Jove, from whatsoever source you may know them.''')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   885
    check_text('''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   886
    Telemachus took this speech as of good omen and rose at once, for
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   887
    he was bursting with what he had to say. He stood in the middle of
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   888
    the assembly and the good herald Pisenor brought him his staff. Then,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   889
    turning to Aegyptius, "Sir," said he, "it is I, as you will shortly
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   890
    learn, who have convened you, for it is I who am the most aggrieved.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   891
    I have not got wind of any host approaching about which I would warn
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   892
    you, nor is there any matter of public moment on which I would speak.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   893
    My grieveance is purely personal, and turns on two great misfortunes
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   894
    which have fallen upon my house. The first of these is the loss of
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   895
    my excellent father, who was chief among all you here present, and
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   896
    was like a father to every one of you; the second is much more serious,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   897
    and ere long will be the utter ruin of my estate. The sons of all
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   898
    the chief men among you are pestering my mother to marry them against
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   899
    her will. They are afraid to go to her father Icarius, asking him
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   900
    to choose the one he likes best, and to provide marriage gifts for
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   901
    his daughter, but day by day they keep hanging about my father's house,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   902
    sacrificing our oxen, sheep, and fat goats for their banquets, and
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   903
    never giving so much as a thought to the quantity of wine they drink.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   904
    No estate can stand such recklessness; we have now no Ulysses to ward
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   905
    off harm from our doors, and I cannot hold my own against them. I
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   906
    shall never all my days be as good a man as he was, still I would
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   907
    indeed defend myself if I had power to do so, for I cannot stand such
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   908
    treatment any longer; my house is being disgraced and ruined. Have
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   909
    respect, therefore, to your own consciences and to public opinion.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   910
    Fear, too, the wrath of heaven, lest the gods should be displeased
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   911
    and turn upon you. I pray you by Jove and Themis, who is the beginning
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   912
    and the end of councils, [do not] hold back, my friends, and leave
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   913
    me singlehanded- unless it be that my brave father Ulysses did some
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   914
    wrong to the Achaeans which you would now avenge on me, by aiding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   915
    and abetting these suitors. Moreover, if I am to be eaten out of house
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   916
    and home at all, I had rather you did the eating yourselves, for I
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   917
    could then take action against you to some purpose, and serve you
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   918
    with notices from house to house till I got paid in full, whereas
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   919
    now I have no remedy."''')
133
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   920
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   921
    check_text('''
133
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   922
But as the sun was rising from the fair sea into the firmament of
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   923
heaven to shed light on mortals and immortals, they reached Pylos
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   924
the city of Neleus. Now the people of Pylos were gathered on the sea
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   925
shore to offer sacrifice of black bulls to Neptune lord of the Earthquake.
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   926
There were nine guilds with five hundred men in each, and there were
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   927
nine bulls to each guild. As they were eating the inward meats and
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   928
burning the thigh bones [on the embers] in the name of Neptune, Telemachus
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   929
and his crew arrived, furled their sails, brought their ship to anchor,
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   930
and went ashore. ''')
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   931
    check_text('''
133
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   932
So the neighbours and kinsmen of Menelaus were feasting and making
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   933
merry in his house. There was a bard also to sing to them and play
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   934
his lyre, while two tumblers went about performing in the midst of
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   935
them when the man struck up with his tune.]''')
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   936
    check_text('''
133
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   937
"When we had passed the [Wandering] rocks, with Scylla and terrible
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   938
Charybdis, we reached the noble island of the sun-god, where were
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   939
the goodly cattle and sheep belonging to the sun Hyperion. While still
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   940
at sea in my ship I could bear the cattle lowing as they came home
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   941
to the yards, and the sheep bleating. Then I remembered what the blind
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   942
Theban prophet Teiresias had told me, and how carefully Aeaean Circe
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   943
had warned me to shun the island of the blessed sun-god. So being
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   944
much troubled I said to the men, 'My men, I know you are hard pressed,
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   945
but listen while I tell you the prophecy that Teiresias made me, and
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   946
how carefully Aeaean Circe warned me to shun the island of the blessed
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   947
sun-god, for it was here, she said, that our worst danger would lie.
ba7b4eb9be6c Debugging xml changes
rgbecker
parents: 132
diff changeset
   948
Head the ship, therefore, away from the island.''')
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   949
    check_text('''A&lt;B&gt;C&amp;D&quot;E&apos;F''')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   950
    check_text('''A&lt; B&gt; C&amp; D&quot; E&apos; F''')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   951
    check_text('''<![CDATA[<>&'"]]>''')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   952
    check_text('''<bullet face=courier size=14 color=green>+</bullet>
250
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   953
There was a bard also to sing to them and play
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   954
his lyre, while two tumblers went about performing in the midst of
a1bcf9c6c21e <bullet> xml tag added
rgbecker
parents: 248
diff changeset
   955
them when the man struck up with his tune.]''')
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1160
diff changeset
   956
    check_text('''<onDraw name="myFunc" label="aaa   bbb">A paragraph''')
1736
dafc17db33d2 Attempt to use sup as well as super
rgbecker
parents: 1683
diff changeset
   957
    check_text('''<para><onDraw name="myFunc" label="aaa   bbb">B paragraph</para>''')
1940
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   958
    # HVB, 30.05.2003: Test for new features
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   959
    _parser.caseSensitive=0
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   960
    check_text('''Here comes <FONT FACE="Helvetica" SIZE="14pt">Helvetica 14</FONT> with <STRONG>strong</STRONG> <EM>emphasis</EM>.''')
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   961
    check_text('''Here comes <font face="Helvetica" size="14pt">Helvetica 14</font> with <Strong>strong</Strong> <em>emphasis</em>.''')
baa0abc136c4 Henning von Bargen's caseSensitive flag
rgbecker
parents: 1932
diff changeset
   962
    check_text('''Here comes <font face="Courier" size="3cm">Courier 3cm</font> and normal again.''')