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 QPRINTENGINE_PDF_P_H
|
---|
43 | #define QPRINTENGINE_PDF_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 |
|
---|
56 | #include "QtGui/qprintengine.h"
|
---|
57 |
|
---|
58 | #ifndef QT_NO_PRINTER
|
---|
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"
|
---|
66 |
|
---|
67 | #include "private/qfontengine_p.h"
|
---|
68 | #include "private/qpdf_p.h"
|
---|
69 | #include "private/qpaintengine_p.h"
|
---|
70 |
|
---|
71 | QT_BEGIN_NAMESPACE
|
---|
72 |
|
---|
73 | // #define USE_NATIVE_GRADIENTS
|
---|
74 |
|
---|
75 | class QImage;
|
---|
76 | class QDataStream;
|
---|
77 | class QPen;
|
---|
78 | class QPointF;
|
---|
79 | class QRegion;
|
---|
80 | class QFile;
|
---|
81 | class QPdfEngine;
|
---|
82 |
|
---|
83 | class QPdfEnginePrivate;
|
---|
84 |
|
---|
85 | class QPdfEngine : public QPdfBaseEngine
|
---|
86 | {
|
---|
87 | Q_DECLARE_PRIVATE(QPdfEngine)
|
---|
88 | public:
|
---|
89 | QPdfEngine(QPrinter::PrinterMode m);
|
---|
90 | virtual ~QPdfEngine();
|
---|
91 |
|
---|
92 | // reimplementations QPaintEngine
|
---|
93 | bool begin(QPaintDevice *pdev);
|
---|
94 | bool end();
|
---|
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);
|
---|
99 |
|
---|
100 | Type type() const;
|
---|
101 | // end reimplementations QPaintEngine
|
---|
102 |
|
---|
103 | // reimplementations QPrintEngine
|
---|
104 | bool abort() {return false;}
|
---|
105 | bool newPage();
|
---|
106 | QPrinter::PrinterState printerState() const {return state;}
|
---|
107 | // end reimplementations QPrintEngine
|
---|
108 |
|
---|
109 | void setBrush();
|
---|
110 |
|
---|
111 | // ### unused, should have something for this in QPrintEngine
|
---|
112 | void setAuthor(const QString &author);
|
---|
113 | QString author() const;
|
---|
114 |
|
---|
115 | void setDevice(QIODevice* dev);
|
---|
116 |
|
---|
117 | private:
|
---|
118 | Q_DISABLE_COPY(QPdfEngine)
|
---|
119 |
|
---|
120 | QPrinter::PrinterState state;
|
---|
121 | };
|
---|
122 |
|
---|
123 | class QPdfEnginePrivate : public QPdfBaseEnginePrivate
|
---|
124 | {
|
---|
125 | Q_DECLARE_PUBLIC(QPdfEngine)
|
---|
126 | public:
|
---|
127 | QPdfEnginePrivate(QPrinter::PrinterMode m);
|
---|
128 | ~QPdfEnginePrivate();
|
---|
129 |
|
---|
130 | void newPage();
|
---|
131 |
|
---|
132 | int width() const {
|
---|
133 | QRect r = paperRect();
|
---|
134 | return qRound(r.width()*72./resolution);
|
---|
135 | }
|
---|
136 | int height() const {
|
---|
137 | QRect r = paperRect();
|
---|
138 | return qRound(r.height()*72./resolution);
|
---|
139 | }
|
---|
140 |
|
---|
141 | void writeHeader();
|
---|
142 | void writeTail();
|
---|
143 |
|
---|
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);
|
---|
147 |
|
---|
148 | void drawTextItem(const QPointF &p, const QTextItemInt &ti);
|
---|
149 |
|
---|
150 | QTransform pageMatrix() const;
|
---|
151 |
|
---|
152 | private:
|
---|
153 | Q_DISABLE_COPY(QPdfEnginePrivate)
|
---|
154 |
|
---|
155 | #ifdef USE_NATIVE_GRADIENTS
|
---|
156 | int gradientBrush(const QBrush &b, const QMatrix &matrix, int *gStateObject);
|
---|
157 | #endif
|
---|
158 |
|
---|
159 | void writeInfo();
|
---|
160 | void writePageRoot();
|
---|
161 | void writeFonts();
|
---|
162 | void embedFont(QFontSubset *font);
|
---|
163 |
|
---|
164 | QVector<int> xrefPositions;
|
---|
165 | QDataStream* stream;
|
---|
166 | int streampos;
|
---|
167 |
|
---|
168 | int writeImage(const QByteArray &data, int width, int height, int depth,
|
---|
169 | int maskObject, int softMaskObject, bool dct = false);
|
---|
170 | void writePage();
|
---|
171 |
|
---|
172 | int addXrefEntry(int object, bool printostr = true);
|
---|
173 | void xprintf(const char* fmt, ...);
|
---|
174 | inline void write(const QByteArray &data) {
|
---|
175 | stream->writeRawData(data.constData(), data.size());
|
---|
176 | streampos += data.size();
|
---|
177 | }
|
---|
178 |
|
---|
179 | int writeCompressed(const char *src, int len);
|
---|
180 | inline int writeCompressed(const QByteArray &data) { return writeCompressed(data.constData(), data.length()); }
|
---|
181 | int writeCompressed(QIODevice *dev);
|
---|
182 |
|
---|
183 | // various PDF objects
|
---|
184 | int pageRoot, catalog, info, graphicsState, patternColorSpace;
|
---|
185 | QVector<uint> pages;
|
---|
186 | QHash<qint64, uint> imageCache;
|
---|
187 | QHash<QPair<uint, uint>, uint > alphaCache;
|
---|
188 | };
|
---|
189 |
|
---|
190 | QT_END_NAMESPACE
|
---|
191 |
|
---|
192 | #endif // QT_NO_PRINTER
|
---|
193 |
|
---|
194 | #endif // QPRINTENGINE_PDF_P_H
|
---|