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 ****************************************************************************/
42 #ifndef QPRINTENGINE_PDF_P_H
43 #define QPRINTENGINE_PDF_P_H
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.
56 #include "QtGui/qprintengine.h"
59 #include "QtCore/qmap.h"
60 #include "QtGui/qmatrix.h"
61 #include "QtCore/qstring.h"
62 #include "QtCore/qvector.h"
63 #include "QtGui/qpaintengine.h"
64 #include "QtGui/qpainterpath.h"
65 #include "QtCore/qdatastream.h"
67 #include "private/qfontengine_p.h"
68 #include "private/qpdf_p.h"
69 #include "private/qpaintengine_p.h"
73 // #define USE_NATIVE_GRADIENTS
83 class QPdfEnginePrivate;
85 class QPdfEngine : public QPdfBaseEngine
87 Q_DECLARE_PRIVATE(QPdfEngine)
89 QPdfEngine(QPrinter::PrinterMode m);
90 virtual ~QPdfEngine();
92 // reimplementations QPaintEngine
93 bool begin(QPaintDevice *pdev);
95 void drawPixmap (const QRectF & rectangle, const QPixmap & pixmap, const QRectF & sr);
96 void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
97 Qt::ImageConversionFlags flags = Qt::AutoColor);
98 void drawTiledPixmap (const QRectF & rectangle, const QPixmap & pixmap, const QPointF & point);
101 // end reimplementations QPaintEngine
103 // reimplementations QPrintEngine
104 bool abort() {return false;}
106 QPrinter::PrinterState printerState() const {return state;}
107 // end reimplementations QPrintEngine
111 // ### unused, should have something for this in QPrintEngine
112 void setAuthor(const QString &author);
113 QString author() const;
115 void setDevice(QIODevice* dev);
118 Q_DISABLE_COPY(QPdfEngine)
120 QPrinter::PrinterState state;
123 class QPdfEnginePrivate : public QPdfBaseEnginePrivate
125 Q_DECLARE_PUBLIC(QPdfEngine)
127 QPdfEnginePrivate(QPrinter::PrinterMode m);
128 ~QPdfEnginePrivate();
133 QRect r = paperRect();
134 return qRound(r.width()*72./resolution);
137 QRect r = paperRect();
138 return qRound(r.height()*72./resolution);
144 int addImage(const QImage &image, bool *bitmap, qint64 serial_no);
145 int addConstantAlphaObject(int brushAlpha, int penAlpha = 255);
146 int addBrushPattern(const QTransform &matrix, bool *specifyColor, int *gStateObject);
148 void drawTextItem(const QPointF &p, const QTextItemInt &ti);
150 QTransform pageMatrix() const;
153 Q_DISABLE_COPY(QPdfEnginePrivate)
155 #ifdef USE_NATIVE_GRADIENTS
156 int gradientBrush(const QBrush &b, const QMatrix &matrix, int *gStateObject);
160 void writePageRoot();
162 void embedFont(QFontSubset *font);
164 QVector<int> xrefPositions;
168 int writeImage(const QByteArray &data, int width, int height, int depth,
169 int maskObject, int softMaskObject, bool dct = false);
172 int addXrefEntry(int object, bool printostr = true);
173 void printString(const QString &string);
174 void xprintf(const char* fmt, ...);
175 inline void write(const QByteArray &data) {
176 stream->writeRawData(data.constData(), data.size());
177 streampos += data.size();
180 int writeCompressed(const char *src, int len);
181 inline int writeCompressed(const QByteArray &data) { return writeCompressed(data.constData(), data.length()); }
182 int writeCompressed(QIODevice *dev);
184 // various PDF objects
185 int pageRoot, catalog, info, graphicsState, patternColorSpace;
187 QHash<qint64, uint> imageCache;
188 QHash<QPair<uint, uint>, uint > alphaCache;
193 #endif // QT_NO_PRINTER
195 #endif // QPRINTENGINE_PDF_P_H