Replace 'i < len-1 && func(i+1)' by 'i+1 < len && func(i+1)'
[profile/ivi/qtbase.git] / src / gui / painting / qprintengine_pdf_p.h
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 ** 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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
33 **
34 **
35 **
36 **
37 **
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 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();
178     }
179
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);
183
184     // various PDF objects
185     int pageRoot, catalog, info, graphicsState, patternColorSpace;
186     QVector<uint> pages;
187     QHash<qint64, uint> imageCache;
188     QHash<QPair<uint, uint>, uint > alphaCache;
189 };
190
191 QT_END_NAMESPACE
192
193 #endif // QT_NO_PRINTER
194
195 #endif // QPRINTENGINE_PDF_P_H