21#include "ai88handler.h"
23AI88Handler::AI88Handler(AIParserBase *delegate){
24 m_delegate = delegate;
26AI88Handler::~AI88Handler(){
29bool AI88Handler::handleAIOperation (AIOperation op) {
30 PathElement pathElement;
35 case AIO_SetFillColorCMYK :
36 _handleSetFillColorCMYK();
39 case AIO_SetStrokeColorCMYK :
40 _handleSetStrokeColorCMYK();
43 case AIO_SetFillColorGray :
44 _handleSetFillColorGray();
47 case AIO_SetStrokeColorGray :
48 _handleSetStrokeColorGray();
51 case AIO_SetFillColorCustom :
52 _handleSetFillColorCustom();
55 case AIO_SetStrokeColorCustom :
56 _handleSetStrokeColorCustom();
59 case AIO_SetFillPattern :
60 _handleSetFillPattern();
63 case AIO_SetStrokePattern :
64 _handleSetStrokePattern();
67 case AIO_SetFillOverprinting :
68 if (m_delegate->m_miscGStateHandler) m_delegate->m_miscGStateHandler->gotFillOverprinting (m_delegate->getBoolValue());
71 case AIO_SetStrokeOverprinting :
72 if (m_delegate->m_miscGStateHandler) m_delegate->m_miscGStateHandler->gotStrokeOverprinting (m_delegate->getBoolValue());
75 case AIO_LockElement :
76 if (m_delegate->m_miscGStateHandler) m_delegate->m_miscGStateHandler->gotLockNextObject (m_delegate->getBoolValue());
79 case AIO_SetFlatness :
80 fval = m_delegate->getDoubleValue();
81 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFlatness (fval);
85 ival = m_delegate->getIntValue();
86 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotLineCaps (ival);
89 case AIO_SetLineJoin :
90 ival = m_delegate->getIntValue();
91 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotLineJoin (ival);
94 case AIO_SetLineWidth :
95 fval = kMax(0.2, m_delegate->getDoubleValue());
96 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotLineWidth (fval);
99 case AIO_SetMiterLimit :
100 fval = m_delegate->getDoubleValue();
101 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotMiterLimit (fval);
108 case AIO_BeginGroupClip :
109 if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotBeginGroup (
true);
112 case AIO_EndGroupClip :
113 if (m_delegate->m_debug) tqDebug (
"got end group clip");
114 if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotEndGroup (
true);
115 if (m_delegate->m_debug) tqDebug (
"/got end group clip");
120 pathElement.petype = PET_MoveTo;
121 pathElement.pttype = PT_Corner;
122 pathElement.pevalue.pointdata.y = m_delegate->getDoubleValue();
123 pathElement.pevalue.pointdata.x = m_delegate->getDoubleValue();
124 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement);
127 case AIO_LineToCorner :
128 pathElement.petype = PET_LineTo;
129 pathElement.pttype = PT_Corner;
130 pathElement.pevalue.pointdata.y = m_delegate->getDoubleValue();
131 pathElement.pevalue.pointdata.x = m_delegate->getDoubleValue();
132 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement);
135 case AIO_LineToSmooth :
136 pathElement.petype = PET_LineTo;
137 pathElement.pttype = PT_Smooth;
138 pathElement.pevalue.pointdata.y = m_delegate->getDoubleValue();
139 pathElement.pevalue.pointdata.x = m_delegate->getDoubleValue();
140 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement);
143 case AIO_CurveToCorner :
144 pathElement.petype = PET_CurveTo;
145 pathElement.pttype = PT_Corner;
146 pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue();
147 pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue();
148 pathElement.pevalue.bezierdata.y2 = m_delegate->getDoubleValue();
149 pathElement.pevalue.bezierdata.x2 = m_delegate->getDoubleValue();
150 pathElement.pevalue.bezierdata.y1 = m_delegate->getDoubleValue();
151 pathElement.pevalue.bezierdata.x1 = m_delegate->getDoubleValue();
152 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement);
155 case AIO_CurveToSmooth :
156 pathElement.petype = PET_CurveTo;
157 pathElement.pttype = PT_Smooth;
158 pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue();
159 pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue();
160 pathElement.pevalue.bezierdata.y2 = m_delegate->getDoubleValue();
161 pathElement.pevalue.bezierdata.x2 = m_delegate->getDoubleValue();
162 pathElement.pevalue.bezierdata.y1 = m_delegate->getDoubleValue();
163 pathElement.pevalue.bezierdata.x1 = m_delegate->getDoubleValue();
164 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement);
167 case AIO_CurveToOmitC1Corner :
168 pathElement.petype = PET_CurveTo;
169 pathElement.pttype = PT_Corner;
170 pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue();
171 pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue();
172 pathElement.pevalue.bezierdata.y2 = m_delegate->getDoubleValue();
173 pathElement.pevalue.bezierdata.x2 = m_delegate->getDoubleValue();
174 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement);
177 case AIO_CurveToOmitC1Smooth :
178 pathElement.petype = PET_CurveTo;
179 pathElement.pttype = PT_Smooth;
180 pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue();
181 pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue();
182 pathElement.pevalue.bezierdata.y2 = m_delegate->getDoubleValue();
183 pathElement.pevalue.bezierdata.x2 = m_delegate->getDoubleValue();
184 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement);
187 case AIO_CurveToOmitC2Corner :
188 pathElement.petype = PET_CurveTo;
189 pathElement.pttype = PT_Corner;
190 pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue();
191 pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue();
192 pathElement.pevalue.bezierdata.y1 = m_delegate->getDoubleValue();
193 pathElement.pevalue.bezierdata.x1 = m_delegate->getDoubleValue();
194 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement);
197 case AIO_CurveToOmitC2Smooth :
198 pathElement.petype = PET_CurveTo;
199 pathElement.pttype = PT_Smooth;
200 pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue();
201 pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue();
202 pathElement.pevalue.bezierdata.y1 = m_delegate->getDoubleValue();
203 pathElement.pevalue.bezierdata.x1 = m_delegate->getDoubleValue();
204 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement);
208 case AIO_PathIgnoreReset :
209 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotIgnorePath(
false,
true);
212 case AIO_PathIgnoreResetClose :
213 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotIgnorePath(
true,
true);
216 case AIO_PathIgnoreNoReset :
217 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotIgnorePath(
false,
false);
220 case AIO_PathIgnoreNoResetClose :
221 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotIgnorePath(
true,
false);
224 case AIO_PathClipPath :
225 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotClipPath(
false);
228 case AIO_PathFillNonZero :
229 if (m_delegate->m_pathHandler)
231 m_delegate->m_pathHandler->gotFillMode (FM_NonZero);
232 m_delegate->m_pathHandler->gotFillPath(
false,
true);
236 case AIO_PathFillNonZeroClose :
237 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotFillPath(
true,
true);
240 case AIO_PathFillNoReset :
241 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotFillPath(
false,
false);
244 case AIO_PathFillNoResetClose :
245 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotFillPath(
true,
false);
248 case AIO_PathStroke :
249 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotStrokePath(
false);
252 case AIO_PathStrokeClose :
253 if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotStrokePath(
true);
256 case AIO_PatternDefinition :
257 _handlePatternDefinition();
260 case AIO_GsaveIncludeDocument :
261 _handleGsaveIncludeDocument();
265 if (m_delegate->m_embeddedHandler) m_delegate->m_embeddedHandler->gotGrestore();
268 case AIO_FontEncoding :
269 _handleFontEncoding();
272 case AIO_SetCurrentText :
273 _handleSetCurrentText();
276 case AIO_TextBlockFillStroke :
277 _handleTextBlock (TO_FillStroke);
280 case AIO_TextBlockFill :
281 _handleTextBlock (TO_Fill);
284 case AIO_TextBlockAppend :
285 _handleTextBlock (TO_Append);
288 case AIO_TextBlockIgnore :
289 _handleTextBlock (TO_Ignore);
292 case AIO_TextBlockStroke :
293 _handleTextBlock (TO_Stroke);
296 case AIO_TextOutput :
297 _handleTextOutput ();
300 case AIO_TextBlockEnd :
301 if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotTextBlockEnd();
311void AI88Handler::_handleSetFillColorCMYK()
313 double k = m_delegate->getDoubleValue();
314 double y = m_delegate->getDoubleValue();
315 double m = m_delegate->getDoubleValue();
316 double c = m_delegate->getDoubleValue();
318 if (m_delegate->m_debug) tqDebug (
"values 1 are %f %f %f %f",c,m,y,k);
321 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFillColor (color);
324void AI88Handler::_handleSetFillPattern()
326 AIElement elem (m_delegate->m_stack.top());
327 m_delegate->m_stack.pop();
329 const TQValueVector<AIElement> aval = elem.toElementArray();
331 double ka = m_delegate->getDoubleValue();
332 double k = m_delegate->getDoubleValue();
333 double r = m_delegate->getDoubleValue();
334 double rf = m_delegate->getDoubleValue();
335 double angle = m_delegate->getDoubleValue();
336 double sy = m_delegate->getDoubleValue();
337 double sx = m_delegate->getDoubleValue();
338 double py = m_delegate->getDoubleValue();
339 double px = m_delegate->getDoubleValue();
341 AIElement elem2 (m_delegate->m_stack.top());
342 m_delegate->m_stack.pop();
344 const TQString &name = elem2.toString();
345 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFillPattern (name.latin1(), px, py, sx, sy, angle, rf, r, k, ka, aval);
348void AI88Handler::_handleSetStrokePattern()
350 AIElement elem (m_delegate->m_stack.top());
351 m_delegate->m_stack.pop();
353 const TQValueVector<AIElement> aval = elem.toElementArray();
355 double ka = m_delegate->getDoubleValue();
356 double k = m_delegate->getDoubleValue();
357 double r = m_delegate->getDoubleValue();
358 double rf = m_delegate->getDoubleValue();
359 double angle = m_delegate->getDoubleValue();
360 double sy = m_delegate->getDoubleValue();
361 double sx = m_delegate->getDoubleValue();
362 double py = m_delegate->getDoubleValue();
363 double px = m_delegate->getDoubleValue();
365 AIElement elem2 (m_delegate->m_stack.top());
366 m_delegate->m_stack.pop();
368 const TQString &name = elem2.toString();
369 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotStrokePattern (name.latin1(), px, py, sx, sy, angle, rf, r, k, ka, aval);
373void AI88Handler::_handleSetStrokeColorCMYK()
375 double k = m_delegate->getDoubleValue();
376 double y = m_delegate->getDoubleValue();
377 double m = m_delegate->getDoubleValue();
378 double c = m_delegate->getDoubleValue();
379 if (m_delegate->m_debug) tqDebug (
"values 2 are %f %f %f %f",c,m,y,k);
383 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotStrokeColor (color);
386void AI88Handler::_handleSetFillColorGray()
388 double g = m_delegate->getDoubleValue();
389 if (m_delegate->m_debug) tqDebug (
"values 3 are %f",g);
393 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFillColor (color);
396void AI88Handler::_handleSetStrokeColorGray()
398 double g = m_delegate->getDoubleValue();
399 if (m_delegate->m_debug) tqDebug (
"values 4 are %f",g);
403 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotStrokeColor (color);
406void AI88Handler::_handleSetFillColorCustom()
408 double g = m_delegate->getDoubleValue();
409 const TQString name = m_delegate->getStringValue();
410 double k = m_delegate->getDoubleValue();
411 double y = m_delegate->getDoubleValue();
412 double m = m_delegate->getDoubleValue();
413 double c = m_delegate->getDoubleValue();
414 if (m_delegate->m_debug) tqDebug (
"values 5 are %f %f %f %f",c,m,y,k);
416 AIColor color (c,m,y,k,name.latin1(),g);
418 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFillColor (color);
421void AI88Handler::_handleSetDash()
424 double fval = m_delegate->getDoubleValue();
426 AIElement elem (m_delegate->m_stack.top());
427 m_delegate->m_stack.pop();
429 const TQValueVector<AIElement> aval = elem.toElementArray();
430 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotDash (aval, fval);
434void AI88Handler::_handlePatternDefinition()
436 AIElement elem (m_delegate->m_stack.top());
437 m_delegate->m_stack.pop();
439 const TQValueVector<AIElement> aval = elem.toElementArray();
441 double ury = m_delegate->getDoubleValue();
442 double urx = m_delegate->getDoubleValue();
443 double lly = m_delegate->getDoubleValue();
444 double llx = m_delegate->getDoubleValue();
446 AIElement elem2 (m_delegate->m_stack.top());
447 m_delegate->m_stack.pop();
449 const TQString &name = elem2.toString();
451 if (m_delegate->m_documentHandler) m_delegate->m_documentHandler->gotPatternDefinition (name.latin1(), aval, llx, lly, urx, ury);
454void AI88Handler::_handleGsaveIncludeDocument() {
455 AIElement elem2 (m_delegate->m_stack.top());
456 m_delegate->m_stack.pop();
458 const TQString &name = elem2.toString();
460 int ury = m_delegate->getIntValue();
461 int urx = m_delegate->getIntValue();
462 int lly = m_delegate->getIntValue();
463 int llx = m_delegate->getIntValue();
465 AIElement elem (m_delegate->m_stack.top());
466 m_delegate->m_stack.pop();
468 const TQValueVector<AIElement> aval = elem.toElementArray();
470 if (m_delegate->m_embeddedHandler) m_delegate->m_embeddedHandler->gotGsaveIncludeDocument (aval, llx,lly,urx,ury,name.latin1());
473void AI88Handler::_handleSetCurrentText() {
474 int iAlign = m_delegate->getIntValue();
475 TextAlign ta = TA_HLeft;
479 case 0 : ta = TA_HLeft;
break;
480 case 1 : ta = TA_HCenter;
break;
481 case 2 : ta = TA_HRight;
break;
482 case 3: ta = TA_VTop;
break;
483 case 4 : ta = TA_VCenter;
break;
484 case 5 : ta = TA_VBottom;
break;
487 double kerning = m_delegate->getDoubleValue();
488 double leading = m_delegate->getDoubleValue();
489 double size = m_delegate->getDoubleValue();
491 AIElement elem2 (m_delegate->m_stack.top());
492 m_delegate->m_stack.pop();
494 const TQString &fontname = elem2.toReference();
496 if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotFontDefinition (fontname.latin1(), size, leading, kerning, ta);
500void AI88Handler::_handleTextBlock (TextOperation to) {
501 AIElement elem (m_delegate->m_stack.top());
502 tqDebug (
"to element is (%s)",elem.typeName());
503 m_delegate->m_stack.pop();
505 const TQValueVector<AIElement> aval = elem.toElementArray();
507 if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotTextBlockBegin (aval, to);
510void AI88Handler::_handleTextOutput () {
511 AIElement elem (m_delegate->m_stack.top());
512 m_delegate->m_stack.pop();
514 const TQString &text = elem.toString();
518 if (m_delegate->m_stack.empty())
520 AIElement elem2 (m_delegate->m_stack.top());
521 if (elem2.type() == AIElement::Int)
523 length = elem2.asInt();
524 m_delegate->m_stack.pop();
527 if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotTextOutput (text.latin1(), length);
530void AI88Handler::_handleFontEncoding()
532 while (m_delegate->m_stack.top().type() != AIElement::Reference) {
533 m_delegate->m_stack.pop();
536 AIElement elem (m_delegate->m_stack.top());
537 m_delegate->m_stack.pop();
538 const TQString &oldFont = elem.toReference();
540 AIElement elem2 (m_delegate->m_stack.top());
541 m_delegate->m_stack.pop();
542 const TQString &newFont = elem2.toReference();
544 AIElement elem3 (m_delegate->m_stack.top());
545 m_delegate->m_stack.pop();
546 const TQValueVector<AIElement> encodingData = elem3.toElementArray();
548 if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotFontEncoding (encodingData, oldFont.latin1(), newFont.latin1());
551void AI88Handler::_handleSetStrokeColorCustom()
553 double g = m_delegate->getDoubleValue();
554 const TQString name = m_delegate->getStringValue();
555 double k = m_delegate->getDoubleValue();
556 double y = m_delegate->getDoubleValue();
557 double m = m_delegate->getDoubleValue();
558 double c = m_delegate->getDoubleValue();
559 if (m_delegate->m_debug) tqDebug (
"values 6 are %f %f %f %f",c,m,y,k);
561 AIColor color (c,m,y,k,name.latin1(),g);
563 if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotStrokeColor (color);