author | eckhart.koppen@nokia.com |
Wed, 31 Mar 2010 11:06:36 +0300 | |
changeset 7 | f7bc934e204c |
parent 0 | 1918ee327afb |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
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 |