Diffstat (limited to 'noncore/apps/opie-reader/CFilter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CFilter.cpp | 600 |
1 files changed, 337 insertions, 263 deletions
diff --git a/noncore/apps/opie-reader/CFilter.cpp b/noncore/apps/opie-reader/CFilter.cpp index 0422ba6..6f76e9a 100644 --- a/noncore/apps/opie-reader/CFilter.cpp +++ b/noncore/apps/opie-reader/CFilter.cpp | |||
@@ -1,623 +1,422 @@ | |||
1 | #include <qmap.h> | ||
2 | #include <qfileinfo.h> | ||
3 | #include <qtextstream.h> | ||
4 | #include <qdir.h> | ||
5 | #include "useqpe.h" | ||
6 | #ifdef USEQPE | ||
7 | #include <qpe/global.h> | ||
8 | #endif | ||
9 | #include "CDrawBuffer.h" | ||
1 | #include "CFilter.h" | 10 | #include "CFilter.h" |
11 | #include "hrule.h" | ||
12 | #include "util.h" | ||
2 | 13 | ||
3 | unsigned short striphtml::skip_ws() | 14 | #include <qregexp.h> |
4 | { | 15 | #include <qimage.h> |
5 | tchar ch; | 16 | #include <qpixmap.h> |
6 | CStyle sty; | 17 | //#include <qprogressdialog.h> |
7 | do | 18 | //#include <qapplication.h> |
8 | { | ||
9 | parent->getch(ch, sty); | ||
10 | } | ||
11 | while (ch < 33); | ||
12 | return ch; | ||
13 | } | ||
14 | |||
15 | unsigned short striphtml::skip_ws_end() | ||
16 | { | ||
17 | tchar ch; | ||
18 | CStyle sty; | ||
19 | parent->getch(ch, sty); | ||
20 | if (ch == ' ') | ||
21 | { | ||
22 | do | ||
23 | { | ||
24 | parent->getch(ch, sty); | ||
25 | } | ||
26 | while (ch != '>'); | ||
27 | } | ||
28 | return ch; | ||
29 | } | ||
30 | |||
31 | unsigned short striphtml::parse_m() | ||
32 | { | ||
33 | tchar ch; | ||
34 | CStyle sty; | ||
35 | parent->getch(ch, sty); | ||
36 | if (ch == 'm' || ch == 'M') | ||
37 | { | ||
38 | ch = skip_ws_end(); | ||
39 | if (ch == '>') | ||
40 | { | ||
41 | return 0; | ||
42 | } | ||
43 | } | ||
44 | return ch; | ||
45 | } | ||
46 | |||
47 | void striphtml::mygetch(tchar& ch, CStyle& sty) | ||
48 | { | ||
49 | parent->getch(ch, sty); | ||
50 | if (ch == 10) ch = ' '; | ||
51 | } | ||
52 | |||
53 | void striphtml::getch(tchar& ch, CStyle& sty) | ||
54 | { | ||
55 | CStyle dummy; | ||
56 | mygetch(ch, dummy); | ||
57 | if (ch == 10) ch = ' '; | ||
58 | while (ch == '<') | ||
59 | { | ||
60 | ch = skip_ws(); | ||
61 | |||
62 | switch (ch) | ||
63 | { | ||
64 | case 'p': | ||
65 | case 'P': | ||
66 | ch = skip_ws_end(); | ||
67 | if (ch == '>') | ||
68 | { | ||
69 | ch = 10; | ||
70 | continue; | ||
71 | } | ||
72 | break; | ||
73 | case 'b': | ||
74 | case 'B': | ||
75 | ch = skip_ws_end(); | ||
76 | if (ch == '>') | ||
77 | { | ||
78 | currentstyle.setBold(); | ||
79 | mygetch(ch, dummy); | ||
80 | continue; | ||
81 | } | ||
82 | else if (ch == 'r' || ch == 'R') | ||
83 | { | ||
84 | ch = skip_ws_end(); | ||
85 | if (ch == '>') | ||
86 | { | ||
87 | ch = 10; | ||
88 | continue; | ||
89 | } | ||
90 | } | ||
91 | break; | ||
92 | case 'i': | ||
93 | case 'I': | ||
94 | ch = skip_ws_end(); | ||
95 | if (ch == '>') | ||
96 | { | ||
97 | currentstyle.setItalic(); | ||
98 | mygetch(ch, dummy); | ||
99 | continue; | ||
100 | } | ||
101 | break; | ||
102 | case 'e': | ||
103 | case 'E': | ||
104 | if ((ch = parse_m()) == 0) | ||
105 | { | ||
106 | currentstyle.setItalic(); | ||
107 | mygetch(ch, dummy); | ||
108 | continue; | ||
109 | } | ||
110 | break; | ||
111 | case 'h': | ||
112 | case 'H': | ||
113 | mygetch(ch, dummy); | ||
114 | if ('0' < ch && ch <= '9') | ||
115 | { | ||
116 | tchar hs = ch; | ||
117 | ch = skip_ws_end(); | ||
118 | if (ch == '>') | ||
119 | { | ||
120 | switch (hs) | ||
121 | { | ||
122 | case '1': | ||
123 | // currentstyle = ucBold | ucFontBase+2 | (ucAlignCentre << ucAlignShift); | ||
124 | currentstyle.unset(); | ||
125 | currentstyle.setFontSize(2); | ||
126 | currentstyle.setBold(); | ||
127 | currentstyle.setCentreJustify(); | ||
128 | break; | ||
129 | case '2': | ||
130 | // currentstyle = ucBold | ucFontBase+1; | ||
131 | currentstyle.unset(); | ||
132 | currentstyle.setFontSize(1); | ||
133 | currentstyle.setBold(); | ||
134 | break; | ||
135 | default: | ||
136 | // currentstyle = ucBold | ucFontBase; | ||
137 | currentstyle.unset(); | ||
138 | currentstyle.setBold(); | ||
139 | } | ||
140 | ch = 10; | ||
141 | // mygetch(ch, dummy); | ||
142 | continue; | ||
143 | } | ||
144 | } | ||
145 | break; | ||
146 | case '/': | ||
147 | mygetch(ch, dummy); | ||
148 | switch (ch) | ||
149 | { | ||
150 | case 'b': | ||
151 | case 'B': | ||
152 | ch = skip_ws_end(); | ||
153 | if (ch == '>') | ||
154 | { | ||
155 | currentstyle.unsetBold(); | ||
156 | mygetch(ch, dummy); | ||
157 | continue; | ||
158 | } | ||
159 | break; | ||
160 | case 'i': | ||
161 | case 'I': | ||
162 | ch = skip_ws_end(); | ||
163 | if (ch == '>') | ||
164 | { | ||
165 | currentstyle.unsetItalic(); | ||
166 | mygetch(ch, dummy); | ||
167 | continue; | ||
168 | } | ||
169 | break; | ||
170 | case 'e': | ||
171 | case 'E': | ||
172 | if ((ch = parse_m()) == 0) | ||
173 | { | ||
174 | currentstyle.unsetItalic(); | ||
175 | mygetch(ch, dummy); | ||
176 | continue; | ||
177 | } | ||
178 | break; | ||
179 | case 'h': | ||
180 | case 'H': | ||
181 | mygetch(ch, dummy); | ||
182 | if ('0' < ch && ch <= '9') | ||
183 | { | ||
184 | ch = skip_ws_end(); | ||
185 | if (ch == '>') | ||
186 | { | ||
187 | currentstyle.unset(); | ||
188 | //mygetch(ch, dummy); | ||
189 | ch = 10; | ||
190 | continue; | ||
191 | } | ||
192 | } | ||
193 | break; | ||
194 | default: | ||
195 | break; | ||
196 | } | ||
197 | break; | ||
198 | default: | ||
199 | break; | ||
200 | } | ||
201 | while (ch != '>' && ch != UEOF) | ||
202 | { | ||
203 | mygetch(ch, dummy); | ||
204 | } | ||
205 | mygetch(ch, dummy); | ||
206 | } | ||
207 | if (ch == '&') | ||
208 | { | ||
209 | mygetch(ch, dummy); | ||
210 | if (ch == '#') | ||
211 | { | ||
212 | int id = 0; | ||
213 | mygetch(ch, dummy); | ||
214 | while (ch != ';' && ch != UEOF) | ||
215 | { | ||
216 | id = 10*id+ch-'0'; | ||
217 | mygetch(ch, dummy); | ||
218 | } | ||
219 | ch = id; | ||
220 | } | ||
221 | } | ||
222 | // sty = (dummy == ucFontBase) ? currentstyle : dummy; | ||
223 | sty = currentstyle; | ||
224 | return; | ||
225 | } | ||
226 | |||
227 | 19 | ||
228 | void textfmt::mygetch(tchar& ch, CStyle& sty) | 20 | void textfmt::mygetch(tchar& ch, CStyle& sty, unsigned long& pos) |
229 | { | 21 | { |
230 | if (uselast) | 22 | if (uselast) |
231 | { | 23 | { |
232 | ch = lastchar; | 24 | ch = lastchar; |
233 | uselast = false; | 25 | uselast = false; |
234 | } | 26 | } |
235 | else | 27 | else |
236 | { | 28 | { |
237 | parent->getch(ch, sty); | 29 | parent->getch(ch, sty, pos); |
238 | } | 30 | } |
239 | } | 31 | } |
240 | 32 | ||
241 | void textfmt::getch(tchar& ch, CStyle& sty) | 33 | void textfmt::getch(tchar& ch, CStyle& sty, unsigned long& pos) |
242 | { | 34 | { |
243 | mygetch(ch, sty); | 35 | mygetch(ch, sty, pos); |
244 | do | 36 | do |
245 | { | 37 | { |
246 | sty = currentstyle; | 38 | sty = currentstyle; |
247 | switch (ch) | 39 | switch (ch) |
248 | { | 40 | { |
249 | case 10: | 41 | case 10: |
250 | currentstyle.unset(); | 42 | currentstyle.unset(); |
251 | sty = currentstyle; | 43 | sty = currentstyle; |
252 | break; | 44 | break; |
253 | // Use this if you want to replace -- by em-dash | 45 | // Use this if you want to replace -- by em-dash |
254 | case '-': | 46 | case '-': |
255 | // parent->getch(ch, sty); | 47 | // parent->getch(ch, sty); |
256 | mygetch(ch, sty); | 48 | mygetch(ch, sty, pos); |
257 | if (ch == '-') | 49 | if (ch == '-') |
258 | { | 50 | { |
259 | ch = 0x2014; | 51 | ch = 0x2014; |
260 | } | 52 | } |
261 | else | 53 | else |
262 | { | 54 | { |
263 | lastchar = ch; | 55 | lastchar = ch; |
264 | uselast = true; | 56 | uselast = true; |
265 | ch = '-'; | 57 | ch = '-'; |
266 | } | 58 | } |
267 | break; | 59 | break; |
268 | case '*': | 60 | case '*': |
269 | if (currentstyle.isBold()) | 61 | if (currentstyle.isBold()) |
270 | { | 62 | { |
271 | // Already bold - time to turn it off? | 63 | // Already bold - time to turn it off? |
272 | // The next two lines ensure that * follows a character but it works better without | 64 | // The next two lines ensure that * follows a character but it works better without |
273 | // QChar c(lastchar); | 65 | // QChar c(lastchar); |
274 | // if ((lastchar != '*') && (c.isPunct() || c.isLetterOrNumber())) | 66 | // if ((lastchar != '*') && (c.isPunct() || c.isLetterOrNumber())) |
275 | if (lastchar != '*') | 67 | if (lastchar != '*') |
276 | { | 68 | { |
277 | currentstyle.unsetBold(); | 69 | currentstyle.unsetBold(); |
278 | CStyle dummy; | 70 | CStyle dummy; |
279 | // parent->getch(ch, dummy); | 71 | // parent->getch(ch, dummy); |
280 | mygetch(ch, dummy); | 72 | mygetch(ch, dummy, pos); |
281 | } | 73 | } |
282 | } | 74 | } |
283 | else | 75 | else |
284 | { | 76 | { |
285 | // not bold - time to turn it on? | 77 | // not bold - time to turn it on? |
286 | CStyle dummy; | 78 | CStyle dummy; |
287 | // parent->getch(ch, dummy); | 79 | // parent->getch(ch, dummy); |
288 | mygetch(ch, dummy); | 80 | mygetch(ch, dummy, pos); |
289 | QChar c(ch); | 81 | QChar c(ch); |
290 | if ((ch != '*') && (c.isPunct() || c.isLetterOrNumber())) | 82 | if ((ch != '*') && (c.isPunct() || c.isLetterOrNumber())) |
291 | { | 83 | { |
292 | currentstyle.setBold(); | 84 | currentstyle.setBold(); |
293 | } | 85 | } |
294 | else | 86 | else |
295 | { | 87 | { |
296 | lastchar = ch; | 88 | lastchar = ch; |
297 | uselast = true; | 89 | uselast = true; |
298 | ch = '*'; | 90 | ch = '*'; |
299 | } | 91 | } |
300 | 92 | ||
301 | } | 93 | } |
302 | break; | 94 | break; |
303 | case '_': | 95 | case '_': |
304 | if (currentstyle.isItalic()) | 96 | if (currentstyle.isItalic()) |
305 | { | 97 | { |
306 | // Already bold - time to turn it off? | 98 | // Already bold - time to turn it off? |
307 | // The next two lines ensure that * follows a character but it works better without | 99 | // The next two lines ensure that * follows a character but it works better without |
308 | // QChar c(lastchar); | 100 | // QChar c(lastchar); |
309 | // if ((lastchar != '_') && (c.isPunct() || c.isLetterOrNumber())) | 101 | // if ((lastchar != '_') && (c.isPunct() || c.isLetterOrNumber())) |
310 | if (lastchar != '_') | 102 | if (lastchar != '_') |
311 | { | 103 | { |
312 | currentstyle.unsetItalic(); | 104 | currentstyle.unsetItalic(); |
313 | CStyle dummy; | 105 | CStyle dummy; |
314 | // parent->getch(ch, dummy); | 106 | // parent->getch(ch, dummy); |
315 | mygetch(ch, dummy); | 107 | mygetch(ch, dummy, pos); |
316 | } | 108 | } |
317 | } | 109 | } |
318 | else | 110 | else |
319 | { | 111 | { |
320 | // not bold - time to turn it on? | 112 | // not bold - time to turn it on? |
321 | CStyle dummy; | 113 | CStyle dummy; |
322 | // parent->getch(ch, dummy); | 114 | // parent->getch(ch, dummy); |
323 | mygetch(ch, dummy); | 115 | mygetch(ch, dummy, pos); |
324 | QChar c(ch); | 116 | QChar c(ch); |
325 | if ((ch != '_') && (c.isPunct() || c.isLetterOrNumber())) | 117 | if ((ch != '_') && (c.isPunct() || c.isLetterOrNumber())) |
326 | { | 118 | { |
327 | currentstyle.setItalic(); | 119 | currentstyle.setItalic(); |
328 | } | 120 | } |
329 | else | 121 | else |
330 | { | 122 | { |
331 | lastchar = ch; | 123 | lastchar = ch; |
332 | uselast = true; | 124 | uselast = true; |
333 | ch = '_'; | 125 | ch = '_'; |
334 | } | 126 | } |
335 | 127 | ||
336 | } | 128 | } |
337 | break; | 129 | break; |
338 | } | 130 | } |
339 | } | 131 | } |
340 | while (sty != currentstyle); | 132 | while (sty != currentstyle); |
341 | if (!uselast) lastchar = ch; | 133 | if (!uselast) lastchar = ch; |
342 | return; | 134 | return; |
343 | } | 135 | } |
344 | 136 | ||
345 | void remap::getch(tchar& ch, CStyle& sty) | 137 | void remap::getch(tchar& ch, CStyle& sty, unsigned long& pos) |
346 | { | 138 | { |
347 | if (q[offset] != 0) | 139 | if (q[offset] != 0) |
348 | { | 140 | { |
349 | q[offset++]; | 141 | q[offset++]; |
350 | sty = currentstyle; | 142 | sty = currentstyle; |
351 | return; | 143 | return; |
352 | } | 144 | } |
353 | parent->getch(ch, sty); | 145 | parent->getch(ch, sty, pos); |
354 | switch (ch) | 146 | switch (ch) |
355 | { | 147 | { |
356 | case 0x201a: | 148 | case 0x201a: |
357 | ch = '\''; | 149 | ch = '\''; |
358 | break; | 150 | break; |
359 | case 0x0192: | 151 | case 0x0192: |
360 | ch = 'f'; | 152 | ch = 'f'; |
361 | break; | 153 | break; |
362 | case 0x201e: | 154 | case 0x201e: |
363 | ch = '"'; | 155 | ch = '"'; |
364 | break; | 156 | break; |
365 | case 0x2026: | 157 | case 0x2026: |
366 | offset = 0; | 158 | offset = 0; |
367 | q[0] = '.'; | 159 | q[0] = '.'; |
368 | q[1] = '.'; | 160 | q[1] = '.'; |
369 | q[2] = 0; | 161 | q[2] = 0; |
370 | ch = '.'; // should be ... | 162 | ch = '.'; // should be ... |
371 | break; | 163 | break; |
372 | case 0x0160: | 164 | case 0x0160: |
373 | ch = 'S'; | 165 | ch = 'S'; |
374 | break; | 166 | break; |
375 | case 0x2039: | 167 | case 0x2039: |
376 | ch = '<'; | 168 | ch = '<'; |
377 | break; | 169 | break; |
378 | case 0x0152: | 170 | case 0x0152: |
379 | offset = 0; | 171 | offset = 0; |
380 | q[0] = 'E'; | 172 | q[0] = 'E'; |
381 | q[1] = 0; | 173 | q[1] = 0; |
382 | ch = 'O'; | 174 | ch = 'O'; |
383 | break; | 175 | break; |
384 | case 0x017d: | 176 | case 0x017d: |
385 | ch = 'Z'; | 177 | ch = 'Z'; |
386 | break; | 178 | break; |
387 | case 0x2018: | 179 | case 0x2018: |
388 | ch = '\''; | 180 | ch = '\''; |
389 | break; | 181 | break; |
390 | case 0x2019: | 182 | case 0x2019: |
391 | ch = '\''; | 183 | ch = '\''; |
392 | break; | 184 | break; |
393 | case 0x201c: | 185 | case 0x201c: |
394 | ch = '"'; | 186 | ch = '"'; |
395 | break; | 187 | break; |
396 | case 0x201d: | 188 | case 0x201d: |
397 | ch = '"'; | 189 | ch = '"'; |
398 | break; | 190 | break; |
399 | case 0x2022: | 191 | case 0x2022: |
400 | ch = '>'; | 192 | ch = '>'; |
401 | break; | 193 | break; |
402 | case 0x2013: | 194 | case 0x2013: |
403 | ch = '-'; | 195 | ch = '-'; |
404 | break; | 196 | break; |
405 | case 0x2014: | 197 | case 0x2014: |
406 | offset = 0; | 198 | offset = 0; |
407 | q[0] = '-'; | 199 | q[0] = '-'; |
408 | q[1] = 0; | 200 | q[1] = 0; |
409 | ch = '-'; // should be -- | 201 | ch = '-'; // should be -- |
410 | break; | 202 | break; |
411 | case 0x02dc: | 203 | case 0x02dc: |
412 | ch = '~'; | 204 | ch = '~'; |
413 | break; | 205 | break; |
414 | case 0x0161: | 206 | case 0x0161: |
415 | ch = 's'; | 207 | ch = 's'; |
416 | break; | 208 | break; |
417 | case 0x203a: | 209 | case 0x203a: |
418 | ch = '>'; | 210 | ch = '>'; |
419 | break; | 211 | break; |
420 | case 0x0153: | 212 | case 0x0153: |
421 | offset = 0; | 213 | offset = 0; |
422 | q[0] = 'e'; | 214 | q[0] = 'e'; |
423 | q[1] = 0; | 215 | q[1] = 0; |
424 | ch = 'o';// should be oe | 216 | ch = 'o';// should be oe |
425 | break; | 217 | break; |
218 | /* | ||
219 | case 0x0009: // tab | ||
220 | offset = 0; | ||
221 | q[0] = ' '; | ||
222 | q[1] = 0; | ||
223 | ch = ' '; | ||
224 | break; | ||
225 | */ | ||
426 | case 0x017e: | 226 | case 0x017e: |
427 | ch = 'z'; | 227 | ch = 'z'; |
428 | break; | 228 | break; |
429 | case 0x0178: | 229 | case 0x0178: |
430 | ch = 'Y'; | 230 | ch = 'Y'; |
431 | break; | 231 | break; |
432 | } | 232 | } |
433 | currentstyle = sty; | 233 | currentstyle = sty; |
434 | } | 234 | } |
435 | 235 | ||
436 | void PeanutFormatter::getch(tchar& ch, CStyle& sty) | 236 | void PeanutFormatter::getch(tchar& ch, CStyle& sty, unsigned long& pos) |
437 | { | 237 | { |
438 | CStyle dummy; | 238 | CStyle dummy; |
439 | currentstyle.setColour(0,0,0); | 239 | currentstyle.setColour(0,0,0); |
440 | parent->getch(ch, dummy); | 240 | parent->getch(ch, dummy, pos); |
441 | while (ch == '\\') | 241 | while (ch == '\\') |
442 | { | 242 | { |
443 | parent->getch(ch, dummy); | 243 | parent->getch(ch, dummy, pos); |
444 | if (ch == '\\') break; | 244 | if (ch == '\\') break; |
445 | switch(ch) | 245 | switch(ch) |
446 | { | 246 | { |
447 | case 'a': | 247 | case 'a': |
448 | { | 248 | { |
449 | int code = 0; | 249 | int code = 0; |
450 | for (int i = 0; i < 3; i++) | 250 | for (int i = 0; i < 3; i++) |
451 | { | 251 | { |
452 | parent->getch(ch, dummy); | 252 | parent->getch(ch, dummy, pos); |
453 | code = 10*code + ch - '0'; | 253 | code = 10*code + ch - '0'; |
454 | } | 254 | } |
455 | ch = code; | 255 | ch = code; |
456 | } | 256 | } |
457 | break; | 257 | break; |
458 | case 'v': | 258 | case 'v': |
459 | { | 259 | { |
460 | while (1) | 260 | while (1) |
461 | { | 261 | { |
462 | parent->getch(ch, dummy); | 262 | parent->getch(ch, dummy, pos); |
463 | if (ch == '\\') | 263 | if (ch == '\\') |
464 | { | 264 | { |
465 | parent->getch(ch, dummy); | 265 | parent->getch(ch, dummy, pos); |
466 | if (ch == 'v') | 266 | if (ch == 'v') |
467 | { | 267 | { |
468 | parent->getch(ch, dummy); | 268 | parent->getch(ch, dummy, pos); |
469 | break; | 269 | break; |
470 | } | 270 | } |
471 | } | 271 | } |
472 | } | 272 | } |
473 | } | 273 | } |
474 | break; | 274 | break; |
475 | case 's': | 275 | case 's': |
476 | case 'n': | 276 | case 'n': |
477 | currentstyle.setFontSize(0); | 277 | currentstyle.setFontSize(0); |
478 | parent->getch(ch,dummy); | 278 | parent->getch(ch,dummy, pos); |
479 | break; | 279 | break; |
480 | case 'p': | 280 | case 'p': |
481 | currentstyle.unset(); | 281 | currentstyle.unset(); |
482 | // parent->getch(ch,dummy); | 282 | // parent->getch(ch,dummy); |
483 | ch = 10; | 283 | ch = 10; |
484 | break; | 284 | break; |
485 | case 'l': | 285 | case 'l': |
486 | if (currentstyle.getFontSize() == 1) | 286 | if (currentstyle.getFontSize() == 1) |
487 | { | 287 | { |
488 | currentstyle.setFontSize(0); | 288 | currentstyle.setFontSize(0); |
489 | } | 289 | } |
490 | else | 290 | else |
491 | { | 291 | { |
492 | currentstyle.setFontSize(1); | 292 | currentstyle.setFontSize(1); |
493 | } | 293 | } |
494 | parent->getch(ch, dummy); | 294 | parent->getch(ch, dummy, pos); |
495 | break; | 295 | break; |
496 | case 'x': | 296 | case 'x': |
497 | if (currentstyle.getFontSize() == 0) | 297 | if (currentstyle.getFontSize() == 0) |
498 | { | 298 | { |
499 | // currentstyle.unset(); | 299 | // currentstyle.unset(); |
500 | // currentstyle.setBold(); | 300 | // currentstyle.setBold(); |
501 | currentstyle.setFontSize(1); | 301 | currentstyle.setFontSize(1); |
502 | } | 302 | } |
503 | else | 303 | else |
504 | { | 304 | { |
505 | currentstyle.unset(); | 305 | currentstyle.unset(); |
506 | } | 306 | } |
507 | // parent->getch(ch, dummy); | 307 | // parent->getch(ch, dummy); |
508 | ch = 10; | 308 | ch = 10; |
509 | break; | 309 | break; |
510 | case 'i': | 310 | case 'i': |
511 | if (currentstyle.isItalic()) | 311 | if (currentstyle.isItalic()) |
512 | { | 312 | { |
513 | currentstyle.unsetItalic(); | 313 | currentstyle.unsetItalic(); |
514 | } | 314 | } |
515 | else | 315 | else |
516 | { | 316 | { |
517 | currentstyle.setItalic(); | 317 | currentstyle.setItalic(); |
518 | } | 318 | } |
519 | parent->getch(ch, dummy); | 319 | parent->getch(ch, dummy, pos); |
520 | break; | 320 | break; |
521 | case 'b': | 321 | case 'b': |
522 | case 'B': | 322 | case 'B': |
523 | if (currentstyle.isBold()) | 323 | if (currentstyle.isBold()) |
524 | { | 324 | { |
525 | currentstyle.unsetBold(); | 325 | currentstyle.unsetBold(); |
526 | } | 326 | } |
527 | else | 327 | else |
528 | { | 328 | { |
529 | currentstyle.setBold(); | 329 | currentstyle.setBold(); |
530 | } | 330 | } |
531 | parent->getch(ch, dummy); | 331 | parent->getch(ch, dummy, pos); |
532 | break; | 332 | break; |
533 | case 'c': | 333 | case 'c': |
534 | if (currentstyle.getJustify() == m_AlignCentre) | 334 | if (currentstyle.getJustify() == m_AlignCentre) |
535 | { | 335 | { |
536 | currentstyle.setLeftJustify(); | 336 | currentstyle.setLeftJustify(); |
537 | } | 337 | } |
538 | else | 338 | else |
539 | { | 339 | { |
540 | currentstyle.setCentreJustify(); | 340 | currentstyle.setCentreJustify(); |
541 | } | 341 | } |
542 | parent->getch(ch, dummy); | 342 | parent->getch(ch, dummy, pos); |
543 | break; | 343 | break; |
544 | case 'r': | 344 | case 'r': |
545 | if (currentstyle.getJustify() == m_AlignRight) | 345 | if (currentstyle.getJustify() == m_AlignRight) |
546 | { | 346 | { |
547 | currentstyle.setLeftJustify(); | 347 | currentstyle.setLeftJustify(); |
548 | } | 348 | } |
549 | else | 349 | else |
550 | { | 350 | { |
551 | currentstyle.setRightJustify(); | 351 | currentstyle.setRightJustify(); |
552 | } | 352 | } |
553 | parent->getch(ch, dummy); | 353 | parent->getch(ch, dummy, pos); |
554 | break; | 354 | break; |
555 | default: | 355 | default: |
556 | currentstyle.setColour(255,0,0); | 356 | currentstyle.setColour(255,0,0); |
557 | } | 357 | } |
558 | } | 358 | } |
559 | sty = currentstyle; | 359 | sty = currentstyle; |
560 | } | 360 | } |
561 | 361 | ||
562 | void OnePara::getch(tchar& ch, CStyle& sty) | 362 | void OnePara::getch(tchar& ch, CStyle& sty, unsigned long& pos) |
563 | { | 363 | { |
564 | parent->getch(ch, sty); | 364 | parent->getch(ch, sty, pos); |
565 | if (m_lastchar == 10) | 365 | if (m_lastchar == 10) |
566 | { | 366 | { |
567 | while (ch == 10) parent->getch(ch, sty); | 367 | while (ch == 10) parent->getch(ch, sty, pos); |
568 | } | 368 | } |
569 | m_lastchar = ch; | 369 | m_lastchar = ch; |
570 | } | 370 | } |
571 | 371 | ||
572 | #ifdef REPALM | 372 | void repalm::getch(tchar& ch, CStyle& sty, unsigned long& pos) |
573 | void repalm::getch(tchar& ch, CStyle& sty) | ||
574 | { | 373 | { |
575 | parent->getch(ch, sty); | 374 | parent->getch(ch, sty, pos); |
576 | switch (ch) | 375 | switch (ch) |
577 | { | 376 | { |
578 | case 0x80: | 377 | case 0x80: |
579 | ch = 0x20ac; | 378 | ch = 0x20ac; |
580 | break; | 379 | break; |
581 | case 0x82: | 380 | case 0x82: |
582 | ch = 0x201a; | 381 | ch = 0x201a; |
583 | break; | 382 | break; |
584 | case 0x83: | 383 | case 0x83: |
585 | ch = 0x0192; | 384 | ch = 0x0192; |
586 | break; | 385 | break; |
587 | case 0x84: | 386 | case 0x84: |
588 | ch = 0x201e; | 387 | ch = 0x201e; |
589 | break; | 388 | break; |
590 | case 0x85: | 389 | case 0x85: |
591 | ch = 0x2026; | 390 | ch = 0x2026; |
592 | break; | 391 | break; |
593 | case 0x86: | 392 | case 0x86: |
594 | ch = 0x2020; | 393 | ch = 0x2020; |
595 | break; | 394 | break; |
596 | case 0x87: | 395 | case 0x87: |
597 | ch = 0x2021; | 396 | ch = 0x2021; |
598 | break; | 397 | break; |
599 | case 0x88: | 398 | case 0x88: |
600 | ch = 0x02c6; | 399 | ch = 0x02c6; |
601 | break; | 400 | break; |
602 | case 0x89: | 401 | case 0x89: |
603 | ch = 0x2030; | 402 | ch = 0x2030; |
604 | break; | 403 | break; |
605 | case 0x8a: | 404 | case 0x8a: |
606 | ch = 0x0160; | 405 | ch = 0x0160; |
607 | break; | 406 | break; |
608 | case 0x8b: | 407 | case 0x8b: |
609 | ch = 0x2039; | 408 | ch = 0x2039; |
610 | break; | 409 | break; |
611 | case 0x8c: | 410 | case 0x8c: |
612 | ch = 0x0152; | 411 | ch = 0x0152; |
613 | break; | 412 | break; |
614 | /* | 413 | /* |
615 | case 0x8e: | 414 | case 0x8e: |
616 | ch = 0x017d; | 415 | ch = 0x017d; |
617 | break; | 416 | break; |
618 | */ | 417 | */ |
619 | case 0x91: | 418 | case 0x91: |
620 | ch = 0x2018; | 419 | ch = 0x2018; |
621 | break; | 420 | break; |
622 | case 0x92: | 421 | case 0x92: |
623 | ch = 0x2019; | 422 | ch = 0x2019; |
@@ -635,107 +434,382 @@ void repalm::getch(tchar& ch, CStyle& sty) | |||
635 | ch = 0x2013; | 434 | ch = 0x2013; |
636 | break; | 435 | break; |
637 | case 0x97: | 436 | case 0x97: |
638 | ch = 0x2014; | 437 | ch = 0x2014; |
639 | break; | 438 | break; |
640 | case 0x98: | 439 | case 0x98: |
641 | ch = 0x02dc; | 440 | ch = 0x02dc; |
642 | break; | 441 | break; |
643 | case 0x99: | 442 | case 0x99: |
644 | ch = 0x2122; | 443 | ch = 0x2122; |
645 | break; | 444 | break; |
646 | case 0x9a: | 445 | case 0x9a: |
647 | ch = 0x0161; | 446 | ch = 0x0161; |
648 | break; | 447 | break; |
649 | case 0x9b: | 448 | case 0x9b: |
650 | ch = 0x203a; | 449 | ch = 0x203a; |
651 | break; | 450 | break; |
652 | case 0x9c: | 451 | case 0x9c: |
653 | ch = 0x0153; | 452 | ch = 0x0153; |
654 | break; | 453 | break; |
655 | case 0x9e: | 454 | case 0x9e: |
656 | ch = 0x017e; | 455 | ch = 0x017e; |
657 | break; | 456 | break; |
658 | case 0x9f: | 457 | case 0x9f: |
659 | ch = 0x0178; | 458 | ch = 0x0178; |
660 | break; | 459 | break; |
661 | case 0x18: | 460 | case 0x18: |
662 | ch = 0x2026; | 461 | ch = 0x2026; |
663 | break; | 462 | break; |
664 | case 0x19: | 463 | case 0x19: |
665 | ch = 0x2007; | 464 | ch = 0x2007; |
666 | break; | 465 | break; |
667 | case 0x8d: | 466 | case 0x8d: |
668 | ch = 0x2662; | 467 | ch = 0x2662; |
669 | break; | 468 | break; |
670 | case 0x8e: | 469 | case 0x8e: |
671 | ch = 0x2663; | 470 | ch = 0x2663; |
672 | break; | 471 | break; |
673 | case 0x8f: | 472 | case 0x8f: |
674 | ch = 0x2661; | 473 | ch = 0x2661; |
675 | break; | 474 | break; |
676 | case 0x90: | 475 | case 0x90: |
677 | ch = 0x2660; | 476 | ch = 0x2660; |
678 | break; | 477 | break; |
679 | default: | 478 | default: |
680 | break; | 479 | break; |
681 | } | 480 | } |
682 | } | 481 | } |
683 | #endif | ||
684 | 482 | ||
685 | //static tchar nextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 }; | 483 | //static tchar nextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 }; |
686 | //static tchar prevpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','p','r','e','v','i','o','u','s',' ','p','a','r','t',0 }; | 484 | //static tchar prevpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','p','r','e','v','i','o','u','s',' ','p','a','r','t',0 }; |
687 | 485 | ||
688 | void DePluck::getch(tchar& ch, CStyle& sty) | 486 | void DePluck::getch(tchar& ch, CStyle& sty, unsigned long& pos) |
689 | { | 487 | { |
690 | if (m_buffed > 0) | 488 | if (m_buffed > 0) |
691 | { | 489 | { |
692 | sty = m_laststyle; | 490 | sty = m_laststyle; |
693 | ch = nextpart[m_current++]; | 491 | ch = nextpart[m_current++]; |
694 | if (m_current == m_buffed) | 492 | if (m_current == m_buffed) |
695 | { | 493 | { |
696 | m_current = m_buffed = 0; | 494 | m_current = m_buffed = 0; |
697 | } | 495 | } |
698 | } | 496 | } |
699 | else | 497 | else |
700 | { | 498 | { |
701 | if (m_buffer != 0) | 499 | if (m_buffer != 0) |
702 | { | 500 | { |
703 | ch = m_buffer; | 501 | ch = m_buffer; |
704 | m_buffer = 0; | 502 | m_buffer = 0; |
705 | return; | 503 | return; |
706 | } | 504 | } |
707 | unsigned long lnk; | 505 | unsigned long lnk, lnkoff; |
708 | do | 506 | do |
709 | { | 507 | { |
710 | if (nextpart[m_buffed] == 0) break; | 508 | if (nextpart[m_buffed] == 0) break; |
711 | parent->getch(ch, sty); | 509 | parent->getch(ch, sty, pos); |
712 | m_laststyle = sty; | 510 | m_laststyle = sty; |
713 | if (sty.getLink()) lnk = sty.getData(); | 511 | if (sty.getLink()) |
512 | { | ||
513 | lnk = sty.getData(); | ||
514 | lnkoff = sty.getOffset(); | ||
515 | } | ||
714 | } while (ch == nextpart[m_buffed] && sty.getLink() && ++m_buffed); | 516 | } while (ch == nextpart[m_buffed] && sty.getLink() && ++m_buffed); |
715 | m_current = 0; | 517 | m_current = 0; |
716 | if (nextpart[m_buffed] == 0) | 518 | if (nextpart[m_buffed] == 0) |
717 | { | 519 | { |
718 | m_buffed = 0; | 520 | m_buffed = 0; |
719 | QString dmy; | 521 | QString dmy, dmy2; |
720 | parent->hyperlink(lnk, dmy); | 522 | parent->hyperlink(lnk, lnkoff, dmy, dmy2); |
721 | do | 523 | do |
722 | { | 524 | { |
723 | parent->getch(ch, sty); | 525 | parent->getch(ch, sty, pos); |
724 | } | 526 | } |
725 | while (ch != 10); | 527 | while (ch != 10); |
726 | parent->getch(ch, sty); | 528 | parent->getch(ch, sty, pos); |
727 | } | 529 | } |
728 | else if (m_buffed > 0) | 530 | else if (m_buffed > 0) |
729 | { | 531 | { |
730 | m_buffer = ch; | 532 | m_buffer = ch; |
731 | ch = nextpart[0]; | 533 | ch = nextpart[0]; |
732 | if (m_buffed == 1) | 534 | if (m_buffed == 1) |
733 | { | 535 | { |
734 | m_buffed = 0; | 536 | m_buffed = 0; |
735 | } | 537 | } |
736 | else m_current = 1; | 538 | else m_current = 1; |
737 | } | 539 | } |
738 | } | 540 | } |
739 | 541 | ||
740 | return; | 542 | return; |
741 | } | 543 | } |
544 | |||
545 | HighlightFilter::HighlightFilter(QTReader* _p) : pReader(_p), lastpos(0), nextpos(0), red(255), green(255), blue(255) | ||
546 | { | ||
547 | } | ||
548 | |||
549 | #include "Bkmks.h" | ||
550 | #include "QTReader.h" | ||
551 | |||
552 | void HighlightFilter::refresh(unsigned long pos) | ||
553 | { | ||
554 | bkmks = pReader->Bkmklist(); | ||
555 | |||
556 | red = green = blue = 255; | ||
557 | |||
558 | if (bkmks == NULL) | ||
559 | { | ||
560 | lastpos = 0; | ||
561 | nextpos = 0xffffffff; | ||
562 | } | ||
563 | else | ||
564 | { | ||
565 | lastpos = 0; | ||
566 | nextpos = 0xffffffff; | ||
567 | for (CList<Bkmk>::iterator i = bkmks->begin(); i != bkmks->end(); i++) | ||
568 | { | ||
569 | if ((*i).value() <= pos && pos < (*i).value2()) | ||
570 | { | ||
571 | red = i->red(); | ||
572 | green = i->green(); | ||
573 | blue = i->blue(); | ||
574 | lastpos = (*i).value(); | ||
575 | nextpos = (*i).value2(); | ||
576 | break; | ||
577 | } | ||
578 | if ((*i).value() > pos) | ||
579 | { | ||
580 | nextpos = (*i).value(); | ||
581 | break; | ||
582 | } | ||
583 | lastpos = (*i).value(); | ||
584 | } | ||
585 | } | ||
586 | } | ||
587 | |||
588 | void HighlightFilter::getch(tchar& ch, CStyle& sty, unsigned long& pos) | ||
589 | { | ||
590 | parent->getch(ch, sty, pos); | ||
591 | if (bkmks != pReader->Bkmklist() || pos <= lastpos || pos >= nextpos) | ||
592 | { | ||
593 | // qDebug("Recalc <%lu, %lu, %lu>", lastpos, pos, nextpos); | ||
594 | refresh(pos); | ||
595 | // qDebug("Recalc(2) <%lu, %lu, %lu>", lastpos, pos, nextpos); | ||
596 | } | ||
597 | int r = sty.bRed(), g = sty.bGreen(), b = sty.bBlue(); | ||
598 | if (r == 255 && g == 255 && b == 255) | ||
599 | { | ||
600 | sty.setBackground(red, green, blue); | ||
601 | } | ||
602 | } | ||
603 | |||
604 | void kern::getch(tchar& ch, CStyle& sty, unsigned long& pos) | ||
605 | { | ||
606 | if (uselast) | ||
607 | { | ||
608 | ch = lastchar; | ||
609 | sty = laststy; | ||
610 | uselast = false; | ||
611 | return; | ||
612 | } | ||
613 | else | ||
614 | { | ||
615 | parent->getch(ch, sty, pos); | ||
616 | } | ||
617 | switch (ch) | ||
618 | { | ||
619 | case 'f': | ||
620 | { | ||
621 | tchar savedchar = 'f'; | ||
622 | parent->getch(ch, sty, pos); | ||
623 | switch (ch) | ||
624 | { | ||
625 | case 'i': | ||
626 | ch = (251 << 8) + 1; | ||
627 | break; | ||
628 | case 'l': | ||
629 | ch = (251 << 8) + 2; | ||
630 | break; | ||
631 | default: | ||
632 | lastchar = ch; | ||
633 | uselast = true; | ||
634 | laststy = sty; | ||
635 | ch = savedchar; | ||
636 | } | ||
637 | } | ||
638 | break; | ||
639 | default: | ||
640 | break; | ||
641 | } | ||
642 | } | ||
643 | |||
644 | class ErrorFilter : public CFilter | ||
645 | { | ||
646 | QString error; | ||
647 | int currentpos; | ||
648 | public: | ||
649 | ErrorFilter(const QString& _s) : error(_s), currentpos(0) {} | ||
650 | ~ErrorFilter() {} | ||
651 | void getch(tchar& ch, CStyle& sty, unsigned long& pos) | ||
652 | { | ||
653 | if (currentpos == error.length()) | ||
654 | { | ||
655 | ch = UEOF; | ||
656 | currentpos = 0; | ||
657 | } | ||
658 | else | ||
659 | { | ||
660 | ch = error[currentpos++].unicode(); | ||
661 | } | ||
662 | } | ||
663 | QString about() { return parent->about(); } | ||
664 | }; | ||
665 | |||
666 | #ifndef __STATIC | ||
667 | ExternFilter::ExternFilter(const QString& nm, const QString& optional) : filt(NULL), handle(NULL) | ||
668 | { | ||
669 | QString filterpath(QTReaderUtil::getPluginPath("filters/lib")); | ||
670 | filterpath += nm; | ||
671 | filterpath += ".so"; | ||
672 | if (QFile::exists(filterpath)) | ||
673 | { | ||
674 | qDebug("Filter:%s", (const char*)filterpath); | ||
675 | handle = dlopen(filterpath, RTLD_LAZY); | ||
676 | if (handle == 0) | ||
677 | { | ||
678 | qDebug("Can't find filter:%s", dlerror()); | ||
679 | // status = -10; | ||
680 | filt = new ErrorFilter(QString("Can't find plugin:")+nm); | ||
681 | return; | ||
682 | } | ||
683 | CFilter* (*newfilter)(const QString&); | ||
684 | newfilter = (CFilter* (*)(const QString&))dlsym(handle, "newfilter"); | ||
685 | if (newfilter == NULL) | ||
686 | { | ||
687 | qDebug("Can't find newfilter"); | ||
688 | filt = new ErrorFilter(QString("Can't find entry point in plugin:")+nm); | ||
689 | return; | ||
690 | } | ||
691 | filt = (*newfilter)(optional); | ||
692 | } | ||
693 | else | ||
694 | { | ||
695 | qDebug("No filter path"); | ||
696 | filt = new ErrorFilter(QString("No filter plugins installed:")+nm); | ||
697 | } | ||
698 | if (filt == NULL) | ||
699 | { | ||
700 | qDebug("Can't do newfilter"); | ||
701 | filt = new ErrorFilter(QString("Filter creation failed:")+nm); | ||
702 | return; | ||
703 | } | ||
704 | } | ||
705 | #endif | ||
706 | |||
707 | void makeInverse::getch(tchar& ch, CStyle& sty, unsigned long& pos) | ||
708 | { | ||
709 | parent->getch(ch, sty, pos); | ||
710 | int r,g,b; | ||
711 | r = 255 - sty.Red(), g = 255 - sty.Green(), b = 255 - sty.Blue(); | ||
712 | sty.setColour(r,g,b); | ||
713 | r = 255 - sty.bRed(), g = 255 - sty.bGreen(), b = 255 - sty.bBlue(); | ||
714 | sty.setBackground(r,g,b); | ||
715 | r = 255 - sty.pRed(), g = 255 - sty.pGreen(), b = 255 - sty.pBlue(); | ||
716 | sty.setPaper(r,g,b); | ||
717 | } | ||
718 | /* | ||
719 | void makeNegative::getch(tchar& ch, CStyle& sty, unsigned long& pos) | ||
720 | { | ||
721 | parent->getch(ch, sty, pos); | ||
722 | QColor fg(sty.Red(), sty.Green(), sty.Blue()); | ||
723 | int h,s,v; | ||
724 | fg.hsv(&h,&s,&v); | ||
725 | fg.setHsv(h,s,255-v); | ||
726 | int r,g,b; | ||
727 | fg.rgb(&r,&g,&b); | ||
728 | sty.setColour(r,g,b); | ||
729 | |||
730 | fg = QColor(sty.bRed(), sty.bGreen(), sty.bBlue()); | ||
731 | fg.hsv(&h,&s,&v); | ||
732 | fg.setHsv(h,s,255-v); | ||
733 | fg.rgb(&r,&g,&b); | ||
734 | sty.setBackground(r,g,b); | ||
735 | } | ||
736 | */ | ||
737 | void setbg::getch(tchar& ch, CStyle& sty, unsigned long& pos) | ||
738 | { | ||
739 | parent->getch(ch, sty, pos); | ||
740 | int r = sty.pRed(), g = sty.pGreen(), b = sty.pBlue(); | ||
741 | if (r == 255 && g == 255 && b == 255) | ||
742 | { | ||
743 | sty.setPaper(m_r,m_g,m_b); | ||
744 | } | ||
745 | else | ||
746 | { | ||
747 | qDebug("We have background [%x%x%x]", r, g, b); | ||
748 | } | ||
749 | r = sty.bRed(), g = sty.bGreen(), b = sty.bBlue(); | ||
750 | if (r == 255 && g == 255 && b == 255) | ||
751 | { | ||
752 | sty.setBackground(m_r,m_g,m_b); | ||
753 | } | ||
754 | else | ||
755 | { | ||
756 | qDebug("We have background [%x%x%x]", r, g, b); | ||
757 | } | ||
758 | } | ||
759 | |||
760 | void setfg::getch(tchar& ch, CStyle& sty, unsigned long& pos) | ||
761 | { | ||
762 | parent->getch(ch, sty, pos); | ||
763 | int r = sty.Red(), g = sty.Green(), b = sty.Blue(); | ||
764 | if (r == 0 && g == 0 && b == 0) | ||
765 | { | ||
766 | sty.setColour(m_r,m_g,m_b); | ||
767 | } | ||
768 | } | ||
769 | |||
770 | #include "CRegExp.h" | ||
771 | |||
772 | repara::repara(const QString& pat) : tch(0) | ||
773 | { | ||
774 | // QString pat("{\\n[A-Z\"]}"); | ||
775 | flt = new CRegExpFilt(pat, false); | ||
776 | qDebug("Construction done"); | ||
777 | } | ||
778 | |||
779 | repara::~repara() | ||
780 | { | ||
781 | delete flt; | ||
782 | } | ||
783 | |||
784 | void repara::getch(tchar& ch, CStyle& sty, unsigned long& pos) | ||
785 | { | ||
786 | if (flt->empty()) | ||
787 | { | ||
788 | while (flt->empty()) | ||
789 | { | ||
790 | parent->getch(ch, sty, pos); | ||
791 | flt->addch(ch); | ||
792 | } | ||
793 | } | ||
794 | ch = flt->pop(); | ||
795 | /* | ||
796 | parent->getch(ch, sty, pos); | ||
797 | if (ch == 10 || ch == ' ') | ||
798 | { | ||
799 | if (tch == 10) | ||
800 | { | ||
801 | tch = ch; | ||
802 | ch = 10; | ||
803 | return; | ||
804 | } | ||
805 | else | ||
806 | { | ||
807 | tch = ch; | ||
808 | ch = ' '; | ||
809 | return; | ||
810 | } | ||
811 | } | ||
812 | tch = ch; | ||
813 | */ | ||
814 | return; | ||
815 | } | ||