Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CFilter.h

Go to the documentation of this file.
00001 #ifndef __CFILTER_H
00002 #define __CFILTER_H
00003 
00004 #include "CExpander.h"
00005 #include "CEncoding.h"
00006 
00007 class CFilter_IFace : public CCharacterSource
00008 {
00009  public:
00010     virtual linkType hyperlink(unsigned int n, unsigned int noff, QString& w, QString& nm) = 0;
00011     virtual void setparent(CCharacterSource* p) = 0;
00012     virtual ~CFilter_IFace() {};
00013     virtual void locate(unsigned int n) = 0;
00014     virtual bool findanchor(const QString& nm) = 0;
00015     virtual void saveposn(const QString& f, size_t posn) = 0;
00016     virtual void writeposn(const QString& f, size_t posn) = 0;
00017     virtual linkType forward(QString& f, size_t& loc) = 0;
00018     virtual linkType back(QString& f, size_t& loc) = 0;
00019     virtual bool hasnavigation() = 0;
00020     virtual int getwidth() = 0;
00021     virtual CCharacterSource* getparent() = 0;
00022     virtual unsigned long startSection() = 0;
00023 };
00024 
00025 class CFilter : public CFilter_IFace
00026 {
00027  protected:
00028     CCharacterSource* parent;
00029  public:
00030   virtual QString getTableAsHtml(unsigned long loc)
00031     {
00032       qDebug("CFilter::getTableAsHtml()");
00033       return parent->getTableAsHtml(loc);
00034     }
00035     virtual linkType hyperlink(unsigned int n, unsigned int noff, QString& w, QString& nm)
00036         {
00037             return parent->hyperlink(n,noff,w,nm);
00038         }
00039     CFilter() : parent(NULL) {}
00040     void setparent(CCharacterSource* p) { parent = p; }
00041     CCharacterSource* getparent() { return parent; }
00042     virtual ~CFilter() {};
00043     virtual void locate(unsigned int n)
00044       {
00045         parent->locate(n);
00046       }
00047    virtual bool findanchor(const QString& nm)
00048      {
00049        return parent->findanchor(nm);
00050      }
00051     virtual void saveposn(const QString& f, size_t posn) { parent->saveposn(f, posn); }
00052     virtual void writeposn(const QString& f, size_t posn) { parent->writeposn(f, posn); }
00053     virtual linkType forward(QString& f, size_t& loc) { return parent->forward(f, loc); }
00054     virtual linkType back(QString& f, size_t& loc) { return parent->back(f, loc); }
00055     virtual bool hasnavigation() { return parent->hasnavigation(); }
00056     virtual int getwidth() { return parent->getwidth(); }
00057     QImage* getPicture(unsigned long tgt) { return parent->getPicture(tgt); }
00058     QImage* getPicture(const QString& href) { return parent->getPicture(href); }
00059     bool getFile(const QString& href, const QString& nm) { return parent->getFile(href, nm); }
00060     virtual unsigned long startSection() { return parent->startSection(); }
00061 };
00062 
00063 class CFilterChain
00064 {
00065     CExpander_Interface* expander;
00066     CEncoding* encoder;
00067     CFilter_IFace* first;
00068     CCharacterSource* front;
00069  public:
00070     CFilterChain(CEncoding* _e) : encoder(_e), first(NULL), front(_e) {};
00071     ~CFilterChain()
00072         {
00073             CCharacterSource* p = front;
00074             while (p != encoder)
00075             {
00076                 CFilter_IFace* pnext = (CFilter_IFace*)p;
00077                 p = ((CFilter_IFace*)p)->getparent();
00078                 delete pnext;
00079             }
00080             delete encoder;
00081         }
00082     linkType hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm)
00083       {
00084         return front->hyperlink(n, noff, wrd, nm);
00085       }
00086     QString getTableAsHtml(unsigned long loc)
00087       {
00088         return front->getTableAsHtml(loc);
00089       }
00090     void locate(unsigned int n)
00091       {
00092         front->locate(n);
00093       }
00094     void getch(tchar& ch, CStyle& sty, unsigned long& pos)
00095         {
00096             front->getch(ch, sty, pos);
00097         }
00098     /*
00099     void rawgetch(tchar& ch, CStyle& sty, unsigned long& pos)
00100       {
00101         encoder->getch(ch, sty, pos);
00102       }
00103     */
00104     void addfilter(CFilter_IFace* p)
00105         {
00106             if (first == NULL)
00107             {
00108                 front = first = p;
00109                 p->setparent(encoder);
00110             }
00111             else
00112             {
00113                 p->setparent(front);
00114                 front = p;
00115             }
00116         }
00117     void setsource(CExpander_Interface* p)
00118         {
00119             expander = p;
00120             encoder->setparent(p);
00121         }
00122     void setencoder(CEncoding* p)
00123       {
00124         delete encoder;
00125         encoder = p;
00126         first->setparent(p);
00127         encoder->setparent(expander);
00128       }
00129     bool findanchor(const QString& nm)
00130       {
00131         return front->findanchor(nm);
00132       }
00133     void saveposn(const QString& f, size_t posn) { front->saveposn(f, posn); }
00134     void writeposn(const QString& f, size_t posn) { front->writeposn(f, posn); }
00135     linkType forward(QString& f, size_t& loc) { return front->forward(f, loc); }
00136     linkType back(QString& f, size_t& loc) { return front->back(f, loc); }
00137     bool hasnavigation() { return front->hasnavigation(); }
00138     QString about() { return QString("Filter chain (c) Tim Wentford\n")+front->about(); }
00139 };
00140 
00141 class stripcr : public CFilter
00142 {
00143  public:
00144     stripcr() {}
00145     ~stripcr() {}
00146     void getch(tchar& ch, CStyle& sty, unsigned long& pos)
00147         {
00148             do
00149             {
00150                 parent->getch(ch, sty, pos);
00151             }
00152             while (ch == 13);
00153         }
00154     QString about() { return QString("StripCR filter (c) Tim Wentford\n")+parent->about(); }
00155 };
00156 
00157 class dehyphen : public CFilter
00158 {
00159     bool m_bCharWaiting;
00160     tchar m_nextChar;
00161     CStyle m_nextSty;
00162  public:
00163     dehyphen() : m_bCharWaiting(false) {}
00164     ~dehyphen() {}
00165     void getch(tchar& ch, CStyle& sty, unsigned long& pos)
00166         {
00167             if (m_bCharWaiting)
00168             {
00169                 m_bCharWaiting = false;
00170                 ch = m_nextChar;
00171                 sty = m_nextSty;
00172                 return;
00173             }
00174             parent->getch(ch, sty, pos);
00175             if (ch != '-') return;
00176             parent->getch(m_nextChar, m_nextSty, pos);
00177             if (m_nextChar != 10)
00178             {
00179                 m_bCharWaiting = true;
00180                 ch = '-';
00181                 return;
00182             }
00183             parent->getch(ch, sty, pos);
00184         }
00185     QString about() { return QString("Hyphenation filter (c) Tim Wentford\n")+parent->about(); }
00186 };
00187 
00188 template<class A, class B>class QMap;
00189 
00190 const int m_cmaxdepth = 8;
00191 
00192 class htmlmark
00193 {
00194   QString file;
00195   size_t pos;
00196  public:
00197   htmlmark() : file(), pos(0) {}
00198   htmlmark(const QString& _f, size_t _p) : file(_f), pos(_p) {}
00199   QString filename() { return file; }
00200   size_t posn() { return pos; }
00201 };
00202 
00203 class unindent : public CFilter
00204 {
00205     tchar lc;
00206  public:
00207     unindent() : lc(0) {}
00208     ~unindent() {}
00209     void getch(tchar& ch, CStyle& sty, unsigned long& pos)
00210         {
00211             if (lc == 10)
00212             {
00213                 do
00214                 {
00215                     parent->getch(ch, sty, pos);
00216                 }
00217                 while (ch == ' ');
00218             }
00219             else parent->getch(ch, sty, pos);
00220             lc = ch;
00221             return;
00222         }
00223     QString about() { return QString("Unindent filter (c) Tim Wentford\n")+parent->about(); }
00224 };
00225 
00226 class CRegExpFilt;
00227 class repara : public CFilter
00228 {
00229     tchar tch;
00230     CRegExpFilt* flt;
00231  public:
00232     repara(const QString&);
00233     ~repara();
00234     void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00235     QString about() { return QString("Reparagraph filter (c) Tim Wentford\n")+parent->about(); }
00236 };
00237 
00238 class indenter : public CFilter
00239 {
00240     int amnt;
00241     int indent;
00242     CStyle lsty;
00243  public:
00244     indenter(int _a=5) : amnt(_a), indent(0) {}
00245     ~indenter() {}
00246     void getch(tchar& ch, CStyle& sty, unsigned long& pos)
00247         {
00248             if (indent > 0)
00249             {
00250                 indent--;
00251                 ch = ' ';
00252                 sty = lsty;
00253                 return;
00254             }
00255             parent->getch(ch, sty, pos);
00256             if (ch == 10)
00257             {
00258                 indent = amnt;
00259                 lsty = sty;
00260             }
00261             return;
00262         }
00263     QString about() { return QString("Indentation filter (c) Tim Wentford\n")+parent->about(); }
00264 };
00265 
00266 class dblspce : public CFilter
00267 {
00268     bool lastlf;
00269     CStyle lsty;
00270  public:
00271     dblspce() : lastlf(false) {}
00272     ~dblspce() {}
00273     void getch(tchar& ch, CStyle& sty, unsigned long& pos)
00274         {
00275             if (lastlf)
00276             {
00277                 lastlf = false;
00278                 ch = 10;
00279                 sty = lsty;
00280                 return;
00281             }
00282             parent->getch(ch, sty, pos);
00283             if (lastlf = (ch == 10))
00284             {
00285                 lsty = sty;
00286             }
00287             return;
00288         }
00289     QString about() { return QString("Double space (c) Tim Wentford\n")+parent->about(); }
00290 };
00291 
00292 class textfmt : public CFilter
00293 {
00294     CStyle currentstyle;
00295     tchar lastchar;
00296     bool uselast;
00297     void mygetch(tchar&, CStyle&, unsigned long& pos);
00298  public:
00299     textfmt() : lastchar(0), uselast(false) {}
00300     ~textfmt() {}
00301     void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00302     QString about() { return QString("Text formatting filter (c) Tim Wentford\n")+parent->about(); }
00303 };
00304 
00305 class embolden : public CFilter
00306 {
00307  public:
00308     embolden() {}
00309     ~embolden() {}
00310     void getch(tchar& ch, CStyle& sty, unsigned long& pos)
00311         {
00312             parent->getch(ch, sty, pos);
00313             sty.setBold();
00314         }
00315     QString about() { return QString("Emboldening filter (c) Tim Wentford\n")+parent->about(); }
00316 };
00317 
00318 class remap : public CFilter
00319 {
00320     tchar q[3];
00321     int offset;
00322     CStyle currentstyle;
00323  public:
00324     remap() : offset(0) { q[0] = 0; }
00325     ~remap() {}
00326     void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00327     QString about() { return QString("Character remapping filter (c) Tim Wentford\n")+parent->about(); }
00328 };
00329 
00330 class PeanutFormatter : public CFilter
00331 {
00332     CStyle currentstyle;
00333  public:
00334     ~PeanutFormatter() {}
00335     void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00336     QString about() { return QString("PML filter (c) Tim Wentford\n")+parent->about(); }
00337 };
00338 
00339 class OnePara : public CFilter
00340 {
00341     tchar m_lastchar;
00342  public:
00343     OnePara() : m_lastchar(0) {}
00344     ~OnePara() {}
00345     void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00346     QString about() { return QString("Single space filter (c) Tim Wentford\n")+parent->about(); }
00347 };
00348 
00349 class DePluck : public CFilter
00350 {
00351     tchar* nextpart;
00352     tchar m_buffer;
00353     int m_buffed;
00354     int m_current;
00355     bool m_debuff;
00356     CStyle m_laststyle;
00357  public:
00358     DePluck(tchar* t) : nextpart(t), m_buffer(0), m_buffed(0), m_current(0), m_debuff(false) {}
00359     ~DePluck() {}
00360     void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00361     QString about() { return QString("Depluck filter (c) Tim Wentford\n")+parent->about(); }
00362 };
00363 
00364 class repalm : public CFilter
00365 {
00366  public:
00367     ~repalm() {}
00368     void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00369     QString about() { return QString("Repalm filter (c) Tim Wentford\n")+parent->about(); }
00370 };
00371 
00372 class FullJust : public CFilter
00373 {
00374  public:
00375     void getch(tchar& ch, CStyle& sty, unsigned long& pos)
00376         {
00377             parent->getch(ch, sty, pos);
00378             if (sty.getJustify() == m_AlignLeft) sty.setFullJustify();
00379         }
00380     QString about() { return QString("Full justification filter (c) Tim Wentford\n")+parent->about(); }
00381 };
00382 /*
00383 class AddSpace : public CFilter
00384 {
00385     unsigned char m_espc;
00386  public:
00387     AddSpace(unsigned char s) : m_espc(s) {}
00388     void getch(tchar& ch, CStyle& sty, unsigned long& pos)
00389         {
00390             parent->getch(ch, sty, pos);
00391             sty.setExtraSpace(m_espc);
00392         }
00393 };
00394 */
00395 
00396 class QTReader;
00397 
00398 class HighlightFilter : public CFilter
00399 {
00400   QTReader* pReader;
00401   unsigned long lastpos, nextpos;
00402   unsigned char red, green, blue;
00403   CList<Bkmk>* bkmks;
00404  public:
00405   HighlightFilter(QTReader*);
00406   void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00407   void refresh(unsigned long);
00408   QString about() { return QString("High-lighting filter (c) Tim Wentford\n")+parent->about(); }
00409 };
00410 
00411 #ifndef __STATIC
00412 #include <dlfcn.h>
00413 
00414 class ExternFilter : public CFilter_IFace
00415 {
00416   CFilter* filt;
00417   void *handle;
00418  public:
00419   linkType hyperlink(unsigned int n, unsigned int noff, QString& w, QString& nm)
00420     {
00421       return filt->hyperlink(n, noff, w, nm);
00422     }
00423   QString getTableAsHtml(unsigned long loc)
00424     {
00425       qDebug("ExternFilter::getTableAsHtml()");
00426       return filt->getTableAsHtml(loc);
00427     }
00428   void setparent(CCharacterSource* p) { filt->setparent(p); }
00429   ExternFilter(const QString& nm, const QString& optional);
00430   ~ExternFilter()
00431     {
00432       if (filt != NULL) delete filt;
00433       if (handle != NULL) dlclose(handle);
00434     }
00435   void locate(unsigned int n) { filt->locate(n); }
00436   bool findanchor(const QString& nm)
00437     {
00438       return filt->findanchor(nm);
00439     }
00440   void saveposn(const QString& f, size_t posn) { filt->saveposn(f, posn); }
00441   void writeposn(const QString& f, size_t posn) { filt->writeposn(f, posn); }
00442   linkType forward(QString& f, size_t& loc) { return filt->forward(f, loc); }
00443   linkType back(QString& f, size_t& loc) { return filt->back(f, loc); }
00444   bool hasnavigation() { return filt->hasnavigation(); }
00445   int getwidth() { return filt->getwidth(); }
00446   CCharacterSource* getparent() { return filt->getparent(); }
00447   void getch(tchar& c, CStyle& s, unsigned long& l) { filt->getch(c, s, l); }
00448   QImage* getPicture(unsigned long tgt) { return filt->getPicture(tgt); }
00449   CFilter* filter() { return filt; }
00450   QImage* getPicture(const QString& href) { return filt->getPicture(href); }
00451   bool getFile(const QString& href, const QString& nm) { return filt->getFile(href, nm); }
00452   QString about() { return QString("Filter plug-in (c) Tim Wentford\n")+filt->about(); }
00453   unsigned long startSection() { return filt->startSection(); }
00454 };
00455 #endif
00456 
00457 class kern : public CFilter
00458 {
00459     tchar lastchar;
00460     bool uselast;
00461     CStyle laststy;
00462  public:
00463     kern() : lastchar(0), uselast(false) {}
00464     ~kern() {}
00465     void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00466     QString about() { return QString("Kerning filter (c) Tim Wentford\n")+parent->about(); }
00467 };
00468 
00469 class makeInverse : public CFilter
00470 {
00471  public:
00472   void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00473   QString about() { return QString("Colourmap inversion filter (c) Tim Wentford\n")+parent->about(); }
00474 };
00475 /*
00476 class makeNegative : public CFilter
00477 {
00478  public:
00479   void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00480 };
00481 */
00482 class setbg : public CFilter
00483 {
00484   int m_r, m_g, m_b;
00485  public:
00486   setbg(int _r, int _g, int _b) : m_r(_r), m_g(_g), m_b(_b) {}
00487   void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00488   QString about() { return QString("Background colour filter (c) Tim Wentford\n")+parent->about(); }
00489 };
00490 
00491 class setfg : public CFilter
00492 {
00493   int m_r, m_g, m_b;
00494  public:
00495   setfg(int _r, int _g, int _b) : m_r(_r), m_g(_g), m_b(_b) {}
00496   void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00497   QString about() { return QString("Foreground colour filter (c) Tim Wentford\n")+parent->about(); }
00498 };
00499 
00500 class tableLink : public CFilter
00501 {
00502   QString text;
00503   int offset;
00504   int m_r, m_g, m_b;
00505  public:
00506   tableLink() : text( "See Table" ), offset(-1)
00507     {
00508     }
00509   void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00510   QString about() { return QString("Table link filter (c) Tim Wentford\n")+parent->about(); }
00511 };
00512 
00513 class underlineLink : public CFilter
00514 {
00515   bool isLink;
00516  public:
00517     underlineLink() : isLink(false) {}
00518     ~underlineLink() {}
00519     void getch(tchar& ch, CStyle& sty, unsigned long& pos);
00520     QString about() { return QString("Link underlining filter (c) Tim Wentford\n")+parent->about(); }
00521 };
00522 
00523 #endif

Generated on Sat Nov 5 16:16:54 2005 for OPIE by  doxygen 1.4.2