filters

pscommentlexer.h
1/* This file is part of the KDE project
2 Copyright (C) 2002, Dirk Schönberger <dirk.schoenberger@sz-online.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef PSCOMMENTLEXER_H
21#define PSCOMMENTLEXER_H
22
23#include <tqiodevice.h>
24#include <tqstring.h>
25
29typedef enum {
30 State_Comment=0,
31 State_CommentEncodedChar,
32 State_Start
33} State;
34
35typedef enum {
36 Action_Copy=1,
37 Action_CopyOutput,
38 Action_Output,
39 Action_Ignore,
40 Action_Abort,
41 Action_OutputUnget,
42 Action_InitTemp,
43 Action_CopyTemp,
44 Action_DecodeUnget,
45 Action_ByteArraySpecial
46} Action;
47
48class StringBuffer {
49public:
50 StringBuffer ();
51 virtual ~StringBuffer ();
52
53 void append (char c);
54 void clear();
55 TQString toString() const;
56 uint length();
57 double toFloat();
58 int toInt();
59 const char *latin1();
60 TQString mid( uint index, uint len=0xffffffff) const;
61private:
62 char *m_buffer;
63 uint m_length;
64 int m_capacity;
65
66 void ensureCapacity (int p_capacity);
67};
68
69class PSCommentLexer {
70public:
71 PSCommentLexer();
72 virtual ~PSCommentLexer();
73
74 virtual bool parse (TQIODevice& fin);
75private:
76 State m_curState;
77 StringBuffer m_buffer;
78 StringBuffer m_temp;
79
80 void nextStep (char c, State* newState, Action* newAction);
81
82 void doOutput ();
83 uchar decode();
84
85protected:
86 virtual void parsingStarted();
87 virtual void parsingFinished();
88 virtual void parsingAborted();
89
90 virtual void gotComment (const char *value);
91};
92
93class BoundingBoxExtractor : public PSCommentLexer
94{
95public:
96 BoundingBoxExtractor();
97 virtual ~BoundingBoxExtractor();
98
99 int llx() { return m_llx; }
100 int lly() { return m_lly; }
101 int urx() { return m_urx; }
102 int ury() { return m_ury; }
103private:
104 int m_llx, m_lly, m_urx, m_ury;
105 bool getRectangle (const char* input, int &llx, int &lly, int &urx, int &ury);
106
107protected:
108 void gotComment (const char *value);
109};
110
111#endif
112