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                           pslib.h  -  description
9                              -------------------
10     begin                : Sat May 26 2001
11     copyright            : (C) 2001 by Franz Schmid
12     email                : Franz.Schmid@altmuehlnet.de
13  ***************************************************************************/
14 
15 /***************************************************************************
16  *                                                                         *
17  *   This program is free software; you can redistribute it and/or modify  *
18  *   it under the terms of the GNU General Public License as published by  *
19  *   the Free Software Foundation; either version 2 of the License, or     *
20  *   (at your option) any later version.                                   *
21  *                                                                         *
22  ***************************************************************************/
23 
24 #ifndef PSLIB_H
25 #define PSLIB_H
26 
27 #include <vector>
28 #include <utility>
29 
30 #include <QDataStream>
31 #include <QFile>
32 #include <QList>
33 #include <QPen>
34 #include <QString>
35 
36 #include "scribusapi.h"
37 #include "scribusstructs.h"
38 #include "colormgmt/sccolormgmtengine.h"
39 #include "tableborder.h"
40 
41 
42 class ScPage;
43 class ScribusDoc;
44 class PageItem;
45 class MultiProgressDialog;
46 class ScImage;
47 class ScLayer;
48 class PSPainter;
49 
50 /**
51   *@author Franz Schmid
52   * Diese Klasse erzeugt Postscript-Dateien
53   */
54 
55 class SCRIBUS_API PSLib : public QObject
56 {
57 	Q_OBJECT
58 
59 	friend class PSPainter;
60 
61 	public:
62 
63 		enum Optimization
64 		{
65 			OptimizeCompat = 0,
66 			OptimizeSize = 1
67 		};
68 
69 		enum OutputFormat
70 		{
71 			OutputPS = 0,
72 			OutputEPS = 1
73 		};
74 
75 		PSLib(ScribusDoc* doc, PrintOptions &options, OutputFormat outputFmt, ColorList *docColors = nullptr);
76 		virtual ~PSLib();
77 
setOptimization(Optimization opt)78 		void setOptimization (Optimization opt) { m_optimization = opt; }
setOutputFormat(OutputFormat outputFmt)79 		void setOutputFormat (OutputFormat outputFmt) { m_outputFormat = outputFmt; }
80 
81 		virtual int   createPS(const QString& outputFileName);
82 		virtual const QString& errorMessage();
83 		virtual void PS_set_Info(const QString& art, const QString& was);
84 
85 	protected:
86 		virtual void PS_Error(const QString& message);
87 		virtual void PS_Error_ImageDataWriteFailure();
88 		virtual void PS_Error_ImageLoadFailure(const QString& fileName);
89 		virtual void PS_Error_MaskLoadFailure(const QString& fileName);
90 		virtual void PS_Error_InsufficientMemory();
91 
92 		virtual bool PS_set_file(const QString& fn);
93 
94 		virtual bool PS_begin_doc( double x, double y, double width, double height, int numpage);
95 		virtual void PS_begin_page(ScPage* pg, MarginStruct* Ma, bool clipping);
96 		virtual void PS_end_page();
97 		virtual void PS_curve(double x1, double y1, double x2, double y2, double x3, double y3);
98 		virtual void PS_moveto(double x, double y);
99 		virtual void PS_lineto(double x, double y);
100 		virtual void PS_closepath();
101 		virtual void PS_translate(double x, double y);
102 		virtual void PS_scale(double x, double y);
103 		virtual void PS_rotate(double x);
104 		virtual void PS_clip(bool mu);
105 		virtual void PS_save();
106 		virtual void PS_restore();
107 		virtual void PS_setcmykcolor_fill(double c, double m, double y, double k);
108 		virtual void PS_setcmykcolor_dummy();
109 		virtual void PS_setcmykcolor_stroke(double c, double m, double y, double k);
110 		virtual void PS_setlinewidth(double w);
111 		virtual void PS_setcapjoin(Qt::PenCapStyle ca, Qt::PenJoinStyle jo);
112 		virtual void PS_setdash(Qt::PenStyle st, double offset, QVector<double> dash);
113 		virtual void PS_fill();
114 		virtual void PS_fillspot(const QString& color, double shade);
115 		virtual void PS_stroke();
116 		virtual void PS_strokespot(const QString& color, double shade);
117 		virtual void PS_fill_stroke();
118 		virtual void PS_newpath();
119 		virtual void PS_show(double x, double y);
120 		virtual void PS_showSub(uint chr, const QString& font, double size, bool stroke);
121 		virtual bool PS_image(PageItem *item, double x, double y, const QString& fn, double scalex, double scaley, const QString& Prof, bool UseEmbedded, const QString& Name = "");
122 		virtual bool PS_ImageData(PageItem *item, const QString& fn, const QString& Name, const QString& Prof, bool UseEmbedded);
123 		virtual void PS_plate(int nr, const QString& name = "");
124 		virtual void PS_setGray();
125 		virtual void PDF_Bookmark(const QString& text, uint Seite);
126 		virtual void PDF_Annotation(PageItem *item, const QString& text, double x, double y, double b, double h);
127 		virtual void PS_close();
128 		virtual void PS_insert(const QString& i);
129 		virtual void PS_TemplateStart(const QString& Name);
130 		virtual void PS_TemplateEnd();
131 		virtual void PS_UseTemplate(const QString& Name);
132 		virtual bool ProcessItem(ScPage* page, PageItem* item, uint PNr, bool master, bool embedded = false, bool useTemplate = false);
133 		virtual void ProcessPage(ScPage* page, uint PNr);
134 		virtual bool ProcessMasterPageLayer(ScPage* page, ScLayer& ll, uint PNr);
135 		virtual bool ProcessPageLayer(ScPage* a, ScLayer& ll, uint PNr);
136 		virtual void PS_HatchFill(PageItem *currItem);
137 		virtual void drawArrow(PageItem *ite, QTransform &arrowTrans, int arrowIndex);
138 		virtual void putColor(const QString& color, double shade, bool fill);
139 		virtual void putColorNoDraw(const QString& color, double shade);
140 		virtual void GetBleeds(ScPage* page, double& left, double& right);
141 		virtual void GetBleeds(ScPage* page, double& left, double& right, double& bottom, double& top);
142 		virtual void SetClipPath(const FPointArray &points, bool poly = true);
143 		virtual void SetPathAndClip(const FPointArray &points, bool clipRule);
144 		virtual void HandleBrushPattern(PageItem *item, QPainterPath &path, ScPage* a, uint PNr, bool master);
145 		virtual void HandleStrokePattern(PageItem *item);
146 		virtual void HandleMeshGradient(PageItem* item);
147 		virtual void HandlePatchMeshGradient(PageItem* item);
148 		virtual void HandleDiamondGradient(PageItem* item);
149 		virtual void HandleTensorGradient(PageItem* item);
150 		virtual void HandleGradientFillStroke(PageItem *item, bool stroke = true, bool forArrow = false);
151 		virtual void SetColor(const QString& color, double shade, double *c, double *m, double *y, double *k);
152 		virtual void SetColor(const ScColor& color, double shade, double *c, double *m, double *y, double *k);
153 		virtual void setTextSt(PageItem* ite, uint a, ScPage* pg, bool master);
154 
155 	private:
156 		void PutStream (const QString& c);
157 		void PutStream (const QByteArray& array, bool hexEnc);
158 		void PutStream (const char* in, int length, bool hexEnc);
159 
160 		bool PutImageToStream(ScImage& image, int plate);
161 		bool PutImageToStream(ScImage& image, const QByteArray& mask, int plate);
162 
163 		bool PutImageDataToStream(const QByteArray& image);
164 		bool PutInterleavedImageMaskToStream(const QByteArray& image, const QByteArray& mask, bool gray);
165 
166 		void WriteASCII85Bytes(const QByteArray& array);
167 		void WriteASCII85Bytes(const unsigned char* array, int length);
168 
169 		void paintBorder(const TableBorder& border, const QPointF& start, const QPointF& end, const QPointF& startOffsetFactors, const QPointF& endOffsetFactors);
170 
171 		ScribusDoc *m_Doc { nullptr };
172 		ScPage*      m_currentPage { nullptr };
173 		Optimization m_optimization { OptimizeCompat };
174 		OutputFormat m_outputFormat { OutputPS };
175 
176 		QString ToStr(double c);
177 		QString IToStr(int c);
178 		QString MatrixToStr(double m11, double m12, double m21, double m22, double x, double y);
179 		QString PSEncode(const QString& in);
180 		QString ErrorMessage;
181 		QString Creator;
182 		QString User;
183 		QString Title;
184 		bool GraySc { false };
185 		int  PageIndex { 0 };
186 		QString FillColor;
187 		QString StrokeColor;
188 		double LineW { 1.0 };
189 		QString FontDesc;
190 		QMap<QString, QString> FontSubsetMap;
191 		QFile Spool;
192 		QDataStream spoolStream;
193 		int  Plate { -1 };
194 		bool DoSep { false };
195 		bool fillRule { true };
196 		ScColorTransform solidTransform;
197 		QString currentSpot;
198 		ColorList colorsToUse;
199 		QString colorDesc;
200 		QString cmykCustomColors;
201 		QString docCustomColors;
202 		QMap<QString, QString> spotMap;
203 		MultiProgressDialog* progressDialog { nullptr };
204 		bool abortExport { false };
205 		PrintOptions Options;
206 
207 	protected slots:
208 		void cancelRequested();
209 };
210 
211 #endif
212