From 8b78a8791bc539bcffe7159f9d9714d577cb3d7d Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 23 May 2021 20:48:35 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro --- filters/karbon/ai/Makefile.am | 16 +- filters/karbon/ai/ai3handler.cc | 74 -- filters/karbon/ai/ai3handler.cpp | 74 ++ filters/karbon/ai/ai88handler.cc | 564 ------------- filters/karbon/ai/ai88handler.cpp | 564 +++++++++++++ filters/karbon/ai/aicolor.cc | 100 --- filters/karbon/ai/aicolor.cpp | 100 +++ filters/karbon/ai/aielement.cc | 804 ------------------ filters/karbon/ai/aielement.cpp | 804 ++++++++++++++++++ filters/karbon/ai/aiimport.cc | 101 --- filters/karbon/ai/aiimport.cpp | 101 +++ filters/karbon/ai/ailexer.cc | 514 ------------ filters/karbon/ai/ailexer.cpp | 514 ++++++++++++ filters/karbon/ai/aiparserbase.cc | 1337 ------------------------------ filters/karbon/ai/aiparserbase.cpp | 1337 ++++++++++++++++++++++++++++++ filters/karbon/ai/karbonaiparserbase.cc | 637 -------------- filters/karbon/ai/karbonaiparserbase.cpp | 637 ++++++++++++++ 17 files changed, 4139 insertions(+), 4139 deletions(-) delete mode 100644 filters/karbon/ai/ai3handler.cc create mode 100644 filters/karbon/ai/ai3handler.cpp delete mode 100644 filters/karbon/ai/ai88handler.cc create mode 100644 filters/karbon/ai/ai88handler.cpp delete mode 100644 filters/karbon/ai/aicolor.cc create mode 100644 filters/karbon/ai/aicolor.cpp delete mode 100644 filters/karbon/ai/aielement.cc create mode 100644 filters/karbon/ai/aielement.cpp delete mode 100644 filters/karbon/ai/aiimport.cc create mode 100644 filters/karbon/ai/aiimport.cpp delete mode 100644 filters/karbon/ai/ailexer.cc create mode 100644 filters/karbon/ai/ailexer.cpp delete mode 100644 filters/karbon/ai/aiparserbase.cc create mode 100644 filters/karbon/ai/aiparserbase.cpp delete mode 100644 filters/karbon/ai/karbonaiparserbase.cc create mode 100644 filters/karbon/ai/karbonaiparserbase.cpp (limited to 'filters/karbon/ai') diff --git a/filters/karbon/ai/Makefile.am b/filters/karbon/ai/Makefile.am index 761feaff..2bbc124d 100644 --- a/filters/karbon/ai/Makefile.am +++ b/filters/karbon/ai/Makefile.am @@ -30,14 +30,14 @@ noinst_HEADERS = \ karbonaiparserbase.h libkarbonaiimport_la_SOURCES = \ - aicolor.cc \ - aielement.cc \ - aiimport.cc \ - ailexer.cc \ - aiparserbase.cc \ - ai88handler.cc \ - ai3handler.cc \ - karbonaiparserbase.cc + aicolor.cpp \ + aielement.cpp \ + aiimport.cpp \ + ailexer.cpp \ + aiparserbase.cpp \ + ai88handler.cpp \ + ai3handler.cpp \ + karbonaiparserbase.cpp libkarbonaiimport_la_METASOURCES = \ AUTO diff --git a/filters/karbon/ai/ai3handler.cc b/filters/karbon/ai/ai3handler.cc deleted file mode 100644 index c014d930..00000000 --- a/filters/karbon/ai/ai3handler.cc +++ /dev/null @@ -1,74 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002, Dirk Schönberger - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "ai3handler.h" - -AI3Handler::AI3Handler(AIParserBase *delegate){ - m_delegate = delegate; -} -AI3Handler::~AI3Handler(){ -} - -bool AI3Handler::handleAIOperation (AIOperation op) { -// PathElement pathElement; -// double fval; - int ival; - - switch (op) { - case AIO_SetWindingOrder : - ival = m_delegate->getIntValue(); - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotWindingOrder (ival); - return true; - break; - case AIO_BeginGroupNoClip : - if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotBeginGroup (false); - return true; - break; - case AIO_EndGroupNoClip : - if (m_delegate->m_debug) tqDebug ("got end group noclip"); - if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotEndGroup (false); - if (m_delegate->m_debug) tqDebug ("/got end group noclip"); - return true; - break; - case AIO_BeginCombination : - if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotBeginCombination (); - return true; - break; - case AIO_EndCombination : - if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotEndCombination (); - return true; - break; - case AIO_BeginGroupClip : - if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotBeginGroup (true); - return true; - break; - case AIO_EndGroupClip : - if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotEndGroup (true); - return true; - break; - case AIO_SetFillMode : - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotFillMode((FillMode) m_delegate->getIntValue()); - return true; - break; - default : - return false; - } - return false; -} - diff --git a/filters/karbon/ai/ai3handler.cpp b/filters/karbon/ai/ai3handler.cpp new file mode 100644 index 00000000..c014d930 --- /dev/null +++ b/filters/karbon/ai/ai3handler.cpp @@ -0,0 +1,74 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schönberger + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "ai3handler.h" + +AI3Handler::AI3Handler(AIParserBase *delegate){ + m_delegate = delegate; +} +AI3Handler::~AI3Handler(){ +} + +bool AI3Handler::handleAIOperation (AIOperation op) { +// PathElement pathElement; +// double fval; + int ival; + + switch (op) { + case AIO_SetWindingOrder : + ival = m_delegate->getIntValue(); + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotWindingOrder (ival); + return true; + break; + case AIO_BeginGroupNoClip : + if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotBeginGroup (false); + return true; + break; + case AIO_EndGroupNoClip : + if (m_delegate->m_debug) tqDebug ("got end group noclip"); + if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotEndGroup (false); + if (m_delegate->m_debug) tqDebug ("/got end group noclip"); + return true; + break; + case AIO_BeginCombination : + if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotBeginCombination (); + return true; + break; + case AIO_EndCombination : + if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotEndCombination (); + return true; + break; + case AIO_BeginGroupClip : + if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotBeginGroup (true); + return true; + break; + case AIO_EndGroupClip : + if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotEndGroup (true); + return true; + break; + case AIO_SetFillMode : + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotFillMode((FillMode) m_delegate->getIntValue()); + return true; + break; + default : + return false; + } + return false; +} + diff --git a/filters/karbon/ai/ai88handler.cc b/filters/karbon/ai/ai88handler.cc deleted file mode 100644 index 87a937ae..00000000 --- a/filters/karbon/ai/ai88handler.cc +++ /dev/null @@ -1,564 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002, Dirk Schönberger - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include -#include "ai88handler.h" - -AI88Handler::AI88Handler(AIParserBase *delegate){ - m_delegate = delegate; -} -AI88Handler::~AI88Handler(){ -} - -bool AI88Handler::handleAIOperation (AIOperation op) { - PathElement pathElement; - double fval; - int ival; - - switch (op) { - case AIO_SetFillColorCMYK : - _handleSetFillColorCMYK(); - return true; - break; - case AIO_SetStrokeColorCMYK : - _handleSetStrokeColorCMYK(); - return true; - break; - case AIO_SetFillColorGray : - _handleSetFillColorGray(); - return true; - break; - case AIO_SetStrokeColorGray : - _handleSetStrokeColorGray(); - return true; - break; - case AIO_SetFillColorCustom : - _handleSetFillColorCustom(); - return true; - break; - case AIO_SetStrokeColorCustom : - _handleSetStrokeColorCustom(); - return true; - break; - case AIO_SetFillPattern : - _handleSetFillPattern(); - return true; - break; - case AIO_SetStrokePattern : - _handleSetStrokePattern(); - return true; - break; - case AIO_SetFillOverprinting : - if (m_delegate->m_miscGStateHandler) m_delegate->m_miscGStateHandler->gotFillOverprinting (m_delegate->getBoolValue()); - return true; - break; - case AIO_SetStrokeOverprinting : - if (m_delegate->m_miscGStateHandler) m_delegate->m_miscGStateHandler->gotStrokeOverprinting (m_delegate->getBoolValue()); - return true; - break; - case AIO_LockElement : - if (m_delegate->m_miscGStateHandler) m_delegate->m_miscGStateHandler->gotLockNextObject (m_delegate->getBoolValue()); - return true; - break; - case AIO_SetFlatness : - fval = m_delegate->getDoubleValue(); - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFlatness (fval); - return true; - break; - case AIO_SetLineCap : - ival = m_delegate->getIntValue(); - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotLineCaps (ival); - return true; - break; - case AIO_SetLineJoin : - ival = m_delegate->getIntValue(); - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotLineJoin (ival); - return true; - break; - case AIO_SetLineWidth : - fval = kMax(0.2, m_delegate->getDoubleValue()); // Use thinnest pen stroke possible for 0 (Rob) - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotLineWidth (fval); - return true; - break; - case AIO_SetMiterLimit : - fval = m_delegate->getDoubleValue(); - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotMiterLimit (fval); - return true; - break; - case AIO_SetDash : - _handleSetDash(); - return true; - break; - case AIO_BeginGroupClip : - if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotBeginGroup (true); - return true; - break; - case AIO_EndGroupClip : - if (m_delegate->m_debug) tqDebug ("got end group clip"); - if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotEndGroup (true); - if (m_delegate->m_debug) tqDebug ("/got end group clip"); - return true; - - break; - case AIO_MoveTo : - pathElement.petype = PET_MoveTo; - pathElement.pttype = PT_Corner; - pathElement.pevalue.pointdata.y = m_delegate->getDoubleValue(); - pathElement.pevalue.pointdata.x = m_delegate->getDoubleValue(); - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); - return true; - break; - case AIO_LineToCorner : - pathElement.petype = PET_LineTo; - pathElement.pttype = PT_Corner; - pathElement.pevalue.pointdata.y = m_delegate->getDoubleValue(); - pathElement.pevalue.pointdata.x = m_delegate->getDoubleValue(); - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); - return true; - break; - case AIO_LineToSmooth : - pathElement.petype = PET_LineTo; - pathElement.pttype = PT_Smooth; - pathElement.pevalue.pointdata.y = m_delegate->getDoubleValue(); - pathElement.pevalue.pointdata.x = m_delegate->getDoubleValue(); - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); - return true; - break; - case AIO_CurveToCorner : - pathElement.petype = PET_CurveTo; - pathElement.pttype = PT_Corner; - pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.y2 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x2 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.y1 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x1 = m_delegate->getDoubleValue(); - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); - return true; - break; - case AIO_CurveToSmooth : - pathElement.petype = PET_CurveTo; - pathElement.pttype = PT_Smooth; - pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.y2 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x2 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.y1 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x1 = m_delegate->getDoubleValue(); - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); - return true; - break; - case AIO_CurveToOmitC1Corner : - pathElement.petype = PET_CurveTo; - pathElement.pttype = PT_Corner; - pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.y2 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x2 = m_delegate->getDoubleValue(); - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); - return true; - break; - case AIO_CurveToOmitC1Smooth : - pathElement.petype = PET_CurveTo; - pathElement.pttype = PT_Smooth; - pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.y2 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x2 = m_delegate->getDoubleValue(); - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); - return true; - break; - case AIO_CurveToOmitC2Corner : - pathElement.petype = PET_CurveTo; - pathElement.pttype = PT_Corner; - pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.y1 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x1 = m_delegate->getDoubleValue(); - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); - return true; - break; - case AIO_CurveToOmitC2Smooth : - pathElement.petype = PET_CurveTo; - pathElement.pttype = PT_Smooth; - pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.y1 = m_delegate->getDoubleValue(); - pathElement.pevalue.bezierdata.x1 = m_delegate->getDoubleValue(); - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); - return true; - break; - - case AIO_PathIgnoreReset : - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotIgnorePath(false, true); - return true; - break; - case AIO_PathIgnoreResetClose : - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotIgnorePath(true, true); - return true; - break; - case AIO_PathIgnoreNoReset : - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotIgnorePath(false, false); - return true; - break; - case AIO_PathIgnoreNoResetClose : - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotIgnorePath(true, false); - return true; - break; - case AIO_PathClipPath : - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotClipPath(false); - return true; - break; - case AIO_PathFillNonZero : - if (m_delegate->m_pathHandler) - { - m_delegate->m_pathHandler->gotFillMode (FM_NonZero); - m_delegate->m_pathHandler->gotFillPath(false, true); - } - return true; - break; - case AIO_PathFillNonZeroClose : - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotFillPath(true, true); - return true; - break; - case AIO_PathFillNoReset : - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotFillPath(false, false); - return true; - break; - case AIO_PathFillNoResetClose : - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotFillPath(true, false); - return true; - break; - case AIO_PathStroke : - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotStrokePath(false); - return true; - break; - case AIO_PathStrokeClose : - if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotStrokePath(true); - return true; - break; - case AIO_PatternDefinition : - _handlePatternDefinition(); - return true; - break; - case AIO_GsaveIncludeDocument : - _handleGsaveIncludeDocument(); - return true; - break; - case AIO_Grestore : - if (m_delegate->m_embeddedHandler) m_delegate->m_embeddedHandler->gotGrestore(); - return true; - break; - case AIO_FontEncoding : - _handleFontEncoding(); - return true; - break; - case AIO_SetCurrentText : - _handleSetCurrentText(); - return true; - break; - case AIO_TextBlockFillStroke : - _handleTextBlock (TO_FillStroke); - return true; - break; - case AIO_TextBlockFill : - _handleTextBlock (TO_Fill); - return true; - break; - case AIO_TextBlockAppend : - _handleTextBlock (TO_Append); - return true; - break; - case AIO_TextBlockIgnore : - _handleTextBlock (TO_Ignore); - return true; - break; - case AIO_TextBlockStroke : - _handleTextBlock (TO_Stroke); - return true; - break; - case AIO_TextOutput : - _handleTextOutput (); - return true; - break; - case AIO_TextBlockEnd : - if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotTextBlockEnd(); - return true; - break; - default : - return false; - } - return false; -} - - -void AI88Handler::_handleSetFillColorCMYK() -{ - double k = m_delegate->getDoubleValue(); - double y = m_delegate->getDoubleValue(); - double m = m_delegate->getDoubleValue(); - double c = m_delegate->getDoubleValue(); - - if (m_delegate->m_debug) tqDebug ("values 1 are %f %f %f %f",c,m,y,k); - AIColor color (c,m,y,k); - - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFillColor (color); -} - -void AI88Handler::_handleSetFillPattern() -{ - AIElement elem (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - - const TQValueVector aval = elem.toElementArray(); - - double ka = m_delegate->getDoubleValue(); - double k = m_delegate->getDoubleValue(); - double r = m_delegate->getDoubleValue(); - double rf = m_delegate->getDoubleValue(); - double angle = m_delegate->getDoubleValue(); - double sy = m_delegate->getDoubleValue(); - double sx = m_delegate->getDoubleValue(); - double py = m_delegate->getDoubleValue(); - double px = m_delegate->getDoubleValue(); - - AIElement elem2 (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - - const TQString &name = elem2.toString(); - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFillPattern (name.latin1(), px, py, sx, sy, angle, rf, r, k, ka, aval); -} - -void AI88Handler::_handleSetStrokePattern() -{ - AIElement elem (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - - const TQValueVector aval = elem.toElementArray(); - - double ka = m_delegate->getDoubleValue(); - double k = m_delegate->getDoubleValue(); - double r = m_delegate->getDoubleValue(); - double rf = m_delegate->getDoubleValue(); - double angle = m_delegate->getDoubleValue(); - double sy = m_delegate->getDoubleValue(); - double sx = m_delegate->getDoubleValue(); - double py = m_delegate->getDoubleValue(); - double px = m_delegate->getDoubleValue(); - - AIElement elem2 (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - - const TQString &name = elem2.toString(); - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotStrokePattern (name.latin1(), px, py, sx, sy, angle, rf, r, k, ka, aval); -} - - -void AI88Handler::_handleSetStrokeColorCMYK() -{ - double k = m_delegate->getDoubleValue(); - double y = m_delegate->getDoubleValue(); - double m = m_delegate->getDoubleValue(); - double c = m_delegate->getDoubleValue(); - if (m_delegate->m_debug) tqDebug ("values 2 are %f %f %f %f",c,m,y,k); - - AIColor color (c,m,y,k); - - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotStrokeColor (color); -} - -void AI88Handler::_handleSetFillColorGray() -{ - double g = m_delegate->getDoubleValue(); - if (m_delegate->m_debug) tqDebug ("values 3 are %f",g); - - AIColor color (g); - - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFillColor (color); -} - -void AI88Handler::_handleSetStrokeColorGray() -{ - double g = m_delegate->getDoubleValue(); - if (m_delegate->m_debug) tqDebug ("values 4 are %f",g); - - AIColor color (g); - - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotStrokeColor (color); -} - -void AI88Handler::_handleSetFillColorCustom() -{ - double g = m_delegate->getDoubleValue(); - const TQString name = m_delegate->getStringValue(); - double k = m_delegate->getDoubleValue(); - double y = m_delegate->getDoubleValue(); - double m = m_delegate->getDoubleValue(); - double c = m_delegate->getDoubleValue(); - if (m_delegate->m_debug) tqDebug ("values 5 are %f %f %f %f",c,m,y,k); - - AIColor color (c,m,y,k,name.latin1(),g); - - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFillColor (color); -} - -void AI88Handler::_handleSetDash() -{ -// tqDebug ("found dash operation"); - double fval = m_delegate->getDoubleValue(); - - AIElement elem (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - - const TQValueVector aval = elem.toElementArray(); - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotDash (aval, fval); -// tqDebug ("dash operation finished"); -} - -void AI88Handler::_handlePatternDefinition() -{ - AIElement elem (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - - const TQValueVector aval = elem.toElementArray(); - - double ury = m_delegate->getDoubleValue(); - double urx = m_delegate->getDoubleValue(); - double lly = m_delegate->getDoubleValue(); - double llx = m_delegate->getDoubleValue(); - - AIElement elem2 (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - - const TQString &name = elem2.toString(); - - if (m_delegate->m_documentHandler) m_delegate->m_documentHandler->gotPatternDefinition (name.latin1(), aval, llx, lly, urx, ury); -} - -void AI88Handler::_handleGsaveIncludeDocument() { - AIElement elem2 (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - - const TQString &name = elem2.toString(); - - int ury = m_delegate->getIntValue(); - int urx = m_delegate->getIntValue(); - int lly = m_delegate->getIntValue(); - int llx = m_delegate->getIntValue(); - - AIElement elem (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - - const TQValueVector aval = elem.toElementArray(); - - if (m_delegate->m_embeddedHandler) m_delegate->m_embeddedHandler->gotGsaveIncludeDocument (aval, llx,lly,urx,ury,name.latin1()); -} - -void AI88Handler::_handleSetCurrentText() { - int iAlign = m_delegate->getIntValue(); - TextAlign ta = TA_HLeft; - - switch (iAlign) - { - case 0 : ta = TA_HLeft; break; - case 1 : ta = TA_HCenter; break; - case 2 : ta = TA_HRight; break; - case 3: ta = TA_VTop; break; - case 4 : ta = TA_VCenter; break; - case 5 : ta = TA_VBottom; break; - } - - double kerning = m_delegate->getDoubleValue(); - double leading = m_delegate->getDoubleValue(); - double size = m_delegate->getDoubleValue(); - - AIElement elem2 (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - - const TQString &fontname = elem2.toReference(); - - if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotFontDefinition (fontname.latin1(), size, leading, kerning, ta); - -} - -void AI88Handler::_handleTextBlock (TextOperation to) { - AIElement elem (m_delegate->m_stack.top()); - tqDebug ("to element is (%s)",elem.typeName()); - m_delegate->m_stack.pop(); - - const TQValueVector aval = elem.toElementArray(); - - if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotTextBlockBegin (aval, to); -} - -void AI88Handler::_handleTextOutput () { - AIElement elem (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - - const TQString &text = elem.toString(); - - int length = -1; - - if (m_delegate->m_stack.empty()) - { - AIElement elem2 (m_delegate->m_stack.top()); - if (elem2.type() == AIElement::Int) - { - length = elem2.asInt(); - m_delegate->m_stack.pop(); - } - } - if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotTextOutput (text.latin1(), length); -} - -void AI88Handler::_handleFontEncoding() -{ - while (m_delegate->m_stack.top().type() != AIElement::Reference) { - m_delegate->m_stack.pop(); - } - - AIElement elem (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - const TQString &oldFont = elem.toReference(); - - AIElement elem2 (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - const TQString &newFont = elem2.toReference(); - - AIElement elem3 (m_delegate->m_stack.top()); - m_delegate->m_stack.pop(); - const TQValueVector encodingData = elem3.toElementArray(); - - if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotFontEncoding (encodingData, oldFont.latin1(), newFont.latin1()); -} - -void AI88Handler::_handleSetStrokeColorCustom() -{ - double g = m_delegate->getDoubleValue(); - const TQString name = m_delegate->getStringValue(); - double k = m_delegate->getDoubleValue(); - double y = m_delegate->getDoubleValue(); - double m = m_delegate->getDoubleValue(); - double c = m_delegate->getDoubleValue(); - if (m_delegate->m_debug) tqDebug ("values 6 are %f %f %f %f",c,m,y,k); - - AIColor color (c,m,y,k,name.latin1(),g); - - if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotStrokeColor (color); -} diff --git a/filters/karbon/ai/ai88handler.cpp b/filters/karbon/ai/ai88handler.cpp new file mode 100644 index 00000000..87a937ae --- /dev/null +++ b/filters/karbon/ai/ai88handler.cpp @@ -0,0 +1,564 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schönberger + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include +#include "ai88handler.h" + +AI88Handler::AI88Handler(AIParserBase *delegate){ + m_delegate = delegate; +} +AI88Handler::~AI88Handler(){ +} + +bool AI88Handler::handleAIOperation (AIOperation op) { + PathElement pathElement; + double fval; + int ival; + + switch (op) { + case AIO_SetFillColorCMYK : + _handleSetFillColorCMYK(); + return true; + break; + case AIO_SetStrokeColorCMYK : + _handleSetStrokeColorCMYK(); + return true; + break; + case AIO_SetFillColorGray : + _handleSetFillColorGray(); + return true; + break; + case AIO_SetStrokeColorGray : + _handleSetStrokeColorGray(); + return true; + break; + case AIO_SetFillColorCustom : + _handleSetFillColorCustom(); + return true; + break; + case AIO_SetStrokeColorCustom : + _handleSetStrokeColorCustom(); + return true; + break; + case AIO_SetFillPattern : + _handleSetFillPattern(); + return true; + break; + case AIO_SetStrokePattern : + _handleSetStrokePattern(); + return true; + break; + case AIO_SetFillOverprinting : + if (m_delegate->m_miscGStateHandler) m_delegate->m_miscGStateHandler->gotFillOverprinting (m_delegate->getBoolValue()); + return true; + break; + case AIO_SetStrokeOverprinting : + if (m_delegate->m_miscGStateHandler) m_delegate->m_miscGStateHandler->gotStrokeOverprinting (m_delegate->getBoolValue()); + return true; + break; + case AIO_LockElement : + if (m_delegate->m_miscGStateHandler) m_delegate->m_miscGStateHandler->gotLockNextObject (m_delegate->getBoolValue()); + return true; + break; + case AIO_SetFlatness : + fval = m_delegate->getDoubleValue(); + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFlatness (fval); + return true; + break; + case AIO_SetLineCap : + ival = m_delegate->getIntValue(); + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotLineCaps (ival); + return true; + break; + case AIO_SetLineJoin : + ival = m_delegate->getIntValue(); + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotLineJoin (ival); + return true; + break; + case AIO_SetLineWidth : + fval = kMax(0.2, m_delegate->getDoubleValue()); // Use thinnest pen stroke possible for 0 (Rob) + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotLineWidth (fval); + return true; + break; + case AIO_SetMiterLimit : + fval = m_delegate->getDoubleValue(); + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotMiterLimit (fval); + return true; + break; + case AIO_SetDash : + _handleSetDash(); + return true; + break; + case AIO_BeginGroupClip : + if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotBeginGroup (true); + return true; + break; + case AIO_EndGroupClip : + if (m_delegate->m_debug) tqDebug ("got end group clip"); + if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotEndGroup (true); + if (m_delegate->m_debug) tqDebug ("/got end group clip"); + return true; + + break; + case AIO_MoveTo : + pathElement.petype = PET_MoveTo; + pathElement.pttype = PT_Corner; + pathElement.pevalue.pointdata.y = m_delegate->getDoubleValue(); + pathElement.pevalue.pointdata.x = m_delegate->getDoubleValue(); + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); + return true; + break; + case AIO_LineToCorner : + pathElement.petype = PET_LineTo; + pathElement.pttype = PT_Corner; + pathElement.pevalue.pointdata.y = m_delegate->getDoubleValue(); + pathElement.pevalue.pointdata.x = m_delegate->getDoubleValue(); + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); + return true; + break; + case AIO_LineToSmooth : + pathElement.petype = PET_LineTo; + pathElement.pttype = PT_Smooth; + pathElement.pevalue.pointdata.y = m_delegate->getDoubleValue(); + pathElement.pevalue.pointdata.x = m_delegate->getDoubleValue(); + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); + return true; + break; + case AIO_CurveToCorner : + pathElement.petype = PET_CurveTo; + pathElement.pttype = PT_Corner; + pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.y2 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x2 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.y1 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x1 = m_delegate->getDoubleValue(); + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); + return true; + break; + case AIO_CurveToSmooth : + pathElement.petype = PET_CurveTo; + pathElement.pttype = PT_Smooth; + pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.y2 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x2 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.y1 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x1 = m_delegate->getDoubleValue(); + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); + return true; + break; + case AIO_CurveToOmitC1Corner : + pathElement.petype = PET_CurveTo; + pathElement.pttype = PT_Corner; + pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.y2 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x2 = m_delegate->getDoubleValue(); + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); + return true; + break; + case AIO_CurveToOmitC1Smooth : + pathElement.petype = PET_CurveTo; + pathElement.pttype = PT_Smooth; + pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.y2 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x2 = m_delegate->getDoubleValue(); + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); + return true; + break; + case AIO_CurveToOmitC2Corner : + pathElement.petype = PET_CurveTo; + pathElement.pttype = PT_Corner; + pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.y1 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x1 = m_delegate->getDoubleValue(); + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); + return true; + break; + case AIO_CurveToOmitC2Smooth : + pathElement.petype = PET_CurveTo; + pathElement.pttype = PT_Smooth; + pathElement.pevalue.bezierdata.y3 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x3 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.y1 = m_delegate->getDoubleValue(); + pathElement.pevalue.bezierdata.x1 = m_delegate->getDoubleValue(); + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotPathElement (pathElement); + return true; + break; + + case AIO_PathIgnoreReset : + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotIgnorePath(false, true); + return true; + break; + case AIO_PathIgnoreResetClose : + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotIgnorePath(true, true); + return true; + break; + case AIO_PathIgnoreNoReset : + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotIgnorePath(false, false); + return true; + break; + case AIO_PathIgnoreNoResetClose : + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotIgnorePath(true, false); + return true; + break; + case AIO_PathClipPath : + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotClipPath(false); + return true; + break; + case AIO_PathFillNonZero : + if (m_delegate->m_pathHandler) + { + m_delegate->m_pathHandler->gotFillMode (FM_NonZero); + m_delegate->m_pathHandler->gotFillPath(false, true); + } + return true; + break; + case AIO_PathFillNonZeroClose : + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotFillPath(true, true); + return true; + break; + case AIO_PathFillNoReset : + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotFillPath(false, false); + return true; + break; + case AIO_PathFillNoResetClose : + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotFillPath(true, false); + return true; + break; + case AIO_PathStroke : + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotStrokePath(false); + return true; + break; + case AIO_PathStrokeClose : + if (m_delegate->m_pathHandler) m_delegate->m_pathHandler->gotStrokePath(true); + return true; + break; + case AIO_PatternDefinition : + _handlePatternDefinition(); + return true; + break; + case AIO_GsaveIncludeDocument : + _handleGsaveIncludeDocument(); + return true; + break; + case AIO_Grestore : + if (m_delegate->m_embeddedHandler) m_delegate->m_embeddedHandler->gotGrestore(); + return true; + break; + case AIO_FontEncoding : + _handleFontEncoding(); + return true; + break; + case AIO_SetCurrentText : + _handleSetCurrentText(); + return true; + break; + case AIO_TextBlockFillStroke : + _handleTextBlock (TO_FillStroke); + return true; + break; + case AIO_TextBlockFill : + _handleTextBlock (TO_Fill); + return true; + break; + case AIO_TextBlockAppend : + _handleTextBlock (TO_Append); + return true; + break; + case AIO_TextBlockIgnore : + _handleTextBlock (TO_Ignore); + return true; + break; + case AIO_TextBlockStroke : + _handleTextBlock (TO_Stroke); + return true; + break; + case AIO_TextOutput : + _handleTextOutput (); + return true; + break; + case AIO_TextBlockEnd : + if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotTextBlockEnd(); + return true; + break; + default : + return false; + } + return false; +} + + +void AI88Handler::_handleSetFillColorCMYK() +{ + double k = m_delegate->getDoubleValue(); + double y = m_delegate->getDoubleValue(); + double m = m_delegate->getDoubleValue(); + double c = m_delegate->getDoubleValue(); + + if (m_delegate->m_debug) tqDebug ("values 1 are %f %f %f %f",c,m,y,k); + AIColor color (c,m,y,k); + + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFillColor (color); +} + +void AI88Handler::_handleSetFillPattern() +{ + AIElement elem (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const TQValueVector aval = elem.toElementArray(); + + double ka = m_delegate->getDoubleValue(); + double k = m_delegate->getDoubleValue(); + double r = m_delegate->getDoubleValue(); + double rf = m_delegate->getDoubleValue(); + double angle = m_delegate->getDoubleValue(); + double sy = m_delegate->getDoubleValue(); + double sx = m_delegate->getDoubleValue(); + double py = m_delegate->getDoubleValue(); + double px = m_delegate->getDoubleValue(); + + AIElement elem2 (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const TQString &name = elem2.toString(); + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFillPattern (name.latin1(), px, py, sx, sy, angle, rf, r, k, ka, aval); +} + +void AI88Handler::_handleSetStrokePattern() +{ + AIElement elem (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const TQValueVector aval = elem.toElementArray(); + + double ka = m_delegate->getDoubleValue(); + double k = m_delegate->getDoubleValue(); + double r = m_delegate->getDoubleValue(); + double rf = m_delegate->getDoubleValue(); + double angle = m_delegate->getDoubleValue(); + double sy = m_delegate->getDoubleValue(); + double sx = m_delegate->getDoubleValue(); + double py = m_delegate->getDoubleValue(); + double px = m_delegate->getDoubleValue(); + + AIElement elem2 (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const TQString &name = elem2.toString(); + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotStrokePattern (name.latin1(), px, py, sx, sy, angle, rf, r, k, ka, aval); +} + + +void AI88Handler::_handleSetStrokeColorCMYK() +{ + double k = m_delegate->getDoubleValue(); + double y = m_delegate->getDoubleValue(); + double m = m_delegate->getDoubleValue(); + double c = m_delegate->getDoubleValue(); + if (m_delegate->m_debug) tqDebug ("values 2 are %f %f %f %f",c,m,y,k); + + AIColor color (c,m,y,k); + + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotStrokeColor (color); +} + +void AI88Handler::_handleSetFillColorGray() +{ + double g = m_delegate->getDoubleValue(); + if (m_delegate->m_debug) tqDebug ("values 3 are %f",g); + + AIColor color (g); + + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFillColor (color); +} + +void AI88Handler::_handleSetStrokeColorGray() +{ + double g = m_delegate->getDoubleValue(); + if (m_delegate->m_debug) tqDebug ("values 4 are %f",g); + + AIColor color (g); + + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotStrokeColor (color); +} + +void AI88Handler::_handleSetFillColorCustom() +{ + double g = m_delegate->getDoubleValue(); + const TQString name = m_delegate->getStringValue(); + double k = m_delegate->getDoubleValue(); + double y = m_delegate->getDoubleValue(); + double m = m_delegate->getDoubleValue(); + double c = m_delegate->getDoubleValue(); + if (m_delegate->m_debug) tqDebug ("values 5 are %f %f %f %f",c,m,y,k); + + AIColor color (c,m,y,k,name.latin1(),g); + + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotFillColor (color); +} + +void AI88Handler::_handleSetDash() +{ +// tqDebug ("found dash operation"); + double fval = m_delegate->getDoubleValue(); + + AIElement elem (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const TQValueVector aval = elem.toElementArray(); + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotDash (aval, fval); +// tqDebug ("dash operation finished"); +} + +void AI88Handler::_handlePatternDefinition() +{ + AIElement elem (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const TQValueVector aval = elem.toElementArray(); + + double ury = m_delegate->getDoubleValue(); + double urx = m_delegate->getDoubleValue(); + double lly = m_delegate->getDoubleValue(); + double llx = m_delegate->getDoubleValue(); + + AIElement elem2 (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const TQString &name = elem2.toString(); + + if (m_delegate->m_documentHandler) m_delegate->m_documentHandler->gotPatternDefinition (name.latin1(), aval, llx, lly, urx, ury); +} + +void AI88Handler::_handleGsaveIncludeDocument() { + AIElement elem2 (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const TQString &name = elem2.toString(); + + int ury = m_delegate->getIntValue(); + int urx = m_delegate->getIntValue(); + int lly = m_delegate->getIntValue(); + int llx = m_delegate->getIntValue(); + + AIElement elem (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const TQValueVector aval = elem.toElementArray(); + + if (m_delegate->m_embeddedHandler) m_delegate->m_embeddedHandler->gotGsaveIncludeDocument (aval, llx,lly,urx,ury,name.latin1()); +} + +void AI88Handler::_handleSetCurrentText() { + int iAlign = m_delegate->getIntValue(); + TextAlign ta = TA_HLeft; + + switch (iAlign) + { + case 0 : ta = TA_HLeft; break; + case 1 : ta = TA_HCenter; break; + case 2 : ta = TA_HRight; break; + case 3: ta = TA_VTop; break; + case 4 : ta = TA_VCenter; break; + case 5 : ta = TA_VBottom; break; + } + + double kerning = m_delegate->getDoubleValue(); + double leading = m_delegate->getDoubleValue(); + double size = m_delegate->getDoubleValue(); + + AIElement elem2 (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const TQString &fontname = elem2.toReference(); + + if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotFontDefinition (fontname.latin1(), size, leading, kerning, ta); + +} + +void AI88Handler::_handleTextBlock (TextOperation to) { + AIElement elem (m_delegate->m_stack.top()); + tqDebug ("to element is (%s)",elem.typeName()); + m_delegate->m_stack.pop(); + + const TQValueVector aval = elem.toElementArray(); + + if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotTextBlockBegin (aval, to); +} + +void AI88Handler::_handleTextOutput () { + AIElement elem (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const TQString &text = elem.toString(); + + int length = -1; + + if (m_delegate->m_stack.empty()) + { + AIElement elem2 (m_delegate->m_stack.top()); + if (elem2.type() == AIElement::Int) + { + length = elem2.asInt(); + m_delegate->m_stack.pop(); + } + } + if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotTextOutput (text.latin1(), length); +} + +void AI88Handler::_handleFontEncoding() +{ + while (m_delegate->m_stack.top().type() != AIElement::Reference) { + m_delegate->m_stack.pop(); + } + + AIElement elem (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + const TQString &oldFont = elem.toReference(); + + AIElement elem2 (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + const TQString &newFont = elem2.toReference(); + + AIElement elem3 (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + const TQValueVector encodingData = elem3.toElementArray(); + + if (m_delegate->m_textHandler) m_delegate->m_textHandler->gotFontEncoding (encodingData, oldFont.latin1(), newFont.latin1()); +} + +void AI88Handler::_handleSetStrokeColorCustom() +{ + double g = m_delegate->getDoubleValue(); + const TQString name = m_delegate->getStringValue(); + double k = m_delegate->getDoubleValue(); + double y = m_delegate->getDoubleValue(); + double m = m_delegate->getDoubleValue(); + double c = m_delegate->getDoubleValue(); + if (m_delegate->m_debug) tqDebug ("values 6 are %f %f %f %f",c,m,y,k); + + AIColor color (c,m,y,k,name.latin1(),g); + + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotStrokeColor (color); +} diff --git a/filters/karbon/ai/aicolor.cc b/filters/karbon/ai/aicolor.cc deleted file mode 100644 index cabc932f..00000000 --- a/filters/karbon/ai/aicolor.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002, Dirk Schönberger - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "aicolor.h" -#include - -AIColor::AIColor(){ - ctype = AIColor::CT_CMYK; - cdata.cmykdata.cvalue = 0; - cdata.cmykdata.mvalue = 0; - cdata.cmykdata.yvalue = 0; - cdata.cmykdata.kvalue = 0; -} - -AIColor::AIColor( const AIColor& value ){ - ctype = value.ctype; - memcpy (&cdata, &value.cdata, sizeof (cdata)); -} -AIColor::AIColor( double c, double m, double y, double k ){ - ctype = AIColor::CT_CMYK; - cdata.cmykdata.cvalue = c; - cdata.cmykdata.mvalue = m; - cdata.cmykdata.yvalue = y; - cdata.cmykdata.kvalue = k; -} -AIColor::AIColor( double c, double m, double y, double k, const char* colorname, double gray ){ - ctype = AIColor::CT_CMYK_Key; - cdata.cmykdata.cvalue = c; - cdata.cmykdata.mvalue = m; - cdata.cmykdata.yvalue = y; - cdata.cmykdata.kvalue = k; - cdata.cmykdata.colorname = strdup (colorname); -} -AIColor::AIColor( double gray ){ - ctype = AIColor::CT_Gray; - cdata.graydata = gray; -} - -AIColor::~AIColor(){ -} - -void AIColor::toRGB (double &r, double &g, double &b) -{ - switch (ctype) - { - case CT_CMYK : - case CT_CMYK_Key : - r = 1 - cdata.cmykdata.cvalue - cdata.cmykdata.kvalue; - g = 1 - cdata.cmykdata.mvalue - cdata.cmykdata.kvalue; - b = 1 - cdata.cmykdata.yvalue - cdata.cmykdata.kvalue; - break; - case CT_Gray : - r = cdata.graydata; - g = cdata.graydata; - b = cdata.graydata; - break; - default : - tqDebug ("unknown colortype %d", ctype); - } -} - -void AIColor::toCMYK (double &c, double &m, double &y, double &k) -{ - switch (ctype) - { - case CT_CMYK : - case CT_CMYK_Key : - c = cdata.cmykdata.cvalue; - m = cdata.cmykdata.mvalue; - y = cdata.cmykdata.yvalue; - k = cdata.cmykdata.kvalue; - break; - case CT_Gray : - c = 0; - m = 0; - y = 0; - k = cdata.graydata; - break; - default : - tqDebug ("unknown colortype %d", ctype); - } -} - - diff --git a/filters/karbon/ai/aicolor.cpp b/filters/karbon/ai/aicolor.cpp new file mode 100644 index 00000000..cabc932f --- /dev/null +++ b/filters/karbon/ai/aicolor.cpp @@ -0,0 +1,100 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schönberger + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "aicolor.h" +#include + +AIColor::AIColor(){ + ctype = AIColor::CT_CMYK; + cdata.cmykdata.cvalue = 0; + cdata.cmykdata.mvalue = 0; + cdata.cmykdata.yvalue = 0; + cdata.cmykdata.kvalue = 0; +} + +AIColor::AIColor( const AIColor& value ){ + ctype = value.ctype; + memcpy (&cdata, &value.cdata, sizeof (cdata)); +} +AIColor::AIColor( double c, double m, double y, double k ){ + ctype = AIColor::CT_CMYK; + cdata.cmykdata.cvalue = c; + cdata.cmykdata.mvalue = m; + cdata.cmykdata.yvalue = y; + cdata.cmykdata.kvalue = k; +} +AIColor::AIColor( double c, double m, double y, double k, const char* colorname, double gray ){ + ctype = AIColor::CT_CMYK_Key; + cdata.cmykdata.cvalue = c; + cdata.cmykdata.mvalue = m; + cdata.cmykdata.yvalue = y; + cdata.cmykdata.kvalue = k; + cdata.cmykdata.colorname = strdup (colorname); +} +AIColor::AIColor( double gray ){ + ctype = AIColor::CT_Gray; + cdata.graydata = gray; +} + +AIColor::~AIColor(){ +} + +void AIColor::toRGB (double &r, double &g, double &b) +{ + switch (ctype) + { + case CT_CMYK : + case CT_CMYK_Key : + r = 1 - cdata.cmykdata.cvalue - cdata.cmykdata.kvalue; + g = 1 - cdata.cmykdata.mvalue - cdata.cmykdata.kvalue; + b = 1 - cdata.cmykdata.yvalue - cdata.cmykdata.kvalue; + break; + case CT_Gray : + r = cdata.graydata; + g = cdata.graydata; + b = cdata.graydata; + break; + default : + tqDebug ("unknown colortype %d", ctype); + } +} + +void AIColor::toCMYK (double &c, double &m, double &y, double &k) +{ + switch (ctype) + { + case CT_CMYK : + case CT_CMYK_Key : + c = cdata.cmykdata.cvalue; + m = cdata.cmykdata.mvalue; + y = cdata.cmykdata.yvalue; + k = cdata.cmykdata.kvalue; + break; + case CT_Gray : + c = 0; + m = 0; + y = 0; + k = cdata.graydata; + break; + default : + tqDebug ("unknown colortype %d", ctype); + } +} + + diff --git a/filters/karbon/ai/aielement.cc b/filters/karbon/ai/aielement.cc deleted file mode 100644 index 2f514d06..00000000 --- a/filters/karbon/ai/aielement.cc +++ /dev/null @@ -1,804 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002, Dirk Schönberger - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "aielement.h" -#include - -AIElement::Private::Private() -{ - typ = AIElement::Invalid; -} - -AIElement::Private::Private( Private* d ) -{ - switch( d->typ ) - { - case AIElement::Invalid: - break; - case AIElement::String: - case AIElement::Reference: - case AIElement::Operator: - value.ptr = new TQString( *((TQString*)d->value.ptr) ); - break; - case AIElement::CString: - // TQCString is explicit shared - value.ptr = new TQCString( *((TQCString*)d->value.ptr) ); - break; -/* case AIElement::List: - value.ptr = new TQValueList( *((TQValueList*)d->value.ptr) ); - break; */ - case AIElement::ElementArray: - value.ptr = new TQValueVector( *((TQValueVector*)d->value.ptr) ); - break; - case AIElement::Block: - value.ptr = new TQValueVector( *((TQValueVector*)d->value.ptr) ); - break; - case AIElement::ByteArray: - value.ptr = new TQByteArray( *((TQByteArray*)d->value.ptr) ); - break; - case AIElement::Int: - value.i = d->value.i; - break; - case AIElement::UInt: - value.u = d->value.u; - break; - case AIElement::Double: - value.d = d->value.d; - break; - case AIElement::Byte: - value.b = d->value.b; - break; - default: - Q_ASSERT( 0 ); - } - - typ = d->typ; -} - -AIElement::Private::~Private() -{ - clear(); -} - -void AIElement::Private::clear() -{ - switch( typ ) - { - case AIElement::String: - case AIElement::Operator: - case AIElement::Reference: - delete (TQString*)value.ptr; - break; - case AIElement::CString: - delete (TQCString*)value.ptr; - break; -/* case AIElement::List: - delete (TQValueList*)value.ptr; - break; */ - case AIElement::ElementArray: - delete (TQValueVector*)value.ptr; - break; - case AIElement::Block: - delete (TQValueVector*)value.ptr; - break; - case AIElement::ByteArray: - delete (TQByteArray*)value.ptr; - break; - case AIElement::Invalid: - case AIElement::Int: - case AIElement::UInt: - case AIElement::Double: - case AIElement::Byte: - break; - } - - typ = AIElement::Invalid; -} - -/*! - Constructs an invalid aielement. -*/ -AIElement::AIElement() -{ - d = new Private; -} - -/*! - Destroys the AIElement and the contained object. - - Note that subclasses that reimplement clear() should reimplement - the destructor to call clear(). This destructor calls clear(), but - because it is the destructor, AIElement::clear() is called rather than - a subclass's clear(). -*/ -AIElement::~AIElement() -{ - if ( d->deref() ) - delete d; -} - -/*! - Constructs a copy of the aielement, \a p, passed as the argument to this - constructor. Usually this is a deep copy, but a shallow copy is made - if the stored data type is explicitly shared, as e.g. TQImage is. -*/ -AIElement::AIElement( const AIElement& p ) -{ - d = new Private; - *this = p; -} - -/*! - Constructs a new aielement with a string value, \a val. -*/ -AIElement::AIElement( const TQString& val, Type type ) -{ - d = new Private; - d->typ = type; - d->value.ptr = new TQString( val ); -} - -/*! - Constructs a new aielement with a C-string value, \a val. - - If you want to modify the TQCString after you've passed it to this - constructor, we recommend passing a deep copy (see - TQCString::copy()). -*/ -AIElement::AIElement( const TQCString& val ) -{ - d = new Private; - d->typ = CString; - d->value.ptr = new TQCString( val ); -} - -/*! - Constructs a new aielement with a C-string value of \a val if \a val - is non-null. The aielement creates a deep copy of \a val. - - If \a val is null, the resulting aielement has type Invalid. -*/ -AIElement::AIElement( const char* val ) -{ - d = new Private; - if ( val == 0 ) - return; - d->typ = CString; - d->value.ptr = new TQCString( val ); -} - -/*! - Constructs a new aielement with an integer value, \a val. -*/ -AIElement::AIElement( int val ) -{ - d = new Private; - d->typ = Int; - d->value.i = val; -} - -/*! - Constructs a new aielement with an unsigned integer value, \a val. -*/ -AIElement::AIElement( uint val ) -{ - d = new Private; - d->typ = UInt; - d->value.u = val; -} - -/*! - Constructs a new aielement with an byte value, \a val. -*/ -AIElement::AIElement( uchar val ) -{ - d = new Private; - d->typ = Byte; - d->value.b = val; -} - - -/*! - Constructs a new aielement with a floating point value, \a val. -*/ -AIElement::AIElement( double val ) -{ - d = new Private; - d->typ = Double; - d->value.d = val; -} - -/*! - Constructs a new aielement with a list value, \a val. -*/ -/* AIElement::AIElement( const TQValueList& val ) -{ - d = new Private; - d->typ = List; - d->value.ptr = new TQValueList( val ); -} */ - -AIElement::AIElement( const TQValueVector& val, Type type ) -{ - d = new Private; - d->typ = type; - d->value.ptr = new TQValueVector( val ); -} - -AIElement::AIElement( const TQByteArray& val ) -{ - d = new Private; - d->typ = ByteArray; - d->value.ptr = new TQByteArray( val ); -} - -/*! - Assigns the value of the aielement \a aielement to this aielement. - - This is a deep copy of the aielement, but note that if the aielement - holds an explicitly shared type such as TQImage, a shallow copy - is performed. -*/ -AIElement& AIElement::operator= ( const AIElement& aielement ) -{ - AIElement& other = (AIElement&)aielement; - - other.d->ref(); - if ( d->deref() ) - delete d; - - d = other.d; - - return *this; -} - -/*! - \internal -*/ -void AIElement::detach() -{ - if ( d->count == 1 ) - return; - - d->deref(); - d = new Private( d ); -} - -/*! - Returns the name of the type stored in the aielement. - The returned strings describe the C++ datatype used to store the - data: for example, "TQFont", TQSTRING_OBJECT_NAME_STRING, or "TQValueList". - An Invalid aielement returns 0. -*/ -const char* AIElement::typeName() const -{ - return typeToName( d->typ ); -} - -/*! Convert this aielement to type Invalid and free up any resources - used. -*/ -void AIElement::clear() -{ - if ( d->count > 1 ) - { - d->deref(); - d = new Private; - return; - } - - d->clear(); -} - -static const int ntypes = 11; -static const char* const type_map[ntypes] = -{ - 0, -// "TQValueList", - TQSTRING_OBJECT_NAME_STRING, - "int", - "uint", - "double", - "TQCString", - "Operator", - "Reference", - "TQValueVector", - TQBYTEARRAY_OBJECT_NAME_STRING, - "uchar", -}; - -/*! - Converts the enum representation of the storage type, \a typ, to its - string representation. -*/ -const char* AIElement::typeToName( Type typ ) -{ - if ( typ >= ntypes ) - return 0; - return type_map[typ]; -} - -/*! - Converts the string representation of the storage type gven in \a - name, to its enum representation. - - If the string representation cannot be converted to any enum - representation, the aielement is set to \c Invalid. -*/ -AIElement::Type AIElement::nameToType( const char* name ) -{ - for ( int i = 0; i < ntypes; i++ ) { - if ( !qstrcmp( type_map[i], name ) ) - return (Type) i; - } - return Invalid; -} - -/*! - Returns the aielement as a TQString if the aielement has type() - String, CString, ByteArray, Int, Uint, Double, - or TQString() otherwise. - - \sa asString() -*/ -const TQString AIElement::toString() const -{ - if ( d->typ == CString ) - return TQString::fromLatin1( toCString() ); - if ( d->typ == Int ) - return TQString::number( toInt() ); - if ( d->typ == UInt ) - return TQString::number( toUInt() ); - if ( d->typ == Double ) - return TQString::number( toDouble() ); - if ( d->typ == Byte ) - return TQString::number( toByte() ); - if ( d->typ != String ) - return TQString(); - return *((TQString*)d->value.ptr); -} - -const TQString AIElement::toReference() const -{ - if ( d->typ != Reference ) - return TQString(); - return *((TQString*)d->value.ptr); -} - -const TQString AIElement::toOperator() const -{ - if ( d->typ != Operator ) - return TQString(); - return *((TQString*)d->value.ptr); -} - -/*! - Returns the aielement as a TQCString if the aielement has type() - CString or String, or a 0 otherwise. - - \sa asCString() -*/ -const TQCString AIElement::toCString() const -{ - if ( d->typ == CString ) - return *((TQCString*)d->value.ptr); - if ( d->typ == String ) - return ((TQString*)d->value.ptr)->latin1(); - if ( d->typ == Operator ) - return ((TQString*)d->value.ptr)->latin1(); - if ( d->typ == Reference ) - return ((TQString*)d->value.ptr)->latin1(); - - return 0; -} - - -/*! - Returns the aielement as an int if the aielement has type() - String, CString, Int, UInt, Double, Byte, or 0 otherwise. - - If \a ok is non-null, \a *ok is set to TRUE if the value could be - converted to an int and FALSE otherwise. - - \sa asInt() canCast() -*/ -int AIElement::toInt( bool * ok ) const -{ - if( d->typ == String ) - return ((TQString*)d->value.ptr)->toInt( ok ); - if ( d->typ == CString ) - return ((TQCString*)d->value.ptr)->toInt( ok ); - if ( ok ) - *ok = canCast( UInt ); - if( d->typ == Int ) - return d->value.i; - if( d->typ == UInt ) - return (int)d->value.u; - if( d->typ == Byte ) - return (int)d->value.b; - if ( d->typ == Double ) - return (int)d->value.d; - return 0; -} - -uchar AIElement::toByte( bool * ok ) const -{ - if( d->typ == String ) - return ((TQString*)d->value.ptr)->toShort( ok ); - if ( d->typ == CString ) - return ((TQCString*)d->value.ptr)->toShort( ok ); - if ( ok ) - *ok = canCast( UInt ); - if( d->typ == Byte ) - return d->value.b; - if( d->typ == Int ) - return (uchar)d->value.i; - if( d->typ == UInt ) - return (uchar)d->value.u; - if ( d->typ == Double ) - return (uchar)d->value.d; - return 0; -} - - -/*! - Returns the aielement as an unsigned int if the aielement has type() - String, CString, UInt, Int, Double, Byte, or 0 otherwise. - - If \a ok is non-null, \a *ok is set to TRUE if the value could be - converted to a uint and FALSE otherwise. - - \sa asUInt() -*/ -uint AIElement::toUInt( bool * ok ) const -{ - if( d->typ == String ) - return ((TQString*)d->value.ptr)->toUInt( ok ); - if ( d->typ == CString ) - return ((TQCString*)d->value.ptr)->toUInt( ok ); - if ( ok ) - *ok = canCast( UInt ); - if( d->typ == Int ) - return d->value.i; - if( d->typ == UInt ) - return (int)d->value.u; - if( d->typ == Byte ) - return (int)d->value.b; - if ( d->typ == Double ) - return (int)d->value.d; - - return 0; -} - -/*! - Returns the aielement as a double if the aielement has type() - String, CString, Double, Int, UInt, Byte, or 0.0 otherwise. - - If \a ok is non-null, \a *ok is set to TRUE if the value could be - converted to a double and FALSE otherwise. - - \sa asDouble() -*/ -double AIElement::toDouble( bool * ok ) const -{ - if( d->typ == String ) - return ((TQString*)d->value.ptr)->toDouble( ok ); - if ( d->typ == CString ) - return ((TQCString*)d->value.ptr)->toDouble( ok ); - if ( ok ) - *ok = canCast( Double ); - if ( d->typ == Double ) - return d->value.d; - if ( d->typ == Int ) - return (double)d->value.i; - if ( d->typ == UInt ) - return (double)d->value.u; - if ( d->typ == Byte ) - return (double)d->value.b; - return 0.0; -} - -/*! - Returns the aielement as a TQValueList if the aielement has type() - List or StringList, or an empty list otherwise. - - Note that if you want to iterate over the list, you should - iterate over a copy, e.g. - \code - TQValueList list = myAIElement.toList(); - TQValueList::Iterator it = list.begin(); - while( it != list.end() ) { - myProcessing( *it ); - ++it; - } - \endcode - - \sa asList() -*/ -/* const TQValueList AIElement::toList() const -{ - if ( d->typ == List ) - return *((TQValueList*)d->value.ptr); - return TQValueList(); -} */ - -const TQValueVector AIElement::toElementArray() const -{ - if ( d->typ == ElementArray ) - return *((TQValueVector*)d->value.ptr); - return TQValueVector(); -} - -const TQValueVector AIElement::toBlock() const -{ - if ( d->typ == Block ) - return *((TQValueVector*)d->value.ptr); - return TQValueVector(); -} - - -const TQByteArray AIElement::toByteArray() const -{ - if ( d->typ == ByteArray ) - return *((TQByteArray*)d->value.ptr); - return TQByteArray(); -} - -#define TQ_VARIANT_AS( f ) TQ##f& AIElement::as##f() { \ - if ( d->typ != f ) *this = AIElement( to##f() ); else detach(); return *((TQ##f*)d->value.ptr);} - -TQ_VARIANT_AS(String) -TQ_VARIANT_AS(CString) - -/*! - Returns the aielement's value as int reference. -*/ -int& AIElement::asInt() -{ - detach(); - if ( d->typ != Int ) { - int i = toInt(); - d->clear(); - d->value.i = i; - d->typ = Int; - } - return d->value.i; -} - -/*! - Returns the aielement's value as unsigned int reference. -*/ -uint& AIElement::asUInt() -{ - detach(); - if ( d->typ != UInt ) { - uint u = toUInt(); - d->clear(); - d->value.u = u; - d->typ = UInt; - } - return d->value.u; -} - -/*! - Returns the aielement's value as double reference. -*/ -double& AIElement::asDouble() -{ - if ( d->typ != Double ) { - double dbl = toDouble(); - d->clear(); - d->value.d = dbl; - d->typ = Double; - } - return d->value.d; -} - -/*! - Returns the aielement's value as byte reference. -*/ -uchar& AIElement::asByte() -{ - detach(); - if ( d->typ != Byte ) { - uchar b = toByte(); - d->clear(); - d->value.b = b; - d->typ = Byte; - } - return d->value.b; -} - - -/*! - Returns the aielement's value as aielement list reference. - - Note that if you want to iterate over the list, you should - iterate over a copy, e.g. - \code - TQValueList list = myAIElement.asList(); - TQValueList::Iterator it = list.begin(); - while( it != list.end() ) { - myProcessing( *it ); - ++it; - } - \endcode -*/ -/* TQValueList& AIElement::asList() -{ - if ( d->typ != List ) - *this = AIElement( toList() ); - return *((TQValueList*)d->value.ptr); -} */ - -TQValueVector& AIElement::asElementArray() -{ - if ( d->typ != ElementArray ) - *this = AIElement( toElementArray() ); - return *((TQValueVector*)d->value.ptr); -} - -TQValueVector& AIElement::asBlock() -{ - if ( d->typ != Block ) - *this = AIElement( toBlock() ); - return *((TQValueVector*)d->value.ptr); -} - - -TQByteArray& AIElement::asByteArray() -{ - if ( d->typ != ByteArray ) - *this = AIElement( toByteArray() ); - return *((TQByteArray*)d->value.ptr); -} - -/*! - Returns TRUE if the aielement's type can be cast to the requested - type, \p t. Such casting is done automatically when calling the - toInt(), ... or asInt(), ... methods. - - The following casts are done automatically: -
    -
  • CString => String -
  • Double => String, Int, UInt -
  • Int => String, Double, UInt -
  • String => CString, Int, Uint, Double -
  • UInt => String, Double, Int -
-*/ -bool AIElement::canCast( Type t ) const -{ - if ( d->typ == t ) - return TRUE; - if ( t == Int && ( d->typ == String || d->typ == Double || d->typ == UInt || d->typ == Byte) ) - return TRUE; - if ( t == UInt && ( d->typ == String || d->typ == Double || d->typ == Int || d->typ == Byte) ) - return TRUE; - if ( t == Double && ( d->typ == String || d->typ == Int || d->typ == UInt || d->typ == Byte) ) - return TRUE; - if ( t == CString && d->typ == String ) - return TRUE; - if ( t == String && ( d->typ == CString || d->typ == Int || d->typ == UInt || d->typ == Double || d->typ == Byte) ) - return TRUE; - - return FALSE; -} - -/*! - \brief Casts the aielement to the requested type. - - If the cast cannot be - done, the aielement is set to the default value of the requested type - (e.g. an empty string if the requested type \p t is - AIElement::String, an empty point array if the requested type \p t is - AIElement::PointArray, etc). - - \returns TRUE if the current type of the - aielement was successfully casted; otherwise returns FALSE. - - \see canCast() -*/ - -bool AIElement::cast( Type t ) -{ - switch ( t ) { -/* case AIElement::List: - asList(); - break; */ - case AIElement::ElementArray: - asElementArray(); - break; - case AIElement::Block: - asBlock(); - break; - case AIElement::String: - asString(); - break; - case AIElement::Int: - asInt(); - break; - case AIElement::UInt: - asUInt(); - break; - case AIElement::Double: - asDouble(); - break; - case AIElement::CString: - asCString(); - break; - case AIElement::Byte: - asByte(); - break; - case AIElement::ByteArray: - asByteArray(); - break; - default: - case AIElement::Invalid: - (*this) = AIElement(); - } - return canCast( t ); -} - -/*! Compares this AIElement with \a v and returns TRUE if they are - equal; otherwise returns FALSE. -*/ - -bool AIElement::operator==( const AIElement &v ) const -{ - if ( !v.canCast( type() ) ) - return FALSE; - switch( d->typ ) { -/* case List: - return v.toList() == toList(); */ - case ElementArray: - return v.toElementArray() == toElementArray(); - case Block: - return v.toBlock() == toBlock(); - case ByteArray: - return v.toByteArray() == toByteArray(); - - case String: - return v.toString() == toString(); - case Operator: - return v.toOperator() == toOperator(); - case Reference: - return v.toReference() == toReference(); - case CString: - return v.toCString() == toCString(); - case Int: - return v.toInt() == toInt(); - case UInt: - return v.toUInt() == toUInt(); - case Byte: - return v.toByte() == toByte(); - case Invalid: - break; - } - return FALSE; -} - -/*! Compares this AIElement with \a v and returns TRUE if they are - not equal; otherwise returns FALSE. -*/ - -bool AIElement::operator!=( const AIElement &v ) const -{ - return !( v == *this ); -} diff --git a/filters/karbon/ai/aielement.cpp b/filters/karbon/ai/aielement.cpp new file mode 100644 index 00000000..2f514d06 --- /dev/null +++ b/filters/karbon/ai/aielement.cpp @@ -0,0 +1,804 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schönberger + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "aielement.h" +#include + +AIElement::Private::Private() +{ + typ = AIElement::Invalid; +} + +AIElement::Private::Private( Private* d ) +{ + switch( d->typ ) + { + case AIElement::Invalid: + break; + case AIElement::String: + case AIElement::Reference: + case AIElement::Operator: + value.ptr = new TQString( *((TQString*)d->value.ptr) ); + break; + case AIElement::CString: + // TQCString is explicit shared + value.ptr = new TQCString( *((TQCString*)d->value.ptr) ); + break; +/* case AIElement::List: + value.ptr = new TQValueList( *((TQValueList*)d->value.ptr) ); + break; */ + case AIElement::ElementArray: + value.ptr = new TQValueVector( *((TQValueVector*)d->value.ptr) ); + break; + case AIElement::Block: + value.ptr = new TQValueVector( *((TQValueVector*)d->value.ptr) ); + break; + case AIElement::ByteArray: + value.ptr = new TQByteArray( *((TQByteArray*)d->value.ptr) ); + break; + case AIElement::Int: + value.i = d->value.i; + break; + case AIElement::UInt: + value.u = d->value.u; + break; + case AIElement::Double: + value.d = d->value.d; + break; + case AIElement::Byte: + value.b = d->value.b; + break; + default: + Q_ASSERT( 0 ); + } + + typ = d->typ; +} + +AIElement::Private::~Private() +{ + clear(); +} + +void AIElement::Private::clear() +{ + switch( typ ) + { + case AIElement::String: + case AIElement::Operator: + case AIElement::Reference: + delete (TQString*)value.ptr; + break; + case AIElement::CString: + delete (TQCString*)value.ptr; + break; +/* case AIElement::List: + delete (TQValueList*)value.ptr; + break; */ + case AIElement::ElementArray: + delete (TQValueVector*)value.ptr; + break; + case AIElement::Block: + delete (TQValueVector*)value.ptr; + break; + case AIElement::ByteArray: + delete (TQByteArray*)value.ptr; + break; + case AIElement::Invalid: + case AIElement::Int: + case AIElement::UInt: + case AIElement::Double: + case AIElement::Byte: + break; + } + + typ = AIElement::Invalid; +} + +/*! + Constructs an invalid aielement. +*/ +AIElement::AIElement() +{ + d = new Private; +} + +/*! + Destroys the AIElement and the contained object. + + Note that subclasses that reimplement clear() should reimplement + the destructor to call clear(). This destructor calls clear(), but + because it is the destructor, AIElement::clear() is called rather than + a subclass's clear(). +*/ +AIElement::~AIElement() +{ + if ( d->deref() ) + delete d; +} + +/*! + Constructs a copy of the aielement, \a p, passed as the argument to this + constructor. Usually this is a deep copy, but a shallow copy is made + if the stored data type is explicitly shared, as e.g. TQImage is. +*/ +AIElement::AIElement( const AIElement& p ) +{ + d = new Private; + *this = p; +} + +/*! + Constructs a new aielement with a string value, \a val. +*/ +AIElement::AIElement( const TQString& val, Type type ) +{ + d = new Private; + d->typ = type; + d->value.ptr = new TQString( val ); +} + +/*! + Constructs a new aielement with a C-string value, \a val. + + If you want to modify the TQCString after you've passed it to this + constructor, we recommend passing a deep copy (see + TQCString::copy()). +*/ +AIElement::AIElement( const TQCString& val ) +{ + d = new Private; + d->typ = CString; + d->value.ptr = new TQCString( val ); +} + +/*! + Constructs a new aielement with a C-string value of \a val if \a val + is non-null. The aielement creates a deep copy of \a val. + + If \a val is null, the resulting aielement has type Invalid. +*/ +AIElement::AIElement( const char* val ) +{ + d = new Private; + if ( val == 0 ) + return; + d->typ = CString; + d->value.ptr = new TQCString( val ); +} + +/*! + Constructs a new aielement with an integer value, \a val. +*/ +AIElement::AIElement( int val ) +{ + d = new Private; + d->typ = Int; + d->value.i = val; +} + +/*! + Constructs a new aielement with an unsigned integer value, \a val. +*/ +AIElement::AIElement( uint val ) +{ + d = new Private; + d->typ = UInt; + d->value.u = val; +} + +/*! + Constructs a new aielement with an byte value, \a val. +*/ +AIElement::AIElement( uchar val ) +{ + d = new Private; + d->typ = Byte; + d->value.b = val; +} + + +/*! + Constructs a new aielement with a floating point value, \a val. +*/ +AIElement::AIElement( double val ) +{ + d = new Private; + d->typ = Double; + d->value.d = val; +} + +/*! + Constructs a new aielement with a list value, \a val. +*/ +/* AIElement::AIElement( const TQValueList& val ) +{ + d = new Private; + d->typ = List; + d->value.ptr = new TQValueList( val ); +} */ + +AIElement::AIElement( const TQValueVector& val, Type type ) +{ + d = new Private; + d->typ = type; + d->value.ptr = new TQValueVector( val ); +} + +AIElement::AIElement( const TQByteArray& val ) +{ + d = new Private; + d->typ = ByteArray; + d->value.ptr = new TQByteArray( val ); +} + +/*! + Assigns the value of the aielement \a aielement to this aielement. + + This is a deep copy of the aielement, but note that if the aielement + holds an explicitly shared type such as TQImage, a shallow copy + is performed. +*/ +AIElement& AIElement::operator= ( const AIElement& aielement ) +{ + AIElement& other = (AIElement&)aielement; + + other.d->ref(); + if ( d->deref() ) + delete d; + + d = other.d; + + return *this; +} + +/*! + \internal +*/ +void AIElement::detach() +{ + if ( d->count == 1 ) + return; + + d->deref(); + d = new Private( d ); +} + +/*! + Returns the name of the type stored in the aielement. + The returned strings describe the C++ datatype used to store the + data: for example, "TQFont", TQSTRING_OBJECT_NAME_STRING, or "TQValueList". + An Invalid aielement returns 0. +*/ +const char* AIElement::typeName() const +{ + return typeToName( d->typ ); +} + +/*! Convert this aielement to type Invalid and free up any resources + used. +*/ +void AIElement::clear() +{ + if ( d->count > 1 ) + { + d->deref(); + d = new Private; + return; + } + + d->clear(); +} + +static const int ntypes = 11; +static const char* const type_map[ntypes] = +{ + 0, +// "TQValueList", + TQSTRING_OBJECT_NAME_STRING, + "int", + "uint", + "double", + "TQCString", + "Operator", + "Reference", + "TQValueVector", + TQBYTEARRAY_OBJECT_NAME_STRING, + "uchar", +}; + +/*! + Converts the enum representation of the storage type, \a typ, to its + string representation. +*/ +const char* AIElement::typeToName( Type typ ) +{ + if ( typ >= ntypes ) + return 0; + return type_map[typ]; +} + +/*! + Converts the string representation of the storage type gven in \a + name, to its enum representation. + + If the string representation cannot be converted to any enum + representation, the aielement is set to \c Invalid. +*/ +AIElement::Type AIElement::nameToType( const char* name ) +{ + for ( int i = 0; i < ntypes; i++ ) { + if ( !qstrcmp( type_map[i], name ) ) + return (Type) i; + } + return Invalid; +} + +/*! + Returns the aielement as a TQString if the aielement has type() + String, CString, ByteArray, Int, Uint, Double, + or TQString() otherwise. + + \sa asString() +*/ +const TQString AIElement::toString() const +{ + if ( d->typ == CString ) + return TQString::fromLatin1( toCString() ); + if ( d->typ == Int ) + return TQString::number( toInt() ); + if ( d->typ == UInt ) + return TQString::number( toUInt() ); + if ( d->typ == Double ) + return TQString::number( toDouble() ); + if ( d->typ == Byte ) + return TQString::number( toByte() ); + if ( d->typ != String ) + return TQString(); + return *((TQString*)d->value.ptr); +} + +const TQString AIElement::toReference() const +{ + if ( d->typ != Reference ) + return TQString(); + return *((TQString*)d->value.ptr); +} + +const TQString AIElement::toOperator() const +{ + if ( d->typ != Operator ) + return TQString(); + return *((TQString*)d->value.ptr); +} + +/*! + Returns the aielement as a TQCString if the aielement has type() + CString or String, or a 0 otherwise. + + \sa asCString() +*/ +const TQCString AIElement::toCString() const +{ + if ( d->typ == CString ) + return *((TQCString*)d->value.ptr); + if ( d->typ == String ) + return ((TQString*)d->value.ptr)->latin1(); + if ( d->typ == Operator ) + return ((TQString*)d->value.ptr)->latin1(); + if ( d->typ == Reference ) + return ((TQString*)d->value.ptr)->latin1(); + + return 0; +} + + +/*! + Returns the aielement as an int if the aielement has type() + String, CString, Int, UInt, Double, Byte, or 0 otherwise. + + If \a ok is non-null, \a *ok is set to TRUE if the value could be + converted to an int and FALSE otherwise. + + \sa asInt() canCast() +*/ +int AIElement::toInt( bool * ok ) const +{ + if( d->typ == String ) + return ((TQString*)d->value.ptr)->toInt( ok ); + if ( d->typ == CString ) + return ((TQCString*)d->value.ptr)->toInt( ok ); + if ( ok ) + *ok = canCast( UInt ); + if( d->typ == Int ) + return d->value.i; + if( d->typ == UInt ) + return (int)d->value.u; + if( d->typ == Byte ) + return (int)d->value.b; + if ( d->typ == Double ) + return (int)d->value.d; + return 0; +} + +uchar AIElement::toByte( bool * ok ) const +{ + if( d->typ == String ) + return ((TQString*)d->value.ptr)->toShort( ok ); + if ( d->typ == CString ) + return ((TQCString*)d->value.ptr)->toShort( ok ); + if ( ok ) + *ok = canCast( UInt ); + if( d->typ == Byte ) + return d->value.b; + if( d->typ == Int ) + return (uchar)d->value.i; + if( d->typ == UInt ) + return (uchar)d->value.u; + if ( d->typ == Double ) + return (uchar)d->value.d; + return 0; +} + + +/*! + Returns the aielement as an unsigned int if the aielement has type() + String, CString, UInt, Int, Double, Byte, or 0 otherwise. + + If \a ok is non-null, \a *ok is set to TRUE if the value could be + converted to a uint and FALSE otherwise. + + \sa asUInt() +*/ +uint AIElement::toUInt( bool * ok ) const +{ + if( d->typ == String ) + return ((TQString*)d->value.ptr)->toUInt( ok ); + if ( d->typ == CString ) + return ((TQCString*)d->value.ptr)->toUInt( ok ); + if ( ok ) + *ok = canCast( UInt ); + if( d->typ == Int ) + return d->value.i; + if( d->typ == UInt ) + return (int)d->value.u; + if( d->typ == Byte ) + return (int)d->value.b; + if ( d->typ == Double ) + return (int)d->value.d; + + return 0; +} + +/*! + Returns the aielement as a double if the aielement has type() + String, CString, Double, Int, UInt, Byte, or 0.0 otherwise. + + If \a ok is non-null, \a *ok is set to TRUE if the value could be + converted to a double and FALSE otherwise. + + \sa asDouble() +*/ +double AIElement::toDouble( bool * ok ) const +{ + if( d->typ == String ) + return ((TQString*)d->value.ptr)->toDouble( ok ); + if ( d->typ == CString ) + return ((TQCString*)d->value.ptr)->toDouble( ok ); + if ( ok ) + *ok = canCast( Double ); + if ( d->typ == Double ) + return d->value.d; + if ( d->typ == Int ) + return (double)d->value.i; + if ( d->typ == UInt ) + return (double)d->value.u; + if ( d->typ == Byte ) + return (double)d->value.b; + return 0.0; +} + +/*! + Returns the aielement as a TQValueList if the aielement has type() + List or StringList, or an empty list otherwise. + + Note that if you want to iterate over the list, you should + iterate over a copy, e.g. + \code + TQValueList list = myAIElement.toList(); + TQValueList::Iterator it = list.begin(); + while( it != list.end() ) { + myProcessing( *it ); + ++it; + } + \endcode + + \sa asList() +*/ +/* const TQValueList AIElement::toList() const +{ + if ( d->typ == List ) + return *((TQValueList*)d->value.ptr); + return TQValueList(); +} */ + +const TQValueVector AIElement::toElementArray() const +{ + if ( d->typ == ElementArray ) + return *((TQValueVector*)d->value.ptr); + return TQValueVector(); +} + +const TQValueVector AIElement::toBlock() const +{ + if ( d->typ == Block ) + return *((TQValueVector*)d->value.ptr); + return TQValueVector(); +} + + +const TQByteArray AIElement::toByteArray() const +{ + if ( d->typ == ByteArray ) + return *((TQByteArray*)d->value.ptr); + return TQByteArray(); +} + +#define TQ_VARIANT_AS( f ) TQ##f& AIElement::as##f() { \ + if ( d->typ != f ) *this = AIElement( to##f() ); else detach(); return *((TQ##f*)d->value.ptr);} + +TQ_VARIANT_AS(String) +TQ_VARIANT_AS(CString) + +/*! + Returns the aielement's value as int reference. +*/ +int& AIElement::asInt() +{ + detach(); + if ( d->typ != Int ) { + int i = toInt(); + d->clear(); + d->value.i = i; + d->typ = Int; + } + return d->value.i; +} + +/*! + Returns the aielement's value as unsigned int reference. +*/ +uint& AIElement::asUInt() +{ + detach(); + if ( d->typ != UInt ) { + uint u = toUInt(); + d->clear(); + d->value.u = u; + d->typ = UInt; + } + return d->value.u; +} + +/*! + Returns the aielement's value as double reference. +*/ +double& AIElement::asDouble() +{ + if ( d->typ != Double ) { + double dbl = toDouble(); + d->clear(); + d->value.d = dbl; + d->typ = Double; + } + return d->value.d; +} + +/*! + Returns the aielement's value as byte reference. +*/ +uchar& AIElement::asByte() +{ + detach(); + if ( d->typ != Byte ) { + uchar b = toByte(); + d->clear(); + d->value.b = b; + d->typ = Byte; + } + return d->value.b; +} + + +/*! + Returns the aielement's value as aielement list reference. + + Note that if you want to iterate over the list, you should + iterate over a copy, e.g. + \code + TQValueList list = myAIElement.asList(); + TQValueList::Iterator it = list.begin(); + while( it != list.end() ) { + myProcessing( *it ); + ++it; + } + \endcode +*/ +/* TQValueList& AIElement::asList() +{ + if ( d->typ != List ) + *this = AIElement( toList() ); + return *((TQValueList*)d->value.ptr); +} */ + +TQValueVector& AIElement::asElementArray() +{ + if ( d->typ != ElementArray ) + *this = AIElement( toElementArray() ); + return *((TQValueVector*)d->value.ptr); +} + +TQValueVector& AIElement::asBlock() +{ + if ( d->typ != Block ) + *this = AIElement( toBlock() ); + return *((TQValueVector*)d->value.ptr); +} + + +TQByteArray& AIElement::asByteArray() +{ + if ( d->typ != ByteArray ) + *this = AIElement( toByteArray() ); + return *((TQByteArray*)d->value.ptr); +} + +/*! + Returns TRUE if the aielement's type can be cast to the requested + type, \p t. Such casting is done automatically when calling the + toInt(), ... or asInt(), ... methods. + + The following casts are done automatically: +
    +
  • CString => String +
  • Double => String, Int, UInt +
  • Int => String, Double, UInt +
  • String => CString, Int, Uint, Double +
  • UInt => String, Double, Int +
+*/ +bool AIElement::canCast( Type t ) const +{ + if ( d->typ == t ) + return TRUE; + if ( t == Int && ( d->typ == String || d->typ == Double || d->typ == UInt || d->typ == Byte) ) + return TRUE; + if ( t == UInt && ( d->typ == String || d->typ == Double || d->typ == Int || d->typ == Byte) ) + return TRUE; + if ( t == Double && ( d->typ == String || d->typ == Int || d->typ == UInt || d->typ == Byte) ) + return TRUE; + if ( t == CString && d->typ == String ) + return TRUE; + if ( t == String && ( d->typ == CString || d->typ == Int || d->typ == UInt || d->typ == Double || d->typ == Byte) ) + return TRUE; + + return FALSE; +} + +/*! + \brief Casts the aielement to the requested type. + + If the cast cannot be + done, the aielement is set to the default value of the requested type + (e.g. an empty string if the requested type \p t is + AIElement::String, an empty point array if the requested type \p t is + AIElement::PointArray, etc). + + \returns TRUE if the current type of the + aielement was successfully casted; otherwise returns FALSE. + + \see canCast() +*/ + +bool AIElement::cast( Type t ) +{ + switch ( t ) { +/* case AIElement::List: + asList(); + break; */ + case AIElement::ElementArray: + asElementArray(); + break; + case AIElement::Block: + asBlock(); + break; + case AIElement::String: + asString(); + break; + case AIElement::Int: + asInt(); + break; + case AIElement::UInt: + asUInt(); + break; + case AIElement::Double: + asDouble(); + break; + case AIElement::CString: + asCString(); + break; + case AIElement::Byte: + asByte(); + break; + case AIElement::ByteArray: + asByteArray(); + break; + default: + case AIElement::Invalid: + (*this) = AIElement(); + } + return canCast( t ); +} + +/*! Compares this AIElement with \a v and returns TRUE if they are + equal; otherwise returns FALSE. +*/ + +bool AIElement::operator==( const AIElement &v ) const +{ + if ( !v.canCast( type() ) ) + return FALSE; + switch( d->typ ) { +/* case List: + return v.toList() == toList(); */ + case ElementArray: + return v.toElementArray() == toElementArray(); + case Block: + return v.toBlock() == toBlock(); + case ByteArray: + return v.toByteArray() == toByteArray(); + + case String: + return v.toString() == toString(); + case Operator: + return v.toOperator() == toOperator(); + case Reference: + return v.toReference() == toReference(); + case CString: + return v.toCString() == toCString(); + case Int: + return v.toInt() == toInt(); + case UInt: + return v.toUInt() == toUInt(); + case Byte: + return v.toByte() == toByte(); + case Invalid: + break; + } + return FALSE; +} + +/*! Compares this AIElement with \a v and returns TRUE if they are + not equal; otherwise returns FALSE. +*/ + +bool AIElement::operator!=( const AIElement &v ) const +{ + return !( v == *this ); +} diff --git a/filters/karbon/ai/aiimport.cc b/filters/karbon/ai/aiimport.cc deleted file mode 100644 index 0af2cc93..00000000 --- a/filters/karbon/ai/aiimport.cc +++ /dev/null @@ -1,101 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002, Dirk Schönberger - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include "aiimport.h" -#include "karbonaiparserbase.h" - -class AiImportFactory : KGenericFactory -{ -public: - AiImportFactory( void ) - : KGenericFactory( "karbonaiimport" ) - {} - -protected: - virtual void setupTranslations( void ) - { - TDEGlobal::locale()->insertCatalogue( "kofficefilters" ); - } -}; - -K_EXPORT_COMPONENT_FACTORY( libkarbonaiimport, AiImportFactory() ) - -AiImport::AiImport( KoFilter*, const char*, const TQStringList& ) - : KoFilter() -{ -} - -AiImport::~AiImport() -{ -} - -KoFilter::ConversionStatus -AiImport::convert( const TQCString& from, const TQCString& to ) -{ - if ( from != "application/illustrator" || to != "application/x-karbon" ) - { - return KoFilter::NotImplemented; - } - TQFile fileIn( m_chain->inputFile() ); - if( !fileIn.open( IO_ReadOnly ) ) - { - fileIn.close(); - return KoFilter::FileNotFound; - } - - TQDomDocument doc ("DOC"); - KarbonAIParserBase parser; - - if (!parser.parse (*TQT_TQIODEVICE(&fileIn), doc)) - { - fileIn.close(); - return KoFilter::CreationError; - } - TQString result = doc.toString(); - - kdDebug() << result << endl; - KoStoreDevice* storeOut = m_chain->storageFile( "root", KoStore::Write ); - if( !storeOut ) - { - fileIn.close(); - return KoFilter::StorageCreationError; - } - - TQCString cStr = result.latin1(); - storeOut->writeBlock( cStr, cStr.size() - 1 ); - - return KoFilter::OK; -} - - -#include "aiimport.moc" - - - diff --git a/filters/karbon/ai/aiimport.cpp b/filters/karbon/ai/aiimport.cpp new file mode 100644 index 00000000..0af2cc93 --- /dev/null +++ b/filters/karbon/ai/aiimport.cpp @@ -0,0 +1,101 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schönberger + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "aiimport.h" +#include "karbonaiparserbase.h" + +class AiImportFactory : KGenericFactory +{ +public: + AiImportFactory( void ) + : KGenericFactory( "karbonaiimport" ) + {} + +protected: + virtual void setupTranslations( void ) + { + TDEGlobal::locale()->insertCatalogue( "kofficefilters" ); + } +}; + +K_EXPORT_COMPONENT_FACTORY( libkarbonaiimport, AiImportFactory() ) + +AiImport::AiImport( KoFilter*, const char*, const TQStringList& ) + : KoFilter() +{ +} + +AiImport::~AiImport() +{ +} + +KoFilter::ConversionStatus +AiImport::convert( const TQCString& from, const TQCString& to ) +{ + if ( from != "application/illustrator" || to != "application/x-karbon" ) + { + return KoFilter::NotImplemented; + } + TQFile fileIn( m_chain->inputFile() ); + if( !fileIn.open( IO_ReadOnly ) ) + { + fileIn.close(); + return KoFilter::FileNotFound; + } + + TQDomDocument doc ("DOC"); + KarbonAIParserBase parser; + + if (!parser.parse (*TQT_TQIODEVICE(&fileIn), doc)) + { + fileIn.close(); + return KoFilter::CreationError; + } + TQString result = doc.toString(); + + kdDebug() << result << endl; + KoStoreDevice* storeOut = m_chain->storageFile( "root", KoStore::Write ); + if( !storeOut ) + { + fileIn.close(); + return KoFilter::StorageCreationError; + } + + TQCString cStr = result.latin1(); + storeOut->writeBlock( cStr, cStr.size() - 1 ); + + return KoFilter::OK; +} + + +#include "aiimport.moc" + + + diff --git a/filters/karbon/ai/ailexer.cc b/filters/karbon/ai/ailexer.cc deleted file mode 100644 index 352b8f48..00000000 --- a/filters/karbon/ai/ailexer.cc +++ /dev/null @@ -1,514 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002, Dirk Schönberger - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include -#include "ailexer.h" - -#define CATEGORY_WHITESPACE -1 -#define CATEGORY_ALPHA -2 -#define CATEGORY_DIGIT -3 -#define CATEGORY_SPECIAL -4 -#define CATEGORY_LETTERHEX -5 -#define CATEGORY_INTTOOLONG -6 - -#define CATEGORY_ANY -127 - -#define MAX_INTLEN 9 -#define MIN_HEXCHARS 6 - -#define STOP 0 - -int iswhitespace(char c){ - return (c==' ')||(c=='\n')||(c=='\t')||(c=='\r'); -} - -int isSpecial(char c){ - return (c=='*')||(c=='_')||(c=='?')||(c=='~')||(c=='-')||(c=='^')||(c=='`')||(c=='!')||(c=='.')||(c=='@')||(c=='&')||(c=='$')||(c=='='); -} - -int isletterhex(char c){ - return (c=='A')||(c=='B')||(c=='C')||(c=='D')||(c=='E')||(c=='F'); -} - -const char*statetoa (State state){ - switch (state) - { - case State_Comment : return "comment"; - case State_Integer : return "integer"; - case State_Float : return "float"; - case State_String : return "string"; - case State_Token : return "token"; - case State_Reference : return "reference"; - case State_Start : return "start"; - case State_BlockStart : return "block start"; - case State_BlockEnd : return "block end"; - case State_ArrayStart : return "array start"; - case State_ArrayEnd : return "array end"; - case State_Byte : return "byte"; - case State_ByteArray : return "byte array"; - case State_StringEncodedChar : return "encoded char (string)"; - case State_CommentEncodedChar : return "encoded char (comment)"; - case State_ByteArray2 : return "byte array (mode 2)"; - default : return "unknown"; - } -} - -typedef struct { - State oldState; - signed char c; - State newState; - Action action; -} Transition; - -static Transition transitions[] = { - { State_Comment, '\n', State_Start, Action_Output}, - { State_Comment, '\r', State_Start, Action_Output}, - { State_Comment, '\\', State_CommentEncodedChar, Action_InitTemp}, - { State_Comment, CATEGORY_ANY, State_Comment, Action_Copy}, - { State_Integer, CATEGORY_DIGIT, State_Integer, Action_Copy}, - { State_Integer, CATEGORY_WHITESPACE, State_Start, Action_Output}, - { State_Integer, '.', State_Float, Action_Copy}, - { State_Integer, ']', State_Start, Action_OutputUnget}, - { State_Integer, '}', State_Start, Action_OutputUnget}, - { State_Integer, '#', State_Byte, Action_Copy }, - { State_Integer, '/', State_Start, Action_OutputUnget }, - { State_Integer, '{', State_Start, Action_OutputUnget }, - { State_Integer, '%', State_Start, Action_OutputUnget }, - { State_Integer, CATEGORY_LETTERHEX, State_ByteArray2, Action_Copy }, - { State_Integer, CATEGORY_INTTOOLONG, State_ByteArray2, Action_Copy }, - { State_Integer, CATEGORY_ANY, State_Start, Action_Abort}, - { State_Float, CATEGORY_DIGIT, State_Float, Action_Copy}, - { State_Float, CATEGORY_WHITESPACE, State_Start, Action_Output}, - { State_Float, ']', State_Start, Action_OutputUnget}, - { State_Float, '}', State_Start, Action_OutputUnget}, - { State_Float, CATEGORY_ANY, State_Start, Action_Abort}, - { State_Token, CATEGORY_ALPHA, State_Token, Action_Copy}, - { State_Token, CATEGORY_DIGIT, State_Token, Action_Copy}, - { State_Token, CATEGORY_SPECIAL, State_Token, Action_Copy}, - { State_Token, '}', State_Start, Action_OutputUnget}, - { State_Token, ']', State_Start, Action_OutputUnget}, - { State_Token, '{', State_BlockStart, Action_Output}, - { State_Token, '}', State_BlockEnd, Action_Output}, - { State_Token, '/', State_Start, Action_OutputUnget}, - { State_Token, CATEGORY_WHITESPACE, State_Start, Action_Output}, - { State_Token, CATEGORY_ANY, State_Start, Action_Abort}, - { State_String, ')', State_Start, Action_Output}, - { State_String, '\\', State_StringEncodedChar, Action_InitTemp}, - { State_String, CATEGORY_ANY, State_String, Action_Copy}, -// { State_Array, CATEGORY_ALPHA, State_Array, Action_Copy}, -// { State_Array, CATEGORY_DIGIT, State_Array, Action_Copy}, -// { State_Array, ' ', State_Array, Action_Copy}, - { State_BlockStart, CATEGORY_ANY, State_Start, Action_OutputUnget }, - { State_BlockEnd, CATEGORY_ANY, State_Start, Action_OutputUnget }, - { State_ArrayStart, CATEGORY_ANY, State_Start, Action_OutputUnget }, - { State_ArrayEnd, CATEGORY_ANY, State_Start, Action_OutputUnget }, - { State_Reference, '#', State_Reference, Action_Copy }, - { State_Reference, CATEGORY_ALPHA, State_Reference, Action_Copy }, - { State_Reference, CATEGORY_DIGIT, State_Reference, Action_Copy }, - { State_Reference, CATEGORY_SPECIAL, State_Reference, Action_Copy }, - { State_Reference, CATEGORY_ANY, State_Start, Action_OutputUnget }, - { State_Byte, '/', State_Start, Action_OutputUnget }, - { State_Byte, CATEGORY_DIGIT, State_Byte, Action_Copy}, - { State_Byte, CATEGORY_ALPHA, State_Byte, Action_Copy}, - { State_Byte, CATEGORY_WHITESPACE, State_Start, Action_Output}, - { State_ByteArray, '>', State_Start, Action_Output }, - { State_ByteArray, CATEGORY_ALPHA, State_ByteArray, Action_Copy }, - { State_ByteArray, CATEGORY_DIGIT, State_ByteArray, Action_Copy }, - { State_ByteArray, CATEGORY_WHITESPACE, State_ByteArray, Action_Ignore }, - { State_ByteArray, CATEGORY_ANY, State_Start, Action_Abort }, - { State_StringEncodedChar, '\\', State_String, Action_Copy}, - { State_StringEncodedChar, CATEGORY_DIGIT, State_StringEncodedChar, Action_CopyTemp}, - { State_StringEncodedChar, CATEGORY_ANY, State_String, Action_DecodeUnget}, - { State_CommentEncodedChar, '\\', State_Comment, Action_Copy}, - { State_CommentEncodedChar, CATEGORY_DIGIT, State_CommentEncodedChar, Action_CopyTemp}, - { State_CommentEncodedChar, CATEGORY_ANY, State_Comment, Action_DecodeUnget}, - { State_ByteArray2, '\n', State_Start, Action_Output}, - { State_ByteArray2, '\r', State_Start, Action_Output}, - { State_ByteArray2, '}', State_Start, Action_ByteArraySpecial}, - { State_ByteArray2, CATEGORY_WHITESPACE, State_Start, Action_Output}, - { State_ByteArray2, CATEGORY_DIGIT, State_ByteArray2, Action_Copy}, - { State_ByteArray2, CATEGORY_LETTERHEX, State_ByteArray2, Action_Copy}, - { State_ByteArray2, CATEGORY_ALPHA, State_Token, Action_Copy}, - { State_ByteArray2, CATEGORY_ANY, State_Start, Action_Abort}, - { State_Start, '%', State_Comment, Action_Ignore}, - { State_Start, CATEGORY_DIGIT, State_Integer, Action_Copy}, - { State_Start, '-', State_Integer, Action_Copy}, - { State_Start, '+', State_Integer, Action_Copy}, - { State_Start, '.', State_Float, Action_Copy}, - { State_Start, '/', State_Reference, Action_Ignore }, - { State_Start, '(', State_String, Action_Ignore}, - { State_Start, '{', State_BlockStart, Action_Copy}, - { State_Start, '}', State_BlockEnd, Action_Copy}, - { State_Start, '[', State_ArrayStart, Action_Copy}, - { State_Start, ']', State_ArrayEnd, Action_Copy}, - { State_Start, '<', State_ByteArray, Action_Ignore}, - { State_Start, CATEGORY_ALPHA, State_Token, Action_Copy}, - { State_Start, CATEGORY_WHITESPACE, State_Start, Action_Output}, - { State_Start, CATEGORY_SPECIAL, State_Token, Action_Copy}, - { State_Start, CATEGORY_LETTERHEX, State_ByteArray2, Action_Copy}, - { State_Start, CATEGORY_ANY, State_Start, Action_Abort}, - { State_Start, STOP, State_Start, Action_Abort} -}; - -AILexer::AILexer(){ -} -AILexer::~AILexer(){ -} - -bool AILexer::parse (TQIODevice& fin){ - char c; - - m_buffer.clear(); - m_curState = State_Start; - - parsingStarted(); - - while (!fin.atEnd()) - { - c = fin.getch (); - -// tqDebug ("got %c", c); - - State newState; - Action action; - - nextStep (c, &newState, &action); - - switch (action) - { - case Action_Copy : - m_buffer.append (c); - break; - case Action_CopyOutput : - m_buffer.append (c); - doOutput(); - break; - case Action_Output : - doOutput(); - break; - case Action_OutputUnget : - doOutput(); - fin.ungetch(c); - break; - case Action_Ignore : - /* ignore */ - break; - case Action_Abort : - tqWarning ( "state %s / %s char %c (%d)" , statetoa(m_curState), statetoa(newState), c, c ); - parsingAborted(); - return false; - break; - case Action_InitTemp : - m_temp.clear(); - break; - case Action_CopyTemp : - m_temp.append (c); - break; - case Action_DecodeUnget : - m_buffer.append (decode()); - fin.ungetch(c); - break; - // in Postscript Quelltext: Kombination F} - case Action_ByteArraySpecial : - m_curState = State_Token; - doOutput(); - fin.ungetch(c); - break; - default : - tqWarning ( "unknown action: %d ", action); - } - - m_curState = newState; - } - - parsingFinished(); - return true; -} - -void AILexer::doOutput () -{ - if (m_buffer.length() == 0) return; - switch (m_curState) - { - case State_Comment : - gotComment (m_buffer.latin1()); - break; - case State_Integer : - gotIntValue (m_buffer.toInt()); - break; - case State_Float : - gotDoubleValue (m_buffer.toFloat()); - break; - case State_String : - gotStringValue (m_buffer.latin1()); - break; - case State_Token : - gotToken (m_buffer.latin1()); - break; - case State_Reference : - gotReference (m_buffer.latin1()); - break; - case State_BlockStart : - gotBlockStart (); - break; - case State_BlockEnd : - gotBlockEnd (); - break; - case State_Start : - break; - case State_ArrayStart : - gotArrayStart (); - break; - case State_ArrayEnd : - gotArrayEnd (); - break; - case State_Byte : - gotByte (getByte()); - break; - case State_ByteArray : - case State_ByteArray2 : - doHandleByteArray (); - break; - default: - tqWarning ( "unknown state: %d", m_curState ); - } - - m_buffer.clear(); -} - -void AILexer::gotComment (const char *value) { - tqDebug ( "gotComment: %s ", value ); -} - -void AILexer::gotIntValue (int value) { - tqDebug ( "gotInt: %d ", value ); -} - -void AILexer::gotDoubleValue (double value) { - tqDebug ( "gotDouble: %f ", value ); -} - -void AILexer::gotStringValue (const char *value) { - tqDebug ( "gotString: %s ", value ); -} - -void AILexer::gotToken (const char *value) { - tqDebug ( "gotToken: %s ", value ); -} - -void AILexer::gotReference (const char *value) { - tqDebug ( "gotReference: %s ", value ); -} - -void AILexer::gotBlockStart (){ - tqDebug ( "gotBlockStart" ); -} - -void AILexer::gotBlockEnd (){ - tqDebug ( "gotBlockEnd" ); -} - -void AILexer::gotArrayStart (){ - tqDebug ( "gotArrayStart" ); -} - -void AILexer::gotArrayEnd (){ - tqDebug ( "gotArrayEnd" ); -} - -void AILexer::parsingStarted() { - tqDebug ( "parsing started" ); -} - -void AILexer::parsingFinished() { - tqDebug ( "parsing finished" ); -} - -void AILexer::parsingAborted() { - tqDebug ( "parsing aborted" ); -} - -void AILexer::gotByte (uchar value) { - tqDebug ( "got byte %d" , value ); -} - -void AILexer::gotByteArray (const TQByteArray &data) { - tqDebug ( "got byte array" ); -/* for ( uint i = 0; i < data.size(); i++ ) - { - uchar value = data[i]; - tqDebug( "%d: %x", i, value ); - } - tqDebug ( "/byte array" ); */ - -} - - -void AILexer::nextStep (char c, State *newState, Action *newAction) { - int i=0; - - while (true) { - Transition trans = transitions[i]; - - if (trans.c == STOP) { - *newState = trans.newState; - *newAction = trans.action; - return; - } - - bool found = false; - - if (trans.oldState == m_curState) { - switch (trans.c) { - case CATEGORY_WHITESPACE : found = isspace(c); break; - case CATEGORY_ALPHA : found = isalpha(c); break; - case CATEGORY_DIGIT : found = isdigit(c); break; - case CATEGORY_SPECIAL : found = isSpecial(c); break; - case CATEGORY_LETTERHEX : found = isletterhex(c); break; - case CATEGORY_INTTOOLONG : found = m_buffer.length() > MAX_INTLEN; break; - case CATEGORY_ANY : found = true; break; - default : found = (trans.c == c); - } - - if (found) { - *newState = trans.newState; - *newAction = trans.action; - - return; - } - } - - - i++; - } -} - -void AILexer::doHandleByteArray () -{ - // Special case - too short - if (m_buffer.length () < MIN_HEXCHARS) - { - gotToken (m_buffer.latin1()); - return; - } - - uint strIdx = 0; - uint arrayIdx = 0; - - TQByteArray data (m_buffer.length() >> 1); - - while (strIdx < m_buffer.length()) - { - const TQString &item = m_buffer.mid (strIdx, 2); - uchar val = item.toShort(NULL, 16); - data[arrayIdx] = val; - strIdx += 2; - arrayIdx++; - } - - gotByteArray (data); -} - -uchar AILexer::getByte() -{ -// tqDebug ("convert string to byte (%s)", m_buffer.latin1()); - - TQStringList list = TQStringList::split ("#", m_buffer.toString()); - int radix = list[0].toShort(); - uchar value = list[1].toShort (NULL, radix); - - return value; -} - -uchar AILexer::decode() -{ - uchar value = m_temp.toString().toShort(NULL, 8); -// tqDebug ("got encoded char %c",value); - return value; -} - -/* StringBuffer implementation */ - -int initialSize = 20; -int addSize = 10; - -StringBuffer::StringBuffer () { - m_buffer = (char*)calloc (initialSize, sizeof(char)); - m_length = 0; - m_capacity = initialSize; -} - -StringBuffer::~StringBuffer (){ - free(m_buffer); -} - -void StringBuffer::append (char c){ - ensureCapacity(m_length + 1); - m_buffer[m_length] = c; - m_length++; -} - -void StringBuffer::clear(){ - for (uint i=0; i= p_capacity) return; - - int newSize = m_capacity + addSize; - if (p_capacity > newSize) newSize = p_capacity; - - char* oldBuffer = m_buffer; - char *newBuffer = (char*)calloc (newSize, sizeof(char)); - strcpy (newBuffer, m_buffer); - free(oldBuffer); - m_buffer = newBuffer; - m_capacity = newSize; -} - -uint StringBuffer::length() { - return m_length; -} - -double StringBuffer::toFloat() { - TQString data = toString(); - return data.toFloat(); -} - -int StringBuffer::toInt() { - TQString data = toString(); - return data.toInt(); -} - -const char *StringBuffer::latin1() { - return m_buffer; -} - -TQString StringBuffer::mid( uint index, uint len) const { - TQString data = toString(); - return data.mid(index,len); -} diff --git a/filters/karbon/ai/ailexer.cpp b/filters/karbon/ai/ailexer.cpp new file mode 100644 index 00000000..352b8f48 --- /dev/null +++ b/filters/karbon/ai/ailexer.cpp @@ -0,0 +1,514 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schönberger + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include "ailexer.h" + +#define CATEGORY_WHITESPACE -1 +#define CATEGORY_ALPHA -2 +#define CATEGORY_DIGIT -3 +#define CATEGORY_SPECIAL -4 +#define CATEGORY_LETTERHEX -5 +#define CATEGORY_INTTOOLONG -6 + +#define CATEGORY_ANY -127 + +#define MAX_INTLEN 9 +#define MIN_HEXCHARS 6 + +#define STOP 0 + +int iswhitespace(char c){ + return (c==' ')||(c=='\n')||(c=='\t')||(c=='\r'); +} + +int isSpecial(char c){ + return (c=='*')||(c=='_')||(c=='?')||(c=='~')||(c=='-')||(c=='^')||(c=='`')||(c=='!')||(c=='.')||(c=='@')||(c=='&')||(c=='$')||(c=='='); +} + +int isletterhex(char c){ + return (c=='A')||(c=='B')||(c=='C')||(c=='D')||(c=='E')||(c=='F'); +} + +const char*statetoa (State state){ + switch (state) + { + case State_Comment : return "comment"; + case State_Integer : return "integer"; + case State_Float : return "float"; + case State_String : return "string"; + case State_Token : return "token"; + case State_Reference : return "reference"; + case State_Start : return "start"; + case State_BlockStart : return "block start"; + case State_BlockEnd : return "block end"; + case State_ArrayStart : return "array start"; + case State_ArrayEnd : return "array end"; + case State_Byte : return "byte"; + case State_ByteArray : return "byte array"; + case State_StringEncodedChar : return "encoded char (string)"; + case State_CommentEncodedChar : return "encoded char (comment)"; + case State_ByteArray2 : return "byte array (mode 2)"; + default : return "unknown"; + } +} + +typedef struct { + State oldState; + signed char c; + State newState; + Action action; +} Transition; + +static Transition transitions[] = { + { State_Comment, '\n', State_Start, Action_Output}, + { State_Comment, '\r', State_Start, Action_Output}, + { State_Comment, '\\', State_CommentEncodedChar, Action_InitTemp}, + { State_Comment, CATEGORY_ANY, State_Comment, Action_Copy}, + { State_Integer, CATEGORY_DIGIT, State_Integer, Action_Copy}, + { State_Integer, CATEGORY_WHITESPACE, State_Start, Action_Output}, + { State_Integer, '.', State_Float, Action_Copy}, + { State_Integer, ']', State_Start, Action_OutputUnget}, + { State_Integer, '}', State_Start, Action_OutputUnget}, + { State_Integer, '#', State_Byte, Action_Copy }, + { State_Integer, '/', State_Start, Action_OutputUnget }, + { State_Integer, '{', State_Start, Action_OutputUnget }, + { State_Integer, '%', State_Start, Action_OutputUnget }, + { State_Integer, CATEGORY_LETTERHEX, State_ByteArray2, Action_Copy }, + { State_Integer, CATEGORY_INTTOOLONG, State_ByteArray2, Action_Copy }, + { State_Integer, CATEGORY_ANY, State_Start, Action_Abort}, + { State_Float, CATEGORY_DIGIT, State_Float, Action_Copy}, + { State_Float, CATEGORY_WHITESPACE, State_Start, Action_Output}, + { State_Float, ']', State_Start, Action_OutputUnget}, + { State_Float, '}', State_Start, Action_OutputUnget}, + { State_Float, CATEGORY_ANY, State_Start, Action_Abort}, + { State_Token, CATEGORY_ALPHA, State_Token, Action_Copy}, + { State_Token, CATEGORY_DIGIT, State_Token, Action_Copy}, + { State_Token, CATEGORY_SPECIAL, State_Token, Action_Copy}, + { State_Token, '}', State_Start, Action_OutputUnget}, + { State_Token, ']', State_Start, Action_OutputUnget}, + { State_Token, '{', State_BlockStart, Action_Output}, + { State_Token, '}', State_BlockEnd, Action_Output}, + { State_Token, '/', State_Start, Action_OutputUnget}, + { State_Token, CATEGORY_WHITESPACE, State_Start, Action_Output}, + { State_Token, CATEGORY_ANY, State_Start, Action_Abort}, + { State_String, ')', State_Start, Action_Output}, + { State_String, '\\', State_StringEncodedChar, Action_InitTemp}, + { State_String, CATEGORY_ANY, State_String, Action_Copy}, +// { State_Array, CATEGORY_ALPHA, State_Array, Action_Copy}, +// { State_Array, CATEGORY_DIGIT, State_Array, Action_Copy}, +// { State_Array, ' ', State_Array, Action_Copy}, + { State_BlockStart, CATEGORY_ANY, State_Start, Action_OutputUnget }, + { State_BlockEnd, CATEGORY_ANY, State_Start, Action_OutputUnget }, + { State_ArrayStart, CATEGORY_ANY, State_Start, Action_OutputUnget }, + { State_ArrayEnd, CATEGORY_ANY, State_Start, Action_OutputUnget }, + { State_Reference, '#', State_Reference, Action_Copy }, + { State_Reference, CATEGORY_ALPHA, State_Reference, Action_Copy }, + { State_Reference, CATEGORY_DIGIT, State_Reference, Action_Copy }, + { State_Reference, CATEGORY_SPECIAL, State_Reference, Action_Copy }, + { State_Reference, CATEGORY_ANY, State_Start, Action_OutputUnget }, + { State_Byte, '/', State_Start, Action_OutputUnget }, + { State_Byte, CATEGORY_DIGIT, State_Byte, Action_Copy}, + { State_Byte, CATEGORY_ALPHA, State_Byte, Action_Copy}, + { State_Byte, CATEGORY_WHITESPACE, State_Start, Action_Output}, + { State_ByteArray, '>', State_Start, Action_Output }, + { State_ByteArray, CATEGORY_ALPHA, State_ByteArray, Action_Copy }, + { State_ByteArray, CATEGORY_DIGIT, State_ByteArray, Action_Copy }, + { State_ByteArray, CATEGORY_WHITESPACE, State_ByteArray, Action_Ignore }, + { State_ByteArray, CATEGORY_ANY, State_Start, Action_Abort }, + { State_StringEncodedChar, '\\', State_String, Action_Copy}, + { State_StringEncodedChar, CATEGORY_DIGIT, State_StringEncodedChar, Action_CopyTemp}, + { State_StringEncodedChar, CATEGORY_ANY, State_String, Action_DecodeUnget}, + { State_CommentEncodedChar, '\\', State_Comment, Action_Copy}, + { State_CommentEncodedChar, CATEGORY_DIGIT, State_CommentEncodedChar, Action_CopyTemp}, + { State_CommentEncodedChar, CATEGORY_ANY, State_Comment, Action_DecodeUnget}, + { State_ByteArray2, '\n', State_Start, Action_Output}, + { State_ByteArray2, '\r', State_Start, Action_Output}, + { State_ByteArray2, '}', State_Start, Action_ByteArraySpecial}, + { State_ByteArray2, CATEGORY_WHITESPACE, State_Start, Action_Output}, + { State_ByteArray2, CATEGORY_DIGIT, State_ByteArray2, Action_Copy}, + { State_ByteArray2, CATEGORY_LETTERHEX, State_ByteArray2, Action_Copy}, + { State_ByteArray2, CATEGORY_ALPHA, State_Token, Action_Copy}, + { State_ByteArray2, CATEGORY_ANY, State_Start, Action_Abort}, + { State_Start, '%', State_Comment, Action_Ignore}, + { State_Start, CATEGORY_DIGIT, State_Integer, Action_Copy}, + { State_Start, '-', State_Integer, Action_Copy}, + { State_Start, '+', State_Integer, Action_Copy}, + { State_Start, '.', State_Float, Action_Copy}, + { State_Start, '/', State_Reference, Action_Ignore }, + { State_Start, '(', State_String, Action_Ignore}, + { State_Start, '{', State_BlockStart, Action_Copy}, + { State_Start, '}', State_BlockEnd, Action_Copy}, + { State_Start, '[', State_ArrayStart, Action_Copy}, + { State_Start, ']', State_ArrayEnd, Action_Copy}, + { State_Start, '<', State_ByteArray, Action_Ignore}, + { State_Start, CATEGORY_ALPHA, State_Token, Action_Copy}, + { State_Start, CATEGORY_WHITESPACE, State_Start, Action_Output}, + { State_Start, CATEGORY_SPECIAL, State_Token, Action_Copy}, + { State_Start, CATEGORY_LETTERHEX, State_ByteArray2, Action_Copy}, + { State_Start, CATEGORY_ANY, State_Start, Action_Abort}, + { State_Start, STOP, State_Start, Action_Abort} +}; + +AILexer::AILexer(){ +} +AILexer::~AILexer(){ +} + +bool AILexer::parse (TQIODevice& fin){ + char c; + + m_buffer.clear(); + m_curState = State_Start; + + parsingStarted(); + + while (!fin.atEnd()) + { + c = fin.getch (); + +// tqDebug ("got %c", c); + + State newState; + Action action; + + nextStep (c, &newState, &action); + + switch (action) + { + case Action_Copy : + m_buffer.append (c); + break; + case Action_CopyOutput : + m_buffer.append (c); + doOutput(); + break; + case Action_Output : + doOutput(); + break; + case Action_OutputUnget : + doOutput(); + fin.ungetch(c); + break; + case Action_Ignore : + /* ignore */ + break; + case Action_Abort : + tqWarning ( "state %s / %s char %c (%d)" , statetoa(m_curState), statetoa(newState), c, c ); + parsingAborted(); + return false; + break; + case Action_InitTemp : + m_temp.clear(); + break; + case Action_CopyTemp : + m_temp.append (c); + break; + case Action_DecodeUnget : + m_buffer.append (decode()); + fin.ungetch(c); + break; + // in Postscript Quelltext: Kombination F} + case Action_ByteArraySpecial : + m_curState = State_Token; + doOutput(); + fin.ungetch(c); + break; + default : + tqWarning ( "unknown action: %d ", action); + } + + m_curState = newState; + } + + parsingFinished(); + return true; +} + +void AILexer::doOutput () +{ + if (m_buffer.length() == 0) return; + switch (m_curState) + { + case State_Comment : + gotComment (m_buffer.latin1()); + break; + case State_Integer : + gotIntValue (m_buffer.toInt()); + break; + case State_Float : + gotDoubleValue (m_buffer.toFloat()); + break; + case State_String : + gotStringValue (m_buffer.latin1()); + break; + case State_Token : + gotToken (m_buffer.latin1()); + break; + case State_Reference : + gotReference (m_buffer.latin1()); + break; + case State_BlockStart : + gotBlockStart (); + break; + case State_BlockEnd : + gotBlockEnd (); + break; + case State_Start : + break; + case State_ArrayStart : + gotArrayStart (); + break; + case State_ArrayEnd : + gotArrayEnd (); + break; + case State_Byte : + gotByte (getByte()); + break; + case State_ByteArray : + case State_ByteArray2 : + doHandleByteArray (); + break; + default: + tqWarning ( "unknown state: %d", m_curState ); + } + + m_buffer.clear(); +} + +void AILexer::gotComment (const char *value) { + tqDebug ( "gotComment: %s ", value ); +} + +void AILexer::gotIntValue (int value) { + tqDebug ( "gotInt: %d ", value ); +} + +void AILexer::gotDoubleValue (double value) { + tqDebug ( "gotDouble: %f ", value ); +} + +void AILexer::gotStringValue (const char *value) { + tqDebug ( "gotString: %s ", value ); +} + +void AILexer::gotToken (const char *value) { + tqDebug ( "gotToken: %s ", value ); +} + +void AILexer::gotReference (const char *value) { + tqDebug ( "gotReference: %s ", value ); +} + +void AILexer::gotBlockStart (){ + tqDebug ( "gotBlockStart" ); +} + +void AILexer::gotBlockEnd (){ + tqDebug ( "gotBlockEnd" ); +} + +void AILexer::gotArrayStart (){ + tqDebug ( "gotArrayStart" ); +} + +void AILexer::gotArrayEnd (){ + tqDebug ( "gotArrayEnd" ); +} + +void AILexer::parsingStarted() { + tqDebug ( "parsing started" ); +} + +void AILexer::parsingFinished() { + tqDebug ( "parsing finished" ); +} + +void AILexer::parsingAborted() { + tqDebug ( "parsing aborted" ); +} + +void AILexer::gotByte (uchar value) { + tqDebug ( "got byte %d" , value ); +} + +void AILexer::gotByteArray (const TQByteArray &data) { + tqDebug ( "got byte array" ); +/* for ( uint i = 0; i < data.size(); i++ ) + { + uchar value = data[i]; + tqDebug( "%d: %x", i, value ); + } + tqDebug ( "/byte array" ); */ + +} + + +void AILexer::nextStep (char c, State *newState, Action *newAction) { + int i=0; + + while (true) { + Transition trans = transitions[i]; + + if (trans.c == STOP) { + *newState = trans.newState; + *newAction = trans.action; + return; + } + + bool found = false; + + if (trans.oldState == m_curState) { + switch (trans.c) { + case CATEGORY_WHITESPACE : found = isspace(c); break; + case CATEGORY_ALPHA : found = isalpha(c); break; + case CATEGORY_DIGIT : found = isdigit(c); break; + case CATEGORY_SPECIAL : found = isSpecial(c); break; + case CATEGORY_LETTERHEX : found = isletterhex(c); break; + case CATEGORY_INTTOOLONG : found = m_buffer.length() > MAX_INTLEN; break; + case CATEGORY_ANY : found = true; break; + default : found = (trans.c == c); + } + + if (found) { + *newState = trans.newState; + *newAction = trans.action; + + return; + } + } + + + i++; + } +} + +void AILexer::doHandleByteArray () +{ + // Special case - too short + if (m_buffer.length () < MIN_HEXCHARS) + { + gotToken (m_buffer.latin1()); + return; + } + + uint strIdx = 0; + uint arrayIdx = 0; + + TQByteArray data (m_buffer.length() >> 1); + + while (strIdx < m_buffer.length()) + { + const TQString &item = m_buffer.mid (strIdx, 2); + uchar val = item.toShort(NULL, 16); + data[arrayIdx] = val; + strIdx += 2; + arrayIdx++; + } + + gotByteArray (data); +} + +uchar AILexer::getByte() +{ +// tqDebug ("convert string to byte (%s)", m_buffer.latin1()); + + TQStringList list = TQStringList::split ("#", m_buffer.toString()); + int radix = list[0].toShort(); + uchar value = list[1].toShort (NULL, radix); + + return value; +} + +uchar AILexer::decode() +{ + uchar value = m_temp.toString().toShort(NULL, 8); +// tqDebug ("got encoded char %c",value); + return value; +} + +/* StringBuffer implementation */ + +int initialSize = 20; +int addSize = 10; + +StringBuffer::StringBuffer () { + m_buffer = (char*)calloc (initialSize, sizeof(char)); + m_length = 0; + m_capacity = initialSize; +} + +StringBuffer::~StringBuffer (){ + free(m_buffer); +} + +void StringBuffer::append (char c){ + ensureCapacity(m_length + 1); + m_buffer[m_length] = c; + m_length++; +} + +void StringBuffer::clear(){ + for (uint i=0; i= p_capacity) return; + + int newSize = m_capacity + addSize; + if (p_capacity > newSize) newSize = p_capacity; + + char* oldBuffer = m_buffer; + char *newBuffer = (char*)calloc (newSize, sizeof(char)); + strcpy (newBuffer, m_buffer); + free(oldBuffer); + m_buffer = newBuffer; + m_capacity = newSize; +} + +uint StringBuffer::length() { + return m_length; +} + +double StringBuffer::toFloat() { + TQString data = toString(); + return data.toFloat(); +} + +int StringBuffer::toInt() { + TQString data = toString(); + return data.toInt(); +} + +const char *StringBuffer::latin1() { + return m_buffer; +} + +TQString StringBuffer::mid( uint index, uint len) const { + TQString data = toString(); + return data.mid(index,len); +} diff --git a/filters/karbon/ai/aiparserbase.cc b/filters/karbon/ai/aiparserbase.cc deleted file mode 100644 index 24f9920e..00000000 --- a/filters/karbon/ai/aiparserbase.cc +++ /dev/null @@ -1,1337 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002, Dirk Schönberger - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "aiparserbase.h" -#include "ai88handler.h" -#include "ai3handler.h" -#include -#include - -typedef struct { - char* op; - AIOperation action; -} AIOperationMapping; - -typedef struct { - char* op; - PSOperation action; -} PSOperationMapping; - -typedef struct { - char* op; - CommentOperation action; -} CommentOperationMapping; - -static AIOperationMapping aiMappings[] = { - { "k", AIO_SetFillColorCMYK }, - { "K", AIO_SetStrokeColorCMYK }, - { "g", AIO_SetFillColorGray }, - { "G", AIO_SetStrokeColorGray }, - { "x", AIO_SetFillColorCustom }, - { "X", AIO_SetStrokeColorCustom }, - { "p", AIO_SetFillPattern }, - { "P", AIO_SetStrokePattern }, - { "O", AIO_SetFillOverprinting }, - { "R", AIO_SetStrokeOverprinting }, - { "i", AIO_SetFlatness }, - { "J", AIO_SetLineCap }, - { "j", AIO_SetLineJoin }, - { "M", AIO_SetMiterLimit }, - { "w", AIO_SetLineWidth }, - { "d", AIO_SetDash }, - { "q", AIO_BeginGroupClip }, - { "Q", AIO_EndGroupClip }, - { "m", AIO_MoveTo }, - { "l", AIO_LineToSmooth }, - { "L", AIO_LineToCorner }, - { "c", AIO_CurveToSmooth }, - { "C", AIO_CurveToCorner }, - - { "v", AIO_CurveToOmitC1Smooth }, - { "V", AIO_CurveToOmitC1Corner }, - { "y", AIO_CurveToOmitC2Smooth }, - { "Y", AIO_CurveToOmitC2Corner }, - - { "H", AIO_PathIgnoreNoReset }, - { "h", AIO_PathIgnoreNoResetClose }, - { "W", AIO_PathClipPath }, - { "N", AIO_PathIgnoreReset }, - { "n", AIO_PathIgnoreResetClose }, - { "F", AIO_PathFillNonZero }, - { "f", AIO_PathFillNonZeroClose }, - { "B", AIO_PathFillNoReset }, - { "b", AIO_PathFillNoResetClose }, - { "S", AIO_PathStroke }, - { "s", AIO_PathStrokeClose }, - { "D", AIO_SetWindingOrder }, - { "Z", AIO_FontEncoding }, - { "E", AIO_PatternDefinition }, - { "A", AIO_LockElement }, - - { "z", AIO_SetCurrentText }, - { "a", AIO_TextBlockFillStroke }, - { "e", AIO_TextBlockFill }, - { "I", AIO_TextBlockAppend }, - { "o", AIO_TextBlockIgnore }, - { "r", AIO_TextBlockStroke }, - { "t", AIO_TextOutput }, - { "T", AIO_TextBlockEnd }, - { "`", AIO_GsaveIncludeDocument }, - { "~", AIO_Grestore }, - - { "u", AIO_BeginGroupNoClip }, - { "U", AIO_EndGroupNoClip }, - { "*u", AIO_BeginCombination }, - { "*U", AIO_EndCombination }, - - { "XR", AIO_SetFillMode }, - - { NULL, AIO_Other } -}; - -static PSOperationMapping psMappings[] = { - { "get", PSO_Get }, - { "exec", PSO_Exec }, - { "string", PSO_String }, - { "bind", PSO_Bind }, - { "def", PSO_Def }, - { "userdict", PSO_Userdict }, - { "dict", PSO_Dict }, - { "dup", PSO_Dup }, - { "begin", PSO_Begin }, - { "put", PSO_Put }, - { NULL, PSO_Other }, -}; - -static CommentOperationMapping commentMappings[] = { - { "BeginProlog", CO_BeginProlog }, - { "BeginSetup", CO_BeginSetup }, - { "BeginProcSet", CO_BeginProcSet }, - { "BeginResource", CO_BeginResource }, - { "BeginEncoding", CO_BeginEncoding }, - { "BeginPattern", CO_BeginPattern }, - { "BeginDocument", CO_BeginPattern }, - { "Trailer", CO_Trailer }, - { "EndProlog", CO_EndProlog }, - { "EndSetup", CO_EndSetup }, - { "EndProcSet", CO_EndProcSet }, - { "EndResource", CO_EndResource }, - { "EndEncoding", CO_EndEncoding }, - { "EndPattern", CO_EndPattern }, - { "EndDocument", CO_EndDocument }, - - { "Title", CO_Title }, - { "Creator", CO_Creator }, - - { "EOF", CO_Ignore }, - { "Note", CO_Ignore }, - { "EndComments", CO_Ignore }, - { "PS-Adobe", CO_Ignore }, - - { "BoundingBox", CO_BoundingBox }, - { "TemplateBox", CO_TemplateBox }, - { "AI3_Margin", CO_Margin }, - - { "For", CO_For }, - { "CreationDate", CO_CreationDate }, - { "DocumentFonts", CO_DocumentFonts }, - { "DocumentFiles", CO_DocumentFiles }, - { "ColorUsage", CO_ColorUsage }, - { "DocumentProcSets", CO_DocumentProcSets }, - { "DocumentSuppliedProcSets", CO_DocumentSuppliedProcSets }, - - { "DocumentProcessColors", CO_DocumentProcessColors }, - { "DocumentCustomColors", CO_DocumentCustomColors }, - { "CMYKCustomColor", CO_CMYKCustomColor }, - { "TileBox", CO_TileBox }, - { "%+", CO_Continuation }, - - { "Template", CO_Template }, - { "PageOrigin", CO_PageOrigin }, - { "PrinterName", CO_PrinterName }, - { "PrinterRect", CO_PrinterRect }, - { "Note", CO_Note }, - - { "DocumentNeededResources", CO_DocumentNeededResources }, - - - { "IncludeFont", CO_IncludeFont }, - { "BeginBrushPattern", CO_BeginBrushPattern }, - { "EndBrushPattern", CO_EndBrushPattern }, - { "BeginGradient", CO_BeginGradient }, - { "EndGradient", CO_EndGradient }, - { "BeginPalette", CO_BeginPalette }, - { "EndPalette", CO_EndPalette }, - - { "IncludeFile", CO_IncludeFile }, - { "IncludeResource", CO_IncludeResource }, - - { NULL, CO_Other } -}; - -AIParserBase::AIParserBase() : m_debug(false), m_ignoring(false), m_sink (DS_Other), m_continuationMode(CM_None) - { - m_gstateHandler = NULL; - m_structureHandler = NULL; - m_pathHandler = NULL; - m_miscGStateHandler = NULL; - m_documentHandler = NULL; - m_moduleHandler = NULL; - m_embeddedHandler = NULL; - m_ai88Handler = new AI88Handler(this); - m_ai3Handler = new AI3Handler(this); -} - -AIParserBase::~AIParserBase(){ - delete m_ai88Handler; - delete m_ai3Handler; - -} - -bool AIParserBase::parse (TQIODevice& fin){ - return AILexer::parse (fin); -} - -void AIParserBase::gotComment (const char *value) { - int llx, lly, urx, ury; - - CommentOperation cop = getCommentOperation (value); - switch (cop) { - case CO_BeginDocument : - if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Document, value); - break; - case CO_EndDocument : - if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Document, value); - break; - case CO_BeginPattern : - if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Pattern, value); - break; - case CO_EndPattern : - if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Pattern, value); - break; - case CO_BeginProlog : - if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Prolog, value); - break; - case CO_BeginProcSet : - if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_ProcSet, value); - if (m_debug) tqDebug ("start ignoring"); - m_ignoring = true; - break; - case CO_BeginResource : - if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Resource, value); - if (m_debug) tqDebug ("start ignoring"); - m_ignoring = true; - break; - case CO_BeginEncoding : - if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Encoding, value); - m_ignoring = false; - break; - case CO_IncludeFont : - if (m_debug) tqDebug ("start ignoring"); - m_ignoring = true; - break; - case CO_BeginBrushPattern : - if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_BrushPattern, value); - break; - case CO_BeginGradient : - if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Gradient, value); - break; - case CO_Trailer : - if (m_debug) tqDebug ("start ignoring"); - m_ignoring = true; - break; - case CO_BeginPalette : - if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Palette, value); - break; - case CO_BeginSetup : - if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Setup, value); - break; - case CO_EndSetup : - cleanupArrays(); - if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Setup, value); - break; - case CO_EndProlog : - if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Prolog, value); - break; - case CO_EndProcSet : - if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_ProcSet, value); - if (m_debug) tqDebug ("stop ignoring"); - m_ignoring = false; - break; - case CO_EndResource : - if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Resource, value); - if (m_debug) tqDebug ("stop ignoring"); - m_ignoring = false; - break; - case CO_EndEncoding : - cleanupArrays(); - if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Encoding, value); - break; - case CO_EndBrushPattern : - cleanupArrays(); - if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_BrushPattern, value); - break; - case CO_EndGradient : - cleanupArrays(); - if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Gradient, value); - break; - case CO_EndPalette : - cleanupArrays(); - if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Palette, value); - break; - case CO_Ignore : - break; - case CO_BoundingBox : - if (getRectangle (value, llx, lly, urx, ury)) - { - if (m_documentHandler) m_documentHandler->gotBoundingBox (llx, lly, urx, ury); - } - break; - case CO_TemplateBox : - if (getRectangle (value, llx, lly, urx, ury)) - { - if (m_documentHandler) m_documentHandler->gotTemplateBox (llx, lly, urx, ury); - } - break; - case CO_Margin : - if (getRectangle (value, llx, lly, urx, ury)) - { - if (m_documentHandler) m_documentHandler->gotMargin (llx, lly, urx, ury); - } - break; - case CO_Title : - if (m_documentHandler) m_documentHandler->gotTitle (getValue (value)); - break; - case CO_Creator : - if (m_documentHandler) m_documentHandler->gotCreator (getValue (value)); - break; - case CO_DocumentFonts : - _handleDocumentFonts (value); - m_continuationMode = CM_DocumentFonts; - break; - case CO_DocumentFiles : - _handleDocumentFiles (value); - m_continuationMode = CM_DocumentFiles; - break; - case CO_DocumentCustomColors : - _handleDocumentCustomColors (value); - m_continuationMode = CM_DocumentFiles; - break; - case CO_CMYKCustomColor : - _handleCMYKCustomColor (value); - m_continuationMode = CM_CMYKCustomColor; - break; - case CO_DocumentNeededResources : - _handleDocumentNeededResources (value); - m_continuationMode = CM_DocumentNeededResources; - break; - case CO_DocumentProcessColors : - _handleDocumentProcessColors (value); - break; - case CO_CreationDate : - _handleCreationDate (value); - break; - case CO_IncludeFile : - break; - case CO_IncludeResource : - _handleIncludeResource (value); - break; - case CO_Continuation : - switch (m_continuationMode) { - case CM_DocumentFonts : _handleDocumentFonts (value); break; - case CM_DocumentFiles : _handleDocumentFiles (value); break; - case CM_DocumentCustomColors : _handleDocumentCustomColors (value); break; - case CM_CMYKCustomColor : _handleCMYKCustomColor (value); break; - case CM_DocumentNeededResources : _handleDocumentNeededResources (value); break; - - default : tqWarning ("unknown continuation mode %d",m_continuationMode); - } - break; - - default : - tqWarning( "unhandled comment: %s", value ); - } -} - -void AIParserBase::handleElement (AIElement &element) -{ - if (m_ignoring) return; - - if (m_sink == DS_Array) - { - if (m_debug) tqDebug ("in mode array"); - TQValueVector &elementArray = m_arrayStack.top(); - elementArray.push_back(element); - } - if (m_sink == DS_Block) - { - if (m_debug) tqDebug ("in mode block"); - TQValueVector &elementArray = m_blockStack.top(); - elementArray.push_back(element); - } - else - { - if (m_debug) tqDebug ("in mode stack"); - m_stack.push (element); - } -} - -void AIParserBase::gotIntValue (int value) { - if (m_debug) tqDebug ("got int value"); - if (m_ignoring) return; - AIElement element (value); - handleElement (element); - if (m_debug) tqDebug ("/got int value"); -} - -void AIParserBase::gotDoubleValue (double value) { - if (m_debug) tqDebug ("got double value"); - if (m_ignoring) return; - AIElement element (value); - handleElement (element); - if (m_debug) tqDebug ("/got double value"); -} - -void AIParserBase::gotStringValue (const char *value) { - if (m_debug) tqDebug ("got string value"); - if (m_ignoring) return; - if (value == NULL) value = ""; - if (m_debug) tqDebug ("string: %s", value); - AIElement element (value); - handleElement (element); - if (m_debug) tqDebug ("/got string value"); - -} - -void AIParserBase::gotReference (const char *value) { - if (m_debug) tqDebug ("got reference value"); - - if (m_ignoring) return; - if (value == NULL) value = ""; - if (m_debug) tqDebug ("reference: %s", value); - TQString string(value); - AIElement element (string, AIElement::Reference); - handleElement (element); - if (m_debug) tqDebug ("/got reference value"); - -} - -void AIParserBase::gotByte (uchar value) { - if (m_debug) tqDebug ("got byte value"); - - if (m_ignoring) return; - AIElement element (value); - handleElement (element); - if (m_debug) tqDebug ("/got byte value"); -} - -void AIParserBase::gotByteArray (const TQByteArray &data) { - if (m_ignoring) return; - AIElement element (data); - handleElement (element); -} - - -void AIParserBase::gotArrayStart () { - if (m_ignoring) return; - if (m_debug) tqDebug ("got array start"); - - TQValueVector array; - m_arrayStack.push (array); - - m_sink = DS_Array; -} - -void AIParserBase::gotBlockStart () { - if (m_ignoring) return; - if (m_debug) tqDebug ("got block start"); - - TQValueVector array; - m_blockStack.push (array); - - m_sink = DS_Block; -} - -void AIParserBase::gotArrayEnd () { - if (m_ignoring) return; - if (m_debug) tqDebug ("got array end"); - - TQValueVector stackArray = m_arrayStack.pop(); - - if (m_arrayStack.empty()) - { - if (m_debug) tqDebug ("put elements to stack"); - AIElement realElement (stackArray); - - if (m_debug) { - tqDebug ("going to stack"); - elementtoa (realElement); - tqDebug ("done"); - } - m_stack.push (realElement); - - m_sink = DS_Other; - } - else - { - if (m_debug) tqDebug ("put elements to nest stack level"); - TQValueVector currentTOS = m_arrayStack.top(); - currentTOS.push_back (stackArray); - } -} - -void AIParserBase::gotBlockEnd () { - if (m_ignoring) return; - if (m_debug) tqDebug ("got block end"); - - TQValueVector stackArray = m_blockStack.pop(); - - if (m_blockStack.empty()) - { - if (m_debug) tqDebug ("put elements to stack"); - AIElement realElement (stackArray, AIElement::Block); - - if (m_debug) { - tqDebug ("going to stack"); - elementtoa (realElement); - tqDebug ("done"); - } - m_stack.push (realElement); - - m_sink = DS_Other; - } - else - { - if (m_debug) tqDebug ("put elements to nest stack level"); - TQValueVector currentTOS = m_blockStack.top(); - currentTOS.push_back (stackArray); - } -} - -/*Ai88*/ /* void AIParserBase::_handleSetDash() -{ - double fval = getDoubleValue(); - - AIElement elem (m_stack.top()); - m_stack.pop(); - - const TQValueVector aval = elem.toElementArray(); - if (m_gstateHandler) m_gstateHandler->gotDash (aval, fval); -} */ - -/*Ai88*/ /* void AIParserBase::_handleSetFillColorCMYK() -{ - double k = getDoubleValue(); - double y = getDoubleValue(); - double m = getDoubleValue(); - double c = getDoubleValue(); - - if (m_debug) tqDebug ("values 1 are %f %f %f %f",c,m,y,k); - AIColor color (c,m,y,k); - - if (m_gstateHandler) m_gstateHandler->gotFillColor (color); -} */ - -/*Ai88*/ /* void AIParserBase::_handleSetFillPattern() -{ - AIElement elem (m_stack.top()); - m_stack.pop(); - - const TQValueVector aval = elem.toElementArray(); - - double ka = getDoubleValue(); - double k = getDoubleValue(); - double r = getDoubleValue(); - double rf = getDoubleValue(); - double angle = getDoubleValue(); - double sy = getDoubleValue(); - double sx = getDoubleValue(); - double py = getDoubleValue(); - double px = getDoubleValue(); - - AIElement elem2 (m_stack.top()); - m_stack.pop(); - - const TQString &name = elem2.toString(); - if (m_gstateHandler) m_gstateHandler->gotFillPattern (name.latin1(), px, py, sx, sy, angle, rf, r, k, ka, aval); -} */ - -/*Ai88*/ /* void AIParserBase::_handleSetStrokePattern() -{ - AIElement elem (m_stack.top()); - m_stack.pop(); - - const TQValueVector aval = elem.toElementArray(); - - double ka = getDoubleValue(); - double k = getDoubleValue(); - double r = getDoubleValue(); - double rf = getDoubleValue(); - double angle = getDoubleValue(); - double sy = getDoubleValue(); - double sx = getDoubleValue(); - double py = getDoubleValue(); - double px = getDoubleValue(); - - AIElement elem2 (m_stack.top()); - m_stack.pop(); - - const TQString &name = elem2.toString(); - if (m_gstateHandler) m_gstateHandler->gotStrokePattern (name.latin1(), px, py, sx, sy, angle, rf, r, k, ka, aval); -} */ - -/*Ai88*/ /* void AIParserBase::_handleSetStrokeColorCMYK() -{ - double k = getDoubleValue(); - double y = getDoubleValue(); - double m = getDoubleValue(); - double c = getDoubleValue(); - if (m_debug) tqDebug ("values 2 are %f %f %f %f",c,m,y,k); - - AIColor color (c,m,y,k); - - if (m_gstateHandler) m_gstateHandler->gotStrokeColor (color); -} */ - -/*Ai88*/ /* void AIParserBase::_handleSetFillColorGray() -{ - double g = getDoubleValue(); - if (m_debug) tqDebug ("values 3 are %f",g); - - AIColor color (g); - - if (m_gstateHandler) m_gstateHandler->gotFillColor (color); -} */ - -/*Ai88*/ /* void AIParserBase::_handleSetStrokeColorGray() -{ - double g = getDoubleValue(); - if (m_debug) tqDebug ("values 4 are %f",g); - - AIColor color (g); - - if (m_gstateHandler) m_gstateHandler->gotStrokeColor (color); -} */ - -/*Ai88*/ /* void AIParserBase::_handleSetFillColorCustom() -{ - double g = getDoubleValue(); - const TQString &name = getStringValue(); - double k = getDoubleValue(); - double y = getDoubleValue(); - double m = getDoubleValue(); - double c = getDoubleValue(); - if (m_debug) tqDebug ("values 5 are %f %f %f %f",c,m,y,k); - - AIColor color (c,m,y,k,name.latin1(),g); - - if (m_gstateHandler) m_gstateHandler->gotFillColor (color); -} */ - -void AIParserBase::_handlePSGet() { - m_stack.pop(); - m_stack.pop(); - - TQString name ("xxx"); - AIElement ref (name,AIElement::Reference); - m_stack.push (ref); -} - -void AIParserBase::_handlePSExec() { - m_stack.pop(); -} - -void AIParserBase::_handlePSString() { - m_stack.pop(); - - TQString name ("stringval"); - AIElement ref (name,AIElement::Reference); - m_stack.push (ref); -} - -void AIParserBase::_handlePSBind() { - m_stack.pop(); - - TQString name ("bindentry"); - AIElement ref (name,AIElement::Reference); - m_stack.push (ref); -} - -void AIParserBase::_handlePSUserdict() { - TQString name ("userdict"); - AIElement ref (name,AIElement::Reference); - m_stack.push (ref); -} - -void AIParserBase::_handlePSDict() { - m_stack.pop(); - m_stack.pop(); - m_stack.pop(); - - TQString name ("dict"); - AIElement ref (name,AIElement::Reference); - m_stack.push (ref); -} - -void AIParserBase::_handlePSDup() { - AIElement &tos = m_stack.top(); - - AIElement copy (tos); - m_stack.push (copy); -} - -void AIParserBase::_handlePSBegin() { - m_stack.pop(); - - TQString name ("dictionary begin"); - AIElement ref (name,AIElement::Reference); - m_stack.push (ref); -} - -void AIParserBase::_handlePSPut() { - m_stack.pop(); - m_stack.pop(); -} - -/*Ai88*/ /* void AIParserBase::_handlePatternDefinition() -{ - AIElement elem (m_stack.top()); - m_stack.pop(); - - const TQValueVector aval = elem.toElementArray(); - - double ury = getDoubleValue(); - double urx = getDoubleValue(); - double lly = getDoubleValue(); - double llx = getDoubleValue(); - - AIElement elem2 (m_stack.top()); - m_stack.pop(); - - const TQString &name = elem2.toString(); - - if (m_documentHandler) m_documentHandler->gotPatternDefinition (name.latin1(), aval, llx, lly, urx, ury); -} */ - -void AIParserBase::_handlePSDef() { - // name ref - m_stack.pop(); - - // impl - m_stack.pop(); -} - -/*Ai88*/ /* void AIParserBase::_handleSetStrokeColorCustom() -{ - double g = getDoubleValue(); - const TQString &name = getStringValue(); - double k = getDoubleValue(); - double y = getDoubleValue(); - double m = getDoubleValue(); - double c = getDoubleValue(); - if (m_debug) tqDebug ("values 6 are %f %f %f %f",c,m,y,k); - - AIColor color (c,m,y,k,name.latin1(),g); - - if (m_gstateHandler) m_gstateHandler->gotStrokeColor (color); -} */ - -void AIParserBase::_handleDocumentFonts(const char *) { -} - -void AIParserBase::_handleDocumentFiles(const char *) { -} - -void AIParserBase::_handleDocumentCustomColors(const char *) { -} - -void AIParserBase::_handleDocumentNeededResources(const char *data) { - if (!data) return; - TQStringList items = TQStringList::split (' ', data); - - TQString itemType = items[1]; - TQString name = items[2]; - TQString version = items[3]; - TQString release = items[4]; -} - -void AIParserBase::_handleIncludeResource(const char *data) { - if (!data) return; - TQStringList items = TQStringList::split (' ', data); - - TQString itemType = items[1]; - TQString name = items[2]; - TQString version = items[3]; - TQString release = items[4]; - - m_modules.push_back (name); -} - -void AIParserBase::_handleDocumentProcessColors(const char *data) { - if (!data) return; - - int colorSet = 0; - TQString tmp (data); - - signed int index; - - index = tmp.find ("Cyan"); - if (index > 0) colorSet |= PC_Cyan; - - index = tmp.find ("Magenta"); - if (index > 0) colorSet |= PC_Magenta; - - index = tmp.find ("Yellow"); - if (index > 0) colorSet |= PC_Yellow; - - index = tmp.find ("Black"); - if (index > 0) colorSet |= PC_Black; - - if (m_documentHandler) m_documentHandler->gotProcessColors (colorSet); -} - -void AIParserBase::_handleCMYKCustomColor(const char *) { -} - -/*Ai88*/ /* void AIParserBase::_handleGsaveIncludeDocument() { - AIElement elem2 (m_stack.top()); - m_stack.pop(); - - const TQString &name = elem2.toString(); - - int ury = getIntValue(); - int urx = getIntValue(); - int lly = getIntValue(); - int llx = getIntValue(); - - AIElement elem (m_stack.top()); - m_stack.pop(); - - const TQValueVector aval = elem.toElementArray(); - - if (m_embeddedHandler) m_embeddedHandler->gotGsaveIncludeDocument (aval, llx,lly,urx,ury,name.latin1()); -} */ - -/*Ai88*/ /* void AIParserBase::_handleSetCurrentText() { - int iAlign = getIntValue(); - TextAlign ta = TA_HLeft; - - switch (iAlign) - { - case 0 : ta = TA_HLeft; break; - case 1 : ta = TA_HCenter; break; - case 2 : ta = TA_HRight; break; - case 3: ta = TA_VTop; break; - case 4 : ta = TA_VCenter; break; - case 5 : ta = TA_VBottom; break; - } - - double kerning = getDoubleValue(); - double leading = getDoubleValue(); - double size = getDoubleValue(); - - AIElement elem2 (m_stack.top()); - m_stack.pop(); - - const TQString &fontname = elem2.toReference(); - - if (m_textHandler) m_textHandler->gotFontDefinition (fontname.latin1(), size, leading, kerning, ta); -} */ - -/*Ai88*/ /* void AIParserBase::_handleTextBlock (TextOperation to) { - AIElement elem (m_stack.top()); - tqDebug ("to element is (%s)",elem.typeName()); - m_stack.pop(); - - const TQValueVector aval = elem.toElementArray(); - - if (m_textHandler) m_textHandler->gotTextBlockBegin (aval, to); -} */ - -/*Ai88*/ /* void AIParserBase::_handleTextOutput () { - AIElement elem (m_stack.top()); - m_stack.pop(); - - const TQString &text = elem.toString(); - - int length = -1; - - if (m_stack.empty()) - { - AIElement elem2 (m_stack.top()); - if (elem2.type() == AIElement::Int) - { - length = elem2.asInt(); - m_stack.pop(); - } - } - if (m_textHandler) m_textHandler->gotTextOutput (text.latin1(), length); -} */ - -void AIParserBase::_handleCreationDate (const char *data) -{ - if (!data) return; - - TQRegExp test ("\\((.+)\\) \\((.+)\\)"); - if (test.search (data)) - { - TQString val1 = test.cap(1); - TQString val2 = test.cap(2); - - if (m_documentHandler) m_documentHandler->gotCreationDate (val1.latin1(),val2.latin1()); - } -} - -void AIParserBase::gotToken (const char *value) { - if (m_debug) tqDebug ("got token"); - - if (m_ignoring) return; - if (m_debug) tqDebug ("token: %s", value); - - if (m_sink == DS_Array) - { - if (m_debug) tqDebug ("token in array"); - TQString op (value); - AIElement realElement (op, AIElement::Operator); - handleElement (realElement); - - return; - } - if (m_sink == DS_Block) - { - if (m_debug) tqDebug ("token in block"); - TQString op (value); - AIElement realElement (op, AIElement::Operator); - handleElement (realElement); - - return; - } - - if (m_debug) tqDebug ("get ai operation"); - - AIOperation op = getAIOperation (value); -// PathElement pathElement; -// double fval; -// int ival; - - bool handled = false; - - handled = m_ai88Handler->handleAIOperation (op); - if (!handled) handled = m_ai3Handler->handleAIOperation (op); - - if (!handled) - { - if (m_sink == DS_Other) - { - if (handlePS (value)) return; - } - tqWarning ( "unknown operator: %s", value ); - - TQString string(value); - - if (m_modules.findIndex(string) != -1) - { - AIElement element (string, AIElement::Reference); - handleElement (element); - return; - } - - if (m_debug) stacktoa (m_stack); - tqWarning ( "pushing %s to stack", value ); - AIElement element (string, AIElement::Operator); - handleElement (element); - } - - if (m_debug) tqDebug ("/got token value"); -} - -bool AIParserBase::handlePS (const char *operand){ - if (m_ignoring) return false; - - PSOperation psop = getPSOperation (operand); - - switch (psop) - { - case PSO_Get : - _handlePSGet (); - return true; - case PSO_Exec : - _handlePSExec (); - return true; - case PSO_Def : - _handlePSDef (); - return true; - case PSO_String : - _handlePSString (); - return true; - case PSO_Bind : - _handlePSBind (); - return true; - case PSO_Userdict : - _handlePSUserdict (); - return true; - case PSO_Dict : - _handlePSDict (); - return true; - case PSO_Dup : - _handlePSDup (); - return true; - case PSO_Begin : - _handlePSBegin (); - return true; - case PSO_Put : - _handlePSPut (); - return true; - default: break; - } - return false; -} - -const double AIParserBase::getDoubleValue(void) { - const AIElement &elem = m_stack.pop(); - - return elem.toDouble(); -} - -const int AIParserBase::getIntValue(void) { - const AIElement &elem = m_stack.pop(); - - return elem.toInt(); -} - -const bool AIParserBase::getBoolValue(void) { - return getIntValue() == 1; -} - -const TQString AIParserBase::getStringValue(void) { - const AIElement &elem = m_stack.pop(); - - return elem.toString(); -} - -const TQString AIParserBase::getOperatorValue(void) { - const AIElement &elem = m_stack.pop(); - - return elem.toOperator(); -} - -AIOperation AIParserBase::getAIOperation (const char *operand) -{ - int i=0; - TQString cmpValue (operand); - - for(;;) { AIOperationMapping map = aiMappings[i]; - if (map.op == NULL) return AIO_Other; - if (cmpValue.compare (map.op) == 0) return map.action; - - i++; - } -} - -PSOperation AIParserBase::getPSOperation (const char *operand) -{ - int i=0; - TQString cmpValue (operand); - - for(;;) { PSOperationMapping map = psMappings[i]; - if (map.op == NULL) return PSO_Other; - if (cmpValue.compare (map.op) == 0) return map.action; - - i++; - } -} - -CommentOperation AIParserBase::getCommentOperation (const char *command) { - TQString data (command); - - signed int index; - - int i=0; - - for(;;) { - CommentOperationMapping map = commentMappings[i]; - if (map.op == NULL) return CO_Other; - index = data.find (map.op); - if (index >= 0) return map.action; - i++; - } -} - -void 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& transformData) { - tqDebug ( "got fill pattern %s %f %f %f %f %f %f %f %f %f", pname, px, py, sx, sy, angle, rf, r, k, ka); - arraytoa (transformData); - tqDebug ("/got fill pattern"); -} - -void 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& transformData) { - tqDebug ( "got stroke pattern %s %f %f %f %f %f %f %f %f %f", pname, px, py, sx, sy, angle, rf, r, k, ka); - arraytoa (transformData); - tqDebug ("/got stroke pattern"); -} - -const char *AIParserBase::getValue (const char *input) { - TQString data(input); - - signed int index = data.find (':'); - if (index < 0) return ""; - index++; - while (data.at(index) == ' ') index++; - return data.mid(index).latin1(); -} - -bool AIParserBase::getRectangle (const char* input, int &llx, int &lly, int &urx, int &ury) { - if (input == NULL) return false; - - TQString s(input); - if (s.contains ("(atend)")) return false; - TQStringList values = TQStringList::split (" ", input); - if (values.size() < 5) return false; - llx = values[1].toInt(); - lly = values[2].toInt(); - urx = values[3].toInt(); - ury = values[4].toInt(); - - return true; -} - -bool AIParserBase::getPoint (const char* input, int &x, int &y) { - if (input == NULL) return false; - - TQString s(input); - TQStringList values = TQStringList::split (" ", input); - - if (values.size() < 3) return false; - - x = values[1].toInt(); - y = values[2].toInt(); - - return true; -} - -void AIParserBase::cleanupArrays() -{ - if (m_sink == DS_Array) tqDebug ("unclosed array(s)."); - while (m_sink == DS_Array) gotArrayEnd (); - stacktoa (m_stack); -} - -/*Ai88*/ /* void AIParserBase::_handleFontEncoding() -{ - while (m_stack.top().type() != AIElement::Reference) { - m_stack.pop(); - } - - AIElement elem (m_stack.top()); - m_stack.pop(); - const TQString &oldFont = elem.toReference(); - - AIElement elem2 (m_stack.top()); - m_stack.pop(); - const TQString &newFont = elem2.toReference(); - - AIElement elem3 (m_stack.top()); - m_stack.pop(); - const TQValueVector encodingData = elem3.toElementArray(); - - if (m_textHandler) m_textHandler->gotFontEncoding (encodingData, oldFont.latin1(), newFont.latin1()); -} */ - -void TextHandlerBase::gotFontEncoding (const TQValueVector& encodingData, const char*oldFontName, const char*newFontName) -{ - tqDebug ("font encoding %s to %s",oldFontName, newFontName); - arraytoa (encodingData); - tqDebug ("/font encoding"); -} - -void TextHandlerBase::gotFontDefinition (const char*fontName, double size, double leading, double kerning, TextAlign align) -{ - tqDebug ("font definition: name %s size %f leading %f kerning %f align %d", fontName, size, leading, kerning, align); -} - -void TextHandlerBase::gotTextBlockBegin (const TQValueVector& transData, TextOperation mode) -{ - tqDebug ("text block begin %d",mode); - arraytoa (transData); - tqDebug ("/text block begin"); -} - -void TextHandlerBase::gotTextOutput (const char*text, int length) -{ - tqDebug ("text output (%s) %d",text,length); -} - -void TextHandlerBase::gotTextBlockEnd () -{ - tqDebug ("text block end"); -} - -const void elementtoa (const AIElement &/*data*/) -{ -/* AIElement::Type type = data.type(); - tqDebug ("type: %s", AIElement::typeToName (type)); - - switch (type) - { - case AIElement::String : - case AIElement::CString : - case AIElement::Int : - case AIElement::UInt : - case AIElement::Double : - tqDebug ("string value : %s",data.toString().latin1()); - break; - case AIElement::Reference : - tqDebug ("string value : %s",data.toReference().latin1()); - break; - case AIElement::Operator : - tqDebug ("string value : %s",data.toOperator().latin1()); - break; - case AIElement::ElementArray : - arraytoa (data.toElementArray()); - break; - case AIElement::Block : - arraytoa (data.toBlock()); - break; - - default : - tqDebug ("could not fetch data"); - } */ -} - -const void arraytoa (const TQValueVector &/*data*/) -{ -/* tqDebug ("array size is %d ",data.size()); - if (data.size() > 0) - { - tqDebug ("[[[[[[[[[[[[[[[[[[[["); - for (uint i=0; i< data.size(); i++) - { - elementtoa (data[i]); - } - tqDebug ("]]]]]]]]]]]]]]]]]]]]"); - } */ -} - -const void stacktoa (const TQValueStack &/*data*/) -{ -/* tqDebug ("stack size is %d",data.size()); - if (data.size() > 0) - { - tqDebug ("<<<<<<<<<<<<<<<<<<"); - for (uint i=0; i< data.size(); i++) - { - elementtoa (data[i]); - } - } - tqDebug (">>>>>>>>>>>>>>>>>>"); */ -} - -const void stacktoa2 (const TQValueStack >&/*data*/) -{ -/* tqDebug ("stack size is %d",data.size()); - - if (data.size() > 0) - { - tqDebug ("((((((((((((((((((((((("); - for (uint i=0; i< data.size(); i++) - { - arraytoa (data[i]); - } - tqDebug (")))))))))))))))))))))))"); - } */ -} - -const void aiotoa (AIOperation &data) -{ - switch (data) - { - case AIO_SetFillColorCMYK : tqDebug ("AIO_SetFillColorCMYK"); break; - case AIO_SetStrokeColorCMYK : tqDebug ("AIO_SetStrokeColorCMYK"); break; - case AIO_SetFillColorGray : tqDebug ("AIO_SetFillColorGray"); break; - case AIO_SetStrokeColorGray : tqDebug ("AIO_SetStrokeColorGray"); break; - case AIO_SetFillColorCustom : tqDebug ("AIO_SetFillColorCustom"); break; - case AIO_SetStrokeColorCustom : tqDebug ("AIO_SetStrokeColorCustom"); break; - case AIO_SetFillPattern : tqDebug ("AIO_SetFillPattern"); break; - case AIO_SetStrokePattern : tqDebug ("AIO_SetStrokePattern"); break; - case AIO_SetFillOverprinting : tqDebug ("AIO_SetFillOverprinting"); break; - case AIO_SetStrokeOverprinting : tqDebug ("AIO_SetStrokeOverprinting"); break; - case AIO_SetFlatness : tqDebug ("AIO_SetFlatness"); break; - case AIO_SetLineCap : tqDebug ("AIO_SetLineCap"); break; - case AIO_SetLineJoin : tqDebug ("AIO_SetLineJoin"); break; - case AIO_SetLineWidth : tqDebug ("AIO_SetLineWidth"); break; - case AIO_SetMiterLimit : tqDebug ("AIO_SetMiterLimit"); break; - case AIO_SetDash : tqDebug ("AIO_SetDash"); break; - case AIO_BeginGroupClip : tqDebug ("AIO_BeginGroupClip"); break; - case AIO_EndGroupClip : tqDebug ("AIO_EndGroupClip"); break; - case AIO_MoveTo : tqDebug ("AIO_MoveTo"); break; - case AIO_LineToCorner : tqDebug ("AIO_LineToCorner"); break; - case AIO_LineToSmooth : tqDebug ("AIO_LineToSmooth"); break; - case AIO_CurveToSmooth : tqDebug ("AIO_CurveToSmooth"); break; - case AIO_CurveToCorner : tqDebug ("AIO_CurveToCorner"); break; - case AIO_CurveToOmitC1Smooth : tqDebug ("AIO_CurveToOmitC1Smooth"); break; - case AIO_CurveToOmitC1Corner : tqDebug ("AIO_CurveToOmitC1Corner"); break; - case AIO_CurveToOmitC2Smooth : tqDebug ("AIO_CurveToOmitC2Smooth"); break; - case AIO_CurveToOmitC2Corner : tqDebug ("AIO_CurveToOmitC2Corner"); break; - case AIO_PathIgnoreNoReset : tqDebug ("AIO_PathIgnoreNoReset"); break; - case AIO_PathIgnoreNoResetClose : tqDebug ("AIO_PathIgnoreNoResetClose"); break; - case AIO_PathClipPath : tqDebug ("AIO_PathClipPath"); break; - case AIO_PathIgnoreReset : tqDebug ("AIO_PathIgnoreReset"); break; - case AIO_PathIgnoreResetClose : tqDebug ("AIO_PathIgnoreResetClose"); break; - case AIO_PathFillNonZero : tqDebug ("AIO_PathFillNonZero"); break; - case AIO_PathFillNonZeroClose : tqDebug ("AIO_PathFillNonZeroClose"); break; - case AIO_PathStroke : tqDebug ("AIO_PathStroke"); break; - case AIO_PathStrokeClose : tqDebug ("AIO_PathStrokeClose"); break; - case AIO_PathFillNoReset : tqDebug ("AIO_PathFillNoReset"); break; - case AIO_PathFillNoResetClose : tqDebug ("AIO_PathFillNoResetClose"); break; - case AIO_FontEncoding : tqDebug ("AIO_FontEncoding"); break; - case AIO_PatternDefinition : tqDebug ("AIO_PatternDefinition"); break; - case AIO_SetCurrentText : tqDebug ("AIO_SetCurrentText"); break; - case AIO_TextBlockFillStroke : tqDebug ("AIO_TextBlockFillStroke"); break; - case AIO_TextBlockFill : tqDebug ("AIO_TextBlockFill"); break; - case AIO_TextBlockAppend : tqDebug ("AIO_TextBlockAppend"); break; - case AIO_TextBlockIgnore : tqDebug ("AIO_TextBlockIgnore"); break; - case AIO_TextBlockStroke : tqDebug ("AIO_TextBlockStroke"); break; - case AIO_TextOutput : tqDebug ("AIO_TextOutput"); break; - case AIO_TextBlockEnd : tqDebug ("AIO_TextBlockEnd"); break; - case AIO_GsaveIncludeDocument : tqDebug ("AIO_GsaveIncludeDocument"); break; - case AIO_Grestore : tqDebug ("AIO_Grestore"); break; - case AIO_LockElement : tqDebug ("AIO_LockElement"); break; - case AIO_SetWindingOrder : tqDebug ("AIO_SetWindingOrder"); break; - default : tqDebug ("unknown"); - } -} - -const void sttoa (SectionType &data, bool begin) -{ - switch (data) - { - case ST_Setup : begin ? tqDebug ("start setup") : tqDebug ("end setup"); break; - case ST_Prolog : begin ? tqDebug ("start prolog") : tqDebug ("end prolog"); break; - case ST_ProcSet : begin ? tqDebug ("start procset") : tqDebug ("end procset"); break; - case ST_Encoding : begin ? tqDebug ("start encoding") : tqDebug ("end encoding"); break; - case ST_Pattern : begin ? tqDebug ("start pattern") : tqDebug ("end pattern"); break; - case ST_Document : begin ? tqDebug ("start document") : tqDebug ("end document"); break; - case ST_BrushPattern : begin ? tqDebug ("start brush pattern") : tqDebug ("end brush pattern"); break; - case ST_Gradient : begin ? tqDebug ("start gradient") : tqDebug ("end gradient"); break; - case ST_Palette : begin ? tqDebug ("start palette") : tqDebug ("end palette"); break; - case ST_Resource : begin ? tqDebug ("start resource") : tqDebug ("end resouce"); break; - - default : begin ? tqDebug ("unknown") : tqDebug ("end unknown"); - } -} - diff --git a/filters/karbon/ai/aiparserbase.cpp b/filters/karbon/ai/aiparserbase.cpp new file mode 100644 index 00000000..24f9920e --- /dev/null +++ b/filters/karbon/ai/aiparserbase.cpp @@ -0,0 +1,1337 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schönberger + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "aiparserbase.h" +#include "ai88handler.h" +#include "ai3handler.h" +#include +#include + +typedef struct { + char* op; + AIOperation action; +} AIOperationMapping; + +typedef struct { + char* op; + PSOperation action; +} PSOperationMapping; + +typedef struct { + char* op; + CommentOperation action; +} CommentOperationMapping; + +static AIOperationMapping aiMappings[] = { + { "k", AIO_SetFillColorCMYK }, + { "K", AIO_SetStrokeColorCMYK }, + { "g", AIO_SetFillColorGray }, + { "G", AIO_SetStrokeColorGray }, + { "x", AIO_SetFillColorCustom }, + { "X", AIO_SetStrokeColorCustom }, + { "p", AIO_SetFillPattern }, + { "P", AIO_SetStrokePattern }, + { "O", AIO_SetFillOverprinting }, + { "R", AIO_SetStrokeOverprinting }, + { "i", AIO_SetFlatness }, + { "J", AIO_SetLineCap }, + { "j", AIO_SetLineJoin }, + { "M", AIO_SetMiterLimit }, + { "w", AIO_SetLineWidth }, + { "d", AIO_SetDash }, + { "q", AIO_BeginGroupClip }, + { "Q", AIO_EndGroupClip }, + { "m", AIO_MoveTo }, + { "l", AIO_LineToSmooth }, + { "L", AIO_LineToCorner }, + { "c", AIO_CurveToSmooth }, + { "C", AIO_CurveToCorner }, + + { "v", AIO_CurveToOmitC1Smooth }, + { "V", AIO_CurveToOmitC1Corner }, + { "y", AIO_CurveToOmitC2Smooth }, + { "Y", AIO_CurveToOmitC2Corner }, + + { "H", AIO_PathIgnoreNoReset }, + { "h", AIO_PathIgnoreNoResetClose }, + { "W", AIO_PathClipPath }, + { "N", AIO_PathIgnoreReset }, + { "n", AIO_PathIgnoreResetClose }, + { "F", AIO_PathFillNonZero }, + { "f", AIO_PathFillNonZeroClose }, + { "B", AIO_PathFillNoReset }, + { "b", AIO_PathFillNoResetClose }, + { "S", AIO_PathStroke }, + { "s", AIO_PathStrokeClose }, + { "D", AIO_SetWindingOrder }, + { "Z", AIO_FontEncoding }, + { "E", AIO_PatternDefinition }, + { "A", AIO_LockElement }, + + { "z", AIO_SetCurrentText }, + { "a", AIO_TextBlockFillStroke }, + { "e", AIO_TextBlockFill }, + { "I", AIO_TextBlockAppend }, + { "o", AIO_TextBlockIgnore }, + { "r", AIO_TextBlockStroke }, + { "t", AIO_TextOutput }, + { "T", AIO_TextBlockEnd }, + { "`", AIO_GsaveIncludeDocument }, + { "~", AIO_Grestore }, + + { "u", AIO_BeginGroupNoClip }, + { "U", AIO_EndGroupNoClip }, + { "*u", AIO_BeginCombination }, + { "*U", AIO_EndCombination }, + + { "XR", AIO_SetFillMode }, + + { NULL, AIO_Other } +}; + +static PSOperationMapping psMappings[] = { + { "get", PSO_Get }, + { "exec", PSO_Exec }, + { "string", PSO_String }, + { "bind", PSO_Bind }, + { "def", PSO_Def }, + { "userdict", PSO_Userdict }, + { "dict", PSO_Dict }, + { "dup", PSO_Dup }, + { "begin", PSO_Begin }, + { "put", PSO_Put }, + { NULL, PSO_Other }, +}; + +static CommentOperationMapping commentMappings[] = { + { "BeginProlog", CO_BeginProlog }, + { "BeginSetup", CO_BeginSetup }, + { "BeginProcSet", CO_BeginProcSet }, + { "BeginResource", CO_BeginResource }, + { "BeginEncoding", CO_BeginEncoding }, + { "BeginPattern", CO_BeginPattern }, + { "BeginDocument", CO_BeginPattern }, + { "Trailer", CO_Trailer }, + { "EndProlog", CO_EndProlog }, + { "EndSetup", CO_EndSetup }, + { "EndProcSet", CO_EndProcSet }, + { "EndResource", CO_EndResource }, + { "EndEncoding", CO_EndEncoding }, + { "EndPattern", CO_EndPattern }, + { "EndDocument", CO_EndDocument }, + + { "Title", CO_Title }, + { "Creator", CO_Creator }, + + { "EOF", CO_Ignore }, + { "Note", CO_Ignore }, + { "EndComments", CO_Ignore }, + { "PS-Adobe", CO_Ignore }, + + { "BoundingBox", CO_BoundingBox }, + { "TemplateBox", CO_TemplateBox }, + { "AI3_Margin", CO_Margin }, + + { "For", CO_For }, + { "CreationDate", CO_CreationDate }, + { "DocumentFonts", CO_DocumentFonts }, + { "DocumentFiles", CO_DocumentFiles }, + { "ColorUsage", CO_ColorUsage }, + { "DocumentProcSets", CO_DocumentProcSets }, + { "DocumentSuppliedProcSets", CO_DocumentSuppliedProcSets }, + + { "DocumentProcessColors", CO_DocumentProcessColors }, + { "DocumentCustomColors", CO_DocumentCustomColors }, + { "CMYKCustomColor", CO_CMYKCustomColor }, + { "TileBox", CO_TileBox }, + { "%+", CO_Continuation }, + + { "Template", CO_Template }, + { "PageOrigin", CO_PageOrigin }, + { "PrinterName", CO_PrinterName }, + { "PrinterRect", CO_PrinterRect }, + { "Note", CO_Note }, + + { "DocumentNeededResources", CO_DocumentNeededResources }, + + + { "IncludeFont", CO_IncludeFont }, + { "BeginBrushPattern", CO_BeginBrushPattern }, + { "EndBrushPattern", CO_EndBrushPattern }, + { "BeginGradient", CO_BeginGradient }, + { "EndGradient", CO_EndGradient }, + { "BeginPalette", CO_BeginPalette }, + { "EndPalette", CO_EndPalette }, + + { "IncludeFile", CO_IncludeFile }, + { "IncludeResource", CO_IncludeResource }, + + { NULL, CO_Other } +}; + +AIParserBase::AIParserBase() : m_debug(false), m_ignoring(false), m_sink (DS_Other), m_continuationMode(CM_None) + { + m_gstateHandler = NULL; + m_structureHandler = NULL; + m_pathHandler = NULL; + m_miscGStateHandler = NULL; + m_documentHandler = NULL; + m_moduleHandler = NULL; + m_embeddedHandler = NULL; + m_ai88Handler = new AI88Handler(this); + m_ai3Handler = new AI3Handler(this); +} + +AIParserBase::~AIParserBase(){ + delete m_ai88Handler; + delete m_ai3Handler; + +} + +bool AIParserBase::parse (TQIODevice& fin){ + return AILexer::parse (fin); +} + +void AIParserBase::gotComment (const char *value) { + int llx, lly, urx, ury; + + CommentOperation cop = getCommentOperation (value); + switch (cop) { + case CO_BeginDocument : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Document, value); + break; + case CO_EndDocument : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Document, value); + break; + case CO_BeginPattern : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Pattern, value); + break; + case CO_EndPattern : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Pattern, value); + break; + case CO_BeginProlog : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Prolog, value); + break; + case CO_BeginProcSet : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_ProcSet, value); + if (m_debug) tqDebug ("start ignoring"); + m_ignoring = true; + break; + case CO_BeginResource : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Resource, value); + if (m_debug) tqDebug ("start ignoring"); + m_ignoring = true; + break; + case CO_BeginEncoding : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Encoding, value); + m_ignoring = false; + break; + case CO_IncludeFont : + if (m_debug) tqDebug ("start ignoring"); + m_ignoring = true; + break; + case CO_BeginBrushPattern : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_BrushPattern, value); + break; + case CO_BeginGradient : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Gradient, value); + break; + case CO_Trailer : + if (m_debug) tqDebug ("start ignoring"); + m_ignoring = true; + break; + case CO_BeginPalette : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Palette, value); + break; + case CO_BeginSetup : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Setup, value); + break; + case CO_EndSetup : + cleanupArrays(); + if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Setup, value); + break; + case CO_EndProlog : + if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Prolog, value); + break; + case CO_EndProcSet : + if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_ProcSet, value); + if (m_debug) tqDebug ("stop ignoring"); + m_ignoring = false; + break; + case CO_EndResource : + if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Resource, value); + if (m_debug) tqDebug ("stop ignoring"); + m_ignoring = false; + break; + case CO_EndEncoding : + cleanupArrays(); + if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Encoding, value); + break; + case CO_EndBrushPattern : + cleanupArrays(); + if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_BrushPattern, value); + break; + case CO_EndGradient : + cleanupArrays(); + if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Gradient, value); + break; + case CO_EndPalette : + cleanupArrays(); + if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Palette, value); + break; + case CO_Ignore : + break; + case CO_BoundingBox : + if (getRectangle (value, llx, lly, urx, ury)) + { + if (m_documentHandler) m_documentHandler->gotBoundingBox (llx, lly, urx, ury); + } + break; + case CO_TemplateBox : + if (getRectangle (value, llx, lly, urx, ury)) + { + if (m_documentHandler) m_documentHandler->gotTemplateBox (llx, lly, urx, ury); + } + break; + case CO_Margin : + if (getRectangle (value, llx, lly, urx, ury)) + { + if (m_documentHandler) m_documentHandler->gotMargin (llx, lly, urx, ury); + } + break; + case CO_Title : + if (m_documentHandler) m_documentHandler->gotTitle (getValue (value)); + break; + case CO_Creator : + if (m_documentHandler) m_documentHandler->gotCreator (getValue (value)); + break; + case CO_DocumentFonts : + _handleDocumentFonts (value); + m_continuationMode = CM_DocumentFonts; + break; + case CO_DocumentFiles : + _handleDocumentFiles (value); + m_continuationMode = CM_DocumentFiles; + break; + case CO_DocumentCustomColors : + _handleDocumentCustomColors (value); + m_continuationMode = CM_DocumentFiles; + break; + case CO_CMYKCustomColor : + _handleCMYKCustomColor (value); + m_continuationMode = CM_CMYKCustomColor; + break; + case CO_DocumentNeededResources : + _handleDocumentNeededResources (value); + m_continuationMode = CM_DocumentNeededResources; + break; + case CO_DocumentProcessColors : + _handleDocumentProcessColors (value); + break; + case CO_CreationDate : + _handleCreationDate (value); + break; + case CO_IncludeFile : + break; + case CO_IncludeResource : + _handleIncludeResource (value); + break; + case CO_Continuation : + switch (m_continuationMode) { + case CM_DocumentFonts : _handleDocumentFonts (value); break; + case CM_DocumentFiles : _handleDocumentFiles (value); break; + case CM_DocumentCustomColors : _handleDocumentCustomColors (value); break; + case CM_CMYKCustomColor : _handleCMYKCustomColor (value); break; + case CM_DocumentNeededResources : _handleDocumentNeededResources (value); break; + + default : tqWarning ("unknown continuation mode %d",m_continuationMode); + } + break; + + default : + tqWarning( "unhandled comment: %s", value ); + } +} + +void AIParserBase::handleElement (AIElement &element) +{ + if (m_ignoring) return; + + if (m_sink == DS_Array) + { + if (m_debug) tqDebug ("in mode array"); + TQValueVector &elementArray = m_arrayStack.top(); + elementArray.push_back(element); + } + if (m_sink == DS_Block) + { + if (m_debug) tqDebug ("in mode block"); + TQValueVector &elementArray = m_blockStack.top(); + elementArray.push_back(element); + } + else + { + if (m_debug) tqDebug ("in mode stack"); + m_stack.push (element); + } +} + +void AIParserBase::gotIntValue (int value) { + if (m_debug) tqDebug ("got int value"); + if (m_ignoring) return; + AIElement element (value); + handleElement (element); + if (m_debug) tqDebug ("/got int value"); +} + +void AIParserBase::gotDoubleValue (double value) { + if (m_debug) tqDebug ("got double value"); + if (m_ignoring) return; + AIElement element (value); + handleElement (element); + if (m_debug) tqDebug ("/got double value"); +} + +void AIParserBase::gotStringValue (const char *value) { + if (m_debug) tqDebug ("got string value"); + if (m_ignoring) return; + if (value == NULL) value = ""; + if (m_debug) tqDebug ("string: %s", value); + AIElement element (value); + handleElement (element); + if (m_debug) tqDebug ("/got string value"); + +} + +void AIParserBase::gotReference (const char *value) { + if (m_debug) tqDebug ("got reference value"); + + if (m_ignoring) return; + if (value == NULL) value = ""; + if (m_debug) tqDebug ("reference: %s", value); + TQString string(value); + AIElement element (string, AIElement::Reference); + handleElement (element); + if (m_debug) tqDebug ("/got reference value"); + +} + +void AIParserBase::gotByte (uchar value) { + if (m_debug) tqDebug ("got byte value"); + + if (m_ignoring) return; + AIElement element (value); + handleElement (element); + if (m_debug) tqDebug ("/got byte value"); +} + +void AIParserBase::gotByteArray (const TQByteArray &data) { + if (m_ignoring) return; + AIElement element (data); + handleElement (element); +} + + +void AIParserBase::gotArrayStart () { + if (m_ignoring) return; + if (m_debug) tqDebug ("got array start"); + + TQValueVector array; + m_arrayStack.push (array); + + m_sink = DS_Array; +} + +void AIParserBase::gotBlockStart () { + if (m_ignoring) return; + if (m_debug) tqDebug ("got block start"); + + TQValueVector array; + m_blockStack.push (array); + + m_sink = DS_Block; +} + +void AIParserBase::gotArrayEnd () { + if (m_ignoring) return; + if (m_debug) tqDebug ("got array end"); + + TQValueVector stackArray = m_arrayStack.pop(); + + if (m_arrayStack.empty()) + { + if (m_debug) tqDebug ("put elements to stack"); + AIElement realElement (stackArray); + + if (m_debug) { + tqDebug ("going to stack"); + elementtoa (realElement); + tqDebug ("done"); + } + m_stack.push (realElement); + + m_sink = DS_Other; + } + else + { + if (m_debug) tqDebug ("put elements to nest stack level"); + TQValueVector currentTOS = m_arrayStack.top(); + currentTOS.push_back (stackArray); + } +} + +void AIParserBase::gotBlockEnd () { + if (m_ignoring) return; + if (m_debug) tqDebug ("got block end"); + + TQValueVector stackArray = m_blockStack.pop(); + + if (m_blockStack.empty()) + { + if (m_debug) tqDebug ("put elements to stack"); + AIElement realElement (stackArray, AIElement::Block); + + if (m_debug) { + tqDebug ("going to stack"); + elementtoa (realElement); + tqDebug ("done"); + } + m_stack.push (realElement); + + m_sink = DS_Other; + } + else + { + if (m_debug) tqDebug ("put elements to nest stack level"); + TQValueVector currentTOS = m_blockStack.top(); + currentTOS.push_back (stackArray); + } +} + +/*Ai88*/ /* void AIParserBase::_handleSetDash() +{ + double fval = getDoubleValue(); + + AIElement elem (m_stack.top()); + m_stack.pop(); + + const TQValueVector aval = elem.toElementArray(); + if (m_gstateHandler) m_gstateHandler->gotDash (aval, fval); +} */ + +/*Ai88*/ /* void AIParserBase::_handleSetFillColorCMYK() +{ + double k = getDoubleValue(); + double y = getDoubleValue(); + double m = getDoubleValue(); + double c = getDoubleValue(); + + if (m_debug) tqDebug ("values 1 are %f %f %f %f",c,m,y,k); + AIColor color (c,m,y,k); + + if (m_gstateHandler) m_gstateHandler->gotFillColor (color); +} */ + +/*Ai88*/ /* void AIParserBase::_handleSetFillPattern() +{ + AIElement elem (m_stack.top()); + m_stack.pop(); + + const TQValueVector aval = elem.toElementArray(); + + double ka = getDoubleValue(); + double k = getDoubleValue(); + double r = getDoubleValue(); + double rf = getDoubleValue(); + double angle = getDoubleValue(); + double sy = getDoubleValue(); + double sx = getDoubleValue(); + double py = getDoubleValue(); + double px = getDoubleValue(); + + AIElement elem2 (m_stack.top()); + m_stack.pop(); + + const TQString &name = elem2.toString(); + if (m_gstateHandler) m_gstateHandler->gotFillPattern (name.latin1(), px, py, sx, sy, angle, rf, r, k, ka, aval); +} */ + +/*Ai88*/ /* void AIParserBase::_handleSetStrokePattern() +{ + AIElement elem (m_stack.top()); + m_stack.pop(); + + const TQValueVector aval = elem.toElementArray(); + + double ka = getDoubleValue(); + double k = getDoubleValue(); + double r = getDoubleValue(); + double rf = getDoubleValue(); + double angle = getDoubleValue(); + double sy = getDoubleValue(); + double sx = getDoubleValue(); + double py = getDoubleValue(); + double px = getDoubleValue(); + + AIElement elem2 (m_stack.top()); + m_stack.pop(); + + const TQString &name = elem2.toString(); + if (m_gstateHandler) m_gstateHandler->gotStrokePattern (name.latin1(), px, py, sx, sy, angle, rf, r, k, ka, aval); +} */ + +/*Ai88*/ /* void AIParserBase::_handleSetStrokeColorCMYK() +{ + double k = getDoubleValue(); + double y = getDoubleValue(); + double m = getDoubleValue(); + double c = getDoubleValue(); + if (m_debug) tqDebug ("values 2 are %f %f %f %f",c,m,y,k); + + AIColor color (c,m,y,k); + + if (m_gstateHandler) m_gstateHandler->gotStrokeColor (color); +} */ + +/*Ai88*/ /* void AIParserBase::_handleSetFillColorGray() +{ + double g = getDoubleValue(); + if (m_debug) tqDebug ("values 3 are %f",g); + + AIColor color (g); + + if (m_gstateHandler) m_gstateHandler->gotFillColor (color); +} */ + +/*Ai88*/ /* void AIParserBase::_handleSetStrokeColorGray() +{ + double g = getDoubleValue(); + if (m_debug) tqDebug ("values 4 are %f",g); + + AIColor color (g); + + if (m_gstateHandler) m_gstateHandler->gotStrokeColor (color); +} */ + +/*Ai88*/ /* void AIParserBase::_handleSetFillColorCustom() +{ + double g = getDoubleValue(); + const TQString &name = getStringValue(); + double k = getDoubleValue(); + double y = getDoubleValue(); + double m = getDoubleValue(); + double c = getDoubleValue(); + if (m_debug) tqDebug ("values 5 are %f %f %f %f",c,m,y,k); + + AIColor color (c,m,y,k,name.latin1(),g); + + if (m_gstateHandler) m_gstateHandler->gotFillColor (color); +} */ + +void AIParserBase::_handlePSGet() { + m_stack.pop(); + m_stack.pop(); + + TQString name ("xxx"); + AIElement ref (name,AIElement::Reference); + m_stack.push (ref); +} + +void AIParserBase::_handlePSExec() { + m_stack.pop(); +} + +void AIParserBase::_handlePSString() { + m_stack.pop(); + + TQString name ("stringval"); + AIElement ref (name,AIElement::Reference); + m_stack.push (ref); +} + +void AIParserBase::_handlePSBind() { + m_stack.pop(); + + TQString name ("bindentry"); + AIElement ref (name,AIElement::Reference); + m_stack.push (ref); +} + +void AIParserBase::_handlePSUserdict() { + TQString name ("userdict"); + AIElement ref (name,AIElement::Reference); + m_stack.push (ref); +} + +void AIParserBase::_handlePSDict() { + m_stack.pop(); + m_stack.pop(); + m_stack.pop(); + + TQString name ("dict"); + AIElement ref (name,AIElement::Reference); + m_stack.push (ref); +} + +void AIParserBase::_handlePSDup() { + AIElement &tos = m_stack.top(); + + AIElement copy (tos); + m_stack.push (copy); +} + +void AIParserBase::_handlePSBegin() { + m_stack.pop(); + + TQString name ("dictionary begin"); + AIElement ref (name,AIElement::Reference); + m_stack.push (ref); +} + +void AIParserBase::_handlePSPut() { + m_stack.pop(); + m_stack.pop(); +} + +/*Ai88*/ /* void AIParserBase::_handlePatternDefinition() +{ + AIElement elem (m_stack.top()); + m_stack.pop(); + + const TQValueVector aval = elem.toElementArray(); + + double ury = getDoubleValue(); + double urx = getDoubleValue(); + double lly = getDoubleValue(); + double llx = getDoubleValue(); + + AIElement elem2 (m_stack.top()); + m_stack.pop(); + + const TQString &name = elem2.toString(); + + if (m_documentHandler) m_documentHandler->gotPatternDefinition (name.latin1(), aval, llx, lly, urx, ury); +} */ + +void AIParserBase::_handlePSDef() { + // name ref + m_stack.pop(); + + // impl + m_stack.pop(); +} + +/*Ai88*/ /* void AIParserBase::_handleSetStrokeColorCustom() +{ + double g = getDoubleValue(); + const TQString &name = getStringValue(); + double k = getDoubleValue(); + double y = getDoubleValue(); + double m = getDoubleValue(); + double c = getDoubleValue(); + if (m_debug) tqDebug ("values 6 are %f %f %f %f",c,m,y,k); + + AIColor color (c,m,y,k,name.latin1(),g); + + if (m_gstateHandler) m_gstateHandler->gotStrokeColor (color); +} */ + +void AIParserBase::_handleDocumentFonts(const char *) { +} + +void AIParserBase::_handleDocumentFiles(const char *) { +} + +void AIParserBase::_handleDocumentCustomColors(const char *) { +} + +void AIParserBase::_handleDocumentNeededResources(const char *data) { + if (!data) return; + TQStringList items = TQStringList::split (' ', data); + + TQString itemType = items[1]; + TQString name = items[2]; + TQString version = items[3]; + TQString release = items[4]; +} + +void AIParserBase::_handleIncludeResource(const char *data) { + if (!data) return; + TQStringList items = TQStringList::split (' ', data); + + TQString itemType = items[1]; + TQString name = items[2]; + TQString version = items[3]; + TQString release = items[4]; + + m_modules.push_back (name); +} + +void AIParserBase::_handleDocumentProcessColors(const char *data) { + if (!data) return; + + int colorSet = 0; + TQString tmp (data); + + signed int index; + + index = tmp.find ("Cyan"); + if (index > 0) colorSet |= PC_Cyan; + + index = tmp.find ("Magenta"); + if (index > 0) colorSet |= PC_Magenta; + + index = tmp.find ("Yellow"); + if (index > 0) colorSet |= PC_Yellow; + + index = tmp.find ("Black"); + if (index > 0) colorSet |= PC_Black; + + if (m_documentHandler) m_documentHandler->gotProcessColors (colorSet); +} + +void AIParserBase::_handleCMYKCustomColor(const char *) { +} + +/*Ai88*/ /* void AIParserBase::_handleGsaveIncludeDocument() { + AIElement elem2 (m_stack.top()); + m_stack.pop(); + + const TQString &name = elem2.toString(); + + int ury = getIntValue(); + int urx = getIntValue(); + int lly = getIntValue(); + int llx = getIntValue(); + + AIElement elem (m_stack.top()); + m_stack.pop(); + + const TQValueVector aval = elem.toElementArray(); + + if (m_embeddedHandler) m_embeddedHandler->gotGsaveIncludeDocument (aval, llx,lly,urx,ury,name.latin1()); +} */ + +/*Ai88*/ /* void AIParserBase::_handleSetCurrentText() { + int iAlign = getIntValue(); + TextAlign ta = TA_HLeft; + + switch (iAlign) + { + case 0 : ta = TA_HLeft; break; + case 1 : ta = TA_HCenter; break; + case 2 : ta = TA_HRight; break; + case 3: ta = TA_VTop; break; + case 4 : ta = TA_VCenter; break; + case 5 : ta = TA_VBottom; break; + } + + double kerning = getDoubleValue(); + double leading = getDoubleValue(); + double size = getDoubleValue(); + + AIElement elem2 (m_stack.top()); + m_stack.pop(); + + const TQString &fontname = elem2.toReference(); + + if (m_textHandler) m_textHandler->gotFontDefinition (fontname.latin1(), size, leading, kerning, ta); +} */ + +/*Ai88*/ /* void AIParserBase::_handleTextBlock (TextOperation to) { + AIElement elem (m_stack.top()); + tqDebug ("to element is (%s)",elem.typeName()); + m_stack.pop(); + + const TQValueVector aval = elem.toElementArray(); + + if (m_textHandler) m_textHandler->gotTextBlockBegin (aval, to); +} */ + +/*Ai88*/ /* void AIParserBase::_handleTextOutput () { + AIElement elem (m_stack.top()); + m_stack.pop(); + + const TQString &text = elem.toString(); + + int length = -1; + + if (m_stack.empty()) + { + AIElement elem2 (m_stack.top()); + if (elem2.type() == AIElement::Int) + { + length = elem2.asInt(); + m_stack.pop(); + } + } + if (m_textHandler) m_textHandler->gotTextOutput (text.latin1(), length); +} */ + +void AIParserBase::_handleCreationDate (const char *data) +{ + if (!data) return; + + TQRegExp test ("\\((.+)\\) \\((.+)\\)"); + if (test.search (data)) + { + TQString val1 = test.cap(1); + TQString val2 = test.cap(2); + + if (m_documentHandler) m_documentHandler->gotCreationDate (val1.latin1(),val2.latin1()); + } +} + +void AIParserBase::gotToken (const char *value) { + if (m_debug) tqDebug ("got token"); + + if (m_ignoring) return; + if (m_debug) tqDebug ("token: %s", value); + + if (m_sink == DS_Array) + { + if (m_debug) tqDebug ("token in array"); + TQString op (value); + AIElement realElement (op, AIElement::Operator); + handleElement (realElement); + + return; + } + if (m_sink == DS_Block) + { + if (m_debug) tqDebug ("token in block"); + TQString op (value); + AIElement realElement (op, AIElement::Operator); + handleElement (realElement); + + return; + } + + if (m_debug) tqDebug ("get ai operation"); + + AIOperation op = getAIOperation (value); +// PathElement pathElement; +// double fval; +// int ival; + + bool handled = false; + + handled = m_ai88Handler->handleAIOperation (op); + if (!handled) handled = m_ai3Handler->handleAIOperation (op); + + if (!handled) + { + if (m_sink == DS_Other) + { + if (handlePS (value)) return; + } + tqWarning ( "unknown operator: %s", value ); + + TQString string(value); + + if (m_modules.findIndex(string) != -1) + { + AIElement element (string, AIElement::Reference); + handleElement (element); + return; + } + + if (m_debug) stacktoa (m_stack); + tqWarning ( "pushing %s to stack", value ); + AIElement element (string, AIElement::Operator); + handleElement (element); + } + + if (m_debug) tqDebug ("/got token value"); +} + +bool AIParserBase::handlePS (const char *operand){ + if (m_ignoring) return false; + + PSOperation psop = getPSOperation (operand); + + switch (psop) + { + case PSO_Get : + _handlePSGet (); + return true; + case PSO_Exec : + _handlePSExec (); + return true; + case PSO_Def : + _handlePSDef (); + return true; + case PSO_String : + _handlePSString (); + return true; + case PSO_Bind : + _handlePSBind (); + return true; + case PSO_Userdict : + _handlePSUserdict (); + return true; + case PSO_Dict : + _handlePSDict (); + return true; + case PSO_Dup : + _handlePSDup (); + return true; + case PSO_Begin : + _handlePSBegin (); + return true; + case PSO_Put : + _handlePSPut (); + return true; + default: break; + } + return false; +} + +const double AIParserBase::getDoubleValue(void) { + const AIElement &elem = m_stack.pop(); + + return elem.toDouble(); +} + +const int AIParserBase::getIntValue(void) { + const AIElement &elem = m_stack.pop(); + + return elem.toInt(); +} + +const bool AIParserBase::getBoolValue(void) { + return getIntValue() == 1; +} + +const TQString AIParserBase::getStringValue(void) { + const AIElement &elem = m_stack.pop(); + + return elem.toString(); +} + +const TQString AIParserBase::getOperatorValue(void) { + const AIElement &elem = m_stack.pop(); + + return elem.toOperator(); +} + +AIOperation AIParserBase::getAIOperation (const char *operand) +{ + int i=0; + TQString cmpValue (operand); + + for(;;) { AIOperationMapping map = aiMappings[i]; + if (map.op == NULL) return AIO_Other; + if (cmpValue.compare (map.op) == 0) return map.action; + + i++; + } +} + +PSOperation AIParserBase::getPSOperation (const char *operand) +{ + int i=0; + TQString cmpValue (operand); + + for(;;) { PSOperationMapping map = psMappings[i]; + if (map.op == NULL) return PSO_Other; + if (cmpValue.compare (map.op) == 0) return map.action; + + i++; + } +} + +CommentOperation AIParserBase::getCommentOperation (const char *command) { + TQString data (command); + + signed int index; + + int i=0; + + for(;;) { + CommentOperationMapping map = commentMappings[i]; + if (map.op == NULL) return CO_Other; + index = data.find (map.op); + if (index >= 0) return map.action; + i++; + } +} + +void 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& transformData) { + tqDebug ( "got fill pattern %s %f %f %f %f %f %f %f %f %f", pname, px, py, sx, sy, angle, rf, r, k, ka); + arraytoa (transformData); + tqDebug ("/got fill pattern"); +} + +void 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& transformData) { + tqDebug ( "got stroke pattern %s %f %f %f %f %f %f %f %f %f", pname, px, py, sx, sy, angle, rf, r, k, ka); + arraytoa (transformData); + tqDebug ("/got stroke pattern"); +} + +const char *AIParserBase::getValue (const char *input) { + TQString data(input); + + signed int index = data.find (':'); + if (index < 0) return ""; + index++; + while (data.at(index) == ' ') index++; + return data.mid(index).latin1(); +} + +bool AIParserBase::getRectangle (const char* input, int &llx, int &lly, int &urx, int &ury) { + if (input == NULL) return false; + + TQString s(input); + if (s.contains ("(atend)")) return false; + TQStringList values = TQStringList::split (" ", input); + if (values.size() < 5) return false; + llx = values[1].toInt(); + lly = values[2].toInt(); + urx = values[3].toInt(); + ury = values[4].toInt(); + + return true; +} + +bool AIParserBase::getPoint (const char* input, int &x, int &y) { + if (input == NULL) return false; + + TQString s(input); + TQStringList values = TQStringList::split (" ", input); + + if (values.size() < 3) return false; + + x = values[1].toInt(); + y = values[2].toInt(); + + return true; +} + +void AIParserBase::cleanupArrays() +{ + if (m_sink == DS_Array) tqDebug ("unclosed array(s)."); + while (m_sink == DS_Array) gotArrayEnd (); + stacktoa (m_stack); +} + +/*Ai88*/ /* void AIParserBase::_handleFontEncoding() +{ + while (m_stack.top().type() != AIElement::Reference) { + m_stack.pop(); + } + + AIElement elem (m_stack.top()); + m_stack.pop(); + const TQString &oldFont = elem.toReference(); + + AIElement elem2 (m_stack.top()); + m_stack.pop(); + const TQString &newFont = elem2.toReference(); + + AIElement elem3 (m_stack.top()); + m_stack.pop(); + const TQValueVector encodingData = elem3.toElementArray(); + + if (m_textHandler) m_textHandler->gotFontEncoding (encodingData, oldFont.latin1(), newFont.latin1()); +} */ + +void TextHandlerBase::gotFontEncoding (const TQValueVector& encodingData, const char*oldFontName, const char*newFontName) +{ + tqDebug ("font encoding %s to %s",oldFontName, newFontName); + arraytoa (encodingData); + tqDebug ("/font encoding"); +} + +void TextHandlerBase::gotFontDefinition (const char*fontName, double size, double leading, double kerning, TextAlign align) +{ + tqDebug ("font definition: name %s size %f leading %f kerning %f align %d", fontName, size, leading, kerning, align); +} + +void TextHandlerBase::gotTextBlockBegin (const TQValueVector& transData, TextOperation mode) +{ + tqDebug ("text block begin %d",mode); + arraytoa (transData); + tqDebug ("/text block begin"); +} + +void TextHandlerBase::gotTextOutput (const char*text, int length) +{ + tqDebug ("text output (%s) %d",text,length); +} + +void TextHandlerBase::gotTextBlockEnd () +{ + tqDebug ("text block end"); +} + +const void elementtoa (const AIElement &/*data*/) +{ +/* AIElement::Type type = data.type(); + tqDebug ("type: %s", AIElement::typeToName (type)); + + switch (type) + { + case AIElement::String : + case AIElement::CString : + case AIElement::Int : + case AIElement::UInt : + case AIElement::Double : + tqDebug ("string value : %s",data.toString().latin1()); + break; + case AIElement::Reference : + tqDebug ("string value : %s",data.toReference().latin1()); + break; + case AIElement::Operator : + tqDebug ("string value : %s",data.toOperator().latin1()); + break; + case AIElement::ElementArray : + arraytoa (data.toElementArray()); + break; + case AIElement::Block : + arraytoa (data.toBlock()); + break; + + default : + tqDebug ("could not fetch data"); + } */ +} + +const void arraytoa (const TQValueVector &/*data*/) +{ +/* tqDebug ("array size is %d ",data.size()); + if (data.size() > 0) + { + tqDebug ("[[[[[[[[[[[[[[[[[[[["); + for (uint i=0; i< data.size(); i++) + { + elementtoa (data[i]); + } + tqDebug ("]]]]]]]]]]]]]]]]]]]]"); + } */ +} + +const void stacktoa (const TQValueStack &/*data*/) +{ +/* tqDebug ("stack size is %d",data.size()); + if (data.size() > 0) + { + tqDebug ("<<<<<<<<<<<<<<<<<<"); + for (uint i=0; i< data.size(); i++) + { + elementtoa (data[i]); + } + } + tqDebug (">>>>>>>>>>>>>>>>>>"); */ +} + +const void stacktoa2 (const TQValueStack >&/*data*/) +{ +/* tqDebug ("stack size is %d",data.size()); + + if (data.size() > 0) + { + tqDebug ("((((((((((((((((((((((("); + for (uint i=0; i< data.size(); i++) + { + arraytoa (data[i]); + } + tqDebug (")))))))))))))))))))))))"); + } */ +} + +const void aiotoa (AIOperation &data) +{ + switch (data) + { + case AIO_SetFillColorCMYK : tqDebug ("AIO_SetFillColorCMYK"); break; + case AIO_SetStrokeColorCMYK : tqDebug ("AIO_SetStrokeColorCMYK"); break; + case AIO_SetFillColorGray : tqDebug ("AIO_SetFillColorGray"); break; + case AIO_SetStrokeColorGray : tqDebug ("AIO_SetStrokeColorGray"); break; + case AIO_SetFillColorCustom : tqDebug ("AIO_SetFillColorCustom"); break; + case AIO_SetStrokeColorCustom : tqDebug ("AIO_SetStrokeColorCustom"); break; + case AIO_SetFillPattern : tqDebug ("AIO_SetFillPattern"); break; + case AIO_SetStrokePattern : tqDebug ("AIO_SetStrokePattern"); break; + case AIO_SetFillOverprinting : tqDebug ("AIO_SetFillOverprinting"); break; + case AIO_SetStrokeOverprinting : tqDebug ("AIO_SetStrokeOverprinting"); break; + case AIO_SetFlatness : tqDebug ("AIO_SetFlatness"); break; + case AIO_SetLineCap : tqDebug ("AIO_SetLineCap"); break; + case AIO_SetLineJoin : tqDebug ("AIO_SetLineJoin"); break; + case AIO_SetLineWidth : tqDebug ("AIO_SetLineWidth"); break; + case AIO_SetMiterLimit : tqDebug ("AIO_SetMiterLimit"); break; + case AIO_SetDash : tqDebug ("AIO_SetDash"); break; + case AIO_BeginGroupClip : tqDebug ("AIO_BeginGroupClip"); break; + case AIO_EndGroupClip : tqDebug ("AIO_EndGroupClip"); break; + case AIO_MoveTo : tqDebug ("AIO_MoveTo"); break; + case AIO_LineToCorner : tqDebug ("AIO_LineToCorner"); break; + case AIO_LineToSmooth : tqDebug ("AIO_LineToSmooth"); break; + case AIO_CurveToSmooth : tqDebug ("AIO_CurveToSmooth"); break; + case AIO_CurveToCorner : tqDebug ("AIO_CurveToCorner"); break; + case AIO_CurveToOmitC1Smooth : tqDebug ("AIO_CurveToOmitC1Smooth"); break; + case AIO_CurveToOmitC1Corner : tqDebug ("AIO_CurveToOmitC1Corner"); break; + case AIO_CurveToOmitC2Smooth : tqDebug ("AIO_CurveToOmitC2Smooth"); break; + case AIO_CurveToOmitC2Corner : tqDebug ("AIO_CurveToOmitC2Corner"); break; + case AIO_PathIgnoreNoReset : tqDebug ("AIO_PathIgnoreNoReset"); break; + case AIO_PathIgnoreNoResetClose : tqDebug ("AIO_PathIgnoreNoResetClose"); break; + case AIO_PathClipPath : tqDebug ("AIO_PathClipPath"); break; + case AIO_PathIgnoreReset : tqDebug ("AIO_PathIgnoreReset"); break; + case AIO_PathIgnoreResetClose : tqDebug ("AIO_PathIgnoreResetClose"); break; + case AIO_PathFillNonZero : tqDebug ("AIO_PathFillNonZero"); break; + case AIO_PathFillNonZeroClose : tqDebug ("AIO_PathFillNonZeroClose"); break; + case AIO_PathStroke : tqDebug ("AIO_PathStroke"); break; + case AIO_PathStrokeClose : tqDebug ("AIO_PathStrokeClose"); break; + case AIO_PathFillNoReset : tqDebug ("AIO_PathFillNoReset"); break; + case AIO_PathFillNoResetClose : tqDebug ("AIO_PathFillNoResetClose"); break; + case AIO_FontEncoding : tqDebug ("AIO_FontEncoding"); break; + case AIO_PatternDefinition : tqDebug ("AIO_PatternDefinition"); break; + case AIO_SetCurrentText : tqDebug ("AIO_SetCurrentText"); break; + case AIO_TextBlockFillStroke : tqDebug ("AIO_TextBlockFillStroke"); break; + case AIO_TextBlockFill : tqDebug ("AIO_TextBlockFill"); break; + case AIO_TextBlockAppend : tqDebug ("AIO_TextBlockAppend"); break; + case AIO_TextBlockIgnore : tqDebug ("AIO_TextBlockIgnore"); break; + case AIO_TextBlockStroke : tqDebug ("AIO_TextBlockStroke"); break; + case AIO_TextOutput : tqDebug ("AIO_TextOutput"); break; + case AIO_TextBlockEnd : tqDebug ("AIO_TextBlockEnd"); break; + case AIO_GsaveIncludeDocument : tqDebug ("AIO_GsaveIncludeDocument"); break; + case AIO_Grestore : tqDebug ("AIO_Grestore"); break; + case AIO_LockElement : tqDebug ("AIO_LockElement"); break; + case AIO_SetWindingOrder : tqDebug ("AIO_SetWindingOrder"); break; + default : tqDebug ("unknown"); + } +} + +const void sttoa (SectionType &data, bool begin) +{ + switch (data) + { + case ST_Setup : begin ? tqDebug ("start setup") : tqDebug ("end setup"); break; + case ST_Prolog : begin ? tqDebug ("start prolog") : tqDebug ("end prolog"); break; + case ST_ProcSet : begin ? tqDebug ("start procset") : tqDebug ("end procset"); break; + case ST_Encoding : begin ? tqDebug ("start encoding") : tqDebug ("end encoding"); break; + case ST_Pattern : begin ? tqDebug ("start pattern") : tqDebug ("end pattern"); break; + case ST_Document : begin ? tqDebug ("start document") : tqDebug ("end document"); break; + case ST_BrushPattern : begin ? tqDebug ("start brush pattern") : tqDebug ("end brush pattern"); break; + case ST_Gradient : begin ? tqDebug ("start gradient") : tqDebug ("end gradient"); break; + case ST_Palette : begin ? tqDebug ("start palette") : tqDebug ("end palette"); break; + case ST_Resource : begin ? tqDebug ("start resource") : tqDebug ("end resouce"); break; + + default : begin ? tqDebug ("unknown") : tqDebug ("end unknown"); + } +} + diff --git a/filters/karbon/ai/karbonaiparserbase.cc b/filters/karbon/ai/karbonaiparserbase.cc deleted file mode 100644 index c4321252..00000000 --- a/filters/karbon/ai/karbonaiparserbase.cc +++ /dev/null @@ -1,637 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002, Dirk Schönberger - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "karbonaiparserbase.h" - -#include -#include -#include -#include -#include -#include "aicolor.h" -#include -#include - -#include - -const void pottoa (PathOutputType &data); - -// generic -KarbonAIParserBase::KarbonAIParserBase() : m_pot(POT_Other), m_ptt (PTT_Output), m_bbox(0,0,612,792), m_emptyFill(), m_emptyStroke() -/* , m_strokeColor(), m_fillColor() */ { - - // A4, 70 dpi -/* m_bbox.llx = 0; - m_bbox.lly = 0; - m_bbox.urx = 612; - m_bbox.ury = 792; */ - -/* m_lineWidth = 0; - m_flatness = 0; - m_lineCaps = 0; - m_lineJoin = 0; - m_miterLimit = 10; */ - m_windingOrder = 0; - - m_fm = FM_NonZero; - - m_curKarbonPath = new VPath( 0L ); - - m_document = new VDocument(); - m_layer = NULL; - m_combination = NULL; - - m_emptyFill.setType (VFill::none); - m_emptyStroke.setType (VStroke::none); - - setupHandlers(); -} - -// generic -KarbonAIParserBase::~KarbonAIParserBase(){ - teardownHandlers(); - delete m_curKarbonPath; - - delete m_document; -} - -// generic -void KarbonAIParserBase::parsingStarted(){ -// tqDebug ( getHeader().latin1() ); -} - -// generic -void KarbonAIParserBase::parsingFinished(){ -// tqDebug ( getFooter().latin1() ); - - // handle bounding box - if (m_document) - { - kdDebug() << "bbox 1 is " << m_bbox << endl; - - if (m_bbox.width() > 0. ) - m_document->setWidth (m_bbox.width()); - if (m_bbox.height() > 0. ) - m_document->setHeight (m_bbox.height()); - -/* TQWMatrix matrix; - matrix.translate (-m_bbox.x(),-m_bbox.y()); - - VTransformNodes translator (matrix); - m_document->accept (translator); */ - VTranslateCmd cmd (0L, -m_bbox.x(), -m_bbox.y()); - m_document->accept (cmd); - } -} - -// generic -TQString KarbonAIParserBase::getParamList(Parameters& params){ - TQString data(""); - - Parameter *param; - - if (params.count() > 0) - { - - for ( param=params.first(); param != 0; param=params.next() ) { - data += " " + param->first + "=\"" + param->second + "\""; - } - } - - return data; -} - -// generic -void KarbonAIParserBase::gotStartTag (const char *tagName, Parameters& params){ - tqDebug ("<%s%s>", tagName, getParamList (params).latin1() ); -} - -// generic -void KarbonAIParserBase::gotEndTag (const char *tagName){ - tqDebug ("", tagName ); -} - -// generic -void KarbonAIParserBase::gotSimpleTag (const char *tagName, Parameters& params){ - tqDebug ("<%s%s/>", tagName, getParamList (params).latin1() ); -} - -// generic -void KarbonAIParserBase::gotPathElement (PathElement &element){ - switch (element.petype) - { - case PET_MoveTo : - m_curKarbonPath->moveTo (KoPoint (element.pevalue.pointdata.x,element.pevalue.pointdata.y)); - break; - case PET_LineTo : - m_curKarbonPath->lineTo (KoPoint (element.pevalue.pointdata.x,element.pevalue.pointdata.y)); - break; - case PET_CurveTo : - m_curKarbonPath->curveTo (KoPoint (element.pevalue.bezierdata.x1,element.pevalue.bezierdata.y1), - KoPoint (element.pevalue.bezierdata.x2,element.pevalue.bezierdata.y2), - KoPoint (element.pevalue.bezierdata.x3,element.pevalue.bezierdata.y3)); - break; - case PET_CurveToOmitC1 : - m_curKarbonPath->curve1To (KoPoint (element.pevalue.bezierdata.x2,element.pevalue.bezierdata.y2), - KoPoint (element.pevalue.bezierdata.x3,element.pevalue.bezierdata.y3)); - break; - case PET_CurveToOmitC2 : - m_curKarbonPath->curve2To (KoPoint (element.pevalue.bezierdata.x1,element.pevalue.bezierdata.y1), - KoPoint (element.pevalue.bezierdata.x3,element.pevalue.bezierdata.y3)); - break; - } -} - -// generic -void KarbonAIParserBase::gotFillPath (bool closed, bool reset, FillMode /*fm*/){ -// tqDebug ("found fill path"); -// if (!reset) tqDebug ("retain filled path"); - - if (closed) m_curKarbonPath->close(); - - if (!reset) - m_pot = POT_Filled; - else - { - doOutputCurrentPath2 (POT_Filled); - m_pot = POT_Other; - } -} - -// generic -void KarbonAIParserBase::gotIgnorePath (bool closed, bool reset){ -// tqDebug ("found ignore path"); - - if (closed) m_curKarbonPath->close(); - - if (! reset) - m_pot = POT_Other; - else - { - doOutputCurrentPath2 (POT_Ignore); - m_pot = POT_Other; - } -} - -// generic -void KarbonAIParserBase::gotStrokePath (bool closed) { -// tqDebug ("found stroke path"); - - if (closed) m_curKarbonPath->close(); - - PathOutputType pot = POT_Stroked; - if (m_pot != POT_Other) - { - pot = POT_FilledStroked; - } - - doOutputCurrentPath2 (pot); - - m_pot = POT_Other; -} - -// generic -void KarbonAIParserBase::gotClipPath (bool /*closed*/){ - - doOutputCurrentPath2 (POT_Clip); -} - -// generic -void KarbonAIParserBase::gotFillColor (AIColor &color){ -// double r, g, b; -// color.toRGB (r,g,b); -// tqDebug ("set fillcolor to %f %f %f",r,g,b); -// m_fillColor = color; - - VColor karbonColor = toKarbonColor (color); - m_fill.setColor (karbonColor); -} - -// generic -void KarbonAIParserBase::gotStrokeColor (AIColor &color){ -// double r, g, b; -// color.toRGB (r,g,b); -// tqDebug ("set strokecolor to %f %f %f",r,g,b); -// m_strokeColor = color; - - VColor karbonColor = toKarbonColor (color); - m_stroke.setColor (karbonColor); -} - -// generic -void KarbonAIParserBase::gotBoundingBox (int llx, int lly, int urx, int ury){ -/* m_bbox.llx = llx; - m_bbox.lly = lly; - m_bbox.urx = urx; - m_bbox.ury = ury; */ - m_bbox.setCoords(llx,lly,urx,ury); -} - -void KarbonAIParserBase::gotLineWidth (double val){ -// m_lineWidth = val; - m_stroke.setLineWidth (val); -} - -void KarbonAIParserBase::gotFlatness (double /*val*/) -{ -// m_flatness = val; -// m_stroke.setFlatness (val); -} - -void KarbonAIParserBase::gotLineCaps (int val) -{ -// m_lineCaps = val; - VStroke::VLineCap lineCap = VStroke::capButt; - - switch (val) - { - case 0 : lineCap = VStroke::capButt; break; - case 1 : lineCap = VStroke::capRound; break; - case 2 : lineCap = VStroke::capSquare; break; - } - - m_stroke.setLineCap (lineCap); -} - -void KarbonAIParserBase::gotLineJoin (int val) -{ -// m_lineJoin = val; - - VStroke::VLineJoin lineJoin = VStroke::joinMiter; - - switch (val) - { - case 0 : lineJoin = VStroke::joinMiter; break; - case 1 : lineJoin = VStroke::joinRound; break; - case 2 : lineJoin = VStroke::joinBevel; break; - } - - m_stroke.setLineJoin (lineJoin); - -} - -void KarbonAIParserBase::gotMiterLimit (double val) -{ -// m_miterLimit = val; - m_stroke.setMiterLimit (val); -} - -void KarbonAIParserBase::gotWindingOrder (int val) -{ - m_windingOrder = val; -} - -void KarbonAIParserBase::gotBeginGroup (bool clipping) -{ -// tqDebug ("start begin group"); - if (clipping) - { - VClipGroup *group = new VClipGroup( 0L ); - m_groupStack.push (group); - } - else - { - VGroup *group = new VGroup( 0L ); - m_groupStack.push (group); - } - -// tqDebug ("end begin group"); - -} - -void KarbonAIParserBase::gotEndGroup (bool /*clipping*/) -{ -// tqDebug ("start end group"); - - if (m_debug) tqDebug ("got end group"); - - if (m_groupStack.isEmpty()) return; - - if (m_debug) tqDebug ("got end group 2"); - - VGroup *group = m_groupStack.pop(); - - if (m_debug) tqDebug ("got end group 3"); - - if (m_debug) - { - if (!group) tqDebug ("group is NULL"); - } - - if (m_groupStack.isEmpty()) - { - if (m_debug) tqDebug ("insert object"); - ensureLayer(); - m_layer->append (group); - if (m_debug) tqDebug ("/insert object"); - } - else - { - if (m_debug) tqDebug ("insert object to group"); - - m_groupStack.top()->append (group); - if (m_debug) tqDebug ("/insert object to group"); - } - - if (m_debug) tqDebug ("/got end group"); - -// tqDebug ("end end group"); -} - -void KarbonAIParserBase::gotBeginCombination () { - m_ptt = PTT_Combine; -} - -void KarbonAIParserBase::gotEndCombination () { -// tqDebug ( "got end combination" ); - - m_ptt = PTT_Output; - - if (m_combination != NULL) - { - m_curKarbonPath = m_combination; - doOutputCurrentPath2 (POT_Leave); - } - - m_combination = NULL; -} - - -const VColor KarbonAIParserBase::toKarbonColor (const AIColor &color) -{ - AIColor temp (color); - VColor value; - - double v1, v2, v3, v4; - temp.toCMYK (v1, v2, v3, v4); - - float cv1 = v1; - float cv2 = v2; - float cv3 = v3; - float cv4 = v4; - - value.setColorSpace (VColor::cmyk); - value.set (cv1, cv2, cv3, cv4); - - return value; -} - -void KarbonAIParserBase::doOutputCurrentPath2(PathOutputType type) -{ - ensureLayer(); - - if (type != POT_Leave) - { -// pottoa(type); - - m_curKarbonPath->setStroke(m_emptyStroke); - m_curKarbonPath->setFill(m_emptyFill); - - if ((type != POT_Filled) && (type != POT_Stroked) && (type != POT_FilledStroked)) return; - if ((type == POT_Filled) || (type == POT_FilledStroked)) - { -/* VFill fill; - fill.setColor (toKarbonColor (m_fillColor)); - m_curKarbonPath->setFill(fill); */ -// tqDebug ("set filled"); - m_curKarbonPath->setFill(m_fill); - } - - if ((type == POT_Stroked) || (type == POT_FilledStroked)) - { -/* VStroke stroke; - stroke.setColor (toKarbonColor (m_strokeColor)); - m_curKarbonPath->setStroke (stroke); */ -// tqDebug ("set stroked"); - m_curKarbonPath->setStroke (m_stroke); - } - } - - if (m_ptt == PTT_Combine) - { -// m_pot |= type; - if (m_combination == NULL) - m_combination = m_curKarbonPath; - else - m_combination->combine (*m_curKarbonPath); - - m_curKarbonPath = new VPath( 0L ); - - return; - } - - ensureLayer(); - - if (m_groupStack.isEmpty()) - { - m_layer->append( m_curKarbonPath ); - } - else - { - m_groupStack.top()->append( m_curKarbonPath ); - } - - m_curKarbonPath = new VPath( 0L ); -} - -bool KarbonAIParserBase::parse (TQIODevice& fin, TQDomDocument &doc) -{ - - bool res = AIParserBase::parse (fin); - -// tqDebug ("document is %s",doc.toString().latin1()); - if (res) - { - tqDebug ("before save document"); - doc = m_document->saveXML(); - // add paper info, we always need custom for svg (Rob) - TQDomElement paper = doc.createElement( "PAPER" ); - doc.documentElement().appendChild( paper ); - paper.setAttribute( "format", PG_CUSTOM ); - paper.setAttribute( "width", m_document->width() ); - paper.setAttribute( "height", m_document->height() ); - - tqDebug ("after save document"); - } - else - { - TQDomDocument tempDoc; - doc = tempDoc; - } - - return res; -} - -void KarbonAIParserBase::ensureLayer () -{ - if (!m_layer) - { - m_layer = new VLayer( 0 ); - m_document->insertLayer (m_layer); - } -} - - -void KarbonAIParserBase::setupHandlers() -{ -// tqDebug("setupHandler called"); - m_gstateHandler = new KarbonGStateHandler(this); - m_structureHandler = new KarbonStructureHandler(this); - m_pathHandler = new KarbonPathHandler(this); - m_documentHandler = new KarbonDocumentHandler(this); - - m_textHandler = new TextHandlerBase(); - -} - -void KarbonAIParserBase::teardownHandlers() -{ -// tqDebug("teardownHandler called"); - delete m_textHandler; - - delete m_gstateHandler; - delete m_structureHandler; - delete m_pathHandler; - delete m_documentHandler; -} - - -void KarbonDocumentHandler::gotBoundingBox (int llx, int lly, int urx, int ury) -{ - delegate->gotBoundingBox(llx,lly,urx,ury); -} - -void KarbonDocumentHandler::gotCreationDate (const char */*val1*/,const char */*val2*/) -{ -// tqDebug ("got creation date [%s], [%s]",val1,val2); -} - -void KarbonDocumentHandler::gotProcessColors (int /*colors*/) -{ -/* if (colors && PC_Cyan) tqDebug ("contains cyan"); - if (colors && PC_Magenta) tqDebug ("contains magenta"); - if (colors && PC_Yellow) tqDebug ("contains yellow"); - if (colors && PC_Black) tqDebug ("contains black"); */ -} - - -void KarbonGStateHandler::gotFillColor (AIColor &color) -{ - delegate->gotFillColor (color); -} - -void KarbonGStateHandler::gotStrokeColor (AIColor &color) -{ - delegate->gotStrokeColor(color); -} - -void KarbonGStateHandler::gotFlatness (double val) -{ - delegate->gotFlatness(val); -} - -void KarbonGStateHandler::gotLineWidth (double val) -{ - delegate->gotLineWidth(val); -} - -void KarbonGStateHandler::gotLineCaps (int val) -{ - delegate->gotLineCaps(val); -} - -void KarbonGStateHandler::gotLineJoin (int val) -{ - delegate->gotLineJoin(val); -} - -void KarbonGStateHandler::gotMiterLimit (double val) -{ - delegate->gotMiterLimit(val); -} - -void KarbonGStateHandler::gotWindingOrder (int val) -{ - delegate->gotWindingOrder(val); -} - -void KarbonStructureHandler::gotBeginGroup (bool clipping) -{ - delegate->gotBeginGroup(clipping); -} - -void KarbonStructureHandler::gotEndGroup (bool clipping) -{ - delegate->gotEndGroup(clipping); -} - -void KarbonStructureHandler::gotBeginCombination () -{ - delegate->gotBeginCombination(); -} - -void KarbonStructureHandler::gotEndCombination () -{ - delegate->gotEndCombination(); -} - -void KarbonPathHandler::gotPathElement (PathElement &element) -{ - delegate->gotPathElement (element); -} - -void KarbonPathHandler::gotFillPath (bool closed, bool reset) -{ - delegate->gotFillPath(closed, reset, m_fm); -} - -void KarbonPathHandler::gotFillMode (FillMode fm) -{ - m_fm = fm; -} - -void KarbonPathHandler::gotStrokePath (bool closed) -{ - delegate->gotStrokePath(closed); -} - -void KarbonPathHandler::gotIgnorePath (bool closed, bool reset) -{ - delegate->gotIgnorePath(closed, reset); -} - -void KarbonPathHandler::gotClipPath (bool closed) -{ - delegate->gotClipPath(closed); -} - -const void pottoa (PathOutputType &data) -{ - switch (data) - { - case POT_Filled : tqDebug ("filled"); break; - case POT_Stroked : tqDebug ("stroked"); break; - case POT_FilledStroked : tqDebug ("filled/stroked"); break; - case POT_Clip : tqDebug ("clip"); break; - case POT_Ignore : tqDebug ("ignore"); break; - case POT_Leave : tqDebug ("leave"); break; - default : tqDebug ("unknown"); - } -} - diff --git a/filters/karbon/ai/karbonaiparserbase.cpp b/filters/karbon/ai/karbonaiparserbase.cpp new file mode 100644 index 00000000..c4321252 --- /dev/null +++ b/filters/karbon/ai/karbonaiparserbase.cpp @@ -0,0 +1,637 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schönberger + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "karbonaiparserbase.h" + +#include +#include +#include +#include +#include +#include "aicolor.h" +#include +#include + +#include + +const void pottoa (PathOutputType &data); + +// generic +KarbonAIParserBase::KarbonAIParserBase() : m_pot(POT_Other), m_ptt (PTT_Output), m_bbox(0,0,612,792), m_emptyFill(), m_emptyStroke() +/* , m_strokeColor(), m_fillColor() */ { + + // A4, 70 dpi +/* m_bbox.llx = 0; + m_bbox.lly = 0; + m_bbox.urx = 612; + m_bbox.ury = 792; */ + +/* m_lineWidth = 0; + m_flatness = 0; + m_lineCaps = 0; + m_lineJoin = 0; + m_miterLimit = 10; */ + m_windingOrder = 0; + + m_fm = FM_NonZero; + + m_curKarbonPath = new VPath( 0L ); + + m_document = new VDocument(); + m_layer = NULL; + m_combination = NULL; + + m_emptyFill.setType (VFill::none); + m_emptyStroke.setType (VStroke::none); + + setupHandlers(); +} + +// generic +KarbonAIParserBase::~KarbonAIParserBase(){ + teardownHandlers(); + delete m_curKarbonPath; + + delete m_document; +} + +// generic +void KarbonAIParserBase::parsingStarted(){ +// tqDebug ( getHeader().latin1() ); +} + +// generic +void KarbonAIParserBase::parsingFinished(){ +// tqDebug ( getFooter().latin1() ); + + // handle bounding box + if (m_document) + { + kdDebug() << "bbox 1 is " << m_bbox << endl; + + if (m_bbox.width() > 0. ) + m_document->setWidth (m_bbox.width()); + if (m_bbox.height() > 0. ) + m_document->setHeight (m_bbox.height()); + +/* TQWMatrix matrix; + matrix.translate (-m_bbox.x(),-m_bbox.y()); + + VTransformNodes translator (matrix); + m_document->accept (translator); */ + VTranslateCmd cmd (0L, -m_bbox.x(), -m_bbox.y()); + m_document->accept (cmd); + } +} + +// generic +TQString KarbonAIParserBase::getParamList(Parameters& params){ + TQString data(""); + + Parameter *param; + + if (params.count() > 0) + { + + for ( param=params.first(); param != 0; param=params.next() ) { + data += " " + param->first + "=\"" + param->second + "\""; + } + } + + return data; +} + +// generic +void KarbonAIParserBase::gotStartTag (const char *tagName, Parameters& params){ + tqDebug ("<%s%s>", tagName, getParamList (params).latin1() ); +} + +// generic +void KarbonAIParserBase::gotEndTag (const char *tagName){ + tqDebug ("", tagName ); +} + +// generic +void KarbonAIParserBase::gotSimpleTag (const char *tagName, Parameters& params){ + tqDebug ("<%s%s/>", tagName, getParamList (params).latin1() ); +} + +// generic +void KarbonAIParserBase::gotPathElement (PathElement &element){ + switch (element.petype) + { + case PET_MoveTo : + m_curKarbonPath->moveTo (KoPoint (element.pevalue.pointdata.x,element.pevalue.pointdata.y)); + break; + case PET_LineTo : + m_curKarbonPath->lineTo (KoPoint (element.pevalue.pointdata.x,element.pevalue.pointdata.y)); + break; + case PET_CurveTo : + m_curKarbonPath->curveTo (KoPoint (element.pevalue.bezierdata.x1,element.pevalue.bezierdata.y1), + KoPoint (element.pevalue.bezierdata.x2,element.pevalue.bezierdata.y2), + KoPoint (element.pevalue.bezierdata.x3,element.pevalue.bezierdata.y3)); + break; + case PET_CurveToOmitC1 : + m_curKarbonPath->curve1To (KoPoint (element.pevalue.bezierdata.x2,element.pevalue.bezierdata.y2), + KoPoint (element.pevalue.bezierdata.x3,element.pevalue.bezierdata.y3)); + break; + case PET_CurveToOmitC2 : + m_curKarbonPath->curve2To (KoPoint (element.pevalue.bezierdata.x1,element.pevalue.bezierdata.y1), + KoPoint (element.pevalue.bezierdata.x3,element.pevalue.bezierdata.y3)); + break; + } +} + +// generic +void KarbonAIParserBase::gotFillPath (bool closed, bool reset, FillMode /*fm*/){ +// tqDebug ("found fill path"); +// if (!reset) tqDebug ("retain filled path"); + + if (closed) m_curKarbonPath->close(); + + if (!reset) + m_pot = POT_Filled; + else + { + doOutputCurrentPath2 (POT_Filled); + m_pot = POT_Other; + } +} + +// generic +void KarbonAIParserBase::gotIgnorePath (bool closed, bool reset){ +// tqDebug ("found ignore path"); + + if (closed) m_curKarbonPath->close(); + + if (! reset) + m_pot = POT_Other; + else + { + doOutputCurrentPath2 (POT_Ignore); + m_pot = POT_Other; + } +} + +// generic +void KarbonAIParserBase::gotStrokePath (bool closed) { +// tqDebug ("found stroke path"); + + if (closed) m_curKarbonPath->close(); + + PathOutputType pot = POT_Stroked; + if (m_pot != POT_Other) + { + pot = POT_FilledStroked; + } + + doOutputCurrentPath2 (pot); + + m_pot = POT_Other; +} + +// generic +void KarbonAIParserBase::gotClipPath (bool /*closed*/){ + + doOutputCurrentPath2 (POT_Clip); +} + +// generic +void KarbonAIParserBase::gotFillColor (AIColor &color){ +// double r, g, b; +// color.toRGB (r,g,b); +// tqDebug ("set fillcolor to %f %f %f",r,g,b); +// m_fillColor = color; + + VColor karbonColor = toKarbonColor (color); + m_fill.setColor (karbonColor); +} + +// generic +void KarbonAIParserBase::gotStrokeColor (AIColor &color){ +// double r, g, b; +// color.toRGB (r,g,b); +// tqDebug ("set strokecolor to %f %f %f",r,g,b); +// m_strokeColor = color; + + VColor karbonColor = toKarbonColor (color); + m_stroke.setColor (karbonColor); +} + +// generic +void KarbonAIParserBase::gotBoundingBox (int llx, int lly, int urx, int ury){ +/* m_bbox.llx = llx; + m_bbox.lly = lly; + m_bbox.urx = urx; + m_bbox.ury = ury; */ + m_bbox.setCoords(llx,lly,urx,ury); +} + +void KarbonAIParserBase::gotLineWidth (double val){ +// m_lineWidth = val; + m_stroke.setLineWidth (val); +} + +void KarbonAIParserBase::gotFlatness (double /*val*/) +{ +// m_flatness = val; +// m_stroke.setFlatness (val); +} + +void KarbonAIParserBase::gotLineCaps (int val) +{ +// m_lineCaps = val; + VStroke::VLineCap lineCap = VStroke::capButt; + + switch (val) + { + case 0 : lineCap = VStroke::capButt; break; + case 1 : lineCap = VStroke::capRound; break; + case 2 : lineCap = VStroke::capSquare; break; + } + + m_stroke.setLineCap (lineCap); +} + +void KarbonAIParserBase::gotLineJoin (int val) +{ +// m_lineJoin = val; + + VStroke::VLineJoin lineJoin = VStroke::joinMiter; + + switch (val) + { + case 0 : lineJoin = VStroke::joinMiter; break; + case 1 : lineJoin = VStroke::joinRound; break; + case 2 : lineJoin = VStroke::joinBevel; break; + } + + m_stroke.setLineJoin (lineJoin); + +} + +void KarbonAIParserBase::gotMiterLimit (double val) +{ +// m_miterLimit = val; + m_stroke.setMiterLimit (val); +} + +void KarbonAIParserBase::gotWindingOrder (int val) +{ + m_windingOrder = val; +} + +void KarbonAIParserBase::gotBeginGroup (bool clipping) +{ +// tqDebug ("start begin group"); + if (clipping) + { + VClipGroup *group = new VClipGroup( 0L ); + m_groupStack.push (group); + } + else + { + VGroup *group = new VGroup( 0L ); + m_groupStack.push (group); + } + +// tqDebug ("end begin group"); + +} + +void KarbonAIParserBase::gotEndGroup (bool /*clipping*/) +{ +// tqDebug ("start end group"); + + if (m_debug) tqDebug ("got end group"); + + if (m_groupStack.isEmpty()) return; + + if (m_debug) tqDebug ("got end group 2"); + + VGroup *group = m_groupStack.pop(); + + if (m_debug) tqDebug ("got end group 3"); + + if (m_debug) + { + if (!group) tqDebug ("group is NULL"); + } + + if (m_groupStack.isEmpty()) + { + if (m_debug) tqDebug ("insert object"); + ensureLayer(); + m_layer->append (group); + if (m_debug) tqDebug ("/insert object"); + } + else + { + if (m_debug) tqDebug ("insert object to group"); + + m_groupStack.top()->append (group); + if (m_debug) tqDebug ("/insert object to group"); + } + + if (m_debug) tqDebug ("/got end group"); + +// tqDebug ("end end group"); +} + +void KarbonAIParserBase::gotBeginCombination () { + m_ptt = PTT_Combine; +} + +void KarbonAIParserBase::gotEndCombination () { +// tqDebug ( "got end combination" ); + + m_ptt = PTT_Output; + + if (m_combination != NULL) + { + m_curKarbonPath = m_combination; + doOutputCurrentPath2 (POT_Leave); + } + + m_combination = NULL; +} + + +const VColor KarbonAIParserBase::toKarbonColor (const AIColor &color) +{ + AIColor temp (color); + VColor value; + + double v1, v2, v3, v4; + temp.toCMYK (v1, v2, v3, v4); + + float cv1 = v1; + float cv2 = v2; + float cv3 = v3; + float cv4 = v4; + + value.setColorSpace (VColor::cmyk); + value.set (cv1, cv2, cv3, cv4); + + return value; +} + +void KarbonAIParserBase::doOutputCurrentPath2(PathOutputType type) +{ + ensureLayer(); + + if (type != POT_Leave) + { +// pottoa(type); + + m_curKarbonPath->setStroke(m_emptyStroke); + m_curKarbonPath->setFill(m_emptyFill); + + if ((type != POT_Filled) && (type != POT_Stroked) && (type != POT_FilledStroked)) return; + if ((type == POT_Filled) || (type == POT_FilledStroked)) + { +/* VFill fill; + fill.setColor (toKarbonColor (m_fillColor)); + m_curKarbonPath->setFill(fill); */ +// tqDebug ("set filled"); + m_curKarbonPath->setFill(m_fill); + } + + if ((type == POT_Stroked) || (type == POT_FilledStroked)) + { +/* VStroke stroke; + stroke.setColor (toKarbonColor (m_strokeColor)); + m_curKarbonPath->setStroke (stroke); */ +// tqDebug ("set stroked"); + m_curKarbonPath->setStroke (m_stroke); + } + } + + if (m_ptt == PTT_Combine) + { +// m_pot |= type; + if (m_combination == NULL) + m_combination = m_curKarbonPath; + else + m_combination->combine (*m_curKarbonPath); + + m_curKarbonPath = new VPath( 0L ); + + return; + } + + ensureLayer(); + + if (m_groupStack.isEmpty()) + { + m_layer->append( m_curKarbonPath ); + } + else + { + m_groupStack.top()->append( m_curKarbonPath ); + } + + m_curKarbonPath = new VPath( 0L ); +} + +bool KarbonAIParserBase::parse (TQIODevice& fin, TQDomDocument &doc) +{ + + bool res = AIParserBase::parse (fin); + +// tqDebug ("document is %s",doc.toString().latin1()); + if (res) + { + tqDebug ("before save document"); + doc = m_document->saveXML(); + // add paper info, we always need custom for svg (Rob) + TQDomElement paper = doc.createElement( "PAPER" ); + doc.documentElement().appendChild( paper ); + paper.setAttribute( "format", PG_CUSTOM ); + paper.setAttribute( "width", m_document->width() ); + paper.setAttribute( "height", m_document->height() ); + + tqDebug ("after save document"); + } + else + { + TQDomDocument tempDoc; + doc = tempDoc; + } + + return res; +} + +void KarbonAIParserBase::ensureLayer () +{ + if (!m_layer) + { + m_layer = new VLayer( 0 ); + m_document->insertLayer (m_layer); + } +} + + +void KarbonAIParserBase::setupHandlers() +{ +// tqDebug("setupHandler called"); + m_gstateHandler = new KarbonGStateHandler(this); + m_structureHandler = new KarbonStructureHandler(this); + m_pathHandler = new KarbonPathHandler(this); + m_documentHandler = new KarbonDocumentHandler(this); + + m_textHandler = new TextHandlerBase(); + +} + +void KarbonAIParserBase::teardownHandlers() +{ +// tqDebug("teardownHandler called"); + delete m_textHandler; + + delete m_gstateHandler; + delete m_structureHandler; + delete m_pathHandler; + delete m_documentHandler; +} + + +void KarbonDocumentHandler::gotBoundingBox (int llx, int lly, int urx, int ury) +{ + delegate->gotBoundingBox(llx,lly,urx,ury); +} + +void KarbonDocumentHandler::gotCreationDate (const char */*val1*/,const char */*val2*/) +{ +// tqDebug ("got creation date [%s], [%s]",val1,val2); +} + +void KarbonDocumentHandler::gotProcessColors (int /*colors*/) +{ +/* if (colors && PC_Cyan) tqDebug ("contains cyan"); + if (colors && PC_Magenta) tqDebug ("contains magenta"); + if (colors && PC_Yellow) tqDebug ("contains yellow"); + if (colors && PC_Black) tqDebug ("contains black"); */ +} + + +void KarbonGStateHandler::gotFillColor (AIColor &color) +{ + delegate->gotFillColor (color); +} + +void KarbonGStateHandler::gotStrokeColor (AIColor &color) +{ + delegate->gotStrokeColor(color); +} + +void KarbonGStateHandler::gotFlatness (double val) +{ + delegate->gotFlatness(val); +} + +void KarbonGStateHandler::gotLineWidth (double val) +{ + delegate->gotLineWidth(val); +} + +void KarbonGStateHandler::gotLineCaps (int val) +{ + delegate->gotLineCaps(val); +} + +void KarbonGStateHandler::gotLineJoin (int val) +{ + delegate->gotLineJoin(val); +} + +void KarbonGStateHandler::gotMiterLimit (double val) +{ + delegate->gotMiterLimit(val); +} + +void KarbonGStateHandler::gotWindingOrder (int val) +{ + delegate->gotWindingOrder(val); +} + +void KarbonStructureHandler::gotBeginGroup (bool clipping) +{ + delegate->gotBeginGroup(clipping); +} + +void KarbonStructureHandler::gotEndGroup (bool clipping) +{ + delegate->gotEndGroup(clipping); +} + +void KarbonStructureHandler::gotBeginCombination () +{ + delegate->gotBeginCombination(); +} + +void KarbonStructureHandler::gotEndCombination () +{ + delegate->gotEndCombination(); +} + +void KarbonPathHandler::gotPathElement (PathElement &element) +{ + delegate->gotPathElement (element); +} + +void KarbonPathHandler::gotFillPath (bool closed, bool reset) +{ + delegate->gotFillPath(closed, reset, m_fm); +} + +void KarbonPathHandler::gotFillMode (FillMode fm) +{ + m_fm = fm; +} + +void KarbonPathHandler::gotStrokePath (bool closed) +{ + delegate->gotStrokePath(closed); +} + +void KarbonPathHandler::gotIgnorePath (bool closed, bool reset) +{ + delegate->gotIgnorePath(closed, reset); +} + +void KarbonPathHandler::gotClipPath (bool closed) +{ + delegate->gotClipPath(closed); +} + +const void pottoa (PathOutputType &data) +{ + switch (data) + { + case POT_Filled : tqDebug ("filled"); break; + case POT_Stroked : tqDebug ("stroked"); break; + case POT_FilledStroked : tqDebug ("filled/stroked"); break; + case POT_Clip : tqDebug ("clip"); break; + case POT_Ignore : tqDebug ("ignore"); break; + case POT_Leave : tqDebug ("leave"); break; + default : tqDebug ("unknown"); + } +} + -- cgit v1.2.1