1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QPDF_P_H
|
---|
43 | #define QPDF_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 | #include "QtGui/qmatrix.h"
|
---|
56 | #include "QtCore/qstring.h"
|
---|
57 | #include "QtCore/qvector.h"
|
---|
58 | #include "private/qstroker_p.h"
|
---|
59 | #include "private/qfontengine_p.h"
|
---|
60 | #include "QtGui/qprinter.h"
|
---|
61 | #include "private/qfontsubset_p.h"
|
---|
62 | #include "private/qpaintengine_alpha_p.h"
|
---|
63 | #include "qprintengine.h"
|
---|
64 | #include "qbuffer.h"
|
---|
65 |
|
---|
66 | #ifndef QT_NO_PRINTER
|
---|
67 |
|
---|
68 | QT_BEGIN_NAMESPACE
|
---|
69 |
|
---|
70 | #define PPK_CupsOptions QPrintEngine::PrintEnginePropertyKey(0xfe00)
|
---|
71 | #define PPK_CupsPageRect QPrintEngine::PrintEnginePropertyKey(0xfe01)
|
---|
72 | #define PPK_CupsPaperRect QPrintEngine::PrintEnginePropertyKey(0xfe02)
|
---|
73 | #define PPK_CupsStringPageSize QPrintEngine::PrintEnginePropertyKey(0xfe03)
|
---|
74 |
|
---|
75 | const char *qt_real_to_string(qreal val, char *buf);
|
---|
76 | const char *qt_int_to_string(int val, char *buf);
|
---|
77 |
|
---|
78 | namespace QPdf {
|
---|
79 |
|
---|
80 | class ByteStream
|
---|
81 | {
|
---|
82 | public:
|
---|
83 | // fileBacking means that ByteStream will buffer the contents on disk
|
---|
84 | // if the size exceeds a certain threshold. In this case, if a byte
|
---|
85 | // array was passed in, its contents may no longer correspond to the
|
---|
86 | // ByteStream contents.
|
---|
87 | explicit ByteStream(bool fileBacking = false);
|
---|
88 | explicit ByteStream(QByteArray *ba, bool fileBacking = false);
|
---|
89 | ~ByteStream();
|
---|
90 | ByteStream &operator <<(char chr);
|
---|
91 | ByteStream &operator <<(const char *str);
|
---|
92 | ByteStream &operator <<(const QByteArray &str);
|
---|
93 | ByteStream &operator <<(const ByteStream &src);
|
---|
94 | ByteStream &operator <<(qreal val);
|
---|
95 | ByteStream &operator <<(int val);
|
---|
96 | ByteStream &operator <<(const QPointF &p);
|
---|
97 | // Note that the stream may be invalidated by calls that insert data.
|
---|
98 | QIODevice *stream();
|
---|
99 | void clear();
|
---|
100 |
|
---|
101 | static inline int maxMemorySize() { return 100000000; }
|
---|
102 | static inline int chunkSize() { return 10000000; }
|
---|
103 |
|
---|
104 | protected:
|
---|
105 | void constructor_helper(QIODevice *dev);
|
---|
106 | void constructor_helper(QByteArray *ba);
|
---|
107 |
|
---|
108 | private:
|
---|
109 | void prepareBuffer();
|
---|
110 |
|
---|
111 | private:
|
---|
112 | QIODevice *dev;
|
---|
113 | QByteArray ba;
|
---|
114 | bool fileBackingEnabled;
|
---|
115 | bool fileBackingActive;
|
---|
116 | bool handleDirty;
|
---|
117 | };
|
---|
118 |
|
---|
119 | enum PathFlags {
|
---|
120 | ClipPath,
|
---|
121 | FillPath,
|
---|
122 | StrokePath,
|
---|
123 | FillAndStrokePath
|
---|
124 | };
|
---|
125 | QByteArray generatePath(const QPainterPath &path, const QTransform &matrix, PathFlags flags);
|
---|
126 | QByteArray generateMatrix(const QTransform &matrix);
|
---|
127 | QByteArray generateDashes(const QPen &pen);
|
---|
128 | QByteArray patternForBrush(const QBrush &b);
|
---|
129 | #ifdef USE_NATIVE_GRADIENTS
|
---|
130 | QByteArray generateLinearGradientShader(const QLinearGradient *lg, const QPointF *page_rect, bool alpha = false);
|
---|
131 | #endif
|
---|
132 |
|
---|
133 | struct Stroker {
|
---|
134 | Stroker();
|
---|
135 | void setPen(const QPen &pen);
|
---|
136 | void strokePath(const QPainterPath &path);
|
---|
137 | ByteStream *stream;
|
---|
138 | bool first;
|
---|
139 | QTransform matrix;
|
---|
140 | bool cosmeticPen;
|
---|
141 | private:
|
---|
142 | QStroker basicStroker;
|
---|
143 | QDashStroker dashStroker;
|
---|
144 | QStrokerOps *stroker;
|
---|
145 | };
|
---|
146 |
|
---|
147 | QByteArray ascii85Encode(const QByteArray &input);
|
---|
148 |
|
---|
149 | const char *toHex(ushort u, char *buffer);
|
---|
150 | const char *toHex(uchar u, char *buffer);
|
---|
151 |
|
---|
152 |
|
---|
153 | struct PaperSize {
|
---|
154 | int width, height; // in postscript points
|
---|
155 | };
|
---|
156 | PaperSize paperSize(QPrinter::PaperSize paperSize);
|
---|
157 | const char *paperSizeToString(QPrinter::PaperSize paperSize);
|
---|
158 |
|
---|
159 |
|
---|
160 | QByteArray stripSpecialCharacters(const QByteArray &string);
|
---|
161 | };
|
---|
162 |
|
---|
163 |
|
---|
164 | class QPdfPage : public QPdf::ByteStream
|
---|
165 | {
|
---|
166 | public:
|
---|
167 | QPdfPage();
|
---|
168 |
|
---|
169 | QVector<uint> images;
|
---|
170 | QVector<uint> graphicStates;
|
---|
171 | QVector<uint> patterns;
|
---|
172 | QVector<uint> fonts;
|
---|
173 | QVector<uint> annotations;
|
---|
174 |
|
---|
175 | void streamImage(int w, int h, int object);
|
---|
176 |
|
---|
177 | QSize pageSize;
|
---|
178 | private:
|
---|
179 | };
|
---|
180 |
|
---|
181 |
|
---|
182 | class QPdfBaseEnginePrivate;
|
---|
183 |
|
---|
184 | class QPdfBaseEngine : public QAlphaPaintEngine, public QPrintEngine
|
---|
185 | {
|
---|
186 | Q_DECLARE_PRIVATE(QPdfBaseEngine)
|
---|
187 | public:
|
---|
188 | QPdfBaseEngine(QPdfBaseEnginePrivate &d, PaintEngineFeatures f);
|
---|
189 | ~QPdfBaseEngine() {}
|
---|
190 |
|
---|
191 | // reimplementations QPaintEngine
|
---|
192 | bool begin(QPaintDevice *pdev);
|
---|
193 | bool end();
|
---|
194 |
|
---|
195 | void drawPoints(const QPointF *points, int pointCount);
|
---|
196 | void drawLines(const QLineF *lines, int lineCount);
|
---|
197 | void drawRects(const QRectF *rects, int rectCount);
|
---|
198 | void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
|
---|
199 | void drawPath (const QPainterPath & path);
|
---|
200 |
|
---|
201 | void drawTextItem(const QPointF &p, const QTextItem &textItem);
|
---|
202 |
|
---|
203 | void updateState(const QPaintEngineState &state);
|
---|
204 |
|
---|
205 | int metric(QPaintDevice::PaintDeviceMetric metricType) const;
|
---|
206 | // end reimplementations QPaintEngine
|
---|
207 |
|
---|
208 | // Printer stuff...
|
---|
209 | bool newPage();
|
---|
210 | void setProperty(PrintEnginePropertyKey key, const QVariant &value);
|
---|
211 | QVariant property(PrintEnginePropertyKey key) const;
|
---|
212 |
|
---|
213 | void setPen();
|
---|
214 | virtual void setBrush() = 0;
|
---|
215 | void setupGraphicsState(QPaintEngine::DirtyFlags flags);
|
---|
216 |
|
---|
217 | private:
|
---|
218 | void updateClipPath(const QPainterPath & path, Qt::ClipOperation op);
|
---|
219 |
|
---|
220 | friend int qt_printerRealNumCopies(QPaintEngine *);
|
---|
221 | };
|
---|
222 |
|
---|
223 | class QPdfBaseEnginePrivate : public QAlphaPaintEnginePrivate
|
---|
224 | {
|
---|
225 | Q_DECLARE_PUBLIC(QPdfBaseEngine)
|
---|
226 | public:
|
---|
227 | QPdfBaseEnginePrivate(QPrinter::PrinterMode m);
|
---|
228 | ~QPdfBaseEnginePrivate();
|
---|
229 |
|
---|
230 | bool openPrintDevice();
|
---|
231 | void closePrintDevice();
|
---|
232 |
|
---|
233 |
|
---|
234 | virtual void drawTextItem(const QPointF &p, const QTextItemInt &ti);
|
---|
235 | inline uint requestObject() { return currentObject++; }
|
---|
236 |
|
---|
237 | QRect paperRect() const;
|
---|
238 | QRect pageRect() const;
|
---|
239 |
|
---|
240 | bool postscript;
|
---|
241 | int currentObject;
|
---|
242 |
|
---|
243 | QPdfPage* currentPage;
|
---|
244 | QPdf::Stroker stroker;
|
---|
245 |
|
---|
246 | QPointF brushOrigin;
|
---|
247 | QBrush brush;
|
---|
248 | QPen pen;
|
---|
249 | QList<QPainterPath> clips;
|
---|
250 | bool clipEnabled;
|
---|
251 | bool allClipped;
|
---|
252 | bool hasPen;
|
---|
253 | bool hasBrush;
|
---|
254 | bool simplePen;
|
---|
255 | qreal opacity;
|
---|
256 | bool useAlphaEngine;
|
---|
257 |
|
---|
258 | QHash<QFontEngine::FaceId, QFontSubset *> fonts;
|
---|
259 |
|
---|
260 | QPaintDevice *pdev;
|
---|
261 |
|
---|
262 | // the device the output is in the end streamed to.
|
---|
263 | QIODevice *outDevice;
|
---|
264 | int fd;
|
---|
265 |
|
---|
266 | // printer options
|
---|
267 | QString outputFileName;
|
---|
268 | QString printerName;
|
---|
269 | QString printProgram;
|
---|
270 | QString selectionOption;
|
---|
271 | QString title;
|
---|
272 | QString creator;
|
---|
273 | QPrinter::DuplexMode duplex;
|
---|
274 | bool collate;
|
---|
275 | bool fullPage;
|
---|
276 | bool embedFonts;
|
---|
277 | int copies;
|
---|
278 | int resolution;
|
---|
279 | QPrinter::PageOrder pageOrder;
|
---|
280 | QPrinter::Orientation orientation;
|
---|
281 | QPrinter::PaperSize paperSize;
|
---|
282 | QPrinter::ColorMode colorMode;
|
---|
283 | QPrinter::PaperSource paperSource;
|
---|
284 |
|
---|
285 | QStringList cupsOptions;
|
---|
286 | QRect cupsPaperRect;
|
---|
287 | QRect cupsPageRect;
|
---|
288 | QString cupsStringPageSize;
|
---|
289 | QSizeF customPaperSize; // in postscript points
|
---|
290 | bool hasCustomPageMargins;
|
---|
291 | qreal leftMargin, topMargin, rightMargin, bottomMargin;
|
---|
292 |
|
---|
293 | #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
|
---|
294 | QString cupsTempFile;
|
---|
295 | #endif
|
---|
296 | };
|
---|
297 |
|
---|
298 | QT_END_NAMESPACE
|
---|
299 |
|
---|
300 | #endif // QT_NO_PRINTER
|
---|
301 |
|
---|
302 | #endif // QPDF_P_H
|
---|
303 |
|
---|