filters

karbonaiparserbase.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 KARBONAIPARSERBASE_H
21#define KARBONAIPARSERBASE_H
22
23#include <aiparserbase.h>
24#include <tqptrlist.h>
25#include <tqstring.h>
26#include <tqpair.h>
27
28#include "aicolor.h"
29
30#include <KoPoint.h>
31#include <core/vcomposite.h>
32#include <core/vdocument.h>
33#include <core/vlayer.h>
34#include <core/vgroup.h>
35#include <core/vfill.h>
36#include <core/vstroke.h>
37#include <tqdom.h>
38
39#include <tqptrstack.h>
40
44typedef TQPair<TQString,TQString> Parameter;
45typedef TQPtrList<Parameter> Parameters;
46typedef TQPtrList<PathElement> PathElements;
47
48typedef enum { POT_Filled = 1, POT_Stroked = 2, POT_FilledStroked = 3, POT_Clip = 4, POT_Ignore = 8, POT_Leave = -1, POT_Other = 0 } PathOutputType;
49typedef enum { PTT_Output = 1, PTT_Combine = 2 } PathTransferType;
50
51// typedef struct { int llx, lly, urx, ury; } BoundingBox;
52
53class KarbonAIParserBase;
54class KarbonGStateHandler;
55class KarbonStructureHandler;
56class KarbonPathHandler;
57class KarbonDocumentHandler;
58
59class KarbonDocumentHandler : public DocumentHandlerBase
60{
61 private:
62 KarbonAIParserBase *delegate;
63 public:
64 KarbonDocumentHandler (KarbonAIParserBase *delegate) : DocumentHandlerBase () { this->delegate = delegate; }
65
66 void gotBoundingBox (int llx, int lly, int urx, int ury);
67 void gotCreationDate (const char *val1,const char *val2);
68 void gotProcessColors (int colors);
69};
70
71class KarbonGStateHandler : public GStateHandlerBase
72{
73 private:
74 KarbonAIParserBase *delegate;
75 public:
76 KarbonGStateHandler (KarbonAIParserBase *delegate) : GStateHandlerBase() { this->delegate = delegate; }
77
78 void gotFillColor (AIColor &color);
79 void gotStrokeColor (AIColor &color);
80
81 void gotFlatness (double val);
82 void gotLineWidth (double val);
83 void gotLineCaps (int val);
84 void gotLineJoin (int val);
85 void gotMiterLimit (double val);
86 void gotWindingOrder (int val);
87
88};
89
90class KarbonStructureHandler : public StructureHandlerBase
91{
92 private:
93 KarbonAIParserBase *delegate;
94 public:
95 KarbonStructureHandler (KarbonAIParserBase *delegate) : StructureHandlerBase() { this->delegate = delegate; }
96
97 void gotBeginGroup (bool clipping);
98 void gotEndGroup (bool clipping);
99 void gotBeginCombination ();
100 void gotEndCombination ();
101
102};
103
104class KarbonPathHandler : public PathHandlerBase
105{
106 private:
107 KarbonAIParserBase *delegate;
108 FillMode m_fm;
109 public:
110 KarbonPathHandler (KarbonAIParserBase *delegate) : PathHandlerBase ()
111 {
112 m_fm = FM_EvenOdd;
113 this->delegate = delegate;
114 }
115
116 void gotPathElement (PathElement &element);
117 void gotFillPath (bool closed, bool reset);
118 void gotStrokePath (bool closed);
119 void gotIgnorePath (bool closed, bool reset);
120 void gotClipPath (bool closed);
121 void gotFillMode (FillMode fm);
122
123};
124
125class KarbonAIParserBase : public AIParserBase {
126 friend class KarbonDocumentHandler;
127 friend class KarbonGStateHandler;
128 friend class KarbonStructureHandler;
129 friend class KarbonPathHandler;
130
131public:
132 KarbonAIParserBase();
133 ~KarbonAIParserBase();
134
135 bool parse (TQIODevice& fin, TQDomDocument &doc);
136private:
137 VPath *m_curKarbonPath;
138 VDocument *m_document;
139 VLayer *m_layer;
140 VPath *m_combination;
141 TQPtrStack<VGroup> m_groupStack;
142
143 FillMode m_fm;
144 PathOutputType m_pot;
145 PathTransferType m_ptt;
146
147// BoundingBox m_bbox;
148 KoRect m_bbox;
149 VFill m_fill;
150 VStroke m_stroke;
158 int m_windingOrder;
159
160 void doOutputCurrentPath2(PathOutputType type);
161 const VColor toKarbonColor (const AIColor &color);
162 void ensureLayer ();
163
164 VFill m_emptyFill;
165 VStroke m_emptyStroke;
166
167protected:
168 void setupHandlers();
169 void teardownHandlers();
170
171 void parsingStarted();
172 void parsingFinished();
173
174 TQString getParamList(Parameters& params);
175
176 void gotPathElement (PathElement &element);
177 void gotFillPath (bool closed, bool reset, FillMode fm = FM_NonZero);
178 void gotStrokePath (bool closed);
179 void gotIgnorePath (bool closed, bool reset);
180 void gotClipPath (bool closed);
181
182 void gotFillColor (AIColor &color);
183 void gotStrokeColor (AIColor &color);
184 void gotBoundingBox (int llx, int lly, int urx, int ury);
185
186 void gotFlatness (double val);
187 void gotLineWidth (double val);
188 void gotLineCaps (int val);
189 void gotLineJoin (int val);
190 void gotMiterLimit (double val);
191 void gotWindingOrder (int val);
192 void gotBeginGroup (bool clipping);
193 void gotEndGroup (bool clipping);
194 void gotBeginCombination ();
195 void gotEndCombination ();
196
197 virtual void gotStartTag (const char *tagName, Parameters& params);
198 virtual void gotEndTag (const char *tagName);
199 virtual void gotSimpleTag (const char *tagName, Parameters& params);
200};
201
202#endif