Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qpdf_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPDF_P_H
5#define QPDF_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/private/qtguiglobal_p.h>
19
20#ifndef QT_NO_PDF
21
22#include "QtCore/qlist.h"
23#include "QtCore/qstring.h"
24#include "private/qfontengine_p.h"
25#include "private/qfontsubset_p.h"
26#include "private/qpaintengine_p.h"
27#include "private/qstroker_p.h"
28#include "qpagelayout.h"
29
31
32const char *qt_real_to_string(qreal val, char *buf);
33const char *qt_int_to_string(int val, char *buf);
34
35namespace QPdf {
36
38 {
39 public:
40 // fileBacking means that ByteStream will buffer the contents on disk
41 // if the size exceeds a certain threshold. In this case, if a byte
42 // array was passed in, its contents may no longer correspond to the
43 // ByteStream contents.
44 explicit ByteStream(bool fileBacking = false);
45 explicit ByteStream(QByteArray *ba, bool fileBacking = false);
47 ByteStream &operator <<(char chr);
48 ByteStream &operator <<(const char *str);
53 ByteStream &operator <<(uint val) { return (*this << int(val)); }
54 ByteStream &operator <<(qint64 val) { return (*this << int(val)); }
56 // Note that the stream may be invalidated by calls that insert data.
58 void clear();
59
60 static inline int maxMemorySize() { return 100000000; }
61 static inline int chunkSize() { return 10000000; }
62
63 protected:
66
67 private:
68 void prepareBuffer();
69
70 private:
71 QIODevice *dev;
73 bool fileBackingEnabled;
74 bool fileBackingActive;
75 bool handleDirty;
76 };
77
78 enum PathFlags {
83 };
86 QByteArray generateDashes(const QPen &pen);
88
89 struct Stroker {
90 Stroker();
91 void setPen(const QPen &pen, QPainter::RenderHints hints);
92 void strokePath(const QPainterPath &path);
94 bool first;
97 private:
98 QStroker basicStroker;
99 QDashStroker dashStroker;
100 QStrokerOps *stroker;
101 };
102
104
105 const char *toHex(ushort u, char *buffer);
106 const char *toHex(uchar u, char *buffer);
107
108}
109
110
112{
113public:
114 QPdfPage();
115
121
122 void streamImage(int w, int h, uint object);
123
125private:
126};
127
128class QPdfWriter;
130
131class Q_GUI_EXPORT QPdfEngine : public QPaintEngine
132{
133 Q_DECLARE_PRIVATE(QPdfEngine)
134 friend class QPdfWriter;
135public:
136 // keep in sync with QPagedPaintDevice::PdfVersion and QPdfEnginePrivate::writeHeader()::mapping!
138 {
141 Version_1_6
142 };
143
144 QPdfEngine();
147
148 void setOutputFilename(const QString &filename);
149
150 void setResolution(int resolution);
151 int resolution() const;
152
153 void setPdfVersion(PdfVersion version);
154
155 void setDocumentXmpMetadata(const QByteArray &xmpMetadata);
156 QByteArray documentXmpMetadata() const;
157
158 void addFileAttachment(const QString &fileName, const QByteArray &data, const QString &mimeType);
159
160 // reimplementations QPaintEngine
161 bool begin(QPaintDevice *pdev) override;
162 bool end() override;
163
164 void drawPoints(const QPointF *points, int pointCount) override;
165 void drawLines(const QLineF *lines, int lineCount) override;
166 void drawRects(const QRectF *rects, int rectCount) override;
167 void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override;
168 void drawPath (const QPainterPath & path) override;
169
170 void drawTextItem(const QPointF &p, const QTextItem &textItem) override;
171
172 void drawPixmap (const QRectF & rectangle, const QPixmap & pixmap, const QRectF & sr) override;
173 void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
174 Qt::ImageConversionFlags flags = Qt::AutoColor) override;
175 void drawTiledPixmap (const QRectF & rectangle, const QPixmap & pixmap, const QPointF & point) override;
176
177 void drawHyperlink(const QRectF &r, const QUrl &url);
178
179 void updateState(const QPaintEngineState &state) override;
180
181 int metric(QPaintDevice::PaintDeviceMetric metricType) const;
182 Type type() const override;
183 // end reimplementations QPaintEngine
184
185 // Printer stuff...
186 bool newPage();
187
188 // Page layout stuff
189 void setPageLayout(const QPageLayout &pageLayout);
190 void setPageSize(const QPageSize &pageSize);
191 void setPageOrientation(QPageLayout::Orientation orientation);
192 void setPageMargins(const QMarginsF &margins, QPageLayout::Unit units = QPageLayout::Point);
193
194 QPageLayout pageLayout() const;
195
196 void setPen();
197 void setBrush();
198 void setupGraphicsState(QPaintEngine::DirtyFlags flags);
199
200private:
201 void updateClipPath(const QPainterPath & path, Qt::ClipOperation op);
202};
203
204class Q_GUI_EXPORT QPdfEnginePrivate : public QPaintEnginePrivate
205{
206 Q_DECLARE_PUBLIC(QPdfEngine)
207public:
210
211 inline uint requestObject() { return currentObject++; }
212
213 void writeHeader();
214 void writeTail();
215
216 int addImage(const QImage &image, bool *bitmap, bool lossless, qint64 serial_no);
217 int addConstantAlphaObject(int brushAlpha, int penAlpha = 255);
218 int addBrushPattern(const QTransform &matrix, bool *specifyColor, int *gStateObject);
219
220 void drawTextItem(const QPointF &p, const QTextItemInt &ti);
221
222 QTransform pageMatrix() const;
223
224 void newPage();
225
227
230
237 bool hasPen;
243
245
247
248 // the device the output is in the end streamed to.
251
252 // printer options
259
260 // Page layout: size, orientation and margins
262
263private:
264 int gradientBrush(const QBrush &b, const QTransform &matrix, int *gStateObject);
265 int generateGradientShader(const QGradient *gradient, const QTransform &matrix, bool alpha = false);
266 int generateLinearGradientShader(const QLinearGradient *lg, const QTransform &matrix, bool alpha);
267 int generateRadialGradientShader(const QRadialGradient *gradient, const QTransform &matrix, bool alpha);
268 int createShadingFunction(const QGradient *gradient, int from, int to, bool reflect, bool alpha);
269
270 void writeInfo();
271 int writeXmpDcumentMetaData();
272 int writeOutputIntent();
273 void writePageRoot();
274 void writeDestsRoot();
275 void writeAttachmentRoot();
276 void writeNamesRoot();
277 void writeFonts();
278 void embedFont(QFontSubset *font);
279 qreal calcUserUnit() const;
280
281 QList<int> xrefPositions;
283 int streampos;
284
285 int writeImage(const QByteArray &data, int width, int height, int depth,
286 int maskObject, int softMaskObject, bool dct = false, bool isMono = false);
287 void writePage();
288
289 int addXrefEntry(int object, bool printostr = true);
290 void printString(QStringView string);
291 void xprintf(const char* fmt, ...);
292 inline void write(const QByteArray &data) {
293 stream->writeRawData(data.constData(), data.size());
294 streampos += data.size();
295 }
296
297 int writeCompressed(const char *src, int len);
298 inline int writeCompressed(const QByteArray &data) { return writeCompressed(data.constData(), data.size()); }
299 int writeCompressed(QIODevice *dev);
300
301 struct AttachmentInfo
302 {
303 AttachmentInfo (const QString &fileName, const QByteArray &data, const QString &mimeType)
308 };
309
310 struct DestInfo
311 {
312 QString anchor;
313 uint pageObj;
315 };
316
317 // various PDF objects
318 int pageRoot, namesRoot, destsRoot, attachmentsRoot, catalog, info;
319 int graphicsState, patternColorSpace;
320 QList<uint> pages;
321 QHash<qint64, uint> imageCache;
322 QHash<QPair<uint, uint>, uint > alphaCache;
323 QList<DestInfo> destCache;
324 QList<AttachmentInfo> fileCache;
325 QByteArray xmpDocumentMetadata;
326};
327
329
330#endif // QT_NO_PDF
331
332#endif // QPDF_P_H
333
\inmodule QtGui
Definition qbrush.h:30
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qdatastream.h:30
\inmodule QtGui
Definition qbrush.h:135
\inmodule QtCore
Definition qhash.h:818
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtGui
Definition qimage.h:37
\inmodule QtCore
Definition qline.h:182
\inmodule QtGui
Definition qbrush.h:394
Definition qlist.h:74
\inmodule QtCore
Definition qmargins.h:274
\inmodule QtGui
Definition qpagelayout.h:20
Unit
This enum type is used to specify the measurement unit for page layout and margins.
Definition qpagelayout.h:24
Orientation
This enum type defines the page orientation.
Definition qpagelayout.h:33
\inmodule QtGui
Definition qpagesize.h:22
The QPaintEngineState class provides information about the active paint engine's current state....
\inmodule QtGui
virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
Reimplement this function to draw the pixmap in the given rect, starting at the given p.
virtual void drawRects(const QRect *rects, int rectCount)
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual void updateState(const QPaintEngineState &state)=0
Reimplement this function to update the state of a paint engine.
virtual void drawLines(const QLine *lines, int lineCount)
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.
virtual void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the buffer points.
virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)=0
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.
virtual 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...
virtual bool begin(QPaintDevice *pdev)=0
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
virtual bool end()=0
Reimplement this function to finish painting on the current paint device.
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
virtual void drawPath(const QPainterPath &path)
The default implementation ignores the path and does nothing.
\inmodule QtGui
uint requestObject()
Definition qpdf_p.h:211
QString creator
Definition qpdf_p.h:255
QString title
Definition qpdf_p.h:254
QPageLayout m_pageLayout
Definition qpdf_p.h:261
bool needsTransform
Definition qpdf_p.h:240
QPdf::Stroker stroker
Definition qpdf_p.h:229
QList< QPainterPath > clips
Definition qpdf_p.h:234
QHash< QFontEngine::FaceId, QFontSubset * > fonts
Definition qpdf_p.h:244
QPdfEngine::PdfVersion pdfVersion
Definition qpdf_p.h:242
QPdfPage * currentPage
Definition qpdf_p.h:228
QString outputFileName
Definition qpdf_p.h:253
QPointF brushOrigin
Definition qpdf_p.h:231
QPaintDevice * pdev
Definition qpdf_p.h:246
QIODevice * outDevice
Definition qpdf_p.h:249
@ Version_1_4
Definition qpdf_p.h:139
@ Version_A1b
Definition qpdf_p.h:140
~QPdfEngine()
Definition qpdf_p.h:146
QSize pageSize
Definition qpdf_p.h:124
QList< uint > patterns
Definition qpdf_p.h:118
QList< uint > fonts
Definition qpdf_p.h:119
QList< uint > images
Definition qpdf_p.h:116
void streamImage(int w, int h, uint object)
Definition qpdf.cpp:753
QList< uint > graphicStates
Definition qpdf_p.h:117
QList< uint > annotations
Definition qpdf_p.h:120
QPdfPage()
Definition qpdf.cpp:748
\inmodule QtGui
Definition qpdfwriter.h:21
ByteStream & operator<<(char chr)
Definition qpdf.cpp:200
static int chunkSize()
Definition qpdf_p.h:61
QIODevice * stream()
Definition qpdf.cpp:261
void constructor_helper(QIODevice *dev)
static int maxMemorySize()
Definition qpdf_p.h:60
\inmodule QtGui
Definition qpen.h:25
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:214
\inmodule QtGui
Definition qbrush.h:412
\inmodule QtCore\reentrant
Definition qrect.h:483
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
Definition qstringview.h:76
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
Internal QTextItem.
\inmodule QtGui
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
\inmodule QtCore
Definition qurl.h:94
QString str
[2]
else opt state
[0]
Definition qpdf.cpp:176
const char * toHex(ushort u, char *buffer)
Definition qpdf.cpp:715
QByteArray generatePath(const QPainterPath &path, const QTransform &matrix, PathFlags flags)
Definition qpdf.cpp:308
PathFlags
Definition qpdf_p.h:78
@ StrokePath
Definition qpdf_p.h:81
@ FillAndStrokePath
Definition qpdf_p.h:82
@ FillPath
Definition qpdf_p.h:80
@ ClipPath
Definition qpdf_p.h:79
QByteArray ascii85Encode(const QByteArray &input)
Definition qpdf.cpp:659
QByteArray generateDashes(const QPen &pen)
Definition qpdf.cpp:384
QByteArray patternForBrush(const QBrush &b)
Definition qpdf.cpp:560
QByteArray generateMatrix(const QTransform &matrix)
Definition qpdf.cpp:370
Combined button and popup list for selecting options.
@ AutoColor
Definition qnamespace.h:477
ClipOperation
Definition image.cpp:4
EGLStreamKHR stream
const char * mimeType
GLboolean GLboolean GLboolean b
GLint GLenum GLsizei GLsizei GLsizei depth
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean r
[2]
GLsizei const GLubyte GLsizei GLenum const void * coords
GLenum src
GLenum GLuint buffer
GLint GLsizei width
GLenum GLuint GLenum GLsizei const GLchar * buf
GLbitfield flags
GLfloat units
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat GLfloat GLfloat h
GLfixed GLfixed GLint GLint GLfixed points
GLuint GLfloat * val
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
GLenum GLsizei len
GLuint GLenum matrix
GLsizei const GLchar *const * path
GLfloat GLfloat p
[1]
GLfloat GLfloat GLfloat alpha
Definition qopenglext.h:418
GLenum GLenum GLenum input
const char * qt_int_to_string(int val, char *buf)
Definition qpdf.cpp:151
QT_BEGIN_NAMESPACE const char * qt_real_to_string(qreal val, char *buf)
Definition qpdf.cpp:99
unsigned char uchar
Definition qtypes.h:27
unsigned int uint
Definition qtypes.h:29
long long qint64
Definition qtypes.h:55
unsigned short ushort
Definition qtypes.h:28
double qreal
Definition qtypes.h:92
QVideoFrameFormat::PixelFormat fmt
QByteArray ba
[0]
QFileInfo info(fileName)
[8]
gzip write("uncompressed data")
QUrl url("example.com")
[constructor-url-reference]
widget render & pixmap
bool first
Definition qpdf_p.h:94
bool cosmeticPen
Definition qpdf_p.h:96
ByteStream * stream
Definition qpdf_p.h:93
QTransform matrix
Definition qpdf_p.h:95
void setPen(const QPen &pen, QPainter::RenderHints hints)
Definition qpdf.cpp:618
void strokePath(const QPainterPath &path)
Definition qpdf.cpp:649
Definition moc.h:24