diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /filters/karbon/ai | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'filters/karbon/ai')
-rw-r--r-- | filters/karbon/ai/Makefile.am | 44 | ||||
-rw-r--r-- | filters/karbon/ai/ai3handler.cc | 74 | ||||
-rw-r--r-- | filters/karbon/ai/ai3handler.h | 39 | ||||
-rw-r--r-- | filters/karbon/ai/ai88handler.cc | 564 | ||||
-rw-r--r-- | filters/karbon/ai/ai88handler.h | 56 | ||||
-rw-r--r-- | filters/karbon/ai/aicolor.cc | 100 | ||||
-rw-r--r-- | filters/karbon/ai/aicolor.h | 57 | ||||
-rw-r--r-- | filters/karbon/ai/aielement.cc | 804 | ||||
-rw-r--r-- | filters/karbon/ai/aielement.h | 151 | ||||
-rw-r--r-- | filters/karbon/ai/aiimport.cc | 101 | ||||
-rw-r--r-- | filters/karbon/ai/aiimport.h | 47 | ||||
-rw-r--r-- | filters/karbon/ai/ailexer.cc | 514 | ||||
-rw-r--r-- | filters/karbon/ai/ailexer.h | 123 | ||||
-rw-r--r-- | filters/karbon/ai/aiparserbase.cc | 1337 | ||||
-rw-r--r-- | filters/karbon/ai/aiparserbase.h | 440 | ||||
-rw-r--r-- | filters/karbon/ai/karbon_ai_import.desktop | 67 | ||||
-rw-r--r-- | filters/karbon/ai/karbonaiparserbase.cc | 637 | ||||
-rw-r--r-- | filters/karbon/ai/karbonaiparserbase.h | 202 |
18 files changed, 5357 insertions, 0 deletions
diff --git a/filters/karbon/ai/Makefile.am b/filters/karbon/ai/Makefile.am new file mode 100644 index 00000000..761feaff --- /dev/null +++ b/filters/karbon/ai/Makefile.am @@ -0,0 +1,44 @@ +kde_module_LTLIBRARIES = libkarbonaiimport.la + +libkarbonaiimport_la_LIBADD = \ + $(LIB_KOFFICEUI) \ + ../../../karbon/libkarboncommon.la + +libkarbonaiimport_la_LDFLAGS = \ + $(all_libraries) \ + $(KDE_RPATH) \ + -module -avoid-version -no-undefined + +INCLUDES = \ + $(KOFFICE_INCLUDES) \ + $(KOPAINTER_INCLUDES) \ + -I$(top_srcdir)/karbon \ + -I$(top_srcdir)/karbon/core \ + $(all_includes) + +service_DATA = karbon_ai_import.desktop +servicedir = $(kde_servicesdir) + +noinst_HEADERS = \ + aicolor.h \ + aielement.h \ + aiimport.h \ + ailexer.h \ + aiparserbase.h \ + ai88handler.h \ + ai3handler.h \ + karbonaiparserbase.h + +libkarbonaiimport_la_SOURCES = \ + aicolor.cc \ + aielement.cc \ + aiimport.cc \ + ailexer.cc \ + aiparserbase.cc \ + ai88handler.cc \ + ai3handler.cc \ + karbonaiparserbase.cc + +libkarbonaiimport_la_METASOURCES = \ + AUTO + diff --git a/filters/karbon/ai/ai3handler.cc b/filters/karbon/ai/ai3handler.cc new file mode 100644 index 00000000..ae0252a3 --- /dev/null +++ b/filters/karbon/ai/ai3handler.cc @@ -0,0 +1,74 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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) qDebug ("got end group noclip"); + if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotEndGroup (false); + if (m_delegate->m_debug) qDebug ("/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.h b/filters/karbon/ai/ai3handler.h new file mode 100644 index 00000000..27f23cec --- /dev/null +++ b/filters/karbon/ai/ai3handler.h @@ -0,0 +1,39 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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. +*/ + +#ifndef AI3HANDLER_H +#define AI3HANDLER_H + +#include "aiparserbase.h" + +/** + *@author Dirk Schoenberger + */ + +class AI3Handler { +private: + AIParserBase *m_delegate; +public: + AI3Handler(AIParserBase *delegate); + ~AI3Handler(); + + bool handleAIOperation (AIOperation op); +}; + +#endif diff --git a/filters/karbon/ai/ai88handler.cc b/filters/karbon/ai/ai88handler.cc new file mode 100644 index 00000000..f3cf53a7 --- /dev/null +++ b/filters/karbon/ai/ai88handler.cc @@ -0,0 +1,564 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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 <kglobal.h> +#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) qDebug ("got end group clip"); + if (m_delegate->m_structureHandler) m_delegate->m_structureHandler->gotEndGroup (true); + if (m_delegate->m_debug) qDebug ("/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) qDebug ("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 QValueVector<AIElement> 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 QString &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 QValueVector<AIElement> 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 QString &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) qDebug ("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) qDebug ("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) qDebug ("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 QString 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) qDebug ("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() +{ +// qDebug ("found dash operation"); + double fval = m_delegate->getDoubleValue(); + + AIElement elem (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const QValueVector<AIElement> aval = elem.toElementArray(); + if (m_delegate->m_gstateHandler) m_delegate->m_gstateHandler->gotDash (aval, fval); +// qDebug ("dash operation finished"); +} + +void AI88Handler::_handlePatternDefinition() +{ + AIElement elem (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + + const QValueVector<AIElement> 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 QString &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 QString &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 QValueVector<AIElement> 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 QString &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()); + qDebug ("to element is (%s)",elem.typeName()); + m_delegate->m_stack.pop(); + + const QValueVector<AIElement> 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 QString &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 QString &oldFont = elem.toReference(); + + AIElement elem2 (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + const QString &newFont = elem2.toReference(); + + AIElement elem3 (m_delegate->m_stack.top()); + m_delegate->m_stack.pop(); + const QValueVector<AIElement> 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 QString 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) qDebug ("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.h b/filters/karbon/ai/ai88handler.h new file mode 100644 index 00000000..be031113 --- /dev/null +++ b/filters/karbon/ai/ai88handler.h @@ -0,0 +1,56 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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. +*/ + +#ifndef AI88HANDLER_H +#define AI88HANDLER_H + +#include "aiparserbase.h" + +/** + *@author Dirk Schoenberger + */ + +class AI88Handler { +private: + AIParserBase *m_delegate; + + void _handleSetDash(); + void _handleSetStrokeColorCMYK(); + void _handleSetFillColorCMYK(); + void _handleSetStrokeColorGray(); + void _handleSetFillColorGray(); + void _handleSetStrokeColorCustom(); + void _handleSetFillColorCustom(); + void _handleSetFillPattern(); + void _handleSetStrokePattern(); + void _handlePatternDefinition(); + void _handleGsaveIncludeDocument(); + void _handleSetCurrentText(); + void _handleTextBlock (TextOperation to); + void _handleTextOutput (); + void _handleFontEncoding(); + +public: + AI88Handler(AIParserBase *delegate); + ~AI88Handler(); + + bool handleAIOperation (AIOperation op); +}; + +#endif diff --git a/filters/karbon/ai/aicolor.cc b/filters/karbon/ai/aicolor.cc new file mode 100644 index 00000000..67384167 --- /dev/null +++ b/filters/karbon/ai/aicolor.cc @@ -0,0 +1,100 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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 <stdlib.h> + +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 : + qDebug ("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 : + qDebug ("unknown colortype %d", ctype); + } +} + + diff --git a/filters/karbon/ai/aicolor.h b/filters/karbon/ai/aicolor.h new file mode 100644 index 00000000..b8cc1414 --- /dev/null +++ b/filters/karbon/ai/aicolor.h @@ -0,0 +1,57 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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. +*/ + +#ifndef AICOLOR_H +#define AICOLOR_H + +#include <qstring.h> + +/** + *@author + */ + +class AIColor { + public: + typedef enum { CT_CMYK, CT_CMYK_Key, CT_Gray } ColorType; + + private: + ColorType ctype; + + union { + struct { + double cvalue, mvalue, yvalue, kvalue; + char *colorname; + double graydata; + } cmykdata; + double graydata; + } cdata; +public: + AIColor(); + ~AIColor(); + AIColor( const AIColor& ); + AIColor( double c, double m, double y, double k ); + AIColor( double c, double m, double y, double k, const char *colorname, double gray ); + AIColor( double gray ); + + void toRGB (double &r, double &g, double &b); + void toCMYK (double &c, double &m, double &y, double &k); + +}; + +#endif diff --git a/filters/karbon/ai/aielement.cc b/filters/karbon/ai/aielement.cc new file mode 100644 index 00000000..13887b50 --- /dev/null +++ b/filters/karbon/ai/aielement.cc @@ -0,0 +1,804 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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 <qglobal.h> + +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 QString( *((QString*)d->value.ptr) ); + break; + case AIElement::CString: + // QCString is explicit shared + value.ptr = new QCString( *((QCString*)d->value.ptr) ); + break; +/* case AIElement::List: + value.ptr = new QValueList<AIElement>( *((QValueList<AIElement>*)d->value.ptr) ); + break; */ + case AIElement::ElementArray: + value.ptr = new QValueVector<AIElement>( *((QValueVector<AIElement>*)d->value.ptr) ); + break; + case AIElement::Block: + value.ptr = new QValueVector<AIElement>( *((QValueVector<AIElement>*)d->value.ptr) ); + break; + case AIElement::ByteArray: + value.ptr = new QByteArray( *((QByteArray*)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 (QString*)value.ptr; + break; + case AIElement::CString: + delete (QCString*)value.ptr; + break; +/* case AIElement::List: + delete (QValueList<AIElement>*)value.ptr; + break; */ + case AIElement::ElementArray: + delete (QValueVector<AIElement>*)value.ptr; + break; + case AIElement::Block: + delete (QValueVector<AIElement>*)value.ptr; + break; + case AIElement::ByteArray: + delete (QByteArray*)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. QImage is. +*/ +AIElement::AIElement( const AIElement& p ) +{ + d = new Private; + *this = p; +} + +/*! + Constructs a new aielement with a string value, \a val. +*/ +AIElement::AIElement( const QString& val, Type type ) +{ + d = new Private; + d->typ = type; + d->value.ptr = new QString( val ); +} + +/*! + Constructs a new aielement with a C-string value, \a val. + + If you want to modify the QCString after you've passed it to this + constructor, we recommend passing a deep copy (see + QCString::copy()). +*/ +AIElement::AIElement( const QCString& val ) +{ + d = new Private; + d->typ = CString; + d->value.ptr = new QCString( 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 QCString( 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 QValueList<AIElement>& val ) +{ + d = new Private; + d->typ = List; + d->value.ptr = new QValueList<AIElement>( val ); +} */ + +AIElement::AIElement( const QValueVector<AIElement>& val, Type type ) +{ + d = new Private; + d->typ = type; + d->value.ptr = new QValueVector<AIElement>( val ); +} + +AIElement::AIElement( const QByteArray& val ) +{ + d = new Private; + d->typ = ByteArray; + d->value.ptr = new QByteArray( 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 QImage, 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, "QFont", "QString", or "QValueList<AIElement>". + 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, +// "QValueList<AIElement>", + "QString", + "int", + "uint", + "double", + "QCString", + "Operator", + "Reference", + "QValueVector<AIElement>", + "QByteArray", + "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 QString if the aielement has type() + String, CString, ByteArray, Int, Uint, Double, + or QString::null otherwise. + + \sa asString() +*/ +const QString AIElement::toString() const +{ + if ( d->typ == CString ) + return QString::fromLatin1( toCString() ); + if ( d->typ == Int ) + return QString::number( toInt() ); + if ( d->typ == UInt ) + return QString::number( toUInt() ); + if ( d->typ == Double ) + return QString::number( toDouble() ); + if ( d->typ == Byte ) + return QString::number( toByte() ); + if ( d->typ != String ) + return QString::null; + return *((QString*)d->value.ptr); +} + +const QString AIElement::toReference() const +{ + if ( d->typ != Reference ) + return QString::null; + return *((QString*)d->value.ptr); +} + +const QString AIElement::toOperator() const +{ + if ( d->typ != Operator ) + return QString::null; + return *((QString*)d->value.ptr); +} + +/*! + Returns the aielement as a QCString if the aielement has type() + CString or String, or a 0 otherwise. + + \sa asCString() +*/ +const QCString AIElement::toCString() const +{ + if ( d->typ == CString ) + return *((QCString*)d->value.ptr); + if ( d->typ == String ) + return ((QString*)d->value.ptr)->latin1(); + if ( d->typ == Operator ) + return ((QString*)d->value.ptr)->latin1(); + if ( d->typ == Reference ) + return ((QString*)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 ((QString*)d->value.ptr)->toInt( ok ); + if ( d->typ == CString ) + return ((QCString*)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 ((QString*)d->value.ptr)->toShort( ok ); + if ( d->typ == CString ) + return ((QCString*)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 ((QString*)d->value.ptr)->toUInt( ok ); + if ( d->typ == CString ) + return ((QCString*)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 ((QString*)d->value.ptr)->toDouble( ok ); + if ( d->typ == CString ) + return ((QCString*)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 QValueList<AIElement> 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 + QValueList<AIElement> list = myAIElement.toList(); + QValueList<AIElement>::Iterator it = list.begin(); + while( it != list.end() ) { + myProcessing( *it ); + ++it; + } + \endcode + + \sa asList() +*/ +/* const QValueList<AIElement> AIElement::toList() const +{ + if ( d->typ == List ) + return *((QValueList<AIElement>*)d->value.ptr); + return QValueList<AIElement>(); +} */ + +const QValueVector<AIElement> AIElement::toElementArray() const +{ + if ( d->typ == ElementArray ) + return *((QValueVector<AIElement>*)d->value.ptr); + return QValueVector<AIElement>(); +} + +const QValueVector<AIElement> AIElement::toBlock() const +{ + if ( d->typ == Block ) + return *((QValueVector<AIElement>*)d->value.ptr); + return QValueVector<AIElement>(); +} + + +const QByteArray AIElement::toByteArray() const +{ + if ( d->typ == ByteArray ) + return *((QByteArray*)d->value.ptr); + return QByteArray(); +} + +#define Q_VARIANT_AS( f ) Q##f& AIElement::as##f() { \ + if ( d->typ != f ) *this = AIElement( to##f() ); else detach(); return *((Q##f*)d->value.ptr);} + +Q_VARIANT_AS(String) +Q_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 + QValueList<AIElement> list = myAIElement.asList(); + QValueList<AIElement>::Iterator it = list.begin(); + while( it != list.end() ) { + myProcessing( *it ); + ++it; + } + \endcode +*/ +/* QValueList<AIElement>& AIElement::asList() +{ + if ( d->typ != List ) + *this = AIElement( toList() ); + return *((QValueList<AIElement>*)d->value.ptr); +} */ + +QValueVector<AIElement>& AIElement::asElementArray() +{ + if ( d->typ != ElementArray ) + *this = AIElement( toElementArray() ); + return *((QValueVector<AIElement>*)d->value.ptr); +} + +QValueVector<AIElement>& AIElement::asBlock() +{ + if ( d->typ != Block ) + *this = AIElement( toBlock() ); + return *((QValueVector<AIElement>*)d->value.ptr); +} + + +QByteArray& AIElement::asByteArray() +{ + if ( d->typ != ByteArray ) + *this = AIElement( toByteArray() ); + return *((QByteArray*)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: + <ul> + <li> CString => String + <li> Double => String, Int, UInt + <li> Int => String, Double, UInt + <li> String => CString, Int, Uint, Double + <li> UInt => String, Double, Int + </ul> +*/ +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.h b/filters/karbon/ai/aielement.h new file mode 100644 index 00000000..5c6ab045 --- /dev/null +++ b/filters/karbon/ai/aielement.h @@ -0,0 +1,151 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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. +*/ + +#ifndef AIELEMENT_H +#define AIELEMENT_H + +// #include <qvaluelist.h> +#include <qvaluevector.h> + +class QString; +class QCString; + +/** + *@author + */ + +class AIElement { +public: + enum Type { + Invalid, +// List, + String, + Int, + UInt, + Double, + CString, + // Custom Types + Operator, + Reference, + ElementArray, + Block, + ByteArray, + Byte + }; + + AIElement(); + ~AIElement(); + AIElement( const AIElement& ); + AIElement( const QString&, Type type = String ); + AIElement( const QCString& ); + AIElement( const char* ); +// AIElement( const QValueList<AIElement>& ); + AIElement( const QValueVector<AIElement>&, Type type = ElementArray); + AIElement( int ); + AIElement( uint ); + AIElement( double ); + AIElement( const QByteArray& ); + AIElement( uchar ); + + AIElement& operator= ( const AIElement& ); + bool operator==( const AIElement& ) const; + bool operator!=( const AIElement& ) const; + + Type type() const; + const char* typeName() const; + + bool canCast( Type ) const; + bool cast( Type ); + + bool isValid() const; + + void clear(); + + const QString toString() const; + const QCString toCString() const; + int toInt( bool * ok=0 ) const; + uint toUInt( bool * ok=0 ) const; + double toDouble( bool * ok=0 ) const; +// const QValueList<AIElement> toList() const; + const QValueVector<AIElement> toElementArray() const; + const QValueVector<AIElement> toBlock() const; + + // Custom types + const QString toReference() const; + const QString toOperator() const; + const QByteArray toByteArray() const; + uchar toByte( bool * ok=0 ) const; + +// QValueListConstIterator<AIElement> listBegin() const; +// QValueListConstIterator<AIElement> listEnd() const; + QString& asString(); + QCString& asCString(); + int& asInt(); + uint& asUInt(); + double& asDouble(); +// QValueList<AIElement>& asList(); + QValueVector<AIElement>& asElementArray(); + QValueVector<AIElement>& asBlock(); + + // Custom types + QString& asReference(); + QString& asToken(); + QByteArray& asByteArray(); + uchar& asByte(); + + static const char* typeToName( Type typ ); + static Type nameToType( const char* name ); + +private: + void detach(); + + class Private : public QShared + { + public: + Private(); + Private( Private* ); + ~Private(); + + void clear(); + + Type typ; + union + { + uint u; + int i; + double d; + uchar b; + void *ptr; + } value; + }; + + Private* d; +}; + +inline AIElement::Type AIElement::type() const +{ + return d->typ; +} + +inline bool AIElement::isValid() const +{ + return (d->typ != Invalid); +} + +#endif diff --git a/filters/karbon/ai/aiimport.cc b/filters/karbon/ai/aiimport.cc new file mode 100644 index 00000000..a5e24f5b --- /dev/null +++ b/filters/karbon/ai/aiimport.cc @@ -0,0 +1,101 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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 <qdom.h> +#include <qcstring.h> +#include <qfile.h> +#include <qstring.h> + +#include <kgenericfactory.h> +#include <KoFilterChain.h> +#include <KoStore.h> + +#include <kdebug.h> + +#include "aiimport.h" +#include "karbonaiparserbase.h" + +class AiImportFactory : KGenericFactory<AiImport, KoFilter> +{ +public: + AiImportFactory( void ) + : KGenericFactory<AiImport, KoFilter>( "karbonaiimport" ) + {} + +protected: + virtual void setupTranslations( void ) + { + KGlobal::locale()->insertCatalogue( "kofficefilters" ); + } +}; + +K_EXPORT_COMPONENT_FACTORY( libkarbonaiimport, AiImportFactory() ) + +AiImport::AiImport( KoFilter*, const char*, const QStringList& ) + : KoFilter() +{ +} + +AiImport::~AiImport() +{ +} + +KoFilter::ConversionStatus +AiImport::convert( const QCString& from, const QCString& to ) +{ + if ( from != "application/illustrator" || to != "application/x-karbon" ) + { + return KoFilter::NotImplemented; + } + QFile fileIn( m_chain->inputFile() ); + if( !fileIn.open( IO_ReadOnly ) ) + { + fileIn.close(); + return KoFilter::FileNotFound; + } + + QDomDocument doc ("DOC"); + KarbonAIParserBase parser; + + if (!parser.parse (fileIn, doc)) + { + fileIn.close(); + return KoFilter::CreationError; + } + QString result = doc.toString(); + + kdDebug() << result << endl; + KoStoreDevice* storeOut = m_chain->storageFile( "root", KoStore::Write ); + if( !storeOut ) + { + fileIn.close(); + return KoFilter::StorageCreationError; + } + + QCString cStr = result.latin1(); + storeOut->writeBlock( cStr, cStr.size() - 1 ); + + return KoFilter::OK; +} + + +#include "aiimport.moc" + + + diff --git a/filters/karbon/ai/aiimport.h b/filters/karbon/ai/aiimport.h new file mode 100644 index 00000000..2ec2d19b --- /dev/null +++ b/filters/karbon/ai/aiimport.h @@ -0,0 +1,47 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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. +*/ + +#ifndef __AIIMPORT_H__ +#define __AIIMPORT_H__ + +#include <KoFilter.h> + +#include "karbonaiparserbase.h" + +class QDomElement; +class QTextStream; + +class AiImport : public KoFilter +{ + Q_OBJECT + +public: + AiImport( KoFilter* parent, const char* name, const QStringList& ); + virtual ~AiImport(); + + virtual KoFilter::ConversionStatus convert( const QCString& from, const QCString& to ); +/* private: + QString m_result; */ + + +}; + +#endif + + diff --git a/filters/karbon/ai/ailexer.cc b/filters/karbon/ai/ailexer.cc new file mode 100644 index 00000000..7b660f7f --- /dev/null +++ b/filters/karbon/ai/ailexer.cc @@ -0,0 +1,514 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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 <ctype.h> +#include <stdlib.h> +#include <qstringlist.h> +#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; + 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 (QIODevice& fin){ + char c; + + m_buffer.clear(); + m_curState = State_Start; + + parsingStarted(); + + while (!fin.atEnd()) + { + c = fin.getch (); + +// qDebug ("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 : + qWarning ( "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 : + qWarning ( "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: + qWarning ( "unknown state: %d", m_curState ); + } + + m_buffer.clear(); +} + +void AILexer::gotComment (const char *value) { + qDebug ( "gotComment: %s ", value ); +} + +void AILexer::gotIntValue (int value) { + qDebug ( "gotInt: %d ", value ); +} + +void AILexer::gotDoubleValue (double value) { + qDebug ( "gotDouble: %f ", value ); +} + +void AILexer::gotStringValue (const char *value) { + qDebug ( "gotString: %s ", value ); +} + +void AILexer::gotToken (const char *value) { + qDebug ( "gotToken: %s ", value ); +} + +void AILexer::gotReference (const char *value) { + qDebug ( "gotReference: %s ", value ); +} + +void AILexer::gotBlockStart (){ + qDebug ( "gotBlockStart" ); +} + +void AILexer::gotBlockEnd (){ + qDebug ( "gotBlockEnd" ); +} + +void AILexer::gotArrayStart (){ + qDebug ( "gotArrayStart" ); +} + +void AILexer::gotArrayEnd (){ + qDebug ( "gotArrayEnd" ); +} + +void AILexer::parsingStarted() { + qDebug ( "parsing started" ); +} + +void AILexer::parsingFinished() { + qDebug ( "parsing finished" ); +} + +void AILexer::parsingAborted() { + qDebug ( "parsing aborted" ); +} + +void AILexer::gotByte (uchar value) { + qDebug ( "got byte %d" , value ); +} + +void AILexer::gotByteArray (const QByteArray &data) { + qDebug ( "got byte array" ); +/* for ( uint i = 0; i < data.size(); i++ ) + { + uchar value = data[i]; + qDebug( "%d: %x", i, value ); + } + qDebug ( "/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; + + QByteArray data (m_buffer.length() >> 1); + + while (strIdx < m_buffer.length()) + { + const QString &item = m_buffer.mid (strIdx, 2); + uchar val = item.toShort(NULL, 16); + data[arrayIdx] = val; + strIdx += 2; + arrayIdx++; + } + + gotByteArray (data); +} + +uchar AILexer::getByte() +{ +// qDebug ("convert string to byte (%s)", m_buffer.latin1()); + + QStringList list = QStringList::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); +// qDebug ("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<m_length; i++) m_buffer[i] = '\0'; + m_length = 0; +} + +QString StringBuffer::toString() const { + QString ret(m_buffer); + return ret; +} + +void StringBuffer::ensureCapacity (int p_capacity) { + if (m_capacity >= 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() { + QString data = toString(); + return data.toFloat(); +} + +int StringBuffer::toInt() { + QString data = toString(); + return data.toInt(); +} + +const char *StringBuffer::latin1() { + return m_buffer; +} + +QString StringBuffer::mid( uint index, uint len) const { + QString data = toString(); + return data.mid(index,len); +} diff --git a/filters/karbon/ai/ailexer.h b/filters/karbon/ai/ailexer.h new file mode 100644 index 00000000..c53aab66 --- /dev/null +++ b/filters/karbon/ai/ailexer.h @@ -0,0 +1,123 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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. +*/ + +#ifndef AILEXER_H +#define AILEXER_H + +#include <qiodevice.h> +#include <qstring.h> + +/** + *@author Dirk Schnberger + */ +typedef enum { + State_Comment=0, + State_Integer, + State_Float, + State_String, + State_Token, + State_Reference, + State_Start, + State_BlockStart, + State_BlockEnd, + State_ArrayStart, + State_ArrayEnd, + State_Byte, + State_ByteArray, + State_StringEncodedChar, + State_CommentEncodedChar, + State_ByteArray2 +} State; + +typedef enum { + Action_Copy=1, + Action_CopyOutput, + Action_Output, + Action_Ignore, + Action_Abort, + Action_OutputUnget, + Action_InitTemp, + Action_CopyTemp, + Action_DecodeUnget, + Action_ByteArraySpecial +} Action; + +class StringBuffer { +public: + StringBuffer (); + virtual ~StringBuffer (); + + void append (char c); + void clear(); + QString toString() const; + uint length(); + double toFloat(); + int toInt(); + const char *latin1(); + QString mid( uint index, uint len=0xffffffff) const; +private: + char *m_buffer; + uint m_length; + int m_capacity; + + void ensureCapacity (int p_capacity); +}; + +class AILexer { +public: + AILexer(); + virtual ~AILexer(); + + virtual bool parse (QIODevice& fin); +private: + State m_curState; + StringBuffer m_buffer; + StringBuffer m_temp; + +/* State nextState (char c); + Action nextAction (char c); */ + + void nextStep (char c, State* newState, Action* newAction); + + void doOutput (); + void doHandleByteArray (); + uchar getByte(); + uchar decode(); + +protected: + virtual void parsingStarted(); + virtual void parsingFinished(); + virtual void parsingAborted(); + + virtual void gotComment (const char *value); + virtual void gotIntValue (int value); + virtual void gotDoubleValue (double value); + virtual void gotStringValue (const char *value); + virtual void gotToken (const char *value); + virtual void gotReference (const char *value); + virtual void gotBlockStart (); + virtual void gotBlockEnd (); + virtual void gotArrayStart (); + virtual void gotArrayEnd (); + virtual void gotByte (uchar value); + virtual void gotByteArray (const QByteArray &data); +}; + +#endif + diff --git a/filters/karbon/ai/aiparserbase.cc b/filters/karbon/ai/aiparserbase.cc new file mode 100644 index 00000000..63ace734 --- /dev/null +++ b/filters/karbon/ai/aiparserbase.cc @@ -0,0 +1,1337 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schönberger <dirk.schoenberger@sz-online.de> + + 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 <qregexp.h> +#include <qstringlist.h> + +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 (QIODevice& 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) qDebug ("start ignoring"); + m_ignoring = true; + break; + case CO_BeginResource : + if (m_moduleHandler) m_moduleHandler->gotBeginSection (ST_Resource, value); + if (m_debug) qDebug ("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) qDebug ("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) qDebug ("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) qDebug ("stop ignoring"); + m_ignoring = false; + break; + case CO_EndResource : + if (m_moduleHandler) m_moduleHandler->gotEndSection (ST_Resource, value); + if (m_debug) qDebug ("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 : qWarning ("unknown continuation mode %d",m_continuationMode); + } + break; + + default : + qWarning( "unhandled comment: %s", value ); + } +} + +void AIParserBase::handleElement (AIElement &element) +{ + if (m_ignoring) return; + + if (m_sink == DS_Array) + { + if (m_debug) qDebug ("in mode array"); + QValueVector<AIElement> &elementArray = m_arrayStack.top(); + elementArray.push_back(element); + } + if (m_sink == DS_Block) + { + if (m_debug) qDebug ("in mode block"); + QValueVector<AIElement> &elementArray = m_blockStack.top(); + elementArray.push_back(element); + } + else + { + if (m_debug) qDebug ("in mode stack"); + m_stack.push (element); + } +} + +void AIParserBase::gotIntValue (int value) { + if (m_debug) qDebug ("got int value"); + if (m_ignoring) return; + AIElement element (value); + handleElement (element); + if (m_debug) qDebug ("/got int value"); +} + +void AIParserBase::gotDoubleValue (double value) { + if (m_debug) qDebug ("got double value"); + if (m_ignoring) return; + AIElement element (value); + handleElement (element); + if (m_debug) qDebug ("/got double value"); +} + +void AIParserBase::gotStringValue (const char *value) { + if (m_debug) qDebug ("got string value"); + if (m_ignoring) return; + if (value == NULL) value = ""; + if (m_debug) qDebug ("string: %s", value); + AIElement element (value); + handleElement (element); + if (m_debug) qDebug ("/got string value"); + +} + +void AIParserBase::gotReference (const char *value) { + if (m_debug) qDebug ("got reference value"); + + if (m_ignoring) return; + if (value == NULL) value = ""; + if (m_debug) qDebug ("reference: %s", value); + QString string(value); + AIElement element (string, AIElement::Reference); + handleElement (element); + if (m_debug) qDebug ("/got reference value"); + +} + +void AIParserBase::gotByte (uchar value) { + if (m_debug) qDebug ("got byte value"); + + if (m_ignoring) return; + AIElement element (value); + handleElement (element); + if (m_debug) qDebug ("/got byte value"); +} + +void AIParserBase::gotByteArray (const QByteArray &data) { + if (m_ignoring) return; + AIElement element (data); + handleElement (element); +} + + +void AIParserBase::gotArrayStart () { + if (m_ignoring) return; + if (m_debug) qDebug ("got array start"); + + QValueVector<AIElement> array; + m_arrayStack.push (array); + + m_sink = DS_Array; +} + +void AIParserBase::gotBlockStart () { + if (m_ignoring) return; + if (m_debug) qDebug ("got block start"); + + QValueVector<AIElement> array; + m_blockStack.push (array); + + m_sink = DS_Block; +} + +void AIParserBase::gotArrayEnd () { + if (m_ignoring) return; + if (m_debug) qDebug ("got array end"); + + QValueVector<AIElement> stackArray = m_arrayStack.pop(); + + if (m_arrayStack.empty()) + { + if (m_debug) qDebug ("put elements to stack"); + AIElement realElement (stackArray); + + if (m_debug) { + qDebug ("going to stack"); + elementtoa (realElement); + qDebug ("done"); + } + m_stack.push (realElement); + + m_sink = DS_Other; + } + else + { + if (m_debug) qDebug ("put elements to nest stack level"); + QValueVector<AIElement> currentTOS = m_arrayStack.top(); + currentTOS.push_back (stackArray); + } +} + +void AIParserBase::gotBlockEnd () { + if (m_ignoring) return; + if (m_debug) qDebug ("got block end"); + + QValueVector<AIElement> stackArray = m_blockStack.pop(); + + if (m_blockStack.empty()) + { + if (m_debug) qDebug ("put elements to stack"); + AIElement realElement (stackArray, AIElement::Block); + + if (m_debug) { + qDebug ("going to stack"); + elementtoa (realElement); + qDebug ("done"); + } + m_stack.push (realElement); + + m_sink = DS_Other; + } + else + { + if (m_debug) qDebug ("put elements to nest stack level"); + QValueVector<AIElement> currentTOS = m_blockStack.top(); + currentTOS.push_back (stackArray); + } +} + +/*Ai88*/ /* void AIParserBase::_handleSetDash() +{ + double fval = getDoubleValue(); + + AIElement elem (m_stack.top()); + m_stack.pop(); + + const QValueVector<AIElement> 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) qDebug ("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 QValueVector<AIElement> 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 QString &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 QValueVector<AIElement> 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 QString &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) qDebug ("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) qDebug ("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) qDebug ("values 4 are %f",g); + + AIColor color (g); + + if (m_gstateHandler) m_gstateHandler->gotStrokeColor (color); +} */ + +/*Ai88*/ /* void AIParserBase::_handleSetFillColorCustom() +{ + double g = getDoubleValue(); + const QString &name = getStringValue(); + double k = getDoubleValue(); + double y = getDoubleValue(); + double m = getDoubleValue(); + double c = getDoubleValue(); + if (m_debug) qDebug ("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(); + + QString name ("xxx"); + AIElement ref (name,AIElement::Reference); + m_stack.push (ref); +} + +void AIParserBase::_handlePSExec() { + m_stack.pop(); +} + +void AIParserBase::_handlePSString() { + m_stack.pop(); + + QString name ("stringval"); + AIElement ref (name,AIElement::Reference); + m_stack.push (ref); +} + +void AIParserBase::_handlePSBind() { + m_stack.pop(); + + QString name ("bindentry"); + AIElement ref (name,AIElement::Reference); + m_stack.push (ref); +} + +void AIParserBase::_handlePSUserdict() { + QString name ("userdict"); + AIElement ref (name,AIElement::Reference); + m_stack.push (ref); +} + +void AIParserBase::_handlePSDict() { + m_stack.pop(); + m_stack.pop(); + m_stack.pop(); + + QString 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(); + + QString 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 QValueVector<AIElement> aval = elem.toElementArray(); + + double ury = getDoubleValue(); + double urx = getDoubleValue(); + double lly = getDoubleValue(); + double llx = getDoubleValue(); + + AIElement elem2 (m_stack.top()); + m_stack.pop(); + + const QString &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 QString &name = getStringValue(); + double k = getDoubleValue(); + double y = getDoubleValue(); + double m = getDoubleValue(); + double c = getDoubleValue(); + if (m_debug) qDebug ("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; + QStringList items = QStringList::split (' ', data); + + QString itemType = items[1]; + QString name = items[2]; + QString version = items[3]; + QString release = items[4]; +} + +void AIParserBase::_handleIncludeResource(const char *data) { + if (!data) return; + QStringList items = QStringList::split (' ', data); + + QString itemType = items[1]; + QString name = items[2]; + QString version = items[3]; + QString release = items[4]; + + m_modules.push_back (name); +} + +void AIParserBase::_handleDocumentProcessColors(const char *data) { + if (!data) return; + + int colorSet = 0; + QString 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 QString &name = elem2.toString(); + + int ury = getIntValue(); + int urx = getIntValue(); + int lly = getIntValue(); + int llx = getIntValue(); + + AIElement elem (m_stack.top()); + m_stack.pop(); + + const QValueVector<AIElement> 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 QString &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()); + qDebug ("to element is (%s)",elem.typeName()); + m_stack.pop(); + + const QValueVector<AIElement> aval = elem.toElementArray(); + + if (m_textHandler) m_textHandler->gotTextBlockBegin (aval, to); +} */ + +/*Ai88*/ /* void AIParserBase::_handleTextOutput () { + AIElement elem (m_stack.top()); + m_stack.pop(); + + const QString &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; + + QRegExp test ("\\((.+)\\) \\((.+)\\)"); + if (test.search (data)) + { + QString val1 = test.cap(1); + QString val2 = test.cap(2); + + if (m_documentHandler) m_documentHandler->gotCreationDate (val1.latin1(),val2.latin1()); + } +} + +void AIParserBase::gotToken (const char *value) { + if (m_debug) qDebug ("got token"); + + if (m_ignoring) return; + if (m_debug) qDebug ("token: %s", value); + + if (m_sink == DS_Array) + { + if (m_debug) qDebug ("token in array"); + QString op (value); + AIElement realElement (op, AIElement::Operator); + handleElement (realElement); + + return; + } + if (m_sink == DS_Block) + { + if (m_debug) qDebug ("token in block"); + QString op (value); + AIElement realElement (op, AIElement::Operator); + handleElement (realElement); + + return; + } + + if (m_debug) qDebug ("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; + } + qWarning ( "unknown operator: %s", value ); + + QString string(value); + + if (m_modules.findIndex(string) != -1) + { + AIElement element (string, AIElement::Reference); + handleElement (element); + return; + } + + if (m_debug) stacktoa (m_stack); + qWarning ( "pushing %s to stack", value ); + AIElement element (string, AIElement::Operator); + handleElement (element); + } + + if (m_debug) qDebug ("/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 QString AIParserBase::getStringValue(void) { + const AIElement &elem = m_stack.pop(); + + return elem.toString(); +} + +const QString AIParserBase::getOperatorValue(void) { + const AIElement &elem = m_stack.pop(); + + return elem.toOperator(); +} + +AIOperation AIParserBase::getAIOperation (const char *operand) +{ + int i=0; + QString 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; + QString 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) { + QString 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 QValueVector<AIElement>& transformData) { + qDebug ( "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); + qDebug ("/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 QValueVector<AIElement>& transformData) { + qDebug ( "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); + qDebug ("/got stroke pattern"); +} + +const char *AIParserBase::getValue (const char *input) { + QString 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; + + QString s(input); + if (s.contains ("(atend)")) return false; + QStringList values = QStringList::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; + + QString s(input); + QStringList values = QStringList::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) qDebug ("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 QString &oldFont = elem.toReference(); + + AIElement elem2 (m_stack.top()); + m_stack.pop(); + const QString &newFont = elem2.toReference(); + + AIElement elem3 (m_stack.top()); + m_stack.pop(); + const QValueVector<AIElement> encodingData = elem3.toElementArray(); + + if (m_textHandler) m_textHandler->gotFontEncoding (encodingData, oldFont.latin1(), newFont.latin1()); +} */ + +void TextHandlerBase::gotFontEncoding (const QValueVector<AIElement>& encodingData, const char*oldFontName, const char*newFontName) +{ + qDebug ("font encoding %s to %s",oldFontName, newFontName); + arraytoa (encodingData); + qDebug ("/font encoding"); +} + +void TextHandlerBase::gotFontDefinition (const char*fontName, double size, double leading, double kerning, TextAlign align) +{ + qDebug ("font definition: name %s size %f leading %f kerning %f align %d", fontName, size, leading, kerning, align); +} + +void TextHandlerBase::gotTextBlockBegin (const QValueVector<AIElement>& transData, TextOperation mode) +{ + qDebug ("text block begin %d",mode); + arraytoa (transData); + qDebug ("/text block begin"); +} + +void TextHandlerBase::gotTextOutput (const char*text, int length) +{ + qDebug ("text output (%s) %d",text,length); +} + +void TextHandlerBase::gotTextBlockEnd () +{ + qDebug ("text block end"); +} + +const void elementtoa (const AIElement &/*data*/) +{ +/* AIElement::Type type = data.type(); + qDebug ("type: %s", AIElement::typeToName (type)); + + switch (type) + { + case AIElement::String : + case AIElement::CString : + case AIElement::Int : + case AIElement::UInt : + case AIElement::Double : + qDebug ("string value : %s",data.toString().latin1()); + break; + case AIElement::Reference : + qDebug ("string value : %s",data.toReference().latin1()); + break; + case AIElement::Operator : + qDebug ("string value : %s",data.toOperator().latin1()); + break; + case AIElement::ElementArray : + arraytoa (data.toElementArray()); + break; + case AIElement::Block : + arraytoa (data.toBlock()); + break; + + default : + qDebug ("could not fetch data"); + } */ +} + +const void arraytoa (const QValueVector<AIElement> &/*data*/) +{ +/* qDebug ("array size is %d ",data.size()); + if (data.size() > 0) + { + qDebug ("[[[[[[[[[[[[[[[[[[[["); + for (uint i=0; i< data.size(); i++) + { + elementtoa (data[i]); + } + qDebug ("]]]]]]]]]]]]]]]]]]]]"); + } */ +} + +const void stacktoa (const QValueStack<AIElement> &/*data*/) +{ +/* qDebug ("stack size is %d",data.size()); + if (data.size() > 0) + { + qDebug ("<<<<<<<<<<<<<<<<<<"); + for (uint i=0; i< data.size(); i++) + { + elementtoa (data[i]); + } + } + qDebug (">>>>>>>>>>>>>>>>>>"); */ +} + +const void stacktoa2 (const QValueStack<QValueVector<AIElement> >&/*data*/) +{ +/* qDebug ("stack size is %d",data.size()); + + if (data.size() > 0) + { + qDebug ("((((((((((((((((((((((("); + for (uint i=0; i< data.size(); i++) + { + arraytoa (data[i]); + } + qDebug (")))))))))))))))))))))))"); + } */ +} + +const void aiotoa (AIOperation &data) +{ + switch (data) + { + case AIO_SetFillColorCMYK : qDebug ("AIO_SetFillColorCMYK"); break; + case AIO_SetStrokeColorCMYK : qDebug ("AIO_SetStrokeColorCMYK"); break; + case AIO_SetFillColorGray : qDebug ("AIO_SetFillColorGray"); break; + case AIO_SetStrokeColorGray : qDebug ("AIO_SetStrokeColorGray"); break; + case AIO_SetFillColorCustom : qDebug ("AIO_SetFillColorCustom"); break; + case AIO_SetStrokeColorCustom : qDebug ("AIO_SetStrokeColorCustom"); break; + case AIO_SetFillPattern : qDebug ("AIO_SetFillPattern"); break; + case AIO_SetStrokePattern : qDebug ("AIO_SetStrokePattern"); break; + case AIO_SetFillOverprinting : qDebug ("AIO_SetFillOverprinting"); break; + case AIO_SetStrokeOverprinting : qDebug ("AIO_SetStrokeOverprinting"); break; + case AIO_SetFlatness : qDebug ("AIO_SetFlatness"); break; + case AIO_SetLineCap : qDebug ("AIO_SetLineCap"); break; + case AIO_SetLineJoin : qDebug ("AIO_SetLineJoin"); break; + case AIO_SetLineWidth : qDebug ("AIO_SetLineWidth"); break; + case AIO_SetMiterLimit : qDebug ("AIO_SetMiterLimit"); break; + case AIO_SetDash : qDebug ("AIO_SetDash"); break; + case AIO_BeginGroupClip : qDebug ("AIO_BeginGroupClip"); break; + case AIO_EndGroupClip : qDebug ("AIO_EndGroupClip"); break; + case AIO_MoveTo : qDebug ("AIO_MoveTo"); break; + case AIO_LineToCorner : qDebug ("AIO_LineToCorner"); break; + case AIO_LineToSmooth : qDebug ("AIO_LineToSmooth"); break; + case AIO_CurveToSmooth : qDebug ("AIO_CurveToSmooth"); break; + case AIO_CurveToCorner : qDebug ("AIO_CurveToCorner"); break; + case AIO_CurveToOmitC1Smooth : qDebug ("AIO_CurveToOmitC1Smooth"); break; + case AIO_CurveToOmitC1Corner : qDebug ("AIO_CurveToOmitC1Corner"); break; + case AIO_CurveToOmitC2Smooth : qDebug ("AIO_CurveToOmitC2Smooth"); break; + case AIO_CurveToOmitC2Corner : qDebug ("AIO_CurveToOmitC2Corner"); break; + case AIO_PathIgnoreNoReset : qDebug ("AIO_PathIgnoreNoReset"); break; + case AIO_PathIgnoreNoResetClose : qDebug ("AIO_PathIgnoreNoResetClose"); break; + case AIO_PathClipPath : qDebug ("AIO_PathClipPath"); break; + case AIO_PathIgnoreReset : qDebug ("AIO_PathIgnoreReset"); break; + case AIO_PathIgnoreResetClose : qDebug ("AIO_PathIgnoreResetClose"); break; + case AIO_PathFillNonZero : qDebug ("AIO_PathFillNonZero"); break; + case AIO_PathFillNonZeroClose : qDebug ("AIO_PathFillNonZeroClose"); break; + case AIO_PathStroke : qDebug ("AIO_PathStroke"); break; + case AIO_PathStrokeClose : qDebug ("AIO_PathStrokeClose"); break; + case AIO_PathFillNoReset : qDebug ("AIO_PathFillNoReset"); break; + case AIO_PathFillNoResetClose : qDebug ("AIO_PathFillNoResetClose"); break; + case AIO_FontEncoding : qDebug ("AIO_FontEncoding"); break; + case AIO_PatternDefinition : qDebug ("AIO_PatternDefinition"); break; + case AIO_SetCurrentText : qDebug ("AIO_SetCurrentText"); break; + case AIO_TextBlockFillStroke : qDebug ("AIO_TextBlockFillStroke"); break; + case AIO_TextBlockFill : qDebug ("AIO_TextBlockFill"); break; + case AIO_TextBlockAppend : qDebug ("AIO_TextBlockAppend"); break; + case AIO_TextBlockIgnore : qDebug ("AIO_TextBlockIgnore"); break; + case AIO_TextBlockStroke : qDebug ("AIO_TextBlockStroke"); break; + case AIO_TextOutput : qDebug ("AIO_TextOutput"); break; + case AIO_TextBlockEnd : qDebug ("AIO_TextBlockEnd"); break; + case AIO_GsaveIncludeDocument : qDebug ("AIO_GsaveIncludeDocument"); break; + case AIO_Grestore : qDebug ("AIO_Grestore"); break; + case AIO_LockElement : qDebug ("AIO_LockElement"); break; + case AIO_SetWindingOrder : qDebug ("AIO_SetWindingOrder"); break; + default : qDebug ("unknown"); + } +} + +const void sttoa (SectionType &data, bool begin) +{ + switch (data) + { + case ST_Setup : begin ? qDebug ("start setup") : qDebug ("end setup"); break; + case ST_Prolog : begin ? qDebug ("start prolog") : qDebug ("end prolog"); break; + case ST_ProcSet : begin ? qDebug ("start procset") : qDebug ("end procset"); break; + case ST_Encoding : begin ? qDebug ("start encoding") : qDebug ("end encoding"); break; + case ST_Pattern : begin ? qDebug ("start pattern") : qDebug ("end pattern"); break; + case ST_Document : begin ? qDebug ("start document") : qDebug ("end document"); break; + case ST_BrushPattern : begin ? qDebug ("start brush pattern") : qDebug ("end brush pattern"); break; + case ST_Gradient : begin ? qDebug ("start gradient") : qDebug ("end gradient"); break; + case ST_Palette : begin ? qDebug ("start palette") : qDebug ("end palette"); break; + case ST_Resource : begin ? qDebug ("start resource") : qDebug ("end resouce"); break; + + default : begin ? qDebug ("unknown") : qDebug ("end unknown"); + } +} + diff --git a/filters/karbon/ai/aiparserbase.h b/filters/karbon/ai/aiparserbase.h new file mode 100644 index 00000000..8d2633f3 --- /dev/null +++ b/filters/karbon/ai/aiparserbase.h @@ -0,0 +1,440 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schönberger <dirk.schoenberger@sz-online.de> + + 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. +*/ + +#ifndef AIPARSERBASE_H +#define AIPARSERBASE_H + +#include "ailexer.h" + +#include <qstring.h> +#include <qvaluestack.h> +#include <qvaluevector.h> +#include <qvaluelist.h> + +#include "aielement.h" +#include "aicolor.h" + + +const void arraytoa (const QValueVector<AIElement> &data); +const void elementtoa (const AIElement &data); +const void stacktoa (const QValueStack<AIElement> &data); +const void stacktoa2 (const QValueStack<QValueVector<AIElement> >&data); + +class GStateHandlerBase; +class StructureHandlerBase; +class PathHandlerBase; +class MiscGStateHandlerBase; +class DocumentHandlerBase; +class ModuleHandlerBase; +class EmbeddedHandlerBase; +class TextHandlerBase; +class AI88Handler; +class AI3Handler; + +/** + *@author Dirk Schönberger + */ + +typedef enum { PET_MoveTo, PET_LineTo, PET_CurveTo, PET_CurveToOmitC1, PET_CurveToOmitC2 } PathElementType; +typedef enum { PT_Smooth, PT_Corner } PointType; +typedef enum { TO_FillStroke, TO_Fill, TO_Append, TO_Ignore, TO_Stroke } TextOperation; +typedef enum { FM_NonZero=0, FM_EvenOdd=1 } FillMode; +typedef enum { FS_Roman, FS_Kanji } FontScript; + +typedef enum { DS_Array, DS_Block, DS_Other } DataSink; +typedef enum { ST_Setup, ST_Prolog, ST_ProcSet, ST_Encoding, ST_Pattern, ST_Document, ST_BrushPattern, ST_Gradient, ST_Palette, ST_Resource } SectionType; + +typedef enum { TA_HLeft, TA_HCenter, TA_HRight, TA_VTop, TA_VCenter, TA_VBottom } TextAlign; + +#define PC_Cyan 0x0001 +#define PC_Magenta 0x0002 +#define PC_Yellow 0x0004 +#define PC_Black 0x0008 + +typedef enum { + /* AI 88 */ + AIO_SetFillColorCMYK, AIO_SetStrokeColorCMYK, + AIO_SetFillColorGray, AIO_SetStrokeColorGray, + AIO_SetFillColorCustom, AIO_SetStrokeColorCustom, + AIO_SetFillPattern, AIO_SetStrokePattern, + AIO_SetFillOverprinting, AIO_SetStrokeOverprinting, + AIO_SetFlatness, AIO_SetLineCap, AIO_SetLineJoin, + AIO_SetLineWidth, AIO_SetMiterLimit, AIO_SetDash, + AIO_BeginGroupClip, AIO_EndGroupClip, + AIO_MoveTo, + AIO_LineToCorner, + AIO_LineToSmooth, + AIO_CurveToSmooth, + AIO_CurveToCorner, + AIO_CurveToOmitC1Smooth, + AIO_CurveToOmitC1Corner, + AIO_CurveToOmitC2Smooth, + AIO_CurveToOmitC2Corner, + + AIO_PathIgnoreNoReset, AIO_PathIgnoreNoResetClose, + AIO_PathClipPath, + AIO_PathIgnoreReset, AIO_PathIgnoreResetClose, + AIO_PathFillNonZero, AIO_PathFillNonZeroClose, + AIO_PathStroke, AIO_PathStrokeClose, + AIO_PathFillNoReset, AIO_PathFillNoResetClose, + + AIO_FontEncoding, + AIO_PatternDefinition, + + AIO_SetCurrentText, + AIO_TextBlockFillStroke, + AIO_TextBlockFill, + AIO_TextBlockAppend, + AIO_TextBlockIgnore, + AIO_TextBlockStroke, + AIO_TextOutput, + AIO_TextBlockEnd, + + AIO_GsaveIncludeDocument, + AIO_Grestore, + + AIO_LockElement, + + /* AI 3 */ + AIO_SetWindingOrder, + AIO_SetFillMode, + + AIO_BeginGroupNoClip, AIO_EndGroupNoClip, + AIO_BeginCombination, AIO_EndCombination, + + AIO_Other +} AIOperation; + +typedef enum { + PSO_Get, + PSO_Exec, + PSO_Def, + PSO_String, + PSO_Bind, + PSO_Userdict, + PSO_Dict, + PSO_Dup, + PSO_Begin, + PSO_Put, + PSO_Other +} PSOperation; + +typedef enum { + CU_BlackWhite, + CU_Color, + CU_Unknown +} ColorUsage; + +typedef enum { + CO_BeginSetup, CO_EndSetup, + CO_BeginProlog, CO_EndProlog, + CO_BeginProcSet, CO_EndProcSet, + CO_BeginEncoding, CO_EndEncoding, + CO_BeginPattern, CO_EndPattern, + CO_IncludeFile, + CO_BeginDocument, CO_EndDocument, + + CO_Trailer, + CO_BoundingBox, + CO_TemplateBox, + CO_Margin, + CO_Title, + CO_Creator, + CO_Other, +/**/ CO_For, + CO_CreationDate, +/**/ CO_DocumentFonts, +/**/ CO_DocumentFiles, +/**/ CO_ColorUsage, +/**/ CO_DocumentProcSets, +/**/ CO_DocumentSuppliedProcSets, + CO_DocumentProcessColors, +/**/ CO_DocumentCustomColors, +/**/ CO_CMYKCustomColor, +/**/ CO_TileBox, + CO_Continuation, +/**/ CO_Note, + + // AI88 Win +/**/ CO_Template, +/**/ CO_PageOrigin, +/**/ CO_PrinterName, +/**/ CO_PrinterRect, + + // AI8 + CO_BeginBrushPattern, CO_EndBrushPattern, + CO_BeginGradient, CO_EndGradient, + CO_BeginPalette, CO_EndPalette, + + // other + CO_BeginResource, CO_EndResource, + CO_IncludeFont, + CO_IncludeResource, + CO_DocumentNeededResources, + + CO_Ignore +} CommentOperation; + +typedef enum { + CM_DocumentFonts = 1, + CM_DocumentFiles = 2, + CM_DocumentCustomColors = 3, + CM_CMYKCustomColor = 4, + CM_DocumentNeededResources = 5, + CM_None = -1 +} ContinuationMode; + +typedef enum { +/**/ PDO_ColorDefinition, +/**/ PDO_TileDefinition +} PatternDefinitionOperation; + +/**/ +#define PatternTileFilledDefiniton "_" +#define TextSizeUnknown -1 + +/* typedef QValueVector<AElement> ElementArray; +typedef QValueStack<AIElement> ElementStack; +typedef QValueStack<ElementArray> ElementArrayStack; */ + +typedef struct { + PathElementType petype; + union { + struct { + float x, y; + } pointdata; + struct { + float x1, y1, x2, y2, x3, y3; + } bezierdata; + } pevalue; + PointType pttype; +} PathElement; + +class AIParserBase : protected AILexer { + friend class AI88Handler; + friend class AI3Handler; + +protected: + bool m_debug; +private: + bool m_ignoring; + QValueStack<AIElement> m_stack; + QValueStack<QValueVector<AIElement> > m_arrayStack; + QValueStack<QValueVector<AIElement> > m_blockStack; + DataSink m_sink; + QValueList<QString> m_modules; + ContinuationMode m_continuationMode; + + const double getDoubleValue(void); + const int getIntValue(void); + const bool getBoolValue(void); + const QString getStringValue(void); + const QString& getReferenceValue(void); + const QString getOperatorValue(void); + +/*Ai88*/ // void _handleSetDash(); +/*Ai88*/ // void _handleGsaveIncludeDocument(); +/*Ai88*/ // void _handleSetStrokeColorCMYK(); +/*Ai88*/ // void _handleSetFillColorCMYK(); +/*Ai88*/ // void _handleSetStrokeColorGray(); +/*Ai88*/ // void _handleSetFillColorGray(); +/*Ai88*/ // void _handleSetStrokeColorCustom(); +/*Ai88*/ // void _handleSetFillColorCustom(); +/*Ai88*/ // void _handleSetFillPattern(); +/*Ai88*/ // void _handleSetStrokePattern(); + +/*Ai88*/ // void _handlePatternDefinition(); +/*Ai88*/ // void _handleFontEncoding(); + + void _handlePSGet(); + void _handlePSExec(); + void _handlePSDef(); + void _handlePSString(); + void _handlePSBind(); + void _handlePSUserdict(); + void _handlePSDict(); + void _handlePSDup(); + void _handlePSBegin(); + void _handlePSPut(); + + void _handleDocumentFonts(const char *data); + void _handleDocumentFiles(const char *data); + void _handleDocumentCustomColors(const char *data); + void _handleCMYKCustomColor(const char *data); + void _handleDocumentProcessColors(const char *data); + void _handleDocumentNeededResources(const char *data); + void _handleIncludeResource(const char *data); + +/*Ai88*/ // void _handleSetCurrentText(); +/*Ai88*/ // void _handleTextBlock (TextOperation to); +/*Ai88*/ // void _handleTextOutput (); + + void _handleCreationDate (const char *data); + + AIOperation getAIOperation (const char *operand); + PSOperation getPSOperation (const char *operand); + CommentOperation getCommentOperation (const char *command); + + bool handlePS (const char *operand); + + const char *getValue (const char *input); + bool getRectangle (const char* input, int &llx, int &lly, int &urx, int &ury); + bool getPoint (const char* input, int &x, int &y); +protected: + void gotComment (const char *value); + void gotIntValue (int value); + void gotDoubleValue (double value); + void gotStringValue (const char *value); + void gotToken (const char *value); + void gotReference (const char *value); + void gotBlockStart (); + void gotBlockEnd (); + void gotArrayStart (); + void gotArrayEnd (); + void gotByte (uchar value); + void gotByteArray (const QByteArray &data); + + GStateHandlerBase *m_gstateHandler; + StructureHandlerBase *m_structureHandler; + PathHandlerBase *m_pathHandler; + MiscGStateHandlerBase *m_miscGStateHandler; + DocumentHandlerBase *m_documentHandler; + ModuleHandlerBase *m_moduleHandler; + EmbeddedHandlerBase *m_embeddedHandler; + TextHandlerBase *m_textHandler; + AI88Handler *m_ai88Handler; + AI3Handler *m_ai3Handler; + +private: + void handleElement (AIElement &element); + void cleanupArrays(); +public: + AIParserBase(); + ~AIParserBase(); + + bool parse (QIODevice& fin); +}; + +const void aiotoa (AIOperation &data); +const void sttoa (SectionType &data, bool begin); + +class GStateHandlerBase +{ + public: + GStateHandlerBase() {} + virtual ~GStateHandlerBase() {} + + virtual void gotFillColor (AIColor &) {} + virtual void gotStrokeColor (AIColor &) {} + virtual void gotFillPattern (const char *pname, double px, double py, double sx, double sy, double angle, double rf, double r, double k, double ka, const QValueVector<AIElement>& transformData); + virtual void gotStrokePattern (const char *pname, double px, double py, double sx, double sy, double angle, double rf, double r, double k, double ka, const QValueVector<AIElement>& transformData); + virtual void gotFlatness (double) {} + virtual void gotLineWidth (double) {} + virtual void gotLineCaps (int) {} + virtual void gotLineJoin (int) {} + virtual void gotMiterLimit (double) {} + virtual void gotWindingOrder (int) {} + virtual void gotDash (const QValueVector<AIElement>& /*dashData*/, double /*phase*/) {} +}; + +class StructureHandlerBase { + public: + StructureHandlerBase() {} + virtual ~StructureHandlerBase() {} + + virtual void gotBeginGroup (bool /*clipping*/) {} + virtual void gotEndGroup (bool /*clipping*/) {} + virtual void gotBeginCombination () {} + virtual void gotEndCombination () {} +}; + +class PathHandlerBase { + public: + PathHandlerBase() {} + virtual ~PathHandlerBase() {} + + virtual void gotPathElement (PathElement &) {} + virtual void gotFillPath (bool /*closed*/, bool /*reset*/) {} + virtual void gotStrokePath (bool /*closed*/) {} + virtual void gotIgnorePath (bool /*closed*/, bool /*reset*/) {} + virtual void gotClipPath (bool /*closed*/) {} + virtual void gotFillMode (FillMode) {} +}; + +class MiscGStateHandlerBase { + public: + MiscGStateHandlerBase() {} + virtual ~MiscGStateHandlerBase() {} + + virtual void gotLockNextObject (bool /*value*/) {} + virtual void gotFillOverprinting (bool /*value*/) {} + virtual void gotStrokeOverprinting (bool /*value*/) {} +}; + +class DocumentHandlerBase { + public: + DocumentHandlerBase() {} + virtual ~DocumentHandlerBase() {} + + virtual void gotBoundingBox (int /*llx*/, int /*lly*/, int /*urx*/, int /*ury*/) {} + virtual void gotTemplateBox (int /*llx*/, int /*lly*/, int /*urx*/, int /*ury*/) {} + virtual void gotMargin (int /*llx*/, int /*lly*/, int /*urx*/, int /*ury*/) {} + virtual void gotPrinterRect (int /*llx*/, int /*lly*/, int /*urx*/, int /*ury*/) {} + virtual void gotPrinterName (const char *) {} + virtual void gotPageOrigin (int /*x*/, int /*y*/) {} + virtual void gotTemplate (const char *) {} + virtual void gotTitle (const char *) {} + virtual void gotCreator (const char *) {} + virtual void gotPatternDefinition (const char */*name*/, const QValueVector<AIElement>& /*layerData*/, double /*llx*/, double /*lly*/, double /*urx*/, double /*ury*/) {} + virtual void gotCreationDate (const char */*val1*/,const char */*val2*/) {} + virtual void gotProcessColors (int /*colors*/) {} +}; + +class ModuleHandlerBase { + public: + ModuleHandlerBase() {} + virtual ~ModuleHandlerBase() {} + + virtual void gotBeginSection (SectionType, const char *) {} + virtual void gotEndSection (SectionType, const char *) {} +}; + +class EmbeddedHandlerBase { + public: + EmbeddedHandlerBase() {} + virtual ~EmbeddedHandlerBase() {} + + virtual void gotGsaveIncludeDocument (const QValueVector<AIElement>& /*transData*/, int /*llx*/, int /*lly*/, int /*urx*/, int /*ury*/, const char*/*fileName*/) {} + virtual void gotGrestore () {} +}; + +class TextHandlerBase { + public: + TextHandlerBase() {} + virtual ~TextHandlerBase() {} + + virtual void gotFontEncoding (const QValueVector<AIElement>& encodingData, const char*oldFontName, const char*newFontName); + virtual void gotFontDefinition (const char*fontName, double size, double leading, double kerning, TextAlign align); + virtual void gotTextBlockBegin (const QValueVector<AIElement>& transData, TextOperation mode); + virtual void gotTextOutput (const char*text, int length=-1); + virtual void gotTextBlockEnd (); +}; + +#endif + diff --git a/filters/karbon/ai/karbon_ai_import.desktop b/filters/karbon/ai/karbon_ai_import.desktop new file mode 100644 index 00000000..bec797b2 --- /dev/null +++ b/filters/karbon/ai/karbon_ai_import.desktop @@ -0,0 +1,67 @@ +[Desktop Entry] +Type=Service +Name=Karbon14 Illustrator Import Filter +Name[af]=Karbon14 Illustreerder In voer Filter +Name[ar]=مِرْشَح استيراد Illustrator لدى Karbon14 +Name[bg]=Филтър за импортиране от Illustrator в Karbon14 +Name[br]=Sil enporzh Illustrator evit Karbon14 +Name[ca]=Filtre d'importació Illustrator per a Karbon14 +Name[cs]=Importní filtr souborů aplikace Illustrator pro Karbon14 +Name[cy]=Hidlen Fewnforio Illustrator Karbon14 +Name[da]=Karbon14 Illustrator-importfilter +Name[de]=Karbon14 Illustrator-Importfilter +Name[el]=Φίλτρο εισαγωγής Illustrator του Karbon14 +Name[eo]=Importfiltrilo por Karbon-Ilustrilo +Name[es]=Filtro de importación Karbon14 Illustrator +Name[et]=Karbon14 Illustrator'i impordifilter +Name[eu]=Karbon14 ilustratzailearen inportaziorako iragazkia +Name[fa]=پالایۀ واردات تصویرگر Karbon14 +Name[fi]=Karbon14 Illustrator -tuontisuodin +Name[fr]=Filtre d'importation Illustrator vers Karbon 14 +Name[fy]=Illustrator-Ymportfilter foar Karbon14 +Name[ga]=Scagaire Iompórtála Karbon14 Illustrator +Name[gl]=Filtro de Importación de Illustrator para Karbon14 +Name[he]=מסנן ייבוא מ־Illustrator ל־Karbon14 +Name[hi]=कार्बन 14 इलस्ट्रेटर आयात छननी +Name[hr]=Karbon14 Illustrator filtar uvoza +Name[hu]=Karbon14 Illustrator importszűrő +Name[is]=Karbon14 Illustrator innflutningssía +Name[it]=Filtro di importazione Illustrator per Karbon14 +Name[ja]=Karbon14 Illustrator インポートフィルタ +Name[km]=តម្រងនាំចូលវិចិត្រសាលសម្រាប់ Karbon ១៤ +Name[lo]=ຕົວຕອງການນຳເຂົ້າ Illustrator +Name[lt]=Karbon14 Illustrator importavimo filtras +Name[lv]=Karbon14 Ilustratora importa filtrs +Name[ms]=Penapis Import Karbon14 Illustrator +Name[mt]=Filtru għall-importazzjoni Illustrator għal Karbon14 +Name[nb]=Illustrator-importfilter for Karbon14 +Name[nds]=Illustrator-Importfilter för Karbon14 +Name[ne]=कार्बन१४ ब्याख्याकर्ता आयात फिल्टर +Name[nl]=Illustrator-importfilter voor Karbon14 +Name[nn]=Illustrator-importfilter for Karbon14 +Name[pl]=Filtr importu formatu Illustrator do Karbon14 +Name[pt]=Filtro de Importação de Illustrator para o Karbon14 +Name[pt_BR]=Filtro de Importação Illustrator do Karbon14 +Name[ro]=Filtru importare Karbon14 pentru Illustrator +Name[ru]=Фильтр импорта файлов Illustrator в Karbon14 +Name[se]=Karbon14:a Illustrator-sisafievrridansilli +Name[sk]=Illustrator filter pre import do Karbon14 +Name[sl]=Uvozni filter Illustrator za Karbon14 +Name[sr]=Karbon14-ов филтер за увоз из Illustrator-а +Name[sr@Latn]=Karbon14-ov filter za uvoz iz Illustrator-a +Name[sv]=Karbon14 Illustrator-importfilter +Name[ta]=Karbon 14 Illustrator இறக்குமதி வடிகட்டி +Name[tg]=Karbon14 EPS Филтри Воридоти Иллюстратор +Name[th]=ตัวกรองการนำเข้า Illustrator ของคาร์บอน14 +Name[tr]=Karbon14 Illustrator Alma Filtresi +Name[uk]=Фільтр імпорту Illustrator для Karbon14 +Name[uz]=Karbon14 Illustrator import filteri +Name[uz@cyrillic]=Karbon14 Illustrator импорт филтери +Name[xh]=Isihluzi Sokurhweba Somzobi we Karbon 14 +Name[zh_CN]=Karbon14 Illustrator 导入过滤器 +Name[zh_TW]=Karbon14 Illustrator 匯入過濾程式 +X-KDE-Export=application/x-karbon +X-KDE-Import=application/illustrator +X-KDE-Weight=1 +X-KDE-Library=libkarbonaiimport +ServiceTypes=KOfficeFilter diff --git a/filters/karbon/ai/karbonaiparserbase.cc b/filters/karbon/ai/karbonaiparserbase.cc new file mode 100644 index 00000000..8c2b5a5f --- /dev/null +++ b/filters/karbon/ai/karbonaiparserbase.cc @@ -0,0 +1,637 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schönberger <dirk.schoenberger@sz-online.de> + + 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 <core/vcolor.h> +#include <core/vlayer.h> +#include <core/vgroup.h> +#include <core/vclipgroup.h> +#include <core/vvisitor.h> +#include "aicolor.h" +#include <qwmatrix.h> +#include <commands/vtransformcmd.h> + +#include <KoPageLayout.h> + +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(){ +// qDebug ( getHeader().latin1() ); +} + +// generic +void KarbonAIParserBase::parsingFinished(){ +// qDebug ( 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()); + +/* QWMatrix 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 +QString KarbonAIParserBase::getParamList(Parameters& params){ + QString 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){ + qDebug ("<%s%s>", tagName, getParamList (params).latin1() ); +} + +// generic +void KarbonAIParserBase::gotEndTag (const char *tagName){ + qDebug ("</%s>", tagName ); +} + +// generic +void KarbonAIParserBase::gotSimpleTag (const char *tagName, Parameters& params){ + qDebug ("<%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*/){ +// qDebug ("found fill path"); +// if (!reset) qDebug ("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){ +// qDebug ("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) { +// qDebug ("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); +// qDebug ("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); +// qDebug ("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) +{ +// qDebug ("start begin group"); + if (clipping) + { + VClipGroup *group = new VClipGroup( 0L ); + m_groupStack.push (group); + } + else + { + VGroup *group = new VGroup( 0L ); + m_groupStack.push (group); + } + +// qDebug ("end begin group"); + +} + +void KarbonAIParserBase::gotEndGroup (bool /*clipping*/) +{ +// qDebug ("start end group"); + + if (m_debug) qDebug ("got end group"); + + if (m_groupStack.isEmpty()) return; + + if (m_debug) qDebug ("got end group 2"); + + VGroup *group = m_groupStack.pop(); + + if (m_debug) qDebug ("got end group 3"); + + if (m_debug) + { + if (!group) qDebug ("group is NULL"); + } + + if (m_groupStack.isEmpty()) + { + if (m_debug) qDebug ("insert object"); + ensureLayer(); + m_layer->append (group); + if (m_debug) qDebug ("/insert object"); + } + else + { + if (m_debug) qDebug ("insert object to group"); + + m_groupStack.top()->append (group); + if (m_debug) qDebug ("/insert object to group"); + } + + if (m_debug) qDebug ("/got end group"); + +// qDebug ("end end group"); +} + +void KarbonAIParserBase::gotBeginCombination () { + m_ptt = PTT_Combine; +} + +void KarbonAIParserBase::gotEndCombination () { +// qDebug ( "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); */ +// qDebug ("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); */ +// qDebug ("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 (QIODevice& fin, QDomDocument &doc) +{ + + bool res = AIParserBase::parse (fin); + +// qDebug ("document is %s",doc.toString().latin1()); + if (res) + { + qDebug ("before save document"); + doc = m_document->saveXML(); + // add paper info, we always need custom for svg (Rob) + QDomElement 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() ); + + qDebug ("after save document"); + } + else + { + QDomDocument tempDoc; + doc = tempDoc; + } + + return res; +} + +void KarbonAIParserBase::ensureLayer () +{ + if (!m_layer) + { + m_layer = new VLayer( 0 ); + m_document->insertLayer (m_layer); + } +} + + +void KarbonAIParserBase::setupHandlers() +{ +// qDebug("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() +{ +// qDebug("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*/) +{ +// qDebug ("got creation date [%s], [%s]",val1,val2); +} + +void KarbonDocumentHandler::gotProcessColors (int /*colors*/) +{ +/* if (colors && PC_Cyan) qDebug ("contains cyan"); + if (colors && PC_Magenta) qDebug ("contains magenta"); + if (colors && PC_Yellow) qDebug ("contains yellow"); + if (colors && PC_Black) qDebug ("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 : qDebug ("filled"); break; + case POT_Stroked : qDebug ("stroked"); break; + case POT_FilledStroked : qDebug ("filled/stroked"); break; + case POT_Clip : qDebug ("clip"); break; + case POT_Ignore : qDebug ("ignore"); break; + case POT_Leave : qDebug ("leave"); break; + default : qDebug ("unknown"); + } +} + diff --git a/filters/karbon/ai/karbonaiparserbase.h b/filters/karbon/ai/karbonaiparserbase.h new file mode 100644 index 00000000..4b6f05a9 --- /dev/null +++ b/filters/karbon/ai/karbonaiparserbase.h @@ -0,0 +1,202 @@ +/* This file is part of the KDE project + Copyright (C) 2002, Dirk Schnberger <dirk.schoenberger@sz-online.de> + + 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. +*/ + +#ifndef KARBONAIPARSERBASE_H +#define KARBONAIPARSERBASE_H + +#include <aiparserbase.h> +#include <qptrlist.h> +#include <qstring.h> +#include <qpair.h> + +#include "aicolor.h" + +#include <KoPoint.h> +#include <core/vcomposite.h> +#include <core/vdocument.h> +#include <core/vlayer.h> +#include <core/vgroup.h> +#include <core/vfill.h> +#include <core/vstroke.h> +#include <qdom.h> + +#include <qptrstack.h> + +/** + *@author + */ +typedef QPair<QString,QString> Parameter; +typedef QPtrList<Parameter> Parameters; +typedef QPtrList<PathElement> PathElements; + +typedef enum { POT_Filled = 1, POT_Stroked = 2, POT_FilledStroked = 3, POT_Clip = 4, POT_Ignore = 8, POT_Leave = -1, POT_Other = 0 } PathOutputType; +typedef enum { PTT_Output = 1, PTT_Combine = 2 } PathTransferType; + +// typedef struct { int llx, lly, urx, ury; } BoundingBox; + +class KarbonAIParserBase; +class KarbonGStateHandler; +class KarbonStructureHandler; +class KarbonPathHandler; +class KarbonDocumentHandler; + +class KarbonDocumentHandler : public DocumentHandlerBase +{ + private: + KarbonAIParserBase *delegate; + public: + KarbonDocumentHandler (KarbonAIParserBase *delegate) : DocumentHandlerBase () { this->delegate = delegate; } + + void gotBoundingBox (int llx, int lly, int urx, int ury); + void gotCreationDate (const char *val1,const char *val2); + void gotProcessColors (int colors); +}; + +class KarbonGStateHandler : public GStateHandlerBase +{ + private: + KarbonAIParserBase *delegate; + public: + KarbonGStateHandler (KarbonAIParserBase *delegate) : GStateHandlerBase() { this->delegate = delegate; } + + void gotFillColor (AIColor &color); + void gotStrokeColor (AIColor &color); + + void gotFlatness (double val); + void gotLineWidth (double val); + void gotLineCaps (int val); + void gotLineJoin (int val); + void gotMiterLimit (double val); + void gotWindingOrder (int val); + +}; + +class KarbonStructureHandler : public StructureHandlerBase +{ + private: + KarbonAIParserBase *delegate; + public: + KarbonStructureHandler (KarbonAIParserBase *delegate) : StructureHandlerBase() { this->delegate = delegate; } + + void gotBeginGroup (bool clipping); + void gotEndGroup (bool clipping); + void gotBeginCombination (); + void gotEndCombination (); + +}; + +class KarbonPathHandler : public PathHandlerBase +{ + private: + KarbonAIParserBase *delegate; + FillMode m_fm; + public: + KarbonPathHandler (KarbonAIParserBase *delegate) : PathHandlerBase () + { + m_fm = FM_EvenOdd; + this->delegate = delegate; + } + + void gotPathElement (PathElement &element); + void gotFillPath (bool closed, bool reset); + void gotStrokePath (bool closed); + void gotIgnorePath (bool closed, bool reset); + void gotClipPath (bool closed); + void gotFillMode (FillMode fm); + +}; + +class KarbonAIParserBase : public AIParserBase { + friend class KarbonDocumentHandler; + friend class KarbonGStateHandler; + friend class KarbonStructureHandler; + friend class KarbonPathHandler; + +public: + KarbonAIParserBase(); + ~KarbonAIParserBase(); + + bool parse (QIODevice& fin, QDomDocument &doc); +private: + VPath *m_curKarbonPath; + VDocument *m_document; + VLayer *m_layer; + VPath *m_combination; + QPtrStack<VGroup> m_groupStack; + + FillMode m_fm; + PathOutputType m_pot; + PathTransferType m_ptt; + +// BoundingBox m_bbox; + KoRect m_bbox; + VFill m_fill; + VStroke m_stroke; +/** AIColor m_strokeColor; + AIColor m_fillColor; + double m_lineWidth; + double m_flatness; + int m_lineCaps; + int m_lineJoin; + double m_miterLimit; */ + int m_windingOrder; + + void doOutputCurrentPath2(PathOutputType type); + const VColor toKarbonColor (const AIColor &color); + void ensureLayer (); + + VFill m_emptyFill; + VStroke m_emptyStroke; + +protected: + void setupHandlers(); + void teardownHandlers(); + + void parsingStarted(); + void parsingFinished(); + + QString getParamList(Parameters& params); + + void gotPathElement (PathElement &element); + void gotFillPath (bool closed, bool reset, FillMode fm = FM_NonZero); + void gotStrokePath (bool closed); + void gotIgnorePath (bool closed, bool reset); + void gotClipPath (bool closed); + + void gotFillColor (AIColor &color); + void gotStrokeColor (AIColor &color); + void gotBoundingBox (int llx, int lly, int urx, int ury); + + void gotFlatness (double val); + void gotLineWidth (double val); + void gotLineCaps (int val); + void gotLineJoin (int val); + void gotMiterLimit (double val); + void gotWindingOrder (int val); + void gotBeginGroup (bool clipping); + void gotEndGroup (bool clipping); + void gotBeginCombination (); + void gotEndCombination (); + + virtual void gotStartTag (const char *tagName, Parameters& params); + virtual void gotEndTag (const char *tagName); + virtual void gotSimpleTag (const char *tagName, Parameters& params); +}; + +#endif |