1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
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.
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"
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)
75 const char *qt_real_to_string(qreal val, char *buf);
76 const char *qt_int_to_string(int val, char *buf);
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);
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.
101 static inline int maxMemorySize() { return 100000000; }
102 static inline int chunkSize() { return 10000000; }
105 void constructor_helper(QIODevice *dev);
106 void constructor_helper(QByteArray *ba);
109 void prepareBuffer();
114 bool fileBackingEnabled;
115 bool fileBackingActive;
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);
135 void setPen(const QPen &pen);
136 void strokePath(const QPainterPath &path);
142 QStroker basicStroker;
143 QDashStroker dashStroker;
144 QStrokerOps *stroker;
147 QByteArray ascii85Encode(const QByteArray &input);
149 const char *toHex(ushort u, char *buffer);
150 const char *toHex(uchar u, char *buffer);
154 int width, height; // in postscript points
156 PaperSize paperSize(QPrinter::PaperSize paperSize);
157 const char *paperSizeToString(QPrinter::PaperSize paperSize);
162 class QPdfPage : public QPdf::ByteStream
167 QVector<uint> images;
168 QVector<uint> graphicStates;
169 QVector<uint> patterns;
171 QVector<uint> annotations;
173 void streamImage(int w, int h, int object);
180 class QPdfBaseEnginePrivate;
182 class QPdfBaseEngine : public QAlphaPaintEngine, public QPrintEngine
184 Q_DECLARE_PRIVATE(QPdfBaseEngine)
186 QPdfBaseEngine(QPdfBaseEnginePrivate &d, PaintEngineFeatures f);
189 // reimplementations QPaintEngine
190 bool begin(QPaintDevice *pdev);
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);
199 void drawTextItem(const QPointF &p, const QTextItem &textItem);
201 void updateState(const QPaintEngineState &state);
203 int metric(QPaintDevice::PaintDeviceMetric metricType) const;
204 // end reimplementations QPaintEngine
208 void setProperty(PrintEnginePropertyKey key, const QVariant &value);
209 QVariant property(PrintEnginePropertyKey key) const;
212 virtual void setBrush() = 0;
213 void setupGraphicsState(QPaintEngine::DirtyFlags flags);
216 void updateClipPath(const QPainterPath & path, Qt::ClipOperation op);
219 class QPdfBaseEnginePrivate : public QAlphaPaintEnginePrivate
221 Q_DECLARE_PUBLIC(QPdfBaseEngine)
223 QPdfBaseEnginePrivate(QPrinter::PrinterMode m);
224 ~QPdfBaseEnginePrivate();
226 bool openPrintDevice();
227 void closePrintDevice();
230 virtual void drawTextItem(const QPointF &p, const QTextItemInt &ti);
231 inline uint requestObject() { return currentObject++; }
233 QRect paperRect() const;
234 QRect pageRect() const;
239 QPdfPage* currentPage;
240 QPdf::Stroker stroker;
245 QList<QPainterPath> clips;
254 QHash<QFontEngine::FaceId, QFontSubset *> fonts;
258 // the device the output is in the end streamed to.
259 QIODevice *outDevice;
263 QString outputFileName;
265 QString printProgram;
266 QString selectionOption;
269 QPrinter::DuplexMode duplex;
275 QPrinter::PageOrder pageOrder;
276 QPrinter::Orientation orientation;
277 QPrinter::PaperSize paperSize;
278 QPrinter::ColorMode colorMode;
279 QPrinter::PaperSource paperSource;
281 QStringList cupsOptions;
284 QString cupsStringPageSize;
285 QSizeF customPaperSize; // in postscript points
286 bool hasCustomPageMargins;
287 qreal leftMargin, topMargin, rightMargin, bottomMargin;
289 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
290 QString cupsTempFile;
296 #endif // QT_NO_PRINTER