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