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                           xpsexport.cpp  -  description
9                              -------------------
10     begin                : Sun Nov 24 08:00:00 CEST 2013
11     copyright            : (C) 2013 by Franz Schmid
12     email                : Franz.Schmid@altmuehlnet.de
13  ***************************************************************************/
14 #ifndef XPSPLUG_H
15 #define XPSPLUG_H
16 
17 #include <QObject>
18 #include <QDomElement>
19 #include <QMap>
20 #include <QSet>
21 
22 #include "pluginapi.h"
23 #include "loadsaveplugin.h"
24 #include "tableborder.h"
25 
26 class QString;
27 class QTemporaryDir;
28 class ScLayer;
29 class ScribusDoc;
30 class ScribusMainWindow;
31 class PageItem;
32 class ScPage;
33 class ScText;
34 class ScZipHandler;
35 
36 struct XPSResourceInfo
37 {
38 	QString id;
39 	QString uri;
40 };
41 
42 class PLUGIN_API XPSExportPlugin : public ScActionPlugin
43 {
44 	Q_OBJECT
45 
46 public:
47 	// Standard plugin implementation
48 	XPSExportPlugin();
49 	virtual ~XPSExportPlugin();
50 	/*!
51 	\author Franz Schmid
52 	\brief Run the XPS export
53 	\param filename a file to export to
54 	\retval bool true
55 	*/
56 	bool run(ScribusDoc* doc=nullptr, const QString& filename = QString()) override;
57 	QString fullTrName() const override;
58 	const AboutData* getAboutData() const override;
59 	void deleteAboutData(const AboutData* about) const override;
60 	void languageChange() override;
addToMainWindowMenu(ScribusMainWindow *)61 	void addToMainWindowMenu(ScribusMainWindow *) override {};
62 };
63 
64 extern "C" PLUGIN_API int xpsexplugin_getPluginAPIVersion();
65 extern "C" PLUGIN_API ScPlugin* xpsexplugin_getPlugin();
66 extern "C" PLUGIN_API void xpsexplugin_freePlugin(ScPlugin* plugin);
67 
68 class XPSExPlug : public QObject
69 {
70 	Q_OBJECT
71 
72 	friend class XPSPainter;
73 public:
74 	/*!
75 	\author Franz Schmid
76 	\brief Create the XPS exporter window
77 	\param fName QString file name
78 	 */
79 	XPSExPlug(ScribusDoc* doc, int output_res);
80 	~XPSExPlug();
81 
82 	bool doExport(const QString& fName);
83 
84 private:
85 	void writePages(QDomElement &root);
86 	void writePage(QDomElement &doc_root, QDomElement &rel_root, ScPage *Page);
87 	void writePageLayer(QDomElement &doc_root, QDomElement &rel_root, ScPage *page, ScLayer& layer);
88 	void writeItemOnPage(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root);
89 	void handleImageFallBack(PageItem *Item, QDomElement &parentElem, QDomElement &rel_root);
90 	void processPolyItem(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root);
91 	void processLineItem(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root);
92 	void processImageItem(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root);
93 	void processTextItem(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root);
94 	void processSymbolItem(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root);
95 	void processTableItem(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root);
96 	void paintBorder(const TableBorder &border, const QPointF &start, const QPointF &end, const QPointF &startOffsetFactors, const QPointF &endOffsetFactors, QDomElement &ob);
97 	void processHatchFill(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root);
98 	void processSymbolStroke(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root);
99 	void processArrows(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root);
100 	void drawArrow(double xOffset, double yOffset, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root, FPointArray &arrow);
101 	void addFontRelationship(QDomElement &rel_root, const XPSResourceInfo& fontInfo);
102 	XPSResourceInfo embedFont(const ScFace& font, QDomElement &rel_root);
103 	void getMultiStroke(struct SingleLine *sl, QDomElement &parentElem);
104 	void getStrokeStyle(PageItem *Item, QDomElement &parentElem, QDomElement &rel_root, double xOffset, double yOffset, bool forArrow = false);
105 	void getFillStyle(PageItem *Item, QDomElement &parentElem, QDomElement &rel_root, double xOffset, double yOffset, bool withTransparency = true);
106 	void handleMask(int type, PageItem *Item, QDomElement &parentElem, QDomElement &rel_root, double xOffset, double yOffset);
107 	QString setColor(const QString& farbe, int shad, double transparency);
108 	void    setClipAttr(QDomElement &elem, FPointArray *ite, bool fillRule);
109 	QString setClipPath(FPointArray *ite, bool closed);
110 	void writeDocRels();
111 	void writeCore();
112 	void writeContentType();
113 	void writeBaseRel();
114 	QString FToStr(double c);
115 	QString IToStr(int c);
116 	QString MatrixToStr(QTransform &mat);
117 	QString MatrixToStr(QTransform &mat, double factor);
118 	int hex2int(char hex);
119 	bool checkForFallback(PageItem *Item);
120 
121 	ScribusDoc* m_Doc {nullptr};
122 	QString baseDir;
123 	QDomDocument f_docu;
124 	QDomDocument p_docu;
125 	QDomDocument r_docu;
126 	double conversionFactor { 96.0 / 72.0 };
127 	int imageCounter { 0 };
128 	int fontCounter { 0 };
129 	QMap<QString, XPSResourceInfo> xps_fontMap;
130 	QSet<QString> xps_fontRel;
131 	struct txtRunItem
132 	{
133 		QChar chr;
134 		GlyphLayout* glyphs {nullptr};
135 		CharStyle style;
136 		int index {0};
137 		double CurX {0.0};
138 		PageItem* embItem {nullptr};
139 	};
140 	double m_dpi {0.0};
141 };
142 
143 #endif
144