00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef AIPARSERBASE_H
00021 #define AIPARSERBASE_H
00022
00023 #include "ailexer.h"
00024
00025 #include <qstring.h>
00026 #include <qvaluestack.h>
00027 #include <qvaluevector.h>
00028 #include <qvaluelist.h>
00029
00030 #include "aielement.h"
00031 #include "aicolor.h"
00032
00033
00034 const void arraytoa (const QValueVector<AIElement> &data);
00035 const void elementtoa (const AIElement &data);
00036 const void stacktoa (const QValueStack<AIElement> &data);
00037 const void stacktoa2 (const QValueStack<QValueVector<AIElement> >&data);
00038
00039 class GStateHandlerBase;
00040 class StructureHandlerBase;
00041 class PathHandlerBase;
00042 class MiscGStateHandlerBase;
00043 class DocumentHandlerBase;
00044 class ModuleHandlerBase;
00045 class EmbeddedHandlerBase;
00046 class TextHandlerBase;
00047 class AI88Handler;
00048 class AI3Handler;
00049
00054 typedef enum { PET_MoveTo, PET_LineTo, PET_CurveTo, PET_CurveToOmitC1, PET_CurveToOmitC2 } PathElementType;
00055 typedef enum { PT_Smooth, PT_Corner } PointType;
00056 typedef enum { TO_FillStroke, TO_Fill, TO_Append, TO_Ignore, TO_Stroke } TextOperation;
00057 typedef enum { FM_NonZero=0, FM_EvenOdd=1 } FillMode;
00058 typedef enum { FS_Roman, FS_Kanji } FontScript;
00059
00060 typedef enum { DS_Array, DS_Block, DS_Other } DataSink;
00061 typedef enum { ST_Setup, ST_Prolog, ST_ProcSet, ST_Encoding, ST_Pattern, ST_Document, ST_BrushPattern, ST_Gradient, ST_Palette, ST_Resource } SectionType;
00062
00063 typedef enum { TA_HLeft, TA_HCenter, TA_HRight, TA_VTop, TA_VCenter, TA_VBottom } TextAlign;
00064
00065 #define PC_Cyan 0x0001
00066 #define PC_Magenta 0x0002
00067 #define PC_Yellow 0x0004
00068 #define PC_Black 0x0008
00069
00070 typedef enum {
00071
00072 AIO_SetFillColorCMYK, AIO_SetStrokeColorCMYK,
00073 AIO_SetFillColorGray, AIO_SetStrokeColorGray,
00074 AIO_SetFillColorCustom, AIO_SetStrokeColorCustom,
00075 AIO_SetFillPattern, AIO_SetStrokePattern,
00076 AIO_SetFillOverprinting, AIO_SetStrokeOverprinting,
00077 AIO_SetFlatness, AIO_SetLineCap, AIO_SetLineJoin,
00078 AIO_SetLineWidth, AIO_SetMiterLimit, AIO_SetDash,
00079 AIO_BeginGroupClip, AIO_EndGroupClip,
00080 AIO_MoveTo,
00081 AIO_LineToCorner,
00082 AIO_LineToSmooth,
00083 AIO_CurveToSmooth,
00084 AIO_CurveToCorner,
00085 AIO_CurveToOmitC1Smooth,
00086 AIO_CurveToOmitC1Corner,
00087 AIO_CurveToOmitC2Smooth,
00088 AIO_CurveToOmitC2Corner,
00089
00090 AIO_PathIgnoreNoReset, AIO_PathIgnoreNoResetClose,
00091 AIO_PathClipPath,
00092 AIO_PathIgnoreReset, AIO_PathIgnoreResetClose,
00093 AIO_PathFillNonZero, AIO_PathFillNonZeroClose,
00094 AIO_PathStroke, AIO_PathStrokeClose,
00095 AIO_PathFillNoReset, AIO_PathFillNoResetClose,
00096
00097 AIO_FontEncoding,
00098 AIO_PatternDefinition,
00099
00100 AIO_SetCurrentText,
00101 AIO_TextBlockFillStroke,
00102 AIO_TextBlockFill,
00103 AIO_TextBlockAppend,
00104 AIO_TextBlockIgnore,
00105 AIO_TextBlockStroke,
00106 AIO_TextOutput,
00107 AIO_TextBlockEnd,
00108
00109 AIO_GsaveIncludeDocument,
00110 AIO_Grestore,
00111
00112 AIO_LockElement,
00113
00114
00115 AIO_SetWindingOrder,
00116 AIO_SetFillMode,
00117
00118 AIO_BeginGroupNoClip, AIO_EndGroupNoClip,
00119 AIO_BeginCombination, AIO_EndCombination,
00120
00121 AIO_Other
00122 } AIOperation;
00123
00124 typedef enum {
00125 PSO_Get,
00126 PSO_Exec,
00127 PSO_Def,
00128 PSO_String,
00129 PSO_Bind,
00130 PSO_Userdict,
00131 PSO_Dict,
00132 PSO_Dup,
00133 PSO_Begin,
00134 PSO_Put,
00135 PSO_Other
00136 } PSOperation;
00137
00138 typedef enum {
00139 CU_BlackWhite,
00140 CU_Color,
00141 CU_Unknown
00142 } ColorUsage;
00143
00144 typedef enum {
00145 CO_BeginSetup, CO_EndSetup,
00146 CO_BeginProlog, CO_EndProlog,
00147 CO_BeginProcSet, CO_EndProcSet,
00148 CO_BeginEncoding, CO_EndEncoding,
00149 CO_BeginPattern, CO_EndPattern,
00150 CO_IncludeFile,
00151 CO_BeginDocument, CO_EndDocument,
00152
00153 CO_Trailer,
00154 CO_BoundingBox,
00155 CO_TemplateBox,
00156 CO_Margin,
00157 CO_Title,
00158 CO_Creator,
00159 CO_Other,
00160 CO_For,
00161 CO_CreationDate,
00162 CO_DocumentFonts,
00163 CO_DocumentFiles,
00164 CO_ColorUsage,
00165 CO_DocumentProcSets,
00166 CO_DocumentSuppliedProcSets,
00167 CO_DocumentProcessColors,
00168 CO_DocumentCustomColors,
00169 CO_CMYKCustomColor,
00170 CO_TileBox,
00171 CO_Continuation,
00172 CO_Note,
00173
00174
00175 CO_Template,
00176 CO_PageOrigin,
00177 CO_PrinterName,
00178 CO_PrinterRect,
00179
00180
00181 CO_BeginBrushPattern, CO_EndBrushPattern,
00182 CO_BeginGradient, CO_EndGradient,
00183 CO_BeginPalette, CO_EndPalette,
00184
00185
00186 CO_BeginResource, CO_EndResource,
00187 CO_IncludeFont,
00188 CO_IncludeResource,
00189 CO_DocumentNeededResources,
00190
00191 CO_Ignore
00192 } CommentOperation;
00193
00194 typedef enum {
00195 CM_DocumentFonts = 1,
00196 CM_DocumentFiles = 2,
00197 CM_DocumentCustomColors = 3,
00198 CM_CMYKCustomColor = 4,
00199 CM_DocumentNeededResources = 5,
00200 CM_None = -1
00201 } ContinuationMode;
00202
00203 typedef enum {
00204 PDO_ColorDefinition,
00205 PDO_TileDefinition
00206 } PatternDefinitionOperation;
00207
00208
00209 #define PatternTileFilledDefiniton "_"
00210 #define TextSizeUnknown -1
00211
00212
00213
00214
00215
00216 typedef struct {
00217 PathElementType petype;
00218 union {
00219 struct {
00220 float x, y;
00221 } pointdata;
00222 struct {
00223 float x1, y1, x2, y2, x3, y3;
00224 } bezierdata;
00225 } pevalue;
00226 PointType pttype;
00227 } PathElement;
00228
00229 class AIParserBase : protected AILexer {
00230 friend class AI88Handler;
00231 friend class AI3Handler;
00232
00233 protected:
00234 bool m_debug;
00235 private:
00236 bool m_ignoring;
00237 QValueStack<AIElement> m_stack;
00238 QValueStack<QValueVector<AIElement> > m_arrayStack;
00239 QValueStack<QValueVector<AIElement> > m_blockStack;
00240 DataSink m_sink;
00241 QValueList<QString> m_modules;
00242 ContinuationMode m_continuationMode;
00243
00244 const double getDoubleValue(void);
00245 const int getIntValue(void);
00246 const bool getBoolValue(void);
00247 const QString getStringValue(void);
00248 const QString& getReferenceValue(void);
00249 const QString getOperatorValue(void);
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 void _handlePSGet();
00266 void _handlePSExec();
00267 void _handlePSDef();
00268 void _handlePSString();
00269 void _handlePSBind();
00270 void _handlePSUserdict();
00271 void _handlePSDict();
00272 void _handlePSDup();
00273 void _handlePSBegin();
00274 void _handlePSPut();
00275
00276 void _handleDocumentFonts(const char *data);
00277 void _handleDocumentFiles(const char *data);
00278 void _handleDocumentCustomColors(const char *data);
00279 void _handleCMYKCustomColor(const char *data);
00280 void _handleDocumentProcessColors(const char *data);
00281 void _handleDocumentNeededResources(const char *data);
00282 void _handleIncludeResource(const char *data);
00283
00284
00285
00286
00287
00288 void _handleCreationDate (const char *data);
00289
00290 AIOperation getAIOperation (const char *operand);
00291 PSOperation getPSOperation (const char *operand);
00292 CommentOperation getCommentOperation (const char *command);
00293
00294 bool handlePS (const char *operand);
00295
00296 const char *getValue (const char *input);
00297 bool getRectangle (const char* input, int &llx, int &lly, int &urx, int &ury);
00298 bool getPoint (const char* input, int &x, int &y);
00299 protected:
00300 void gotComment (const char *value);
00301 void gotIntValue (int value);
00302 void gotDoubleValue (double value);
00303 void gotStringValue (const char *value);
00304 void gotToken (const char *value);
00305 void gotReference (const char *value);
00306 void gotBlockStart ();
00307 void gotBlockEnd ();
00308 void gotArrayStart ();
00309 void gotArrayEnd ();
00310 void gotByte (uchar value);
00311 void gotByteArray (const QByteArray &data);
00312
00313 GStateHandlerBase *m_gstateHandler;
00314 StructureHandlerBase *m_structureHandler;
00315 PathHandlerBase *m_pathHandler;
00316 MiscGStateHandlerBase *m_miscGStateHandler;
00317 DocumentHandlerBase *m_documentHandler;
00318 ModuleHandlerBase *m_moduleHandler;
00319 EmbeddedHandlerBase *m_embeddedHandler;
00320 TextHandlerBase *m_textHandler;
00321 AI88Handler *m_ai88Handler;
00322 AI3Handler *m_ai3Handler;
00323
00324 private:
00325 void handleElement (AIElement &element);
00326 void cleanupArrays();
00327 public:
00328 AIParserBase();
00329 ~AIParserBase();
00330
00331 bool parse (QIODevice& fin);
00332 };
00333
00334 const void aiotoa (AIOperation &data);
00335 const void sttoa (SectionType &data, bool begin);
00336
00337 class GStateHandlerBase
00338 {
00339 public:
00340 GStateHandlerBase() {}
00341 virtual ~GStateHandlerBase() {}
00342
00343 virtual void gotFillColor (AIColor &) {}
00344 virtual void gotStrokeColor (AIColor &) {}
00345 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 QValueVector<AIElement>& transformData);
00346 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 QValueVector<AIElement>& transformData);
00347 virtual void gotFlatness (double) {}
00348 virtual void gotLineWidth (double) {}
00349 virtual void gotLineCaps (int) {}
00350 virtual void gotLineJoin (int) {}
00351 virtual void gotMiterLimit (double) {}
00352 virtual void gotWindingOrder (int) {}
00353 virtual void gotDash (const QValueVector<AIElement>& , double ) {}
00354 };
00355
00356 class StructureHandlerBase {
00357 public:
00358 StructureHandlerBase() {}
00359 virtual ~StructureHandlerBase() {}
00360
00361 virtual void gotBeginGroup (bool ) {}
00362 virtual void gotEndGroup (bool ) {}
00363 virtual void gotBeginCombination () {}
00364 virtual void gotEndCombination () {}
00365 };
00366
00367 class PathHandlerBase {
00368 public:
00369 PathHandlerBase() {}
00370 virtual ~PathHandlerBase() {}
00371
00372 virtual void gotPathElement (PathElement &) {}
00373 virtual void gotFillPath (bool , bool ) {}
00374 virtual void gotStrokePath (bool ) {}
00375 virtual void gotIgnorePath (bool , bool ) {}
00376 virtual void gotClipPath (bool ) {}
00377 virtual void gotFillMode (FillMode) {}
00378 };
00379
00380 class MiscGStateHandlerBase {
00381 public:
00382 MiscGStateHandlerBase() {}
00383 virtual ~MiscGStateHandlerBase() {}
00384
00385 virtual void gotLockNextObject (bool ) {}
00386 virtual void gotFillOverprinting (bool ) {}
00387 virtual void gotStrokeOverprinting (bool ) {}
00388 };
00389
00390 class DocumentHandlerBase {
00391 public:
00392 DocumentHandlerBase() {}
00393 virtual ~DocumentHandlerBase() {}
00394
00395 virtual void gotBoundingBox (int , int , int , int ) {}
00396 virtual void gotTemplateBox (int , int , int , int ) {}
00397 virtual void gotMargin (int , int , int , int ) {}
00398 virtual void gotPrinterRect (int , int , int , int ) {}
00399 virtual void gotPrinterName (const char *) {}
00400 virtual void gotPageOrigin (int , int ) {}
00401 virtual void gotTemplate (const char *) {}
00402 virtual void gotTitle (const char *) {}
00403 virtual void gotCreator (const char *) {}
00404 virtual void gotPatternDefinition (const char *, const QValueVector<AIElement>& , double , double , double , double ) {}
00405 virtual void gotCreationDate (const char *,const char *) {}
00406 virtual void gotProcessColors (int ) {}
00407 };
00408
00409 class ModuleHandlerBase {
00410 public:
00411 ModuleHandlerBase() {}
00412 virtual ~ModuleHandlerBase() {}
00413
00414 virtual void gotBeginSection (SectionType, const char *) {}
00415 virtual void gotEndSection (SectionType, const char *) {}
00416 };
00417
00418 class EmbeddedHandlerBase {
00419 public:
00420 EmbeddedHandlerBase() {}
00421 virtual ~EmbeddedHandlerBase() {}
00422
00423 virtual void gotGsaveIncludeDocument (const QValueVector<AIElement>& , int , int , int , int , const char*) {}
00424 virtual void gotGrestore () {}
00425 };
00426
00427 class TextHandlerBase {
00428 public:
00429 TextHandlerBase() {}
00430 virtual ~TextHandlerBase() {}
00431
00432 virtual void gotFontEncoding (const QValueVector<AIElement>& encodingData, const char*oldFontName, const char*newFontName);
00433 virtual void gotFontDefinition (const char*fontName, double size, double leading, double kerning, TextAlign align);
00434 virtual void gotTextBlockBegin (const QValueVector<AIElement>& transData, TextOperation mode);
00435 virtual void gotTextOutput (const char*text, int length=-1);
00436 virtual void gotTextBlockEnd ();
00437 };
00438
00439 #endif
00440