Scribus
Open source desktop publishing at your fingertips
svgplugin.h
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 */
7 #ifndef SVGPLUG_H
8 #define SVGPLUG_H
9 
10 #include <QDomElement>
11 #include <QFont>
12 #include <QList>
13 #include <QRectF>
14 #include <QSizeF>
15 #include <QStack>
16 #include "pluginapi.h"
17 #include "loadsaveplugin.h"
18 #include "../../formatidlist.h"
19 #include "vgradient.h"
20 
21 class ScrAction;
22 class ScribusMainWindow;
24 
28 class PLUGIN_API SVGImportPlugin : public LoadSavePlugin
29 {
30  Q_OBJECT
31 
32  public:
33  // Standard plugin implementation
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();
40  virtual bool fileSupported(QIODevice* file, const QString & fileName=QString::null) const;
41  virtual bool loadFile(const QString & fileName, const FileFormat & fmt, int flags, int index = 0);
42  virtual QImage readThumbnail(const QString& fileName);
44 
45  public slots:
52  virtual bool import(QString filename = QString::null, int flags = lfUseCurrentPage|lfInteractive);
53 
54  private:
55  void registerFormats();
56  ScrAction* importAction;
57 
58 };
59 
60 extern "C" PLUGIN_API int svgimplugin_getPluginAPIVersion();
61 extern "C" PLUGIN_API ScPlugin* svgimplugin_getPlugin();
62 extern "C" PLUGIN_API void svgimplugin_freePlugin(ScPlugin* plugin);
63 
64 class PageItem;
65 class ScribusDoc;
66 class PrefsManager;
67 class FPointArray;
68 
70 {
71 public:
72  GradientHelper() :
73  cspace(false),
74  cspaceValid(true),
75  gradient(VGradient::linear),
76  gradientValid(false),
77  matrix(),
78  matrixValid(false),
79  reference(""),
80  type(1),
81  typeValid(false),
82  x1(0),
83  x1Valid(true),
84  x2(1),
85  x2Valid(true),
86  y1(0),
87  y1Valid(true),
88  y2(0),
89  y2Valid(true),
90  fx(0),
91  fxValid(true),
92  fy(0),
93  fyValid(true)
94  {
95  }
96  bool cspace;
97  bool cspaceValid;
98  VGradient gradient;
99  bool gradientValid;
100  QTransform matrix;
101  bool matrixValid;
102  QString reference;
103  int type;
104  bool typeValid;
105  double x1;
106  bool x1Valid;
107  double x2;
108  bool x2Valid;
109  double y1;
110  bool y1Valid;
111  double y2;
112  bool y2Valid;
113  double fx;
114  bool fxValid;
115  double fy;
116  bool fyValid;
117  };
118 
119 class SvgStyle
120 {
121 public:
122  SvgStyle() :
123  Display(true),
124  FillCSpace(false),
125  StrokeCSpace(false),
126  CurCol("None"),
127  dashOffset(0),
128  FontFamily(""),
129  FontStyle("normal"),
130  FontWeight("normal"),
131  FontStretch("normal"),
132  FontSize(12),
133  FillCol("Black"),
134  fillRule("nonzero"),
135  GFillCol1("Black"),
136  GStrokeCol1("Black"),
137  FillGradient(VGradient::linear),
138  StrokeGradient(VGradient::linear),
139  FillGradientType(0),
140  StrokeGradientType(0),
141  GradFillX1(0),
142  GradFillX2(0),
143  GradFillY1(0),
144  GradFillY2(0),
145  GradFillFX(0),
146  GradFillFY(0),
147  GradStrokeX1(0),
148  GradStrokeX2(0),
149  GradStrokeY1(0),
150  GradStrokeY2(0),
151  GradStrokeFX(0),
152  GradStrokeFY(0),
153  InherCol(false),
154  LWidth(1.0),
155  matrix(),
156  matrixgf(),
157  matrixgs(),
158  PLineArt(Qt::SolidLine),
159  PLineEnd(Qt::FlatCap),
160  PLineJoin(Qt::MiterJoin),
161  StrokeCol("None"),
162  Opacity(1.0),
163  FillOpacity(1.0),
164  StrokeOpacity(1.0),
165  textAnchor("start"),
166  clipPath(),
167  forGroup(false),
168  endMarker(""),
169  startMarker("")
170  {
171  }
172  bool Display;
173  bool FillCSpace;
174  bool StrokeCSpace;
175  QString CurCol;
176  QVector<double> dashArray;
177  double dashOffset;
178  QString FontFamily;
179  QString FontStyle;
180  QString FontWeight;
181  QString FontStretch;
182  double FontSize;
183  QString FillCol;
184  QString fillRule;
185  QString GFillCol1;
186  QString GStrokeCol1;
187  VGradient FillGradient;
188  VGradient StrokeGradient;
189  int FillGradientType;
190  int StrokeGradientType;
191  double GradFillX1;
192  double GradFillX2;
193  double GradFillY1;
194  double GradFillY2;
195  double GradFillFX;
196  double GradFillFY;
197  double GradStrokeX1;
198  double GradStrokeX2;
199  double GradStrokeY1;
200  double GradStrokeY2;
201  double GradStrokeFX;
202  double GradStrokeFY;
203  bool InherCol;
204  double LWidth;
205  QTransform matrix;
206  QTransform matrixgf;
207  QTransform matrixgs;
208  Qt::PenStyle PLineArt;
209  Qt::PenCapStyle PLineEnd;
210  Qt::PenJoinStyle PLineJoin;
211  QString StrokeCol;
212  double Opacity;
213  double FillOpacity;
214  double StrokeOpacity;
215  QString textAnchor;
216  QString textDecoration;
217  FPointArray clipPath;
218  bool forGroup;
219  QString endMarker;
220  QString startMarker;
221 };
222 
223 class SVGPlug : public QObject
224 {
225  Q_OBJECT
226 
227 public:
234  SVGPlug(ScribusDoc* doc, int flags);
235  ~SVGPlug();
236  bool import(QString fname, const TransactionSettings& trSettings, int flags);
237  QImage readThumbnail(QString fn);
238  bool loadData(QString fname);
239  void convert(const TransactionSettings& trSettings, int flags);
240  void addGraphicContext();
241  void setupNode( const QDomElement &e );
242  void setupTransform( const QDomElement &e );
243  void finishNode( const QDomNode &e, PageItem* item);
244  bool isIgnorableNode( const QDomElement &e );
245  bool isIgnorableNodeName( const QString &n );
246  FPoint parseTextPosition(const QDomElement &e, const FPoint* pos = NULL);
247  QSizeF parseWidthHeight(const QDomElement &e);
248  QRectF parseViewBox(const QDomElement &e);
249  void parseDefs(const QDomElement &e);
250  void parseClipPath(const QDomElement &e);
251  void parseClipPathAttr(const QDomElement &e, FPointArray& clipPath);
252  QList<PageItem*> parseA(const QDomElement &e);
253  QList<PageItem*> parseGroup(const QDomElement &e);
254  QList<PageItem*> parseDoc(const QDomElement &e);
255  QList<PageItem*> parseElement(const QDomElement &e);
256  QList<PageItem*> parseCircle(const QDomElement &e);
257  QList<PageItem*> parseEllipse(const QDomElement &e);
258  QList<PageItem*> parseImage(const QDomElement &e);
259  QList<PageItem*> parseLine(const QDomElement &e);
260  QList<PageItem*> parsePath(const QDomElement &e);
261  QList<PageItem*> parsePolyline(const QDomElement &e);
262  QList<PageItem*> parseRect(const QDomElement &e);
263  QList<PageItem*> parseText(const QDomElement &e);
264  QList<PageItem*> parseTextSpan(const QDomElement& e, FPoint& currentPos, double chunkW);
265  QList<PageItem*> parseTextNode(const QDomText& e, FPoint& currentPos, double chunkW);
266  QList<PageItem*> parseSwitch(const QDomElement &e);
267  QList<PageItem*> parseSymbol(const QDomElement &e);
268  QList<PageItem*> parseUse(const QDomElement &e);
269  const char* getCoord( const char *ptr, double &number );
270  QFont getFontFromStyle(SvgStyle& style);
271  QDomElement getReferencedNode(const QDomElement &e);
272  bool getTextChunkWidth(const QDomElement &e, double& width);
273  double fromPercentage(const QString &s );
274  double parseFontSize(const QString& fsize);
275  double parseUnit(const QString &unit);
276  QTransform parseTransform(const QString &transform);
277  bool parseSVG( const QString &s, FPointArray *ite );
278  QColor parseColorN( const QString &rgbColor );
279  QString parseColor( const QString &s );
280  QString parseIccColor( const QString &s );
281  QString parseTagName( const QDomElement &e );
282  void parsePA( SvgStyle *obj, const QString &command, const QString &params );
283  void parseStyle( SvgStyle *obj, const QDomElement &e );
284  void parseColorStops(GradientHelper *gradient, const QDomElement &e);
285  void parseMarker(const QDomElement &b);
286  void parsePattern(const QDomElement &b);
287  void parseGradient( const QDomElement &e );
288  FPoint GetMaxClipO(FPointArray Clip);
289  FPoint GetMinClipO(FPointArray Clip);
290  QDomDocument inpdoc;
291  QString docDesc;
292  QString docTitle;
293  int groupLevel;
294  QStack<SvgStyle*> m_gc;
295  QMap<QString, GradientHelper> m_gradients;
296  QMap<QString, QDomElement> m_nodeMap;
297  QMap<QString, FPointArray> m_clipPaths;
298  QMap<QString, QString> m_unsupportedFeatures;
299  bool PathClosed;
300  double viewTransformX;
301  double viewTransformY;
302  double viewScaleX;
303  double viewScaleY;
304  bool interactive;
307  bool importFailed;
308  bool importCanceled;
309  ScribusDoc* m_Doc;
310  Selection* tmpSel;
311  QStringList importedColors;
312  QStringList importedGradients;
313  QMap<QString, QString> importedGradTrans;
314  QStringList importedPatterns;
315  QMap<QString, QString> importedPattTrans;
316  double inGroupXOrigin;
317  double inGroupYOrigin;
318  int importerFlags;
319  bool firstLayer;
320  struct markerDesc
321  {
322  double xref;
323  double yref;
324  double wpat;
325  double hpat;
326  };
327  QMap<QString, markerDesc> markers;
328  QList<PageItem*> Elements;
329 };
330 
331 #endif
Definition: svgplugin.h:223
Definition: loadsaveplugin.h:190
Definition: svgplugin.h:119
A class providing the plugin interface implementation for this plugin.
Definition: svgplugin.h:28
virtual const QString fullTrName() const =0
Plug-in's human-readable, translated name.
Abstract super class for all Scribus plug-ins.
Definition: scplugin.h:90
This Class is the base class for your application. It sets up the main window and providing a menubar...
Definition: scribus.h:123
virtual void addToMainWindowMenu(ScribusMainWindow *)
Allow plugins to add to a main menu.
Definition: svgplugin.h:43
virtual void languageChange()=0
Update all user-visible text to reflect current UI language.
Definition: vgradient.h:78
A point with floating point precision.
Definition: fpoint.h:43
bool unsupported
Indicator if there is any unsupported feature in imported svg.
Definition: svgplugin.h:306
the Document Class
Definition: scribusdoc.h:90
ScPlugin provides an interface to ask plugins for information about themselves.
Definition: scplugin.h:103
Definition: undomanager.h:52
Definition: scraction.h:33
SVGPlug(ScribusDoc *doc, int flags)
Create the SVG importer window.
Definition: svgplugin.cpp:221
Superclass for all file import/export/load/save plugins.
Definition: loadsaveplugin.h:33
virtual const AboutData * getAboutData() const =0
Return descriptive information about the plug-in.
Definition: pageitem.h:92
Definition: svgplugin.h:69
Definition: fpointarray.h:42
Manage Scribus preferences here, and here alone Start to move the preferences out of scribus...
Definition: prefsmanager.h:43
Definition: svgplugin.h:320
Definition: selection.h:34