Qt 4.8
qprintengine_pdf_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
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 {
88 public:
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();
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:
119 
120  QPrinter::PrinterState state;
121 };
122 
124 {
126 public:
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:
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 
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;
189 };
190 
192 
193 #endif // QT_NO_PRINTER
194 
195 #endif // QPRINTENGINE_PDF_P_H
bool abort()
Instructs the print engine to abort the printing process.
void setAuthor(const QString &author)
static mach_timebase_info_data_t info
PrinterState
Definition: qprinter.h:119
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
PrinterMode
This enum describes the mode the printer should work in.
Definition: qprinter.h:70
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QVector< uint > pages
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QHash< QPair< uint, uint >, uint > alphaCache
QPdfEngine(QPrinter::PrinterMode m)
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
The QString class provides a Unicode character string.
Definition: qstring.h:83
QVector< int > xrefPositions
int writeCompressed(const QByteArray &data)
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
Type type() const
Reimplement this function to return the paint engine Type.
QString author() const
void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor)
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.
Definition: qpdf.cpp:1094
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void write(const QByteArray &data)
void drawTiledPixmap(const QRectF &rectangle, const QPixmap &pixmap, const QPointF &point)
Reimplement this function to draw the pixmap in the given rect, starting at the given p...
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
void setDevice(QIODevice *dev)
Internal QTextItem.
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
QPrinter::PrinterState printerState() const
Returns the current state of the printer being used by the print engine.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
__int64 qint64
Definition: qglobal.h:942
void drawPixmap(const QRectF &rectangle, const QPixmap &pixmap, const QRectF &sr)
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r...
virtual ~QPdfEngine()
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
QHash< qint64, uint > imageCache
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
bool newPage()
Instructs the print engine to start a new page.
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
bool end()
Reimplement this function to finish painting on the current paint device.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
QPrinter::PrinterState state
#define class
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
int writeRawData(const char *, int len)
Writes len bytes from s to the stream.
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
bool begin(QPaintDevice *pdev)
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...