Qt 4.8
qpdf_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 QPDF_P_H
43 #define QPDF_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 #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"
64 #include "qbuffer.h"
65 
66 #ifndef QT_NO_PRINTER
67 
69 
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)
74 
75 const char *qt_real_to_string(qreal val, char *buf);
76 const char *qt_int_to_string(int val, char *buf);
77 
78 namespace QPdf {
79 
80  class ByteStream
81  {
82  public:
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);
89  ~ByteStream();
90  ByteStream &operator <<(char chr);
91  ByteStream &operator <<(const char *str);
92  ByteStream &operator <<(const QByteArray &str);
93  ByteStream &operator <<(const ByteStream &src);
95  ByteStream &operator <<(int val);
96  ByteStream &operator <<(const QPointF &p);
97  // Note that the stream may be invalidated by calls that insert data.
98  QIODevice *stream();
99  void clear();
100 
101  static inline int maxMemorySize() { return 100000000; }
102  static inline int chunkSize() { return 10000000; }
103 
104  protected:
106  void constructor_helper(QByteArray *ba);
107 
108  private:
109  void prepareBuffer();
110 
111  private:
117  };
118 
119  enum PathFlags {
124  };
125  QByteArray generatePath(const QPainterPath &path, const QTransform &matrix, PathFlags flags);
126  QByteArray generateMatrix(const QTransform &matrix);
127  QByteArray generateDashes(const QPen &pen);
129 #ifdef USE_NATIVE_GRADIENTS
130  QByteArray generateLinearGradientShader(const QLinearGradient *lg, const QPointF *page_rect, bool alpha = false);
131 #endif
132 
133  struct Stroker {
134  Stroker();
135  void setPen(const QPen &pen);
136  void strokePath(const QPainterPath &path);
138  bool first;
141  private:
145  };
146 
147  QByteArray ascii85Encode(const QByteArray &input);
148 
149  const char *toHex(ushort u, char *buffer);
150  const char *toHex(uchar u, char *buffer);
151 
152 
153  struct PaperSize {
154  int width, height; // in postscript points
155  };
158 
159 }
160 
161 
163 {
164 public:
165  QPdfPage();
166 
172 
173  void streamImage(int w, int h, int object);
174 
176 private:
177 };
178 
179 
181 
183 {
185 public:
186  QPdfBaseEngine(QPdfBaseEnginePrivate &d, PaintEngineFeatures f);
188 
189  // reimplementations QPaintEngine
190  bool begin(QPaintDevice *pdev);
191  bool end();
192 
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);
198 
199  void drawTextItem(const QPointF &p, const QTextItem &textItem);
200 
201  void updateState(const QPaintEngineState &state);
202 
203  int metric(QPaintDevice::PaintDeviceMetric metricType) const;
204  // end reimplementations QPaintEngine
205 
206  // Printer stuff...
207  bool newPage();
208  void setProperty(PrintEnginePropertyKey key, const QVariant &value);
210 
211  void setPen();
212  virtual void setBrush() = 0;
213  void setupGraphicsState(QPaintEngine::DirtyFlags flags);
214 
215 private:
216  void updateClipPath(const QPainterPath & path, Qt::ClipOperation op);
217 };
218 
220 {
222 public:
225 
226  bool openPrintDevice();
227  void closePrintDevice();
228 
229 
230  virtual void drawTextItem(const QPointF &p, const QTextItemInt &ti);
231  inline uint requestObject() { return currentObject++; }
232 
233  QRect paperRect() const;
234  QRect pageRect() const;
235 
238 
241 
248  bool hasPen;
249  bool hasBrush;
250  bool simplePen;
253 
255 
257 
258  // the device the output is in the end streamed to.
260  int fd;
261 
262  // printer options
270  bool collate;
271  bool fullPage;
273  int copies;
280 
285  QSizeF customPaperSize; // in postscript points
287  qreal leftMargin, topMargin, rightMargin, bottomMargin;
288 
289 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
291 #endif
292 };
293 
295 
296 #endif // QT_NO_PRINTER
297 
298 #endif // QPDF_P_H
299 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
PathFlags
Definition: qpdf_p.h:119
QVector< uint > graphicStates
Definition: qpdf_p.h:168
PaperSize paperSize(QPrinter::PaperSize paperSize)
Definition: qpdf.cpp:905
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QStringList cupsOptions
Definition: qpdf_p.h:281
static int chunkSize()
Definition: qpdf_p.h:102
bool fileBackingEnabled
Definition: qpdf_p.h:114
QByteArray generateMatrix(const QTransform &matrix)
Definition: qpdf.cpp:334
QPrinter::Orientation orientation
Definition: qpdf_p.h:276
static int maxMemorySize()
Definition: qpdf_p.h:101
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QTransform matrix
Definition: qpdf_p.h:139
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
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
Orientation
This enum type (not to be confused with Orientation) is used to specify each page&#39;s orientation...
Definition: qprinter.h:78
const char * qt_int_to_string(int val, char *buf)
Definition: qpdf.cpp:115
QString selectionOption
Definition: qpdf_p.h:266
QPaintDevice * pdev
Definition: qpdf_p.h:256
QString cupsTempFile
Definition: qpdf_p.h:290
quint16 u
QByteArray generateDashes(const QPen &pen)
Definition: qpdf.cpp:348
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
const char * paperSizeToString(QPrinter::PaperSize paperSize)
Definition: qpdf.cpp:912
QVector< uint > fonts
Definition: qpdf_p.h:170
ByteStream(bool fileBacking=false)
Definition: qpdf.cpp:150
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
QSizeF customPaperSize
Definition: qpdf_p.h:285
QVector< uint > images
Definition: qpdf_p.h:167
QStroker basicStroker
Definition: qpdf_p.h:142
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
QPointF brushOrigin
Definition: qpdf_p.h:242
unsigned char uchar
Definition: qglobal.h:994
DuplexMode
This enum is used to indicate whether printing will occur on one or both sides of each sheet of paper...
Definition: qprinter.h:139
#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
QPrinter::PageOrder pageOrder
Definition: qpdf_p.h:275
~QPdfBaseEngine()
Definition: qpdf_p.h:187
The QPrintEngine class defines an interface for how QPrinter interacts with a given printing subsyste...
Definition: qprintengine.h:56
bool first
Definition: qpdf_p.h:138
static void drawRects(const T *rects, int n, const QTransform &transform, IDirectFBSurface *surface)
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QPdf::Stroker stroker
Definition: qpdf_p.h:240
bool fileBackingActive
Definition: qpdf_p.h:115
Internal QTextItem.
unsigned int uint
Definition: qglobal.h:996
uint requestObject()
Definition: qpdf_p.h:231
QVector< uint > patterns
Definition: qpdf_p.h:169
QByteArray ba
Definition: qpdf_p.h:113
QString printerName
Definition: qpdf_p.h:264
bool handleDirty
Definition: qpdf_p.h:116
QPrinter::DuplexMode duplex
Definition: qpdf_p.h:269
QIODevice * stream()
Definition: qpdf.cpp:225
QHash< QFontEngine::FaceId, QFontSubset * > fonts
Definition: qpdf_p.h:254
QString outputFileName
Definition: qpdf_p.h:263
const char * qt_real_to_string(qreal val, char *buf)
Definition: qpdf.cpp:63
bool hasCustomPageMargins
Definition: qpdf_p.h:286
const char * toHex(ushort u, char *buffer)
Definition: qpdf.cpp:862
QPrinter::ColorMode colorMode
Definition: qpdf_p.h:278
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
QList< QPainterPath > clips
Definition: qpdf_p.h:245
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
void prepareBuffer()
Definition: qpdf.cpp:244
QPrinter::PaperSize paperSize
Definition: qpdf_p.h:277
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush...
Definition: qbrush.h:280
unsigned short ushort
Definition: qglobal.h:995
void clear()
Definition: qpdf.cpp:232
PaperSize
This enum type specifies what paper size QPrinter should use.
Definition: qprinter.h:91
QString printProgram
Definition: qpdf_p.h:265
int key
QVector< uint > annotations
Definition: qpdf_p.h:171
QByteArray patternForBrush(const QBrush &b)
Definition: qpdf.cpp:524
const char * property
Definition: qwizard.cpp:138
ColorMode
This enum type is used to indicate whether QPrinter should print in color or not. ...
Definition: qprinter.h:100
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QSize pageSize
Definition: qpdf_p.h:175
void constructor_helper(QIODevice *dev)
QIODevice * outDevice
Definition: qpdf_p.h:259
QPdfPage * currentPage
Definition: qpdf_p.h:239
static void drawPoints(const T *points, int n, const QTransform &transform, IDirectFBSurface *surface)
Definition: qpdf.cpp:140
PageOrder
This enum type is used by QPrinter to tell the application program how to print.
Definition: qprinter.h:97
The QPaintEngineState class provides information about the active paint engine&#39;s current state...
Definition: qpaintengine.h:289
bool cosmeticPen
Definition: qpdf_p.h:140
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
QIODevice * dev
Definition: qpdf_p.h:112
QString cupsStringPageSize
Definition: qpdf_p.h:284
static void drawLines(const T *lines, int n, const QTransform &transform, IDirectFBSurface *surface)
The QTextItem class provides all the information required to draw text in a custom paint engine...
Definition: qpaintengine.h:68
QByteArray generatePath(const QPainterPath &path, const QTransform &matrix, PathFlags flags)
Definition: qpdf.cpp:272
static const KeyPair *const end
QStrokerOps * stroker
Definition: qpdf_p.h:144
ByteStream & operator<<(char chr)
Definition: qpdf.cpp:164
ByteStream * stream
Definition: qpdf_p.h:137
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
QPrinter::PaperSource paperSource
Definition: qpdf_p.h:279
PaperSource
This enum type specifies what paper source QPrinter is to use.
Definition: qprinter.h:103
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QByteArray ascii85Encode(const QByteArray &input)
Definition: qpdf.cpp:806
PrintEnginePropertyKey
This enum is used to communicate properties between the print engine and QPrinter.
Definition: qprintengine.h:60
ClipOperation
Definition: qnamespace.h:1495
QDashStroker dashStroker
Definition: qpdf_p.h:143