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;
34 class TransactionSettings;
35 class ScZipHandler;
36 
37 class ObjStyle
38 {
39 public:
ObjStyle()40 	ObjStyle() {}
41 
42 	QRectF							markerViewBox;
43 	QPainterPath					markerPath;
44 	QString							startMarkerName;
45 	double							startMarkerWidth { 0.0 };
46 	bool							startMarkerCentered { false };
47 	QString							endMarkerName;
48 	double							endMarkerWidth { 0.0 };
49 	bool							endMarkerCentered { false };
50 	double							stroke_dash_distance { 0.0 };
51 	int								stroke_dash_dots1 { 1 };
52 	double							stroke_dash_dots1_length { 0.0 };
53 	int								stroke_dash_dots2 { 1 };
54 	double							stroke_dash_dots2_length { 0.0 };
55 	QString							stroke_dash_style { "solid" };
56 	QString							dashName;
57 	QString							currColorFill { CommonStrings::None };
58 	QString							currColorStroke { CommonStrings::None };
59 	QString							currColorText { "Black" };
60 	QString							currColorBText { CommonStrings::None };
61 	QString							currColorShadow { "Black" };
62 	double							fillOpacity { 0.0 };
63 	double							strokeOpacity { 0.0 };
64 	double							LineW { 0.0 };
65 	QString							fontName;
66 	double							fontSize{ 10.0 };
67 	double							textIndent { 0.0 };
68 	ParagraphStyle::AlignmentType	textAlign { ParagraphStyle::LeftAligned };    // 0 = left
69 	QString							textPos;
70 	QString							textOutline;
71 	bool							textUnderline { false };
72 	bool							textUnderlineWords { false };
73 	QString							textUnderlineColor { CommonStrings::None };
74 	bool							textStrikeThrough { false };
75 	bool							textShadow { false };
76 	double							lineHeight { 1.0 };
77 	bool							absLineHeight { false };
78 	double							margin_top { 0.0 };
79 	double							margin_bottom { 0.0 };
80 	double							margin_left { 0.0 };
81 	double							margin_right { 0.0 };
82 	int								verticalAlignment{ 0 };
83 	double							page_width { 595.0 };
84 	double							page_height { 841.0 };
85 	QString							page_layout_name;
86 	int								fill_type { 0 };		// 0 = none, 1 = solid, 2 = gradient, 3 = bitmap 4 = hatch
87 	int								stroke_type { 0 };	// 0 = none, 1 = solid, 2 = dashed
88 	double							gradientAngle { 0.0 };
89 	double							gradientBorder { 0.0 };
90 	QString							gradientEndColor { CommonStrings::None };
91 	double							gradientEndShade { 100.0 };
92 	QString							gradientStartColor { CommonStrings::None };
93 	double							gradientStartShade { 100.0 };
94 	double							gradientCenterX { 0.0 };
95 	double							gradientCenterY { 0.0 };
96 	QString							gradientType { "linear" };
97 	QString							gradientName;
98 	bool							hasShadow { false };
99 	double							shadowX { 0.0 };
100 	double							shadowY { 0.0 };
101 	double							shadowTrans { 0.0 };
102 	double							measureDist { 0.0 };
103 	QString							patternName;
104 	QString							patternPath;
105 	QByteArray						patternData;
106 	double							patternWidth { 0.0 };
107 	double							patternHeight { 0.0 };
108 	double							patternX { 0.0 };
109 	double							patternY { 0.0 };
110 	bool							patternDim_W_in_Percent { false };
111 	bool							patternDim_H_in_Percent { false };
112 	QString							patternStretch;
113 	QString							hatchName;
114 	QString							hatchColor;
115 	double							hatchDistance { 0.0 };
116 	double							hatchRotation { 0.0 };
117 	QString							hatchStyle;
118 	bool							hatchSolidFill { false };
119 	QString							opacityName;
120 	double							opacityEnd { 1.0 };
121 	double							opacityStart { 0.0 };
122 };
123 
124 class OdgPlug : public QObject
125 {
126 	Q_OBJECT
127 
128 public:
129 	/*!
130 	\author Franz Schmid
131 	\date
132 	\brief Create the importer window.
133 	\param fName QString
134 	\param flags combination of loadFlags
135 	\param showProgress if progress must be displayed
136 	\retval EPSPlug plugin
137 	*/
138 	OdgPlug( ScribusDoc* doc, int flags );
139 	~OdgPlug();
140 
141 	/*!
142 	\author Franz Schmid
143 	\date
144 	\brief Perform import.
145 	\param fn QString
146 	\param trSettings undo transaction settings
147 	\param flags combination of loadFlags
148 	\param showProgress if progress must be displayed
149 	\retval bool true if import was ok
150 	 */
151 	bool import(const QString& fn, const TransactionSettings& trSettings, int flags, bool showProgress = true);
152 	QImage readThumbnail(const QString& fn);
153 
154 private:
155 	struct DrawStyle
156 	{
157 		AttributeValue parentStyle;
158 		AttributeValue markerViewBox;
159 		AttributeValue markerPath;
160 		AttributeValue startMarkerName;
161 		AttributeValue startMarkerWidth;
162 		AttributeValue startMarkerCentered;
163 		AttributeValue endMarkerName;
164 		AttributeValue endMarkerWidth;
165 		AttributeValue endMarkerCentered;
166 		AttributeValue stroke_dash_distance;
167 		AttributeValue stroke_dash_dots1;
168 		AttributeValue stroke_dash_dots1_length;
169 		AttributeValue stroke_dash_dots2;
170 		AttributeValue stroke_dash_dots2_length;
171 		AttributeValue stroke_dash_style;
172 		AttributeValue dashName;
173 		AttributeValue fillMode;
174 		AttributeValue currColorFill;
175 		AttributeValue strokeMode;
176 		AttributeValue currColorStroke;
177 		AttributeValue fontColor;
178 		AttributeValue currColorShadow;
179 		AttributeValue fillOpacity;
180 		AttributeValue strokeOpacity;
181 		AttributeValue LineW;
182 		AttributeValue fontName;
183 		AttributeValue fontSize;
184 		AttributeValue textIndent;
185 		AttributeValue textAlign;
186 		AttributeValue textPos;
187 		AttributeValue textOutline;
188 		AttributeValue textUnderline;
189 		AttributeValue textUnderlineWords;
190 		AttributeValue textUnderlineColor;
191 		AttributeValue textStrikeThrough;
192 		AttributeValue textShadow;
193 		AttributeValue textBackgroundColor;
194 		AttributeValue lineHeight;
195 		AttributeValue margin_top;
196 		AttributeValue margin_bottom;
197 		AttributeValue margin_left;
198 		AttributeValue margin_right;
199 		AttributeValue verticalAlignment;
200 		AttributeValue page_width;
201 		AttributeValue page_height;
202 		AttributeValue page_layout_name;
203 		AttributeValue gradientAngle;
204 		AttributeValue gradientBorder;
205 		AttributeValue gradientEndColor;
206 		AttributeValue gradientEndShade;
207 		AttributeValue gradientStartColor;
208 		AttributeValue gradientStartShade;
209 		AttributeValue gradientCenterX;
210 		AttributeValue gradientCenterY;
211 		AttributeValue gradientType;
212 		AttributeValue gradientName;
213 		AttributeValue hasShadow;
214 		AttributeValue shadowX;
215 		AttributeValue shadowY;
216 		AttributeValue shadowTrans;
217 		AttributeValue measureDist;
218 		AttributeValue patternName;
219 		AttributeValue patternPath;
220 		AttributeValue patternData;
221 		AttributeValue patternWidth;
222 		AttributeValue patternHeight;
223 		AttributeValue patternX;
224 		AttributeValue patternY;
225 		AttributeValue patternStretch;
226 		AttributeValue hatchName;
227 		AttributeValue hatchColor;
228 		AttributeValue hatchDistance;
229 		AttributeValue hatchRotation;
230 		AttributeValue hatchStyle;
231 		AttributeValue hatchSolidFill;
232 		AttributeValue opacityName;
233 		AttributeValue opacityEnd;
234 		AttributeValue opacityStart;
235 	};
236 
237 	bool convert(const QString& fn);
238 	bool parseStyleSheets(const QString& designMap);
239 	bool parseStyleSheetsXML(QDomDocument &designMapDom);
240 	bool parseDocReference(const QString& designMap);
241 	bool parseDocReferenceXML(QDomDocument &designMapDom);
242 	PageItem* parseObj(QDomElement &draw);
243 	PageItem* parseForm(QDomElement &e);
244 	PageItem* parseConnector(QDomElement &e);
245 	PageItem* parseCustomShape(QDomElement &e);
246 	PageItem* parseMeasure(QDomElement &e);
247 	PageItem* parseLine(QDomElement &e);
248 	PageItem* parseEllipse(QDomElement &e);
249 	PageItem* parseRect(QDomElement &e);
250 	PageItem* parsePolygon(QDomElement &e);
251 	PageItem* parsePolyline(QDomElement &e);
252 	PageItem* parsePath(QDomElement &e);
253 	PageItem* parseFrame(QDomElement &e);
254 	void parseText(QDomElement &elem, PageItem* item, ObjStyle& tmpOStyle);
255 	void insertChars(PageItem *item, QString &txt, ParagraphStyle &tmpStyle, CharStyle &tmpCStyle, int &posC);
256 	void applyCharacterStyle(CharStyle &tmpCStyle, ObjStyle &oStyle);
257 	void applyParagraphStyle(ParagraphStyle &tmpStyle, ObjStyle &oStyle);
258 	void parseTransform(const QString &transform, double *rotation, double *transX, double *transY);
259 	void parseTransform(FPointArray *composite, const QString &transform);
260 	void parseViewBox( const QDomElement& object, double *x, double *y, double *w, double *h );
261 	void appendPoints(FPointArray *composite, const QDomElement& object, bool closePath);
262 	void parseStyles(QDomElement &sp);
263 	QString getStyleName(QDomElement &e);
264 	void resovleStyle(ObjStyle &tmpOStyle, const QString& pAttrs);
265 	double parseUnit(const QString &unit);
266 	const char * getCoord( const char *ptr, double &number );
267 	bool parseEnhPath(const QString& svgPath, FPointArray &result, bool &fill, bool &stroke);
268 	double angleFromPoint(const QPointF &point);
269 	double radSweepAngle(double start, double stop, bool clockwise);
270 	double degSweepAngle(double start, double stop, bool clockwise);
271 	void arcTo(QPainterPath &path, QPointF startpoint, double rx, double ry, double startAngle, double sweepAngle);
272 	int arcToCurve(double rx, double ry, double startAngle, double sweepAngle, const QPointF & offset, QPointF * curvePoints);
273 	QString modifyColor(const QString& name, bool darker, int amount);
274 	QString parseColor( const QString &s );
275 	QString constructFontName(const QString& fontBaseName, const QString& fontStyle);
276 	QPointF intersectBoundingRect(PageItem *item, QLineF gradientVector);
277 	PageItem* applyStartArrow(PageItem* item, ObjStyle &obState);
278 	PageItem* applyEndArrow(PageItem* ite, ObjStyle &obState);
279 	PageItem* groupObjects(QList<PageItem*> &GElements);
280 	void finishItem(PageItem* item, ObjStyle &obState);
281 	QList<PageItem*> Elements;
282 	double baseX, baseY;
283 	double docWidth;
284 	double docHeight;
285 	bool interactive;
286 	ScribusDoc* m_Doc;
287 	Selection* tmpSel;
288 	int importerFlags;
289 	MultiProgressDialog * progressDialog;
290 	bool cancel;
291 	QStringList importedColors;
292 	QStringList importedPatterns;
293 	bool firstPage;
294 	bool firstLayer;
295 	int pagecount;
296 	int mpagecount;
297 	double topMargin;
298 	double leftMargin;
299 	double rightMargin;
300 	double bottomMargin;
301 	double pgCols;
302 	double pgGap;
303 	QHash<QString, QString> m_fontMap;
304 	QHash<QString, DrawStyle> m_Styles;
305 	QHash<QString, int> m_Layers;
306 
307 
308 	FPointArray Coords;
309 	QHash<QString, QPainterPath> pathResources;
310 	ScZipHandler *uz;
311 
312 public slots:
cancelRequested()313 	void cancelRequested() { cancel = true; }
314 };
315 
316 #endif
317