filters

aiparserbase.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 AIPARSERBASE_H
21#define AIPARSERBASE_H
22
23#include "ailexer.h"
24
25#include <tqstring.h>
26#include <tqvaluestack.h>
27#include <tqvaluevector.h>
28#include <tqvaluelist.h>
29
30#include "aielement.h"
31#include "aicolor.h"
32
33
34const void arraytoa (const TQValueVector<AIElement> &data);
35const void elementtoa (const AIElement &data);
36const void stacktoa (const TQValueStack<AIElement> &data);
37const void stacktoa2 (const TQValueStack<TQValueVector<AIElement> >&data);
38
39class GStateHandlerBase;
40class StructureHandlerBase;
41class PathHandlerBase;
42class MiscGStateHandlerBase;
43class DocumentHandlerBase;
44class ModuleHandlerBase;
45class EmbeddedHandlerBase;
46class TextHandlerBase;
47class AI88Handler;
48class AI3Handler;
49
53
54typedef enum { PET_MoveTo, PET_LineTo, PET_CurveTo, PET_CurveToOmitC1, PET_CurveToOmitC2 } PathElementType;
55typedef enum { PT_Smooth, PT_Corner } PointType;
56typedef enum { TO_FillStroke, TO_Fill, TO_Append, TO_Ignore, TO_Stroke } TextOperation;
57typedef enum { FM_NonZero=0, FM_EvenOdd=1 } FillMode;
58typedef enum { FS_Roman, FS_Kanji } FontScript;
59
60typedef enum { DS_Array, DS_Block, DS_Other } DataSink;
61typedef enum { ST_Setup, ST_Prolog, ST_ProcSet, ST_Encoding, ST_Pattern, ST_Document, ST_BrushPattern, ST_Gradient, ST_Palette, ST_Resource } SectionType;
62
63typedef enum { TA_HLeft, TA_HCenter, TA_HRight, TA_VTop, TA_VCenter, TA_VBottom } TextAlign;
64
65#define PC_Cyan 0x0001
66#define PC_Magenta 0x0002
67#define PC_Yellow 0x0004
68#define PC_Black 0x0008
69
70typedef enum {
71 /* AI 88 */
72 AIO_SetFillColorCMYK, AIO_SetStrokeColorCMYK,
73 AIO_SetFillColorGray, AIO_SetStrokeColorGray,
74 AIO_SetFillColorCustom, AIO_SetStrokeColorCustom,
75 AIO_SetFillPattern, AIO_SetStrokePattern,
76 AIO_SetFillOverprinting, AIO_SetStrokeOverprinting,
77 AIO_SetFlatness, AIO_SetLineCap, AIO_SetLineJoin,
78 AIO_SetLineWidth, AIO_SetMiterLimit, AIO_SetDash,
79 AIO_BeginGroupClip, AIO_EndGroupClip,
80 AIO_MoveTo,
81 AIO_LineToCorner,
82 AIO_LineToSmooth,
83 AIO_CurveToSmooth,
84 AIO_CurveToCorner,
85 AIO_CurveToOmitC1Smooth,
86 AIO_CurveToOmitC1Corner,
87 AIO_CurveToOmitC2Smooth,
88 AIO_CurveToOmitC2Corner,
89
90 AIO_PathIgnoreNoReset, AIO_PathIgnoreNoResetClose,
91 AIO_PathClipPath,
92 AIO_PathIgnoreReset, AIO_PathIgnoreResetClose,
93 AIO_PathFillNonZero, AIO_PathFillNonZeroClose,
94 AIO_PathStroke, AIO_PathStrokeClose,
95 AIO_PathFillNoReset, AIO_PathFillNoResetClose,
96
97 AIO_FontEncoding,
98 AIO_PatternDefinition,
99
100 AIO_SetCurrentText,
101 AIO_TextBlockFillStroke,
102 AIO_TextBlockFill,
103 AIO_TextBlockAppend,
104 AIO_TextBlockIgnore,
105 AIO_TextBlockStroke,
106 AIO_TextOutput,
107 AIO_TextBlockEnd,
108
109 AIO_GsaveIncludeDocument,
110 AIO_Grestore,
111
112 AIO_LockElement,
113
114 /* AI 3 */
115 AIO_SetWindingOrder,
116 AIO_SetFillMode,
117
118 AIO_BeginGroupNoClip, AIO_EndGroupNoClip,
119 AIO_BeginCombination, AIO_EndCombination,
120
121 AIO_Other
122} AIOperation;
123
124typedef enum {
125 PSO_Get,
126 PSO_Exec,
127 PSO_Def,
128 PSO_String,
129 PSO_Bind,
130 PSO_Userdict,
131 PSO_Dict,
132 PSO_Dup,
133 PSO_Begin,
134 PSO_Put,
135 PSO_Other
136} PSOperation;
137
138typedef enum {
139 CU_BlackWhite,
140 CU_Color,
141 CU_Unknown
142} ColorUsage;
143
144typedef enum {
145 CO_BeginSetup, CO_EndSetup,
146 CO_BeginProlog, CO_EndProlog,
147 CO_BeginProcSet, CO_EndProcSet,
148 CO_BeginEncoding, CO_EndEncoding,
149 CO_BeginPattern, CO_EndPattern,
150 CO_IncludeFile,
151 CO_BeginDocument, CO_EndDocument,
152
153 CO_Trailer,
154 CO_BoundingBox,
155 CO_TemplateBox,
156 CO_Margin,
157 CO_Title,
158 CO_Creator,
159 CO_Other,
160/**/ CO_For,
161 CO_CreationDate,
162/**/ CO_DocumentFonts,
163/**/ CO_DocumentFiles,
164/**/ CO_ColorUsage,
165/**/ CO_DocumentProcSets,
166/**/ CO_DocumentSuppliedProcSets,
167 CO_DocumentProcessColors,
168/**/ CO_DocumentCustomColors,
169/**/ CO_CMYKCustomColor,
170/**/ CO_TileBox,
171 CO_Continuation,
172/**/ CO_Note,
173
174 // AI88 Win
175/**/ CO_Template,
176/**/ CO_PageOrigin,
177/**/ CO_PrinterName,
178/**/ CO_PrinterRect,
179
180 // AI8
181 CO_BeginBrushPattern, CO_EndBrushPattern,
182 CO_BeginGradient, CO_EndGradient,
183 CO_BeginPalette, CO_EndPalette,
184
185 // other
186 CO_BeginResource, CO_EndResource,
187 CO_IncludeFont,
188 CO_IncludeResource,
189 CO_DocumentNeededResources,
190
191 CO_Ignore
192} CommentOperation;
193
194typedef enum {
195 CM_DocumentFonts = 1,
196 CM_DocumentFiles = 2,
197 CM_DocumentCustomColors = 3,
198 CM_CMYKCustomColor = 4,
199 CM_DocumentNeededResources = 5,
200 CM_None = -1
201} ContinuationMode;
202
203typedef enum {
204/**/ PDO_ColorDefinition,
205/**/ PDO_TileDefinition
206} PatternDefinitionOperation;
207
208/**/
209#define PatternTileFilledDefiniton "_"
210#define TextSizeUnknown -1
211
212/* typedef TQValueVector<AElement> ElementArray;
213typedef TQValueStack<AIElement> ElementStack;
214typedef TQValueStack<ElementArray> ElementArrayStack; */
215
216typedef struct {
217 PathElementType petype;
218 union {
219 struct {
220 float x, y;
221 } pointdata;
222 struct {
223 float x1, y1, x2, y2, x3, y3;
224 } bezierdata;
225 } pevalue;
226 PointType pttype;
227} PathElement;
228
229class AIParserBase : protected AILexer {
230 friend class AI88Handler;
231 friend class AI3Handler;
232
233protected:
234 bool m_debug;
235private:
236 bool m_ignoring;
237 TQValueStack<AIElement> m_stack;
238 TQValueStack<TQValueVector<AIElement> > m_arrayStack;
239 TQValueStack<TQValueVector<AIElement> > m_blockStack;
240 DataSink m_sink;
241 TQValueList<TQString> m_modules;
242 ContinuationMode m_continuationMode;
243
244 const double getDoubleValue(void);
245 const int getIntValue(void);
246 const bool getBoolValue(void);
247 const TQString getStringValue(void);
248 const TQString& getReferenceValue(void);
249 const TQString getOperatorValue(void);
250
251/*Ai88*/ // void _handleSetDash();
252/*Ai88*/ // void _handleGsaveIncludeDocument();
253/*Ai88*/ // void _handleSetStrokeColorCMYK();
254/*Ai88*/ // void _handleSetFillColorCMYK();
255/*Ai88*/ // void _handleSetStrokeColorGray();
256/*Ai88*/ // void _handleSetFillColorGray();
257/*Ai88*/ // void _handleSetStrokeColorCustom();
258/*Ai88*/ // void _handleSetFillColorCustom();
259/*Ai88*/ // void _handleSetFillPattern();
260/*Ai88*/ // void _handleSetStrokePattern();
261
262/*Ai88*/ // void _handlePatternDefinition();
263/*Ai88*/ // void _handleFontEncoding();
264
265 void _handlePSGet();
266 void _handlePSExec();
267 void _handlePSDef();
268 void _handlePSString();
269 void _handlePSBind();
270 void _handlePSUserdict();
271 void _handlePSDict();
272 void _handlePSDup();
273 void _handlePSBegin();
274 void _handlePSPut();
275
276 void _handleDocumentFonts(const char *data);
277 void _handleDocumentFiles(const char *data);
278 void _handleDocumentCustomColors(const char *data);
279 void _handleCMYKCustomColor(const char *data);
280 void _handleDocumentProcessColors(const char *data);
281 void _handleDocumentNeededResources(const char *data);
282 void _handleIncludeResource(const char *data);
283
284/*Ai88*/ // void _handleSetCurrentText();
285/*Ai88*/ // void _handleTextBlock (TextOperation to);
286/*Ai88*/ // void _handleTextOutput ();
287
288 void _handleCreationDate (const char *data);
289
290 AIOperation getAIOperation (const char *operand);
291 PSOperation getPSOperation (const char *operand);
292 CommentOperation getCommentOperation (const char *command);
293
294 bool handlePS (const char *operand);
295
296 const char *getValue (const char *input);
297 bool getRectangle (const char* input, int &llx, int &lly, int &urx, int &ury);
298 bool getPoint (const char* input, int &x, int &y);
299protected:
300 void gotComment (const char *value);
301 void gotIntValue (int value);
302 void gotDoubleValue (double value);
303 void gotStringValue (const char *value);
304 void gotToken (const char *value);
305 void gotReference (const char *value);
306 void gotBlockStart ();
307 void gotBlockEnd ();
308 void gotArrayStart ();
309 void gotArrayEnd ();
310 void gotByte (uchar value);
311 void gotByteArray (const TQByteArray &data);
312
313 GStateHandlerBase *m_gstateHandler;
314 StructureHandlerBase *m_structureHandler;
315 PathHandlerBase *m_pathHandler;
316 MiscGStateHandlerBase *m_miscGStateHandler;
317 DocumentHandlerBase *m_documentHandler;
318 ModuleHandlerBase *m_moduleHandler;
319 EmbeddedHandlerBase *m_embeddedHandler;
320 TextHandlerBase *m_textHandler;
321 AI88Handler *m_ai88Handler;
322 AI3Handler *m_ai3Handler;
323
324private:
325 void handleElement (AIElement &element);
326 void cleanupArrays();
327public:
328 AIParserBase();
329 ~AIParserBase();
330
331 bool parse (TQIODevice& fin);
332};
333
334const void aiotoa (AIOperation &data);
335const void sttoa (SectionType &data, bool begin);
336
337class GStateHandlerBase
338{
339 public:
340 GStateHandlerBase() {}
341 virtual ~GStateHandlerBase() {}
342
343 virtual void gotFillColor (AIColor &) {}
344 virtual void gotStrokeColor (AIColor &) {}
345 virtual void gotFillPattern (const char *pname, double px, double py, double sx, double sy, double angle, double rf, double r, double k, double ka, const TQValueVector<AIElement>& transformData);
346 virtual void gotStrokePattern (const char *pname, double px, double py, double sx, double sy, double angle, double rf, double r, double k, double ka, const TQValueVector<AIElement>& transformData);
347 virtual void gotFlatness (double) {}
348 virtual void gotLineWidth (double) {}
349 virtual void gotLineCaps (int) {}
350 virtual void gotLineJoin (int) {}
351 virtual void gotMiterLimit (double) {}
352 virtual void gotWindingOrder (int) {}
353 virtual void gotDash (const TQValueVector<AIElement>& /*dashData*/, double /*phase*/) {}
354};
355
356class StructureHandlerBase {
357 public:
358 StructureHandlerBase() {}
359 virtual ~StructureHandlerBase() {}
360
361 virtual void gotBeginGroup (bool /*clipping*/) {}
362 virtual void gotEndGroup (bool /*clipping*/) {}
363 virtual void gotBeginCombination () {}
364 virtual void gotEndCombination () {}
365};
366
367class PathHandlerBase {
368 public:
369 PathHandlerBase() {}
370 virtual ~PathHandlerBase() {}
371
372 virtual void gotPathElement (PathElement &) {}
373 virtual void gotFillPath (bool /*closed*/, bool /*reset*/) {}
374 virtual void gotStrokePath (bool /*closed*/) {}
375 virtual void gotIgnorePath (bool /*closed*/, bool /*reset*/) {}
376 virtual void gotClipPath (bool /*closed*/) {}
377 virtual void gotFillMode (FillMode) {}
378};
379
380class MiscGStateHandlerBase {
381 public:
382 MiscGStateHandlerBase() {}
383 virtual ~MiscGStateHandlerBase() {}
384
385 virtual void gotLockNextObject (bool /*value*/) {}
386 virtual void gotFillOverprinting (bool /*value*/) {}
387 virtual void gotStrokeOverprinting (bool /*value*/) {}
388};
389
390class DocumentHandlerBase {
391 public:
392 DocumentHandlerBase() {}
393 virtual ~DocumentHandlerBase() {}
394
395 virtual void gotBoundingBox (int /*llx*/, int /*lly*/, int /*urx*/, int /*ury*/) {}
396 virtual void gotTemplateBox (int /*llx*/, int /*lly*/, int /*urx*/, int /*ury*/) {}
397 virtual void gotMargin (int /*llx*/, int /*lly*/, int /*urx*/, int /*ury*/) {}
398 virtual void gotPrinterRect (int /*llx*/, int /*lly*/, int /*urx*/, int /*ury*/) {}
399 virtual void gotPrinterName (const char *) {}
400 virtual void gotPageOrigin (int /*x*/, int /*y*/) {}
401 virtual void gotTemplate (const char *) {}
402 virtual void gotTitle (const char *) {}
403 virtual void gotCreator (const char *) {}
404 virtual void gotPatternDefinition (const char */*name*/, const TQValueVector<AIElement>& /*layerData*/, double /*llx*/, double /*lly*/, double /*urx*/, double /*ury*/) {}
405 virtual void gotCreationDate (const char */*val1*/,const char */*val2*/) {}
406 virtual void gotProcessColors (int /*colors*/) {}
407};
408
409class ModuleHandlerBase {
410 public:
411 ModuleHandlerBase() {}
412 virtual ~ModuleHandlerBase() {}
413
414 virtual void gotBeginSection (SectionType, const char *) {}
415 virtual void gotEndSection (SectionType, const char *) {}
416};
417
418class EmbeddedHandlerBase {
419 public:
420 EmbeddedHandlerBase() {}
421 virtual ~EmbeddedHandlerBase() {}
422
423 virtual void gotGsaveIncludeDocument (const TQValueVector<AIElement>& /*transData*/, int /*llx*/, int /*lly*/, int /*urx*/, int /*ury*/, const char*/*fileName*/) {}
424 virtual void gotGrestore () {}
425};
426
427class TextHandlerBase {
428 public:
429 TextHandlerBase() {}
430 virtual ~TextHandlerBase() {}
431
432 virtual void gotFontEncoding (const TQValueVector<AIElement>& encodingData, const char*oldFontName, const char*newFontName);
433 virtual void gotFontDefinition (const char*fontName, double size, double leading, double kerning, TextAlign align);
434 virtual void gotTextBlockBegin (const TQValueVector<AIElement>& transData, TextOperation mode);
435 virtual void gotTextOutput (const char*text, int length=-1);
436 virtual void gotTextBlockEnd ();
437};
438
439#endif
440