filters
pscommentlexer.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
|