Scribus
Open source desktop publishing at your fingertips
importsvm.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 : Sat Mar 7 2015
10  copyright : (C) 2015 by Franz Schmid
11  email : Franz.Schmid@altmuehlnet.de
12  ***************************************************************************/
13 #ifndef IMPORTSVM_H
14 #define IMPORTSVM_H
15 
16 
17 #include "pluginapi.h"
18 #include "pageitem.h"
19 #include "sccolor.h"
20 #include "fpointarray.h"
21 #include "commonstrings.h"
22 #include <QList>
23 #include <QTransform>
24 #include <QMultiMap>
25 #include <QtGlobal>
26 #include <QObject>
27 #include <QStack>
28 #include <QString>
29 #include <QRect>
30 
31 class MultiProgressDialog;
32 class ScribusDoc;
33 class Selection;
35 
36 class emfStyle
37 {
38 public:
39  emfStyle() :
40  styType(0),
41  penStyle(Qt::SolidLine),
42  penCap(Qt::RoundCap),
43  penJoin(Qt::RoundJoin),
44  penWidth(0.0),
45  dashArray(),
46  dashOffset(0.0),
47  brushStyle(0),
48  hatchStyle(0),
49  gradientStart(),
50  gradientEnd(),
51  gradientAngle(0),
52  gradient(VGradient::linear),
53  gradientPath(),
54  hAlign(0),
55  vAlign(0),
56  fontUnit(0),
57  verticalText(false),
58  fontRotation(0.0),
59  fontSize(12.0),
60  fontName(""),
61  penColor(CommonStrings::None),
62  brushColor(CommonStrings::None),
63  patternName(""),
64  patternMode(0),
65  fillTrans(0.0),
66  penTrans(0.0),
67  Coords(),
68  MetaFile(false),
69  imageType(0),
70  imageWidth(0),
71  imageHeight(0),
72  imagePixelFormat(0),
73  imageData()
74  {
75  gradientPath.resize(0);
76  gradientPath.svgInit();
77  imageData.resize(0);
78  Coords.resize(0);
79  Coords.svgInit();
80  }
81  quint32 styType;
82  Qt::PenStyle penStyle;
83  Qt::PenCapStyle penCap;
84  Qt::PenJoinStyle penJoin;
85  double penWidth;
86  QVector<double> dashArray;
87  double dashOffset;
88  quint32 brushStyle;
89  quint32 hatchStyle;
90  QPointF gradientStart;
91  QPointF gradientEnd;
92  double gradientAngle;
93  VGradient gradient;
94  FPointArray gradientPath;
95  quint32 hAlign;
96  quint32 vAlign;
97  quint32 fontUnit;
98  bool verticalText;
99  double fontRotation;
100  double fontSize;
101  QString fontName;
102  QString penColor;
103  QString brushColor;
104  QString patternName;
105  quint32 patternMode;
106  double fillTrans;
107  double penTrans;
108  FPointArray Coords;
109  bool MetaFile;
110  quint32 imageType;
111  qint32 imageWidth;
112  qint32 imageHeight;
113  quint32 imagePixelFormat;
114  QByteArray imageData;
115 };
116 
117 class SvmPlug : public QObject
118 {
119  Q_OBJECT
120 
121 public:
131  SvmPlug( ScribusDoc* doc, int flags );
132  ~SvmPlug();
133 
144  bool import(QString fn, const TransactionSettings& trSettings, int flags, bool showProgress = true);
145  QImage readThumbnail(QString fn);
146 
147 private:
148  void parseHeader(QString fName, double &x, double &y, double &b, double &h);
149  bool convert(QString fn);
150  // Common functions
151  void aligntoQuadWord(QDataStream &ds);
152  double convertLogical2Pts(double in);
153  QPointF convertLogical2Pts(QPointF in);
154  FPointArray getPolyPolygonPoints(QDataStream &ds, quint16 version);
155  FPointArray getPolyPoints(QDataStream &ds, quint32 count, bool closed);
156  QPointF getPoint(QDataStream &ds);
157  void getColor(QDataStream &ds, QString &colorN);
158  QPointF intersectBoundingRect(PageItem *item, QLineF gradientVector);
159  void finishItem(PageItem* ite, bool fill = true);
160  void handleEllipse(QDataStream &ds);
161  void handleRectangle(QDataStream &ds);
162  void handleRoundRect(QDataStream &ds);
163  void handlePolyline(QDataStream &ds);
164  void handleLine(QDataStream &ds);
165  void handleArc(QDataStream &ds);
166  void handleArcTo(QDataStream &ds);
167  void handleChord(QDataStream &ds);
168  void handlePie(QDataStream &ds);
169  void handleFontDef(QDataStream &ds);
170  void handleSmallText(QDataStream &ds);
171  void handleText(QDataStream &ds, quint16 version);
172  void handleImage(QDataStream &ds, qint64 posi, quint32 totalSize);
173  void handleImageEX(QDataStream &ds, qint64 posi, quint32 totalSize);
174  void handlePolygon(QDataStream &ds);
175  void handlePolyPolygon(QDataStream &ds, quint16 version);
176  void handleTransparent(QDataStream &ds, quint16 version);
177  void handleHatch(QDataStream &ds, quint16 version);
178  void handleGradient(QDataStream &ds);
179  void handleGradientEX(QDataStream &ds, quint16 version);
180  void commonGradient(QDataStream &ds, PageItem* ite);
181  QString handleColor(QColor col);
182  void handleSetClipRegion(QDataStream &ds);
183  void handleComment(QDataStream &ds);
184  // Functions for EMF+ Files
185  void handleEMFPlus(QDataStream &ds, quint32 dtaSize);
186  void handleEMPObject(QDataStream &ds, quint8 flagsH, quint8 flagsL, quint32 dataSize);
187  quint32 handleEMPBrush(QDataStream &ds, quint16 id, bool first, bool cont, quint32 dataSize);
188  void handleEMPPen(QDataStream &ds, quint16 id);
189  void handleEMPPath(QDataStream &ds, quint16 id);
190  void handleEMPRegion(QDataStream &ds, quint16 id);
191  quint32 handleEMPImage(QDataStream &ds, quint16 id, bool first, bool cont, quint32 dataSize);
192  quint32 getImageData(QDataStream &ds, quint16 id, bool first, bool cont, quint32 dataSize, emfStyle &sty);
193  void handleEMPFont(QDataStream &ds, quint16 id);
194  void handleEMPSFormat(QDataStream &ds, quint16 id);
195  void handleEMPLineCap(QDataStream &ds, quint16 id);
196  void handleEMFPFillClosedCurve(QDataStream &ds, quint8 flagsL);
197  void handleEMFPFillEllipse(QDataStream &ds, quint8 flagsL);
198  void handleEMFPFillPath(QDataStream &ds, quint8 flagsL, quint8 flagsH);
199  void handleEMFPFillPie(QDataStream &ds, quint8 flagsL);
200  void handleEMFPFillPolygon(QDataStream &ds, quint8 flagsL);
201  void handleEMFPFillRects(QDataStream &ds, quint8 flagsL);
202  void handleEMFPFillRegion(QDataStream &ds, quint8 flagsL, quint8 flagsH);
203  void handleEMFPDrawArc(QDataStream &ds, quint8 flagsL, quint8 flagsH);
204  void handleEMFPDrawBezier(QDataStream &ds, quint8 flagsL, quint8 flagsH);
205  void handleEMFPDrawClosedCurve(QDataStream &ds, quint8 flagsL, quint8 flagsH);
206  void handleEMFPDrawCurve(QDataStream &ds, quint8 flagsL, quint8 flagsH);
207  void handleEMFPDrawEllipse(QDataStream &ds, quint8 flagsL, quint8 flagsH);
208  void handleEMFPDrawImage(QDataStream &ds, quint8 flagsL, quint8 flagsH);
209  void handleEMFPDrawImagePoints(QDataStream &ds, quint8 flagsL, quint8 flagsH);
210  void handleEMFPDrawLines(QDataStream &ds, quint8 flagsL, quint8 flagsH);
211  void handleEMFPDrawPath(QDataStream &ds, quint8 flagsH);
212  void handleEMFPDrawPie(QDataStream &ds, quint8 flagsL, quint8 flagsH);
213  void handleEMFPDrawRects(QDataStream &ds, quint8 flagsL, quint8 flagsH);
214  void handleEMFPDrawDriverString(QDataStream &ds, quint8 flagsL, quint8 flagsH);
215  void handleEMFPDrawString(QDataStream &ds, quint8 flagsL, quint8 flagsH);
216  void handleEMFPSetClipRect(QDataStream &ds, quint8 flagsL);
217  void handleEMFPSetClipRegion(QDataStream &ds, quint8 flagsL, quint8 flagsH);
218  void handleEMFPSetClipPath(QDataStream &ds, quint8 flagsL, quint8 flagsH);
219  void handleEMFPSerializableObject(QDataStream &ds);
220  void getEMFPBrush(quint32 brushID, bool directBrush);
221  void getEMFPPen(quint32 penID);
222  void getEMFPFont(quint32 fontID);
223  void getEMFPStringFormat(quint32 fontID);
224  FPointArray getEMPPathData(QDataStream &ds);
225  QPolygonF getEMFPCurvePoints(QDataStream &ds, quint8 flagsL, quint32 count);
226  QPolygonF getEMFPRect(QDataStream &ds, bool size);
227  QPointF getEMFPPoint(QDataStream &ds, bool size);
228  double getEMFPDistance(QDataStream &ds, bool size);
229  QPointF convertEMFPLogical2Pts(QPointF in, quint16 unit);
230  double convertEMFPLogical2Pts(double in, quint16 unit);
231  QPolygonF gdip_open_curve_tangents(QPolygonF &points, double tension);
232  QPolygonF gdip_closed_curve_tangents(QPolygonF &points, double tension);
233  void append_curve(QPainterPath &path, QPolygonF &points, QPolygonF &tangents, bool type);
234  void GdipAddPathCurve(QPainterPath &path, QPolygonF &points, float tension);
235  void GdipAddPathClosedCurve(QPainterPath &path, QPolygonF &points, float tension);
236  void handleEMFPDrawImageData(QPointF p1, QPointF p2, QPointF p3, quint8 flagsH);
237  QImage getImageDataFromStyle(quint8 flagsH);
238  struct dcState
239  {
240  quint32 m_mapMode;
241  quint16 emfPlusUnit;
242  quint32 textAlignment;
243  quint32 hatchStyle;
244  quint32 brushStyle;
245  QPointF gradientStart;
246  QPointF gradientEnd;
247  double gradientAngle;
248  VGradient gradient;
249  QTransform m_WorldMap;
250  QTransform m_WorldMapEMFP;
251  bool fillRule;
252  bool backgroundMode;
253  bool arcDirection;
254  bool alphaOn;
255  double LineW;
256  QVector<double> dashArray;
257  double dashOffset;
258  Qt::PenStyle penStyle;
259  Qt::PenCapStyle penCap;
260  Qt::PenJoinStyle penJoin;
261  QString CurrColorFill;
262  QString CurrColorStroke;
263  QString CurrColorText;
264  QString backColor;
265  QString fontName;
266  QString patternName;
267  quint32 patternMode;
268  double fontSize;
269  double fontRotation;
270  double CurrStrokeTrans;
271  double CurrFillTrans;
272  FPointArray Coords;
273  FPointArray clipPath;
274  FPointArray gradientPath;
275  QPointF viewOrigin;
276  QPointF winOrigin;
277  QPointF currentPoint;
278  QPointF originEMFP;
279  quint32 hAlign;
280  quint32 vAlign;
281  quint32 fontUnit;
282  bool verticalText;
283  quint16 fontEnc;
284  quint16 fontPit;
285  quint16 fontWgt;
286  quint16 fontUdl;
287  quint16 fontStk;
288  quint16 fontIta;
289  quint16 fontOvl;
290  quint8 fontOul;
291  quint8 fontShd;
292  quint8 fontKer;
293  quint16 fontWdt;
294  };
295  QStack<dcState> dcStack;
296  QHash<quint32, dcState> dcStackEMP;
297  dcState currentDC;
298  QHash<quint32, emfStyle> emfStyleMapEMP;
299  QList<PageItem*> Elements;
300  double docWidth;
301  double docHeight;
302  double baseX, baseY;
303  double docX;
304  double docY;
305  quint32 EmfPdpiX, EmfPdpiY;
306  quint32 m_records;
307  int recordCount;
308  qint32 viewPextendX, viewPextendY;
309  qint32 winPextendX, winPextendY;
310  qint32 winOrigX, winOrigY;
311  QStringList importedColors;
312  QStringList importedPatterns;
313  bool interactive;
314  MultiProgressDialog * progressDialog;
315  bool cancel;
316  ScribusDoc* m_Doc;
317  Selection* tmpSel;
318  int importerFlags;
319  QString baseFile;
320  struct VersionCompat
321  {
322  quint16 version;
323  quint32 length;
324  };
325  struct Fraction
326  {
327  quint32 numerator;
328  quint32 denominator;
329  };
330  struct MapMode
331  {
332  VersionCompat version;
333  quint16 unit;
334  QPoint origin;
335  Fraction scaleX;
336  Fraction scaleY;
337  quint8 isSimple;
338  };
339  struct SvmHeader
340  {
341  VersionCompat versionCompat;
342  quint32 compressionMode;
343  MapMode mapMode;
344  quint32 width;
345  quint32 height;
346  quint32 actionCount;
347  };
348  enum ActionType
349  {
350  META_NULL_ACTION = 0,
351  META_PIXEL_ACTION = 100,
352  META_POINT_ACTION = 101,
353  META_LINE_ACTION = 102,
354  META_RECT_ACTION = 103,
355  META_ROUNDRECT_ACTION = 104,
356  META_ELLIPSE_ACTION = 105,
357  META_ARC_ACTION = 106,
358  META_PIE_ACTION = 107,
359  META_CHORD_ACTION = 108,
360  META_POLYLINE_ACTION = 109,
361  META_POLYGON_ACTION = 110,
362  META_POLYPOLYGON_ACTION = 111,
363  META_TEXT_ACTION = 112,
364  META_TEXTARRAY_ACTION = 113,
365  META_STRETCHTEXT_ACTION = 114,
366  META_TEXTRECT_ACTION = 115,
367  META_BMP_ACTION = 116,
368  META_BMPSCALE_ACTION = 117,
369  META_BMPSCALEPART_ACTION = 118,
370  META_BMPEX_ACTION = 119,
371  META_BMPEXSCALE_ACTION = 120,
372  META_BMPEXSCALEPART_ACTION = 121,
373  META_MASK_ACTION = 122,
374  META_MASKSCALE_ACTION = 123,
375  META_MASKSCALEPART_ACTION = 124,
376  META_GRADIENT_ACTION = 125,
377  META_HATCH_ACTION = 126,
378  META_WALLPAPER_ACTION = 127,
379  META_CLIPREGION_ACTION = 128,
380  META_ISECTRECTCLIPREGION_ACTION = 129,
381  META_ISECTREGIONCLIPREGION_ACTION = 130,
382  META_MOVECLIPREGION_ACTION = 131,
383  META_LINECOLOR_ACTION = 132,
384  META_FILLCOLOR_ACTION = 133,
385  META_TEXTCOLOR_ACTION = 134,
386  META_TEXTFILLCOLOR_ACTION = 135,
387  META_TEXTALIGN_ACTION = 136,
388  META_MAPMODE_ACTION = 137,
389  META_FONT_ACTION = 138,
390  META_PUSH_ACTION = 139,
391  META_POP_ACTION = 140,
392  META_RASTEROP_ACTION = 141,
393  META_TRANSPARENT_ACTION = 142,
394  META_EPS_ACTION = 143,
395  META_REFPOINT_ACTION = 144,
396  META_TEXTLINECOLOR_ACTION = 145,
397  META_TEXTLINE_ACTION = 146,
398  META_FLOATTRANSPARENT_ACTION = 147,
399  META_GRADIENTEX_ACTION = 148,
400  META_LAYOUTMODE_ACTION = 149,
401  META_TEXTLANGUAGE_ACTION = 150,
402  META_OVERLINECOLOR_ACTION = 151,
403  META_RENDERGRAPHIC_ACTION = 152,
404  META_COMMENT_ACTION = 512
405  };
406  enum MapUnit
407  {
408  MAP_100TH_MM,
409  MAP_10TH_MM,
410  MAP_MM,
411  MAP_CM,
412  MAP_1000TH_INCH,
413  MAP_100TH_INCH,
414  MAP_10TH_INCH,
415  MAP_INCH,
416  MAP_POINT,
417  MAP_TWIP,
418  MAP_PIXEL,
419  MAP_SYSFONT,
420  MAP_APPFONT,
421  MAP_RELATIVE,
422  MAP_LASTENUMDUMMY
423  };
424  enum GradientStyle
425  {
426  GradientStyle_LINEAR = 0,
427  GradientStyle_AXIAL = 1,
428  GradientStyle_RADIAL = 2,
429  GradientStyle_ELLIPTICAL = 3,
430  GradientStyle_SQUARE = 4,
431  GradientStyle_RECT = 5
432  };
433  enum FontPitch
434  {
435  PITCH_DONTKNOW,
436  PITCH_FIXED,
437  PITCH_VARIABLE
438  };
439  enum FontWeight
440  {
441  WEIGHT_DONTKNOW,
442  WEIGHT_THIN,
443  WEIGHT_ULTRALIGHT,
444  WEIGHT_LIGHT,
445  WEIGHT_SEMILIGHT,
446  WEIGHT_NORMAL,
447  WEIGHT_MEDIUM,
448  WEIGHT_SEMIBOLD,
449  WEIGHT_BOLD,
450  WEIGHT_ULTRABOLD,
451  WEIGHT_BLACK
452  };
453  enum FontItalic
454  {
455  ITALIC_NONE,
456  ITALIC_OBLIQUE,
457  ITALIC_NORMAL,
458  ITALIC_DONTKNOW
459  };
460  enum FontWidth
461  {
462  WIDTH_DONTKNOW,
463  WIDTH_ULTRA_CONDENSED,
464  WIDTH_EXTRA_CONDENSED,
465  WIDTH_CONDENSED,
466  WIDTH_SEMI_CONDENSED,
467  WIDTH_NORMAL,
468  WIDTH_SEMI_EXPANDED,
469  WIDTH_EXPANDED,
470  WIDTH_EXTRA_EXPANDED,
471  WIDTH_ULTRA_EXPANDED
472  };
473  enum FontStrikeout
474  {
475  STRIKEOUT_NONE,
476  STRIKEOUT_SINGLE,
477  STRIKEOUT_DOUBLE,
478  STRIKEOUT_DONTKNOW,
479  STRIKEOUT_BOLD,
480  STRIKEOUT_SLASH,
481  STRIKEOUT_X
482  };
483  enum FontUnderline
484  {
485  UNDERLINE_NONE,
486  UNDERLINE_SINGLE,
487  UNDERLINE_DOUBLE,
488  UNDERLINE_DOTTED,
489  UNDERLINE_DONTKNOW,
490  UNDERLINE_DASH,
491  UNDERLINE_LONGDASH,
492  UNDERLINE_DASHDOT,
493  UNDERLINE_DASHDOTDOT,
494  UNDERLINE_SMALLWAVE,
495  UNDERLINE_WAVE,
496  UNDERLINE_DOUBLEWAVE,
497  UNDERLINE_BOLD,
498  UNDERLINE_BOLDDOTTED,
499  UNDERLINE_BOLDDASH,
500  UNDERLINE_BOLDLONGDASH,
501  UNDERLINE_BOLDDASHDOT,
502  UNDERLINE_BOLDDASHDOTDOT,
503  UNDERLINE_BOLDWAVE
504  };
505  enum TextAlign
506  {
507  ALIGN_TOP,
508  ALIGN_BASELINE,
509  ALIGN_BOTTOM
510  };
511  SvmHeader head;
512 
513  bool inPath;
514  bool inEMFPlus;
515  bool emfPlusDual;
516  float emfPlusScale;
517  bool SerializableObject_Valid;
518  QList<ImageEffect> m_Effects;
519  quint32 m_ObjSize;
520  quint32 m_currObjSize;
521  quint16 m_objID;
522  bool seen_XGRAD_SEQ_BEGIN;
523 public slots:
524  void cancelRequested() { cancel = true; }
525 };
526 
527 #endif
Definition: importemf.h:36
SvmPlug(ScribusDoc *doc, int flags)
Create the SVM importer window.
Definition: importsvm.cpp:286
Definition: vgradient.h:78
the Document Class
Definition: scribusdoc.h:90
Definition: undomanager.h:52
Definition: pageitem.h:92
Definition: fpointarray.h:42
A simple common strings class to reduce the string count and ease the translation process a little...
Definition: commonstrings.h:48
Definition: importsvm.h:117
Definition: selection.h:34