author | rgbecker |
Wed, 03 Oct 2007 10:31:55 +0000 | |
changeset 2860 | 3f14d66194c2 |
parent 2857 | 487dc2450eec |
child 2861 | 2096955de8cf |
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 |
2575 | 7 |
from types import TupleType, UnicodeType, StringType |
96 | 8 |
import sys |
9 |
import os |
|
10 |
import copy |
|
2693 | 11 |
import unicodedata |
279 | 12 |
import reportlab.lib.sequencer |
518 | 13 |
from reportlab.lib.abag import ABag |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
14 |
from reportlab.lib.utils import ImageReader |
1160 | 15 |
|
2376 | 16 |
from reportlab.lib import xmllib |
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 |
2410 | 22 |
_re_para = re.compile(r'^\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 |
|
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
28 |
|
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
29 |
def _convnum(s, unit=1): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
30 |
if s[0] in ['+','-']: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
31 |
try: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
32 |
return ('relative',int(s)*unit) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
33 |
except ValueError: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
34 |
return ('relative',float(s)*unit) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
35 |
else: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
36 |
try: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
37 |
return int(s)*unit |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
38 |
except ValueError: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
39 |
return float(s)*unit |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
40 |
|
1940 | 41 |
def _num(s, unit=1): |
42 |
"""Convert a string like '10cm' to an int or float (in points). |
|
43 |
The default unit is point, but optionally you can use other |
|
44 |
default units like mm. |
|
45 |
""" |
|
46 |
if s[-2:]=='cm': |
|
47 |
unit=cm |
|
48 |
s = s[:-2] |
|
49 |
if s[-2:]=='in': |
|
50 |
unit=inch |
|
51 |
s = s[:-2] |
|
52 |
if s[-2:]=='pt': |
|
53 |
unit=1 |
|
54 |
s = s[:-2] |
|
55 |
if s[-1:]=='i': |
|
56 |
unit=inch |
|
57 |
s = s[:-1] |
|
58 |
if s[-2:]=='mm': |
|
59 |
unit=mm |
|
60 |
s = s[:-2] |
|
61 |
if s[-4:]=='pica': |
|
62 |
unit=pica |
|
63 |
s = s[:-4] |
|
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
64 |
return _convnum(s,unit) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
65 |
|
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
66 |
class _PCT: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
67 |
def __init__(self,v): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
68 |
self._value = v*0.01 |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
69 |
|
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
70 |
def normalizedValue(self,normalizer): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
71 |
return normalizer*self._value |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
72 |
|
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
73 |
def _valignpc(s): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
74 |
s = s.lower() |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
75 |
if s in ('baseline','sub','super','top','text-top','middle','bottom','text-bottom'): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
76 |
return s |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
77 |
if s.endswith('%'): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
78 |
n = _convnum(s[:-1]) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
79 |
if isinstance(n,tuple): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
80 |
n = n[1] |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
81 |
return _PCT(n) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
82 |
n = _num(s) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
83 |
if isinstance(n,tuple): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
84 |
n = n[1] |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
85 |
return n |
119 | 86 |
|
2836 | 87 |
def _autoLeading(x): |
88 |
x = x.lower() |
|
89 |
if x in ('','min','max','off'): |
|
90 |
return x |
|
91 |
raise ValueError('Invalid autoLeading=%r' % x ) |
|
92 |
||
119 | 93 |
def _align(s): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
94 |
s = string.lower(s) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
95 |
if s=='left': return TA_LEFT |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
96 |
elif s=='right': return TA_RIGHT |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
97 |
elif s=='justify': return TA_JUSTIFY |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
98 |
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
|
99 |
else: raise ValueError |
119 | 100 |
|
101 |
_paraAttrMap = {'font': ('fontName', None), |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
102 |
'face': ('fontName', None), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
103 |
'fontsize': ('fontSize', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
104 |
'size': ('fontSize', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
105 |
'leading': ('leading', _num), |
2836 | 106 |
'autoleading': ('autoLeading', _autoLeading), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
107 |
'lindent': ('leftIndent', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
108 |
'rindent': ('rightIndent', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
109 |
'findent': ('firstLineIndent', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
110 |
'align': ('alignment', _align), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
111 |
'spaceb': ('spaceBefore', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
112 |
'spacea': ('spaceAfter', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
113 |
'bfont': ('bulletFontName', None), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
114 |
'bfontsize': ('bulletFontSize',_num), |
2860
3f14d66194c2
platypus: added bulletOffsetY inspired by haraldarminmassa@gmail.com
rgbecker
parents:
2857
diff
changeset
|
115 |
'boffsety': ('bulletOffsetY',_num), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
116 |
'bindent': ('bulletIndent',_num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
117 |
'bcolor': ('bulletColor',toColor), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
118 |
'color':('textColor',toColor), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
119 |
'backcolor':('backColor',toColor), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
120 |
'bgcolor':('backColor',toColor), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
121 |
'bg':('backColor',toColor), |
1940 | 122 |
'fg': ('textColor',toColor), |
123 |
} |
|
119 | 124 |
|
250 | 125 |
_bulletAttrMap = { |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
126 |
'font': ('bulletFontName', None), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
127 |
'face': ('bulletFontName', None), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
128 |
'size': ('bulletFontSize',_num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
129 |
'fontsize': ('bulletFontSize',_num), |
2860
3f14d66194c2
platypus: added bulletOffsetY inspired by haraldarminmassa@gmail.com
rgbecker
parents:
2857
diff
changeset
|
130 |
'offsety': ('bulletOffsetY',_num), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
131 |
'indent': ('bulletIndent',_num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
132 |
'color': ('bulletColor',toColor), |
1940 | 133 |
'fg': ('bulletColor',toColor), |
134 |
} |
|
250 | 135 |
|
119 | 136 |
#things which are valid font attributes |
137 |
_fontAttrMap = {'size': ('fontSize', _num), |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
138 |
'face': ('fontName', None), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
139 |
'name': ('fontName', None), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
140 |
'fg': ('textColor', toColor), |
1940 | 141 |
'color':('textColor', toColor), |
2446 | 142 |
'backcolor':('backColor',toColor), |
143 |
'bgcolor':('backColor',toColor), |
|
1940 | 144 |
} |
2575 | 145 |
#things which are valid font attributes |
146 |
_linkAttrMap = {'size': ('fontSize', _num), |
|
147 |
'face': ('fontName', None), |
|
148 |
'name': ('fontName', None), |
|
149 |
'fg': ('textColor', toColor), |
|
150 |
'color':('textColor', toColor), |
|
151 |
'backcolor':('backColor',toColor), |
|
152 |
'bgcolor':('backColor',toColor), |
|
153 |
'dest': ('link', None), |
|
154 |
'destination': ('link', None), |
|
155 |
'target': ('link', None), |
|
2594 | 156 |
'href': ('link', None), |
2575 | 157 |
} |
2744 | 158 |
_anchorAttrMap = {'fontSize': ('fontSize', _num), |
159 |
'fontName': ('fontName', None), |
|
160 |
'name': ('name', None), |
|
161 |
'fg': ('textColor', toColor), |
|
162 |
'color':('textColor', toColor), |
|
163 |
'backcolor':('backColor',toColor), |
|
164 |
'bgcolor':('backColor',toColor), |
|
165 |
'href': ('href', None), |
|
166 |
} |
|
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
167 |
_imgAttrMap = { |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
168 |
'src': ('src', None), |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
169 |
'width': ('width',_num), |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
170 |
'height':('height',_num), |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
171 |
'valign':('valign',_valignpc), |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
172 |
} |
119 | 173 |
|
174 |
def _addAttributeNames(m): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
175 |
K = m.keys() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
176 |
for k in K: |
1944 | 177 |
n = m[k][0] |
178 |
if not m.has_key(n): m[n] = m[k] |
|
179 |
n = string.lower(n) |
|
180 |
if not m.has_key(n): m[n] = m[k] |
|
119 | 181 |
|
182 |
_addAttributeNames(_paraAttrMap) |
|
183 |
_addAttributeNames(_fontAttrMap) |
|
250 | 184 |
_addAttributeNames(_bulletAttrMap) |
2747 | 185 |
_addAttributeNames(_anchorAttrMap) |
186 |
_addAttributeNames(_linkAttrMap) |
|
119 | 187 |
|
188 |
def _applyAttributes(obj, attr): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
189 |
for k, v in attr.items(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
190 |
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
|
191 |
#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
|
192 |
#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
|
193 |
if hasattr(obj, k): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
194 |
v = v[1]+getattr(obj,k) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
195 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
196 |
v = v[1] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
197 |
setattr(obj,k,v) |
102 | 198 |
|
1931
784fce255e2d
Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents:
1736
diff
changeset
|
199 |
#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
|
200 |
#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
|
201 |
#numeric entity names that follow. |
96 | 202 |
greeks = { |
2585 | 203 |
'pound': '\xc2\xa3', |
204 |
'nbsp': '\xc2\xa0', |
|
2575 | 205 |
'alefsym': '\xe2\x84\xb5', |
206 |
'Alpha': '\xce\x91', |
|
207 |
'alpha': '\xce\xb1', |
|
208 |
'and': '\xe2\x88\xa7', |
|
209 |
'ang': '\xe2\x88\xa0', |
|
210 |
'asymp': '\xe2\x89\x88', |
|
211 |
'Beta': '\xce\x92', |
|
212 |
'beta': '\xce\xb2', |
|
213 |
'bull': '\xe2\x80\xa2', |
|
214 |
'cap': '\xe2\x88\xa9', |
|
215 |
'Chi': '\xce\xa7', |
|
216 |
'chi': '\xcf\x87', |
|
217 |
'clubs': '\xe2\x99\xa3', |
|
218 |
'cong': '\xe2\x89\x85', |
|
219 |
'cup': '\xe2\x88\xaa', |
|
220 |
'darr': '\xe2\x86\x93', |
|
221 |
'dArr': '\xe2\x87\x93', |
|
222 |
'delta': '\xce\xb4', |
|
223 |
'Delta': '\xe2\x88\x86', |
|
224 |
'diams': '\xe2\x99\xa6', |
|
225 |
'empty': '\xe2\x88\x85', |
|
226 |
'Epsilon': '\xce\x95', |
|
227 |
'epsilon': '\xce\xb5', |
|
228 |
'epsiv': '\xce\xb5', |
|
229 |
'equiv': '\xe2\x89\xa1', |
|
230 |
'Eta': '\xce\x97', |
|
231 |
'eta': '\xce\xb7', |
|
232 |
'euro': '\xe2\x82\xac', |
|
233 |
'exist': '\xe2\x88\x83', |
|
234 |
'forall': '\xe2\x88\x80', |
|
235 |
'frasl': '\xe2\x81\x84', |
|
236 |
'Gamma': '\xce\x93', |
|
237 |
'gamma': '\xce\xb3', |
|
238 |
'ge': '\xe2\x89\xa5', |
|
239 |
'harr': '\xe2\x86\x94', |
|
240 |
'hArr': '\xe2\x87\x94', |
|
241 |
'hearts': '\xe2\x99\xa5', |
|
242 |
'hellip': '\xe2\x80\xa6', |
|
243 |
'image': '\xe2\x84\x91', |
|
244 |
'infin': '\xe2\x88\x9e', |
|
245 |
'int': '\xe2\x88\xab', |
|
246 |
'Iota': '\xce\x99', |
|
247 |
'iota': '\xce\xb9', |
|
248 |
'isin': '\xe2\x88\x88', |
|
249 |
'Kappa': '\xce\x9a', |
|
250 |
'kappa': '\xce\xba', |
|
251 |
'Lambda': '\xce\x9b', |
|
252 |
'lambda': '\xce\xbb', |
|
253 |
'lang': '\xe2\x8c\xa9', |
|
254 |
'larr': '\xe2\x86\x90', |
|
255 |
'lArr': '\xe2\x87\x90', |
|
256 |
'lceil': '\xef\xa3\xae', |
|
257 |
'le': '\xe2\x89\xa4', |
|
258 |
'lfloor': '\xef\xa3\xb0', |
|
259 |
'lowast': '\xe2\x88\x97', |
|
260 |
'loz': '\xe2\x97\x8a', |
|
261 |
'minus': '\xe2\x88\x92', |
|
262 |
'mu': '\xc2\xb5', |
|
263 |
'Mu': '\xce\x9c', |
|
264 |
'nabla': '\xe2\x88\x87', |
|
265 |
'ne': '\xe2\x89\xa0', |
|
266 |
'ni': '\xe2\x88\x8b', |
|
267 |
'notin': '\xe2\x88\x89', |
|
268 |
'nsub': '\xe2\x8a\x84', |
|
269 |
'Nu': '\xce\x9d', |
|
270 |
'nu': '\xce\xbd', |
|
271 |
'oline': '\xef\xa3\xa5', |
|
272 |
'omega': '\xcf\x89', |
|
273 |
'Omega': '\xe2\x84\xa6', |
|
274 |
'Omicron': '\xce\x9f', |
|
275 |
'omicron': '\xce\xbf', |
|
276 |
'oplus': '\xe2\x8a\x95', |
|
277 |
'or': '\xe2\x88\xa8', |
|
278 |
'otimes': '\xe2\x8a\x97', |
|
279 |
'part': '\xe2\x88\x82', |
|
280 |
'perp': '\xe2\x8a\xa5', |
|
281 |
'Phi': '\xce\xa6', |
|
282 |
'phi': '\xcf\x95', |
|
283 |
'phis': '\xcf\x86', |
|
284 |
'Pi': '\xce\xa0', |
|
285 |
'pi': '\xcf\x80', |
|
286 |
'piv': '\xcf\x96', |
|
287 |
'prime': '\xe2\x80\xb2', |
|
288 |
'prod': '\xe2\x88\x8f', |
|
289 |
'prop': '\xe2\x88\x9d', |
|
290 |
'Psi': '\xce\xa8', |
|
291 |
'psi': '\xcf\x88', |
|
292 |
'radic': '\xe2\x88\x9a', |
|
293 |
'rang': '\xe2\x8c\xaa', |
|
294 |
'rarr': '\xe2\x86\x92', |
|
295 |
'rArr': '\xe2\x87\x92', |
|
296 |
'rceil': '\xef\xa3\xb9', |
|
297 |
'real': '\xe2\x84\x9c', |
|
298 |
'rfloor': '\xef\xa3\xbb', |
|
299 |
'Rho': '\xce\xa1', |
|
300 |
'rho': '\xcf\x81', |
|
301 |
'sdot': '\xe2\x8b\x85', |
|
302 |
'Sigma': '\xce\xa3', |
|
303 |
'sigma': '\xcf\x83', |
|
304 |
'sigmaf': '\xcf\x82', |
|
305 |
'sigmav': '\xcf\x82', |
|
306 |
'sim': '\xe2\x88\xbc', |
|
307 |
'spades': '\xe2\x99\xa0', |
|
308 |
'sub': '\xe2\x8a\x82', |
|
309 |
'sube': '\xe2\x8a\x86', |
|
310 |
'sum': '\xe2\x88\x91', |
|
311 |
'sup': '\xe2\x8a\x83', |
|
312 |
'supe': '\xe2\x8a\x87', |
|
313 |
'Tau': '\xce\xa4', |
|
314 |
'tau': '\xcf\x84', |
|
315 |
'there4': '\xe2\x88\xb4', |
|
316 |
'Theta': '\xce\x98', |
|
317 |
'theta': '\xce\xb8', |
|
318 |
'thetasym': '\xcf\x91', |
|
319 |
'thetav': '\xcf\x91', |
|
320 |
'trade': '\xef\xa3\xaa', |
|
321 |
'uarr': '\xe2\x86\x91', |
|
322 |
'uArr': '\xe2\x87\x91', |
|
323 |
'upsih': '\xcf\x92', |
|
324 |
'Upsilon': '\xce\xa5', |
|
325 |
'upsilon': '\xcf\x85', |
|
326 |
'weierp': '\xe2\x84\x98', |
|
327 |
'Xi': '\xce\x9e', |
|
328 |
'xi': '\xce\xbe', |
|
329 |
'Zeta': '\xce\x96', |
|
330 |
'zeta': '\xce\xb6', |
|
1931
784fce255e2d
Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents:
1736
diff
changeset
|
331 |
} |
96 | 332 |
|
333 |
#------------------------------------------------------------------------ |
|
518 | 334 |
class ParaFrag(ABag): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
335 |
"""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
|
336 |
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
|
337 |
fontname, fontSize, rise, textColor, cbDefn |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
338 |
""" |
96 | 339 |
|
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
340 |
|
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
341 |
_greek2Utf8=None |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
342 |
def _greekConvert(data): |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
343 |
global _greek2Utf8 |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
344 |
if not _greek2Utf8: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
345 |
from reportlab.pdfbase.rl_codecs import RL_Codecs |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
346 |
import codecs |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
347 |
dm = decoding_map = codecs.make_identity_dict(xrange(32,256)) |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
348 |
for k in xrange(0,32): |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
349 |
dm[k] = None |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
350 |
dm.update(RL_Codecs._RL_Codecs__rl_codecs_data['symbol'][0]) |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
351 |
_greek2Utf8 = {} |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
352 |
for k,v in dm.iteritems(): |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
353 |
if not v: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
354 |
u = '\0' |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
355 |
else: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
356 |
u = unichr(v).encode('utf8') |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
357 |
_greek2Utf8[chr(k)] = u |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
358 |
return ''.join(map(_greek2Utf8.__getitem__,data)) |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
359 |
|
96 | 360 |
#------------------------------------------------------------------ |
267
52a348f6c4c3
noted replication of XML markup comment between paraparser.py and paragraph.py
aaron_watters
parents:
266
diff
changeset
|
361 |
# !!! NOTE !!! THIS TEXT IS NOW REPLICATED IN PARAGRAPH.PY !!! |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
362 |
# The ParaFormatter will be able to format the following |
96 | 363 |
# tags: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
364 |
# < /b > - bold |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
365 |
# < /i > - italics |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
366 |
# < u > < /u > - underline |
2644 | 367 |
# < strike > < /strike > - strike through |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
368 |
# < super > < /super > - superscript |
1736 | 369 |
# < sup > < /sup > - superscript |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
370 |
# < sub > < /sub > - subscript |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
371 |
# <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
|
372 |
# < 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
|
373 |
# <onDraw name=callable label="a label"> |
2670 | 374 |
# <link>link text</link> |
375 |
# attributes of links |
|
376 |
# size/fontSize=num |
|
377 |
# name/face/fontName=name |
|
378 |
# fg/textColor/color=color |
|
379 |
# backcolor/backColor/bgcolor=color |
|
380 |
# dest/destination/target/href/link=target |
|
2745 | 381 |
# <a>anchor text</a> |
2744 | 382 |
# attributes of anchors |
383 |
# fontSize=num |
|
384 |
# fontName=name |
|
385 |
# fg/textColor/color=color |
|
386 |
# backcolor/backColor/bgcolor=color |
|
387 |
# href=href |
|
388 |
# <a name="anchorpoint"/> |
|
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
389 |
# <unichar name="unicode character name"/> |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
390 |
# <unichar value="unicode code point"/> |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
391 |
# <img src="path" width="1in" height="1in" valign="bottom"/> |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
392 |
# <greek> - </greek> |
1683 | 393 |
# |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
394 |
# The whole may be surrounded by <para> </para> tags |
119 | 395 |
# |
96 | 396 |
# It will also be able to handle any MathML specified Greek characters. |
397 |
#------------------------------------------------------------------ |
|
398 |
class ParaParser(xmllib.XMLParser): |
|
399 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
400 |
#---------------------------------------------------------- |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
401 |
# 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
|
402 |
# |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
403 |
# start_<tag>(attributes) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
404 |
# end_<tag>() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
405 |
# |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
406 |
# 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
|
407 |
# 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
|
408 |
# 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
|
409 |
# 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
|
410 |
# 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
|
411 |
# 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
|
412 |
#---------------------------------------------------------- |
96 | 413 |
|
1940 | 414 |
def __getattr__( self, attrName ): |
415 |
"""This way we can handle <TAG> the same way as <tag> (ignoring case).""" |
|
2369 | 416 |
if attrName!=attrName.lower() and attrName!="caseSensitive" and not self.caseSensitive and \ |
417 |
(attrName.startswith("start_") or attrName.startswith("end_")): |
|
418 |
return getattr(self,attrName.lower()) |
|
1940 | 419 |
raise AttributeError, attrName |
420 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
421 |
#### bold |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
422 |
def start_b( self, attributes ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
423 |
self._push(bold=1) |
96 | 424 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
425 |
def end_b( self ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
426 |
self._pop(bold=1) |
96 | 427 |
|
1940 | 428 |
def start_strong( self, attributes ): |
429 |
self._push(bold=1) |
|
430 |
||
431 |
def end_strong( self ): |
|
432 |
self._pop(bold=1) |
|
433 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
434 |
#### italics |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
435 |
def start_i( self, attributes ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
436 |
self._push(italic=1) |
96 | 437 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
438 |
def end_i( self ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
439 |
self._pop(italic=1) |
96 | 440 |
|
1940 | 441 |
def start_em( self, attributes ): |
442 |
self._push(italic=1) |
|
443 |
||
444 |
def end_em( self ): |
|
445 |
self._pop(italic=1) |
|
446 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
447 |
#### underline |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
448 |
def start_u( self, attributes ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
449 |
self._push(underline=1) |
96 | 450 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
451 |
def end_u( self ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
452 |
self._pop(underline=1) |
96 | 453 |
|
2644 | 454 |
#### strike |
455 |
def start_strike( self, attributes ): |
|
456 |
self._push(strike=1) |
|
457 |
||
458 |
def end_strike( self ): |
|
459 |
self._pop(strike=1) |
|
460 |
||
2575 | 461 |
#### link |
462 |
def start_link(self, attributes): |
|
463 |
self._push(**self.getAttributes(attributes,_linkAttrMap)) |
|
464 |
||
465 |
def end_link(self): |
|
466 |
frag = self._stack[-1] |
|
467 |
del self._stack[-1] |
|
468 |
assert frag.link!=None |
|
469 |
||
2744 | 470 |
#### anchor |
471 |
def start_a(self, attributes): |
|
472 |
A = self.getAttributes(attributes,_anchorAttrMap) |
|
473 |
if A.get('name',None): |
|
474 |
if len(A)>1: |
|
475 |
self._syntax_error('<a name="..."/> anchor variant only allows name attribute') |
|
476 |
A = dict(name=A['name']) |
|
477 |
A['_selfClosingTag'] = 'anchor' |
|
478 |
elif not A.get('href',None): |
|
479 |
self._syntax_error('<a> tag must have name or href attribute') |
|
480 |
else: |
|
481 |
A['link'] = A.pop('href') #convert to our link form |
|
482 |
self._push(**A) |
|
483 |
||
484 |
def end_a(self): |
|
485 |
frag = self._stack[-1] |
|
486 |
sct = getattr(frag,'_selfClosingTag','') |
|
487 |
if sct: |
|
488 |
assert sct=='anchor' and frag.name,'Parser failure in <a/>' |
|
489 |
defn = frag.cbDefn = ABag() |
|
490 |
defn.label = defn.kind = 'anchor' |
|
491 |
defn.name = frag.name |
|
492 |
del frag.name, frag._selfClosingTag |
|
493 |
self.handle_data('') |
|
494 |
self._pop() |
|
495 |
else: |
|
496 |
del self._stack[-1] |
|
497 |
assert frag.link!=None |
|
2742 | 498 |
|
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
499 |
def start_img(self,attributes): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
500 |
A = self.getAttributes(attributes,_imgAttrMap) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
501 |
if not A.get('src'): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
502 |
self._syntax_error('<img> needs src attribute') |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
503 |
A['_selfClosingTag'] = 'img' |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
504 |
self._push(**A) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
505 |
|
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
506 |
def end_img(self): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
507 |
frag = self._stack[-1] |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
508 |
assert getattr(frag,'_selfClosingTag',''),'Parser failure in <img/>' |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
509 |
defn = frag.cbDefn = ABag() |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
510 |
defn.kind = 'img' |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
511 |
defn.src = getattr(frag,'src',None) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
512 |
defn.image = ImageReader(defn.src) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
513 |
size = defn.image.getSize() |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
514 |
defn.width = getattr(frag,'width',size[0]) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
515 |
defn.height = getattr(frag,'height',size[1]) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
516 |
defn.valign = getattr(frag,'valign','bottom') |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
517 |
del frag._selfClosingTag |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
518 |
self.handle_data('') |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
519 |
self._pop() |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
520 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
521 |
#### super script |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
522 |
def start_super( self, attributes ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
523 |
self._push(super=1) |
96 | 524 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
525 |
def end_super( self ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
526 |
self._pop(super=1) |
96 | 527 |
|
2376 | 528 |
start_sup = start_super |
529 |
end_sup = end_super |
|
1736 | 530 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
531 |
#### sub script |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
532 |
def start_sub( self, attributes ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
533 |
self._push(sub=1) |
96 | 534 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
535 |
def end_sub( self ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
536 |
self._pop(sub=1) |
96 | 537 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
538 |
#### greek script |
2376 | 539 |
#### add symbol encoding |
540 |
def handle_charref(self, name): |
|
541 |
try: |
|
2575 | 542 |
if name[0]=='x': |
543 |
n = int(name[1:],16) |
|
1931
784fce255e2d
Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents:
1736
diff
changeset
|
544 |
else: |
2575 | 545 |
n = int(name) |
546 |
except ValueError: |
|
2376 | 547 |
self.unknown_charref(name) |
548 |
return |
|
2575 | 549 |
self.handle_data(unichr(n).encode('utf8')) |
134 | 550 |
|
2376 | 551 |
def handle_entityref(self,name): |
552 |
if greeks.has_key(name): |
|
553 |
self.handle_data(greeks[name]) |
|
554 |
else: |
|
555 |
xmllib.XMLParser.handle_entityref(self,name) |
|
134 | 556 |
|
2376 | 557 |
def syntax_error(self,lineno,message): |
558 |
self._syntax_error(message) |
|
134 | 559 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
560 |
def _syntax_error(self,message): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
561 |
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
|
562 |
self.errors.append(message) |
134 | 563 |
|
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
564 |
def start_greek(self, attr): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
565 |
self._push(greek=1) |
96 | 566 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
567 |
def end_greek(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
568 |
self._pop(greek=1) |
96 | 569 |
|
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
570 |
def start_unichar(self, attr): |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
571 |
if attr.has_key('name'): |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
572 |
if attr.has_key('code'): |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
573 |
self._syntax_error('<unichar/> invalid with both name and code attributes') |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
574 |
try: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
575 |
v = unicodedata.lookup(attr['name']).encode('utf8') |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
576 |
except KeyError: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
577 |
self._syntax_error('<unichar/> invalid name attribute\n"%s"' % name) |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
578 |
v = '\0' |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
579 |
elif attr.has_key('code'): |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
580 |
try: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
581 |
v = unichr(int(eval(attr['code']))).encode('utf8') |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
582 |
except: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
583 |
self._syntax_error('<unichar/> invalid code attribute %s' % attr['code']) |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
584 |
v = '\0' |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
585 |
else: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
586 |
v = None |
2664 | 587 |
if attr: |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
588 |
self._syntax_error('<unichar/> invalid attribute %s' % attr.keys()[0]) |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
589 |
|
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
590 |
if v is not None: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
591 |
self.handle_data(v) |
2585 | 592 |
self._push(_selfClosingTag='unichar') |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
593 |
|
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
594 |
def end_unichar(self): |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
595 |
self._pop() |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
596 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
597 |
def start_font(self,attr): |
2575 | 598 |
self._push(**self.getAttributes(attr,_fontAttrMap)) |
96 | 599 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
600 |
def end_font(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
601 |
self._pop() |
96 | 602 |
|
2663 | 603 |
def start_br(self, attr): |
604 |
#just do the trick to make sure there is no content |
|
2664 | 605 |
self._push(_selfClosingTag='br',lineBreak=True,text='') |
2663 | 606 |
|
607 |
def end_br(self): |
|
2664 | 608 |
frag = self._stack[-1] |
609 |
assert frag._selfClosingTag=='br' and frag.lineBreak,'Parser failure in <br/>' |
|
610 |
del frag._selfClosingTag |
|
611 |
self.handle_data('') |
|
612 |
self._pop() |
|
2663 | 613 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
614 |
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
|
615 |
style = self._style |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
616 |
if attr!={}: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
617 |
style = copy.deepcopy(style) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
618 |
_applyAttributes(style,self.getAttributes(attr,attrMap)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
619 |
self._style = style |
119 | 620 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
621 |
# initialize semantic values |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
622 |
frag = ParaFrag() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
623 |
frag.sub = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
624 |
frag.super = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
625 |
frag.rise = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
626 |
frag.underline = 0 |
2644 | 627 |
frag.strike = 0 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
628 |
frag.greek = 0 |
2575 | 629 |
frag.link = None |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
630 |
if bullet: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
631 |
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
|
632 |
frag.fontSize = style.bulletFontSize |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
633 |
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
|
634 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
635 |
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
|
636 |
frag.fontSize = style.fontSize |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
637 |
frag.textColor = style.textColor |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
638 |
return frag |
250 | 639 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
640 |
def start_para(self,attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
641 |
self._stack = [self._initial_frag(attr,_paraAttrMap)] |
119 | 642 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
643 |
def end_para(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
644 |
self._pop() |
119 | 645 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
646 |
def start_bullet(self,attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
647 |
if hasattr(self,'bFragList'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
648 |
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
|
649 |
self.bFragList = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
650 |
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
|
651 |
frag.isBullet = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
652 |
self._stack.append(frag) |
250 | 653 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
654 |
def end_bullet(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
655 |
self._pop() |
250 | 656 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
657 |
#--------------------------------------------------------------- |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
658 |
def start_seqdefault(self, attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
659 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
660 |
default = attr['id'] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
661 |
except KeyError: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
662 |
default = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
663 |
self._seq.setDefaultCounter(default) |
266 | 664 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
665 |
def end_seqdefault(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
666 |
pass |
1683 | 667 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
668 |
def start_seqreset(self, attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
669 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
670 |
id = attr['id'] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
671 |
except KeyError: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
672 |
id = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
673 |
try: |
2368 | 674 |
base = int(attr['base']) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
675 |
except: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
676 |
base=0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
677 |
self._seq.reset(id, base) |
266 | 678 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
679 |
def end_seqreset(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
680 |
pass |
744
2abd99baf95b
Accepts seqdefault/seqDefault and seqreset/seqReset
andy_robinson
parents:
677
diff
changeset
|
681 |
|
2368 | 682 |
def start_seqchain(self, attr): |
683 |
try: |
|
684 |
order = attr['order'] |
|
685 |
except KeyError: |
|
686 |
order = '' |
|
687 |
order = order.split() |
|
688 |
seq = self._seq |
|
689 |
for p,c in zip(order[:-1],order[1:]): |
|
690 |
seq.chain(p, c) |
|
691 |
end_seqchain = end_seqreset |
|
692 |
||
693 |
def start_seqformat(self, attr): |
|
694 |
try: |
|
695 |
id = attr['id'] |
|
696 |
except KeyError: |
|
697 |
id = None |
|
698 |
try: |
|
699 |
value = attr['value'] |
|
700 |
except KeyError: |
|
701 |
value = '1' |
|
702 |
self._seq.setFormat(id,value) |
|
703 |
end_seqformat = end_seqreset |
|
704 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
705 |
# 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
|
706 |
# the above ones should be deprecated over time. 2001-03-22 |
2368 | 707 |
start_seqDefault = start_seqdefault |
708 |
end_seqDefault = end_seqdefault |
|
709 |
start_seqReset = start_seqreset |
|
710 |
end_seqReset = end_seqreset |
|
711 |
start_seqChain = start_seqchain |
|
712 |
end_seqChain = end_seqchain |
|
713 |
start_seqFormat = start_seqformat |
|
714 |
end_seqFormat = end_seqformat |
|
1683 | 715 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
716 |
def start_seq(self, attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
717 |
#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
|
718 |
#otherwise take default sequence |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
719 |
if attr.has_key('template'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
720 |
templ = attr['template'] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
721 |
self.handle_data(templ % self._seq) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
722 |
return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
723 |
elif attr.has_key('id'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
724 |
id = attr['id'] |
1683 | 725 |
else: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
726 |
id = None |
2694
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
727 |
increment = attr.get('inc', None) |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
728 |
if not increment: |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
729 |
output = self._seq.nextf(id) |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
730 |
else: |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
731 |
#accepts "no" for do not increment, or an integer. |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
732 |
#thus, 0 and 1 increment by the right amounts. |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
733 |
if increment.lower() == 'no': |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
734 |
output = self._seq.thisf(id) |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
735 |
else: |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
736 |
incr = int(increment) |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
737 |
output = self._seq.thisf(id) |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
738 |
self._seq.reset(id, self._seq._this() + incr) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
739 |
self.handle_data(output) |
1683 | 740 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
741 |
def end_seq(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
742 |
pass |
266 | 743 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
744 |
def start_onDraw(self,attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
745 |
defn = ABag() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
746 |
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
|
747 |
else: self._syntax_error('<onDraw> needs at least a name attribute') |
506 | 748 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
749 |
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
|
750 |
defn.kind='onDraw' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
751 |
self._push(cbDefn=defn) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
752 |
self.handle_data('') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
753 |
self._pop() |
506 | 754 |
|
2663 | 755 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
756 |
#--------------------------------------------------------------- |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
757 |
def _push(self,**attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
758 |
frag = copy.copy(self._stack[-1]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
759 |
_applyAttributes(frag,attr) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
760 |
self._stack.append(frag) |
96 | 761 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
762 |
def _pop(self,**kw): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
763 |
frag = self._stack[-1] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
764 |
del self._stack[-1] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
765 |
for k, v in kw.items(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
766 |
assert getattr(frag,k)==v |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
767 |
return frag |
96 | 768 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
769 |
def getAttributes(self,attr,attrMap): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
770 |
A = {} |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
771 |
for k, v in attr.items(): |
1940 | 772 |
if not self.caseSensitive: |
773 |
k = string.lower(k) |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
774 |
if k in attrMap.keys(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
775 |
j = attrMap[k] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
776 |
func = j[1] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
777 |
try: |
2575 | 778 |
A[j[0]] = (func is None) and v or func(v) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
779 |
except: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
780 |
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
|
781 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
782 |
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
|
783 |
return A |
119 | 784 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
785 |
#---------------------------------------------------------------- |
96 | 786 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
787 |
def __init__(self,verbose=0): |
1944 | 788 |
self.caseSensitive = 0 |
2376 | 789 |
xmllib.XMLParser.__init__(self,verbose=verbose) |
266 | 790 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
791 |
def _iReset(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
792 |
self.fragList = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
793 |
if hasattr(self, 'bFragList'): delattr(self,'bFragList') |
250 | 794 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
795 |
def _reset(self, style): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
796 |
'''reset the parser''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
797 |
xmllib.XMLParser.reset(self) |
96 | 798 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
799 |
# 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
|
800 |
self.errors = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
801 |
self._style = style |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
802 |
self._iReset() |
96 | 803 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
804 |
#---------------------------------------------------------------- |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
805 |
def handle_data(self,data): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
806 |
"Creates an intermediate representation of string segments." |
96 | 807 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
808 |
frag = copy.copy(self._stack[-1]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
809 |
if hasattr(frag,'cbDefn'): |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
810 |
kind = frag.cbDefn.kind |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
811 |
if data: self._syntax_error('Only empty <%s> tag allowed' % kind) |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
812 |
elif hasattr(frag,'_selfClosingTag'): |
2663 | 813 |
if data!='': self._syntax_error('No content allowed in %s tag' % frag._selfClosingTag) |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
814 |
return |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
815 |
else: |
1736 | 816 |
# 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
|
817 |
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
|
818 |
frag.sub = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
819 |
frag.super = 0 |
96 | 820 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
821 |
if frag.sub: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
822 |
frag.rise = -frag.fontSize*subFraction |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
823 |
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
|
824 |
elif frag.super: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
825 |
frag.rise = frag.fontSize*superFraction |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
826 |
frag.fontSize = max(frag.fontSize-sizeDelta,3) |
112 | 827 |
|
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
828 |
if frag.greek: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
829 |
frag.fontName = 'symbol' |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
830 |
data = _greekConvert(data) |
514
3784fe357a72
Slight optimisation in handle_data for cbdefn frags
rgbecker
parents:
508
diff
changeset
|
831 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
832 |
# bold, italic, and underline |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
833 |
x = frag.fontName = tt2ps(frag.fontName,frag.bold,frag.italic) |
96 | 834 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
835 |
#save our data |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
836 |
frag.text = data |
514
3784fe357a72
Slight optimisation in handle_data for cbdefn frags
rgbecker
parents:
508
diff
changeset
|
837 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
838 |
if hasattr(frag,'isBullet'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
839 |
delattr(frag,'isBullet') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
840 |
self.bFragList.append(frag) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
841 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
842 |
self.fragList.append(frag) |
96 | 843 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
844 |
def handle_cdata(self,data): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
845 |
self.handle_data(data) |
211 | 846 |
|
2376 | 847 |
def _setup_for_parse(self,style): |
848 |
self._seq = reportlab.lib.sequencer.getSequencer() |
|
849 |
self._reset(style) # reinitialise the parser |
|
850 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
851 |
def parse(self, text, style): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
852 |
"""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
|
853 |
ParaFrag objects with their calculated widths. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
854 |
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
|
855 |
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
|
856 |
""" |
2575 | 857 |
# AR 20040612 - when we feed Unicode strings in, sgmlop |
858 |
# tries to coerce to ASCII. Must intercept, coerce to |
|
859 |
# any 8-bit encoding which defines most of 256 points, |
|
860 |
# and revert at end. Yuk. Preliminary step prior to |
|
861 |
# removal of parser altogether. |
|
2646
d177c247184a
platypus: eliminate StringType usages and cp1252 usage
rgbecker
parents:
2644
diff
changeset
|
862 |
enc = self._enc = 'utf8' #our legacy default |
2575 | 863 |
self._UNI = type(text) is UnicodeType |
864 |
if self._UNI: |
|
865 |
text = text.encode(enc) |
|
866 |
||
2376 | 867 |
self._setup_for_parse(style) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
868 |
# 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
|
869 |
# 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
|
870 |
# given string |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
871 |
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
|
872 |
text = "<para>"+text+"</para>" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
873 |
self.feed(text) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
874 |
self.close() # force parsing to complete |
2376 | 875 |
return self._complete_parse() |
876 |
||
877 |
def _complete_parse(self): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
878 |
del self._seq |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
879 |
style = self._style |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
880 |
del self._style |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
881 |
if len(self.errors)==0: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
882 |
fragList = self.fragList |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
883 |
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
|
884 |
self._iReset() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
885 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
886 |
fragList = bFragList = None |
2575 | 887 |
|
888 |
if self._UNI: |
|
889 |
#reconvert to unicode |
|
890 |
if fragList: |
|
891 |
for frag in fragList: |
|
892 |
frag.text = unicode(frag.text, self._enc) |
|
893 |
if bFragList: |
|
894 |
for frag in bFragList: |
|
895 |
frag.text = unicode(frag.text, self._enc) |
|
2664 | 896 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
897 |
return style, fragList, bFragList |
96 | 898 |
|
2376 | 899 |
def _tt_parse(self,tt): |
900 |
tag = tt[0] |
|
901 |
try: |
|
902 |
start = getattr(self,'start_'+tag) |
|
903 |
end = getattr(self,'end_'+tag) |
|
904 |
except AttributeError: |
|
905 |
raise ValueError('Invalid tag "%s"' % tag) |
|
906 |
start(tt[1] or {}) |
|
907 |
C = tt[2] |
|
908 |
if C: |
|
909 |
M = self._tt_handlers |
|
910 |
for c in C: |
|
911 |
M[type(c) is TupleType](c) |
|
912 |
end() |
|
913 |
||
914 |
def tt_parse(self,tt,style): |
|
915 |
'''parse from tupletree form''' |
|
916 |
self._setup_for_parse(style) |
|
917 |
self._tt_handlers = self.handle_data,self._tt_parse |
|
918 |
self._tt_parse(tt) |
|
919 |
return self._complete_parse() |
|
920 |
||
96 | 921 |
if __name__=='__main__': |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
922 |
from reportlab.platypus import cleanBlockQuotedText |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
923 |
_parser=ParaParser() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
924 |
def check_text(text,p=_parser): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
925 |
print '##########' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
926 |
text = cleanBlockQuotedText(text) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
927 |
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
|
928 |
if rv is None: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
929 |
for l in _parser.errors: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
930 |
print l |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
931 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
932 |
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
|
933 |
for l in rv: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
934 |
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
|
935 |
if hasattr(l,'cbDefn'): |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
936 |
print 'cbDefn',getattr(l.cbDefn,'name',''),getattr(l.cbDefn,'label',''),l.cbDefn.kind |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
937 |
else: print |
96 | 938 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
939 |
style=ParaFrag() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
940 |
style.fontName='Times-Roman' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
941 |
style.fontSize = 12 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
942 |
style.textColor = black |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
943 |
style.bulletFontName = black |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
944 |
style.bulletFontName='Times-Roman' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
945 |
style.bulletFontSize=12 |
96 | 946 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
947 |
text=''' |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
948 |
<b><i><greek>a</greek>D</i></b>β<unichr value="0x394"/> |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
949 |
<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
|
950 |
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
|
951 |
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
|
952 |
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
|
953 |
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
|
954 |
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
|
955 |
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
|
956 |
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
|
957 |
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
|
958 |
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
|
959 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
960 |
check_text(text) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
961 |
check_text('<para> </para>') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
962 |
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
|
963 |
check_text(''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
964 |
<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
|
965 |
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
|
966 |
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
|
967 |
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
|
968 |
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
|
969 |
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
|
970 |
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
|
971 |
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
|
972 |
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
|
973 |
check_text(''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
974 |
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
|
975 |
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
|
976 |
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
|
977 |
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
|
978 |
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
|
979 |
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
|
980 |
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
|
981 |
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
|
982 |
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
|
983 |
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
|
984 |
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
|
985 |
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
|
986 |
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
|
987 |
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
|
988 |
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
|
989 |
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
|
990 |
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
|
991 |
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
|
992 |
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
|
993 |
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
|
994 |
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
|
995 |
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
|
996 |
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
|
997 |
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
|
998 |
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
|
999 |
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
|
1000 |
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
|
1001 |
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
|
1002 |
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
|
1003 |
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
|
1004 |
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
|
1005 |
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
|
1006 |
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
|
1007 |
now I have no remedy."''') |
133 | 1008 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1009 |
check_text(''' |
133 | 1010 |
But as the sun was rising from the fair sea into the firmament of |
1011 |
heaven to shed light on mortals and immortals, they reached Pylos |
|
1012 |
the city of Neleus. Now the people of Pylos were gathered on the sea |
|
1013 |
shore to offer sacrifice of black bulls to Neptune lord of the Earthquake. |
|
1014 |
There were nine guilds with five hundred men in each, and there were |
|
1015 |
nine bulls to each guild. As they were eating the inward meats and |
|
1016 |
burning the thigh bones [on the embers] in the name of Neptune, Telemachus |
|
1017 |
and his crew arrived, furled their sails, brought their ship to anchor, |
|
1018 |
and went ashore. ''') |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1019 |
check_text(''' |
133 | 1020 |
So the neighbours and kinsmen of Menelaus were feasting and making |
1021 |
merry in his house. There was a bard also to sing to them and play |
|
1022 |
his lyre, while two tumblers went about performing in the midst of |
|
1023 |
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
|
1024 |
check_text(''' |
133 | 1025 |
"When we had passed the [Wandering] rocks, with Scylla and terrible |
1026 |
Charybdis, we reached the noble island of the sun-god, where were |
|
1027 |
the goodly cattle and sheep belonging to the sun Hyperion. While still |
|
1028 |
at sea in my ship I could bear the cattle lowing as they came home |
|
1029 |
to the yards, and the sheep bleating. Then I remembered what the blind |
|
1030 |
Theban prophet Teiresias had told me, and how carefully Aeaean Circe |
|
1031 |
had warned me to shun the island of the blessed sun-god. So being |
|
1032 |
much troubled I said to the men, 'My men, I know you are hard pressed, |
|
2644 | 1033 |
but listen while I <strike>tell you the prophecy that</strike> Teiresias made me, and |
133 | 1034 |
how carefully Aeaean Circe warned me to shun the island of the blessed |
1035 |
sun-god, for it was here, she said, that our worst danger would lie. |
|
1036 |
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
|
1037 |
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
|
1038 |
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
|
1039 |
check_text('''<![CDATA[<>&'"]]>''') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1040 |
check_text('''<bullet face=courier size=14 color=green>+</bullet> |
250 | 1041 |
There was a bard also to sing to them and play |
1042 |
his lyre, while two tumblers went about performing in the midst of |
|
1043 |
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
|
1044 |
check_text('''<onDraw name="myFunc" label="aaa bbb">A paragraph''') |
1736 | 1045 |
check_text('''<para><onDraw name="myFunc" label="aaa bbb">B paragraph</para>''') |
1940 | 1046 |
# HVB, 30.05.2003: Test for new features |
1047 |
_parser.caseSensitive=0 |
|
1048 |
check_text('''Here comes <FONT FACE="Helvetica" SIZE="14pt">Helvetica 14</FONT> with <STRONG>strong</STRONG> <EM>emphasis</EM>.''') |
|
1049 |
check_text('''Here comes <font face="Helvetica" size="14pt">Helvetica 14</font> with <Strong>strong</Strong> <em>emphasis</em>.''') |
|
1050 |
check_text('''Here comes <font face="Courier" size="3cm">Courier 3cm</font> and normal again.''') |
|
2663 | 1051 |
check_text('''Before the break <br/>the middle line <br/> and the last line.''') |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
1052 |
check_text('''This should be an inline image <img src='../docs/images/testimg.gif'/>!''') |