filters

pscommentlexer.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, Dirk Schönberger <dirk.schoenberger@sz-online.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef PSCOMMENTLEXER_H
00021 #define PSCOMMENTLEXER_H
00022 
00023 #include <qiodevice.h>
00024 #include <qstring.h>
00025 
00029 typedef enum {
00030   State_Comment=0,
00031   State_CommentEncodedChar,
00032   State_Start
00033 } State;
00034 
00035 typedef enum {
00036   Action_Copy=1,
00037   Action_CopyOutput,
00038   Action_Output,
00039   Action_Ignore,
00040   Action_Abort,
00041   Action_OutputUnget,
00042   Action_InitTemp,
00043   Action_CopyTemp,
00044   Action_DecodeUnget,
00045   Action_ByteArraySpecial
00046 } Action;
00047 
00048 class StringBuffer {
00049 public:
00050   StringBuffer ();
00051   virtual ~StringBuffer ();
00052 
00053   void append (char c);
00054   void clear();
00055   QString toString() const;
00056   uint length();
00057   double toFloat();
00058   int toInt();
00059   const char *latin1();
00060   QString mid( uint index, uint len=0xffffffff) const;
00061 private:
00062   char *m_buffer;
00063   uint m_length;
00064   int m_capacity;
00065 
00066   void ensureCapacity (int p_capacity);
00067 };
00068 
00069 class PSCommentLexer {
00070 public:
00071     PSCommentLexer();
00072     virtual ~PSCommentLexer();
00073 
00074   virtual bool parse (QIODevice& fin);
00075 private:
00076   State m_curState;
00077   StringBuffer m_buffer;
00078   StringBuffer m_temp;
00079 
00080   void nextStep (char c, State* newState, Action* newAction);
00081 
00082   void doOutput ();
00083   uchar decode();
00084 
00085 protected:
00086   virtual void parsingStarted();
00087   virtual void parsingFinished();
00088   virtual void parsingAborted();
00089 
00090   virtual void gotComment (const char *value);
00091 };
00092 
00093 class BoundingBoxExtractor : public PSCommentLexer
00094 {
00095 public:
00096     BoundingBoxExtractor();
00097     virtual ~BoundingBoxExtractor();
00098 
00099   int llx() { return m_llx; }
00100   int lly() { return m_lly; }
00101   int urx() { return m_urx; }
00102   int ury() { return m_ury; }
00103 private:
00104   int m_llx, m_lly, m_urx, m_ury;
00105   bool getRectangle (const char* input, int &llx, int &lly, int &urx, int &ury);
00106 
00107 protected:
00108   void gotComment (const char *value);
00109 };
00110 
00111 #endif
00112 
KDE Home | KDE Accessibility Home | Description of Access Keys