summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/CFilter.h
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/CFilter.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/CFilter.h301
1 files changed, 224 insertions, 77 deletions
diff --git a/noncore/apps/opie-reader/CFilter.h b/noncore/apps/opie-reader/CFilter.h
index 0a03b3e..cec9618 100644
--- a/noncore/apps/opie-reader/CFilter.h
+++ b/noncore/apps/opie-reader/CFilter.h
@@ -6,15 +6,49 @@
6 6
7class CFilter : public CCharacterSource 7class CFilter_IFace : public CCharacterSource
8{
9 public:
10 virtual linkType hyperlink(unsigned int n, unsigned int noff, QString& w, QString& nm) = 0;
11 virtual void setparent(CCharacterSource* p) = 0;
12 virtual ~CFilter_IFace() {};
13 virtual void locate(unsigned int n) = 0;
14 virtual bool findanchor(const QString& nm) = 0;
15 virtual void saveposn(const QString& f, size_t posn) = 0;
16 virtual void writeposn(const QString& f, size_t posn) = 0;
17 virtual linkType forward(QString& f, size_t& loc) = 0;
18 virtual linkType back(QString& f, size_t& loc) = 0;
19 virtual bool hasnavigation() = 0;
20 virtual int getwidth() = 0;
21 virtual CCharacterSource* getparent() = 0;
22};
23
24class CFilter : public CFilter_IFace
8{ 25{
9 friend class CFilterChain;
10 protected: 26 protected:
11 CCharacterSource* parent; 27 CCharacterSource* parent;
12 linkType hyperlink(unsigned int n, QString& w) 28 public:
29 virtual linkType hyperlink(unsigned int n, unsigned int noff, QString& w, QString& nm)
13 { 30 {
14 return parent->hyperlink(n,w); 31 return parent->hyperlink(n,noff,w,nm);
15 } 32 }
16 public:
17 CFilter() : parent(NULL) {} 33 CFilter() : parent(NULL) {}
18 void setparent(CCharacterSource* p) { parent = p; } 34 void setparent(CCharacterSource* p) { parent = p; }
35 CCharacterSource* getparent() { return parent; }
19 virtual ~CFilter() {}; 36 virtual ~CFilter() {};
37 virtual void locate(unsigned int n)
38 {
39 parent->locate(n);
40 }
41 virtual bool findanchor(const QString& nm)
42 {
43 return parent->findanchor(nm);
44 }
45 virtual void saveposn(const QString& f, size_t posn) { parent->saveposn(f, posn); }
46 virtual void writeposn(const QString& f, size_t posn) { parent->writeposn(f, posn); }
47 virtual linkType forward(QString& f, size_t& loc) { return parent->forward(f, loc); }
48 virtual linkType back(QString& f, size_t& loc) { return parent->back(f, loc); }
49 virtual bool hasnavigation() { return parent->hasnavigation(); }
50 virtual int getwidth() { return parent->getwidth(); }
51 QImage* getPicture(unsigned long tgt) { return parent->getPicture(tgt); }
52 QImage* getPicture(const QString& href) { return parent->getPicture(href); }
53 bool getFile(const QString& href) { return parent->getFile(href); }
20}; 54};
@@ -23,5 +57,5 @@ class CFilterChain
23{ 57{
24 CExpander* expander; 58 CExpander_Interface* expander;
25 CEncoding* encoder; 59 CEncoding* encoder;
26 CFilter* first; 60 CFilter_IFace* first;
27 CCharacterSource* front; 61 CCharacterSource* front;
@@ -34,4 +68,4 @@ class CFilterChain
34 { 68 {
35 CFilter* pnext = (CFilter*)p; 69 CFilter_IFace* pnext = (CFilter_IFace*)p;
36 p = ((CFilter*)p)->parent; 70 p = ((CFilter_IFace*)p)->getparent();
37 delete pnext; 71 delete pnext;
@@ -40,7 +74,15 @@ class CFilterChain
40 } 74 }
41 void getch(tchar& ch, CStyle& sty) 75 linkType hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm)
76 {
77 return front->hyperlink(n, noff, wrd, nm);
78 }
79 void locate(unsigned int n)
80 {
81 front->locate(n);
82 }
83 void getch(tchar& ch, CStyle& sty, unsigned long& pos)
42 { 84 {
43 front->getch(ch, sty); 85 front->getch(ch, sty, pos);
44 } 86 }
45 void addfilter(CFilter* p) 87 void addfilter(CFilter_IFace* p)
46 { 88 {
@@ -57,3 +99,3 @@ class CFilterChain
57 } 99 }
58 void setsource(CExpander* p) 100 void setsource(CExpander_Interface* p)
59 { 101 {
@@ -63,8 +105,18 @@ class CFilterChain
63 void setencoder(CEncoding* p) 105 void setencoder(CEncoding* p)
64 { 106 {
65 delete encoder; 107 delete encoder;
66 encoder = p; 108 encoder = p;
67 first->setparent(p); 109 first->setparent(p);
68 encoder->setparent(expander); 110 encoder->setparent(expander);
69 } 111 }
112 bool findanchor(const QString& nm)
113 {
114 return front->findanchor(nm);
115 }
116 void saveposn(const QString& f, size_t posn) { front->saveposn(f, posn); }
117 void writeposn(const QString& f, size_t posn) { front->writeposn(f, posn); }
118 linkType forward(QString& f, size_t& loc) { return front->forward(f, loc); }
119 linkType back(QString& f, size_t& loc) { return front->back(f, loc); }
120 bool hasnavigation() { return front->hasnavigation(); }
121 QString about() { return QString("Filter chain (c) Tim Wentford\n")+front->about(); }
70}; 122};
@@ -76,3 +128,3 @@ class stripcr : public CFilter
76 ~stripcr() {} 128 ~stripcr() {}
77 void getch(tchar& ch, CStyle& sty) 129 void getch(tchar& ch, CStyle& sty, unsigned long& pos)
78 { 130 {
@@ -80,3 +132,3 @@ class stripcr : public CFilter
80 { 132 {
81 parent->getch(ch, sty); 133 parent->getch(ch, sty, pos);
82 } 134 }
@@ -84,2 +136,3 @@ class stripcr : public CFilter
84 } 136 }
137 QString about() { return QString("StripCR filter (c) Tim Wentford\n")+parent->about(); }
85}; 138};
@@ -94,3 +147,3 @@ class dehyphen : public CFilter
94 ~dehyphen() {} 147 ~dehyphen() {}
95 void getch(tchar& ch, CStyle& sty) 148 void getch(tchar& ch, CStyle& sty, unsigned long& pos)
96 { 149 {
@@ -103,5 +156,5 @@ class dehyphen : public CFilter
103 } 156 }
104 parent->getch(ch, sty); 157 parent->getch(ch, sty, pos);
105 if (ch != '-') return; 158 if (ch != '-') return;
106 parent->getch(m_nextChar, m_nextSty); 159 parent->getch(m_nextChar, m_nextSty, pos);
107 if (m_nextChar != 10) 160 if (m_nextChar != 10)
@@ -112,17 +165,20 @@ class dehyphen : public CFilter
112 } 165 }
113 parent->getch(ch, sty); 166 parent->getch(ch, sty, pos);
114 } 167 }
168 QString about() { return QString("Hyphenation filter (c) Tim Wentford\n")+parent->about(); }
115}; 169};
116 170
117class striphtml : public CFilter 171template<class A, class B>class QMap;
172
173const int m_cmaxdepth = 8;
174
175class htmlmark
118{ 176{
119 CStyle currentstyle; 177 QString file;
120 unsigned short skip_ws(); 178 size_t pos;
121 unsigned short skip_ws_end();
122 unsigned short parse_m();
123 void mygetch(tchar& ch, CStyle& sty);
124 public: 179 public:
125 striphtml() {} 180 htmlmark() : file(), pos(0) {}
126 ~striphtml() {} 181 htmlmark(const QString& _f, size_t _p) : file(_f), pos(_p) {}
127 void getch(tchar& ch, CStyle& sty); 182 QString filename() { return file; }
183 size_t posn() { return pos; }
128}; 184};
@@ -135,3 +191,3 @@ class unindent : public CFilter
135 ~unindent() {} 191 ~unindent() {}
136 void getch(tchar& ch, CStyle& sty) 192 void getch(tchar& ch, CStyle& sty, unsigned long& pos)
137 { 193 {
@@ -141,3 +197,3 @@ class unindent : public CFilter
141 { 197 {
142 parent->getch(ch, sty); 198 parent->getch(ch, sty, pos);
143 } 199 }
@@ -145,3 +201,3 @@ class unindent : public CFilter
145 } 201 }
146 else parent->getch(ch, sty); 202 else parent->getch(ch, sty, pos);
147 lc = ch; 203 lc = ch;
@@ -149,4 +205,6 @@ class unindent : public CFilter
149 } 205 }
206 QString about() { return QString("Unindent filter (c) Tim Wentford\n")+parent->about(); }
150}; 207};
151 208
209class CRegExpFilt;
152class repara : public CFilter 210class repara : public CFilter
@@ -154,24 +212,8 @@ class repara : public CFilter
154 tchar tch; 212 tchar tch;
213 CRegExpFilt* flt;
155 public: 214 public:
156 repara() : tch(0) {} 215 repara(const QString&);
157 ~repara() {} 216 ~repara();
158 void getch(tchar& ch, CStyle& sty) 217 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
159 { 218 QString about() { return QString("Reparagraph filter (c) Tim Wentford\n")+parent->about(); }
160 parent->getch(ch, sty);
161 if (ch == 10)
162 {
163 if (tch == 10)
164 {
165 return;
166 }
167 else
168 {
169 tch = ch;
170 ch = ' ';
171 return;
172 }
173 }
174 tch = ch;
175 return;
176 }
177}; 219};
@@ -186,3 +228,3 @@ class indenter : public CFilter
186 ~indenter() {} 228 ~indenter() {}
187 void getch(tchar& ch, CStyle& sty) 229 void getch(tchar& ch, CStyle& sty, unsigned long& pos)
188 { 230 {
@@ -195,3 +237,3 @@ class indenter : public CFilter
195 } 237 }
196 parent->getch(ch, sty); 238 parent->getch(ch, sty, pos);
197 if (ch == 10) 239 if (ch == 10)
@@ -203,2 +245,3 @@ class indenter : public CFilter
203 } 245 }
246 QString about() { return QString("Indentation filter (c) Tim Wentford\n")+parent->about(); }
204}; 247};
@@ -212,3 +255,3 @@ class dblspce : public CFilter
212 ~dblspce() {} 255 ~dblspce() {}
213 void getch(tchar& ch, CStyle& sty) 256 void getch(tchar& ch, CStyle& sty, unsigned long& pos)
214 { 257 {
@@ -221,3 +264,3 @@ class dblspce : public CFilter
221 } 264 }
222 parent->getch(ch, sty); 265 parent->getch(ch, sty, pos);
223 if (lastlf = (ch == 10)) 266 if (lastlf = (ch == 10))
@@ -228,2 +271,3 @@ class dblspce : public CFilter
228 } 271 }
272 QString about() { return QString("Double space (c) Tim Wentford\n")+parent->about(); }
229}; 273};
@@ -235,3 +279,3 @@ class textfmt : public CFilter
235 bool uselast; 279 bool uselast;
236 void mygetch(tchar&, CStyle&); 280 void mygetch(tchar&, CStyle&, unsigned long& pos);
237 public: 281 public:
@@ -239,3 +283,4 @@ class textfmt : public CFilter
239 ~textfmt() {} 283 ~textfmt() {}
240 void getch(tchar& ch, CStyle& sty); 284 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
285 QString about() { return QString("Text formatting filter (c) Tim Wentford\n")+parent->about(); }
241}; 286};
@@ -247,7 +292,8 @@ class embolden : public CFilter
247 ~embolden() {} 292 ~embolden() {}
248 void getch(tchar& ch, CStyle& sty) 293 void getch(tchar& ch, CStyle& sty, unsigned long& pos)
249 { 294 {
250 parent->getch(ch, sty); 295 parent->getch(ch, sty, pos);
251 sty.setBold(); 296 sty.setBold();
252 } 297 }
298 QString about() { return QString("Emboldening filter (c) Tim Wentford\n")+parent->about(); }
253}; 299};
@@ -262,3 +308,4 @@ class remap : public CFilter
262 ~remap() {} 308 ~remap() {}
263 void getch(tchar& ch, CStyle& sty); 309 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
310 QString about() { return QString("Character remapping filter (c) Tim Wentford\n")+parent->about(); }
264}; 311};
@@ -270,3 +317,4 @@ class PeanutFormatter : public CFilter
270 ~PeanutFormatter() {} 317 ~PeanutFormatter() {}
271 void getch(tchar& ch, CStyle& sty); 318 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
319 QString about() { return QString("PML filter (c) Tim Wentford\n")+parent->about(); }
272}; 320};
@@ -279,3 +327,4 @@ class OnePara : public CFilter
279 ~OnePara() {} 327 ~OnePara() {}
280 void getch(tchar& ch, CStyle& sty); 328 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
329 QString about() { return QString("Single space filter (c) Tim Wentford\n")+parent->about(); }
281}; 330};
@@ -293,6 +342,6 @@ class DePluck : public CFilter
293 ~DePluck() {} 342 ~DePluck() {}
294 void getch(tchar& ch, CStyle& sty); 343 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
344 QString about() { return QString("Depluck filter (c) Tim Wentford\n")+parent->about(); }
295}; 345};
296 346
297#ifdef REPALM
298class repalm : public CFilter 347class repalm : public CFilter
@@ -301,5 +350,5 @@ class repalm : public CFilter
301 ~repalm() {} 350 ~repalm() {}
302 void getch(tchar& ch, CStyle& sty); 351 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
352 QString about() { return QString("Repalm filter (c) Tim Wentford\n")+parent->about(); }
303}; 353};
304#endif
305 354
@@ -308,7 +357,8 @@ class FullJust : public CFilter
308 public: 357 public:
309 void getch(tchar& ch, CStyle& sty) 358 void getch(tchar& ch, CStyle& sty, unsigned long& pos)
310 { 359 {
311 parent->getch(ch, sty); 360 parent->getch(ch, sty, pos);
312 if (sty.getJustify() == m_AlignLeft) sty.setFullJustify(); 361 if (sty.getJustify() == m_AlignLeft) sty.setFullJustify();
313 } 362 }
363 QString about() { return QString("Full justification filter (c) Tim Wentford\n")+parent->about(); }
314}; 364};
@@ -320,5 +370,5 @@ class AddSpace : public CFilter
320 AddSpace(unsigned char s) : m_espc(s) {} 370 AddSpace(unsigned char s) : m_espc(s) {}
321 void getch(tchar& ch, CStyle& sty) 371 void getch(tchar& ch, CStyle& sty, unsigned long& pos)
322 { 372 {
323 parent->getch(ch, sty); 373 parent->getch(ch, sty, pos);
324 sty.setExtraSpace(m_espc); 374 sty.setExtraSpace(m_espc);
@@ -327,2 +377,99 @@ class AddSpace : public CFilter
327*/ 377*/
378
379class QTReader;
380
381class HighlightFilter : public CFilter
382{
383 QTReader* pReader;
384 unsigned long lastpos, nextpos;
385 unsigned char red, green, blue;
386 CList<Bkmk>* bkmks;
387 public:
388 HighlightFilter(QTReader*);
389 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
390 void refresh(unsigned long);
391 QString about() { return QString("High-lighting filter (c) Tim Wentford\n")+parent->about(); }
392};
393
394#include "static.h"
395#ifndef __STATIC
396#include <dlfcn.h>
397
398class ExternFilter : public CFilter_IFace
399{
400 CFilter* filt;
401 void *handle;
402 public:
403 linkType hyperlink(unsigned int n, unsigned int noff, QString& w, QString& nm)
404 {
405 return filt->hyperlink(n, noff, w, nm);
406 }
407 void setparent(CCharacterSource* p) { filt->setparent(p); }
408 ExternFilter(const QString& nm, const QString& optional);
409 ~ExternFilter()
410 {
411 if (filt != NULL) delete filt;
412 if (handle != NULL) dlclose(handle);
413 }
414 void locate(unsigned int n) { filt->locate(n); }
415 bool findanchor(const QString& nm) { return filt->findanchor(nm); }
416 void saveposn(const QString& f, size_t posn) { filt->saveposn(f, posn); }
417 void writeposn(const QString& f, size_t posn) { filt->writeposn(f, posn); }
418 linkType forward(QString& f, size_t& loc) { return filt->forward(f, loc); }
419 linkType back(QString& f, size_t& loc) { return filt->back(f, loc); }
420 bool hasnavigation() { return filt->hasnavigation(); }
421 int getwidth() { return filt->getwidth(); }
422 CCharacterSource* getparent() { return filt->getparent(); }
423 void getch(tchar& c, CStyle& s, unsigned long& l) { filt->getch(c, s, l); }
424 QImage* getPicture(unsigned long tgt) { return filt->getPicture(tgt); }
425 CFilter* filter() { return filt; }
426 QImage* getPicture(const QString& href) { return filt->getPicture(href); }
427 bool getFile(const QString& href) { return filt->getFile(href); }
428 QString about() { return QString("Filter plug-in (c) Tim Wentford\n")+filt->about(); }
429};
430#endif
431
432class kern : public CFilter
433{
434 tchar lastchar;
435 bool uselast;
436 CStyle laststy;
437 public:
438 kern() : lastchar(0), uselast(false) {}
439 ~kern() {}
440 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
441 QString about() { return QString("Kerning filter (c) Tim Wentford\n")+parent->about(); }
442};
443
444class makeInverse : public CFilter
445{
446 public:
447 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
448 QString about() { return QString("Colourmap inversion filter (c) Tim Wentford\n")+parent->about(); }
449};
450/*
451class makeNegative : public CFilter
452{
453 public:
454 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
455};
456*/
457class setbg : public CFilter
458{
459 int m_r, m_g, m_b;
460 public:
461 setbg(int _r, int _g, int _b) : m_r(_r), m_g(_g), m_b(_b) {}
462 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
463 QString about() { return QString("Background colour filter (c) Tim Wentford\n")+parent->about(); }
464};
465
466class setfg : public CFilter
467{
468 int m_r, m_g, m_b;
469 public:
470 setfg(int _r, int _g, int _b) : m_r(_r), m_g(_g), m_b(_b) {}
471 void getch(tchar& ch, CStyle& sty, unsigned long& pos);
472 QString about() { return QString("Foreground colour filter (c) Tim Wentford\n")+parent->about(); }
473};
474
328#endif 475#endif