Rev 21615 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
68 | Franz | 7 | #ifndef SVGPLUG_H |
8 | #define SVGPLUG_H |
||
9 | |||
10223 | cbradney | 10 | #include <QDomElement> |
10638 | jghali | 11 | #include <QFont> |
12 | #include <QList> |
||
20006 | jghali | 13 | #include <QRectF> |
14 | #include <QSizeF> |
||
9922 | fschmid | 15 | #include <QStack> |
2986 | craig | 16 | #include "pluginapi.h" |
3487 | craig | 17 | #include "loadsaveplugin.h" |
14920 | fschmid | 18 | #include "../../formatidlist.h" |
68 | Franz | 19 | #include "vgradient.h" |
20 | |||
3696 | craig | 21 | class ScrAction; |
5243 | cbradney | 22 | class ScribusMainWindow; |
13371 | jghali | 23 | class TransactionSettings; |
3696 | craig | 24 | |
4024 | craig | 25 | /** |
4645 | subik | 26 | * \brief A class providing the plugin interface implementation for this plugin |
4024 | craig | 27 | */ |
3487 | craig | 28 | class PLUGIN_API SVGImportPlugin : public LoadSavePlugin |
3207 | craig | 29 | { |
30 | Q_OBJECT |
||
68 | Franz | 31 | |
3207 | craig | 32 | public: |
33 | // Standard plugin implementation |
||
34 | SVGImportPlugin(); |
||
35 | virtual ~SVGImportPlugin(); |
||
36 | virtual const QString fullTrName() const; |
||
37 | virtual const AboutData* getAboutData() const; |
||
38 | virtual void deleteAboutData(const AboutData* about) const; |
||
39 | virtual void languageChange(); |
||
5642 | cbradney | 40 | virtual bool fileSupported(QIODevice* file, const QString & fileName=QString::null) const; |
5539 | mrdocs | 41 | virtual bool loadFile(const QString & fileName, const FileFormat & fmt, int flags, int index = 0); |
12110 | fschmid | 42 | virtual void addToMainWindowMenu(ScribusMainWindow *) {}; |
1208 | cbradney | 43 | |
3696 | craig | 44 | public slots: |
4645 | subik | 45 | /*! |
46 | \author Franz Schmid |
||
47 | \brief Run the SVG import |
||
48 | \param filename a file name to import |
||
49 | \retval true for success |
||
50 | */ |
||
5539 | mrdocs | 51 | virtual bool import(QString filename = QString::null, int flags = lfUseCurrentPage|lfInteractive); |
3686 | craig | 52 | |
53 | private: |
||
54 | void registerFormats(); |
||
3696 | craig | 55 | ScrAction* importAction; |
3686 | craig | 56 | |
3207 | craig | 57 | }; |
58 | |||
59 | extern "C" PLUGIN_API int svgimplugin_getPluginAPIVersion(); |
||
60 | extern "C" PLUGIN_API ScPlugin* svgimplugin_getPlugin(); |
||
61 | extern "C" PLUGIN_API void svgimplugin_freePlugin(ScPlugin* plugin); |
||
62 | |||
63 | class PageItem; |
||
64 | class ScribusDoc; |
||
3210 | craig | 65 | class PrefsManager; |
66 | class FPointArray; |
||
3207 | craig | 67 | |
68 | Franz | 68 | class GradientHelper |
69 | { |
||
70 | public: |
||
4024 | craig | 71 | GradientHelper() : |
72 | CSpace(false), |
||
73 | cspaceValid(true), |
||
74 | gradient(VGradient::linear), |
||
75 | gradientValid(false), |
||
76 | matrix(), |
||
77 | matrixValid(false), |
||
78 | reference(""), |
||
79 | Type(1), |
||
80 | typeValid(false), |
||
81 | X1(0), |
||
82 | x1Valid(true), |
||
83 | X2(1), |
||
84 | x2Valid(true), |
||
85 | Y1(0), |
||
86 | y1Valid(true), |
||
87 | Y2(0), |
||
88 | y2Valid(true) |
||
68 | Franz | 89 | { |
90 | } |
||
4024 | craig | 91 | bool CSpace; |
92 | bool cspaceValid; |
||
93 | VGradient gradient; |
||
94 | bool gradientValid; |
||
8501 | cbradney | 95 | QMatrix matrix; |
4024 | craig | 96 | bool matrixValid; |
97 | QString reference; |
||
68 | Franz | 98 | int Type; |
943 | fschmid | 99 | bool typeValid; |
292 | Franz | 100 | double X1; |
943 | fschmid | 101 | bool x1Valid; |
4024 | craig | 102 | double X2; |
103 | bool x2Valid; |
||
292 | Franz | 104 | double Y1; |
943 | fschmid | 105 | bool y1Valid; |
292 | Franz | 106 | double Y2; |
943 | fschmid | 107 | bool y2Valid; |
68 | Franz | 108 | }; |
109 | |||
110 | class SvgStyle |
||
111 | { |
||
112 | public: |
||
4024 | craig | 113 | SvgStyle() : |
6356 | jghali | 114 | Display(true), |
4024 | craig | 115 | CSpace(false), |
22735 | jghali | 116 | CurCol("Black"), |
4024 | craig | 117 | dashOffset(0), |
10638 | jghali | 118 | FontFamily(""), |
119 | FontStyle("normal"), |
||
120 | FontWeight("normal"), |
||
121 | FontStretch("normal"), |
||
122 | FontSize(12), |
||
4024 | craig | 123 | FillCol("Black"), |
12802 | fschmid | 124 | fillRule("nonzero"), |
4024 | craig | 125 | GCol1("Black"), |
126 | GCol2("Black"), |
||
127 | GradCo(VGradient::linear), |
||
128 | Gradient(0), |
||
129 | GX1(0), |
||
130 | GX2(0), |
||
131 | GY1(0), |
||
132 | GY2(0), |
||
133 | InherCol(false), |
||
134 | LWidth(1.0), |
||
135 | matrix(), |
||
136 | matrixg(), |
||
137 | PLineArt(Qt::SolidLine), |
||
138 | PLineEnd(Qt::FlatCap), |
||
139 | PLineJoin(Qt::MiterJoin), |
||
140 | StrokeCol("None"), |
||
6136 | jghali | 141 | Opacity(1.0), |
142 | FillOpacity(1.0), |
||
6575 | jghali | 143 | StrokeOpacity(1.0), |
12802 | fschmid | 144 | textAnchor("start"), |
145 | clipPath() |
||
68 | Franz | 146 | { |
147 | } |
||
6356 | jghali | 148 | bool Display; |
4024 | craig | 149 | bool CSpace; |
150 | QString CurCol; |
||
12055 | jghali | 151 | QVector<double> dashArray; |
4024 | craig | 152 | double dashOffset; |
10638 | jghali | 153 | QString FontFamily; |
154 | QString FontStyle; |
||
155 | QString FontWeight; |
||
156 | QString FontStretch; |
||
17435 | jghali | 157 | double FontSize; |
68 | Franz | 158 | QString FillCol; |
4926 | avox | 159 | QString fillRule; |
68 | Franz | 160 | QString GCol1; |
161 | QString GCol2; |
||
4024 | craig | 162 | VGradient GradCo; |
163 | int Gradient; |
||
292 | Franz | 164 | double GX1; |
4024 | craig | 165 | double GX2; |
292 | Franz | 166 | double GY1; |
167 | double GY2; |
||
4024 | craig | 168 | bool InherCol; |
169 | double LWidth; |
||
8501 | cbradney | 170 | QMatrix matrix; |
171 | QMatrix matrixg; |
||
4024 | craig | 172 | Qt::PenStyle PLineArt; |
173 | Qt::PenCapStyle PLineEnd; |
||
174 | Qt::PenJoinStyle PLineJoin; |
||
175 | QString StrokeCol; |
||
6127 | jghali | 176 | double Opacity; |
177 | double FillOpacity; |
||
178 | double StrokeOpacity; |
||
6575 | jghali | 179 | QString textAnchor; |
12887 | jghali | 180 | QString textDecoration; |
12802 | fschmid | 181 | FPointArray clipPath; |
20477 | jghali | 182 | QString filter; |
68 | Franz | 183 | }; |
184 | |||
185 | class SVGPlug : public QObject |
||
1552 | subik | 186 | { |
68 | Franz | 187 | Q_OBJECT |
188 | |||
189 | public: |
||
4645 | subik | 190 | /*! |
191 | \author Franz Schmid |
||
192 | \brief Create the SVG importer window |
||
193 | \param fName QString |
||
194 | \param isInteractive flag to use GUI |
||
195 | */ |
||
8043 | jghali | 196 | SVGPlug(ScribusMainWindow *mw, int flags); |
68 | Franz | 197 | ~SVGPlug(); |
13371 | jghali | 198 | bool import(QString fname, const TransactionSettings& trSettings, int flags); |
8043 | jghali | 199 | bool loadData(QString fname); |
13371 | jghali | 200 | void convert(const TransactionSettings& trSettings, int flags); |
68 | Franz | 201 | void addGraphicContext(); |
7612 | jghali | 202 | void setupNode( const QDomElement &e ); |
68 | Franz | 203 | void setupTransform( const QDomElement &e ); |
10785 | jghali | 204 | void finishNode( const QDomNode &e, PageItem* item); |
7605 | jghali | 205 | bool isIgnorableNode( const QDomElement &e ); |
10021 | jghali | 206 | bool isIgnorableNodeName( const QString &n ); |
12725 | jghali | 207 | FPoint parseTextPosition(const QDomElement &e, const FPoint* pos = NULL); |
20006 | jghali | 208 | QSizeF parseWidthHeight(const QDomElement &e); |
209 | QRectF parseViewBox(const QDomElement &e); |
||
7556 | jghali | 210 | void parseDefs(const QDomElement &e); |
7605 | jghali | 211 | void parseClipPath(const QDomElement &e); |
212 | void parseClipPathAttr(const QDomElement &e, FPointArray& clipPath); |
||
20477 | jghali | 213 | void parseFilterAttr(const QDomElement &e, PageItem* item); |
15171 | jghali | 214 | QList<PageItem*> parseA(const QDomElement &e); |
9856 | fschmid | 215 | QList<PageItem*> parseGroup(const QDomElement &e); |
216 | QList<PageItem*> parseElement(const QDomElement &e); |
||
217 | QList<PageItem*> parseCircle(const QDomElement &e); |
||
218 | QList<PageItem*> parseEllipse(const QDomElement &e); |
||
219 | QList<PageItem*> parseImage(const QDomElement &e); |
||
220 | QList<PageItem*> parseLine(const QDomElement &e); |
||
221 | QList<PageItem*> parsePath(const QDomElement &e); |
||
222 | QList<PageItem*> parsePolyline(const QDomElement &e); |
||
223 | QList<PageItem*> parseRect(const QDomElement &e); |
||
224 | QList<PageItem*> parseText(const QDomElement &e); |
||
12725 | jghali | 225 | QList<PageItem*> parseTextSpan(const QDomElement& e, FPoint& currentPos, double chunkW); |
226 | QList<PageItem*> parseTextNode(const QDomText& e, FPoint& currentPos, double chunkW); |
||
9856 | fschmid | 227 | QList<PageItem*> parseSwitch(const QDomElement &e); |
228 | QList<PageItem*> parseSymbol(const QDomElement &e); |
||
229 | QList<PageItem*> parseUse(const QDomElement &e); |
||
12725 | jghali | 230 | const char* getCoord( const char *ptr, double &number ); |
10638 | jghali | 231 | QFont getFontFromStyle(SvgStyle& style); |
8604 | jghali | 232 | QDomElement getReferencedNode(const QDomElement &e); |
12725 | jghali | 233 | bool getTextChunkWidth(const QDomElement &e, double& width); |
234 | double fromPercentage(const QString &s ); |
||
235 | double parseFontSize(const QString& fsize); |
||
236 | double parseUnit(const QString &unit); |
||
8501 | cbradney | 237 | QMatrix parseTransform(const QString &transform); |
12725 | jghali | 238 | bool parseSVG( const QString &s, FPointArray *ite ); |
10638 | jghali | 239 | QColor parseColorN( const QString &rgbColor ); |
68 | Franz | 240 | QString parseColor( const QString &s ); |
13391 | jghali | 241 | QString parseIccColor( const QString &s ); |
16887 | jghali | 242 | QString parseTagName( const QDomElement &e ); |
68 | Franz | 243 | void parsePA( SvgStyle *obj, const QString &command, const QString ¶ms ); |
244 | void parseStyle( SvgStyle *obj, const QDomElement &e ); |
||
245 | void parseColorStops(GradientHelper *gradient, const QDomElement &e); |
||
20477 | jghali | 246 | void parseFilter(const QDomElement &b); |
12737 | fschmid | 247 | void parsePattern(const QDomElement &b); |
68 | Franz | 248 | void parseGradient( const QDomElement &e ); |
296 | Franz | 249 | FPoint GetMaxClipO(FPointArray Clip); |
250 | FPoint GetMinClipO(FPointArray Clip); |
||
68 | Franz | 251 | QDomDocument inpdoc; |
7866 | fschmid | 252 | QString docDesc; |
253 | QString docTitle; |
||
254 | int groupLevel; |
||
9922 | fschmid | 255 | QStack<SvgStyle*> m_gc; |
68 | Franz | 256 | QMap<QString, GradientHelper> m_gradients; |
7556 | jghali | 257 | QMap<QString, QDomElement> m_nodeMap; |
7605 | jghali | 258 | QMap<QString, FPointArray> m_clipPaths; |
13385 | jghali | 259 | QMap<QString, QString> m_unsupportedFeatures; |
8237 | avox | 260 | bool PathClosed; |
1013 | fschmid | 261 | double viewTransformX; |
262 | double viewTransformY; |
||
263 | double viewScaleX; |
||
264 | double viewScaleY; |
||
3207 | craig | 265 | bool interactive; |
3800 | subik | 266 | //! \brief Indicator if there is any unsupported feature in imported svg. |
267 | bool unsupported; |
||
7794 | fschmid | 268 | bool importFailed; |
7795 | fschmid | 269 | bool importCanceled; |
5781 | cbradney | 270 | ScribusDoc* m_Doc; |
7578 | cbradney | 271 | Selection* tmpSel; |
7991 | fschmid | 272 | QStringList importedColors; |
12737 | fschmid | 273 | QStringList importedPatterns; |
12745 | fschmid | 274 | QMap<QString, QString> importedPattTrans; |
275 | double inGroupXOrigin; |
||
276 | double inGroupYOrigin; |
||
20477 | jghali | 277 | struct filterSpec |
278 | { |
||
279 | int blendMode; |
||
280 | }; |
||
281 | QMap<QString, filterSpec> filters; |
||
21615 | jghali | 282 | |
283 | protected: |
||
284 | QVector<double> parseNumbersList(const QString& numbersStr); |
||
68 | Franz | 285 | }; |
286 | |||
287 | #endif |