Back to index

scribus-ng  1.3.4.dfsg+svn20071115
svgplugin.h
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #ifndef SVGPLUG_H
00008 #define SVGPLUG_H
00009 
00010 #include <qdom.h>
00011 #include <qptrstack.h>
00012 #include <qsize.h>
00013 #include "pluginapi.h"
00014 #include "loadsaveplugin.h"
00015 #include "../formatidlist.h"
00016 #include "vgradient.h"
00017 
00018 class ScrAction;
00019 class ScribusMainWindow;
00020 
00024 class PLUGIN_API SVGImportPlugin : public LoadSavePlugin
00025 {
00026        Q_OBJECT
00027 
00028        public:
00029               // Standard plugin implementation
00030               SVGImportPlugin();
00031               virtual ~SVGImportPlugin();
00032               virtual const QString fullTrName() const;
00033               virtual const AboutData* getAboutData() const;
00034               virtual void deleteAboutData(const AboutData* about) const;
00035               virtual void languageChange();
00036               virtual bool fileSupported(QIODevice* file, const QString & fileName=QString::null) const;
00037               virtual bool loadFile(const QString & fileName, const FileFormat & fmt, int flags, int index = 0);
00038               virtual void addToMainWindowMenu(ScribusMainWindow *);
00039 
00040        public slots:
00047               virtual bool import(QString filename = QString::null, int flags = lfUseCurrentPage|lfInteractive);
00048 
00049        private:
00050               void registerFormats();
00051               ScrAction* importAction;
00052 
00053 };
00054 
00055 extern "C" PLUGIN_API int svgimplugin_getPluginAPIVersion();
00056 extern "C" PLUGIN_API ScPlugin* svgimplugin_getPlugin();
00057 extern "C" PLUGIN_API void svgimplugin_freePlugin(ScPlugin* plugin);
00058 
00059 class PageItem;
00060 class ScribusDoc;
00061 class PrefsManager;
00062 class FPointArray;
00063 
00064 class GradientHelper
00065 {
00066 public:
00067        GradientHelper() :
00068               CSpace(false),
00069               cspaceValid(true),
00070               gradient(VGradient::linear),
00071               gradientValid(false),
00072               matrix(),
00073               matrixValid(false),
00074               reference(""),
00075               Type(1),
00076               typeValid(false),
00077               X1(0),
00078               x1Valid(true),
00079               X2(1),
00080               x2Valid(true),
00081               Y1(0),
00082               y1Valid(true),
00083               Y2(0),
00084               y2Valid(true)
00085               {
00086               }
00087        bool CSpace;
00088        bool cspaceValid;
00089        VGradient gradient;
00090        bool gradientValid;
00091        QWMatrix matrix;
00092        bool matrixValid;
00093        QString reference;
00094        int Type;
00095        bool typeValid;
00096        double X1;
00097        bool x1Valid;
00098        double X2;
00099        bool x2Valid;
00100        double Y1;
00101        bool y1Valid;
00102        double Y2;
00103        bool y2Valid;
00104        };
00105 
00106 class SvgStyle
00107 {
00108 public:
00109        SvgStyle() :
00110               Display(true),
00111               CSpace(false),
00112               CurCol("None"),
00113               dashOffset(0),
00114               Family(""),
00115               FillCol("Black"),
00116               FontSize(12),
00117               GCol1("Black"),
00118               GCol2("Black"),
00119               GradCo(VGradient::linear),
00120               Gradient(0),
00121               GX1(0),
00122               GX2(0),
00123               GY1(0),
00124               GY2(0),
00125               InherCol(false),
00126               LWidth(1.0),
00127               matrix(),
00128               matrixg(),
00129               PLineArt(Qt::SolidLine),
00130               PLineEnd(Qt::FlatCap),
00131               PLineJoin(Qt::MiterJoin),
00132               StrokeCol("None"),
00133               Opacity(1.0),
00134               FillOpacity(1.0),
00135               StrokeOpacity(1.0),
00136               textAnchor("start")
00137               {
00138               }
00139        bool Display;
00140        bool CSpace;
00141        QString CurCol;
00142        QValueList<double> dashArray;
00143        double dashOffset;
00144        QString Family;
00145        QString FillCol;
00146        QString fillRule;
00147        int FontSize;
00148        QString GCol1;
00149        QString GCol2;
00150        VGradient     GradCo;
00151        int Gradient;
00152        double GX1;
00153        double GX2;
00154        double GY1;
00155        double GY2;
00156        bool InherCol;
00157        double LWidth;
00158        QWMatrix matrix;
00159        QWMatrix matrixg;
00160        Qt::PenStyle PLineArt;
00161        Qt::PenCapStyle PLineEnd;
00162        Qt::PenJoinStyle PLineJoin;
00163        QString StrokeCol;
00164        double Opacity;
00165        double FillOpacity;
00166        double StrokeOpacity;
00167        QString textAnchor;
00168 };
00169 
00170 class SVGPlug : public QObject
00171 {
00172        Q_OBJECT
00173 
00174 public:
00181        SVGPlug(ScribusMainWindow *mw, int flags);
00182        ~SVGPlug();
00183        bool import(QString fname, int flags);
00184        bool loadData(QString fname);
00185        void convert(int flags);
00186        void addGraphicContext();
00187        void setupNode( const QDomElement &e );
00188        void setupTransform( const QDomElement &e );
00189        void finishNode( const QDomElement &e, PageItem* item);
00190        bool isIgnorableNode( const QDomElement &e );
00191        FPoint parseTextPosition(const QDomElement &e);
00192        QSize  parseWidthHeight(const QDomElement &e);
00193        QRect  parseViewBox(const QDomElement &e);
00194        void parseDefs(const QDomElement &e);
00195        void parseClipPath(const QDomElement &e);
00196        void parseClipPathAttr(const QDomElement &e, FPointArray& clipPath);
00197        QPtrList<PageItem> parseGroup(const QDomElement &e);
00198        QPtrList<PageItem> parseElement(const QDomElement &e);
00199        QPtrList<PageItem> parseCircle(const QDomElement &e);
00200        QPtrList<PageItem> parseEllipse(const QDomElement &e);
00201        QPtrList<PageItem> parseImage(const QDomElement &e);
00202        QPtrList<PageItem> parseLine(const QDomElement &e);
00203        QPtrList<PageItem> parsePath(const QDomElement &e);
00204        QPtrList<PageItem> parsePolyline(const QDomElement &e);
00205        QPtrList<PageItem> parseRect(const QDomElement &e);
00206        QPtrList<PageItem> parseText(const QDomElement &e);
00207        QPtrList<PageItem> parseTextElement(double x, double y, const QDomElement &e);
00208        QPtrList<PageItem> parseSwitch(const QDomElement &e);
00209        QPtrList<PageItem> parseSymbol(const QDomElement &e);
00210        QPtrList<PageItem> parseUse(const QDomElement &e);
00211        QDomElement getNodeFromUseElement(const QDomElement &e);
00212        QDomElement getReferencedNode(const QDomElement &e);
00213        double fromPercentage( const QString &s );
00214        double parseUnit(const QString &unit);
00215        QWMatrix parseTransform(const QString &transform);
00216        const char * getCoord( const char *ptr, double &number );
00217        bool parseSVG( const QString &s, FPointArray *ite );
00218        void calculateArc(FPointArray *ite, bool relative, double &curx, double &cury, double angle, double x, double y, double r1, double r2, bool largeArcFlag, bool sweepFlag);
00219        void svgClosePath(FPointArray *i);
00220        void svgMoveTo(double x1, double y1);
00221        void svgLineTo(FPointArray *i, double x1, double y1);
00222        void svgCurveToCubic(FPointArray *i, double x1, double y1, double x2, double y2, double x3, double y3);
00223        QColor parseColorN( const QString &rgbColor );
00224        QString parseColor( const QString &s );
00225        void parsePA( SvgStyle *obj, const QString &command, const QString &params );
00226        void parseStyle( SvgStyle *obj, const QDomElement &e );
00227        void parseColorStops(GradientHelper *gradient, const QDomElement &e);
00228        void parseGradient( const QDomElement &e );
00229        FPoint GetMaxClipO(FPointArray Clip);
00230        FPoint GetMinClipO(FPointArray Clip);
00231        QDomDocument inpdoc;
00232        QString docDesc;
00233        QString docTitle;
00234        int groupLevel;
00235        QPtrStack<SvgStyle>  m_gc;
00236        QMap<QString, GradientHelper>      m_gradients;
00237        QMap<QString, QDomElement>         m_nodeMap;
00238        QMap<QString, FPointArray>         m_clipPaths;
00239        bool PathClosed;
00240        double viewTransformX;
00241        double viewTransformY;
00242        double viewScaleX;
00243        double viewScaleY;
00244        bool interactive;
00246        bool unsupported;
00247        bool importFailed;
00248        bool importCanceled;
00249        ScribusDoc* m_Doc;
00250        Selection* tmpSel;
00251        QStringList importedColors;
00252 };
00253 
00254 #endif