Scribus
Open source desktop publishing at your fingertips
importodg.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 /***************************************************************************
8  -------------------
9  begin : Sun Feb 9 2014
10  copyright : (C) 2014 by Franz Schmid
11  email : Franz.Schmid@altmuehlnet.de
12  ***************************************************************************/
13 #ifndef IMPORTODG_H
14 #define IMPORTODG_H
15 
16 #include "commonstrings.h"
17 #include "pluginapi.h"
18 #include "pageitem.h"
19 #include "sccolor.h"
20 #include "fpointarray.h"
21 #include "scribusstructs.h"
22 #include <QList>
23 #include <QTransform>
24 #include <QMultiMap>
25 #include <QtGlobal>
26 #include <QObject>
27 #include <QString>
28 #include <QDomDocument>
29 #include <QDomElement>
30 
31 class MultiProgressDialog;
32 class ScribusDoc;
33 class Selection;
35 class ScZipHandler;
36 
37 class ObjStyle
38 {
39 public:
40  ObjStyle() :
41  markerViewBox(),
42  markerPath(),
43  startMarkerName(""),
44  startMarkerWidth(0.0),
45  startMarkerCentered(false),
46  endMarkerName(""),
47  endMarkerWidth(0.0),
48  endMarkerCentered(false),
49  stroke_dash_distance(0.0),
50  stroke_dash_dots1(1),
51  stroke_dash_dots1_length(0.0),
52  stroke_dash_dots2(1),
53  stroke_dash_dots2_length(0.0),
54  stroke_dash_style("solid"),
55  dashName(""),
56  CurrColorFill(CommonStrings::None),
57  CurrColorStroke(CommonStrings::None),
58  CurrColorText("Black"),
59  CurrColorShadow("Black"),
60  fillOpacity(0.0),
61  strokeOpacity(0.0),
62  LineW(0.0),
63  fontName(""),
64  fontSize(10.0),
65  textIndent(0.0),
66  textAlign(ParagraphStyle::Leftaligned),
67  textPos(""),
68  textOutline(""),
69  textUnderline(false),
70  textUnderlineWords(false),
71  textUnderlineColor(CommonStrings::None),
72  textStrikeThrough(false),
73  textShadow(false),
74  lineHeight(1.0),
75  absLineHeight(false),
76  margin_top(0.0),
77  margin_bottom(0.0),
78  margin_left(0.0),
79  margin_right(0.0),
80  verticalAlignment(0),
81  page_width(595.0),
82  page_height(841.0),
83  page_layout_name(""),
84  fill_type(0),
85  stroke_type(0),
86  gradientAngle(0.0),
87  gradientBorder(0.0),
88  gradientEndColor(CommonStrings::None),
89  gradientEndShade(100.0),
90  gradientStartColor(CommonStrings::None),
91  gradientStartShade(100.0),
92  gradientCenterX(0.0),
93  gradientCenterY(0.0),
94  gradientType("linear"),
95  gradientName(""),
96  hasShadow(false),
97  shadowX(0.0),
98  shadowY(0.0),
99  shadowTrans(0.0),
100  measureDist(0.0),
101  patternName(""),
102  patternPath(""),
103  patternData(),
104  patternWidth(0.0),
105  patternHeight(0.0),
106  patternX(0.0),
107  patternY(0.0),
108  patternDim_W_in_Percent(false),
109  patternDim_H_in_Percent(false),
110  patternStretch(""),
111  hatchName(""),
112  hatchColor(""),
113  hatchDistance(0.0),
114  hatchRotation(0.0),
115  hatchStyle(""),
116  hatchSolidFill(false),
117  opacityName(""),
118  opacityEnd(1.0),
119  opacityStart(0.0)
120  {}
121  QRectF markerViewBox;
122  QPainterPath markerPath;
123  QString startMarkerName;
124  double startMarkerWidth;
125  bool startMarkerCentered;
126  QString endMarkerName;
127  double endMarkerWidth;
128  bool endMarkerCentered;
129  double stroke_dash_distance;
130  int stroke_dash_dots1;
131  double stroke_dash_dots1_length;
132  int stroke_dash_dots2;
133  double stroke_dash_dots2_length;
134  QString stroke_dash_style;
135  QString dashName;
136  QString CurrColorFill;
137  QString CurrColorStroke;
138  QString CurrColorText;
139  QString CurrColorShadow;
140  double fillOpacity;
141  double strokeOpacity;
142  double LineW;
143  QString fontName;
144  double fontSize;
145  double textIndent;
146  ParagraphStyle::AlignmentType textAlign; // 0 = left
147  QString textPos;
148  QString textOutline;
149  bool textUnderline;
150  bool textUnderlineWords;
151  QString textUnderlineColor;
152  bool textStrikeThrough;
153  bool textShadow;
154  double lineHeight;
155  bool absLineHeight;
156  double margin_top;
157  double margin_bottom;
158  double margin_left;
159  double margin_right;
160  int verticalAlignment;
161  double page_width;
162  double page_height;
163  QString page_layout_name;
164  int fill_type; // 0 = none, 1 = solid, 2 = gradient, 3 = bitmap 4 = hatch
165  int stroke_type; // 0 = none, 1 = solid, 2 = dashed
166  double gradientAngle;
167  double gradientBorder;
168  QString gradientEndColor;
169  double gradientEndShade;
170  QString gradientStartColor;
171  double gradientStartShade;
172  double gradientCenterX;
173  double gradientCenterY;
174  QString gradientType;
175  QString gradientName;
176  bool hasShadow;
177  double shadowX;
178  double shadowY;
179  double shadowTrans;
180  double measureDist;
181  QString patternName;
182  QString patternPath;
183  QByteArray patternData;
184  double patternWidth;
185  double patternHeight;
186  double patternX;
187  double patternY;
188  bool patternDim_W_in_Percent;
189  bool patternDim_H_in_Percent;
190  QString patternStretch;
191  QString hatchName;
192  QString hatchColor;
193  double hatchDistance;
194  double hatchRotation;
195  QString hatchStyle;
196  bool hatchSolidFill;
197  QString opacityName;
198  double opacityEnd;
199  double opacityStart;
200 };
201 
202 class OdgPlug : public QObject
203 {
204  Q_OBJECT
205 
206 public:
216  OdgPlug( ScribusDoc* doc, int flags );
217  ~OdgPlug();
218 
229  bool import(QString fn, const TransactionSettings& trSettings, int flags, bool showProgress = true);
230  QImage readThumbnail(QString fn);
231 
232 private:
233  struct DrawStyle
234  {
235  AttributeValue parentStyle;
236  AttributeValue markerViewBox;
237  AttributeValue markerPath;
238  AttributeValue startMarkerName;
239  AttributeValue startMarkerWidth;
240  AttributeValue startMarkerCentered;
241  AttributeValue endMarkerName;
242  AttributeValue endMarkerWidth;
243  AttributeValue endMarkerCentered;
244  AttributeValue stroke_dash_distance;
245  AttributeValue stroke_dash_dots1;
246  AttributeValue stroke_dash_dots1_length;
247  AttributeValue stroke_dash_dots2;
248  AttributeValue stroke_dash_dots2_length;
249  AttributeValue stroke_dash_style;
250  AttributeValue dashName;
251  AttributeValue fillMode;
252  AttributeValue CurrColorFill;
253  AttributeValue strokeMode;
254  AttributeValue CurrColorStroke;
255  AttributeValue fontColor;
256  AttributeValue CurrColorShadow;
257  AttributeValue fillOpacity;
258  AttributeValue strokeOpacity;
259  AttributeValue LineW;
260  AttributeValue fontName;
261  AttributeValue fontSize;
262  AttributeValue textIndent;
263  AttributeValue textAlign;
264  AttributeValue textPos;
265  AttributeValue textOutline;
266  AttributeValue textUnderline;
267  AttributeValue textUnderlineWords;
268  AttributeValue textUnderlineColor;
269  AttributeValue textStrikeThrough;
270  AttributeValue textShadow;
271  AttributeValue lineHeight;
272  AttributeValue margin_top;
273  AttributeValue margin_bottom;
274  AttributeValue margin_left;
275  AttributeValue margin_right;
276  AttributeValue verticalAlignment;
277  AttributeValue page_width;
278  AttributeValue page_height;
279  AttributeValue page_layout_name;
280  AttributeValue gradientAngle;
281  AttributeValue gradientBorder;
282  AttributeValue gradientEndColor;
283  AttributeValue gradientEndShade;
284  AttributeValue gradientStartColor;
285  AttributeValue gradientStartShade;
286  AttributeValue gradientCenterX;
287  AttributeValue gradientCenterY;
288  AttributeValue gradientType;
289  AttributeValue gradientName;
290  AttributeValue hasShadow;
291  AttributeValue shadowX;
292  AttributeValue shadowY;
293  AttributeValue shadowTrans;
294  AttributeValue measureDist;
295  AttributeValue patternName;
296  AttributeValue patternPath;
297  AttributeValue patternData;
298  AttributeValue patternWidth;
299  AttributeValue patternHeight;
300  AttributeValue patternX;
301  AttributeValue patternY;
302  AttributeValue patternStretch;
303  AttributeValue hatchName;
304  AttributeValue hatchColor;
305  AttributeValue hatchDistance;
306  AttributeValue hatchRotation;
307  AttributeValue hatchStyle;
308  AttributeValue hatchSolidFill;
309  AttributeValue opacityName;
310  AttributeValue opacityEnd;
311  AttributeValue opacityStart;
312  };
313 
314  bool convert(QString fn);
315  bool parseStyleSheets(QString designMap);
316  bool parseStyleSheetsXML(QDomDocument &designMapDom);
317  bool parseDocReference(QString designMap);
318  bool parseDocReferenceXML(QDomDocument &designMapDom);
319  PageItem* parseObj(QDomElement &draw);
320  PageItem* parseForm(QDomElement &e);
321  PageItem* parseConnector(QDomElement &e);
322  PageItem* parseCustomShape(QDomElement &e);
323  PageItem* parseMeasure(QDomElement &e);
324  PageItem* parseLine(QDomElement &e);
325  PageItem* parseEllipse(QDomElement &e);
326  PageItem* parseRect(QDomElement &e);
327  PageItem* parsePolygon(QDomElement &e);
328  PageItem* parsePolyline(QDomElement &e);
329  PageItem* parsePath(QDomElement &e);
330  PageItem* parseFrame(QDomElement &e);
331  void parseText(QDomElement &elem, PageItem* item, ObjStyle& tmpOStyle);
332  void insertChars(PageItem *item, QString &txt, ParagraphStyle &tmpStyle, CharStyle &tmpCStyle, int &posC);
333  void applyCharacterStyle(CharStyle &tmpCStyle, ObjStyle &oStyle);
334  void applyParagraphStyle(ParagraphStyle &tmpStyle, ObjStyle &oStyle);
335  void parseTransform(const QString &transform, double *rotation, double *transX, double *transY);
336  void parseTransform(FPointArray *composite, const QString &transform);
337  void parseViewBox( const QDomElement& object, double *x, double *y, double *w, double *h );
338  void appendPoints(FPointArray *composite, const QDomElement& object, bool closePath);
339  void parseStyles(QDomElement &sp);
340  QString getStyleName(QDomElement &e);
341  void resovleStyle(ObjStyle &tmpOStyle, QString pAttrs);
342  double parseUnit(const QString &unit);
343  const char * getCoord( const char *ptr, double &number );
344  bool parseEnhPath(const QString& svgPath, FPointArray &result, bool &fill, bool &stroke);
345  double angleFromPoint(const QPointF &point);
346  double radSweepAngle(double start, double stop, bool clockwise);
347  double degSweepAngle(double start, double stop, bool clockwise);
348  void arcTo(QPainterPath &path, QPointF startpoint, double rx, double ry, double startAngle, double sweepAngle);
349  int arcToCurve(double rx, double ry, double startAngle, double sweepAngle, const QPointF & offset, QPointF * curvePoints);
350  QString modifyColor(QString name, bool darker, int amount);
351  QColor parseColorN( const QString &rgbColor );
352  QString parseColor( const QString &s );
353  QString constructFontName(QString fontBaseName, QString fontStyle);
354  QPointF intersectBoundingRect(PageItem *item, QLineF gradientVector);
355  PageItem* applyStartArrow(PageItem* item, ObjStyle &obState);
356  PageItem* applyEndArrow(PageItem* ite, ObjStyle &obState);
357  PageItem* groupObjects(QList<PageItem*> &GElements);
358  void finishItem(PageItem* item, ObjStyle &obState);
359  QList<PageItem*> Elements;
360  double baseX, baseY;
361  double docWidth;
362  double docHeight;
363  bool interactive;
364  ScribusDoc* m_Doc;
365  Selection* tmpSel;
366  int importerFlags;
367  MultiProgressDialog * progressDialog;
368  bool cancel;
369  QStringList importedColors;
370  QStringList importedPatterns;
371  bool firstPage;
372  bool firstLayer;
373  int pagecount;
374  int mpagecount;
375  double topMargin;
376  double leftMargin;
377  double rightMargin;
378  double bottomMargin;
379  double pgCols;
380  double pgGap;
381  QHash<QString, QString> m_fontMap;
382  QHash<QString, DrawStyle> m_Styles;
383  QHash<QString, int> m_Layers;
384 
385 
386  FPointArray Coords;
387  QHash<QString, QPainterPath> pathResources;
388  ScZipHandler *uz;
389 
390 public slots:
391  void cancelRequested() { cancel = true; }
392 };
393 
394 #endif
Definition: charstyle.h:78
Definition: importodg.h:202
Definition: paragraphstyle.h:27
the Document Class
Definition: scribusdoc.h:90
Definition: undomanager.h:52
Definition: importodg.h:37
Definition: pageitem.h:92
Definition: scribus_zip.h:28
Definition: fpointarray.h:42
OdgPlug(ScribusDoc *doc, int flags)
Create the importer window.
Definition: importodg.cpp:75
Definition: scribusstructs.h:349
Definition: selection.h:34