filters

aiparserbase.cpp
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#include "aiparserbase.h"
21#include "ai88handler.h"
22#include "ai3handler.h"
23#include <tqregexp.h>
24#include <tqstringlist.h>
25
26typedef struct {
27 char* op;
28 AIOperation action;
29} AIOperationMapping;
30
31typedef struct {
32 char* op;
33 PSOperation action;
34} PSOperationMapping;
35
36typedef struct {
37 char* op;
38 CommentOperation action;
39} CommentOperationMapping;
40
41static AIOperationMapping aiMappings[] = {
42 { "k", AIO_SetFillColorCMYK },
43 { "K", AIO_SetStrokeColorCMYK },
44 { "g", AIO_SetFillColorGray },
45 { "G", AIO_SetStrokeColorGray },
46 { "x", AIO_SetFillColorCustom },
47 { "X", AIO_SetStrokeColorCustom },
48 { "p", AIO_SetFillPattern },
49 { "P", AIO_SetStrokePattern },
50 { "O", AIO_SetFillOverprinting },
51 { "R", AIO_SetStrokeOverprinting },
52 { "i", AIO_SetFlatness },
53 { "J", AIO_SetLineCap },
54 { "j", AIO_SetLineJoin },
55 { "M", AIO_SetMiterLimit },
56 { "w", AIO_SetLineWidth },
57 { "d", AIO_SetDash },
58 { "q", AIO_BeginGroupClip },
59 { "Q", AIO_EndGroupClip },
60 { "m", AIO_MoveTo },
61 { "l", AIO_LineToSmooth },
62 { "L", AIO_LineToCorner },
63 { "c", AIO_CurveToSmooth },
64 { "C", AIO_CurveToCorner },
65
66 { "v", AIO_CurveToOmitC1Smooth },
67 { "V", AIO_CurveToOmitC1Corner },
68 { "y", AIO_CurveToOmitC2Smooth },
69 { "Y", AIO_CurveToOmitC2Corner },
70
71 { "H", AIO_PathIgnoreNoReset },
72 { "h", AIO_PathIgnoreNoResetClose },
73 { "W", AIO_PathClipPath },
74 { "N", AIO_PathIgnoreReset },
75 { "n", AIO_PathIgnoreResetClose },
76 { "F", AIO_PathFillNonZero },
77 { "f", AIO_PathFillNonZeroClose },
78 { "B", AIO_PathFillNoReset },
79 { "b", AIO_PathFillNoResetClose },
80 { "S", AIO_PathStroke },
81 { "s", AIO_PathStrokeClose },
82 { "D", AIO_SetWindingOrder },
83 { "Z", AIO_FontEncoding },
84 { "E", AIO_PatternDefinition },
85 { "A", AIO_LockElement },
86
87 { "z", AIO_SetCurrentText },
88 { "a", AIO_TextBlockFillStroke },
89 { "e", AIO_TextBlockFill },
90 { "I", AIO_TextBlockAppend },
91 { "o", AIO_TextBlockIgnore },
92 { "r", AIO_TextBlockStroke },
93 { "t", AIO_TextOutput },
94 { "T", AIO_TextBlockEnd },
95 { "`", AIO_GsaveIncludeDocument },
96 { "~", AIO_Grestore },
97
98 { "u", AIO_BeginGroupNoClip },
99 { "U", AIO_EndGroupNoClip },
100 { "*u", AIO_BeginCombination },
101 { "*U", AIO_EndCombination },
102
103 { "XR", AIO_SetFillMode },
104
105 { NULL, AIO_Other }
106};
107
108static PSOperationMapping psMappings[] = {
109 { "get", PSO_Get },
110 { "exec", PSO_Exec },
111 { "string", PSO_String },
112 { "bind", PSO_Bind },
113 { "def", PSO_Def },
114 { "userdict", PSO_Userdict },
115 { "dict", PSO_Dict },
116 { "dup", PSO_Dup },
117 { "begin", PSO_Begin },
118 { "put", PSO_Put },
119 { NULL, PSO_Other },
120};
121
122static CommentOperationMapping commentMappings[] = {
123 { "BeginProlog", CO_BeginProlog },
124 { "BeginSetup", CO_BeginSetup },
125 { "BeginProcSet", CO_BeginProcSet },
126 { "BeginResource", CO_BeginResource },
127 { "BeginEncoding", CO_BeginEncoding },
128 { "BeginPattern", CO_BeginPattern },
129 { "BeginDocument", CO_BeginPattern },
130 { "Trailer", CO_Trailer },
131 { "EndProlog", CO_EndProlog },
132 { "EndSetup", CO_EndSetup },
133 { "EndProcSet", CO_EndProcSet },
134 { "EndResource", CO_EndResource },
135 { "EndEncoding", CO_EndEncoding },
136 { "EndPattern", CO_EndPattern },
137 { "EndDocument", CO_EndDocument },
138
139 { "Title", CO_Title },
140 { "Creator", CO_Creator },
141
142 { "EOF", CO_Ignore },
143 { "Note", CO_Ignore },
144 { "EndComments", CO_Ignore },
145 { "PS-Adobe", CO_Ignore },
146
147 { "BoundingBox", CO_BoundingBox },
148 { "TemplateBox", CO_TemplateBox },
149 { "AI3_Margin", CO_Margin },
150
151 { "For", CO_For },
152 { "CreationDate", CO_CreationDate },
153 { "DocumentFonts", CO_DocumentFonts },
154 { "DocumentFiles", CO_DocumentFiles },
155 { "ColorUsage", CO_ColorUsage },
156 { "DocumentProcSets", CO_DocumentProcSets },
157 { "DocumentSuppliedProcSets", CO_DocumentSuppliedProcSets },
158
159 { "DocumentProcessColors", CO_DocumentProcessColors },
160 { "DocumentCustomColors", CO_DocumentCustomColors },
161 { "CMYKCustomColor", CO_CMYKCustomColor },
162 { "TileBox", CO_TileBox },
163 { "%+", CO_Continuation },
164
165 { "Template", CO_Template },
166 { "PageOrigin", CO_PageOrigin },
167 { "PrinterName", CO_PrinterName },
168 { "PrinterRect", CO_PrinterRect },
169 { "Note", CO_Note },
170
171 { "DocumentNeededResources", CO_DocumentNeededResources },
172
173
174 { "IncludeFont", CO_IncludeFont },
175 { "BeginBrushPattern", CO_BeginBrushPattern },
176 { "EndBrushPattern", CO_EndBrushPattern },
177 { "BeginGradient", CO_BeginGradient },
178 { "EndGradient", CO_EndGradient },
179 { "BeginPalette", CO_BeginPalette },
180 { "EndPalette", CO_EndPalette },
181
182 { "IncludeFile", CO_IncludeFile },
183 { "IncludeResource", CO_IncludeResource },
184
185 { NULL, CO_Other }
186};
187
188AIParserBase::AIParserBase() : m_debug(false), m_ignoring(false), m_sink (DS_Other), m_continuationMode(CM_None)
189 {
190 m_gstateHandler = NULL;
191 m_structureHandler = NULL;
192 m_pathHandler = NULL;
193 m_miscGStateHandler = NULL;
194 m_documentHandler = NULL;
195 m_moduleHandler = NULL;
196 m_embeddedHandler = NULL;
197 m_ai88Handler = new AI88Handler(this);
198 m_ai3Handler = new AI3Handler(this);
199}
200
201AIParserBase::~AIParserBase(){
202 delete m_ai88Handler;
203 delete m_ai3Handler;
204
205}
206
207bool AIParserBase::parse (TQIODevice& fin){
208 return AILexer::parse (fin);
209}
210
211void AIParserBase::gotComment (const char *value) {
212 int llx, lly, urx, ury;
213
214 CommentOperation cop = getCommentOperation (value);
215 switch (cop) {
216 case CO_BeginDocument :
217 if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Document, value);
218 break;
219 case CO_EndDocument :
220 if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Document, value);
221 break;
222 case CO_BeginPattern :
223 if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Pattern, value);
224 break;
225 case CO_EndPattern :
226 if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Pattern, value);
227 break;
228 case CO_BeginProlog :
229 if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Prolog, value);
230 break;
231 case CO_BeginProcSet :
232 if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_ProcSet, value);
233 if (m_debug) tqDebug ("start ignoring");
234 m_ignoring = true;
235 break;
236 case CO_BeginResource :
237 if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Resource, value);
238 if (m_debug) tqDebug ("start ignoring");
239 m_ignoring = true;
240 break;
241 case CO_BeginEncoding :
242 if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Encoding, value);
243 m_ignoring = false;
244 break;
245 case CO_IncludeFont :
246 if (m_debug) tqDebug ("start ignoring");
247 m_ignoring = true;
248 break;
249 case CO_BeginBrushPattern :
250 if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_BrushPattern, value);
251 break;
252 case CO_BeginGradient :
253 if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Gradient, value);
254 break;
255 case CO_Trailer :
256 if (m_debug) tqDebug ("start ignoring");
257 m_ignoring = true;
258 break;
259 case CO_BeginPalette :
260 if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Palette, value);
261 break;
262 case CO_BeginSetup :
263 if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Setup, value);
264 break;
265 case CO_EndSetup :
266 cleanupArrays();
267 if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Setup, value);
268 break;
269 case CO_EndProlog :
270 if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Prolog, value);
271 break;
272 case CO_EndProcSet :
273 if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_ProcSet, value);
274 if (m_debug) tqDebug ("stop ignoring");
275 m_ignoring = false;
276 break;
277 case CO_EndResource :
278 if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Resource, value);
279 if (m_debug) tqDebug ("stop ignoring");
280 m_ignoring = false;
281 break;
282 case CO_EndEncoding :
283 cleanupArrays();
284 if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Encoding, value);
285 break;
286 case CO_EndBrushPattern :
287 cleanupArrays();
288 if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_BrushPattern, value);
289 break;
290 case CO_EndGradient :
291 cleanupArrays();
292 if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Gradient, value);
293 break;
294 case CO_EndPalette :
295 cleanupArrays();
296 if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Palette, value);
297 break;
298 case CO_Ignore :
299 break;
300 case CO_BoundingBox :
301 if (getRectangle (value, llx, lly, urx, ury))
302 {
303 if (m_documentHandler) m_documentHandler->gotBoundingBox (llx, lly, urx, ury);
304 }
305 break;
306 case CO_TemplateBox :
307 if (getRectangle (value, llx, lly, urx, ury))
308 {
309 if (m_documentHandler) m_documentHandler->gotTemplateBox (llx, lly, urx, ury);
310 }
311 break;
312 case CO_Margin :
313 if (getRectangle (value, llx, lly, urx, ury))
314 {
315 if (m_documentHandler) m_documentHandler->gotMargin (llx, lly, urx, ury);
316 }
317 break;
318 case CO_Title :
319 if (m_documentHandler) m_documentHandler->gotTitle (getValue (value));
320 break;
321 case CO_Creator :
322 if (m_documentHandler) m_documentHandler->gotCreator (getValue (value));
323 break;
324 case CO_DocumentFonts :
325 _handleDocumentFonts (value);
326 m_continuationMode = CM_DocumentFonts;
327 break;
328 case CO_DocumentFiles :
329 _handleDocumentFiles (value);
330 m_continuationMode = CM_DocumentFiles;
331 break;
332 case CO_DocumentCustomColors :
333 _handleDocumentCustomColors (value);
334 m_continuationMode = CM_DocumentFiles;
335 break;
336 case CO_CMYKCustomColor :
337 _handleCMYKCustomColor (value);
338 m_continuationMode = CM_CMYKCustomColor;
339 break;
340 case CO_DocumentNeededResources :
341 _handleDocumentNeededResources (value);
342 m_continuationMode = CM_DocumentNeededResources;
343 break;
344 case CO_DocumentProcessColors :
345 _handleDocumentProcessColors (value);
346 break;
347 case CO_CreationDate :
348 _handleCreationDate (value);
349 break;
350 case CO_IncludeFile :
351 break;
352 case CO_IncludeResource :
353 _handleIncludeResource (value);
354 break;
355 case CO_Continuation :
356 switch (m_continuationMode) {
357 case CM_DocumentFonts : _handleDocumentFonts (value); break;
358 case CM_DocumentFiles : _handleDocumentFiles (value); break;
359 case CM_DocumentCustomColors : _handleDocumentCustomColors (value); break;
360 case CM_CMYKCustomColor : _handleCMYKCustomColor (value); break;
361 case CM_DocumentNeededResources : _handleDocumentNeededResources (value); break;
362
363 default : tqWarning ("unknown continuation mode %d",m_continuationMode);
364 }
365 break;
366
367 default :
368 tqWarning( "unhandled comment: %s", value );
369 }
370}
371
372void AIParserBase::handleElement (AIElement &element)
373{
374 if (m_ignoring) return;
375
376 if (m_sink == DS_Array)
377 {
378 if (m_debug) tqDebug ("in mode array");
379 TQValueVector<AIElement> &elementArray = m_arrayStack.top();
380 elementArray.push_back(element);
381 }
382 if (m_sink == DS_Block)
383 {
384 if (m_debug) tqDebug ("in mode block");
385 TQValueVector<AIElement> &elementArray = m_blockStack.top();
386 elementArray.push_back(element);
387 }
388 else
389 {
390 if (m_debug) tqDebug ("in mode stack");
391 m_stack.push (element);
392 }
393}
394
395void AIParserBase::gotIntValue (int value) {
396 if (m_debug) tqDebug ("got int value");
397 if (m_ignoring) return;
398 AIElement element (value);
399 handleElement (element);
400 if (m_debug) tqDebug ("/got int value");
401}
402
403void AIParserBase::gotDoubleValue (double value) {
404 if (m_debug) tqDebug ("got double value");
405 if (m_ignoring) return;
406 AIElement element (value);
407 handleElement (element);
408 if (m_debug) tqDebug ("/got double value");
409}
410
411void AIParserBase::gotStringValue (const char *value) {
412 if (m_debug) tqDebug ("got string value");
413 if (m_ignoring) return;
414 if (value == NULL) value = "";
415 if (m_debug) tqDebug ("string: %s", value);
416 AIElement element (value);
417 handleElement (element);
418 if (m_debug) tqDebug ("/got string value");
419
420}
421
422void AIParserBase::gotReference (const char *value) {
423 if (m_debug) tqDebug ("got reference value");
424
425 if (m_ignoring) return;
426 if (value == NULL) value = "";
427 if (m_debug) tqDebug ("reference: %s", value);
428 TQString string(value);
429 AIElement element (string, AIElement::Reference);
430 handleElement (element);
431 if (m_debug) tqDebug ("/got reference value");
432
433}
434
435void AIParserBase::gotByte (uchar value) {
436 if (m_debug) tqDebug ("got byte value");
437
438 if (m_ignoring) return;
439 AIElement element (value);
440 handleElement (element);
441 if (m_debug) tqDebug ("/got byte value");
442}
443
444void AIParserBase::gotByteArray (const TQByteArray &data) {
445 if (m_ignoring) return;
446 AIElement element (data);
447 handleElement (element);
448}
449
450
451void AIParserBase::gotArrayStart () {
452 if (m_ignoring) return;
453 if (m_debug) tqDebug ("got array start");
454
455 TQValueVector<AIElement> array;
456 m_arrayStack.push (array);
457
458 m_sink = DS_Array;
459}
460
461void AIParserBase::gotBlockStart () {
462 if (m_ignoring) return;
463 if (m_debug) tqDebug ("got block start");
464
465 TQValueVector<AIElement> array;
466 m_blockStack.push (array);
467
468 m_sink = DS_Block;
469}
470
471void AIParserBase::gotArrayEnd () {
472 if (m_ignoring) return;
473 if (m_debug) tqDebug ("got array end");
474
475 TQValueVector<AIElement> stackArray = m_arrayStack.pop();
476
477 if (m_arrayStack.empty())
478 {
479 if (m_debug) tqDebug ("put elements to stack");
480 AIElement realElement (stackArray);
481
482 if (m_debug) {
483 tqDebug ("going to stack");
484 elementtoa (realElement);
485 tqDebug ("done");
486 }
487 m_stack.push (realElement);
488
489 m_sink = DS_Other;
490 }
491 else
492 {
493 if (m_debug) tqDebug ("put elements to nest stack level");
494 TQValueVector<AIElement> currentTOS = m_arrayStack.top();
495 currentTOS.push_back (stackArray);
496 }
497}
498
499void AIParserBase::gotBlockEnd () {
500 if (m_ignoring) return;
501 if (m_debug) tqDebug ("got block end");
502
503 TQValueVector<AIElement> stackArray = m_blockStack.pop();
504
505 if (m_blockStack.empty())
506 {
507 if (m_debug) tqDebug ("put elements to stack");
508 AIElement realElement (stackArray, AIElement::Block);
509
510 if (m_debug) {
511 tqDebug ("going to stack");
512 elementtoa (realElement);
513 tqDebug ("done");
514 }
515 m_stack.push (realElement);
516
517 m_sink = DS_Other;
518 }
519 else
520 {
521 if (m_debug) tqDebug ("put elements to nest stack level");
522 TQValueVector<AIElement> currentTOS = m_blockStack.top();
523 currentTOS.push_back (stackArray);
524 }
525}
526
527/*Ai88*/ /* void AIParserBase::_handleSetDash()
528{
529 double fval = getDoubleValue();
530
531 AIElement elem (m_stack.top());
532 m_stack.pop();
533
534 const TQValueVector<AIElement> aval = elem.toElementArray();
535 if (m_gstateHandler) m_gstateHandler->gotDash (aval, fval);
536} */
537
538/*Ai88*/ /* void AIParserBase::_handleSetFillColorCMYK()
539{
540 double k = getDoubleValue();
541 double y = getDoubleValue();
542 double m = getDoubleValue();
543 double c = getDoubleValue();
544
545 if (m_debug) tqDebug ("values 1 are %f %f %f %f",c,m,y,k);
546 AIColor color (c,m,y,k);
547
548 if (m_gstateHandler) m_gstateHandler->gotFillColor (color);
549} */
550
551/*Ai88*/ /* void AIParserBase::_handleSetFillPattern()
552{
553 AIElement elem (m_stack.top());
554 m_stack.pop();
555
556 const TQValueVector<AIElement> aval = elem.toElementArray();
557
558 double ka = getDoubleValue();
559 double k = getDoubleValue();
560 double r = getDoubleValue();
561 double rf = getDoubleValue();
562 double angle = getDoubleValue();
563 double sy = getDoubleValue();
564 double sx = getDoubleValue();
565 double py = getDoubleValue();
566 double px = getDoubleValue();
567
568 AIElement elem2 (m_stack.top());
569 m_stack.pop();
570
571 const TQString &name = elem2.toString();
572 if (m_gstateHandler) m_gstateHandler->gotFillPattern (name.latin1(), px, py, sx, sy, angle, rf, r, k, ka, aval);
573} */
574
575/*Ai88*/ /* void AIParserBase::_handleSetStrokePattern()
576{
577 AIElement elem (m_stack.top());
578 m_stack.pop();
579
580 const TQValueVector<AIElement> aval = elem.toElementArray();
581
582 double ka = getDoubleValue();
583 double k = getDoubleValue();
584 double r = getDoubleValue();
585 double rf = getDoubleValue();
586 double angle = getDoubleValue();
587 double sy = getDoubleValue();
588 double sx = getDoubleValue();
589 double py = getDoubleValue();
590 double px = getDoubleValue();
591
592 AIElement elem2 (m_stack.top());
593 m_stack.pop();
594
595 const TQString &name = elem2.toString();
596 if (m_gstateHandler) m_gstateHandler->gotStrokePattern (name.latin1(), px, py, sx, sy, angle, rf, r, k, ka, aval);
597} */
598
599/*Ai88*/ /* void AIParserBase::_handleSetStrokeColorCMYK()
600{
601 double k = getDoubleValue();
602 double y = getDoubleValue();
603 double m = getDoubleValue();
604 double c = getDoubleValue();
605 if (m_debug) tqDebug ("values 2 are %f %f %f %f",c,m,y,k);
606
607 AIColor color (c,m,y,k);
608
609 if (m_gstateHandler) m_gstateHandler->gotStrokeColor (color);
610} */
611
612/*Ai88*/ /* void AIParserBase::_handleSetFillColorGray()
613{
614 double g = getDoubleValue();
615 if (m_debug) tqDebug ("values 3 are %f",g);
616
617 AIColor color (g);
618
619 if (m_gstateHandler) m_gstateHandler->gotFillColor (color);
620} */
621
622/*Ai88*/ /* void AIParserBase::_handleSetStrokeColorGray()
623{
624 double g = getDoubleValue();
625 if (m_debug) tqDebug ("values 4 are %f",g);
626
627 AIColor color (g);
628
629 if (m_gstateHandler) m_gstateHandler->gotStrokeColor (color);
630} */
631
632/*Ai88*/ /* void AIParserBase::_handleSetFillColorCustom()
633{
634 double g = getDoubleValue();
635 const TQString &name = getStringValue();
636 double k = getDoubleValue();
637 double y = getDoubleValue();
638 double m = getDoubleValue();
639 double c = getDoubleValue();
640 if (m_debug) tqDebug ("values 5 are %f %f %f %f",c,m,y,k);
641
642 AIColor color (c,m,y,k,name.latin1(),g);
643
644 if (m_gstateHandler) m_gstateHandler->gotFillColor (color);
645} */
646
647void AIParserBase::_handlePSGet() {
648 m_stack.pop();
649 m_stack.pop();
650
651 TQString name ("xxx");
652 AIElement ref (name,AIElement::Reference);
653 m_stack.push (ref);
654}
655
656void AIParserBase::_handlePSExec() {
657 m_stack.pop();
658}
659
660void AIParserBase::_handlePSString() {
661 m_stack.pop();
662
663 TQString name ("stringval");
664 AIElement ref (name,AIElement::Reference);
665 m_stack.push (ref);
666}
667
668void AIParserBase::_handlePSBind() {
669 m_stack.pop();
670
671 TQString name ("bindentry");
672 AIElement ref (name,AIElement::Reference);
673 m_stack.push (ref);
674}
675
676void AIParserBase::_handlePSUserdict() {
677 TQString name ("userdict");
678 AIElement ref (name,AIElement::Reference);
679 m_stack.push (ref);
680}
681
682void AIParserBase::_handlePSDict() {
683 m_stack.pop();
684 m_stack.pop();
685 m_stack.pop();
686
687 TQString name ("dict");
688 AIElement ref (name,AIElement::Reference);
689 m_stack.push (ref);
690}
691
692void AIParserBase::_handlePSDup() {
693 AIElement &tos = m_stack.top();
694
695 AIElement copy (tos);
696 m_stack.push (copy);
697}
698
699void AIParserBase::_handlePSBegin() {
700 m_stack.pop();
701
702 TQString name ("dictionary begin");
703 AIElement ref (name,AIElement::Reference);
704 m_stack.push (ref);
705}
706
707void AIParserBase::_handlePSPut() {
708 m_stack.pop();
709 m_stack.pop();
710}
711
712/*Ai88*/ /* void AIParserBase::_handlePatternDefinition()
713{
714 AIElement elem (m_stack.top());
715 m_stack.pop();
716
717 const TQValueVector<AIElement> aval = elem.toElementArray();
718
719 double ury = getDoubleValue();
720 double urx = getDoubleValue();
721 double lly = getDoubleValue();
722 double llx = getDoubleValue();
723
724 AIElement elem2 (m_stack.top());
725 m_stack.pop();
726
727 const TQString &name = elem2.toString();
728
729 if (m_documentHandler) m_documentHandler->gotPatternDefinition (name.latin1(), aval, llx, lly, urx, ury);
730} */
731
732void AIParserBase::_handlePSDef() {
733 // name ref
734 m_stack.pop();
735
736 // impl
737 m_stack.pop();
738}
739
740/*Ai88*/ /* void AIParserBase::_handleSetStrokeColorCustom()
741{
742 double g = getDoubleValue();
743 const TQString &name = getStringValue();
744 double k = getDoubleValue();
745 double y = getDoubleValue();
746 double m = getDoubleValue();
747 double c = getDoubleValue();
748 if (m_debug) tqDebug ("values 6 are %f %f %f %f",c,m,y,k);
749
750 AIColor color (c,m,y,k,name.latin1(),g);
751
752 if (m_gstateHandler) m_gstateHandler->gotStrokeColor (color);
753} */
754
755void AIParserBase::_handleDocumentFonts(const char *) {
756}
757
758void AIParserBase::_handleDocumentFiles(const char *) {
759}
760
761void AIParserBase::_handleDocumentCustomColors(const char *) {
762}
763
764void AIParserBase::_handleDocumentNeededResources(const char *data) {
765 if (!data) return;
766 TQStringList items = TQStringList::split (' ', data);
767
768 TQString itemType = items[1];
769 TQString name = items[2];
770 TQString version = items[3];
771 TQString release = items[4];
772}
773
774void AIParserBase::_handleIncludeResource(const char *data) {
775 if (!data) return;
776 TQStringList items = TQStringList::split (' ', data);
777
778 TQString itemType = items[1];
779 TQString name = items[2];
780 TQString version = items[3];
781 TQString release = items[4];
782
783 m_modules.push_back (name);
784}
785
786void AIParserBase::_handleDocumentProcessColors(const char *data) {
787 if (!data) return;
788
789 int colorSet = 0;
790 TQString tmp (data);
791
792 signed int index;
793
794 index = tmp.find ("Cyan");
795 if (index > 0) colorSet |= PC_Cyan;
796
797 index = tmp.find ("Magenta");
798 if (index > 0) colorSet |= PC_Magenta;
799
800 index = tmp.find ("Yellow");
801 if (index > 0) colorSet |= PC_Yellow;
802
803 index = tmp.find ("Black");
804 if (index > 0) colorSet |= PC_Black;
805
806 if (m_documentHandler) m_documentHandler->gotProcessColors (colorSet);
807}
808
809void AIParserBase::_handleCMYKCustomColor(const char *) {
810}
811
812/*Ai88*/ /* void AIParserBase::_handleGsaveIncludeDocument() {
813 AIElement elem2 (m_stack.top());
814 m_stack.pop();
815
816 const TQString &name = elem2.toString();
817
818 int ury = getIntValue();
819 int urx = getIntValue();
820 int lly = getIntValue();
821 int llx = getIntValue();
822
823 AIElement elem (m_stack.top());
824 m_stack.pop();
825
826 const TQValueVector<AIElement> aval = elem.toElementArray();
827
828 if (m_embeddedHandler) m_embeddedHandler->gotGsaveIncludeDocument (aval, llx,lly,urx,ury,name.latin1());
829} */
830
831/*Ai88*/ /* void AIParserBase::_handleSetCurrentText() {
832 int iAlign = getIntValue();
833 TextAlign ta = TA_HLeft;
834
835 switch (iAlign)
836 {
837 case 0 : ta = TA_HLeft; break;
838 case 1 : ta = TA_HCenter; break;
839 case 2 : ta = TA_HRight; break;
840 case 3: ta = TA_VTop; break;
841 case 4 : ta = TA_VCenter; break;
842 case 5 : ta = TA_VBottom; break;
843 }
844
845 double kerning = getDoubleValue();
846 double leading = getDoubleValue();
847 double size = getDoubleValue();
848
849 AIElement elem2 (m_stack.top());
850 m_stack.pop();
851
852 const TQString &fontname = elem2.toReference();
853
854 if (m_textHandler) m_textHandler->gotFontDefinition (fontname.latin1(), size, leading, kerning, ta);
855} */
856
857/*Ai88*/ /* void AIParserBase::_handleTextBlock (TextOperation to) {
858 AIElement elem (m_stack.top());
859 tqDebug ("to element is (%s)",elem.typeName());
860 m_stack.pop();
861
862 const TQValueVector<AIElement> aval = elem.toElementArray();
863
864 if (m_textHandler) m_textHandler->gotTextBlockBegin (aval, to);
865} */
866
867/*Ai88*/ /* void AIParserBase::_handleTextOutput () {
868 AIElement elem (m_stack.top());
869 m_stack.pop();
870
871 const TQString &text = elem.toString();
872
873 int length = -1;
874
875 if (m_stack.empty())
876 {
877 AIElement elem2 (m_stack.top());
878 if (elem2.type() == AIElement::Int)
879 {
880 length = elem2.asInt();
881 m_stack.pop();
882 }
883 }
884 if (m_textHandler) m_textHandler->gotTextOutput (text.latin1(), length);
885} */
886
887void AIParserBase::_handleCreationDate (const char *data)
888{
889 if (!data) return;
890
891 TQRegExp test ("\\((.+)\\) \\((.+)\\)");
892 if (test.search (data))
893 {
894 TQString val1 = test.cap(1);
895 TQString val2 = test.cap(2);
896
897 if (m_documentHandler) m_documentHandler->gotCreationDate (val1.latin1(),val2.latin1());
898 }
899}
900
901void AIParserBase::gotToken (const char *value) {
902 if (m_debug) tqDebug ("got token");
903
904 if (m_ignoring) return;
905 if (m_debug) tqDebug ("token: %s", value);
906
907 if (m_sink == DS_Array)
908 {
909 if (m_debug) tqDebug ("token in array");
910 TQString op (value);
911 AIElement realElement (op, AIElement::Operator);
912 handleElement (realElement);
913
914 return;
915 }
916 if (m_sink == DS_Block)
917 {
918 if (m_debug) tqDebug ("token in block");
919 TQString op (value);
920 AIElement realElement (op, AIElement::Operator);
921 handleElement (realElement);
922
923 return;
924 }
925
926 if (m_debug) tqDebug ("get ai operation");
927
928 AIOperation op = getAIOperation (value);
929// PathElement pathElement;
930// double fval;
931// int ival;
932
933 bool handled = false;
934
935 handled = m_ai88Handler->handleAIOperation (op);
936 if (!handled) handled = m_ai3Handler->handleAIOperation (op);
937
938 if (!handled)
939 {
940 if (m_sink == DS_Other)
941 {
942 if (handlePS (value)) return;
943 }
944 tqWarning ( "unknown operator: %s", value );
945
946 TQString string(value);
947
948 if (m_modules.findIndex(string) != -1)
949 {
950 AIElement element (string, AIElement::Reference);
951 handleElement (element);
952 return;
953 }
954
955 if (m_debug) stacktoa (m_stack);
956 tqWarning ( "pushing %s to stack", value );
957 AIElement element (string, AIElement::Operator);
958 handleElement (element);
959 }
960
961 if (m_debug) tqDebug ("/got token value");
962}
963
964bool AIParserBase::handlePS (const char *operand){
965 if (m_ignoring) return false;
966
967 PSOperation psop = getPSOperation (operand);
968
969 switch (psop)
970 {
971 case PSO_Get :
972 _handlePSGet ();
973 return true;
974 case PSO_Exec :
975 _handlePSExec ();
976 return true;
977 case PSO_Def :
978 _handlePSDef ();
979 return true;
980 case PSO_String :
981 _handlePSString ();
982 return true;
983 case PSO_Bind :
984 _handlePSBind ();
985 return true;
986 case PSO_Userdict :
987 _handlePSUserdict ();
988 return true;
989 case PSO_Dict :
990 _handlePSDict ();
991 return true;
992 case PSO_Dup :
993 _handlePSDup ();
994 return true;
995 case PSO_Begin :
996 _handlePSBegin ();
997 return true;
998 case PSO_Put :
999 _handlePSPut ();
1000 return true;
1001 default: break;
1002 }
1003 return false;
1004}
1005
1006const double AIParserBase::getDoubleValue(void) {
1007 const AIElement &elem = m_stack.pop();
1008
1009 return elem.toDouble();
1010}
1011
1012const int AIParserBase::getIntValue(void) {
1013 const AIElement &elem = m_stack.pop();
1014
1015 return elem.toInt();
1016}
1017
1018const bool AIParserBase::getBoolValue(void) {
1019 return getIntValue() == 1;
1020}
1021
1022const TQString AIParserBase::getStringValue(void) {
1023 const AIElement &elem = m_stack.pop();
1024
1025 return elem.toString();
1026}
1027
1028const TQString AIParserBase::getOperatorValue(void) {
1029 const AIElement &elem = m_stack.pop();
1030
1031 return elem.toOperator();
1032}
1033
1034AIOperation AIParserBase::getAIOperation (const char *operand)
1035{
1036 int i=0;
1037 TQString cmpValue (operand);
1038
1039 for(;;) { AIOperationMapping map = aiMappings[i];
1040 if (map.op == NULL) return AIO_Other;
1041 if (cmpValue.compare (map.op) == 0) return map.action;
1042
1043 i++;
1044 }
1045}
1046
1047PSOperation AIParserBase::getPSOperation (const char *operand)
1048{
1049 int i=0;
1050 TQString cmpValue (operand);
1051
1052 for(;;) { PSOperationMapping map = psMappings[i];
1053 if (map.op == NULL) return PSO_Other;
1054 if (cmpValue.compare (map.op) == 0) return map.action;
1055
1056 i++;
1057 }
1058}
1059
1060CommentOperation AIParserBase::getCommentOperation (const char *command) {
1061 TQString data (command);
1062
1063 signed int index;
1064
1065 int i=0;
1066
1067 for(;;) {
1068 CommentOperationMapping map = commentMappings[i];
1069 if (map.op == NULL) return CO_Other;
1070 index = data.find (map.op);
1071 if (index >= 0) return map.action;
1072 i++;
1073 }
1074}
1075
1076void GStateHandlerBase::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) {
1077 tqDebug ( "got fill pattern %s %f %f %f %f %f %f %f %f %f", pname, px, py, sx, sy, angle, rf, r, k, ka);
1078 arraytoa (transformData);
1079 tqDebug ("/got fill pattern");
1080}
1081
1082void GStateHandlerBase::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) {
1083 tqDebug ( "got stroke pattern %s %f %f %f %f %f %f %f %f %f", pname, px, py, sx, sy, angle, rf, r, k, ka);
1084 arraytoa (transformData);
1085 tqDebug ("/got stroke pattern");
1086}
1087
1088const char *AIParserBase::getValue (const char *input) {
1089 TQString data(input);
1090
1091 signed int index = data.find (':');
1092 if (index < 0) return "";
1093 index++;
1094 while (data.at(index) == ' ') index++;
1095 return data.mid(index).latin1();
1096}
1097
1098bool AIParserBase::getRectangle (const char* input, int &llx, int &lly, int &urx, int &ury) {
1099 if (input == NULL) return false;
1100
1101 TQString s(input);
1102 if (s.contains ("(atend)")) return false;
1103 TQStringList values = TQStringList::split (" ", input);
1104 if (values.size() < 5) return false;
1105 llx = values[1].toInt();
1106 lly = values[2].toInt();
1107 urx = values[3].toInt();
1108 ury = values[4].toInt();
1109
1110 return true;
1111}
1112
1113bool AIParserBase::getPoint (const char* input, int &x, int &y) {
1114 if (input == NULL) return false;
1115
1116 TQString s(input);
1117 TQStringList values = TQStringList::split (" ", input);
1118
1119 if (values.size() < 3) return false;
1120
1121 x = values[1].toInt();
1122 y = values[2].toInt();
1123
1124 return true;
1125}
1126
1127void AIParserBase::cleanupArrays()
1128{
1129 if (m_sink == DS_Array) tqDebug ("unclosed array(s).");
1130 while (m_sink == DS_Array) gotArrayEnd ();
1131 stacktoa (m_stack);
1132}
1133
1134/*Ai88*/ /* void AIParserBase::_handleFontEncoding()
1135{
1136 while (m_stack.top().type() != AIElement::Reference) {
1137 m_stack.pop();
1138 }
1139
1140 AIElement elem (m_stack.top());
1141 m_stack.pop();
1142 const TQString &oldFont = elem.toReference();
1143
1144 AIElement elem2 (m_stack.top());
1145 m_stack.pop();
1146 const TQString &newFont = elem2.toReference();
1147
1148 AIElement elem3 (m_stack.top());
1149 m_stack.pop();
1150 const TQValueVector<AIElement> encodingData = elem3.toElementArray();
1151
1152 if (m_textHandler) m_textHandler->gotFontEncoding (encodingData, oldFont.latin1(), newFont.latin1());
1153} */
1154
1155void TextHandlerBase::gotFontEncoding (const TQValueVector<AIElement>& encodingData, const char*oldFontName, const char*newFontName)
1156{
1157 tqDebug ("font encoding %s to %s",oldFontName, newFontName);
1158 arraytoa (encodingData);
1159 tqDebug ("/font encoding");
1160}
1161
1162void TextHandlerBase::gotFontDefinition (const char*fontName, double size, double leading, double kerning, TextAlign align)
1163{
1164 tqDebug ("font definition: name %s size %f leading %f kerning %f align %d", fontName, size, leading, kerning, align);
1165}
1166
1167void TextHandlerBase::gotTextBlockBegin (const TQValueVector<AIElement>& transData, TextOperation mode)
1168{
1169 tqDebug ("text block begin %d",mode);
1170 arraytoa (transData);
1171 tqDebug ("/text block begin");
1172}
1173
1174void TextHandlerBase::gotTextOutput (const char*text, int length)
1175{
1176 tqDebug ("text output (%s) %d",text,length);
1177}
1178
1179void TextHandlerBase::gotTextBlockEnd ()
1180{
1181 tqDebug ("text block end");
1182}
1183
1184const void elementtoa (const AIElement &/*data*/)
1185{
1186/* AIElement::Type type = data.type();
1187 tqDebug ("type: %s", AIElement::typeToName (type));
1188
1189 switch (type)
1190 {
1191 case AIElement::String :
1192 case AIElement::CString :
1193 case AIElement::Int :
1194 case AIElement::UInt :
1195 case AIElement::Double :
1196 tqDebug ("string value : %s",data.toString().latin1());
1197 break;
1198 case AIElement::Reference :
1199 tqDebug ("string value : %s",data.toReference().latin1());
1200 break;
1201 case AIElement::Operator :
1202 tqDebug ("string value : %s",data.toOperator().latin1());
1203 break;
1204 case AIElement::ElementArray :
1205 arraytoa (data.toElementArray());
1206 break;
1207 case AIElement::Block :
1208 arraytoa (data.toBlock());
1209 break;
1210
1211 default :
1212 tqDebug ("could not fetch data");
1213 } */
1214}
1215
1216const void arraytoa (const TQValueVector<AIElement> &/*data*/)
1217{
1218/* tqDebug ("array size is %d ",data.size());
1219 if (data.size() > 0)
1220 {
1221 tqDebug ("[[[[[[[[[[[[[[[[[[[[");
1222 for (uint i=0; i< data.size(); i++)
1223 {
1224 elementtoa (data[i]);
1225 }
1226 tqDebug ("]]]]]]]]]]]]]]]]]]]]");
1227 } */
1228}
1229
1230const void stacktoa (const TQValueStack<AIElement> &/*data*/)
1231{
1232/* tqDebug ("stack size is %d",data.size());
1233 if (data.size() > 0)
1234 {
1235 tqDebug ("<<<<<<<<<<<<<<<<<<");
1236 for (uint i=0; i< data.size(); i++)
1237 {
1238 elementtoa (data[i]);
1239 }
1240 }
1241 tqDebug (">>>>>>>>>>>>>>>>>>"); */
1242}
1243
1244const void stacktoa2 (const TQValueStack<TQValueVector<AIElement> >&/*data*/)
1245{
1246/* tqDebug ("stack size is %d",data.size());
1247
1248 if (data.size() > 0)
1249 {
1250 tqDebug ("(((((((((((((((((((((((");
1251 for (uint i=0; i< data.size(); i++)
1252 {
1253 arraytoa (data[i]);
1254 }
1255 tqDebug (")))))))))))))))))))))))");
1256 } */
1257}
1258
1259const void aiotoa (AIOperation &data)
1260{
1261 switch (data)
1262 {
1263 case AIO_SetFillColorCMYK : tqDebug ("AIO_SetFillColorCMYK"); break;
1264 case AIO_SetStrokeColorCMYK : tqDebug ("AIO_SetStrokeColorCMYK"); break;
1265 case AIO_SetFillColorGray : tqDebug ("AIO_SetFillColorGray"); break;
1266 case AIO_SetStrokeColorGray : tqDebug ("AIO_SetStrokeColorGray"); break;
1267 case AIO_SetFillColorCustom : tqDebug ("AIO_SetFillColorCustom"); break;
1268 case AIO_SetStrokeColorCustom : tqDebug ("AIO_SetStrokeColorCustom"); break;
1269 case AIO_SetFillPattern : tqDebug ("AIO_SetFillPattern"); break;
1270 case AIO_SetStrokePattern : tqDebug ("AIO_SetStrokePattern"); break;
1271 case AIO_SetFillOverprinting : tqDebug ("AIO_SetFillOverprinting"); break;
1272 case AIO_SetStrokeOverprinting : tqDebug ("AIO_SetStrokeOverprinting"); break;
1273 case AIO_SetFlatness : tqDebug ("AIO_SetFlatness"); break;
1274 case AIO_SetLineCap : tqDebug ("AIO_SetLineCap"); break;
1275 case AIO_SetLineJoin : tqDebug ("AIO_SetLineJoin"); break;
1276 case AIO_SetLineWidth : tqDebug ("AIO_SetLineWidth"); break;
1277 case AIO_SetMiterLimit : tqDebug ("AIO_SetMiterLimit"); break;
1278 case AIO_SetDash : tqDebug ("AIO_SetDash"); break;
1279 case AIO_BeginGroupClip : tqDebug ("AIO_BeginGroupClip"); break;
1280 case AIO_EndGroupClip : tqDebug ("AIO_EndGroupClip"); break;
1281 case AIO_MoveTo : tqDebug ("AIO_MoveTo"); break;
1282 case AIO_LineToCorner : tqDebug ("AIO_LineToCorner"); break;
1283 case AIO_LineToSmooth : tqDebug ("AIO_LineToSmooth"); break;
1284 case AIO_CurveToSmooth : tqDebug ("AIO_CurveToSmooth"); break;
1285 case AIO_CurveToCorner : tqDebug ("AIO_CurveToCorner"); break;
1286 case AIO_CurveToOmitC1Smooth : tqDebug ("AIO_CurveToOmitC1Smooth"); break;
1287 case AIO_CurveToOmitC1Corner : tqDebug ("AIO_CurveToOmitC1Corner"); break;
1288 case AIO_CurveToOmitC2Smooth : tqDebug ("AIO_CurveToOmitC2Smooth"); break;
1289 case AIO_CurveToOmitC2Corner : tqDebug ("AIO_CurveToOmitC2Corner"); break;
1290 case AIO_PathIgnoreNoReset : tqDebug ("AIO_PathIgnoreNoReset"); break;
1291 case AIO_PathIgnoreNoResetClose : tqDebug ("AIO_PathIgnoreNoResetClose"); break;
1292 case AIO_PathClipPath : tqDebug ("AIO_PathClipPath"); break;
1293 case AIO_PathIgnoreReset : tqDebug ("AIO_PathIgnoreReset"); break;
1294 case AIO_PathIgnoreResetClose : tqDebug ("AIO_PathIgnoreResetClose"); break;
1295 case AIO_PathFillNonZero : tqDebug ("AIO_PathFillNonZero"); break;
1296 case AIO_PathFillNonZeroClose : tqDebug ("AIO_PathFillNonZeroClose"); break;
1297 case AIO_PathStroke : tqDebug ("AIO_PathStroke"); break;
1298 case AIO_PathStrokeClose : tqDebug ("AIO_PathStrokeClose"); break;
1299 case AIO_PathFillNoReset : tqDebug ("AIO_PathFillNoReset"); break;
1300 case AIO_PathFillNoResetClose : tqDebug ("AIO_PathFillNoResetClose"); break;
1301 case AIO_FontEncoding : tqDebug ("AIO_FontEncoding"); break;
1302 case AIO_PatternDefinition : tqDebug ("AIO_PatternDefinition"); break;
1303 case AIO_SetCurrentText : tqDebug ("AIO_SetCurrentText"); break;
1304 case AIO_TextBlockFillStroke : tqDebug ("AIO_TextBlockFillStroke"); break;
1305 case AIO_TextBlockFill : tqDebug ("AIO_TextBlockFill"); break;
1306 case AIO_TextBlockAppend : tqDebug ("AIO_TextBlockAppend"); break;
1307 case AIO_TextBlockIgnore : tqDebug ("AIO_TextBlockIgnore"); break;
1308 case AIO_TextBlockStroke : tqDebug ("AIO_TextBlockStroke"); break;
1309 case AIO_TextOutput : tqDebug ("AIO_TextOutput"); break;
1310 case AIO_TextBlockEnd : tqDebug ("AIO_TextBlockEnd"); break;
1311 case AIO_GsaveIncludeDocument : tqDebug ("AIO_GsaveIncludeDocument"); break;
1312 case AIO_Grestore : tqDebug ("AIO_Grestore"); break;
1313 case AIO_LockElement : tqDebug ("AIO_LockElement"); break;
1314 case AIO_SetWindingOrder : tqDebug ("AIO_SetWindingOrder"); break;
1315 default : tqDebug ("unknown");
1316 }
1317}
1318
1319const void sttoa (SectionType &data, bool begin)
1320{
1321 switch (data)
1322 {
1323 case ST_Setup : begin ? tqDebug ("start setup") : tqDebug ("end setup"); break;
1324 case ST_Prolog : begin ? tqDebug ("start prolog") : tqDebug ("end prolog"); break;
1325 case ST_ProcSet : begin ? tqDebug ("start procset") : tqDebug ("end procset"); break;
1326 case ST_Encoding : begin ? tqDebug ("start encoding") : tqDebug ("end encoding"); break;
1327 case ST_Pattern : begin ? tqDebug ("start pattern") : tqDebug ("end pattern"); break;
1328 case ST_Document : begin ? tqDebug ("start document") : tqDebug ("end document"); break;
1329 case ST_BrushPattern : begin ? tqDebug ("start brush pattern") : tqDebug ("end brush pattern"); break;
1330 case ST_Gradient : begin ? tqDebug ("start gradient") : tqDebug ("end gradient"); break;
1331 case ST_Palette : begin ? tqDebug ("start palette") : tqDebug ("end palette"); break;
1332 case ST_Resource : begin ? tqDebug ("start resource") : tqDebug ("end resouce"); break;
1333
1334 default : begin ? tqDebug ("unknown") : tqDebug ("end unknown");
1335 }
1336}
1337
double toDouble(bool *ok=0) const
const TQString toString() const
int toInt(bool *ok=0) const