source: trunk/src/gui/painting/qpdf_p.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 8.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
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** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** 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 have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
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
68QT_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
75const char *qt_real_to_string(qreal val, char *buf);
76const char *qt_int_to_string(int val, char *buf);
77
78namespace 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
161
162class QPdfPage : public QPdf::ByteStream
163{
164public:
165 QPdfPage();
166
167 QVector<uint> images;
168 QVector<uint> graphicStates;
169 QVector<uint> patterns;
170 QVector<uint> fonts;
171 QVector<uint> annotations;
172
173 void streamImage(int w, int h, int object);
174
175 QSize pageSize;
176private:
177};
178
179
180class QPdfBaseEnginePrivate;
181
182class QPdfBaseEngine : public QAlphaPaintEngine, public QPrintEngine
183{
184 Q_DECLARE_PRIVATE(QPdfBaseEngine)
185public:
186 QPdfBaseEngine(QPdfBaseEnginePrivate &d, PaintEngineFeatures f);
187 ~QPdfBaseEngine() {}
188
189 // reimplementations QPaintEngine
190 bool begin(QPaintDevice *pdev);
191 bool end();
192
193 void drawPoints(const QPointF *points, int pointCount);
194 void drawLines(const QLineF *lines, int lineCount);
195 void drawRects(const QRectF *rects, int rectCount);
196 void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
197 void drawPath (const QPainterPath & path);
198
199 void drawTextItem(const QPointF &p, const QTextItem &textItem);
200
201 void updateState(const QPaintEngineState &state);
202
203 int metric(QPaintDevice::PaintDeviceMetric metricType) const;
204 // end reimplementations QPaintEngine
205
206 // Printer stuff...
207 bool newPage();
208 void setProperty(PrintEnginePropertyKey key, const QVariant &value);
209 QVariant property(PrintEnginePropertyKey key) const;
210
211 void setPen();
212 virtual void setBrush() = 0;
213 void setupGraphicsState(QPaintEngine::DirtyFlags flags);
214
215private:
216 void updateClipPath(const QPainterPath & path, Qt::ClipOperation op);
217};
218
219class QPdfBaseEnginePrivate : public QAlphaPaintEnginePrivate
220{
221 Q_DECLARE_PUBLIC(QPdfBaseEngine)
222public:
223 QPdfBaseEnginePrivate(QPrinter::PrinterMode m);
224 ~QPdfBaseEnginePrivate();
225
226 bool openPrintDevice();
227 void closePrintDevice();
228
229
230 virtual void drawTextItem(const QPointF &p, const QTextItemInt &ti);
231 inline uint requestObject() { return currentObject++; }
232
233 QRect paperRect() const;
234 QRect pageRect() const;
235
236 bool postscript;
237 int currentObject;
238
239 QPdfPage* currentPage;
240 QPdf::Stroker stroker;
241
242 QPointF brushOrigin;
243 QBrush brush;
244 QPen pen;
245 QList<QPainterPath> clips;
246 bool clipEnabled;
247 bool allClipped;
248 bool hasPen;
249 bool hasBrush;
250 bool simplePen;
251 qreal opacity;
252 bool useAlphaEngine;
253
254 QHash<QFontEngine::FaceId, QFontSubset *> fonts;
255
256 QPaintDevice *pdev;
257
258 // the device the output is in the end streamed to.
259 QIODevice *outDevice;
260 int fd;
261
262 // printer options
263 QString outputFileName;
264 QString printerName;
265 QString printProgram;
266 QString selectionOption;
267 QString title;
268 QString creator;
269 QPrinter::DuplexMode duplex;
270 bool collate;
271 bool fullPage;
272 bool embedFonts;
273 int copies;
274 int resolution;
275 QPrinter::PageOrder pageOrder;
276 QPrinter::Orientation orientation;
277 QPrinter::PaperSize paperSize;
278 QPrinter::ColorMode colorMode;
279 QPrinter::PaperSource paperSource;
280
281 QStringList cupsOptions;
282 QRect cupsPaperRect;
283 QRect cupsPageRect;
284 QString cupsStringPageSize;
285 QSizeF customPaperSize; // in postscript points
286 bool hasCustomPageMargins;
287 qreal leftMargin, topMargin, rightMargin, bottomMargin;
288
289#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined(Q_WS_PM))
290 QString cupsTempFile;
291#endif
292};
293
294QT_END_NAMESPACE
295
296#endif // QT_NO_PRINTER
297
298#endif // QPDF_P_H
299
Note: See TracBrowser for help on using the repository browser.