Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
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 private:
64 void prepareBuffer();
65
66 private:
67 QIODevice *dev;
69 bool fileBackingEnabled;
70 bool fileBackingActive;
71 bool handleDirty;
72 };
73
82 QByteArray generateDashes(const QPen &pen);
84
85 struct Stroker {
86 Stroker();
87 void setPen(const QPen &pen, QPainter::RenderHints hints);
88 void strokePath(const QPainterPath &path);
90 bool first;
93 private:
94 QStroker basicStroker;
95 QDashStroker dashStroker;
96 QStrokerOps *stroker;
97 };
98
100
101 const char *toHex(ushort u, char *buffer);
102 const char *toHex(uchar u, char *buffer);
103
104}
105
106
108{
109public:
110 QPdfPage();
111
112 QList<uint> images;
113 QList<uint> graphicStates;
114 QList<uint> patterns;
115 QList<uint> fonts;
116 QList<uint> annotations;
117
118 void streamImage(int w, int h, uint object);
119
121private:
122};
123
124class QPdfWriter;
126
127class Q_GUI_EXPORT QPdfEngine : public QPaintEngine
128{
129 Q_DECLARE_PRIVATE(QPdfEngine)
130 friend class QPdfWriter;
131public:
132 // keep in sync with QPagedPaintDevice::PdfVersion and QPdfEnginePrivate::writeHeader()::mapping!
134 {
137 Version_1_6
138 };
139
140 QPdfEngine();
141 explicit QPdfEngine(QPdfEnginePrivate &d);
143
144 void setOutputFilename(const QString &filename);
145
146 void setResolution(int resolution);
147 int resolution() const;
148
149 void setPdfVersion(PdfVersion version);
150
151 void setDocumentXmpMetadata(const QByteArray &xmpMetadata);
152 QByteArray documentXmpMetadata() const;
153
154 void addFileAttachment(const QString &fileName, const QByteArray &data, const QString &mimeType);
155
156 // keep in sync with QPdfWriter
157 enum class ColorModel
158 {
159 RGB,
160 Grayscale,
161 CMYK,
162 Auto,
163 };
164
167
168 // reimplementations QPaintEngine
169 bool begin(QPaintDevice *pdev) override;
170 bool end() override;
171
172 void drawPoints(const QPointF *points, int pointCount) override;
173 void drawLines(const QLineF *lines, int lineCount) override;
174 void drawRects(const QRectF *rects, int rectCount) override;
175 void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override;
176 void drawPath (const QPainterPath & path) override;
177
178 void drawTextItem(const QPointF &p, const QTextItem &textItem) override;
179
180 void drawPixmap (const QRectF & rectangle, const QPixmap & pixmap, const QRectF & sr) override;
181 void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
182 Qt::ImageConversionFlags flags = Qt::AutoColor) override;
183 void drawTiledPixmap (const QRectF & rectangle, const QPixmap & pixmap, const QPointF & point) override;
184
185 void drawHyperlink(const QRectF &r, const QUrl &url);
186
187 void updateState(const QPaintEngineState &state) override;
188
189 int metric(QPaintDevice::PaintDeviceMetric metricType) const;
190 Type type() const override;
191 // end reimplementations QPaintEngine
192
193 // Printer stuff...
194 bool newPage();
195
196 // Page layout stuff
197 void setPageLayout(const QPageLayout &pageLayout);
198 void setPageSize(const QPageSize &pageSize);
199 void setPageOrientation(QPageLayout::Orientation orientation);
200 void setPageMargins(const QMarginsF &margins, QPageLayout::Unit units = QPageLayout::Point);
201
202 QPageLayout pageLayout() const;
203
204 void setPen();
205 void setBrush();
206 void setupGraphicsState(QPaintEngine::DirtyFlags flags);
207
208private:
209 void updateClipPath(const QPainterPath & path, Qt::ClipOperation op);
210};
211
212class Q_GUI_EXPORT QPdfEnginePrivate : public QPaintEnginePrivate
213{
214 Q_DECLARE_PUBLIC(QPdfEngine)
215public:
218
219 inline uint requestObject() { return currentObject++; }
220
221 void writeHeader();
222 void writeTail();
223
224 int addImage(const QImage &image, bool *bitmap, bool lossless, qint64 serial_no);
225 int addConstantAlphaObject(int brushAlpha, int penAlpha = 255);
226 int addBrushPattern(const QTransform &matrix, bool *specifyColor, int *gStateObject);
227
228 void drawTextItem(const QPointF &p, const QTextItemInt &ti);
229
230 QTransform pageMatrix() const;
231
232 void newPage();
233
235
238
242 QList<QPainterPath> clips;
245 bool hasPen;
252
253 QHash<QFontEngine::FaceId, QFontSubset *> fonts;
254
256
257 // the device the output is in the end streamed to.
260
261 // printer options
267
268 // Page layout: size, orientation and margins
270
271private:
272 int gradientBrush(const QBrush &b, const QTransform &matrix, int *gStateObject);
273 int generateGradientShader(const QGradient *gradient, const QTransform &matrix, bool alpha = false);
274 int generateLinearGradientShader(const QLinearGradient *lg, const QTransform &matrix, bool alpha);
275 int generateRadialGradientShader(const QRadialGradient *gradient, const QTransform &matrix, bool alpha);
276 struct ShadingFunctionResult
277 {
278 int function;
279 QPdfEngine::ColorModel colorModel;
280 void writeColorSpace(QPdf::ByteStream *stream) const;
281 };
282 ShadingFunctionResult createShadingFunction(const QGradient *gradient, int from, int to, bool reflect, bool alpha);
283
284 enum class ColorDomain {
285 Stroking,
286 NonStroking,
287 NonStrokingPattern,
288 };
289
290 QPdfEngine::ColorModel colorModelForColor(const QColor &color) const;
291 void writeColor(ColorDomain domain, const QColor &color);
292 void writeInfo();
293 int writeXmpDcumentMetaData();
294 int writeOutputIntent();
295 void writePageRoot();
296 void writeDestsRoot();
297 void writeAttachmentRoot();
298 void writeNamesRoot();
299 void writeFonts();
300 void embedFont(QFontSubset *font);
301 qreal calcUserUnit() const;
302
303 QList<int> xrefPositions;
305 int streampos;
306
307 enum class WriteImageOption
308 {
309 Monochrome,
310 Grayscale,
311 RGB,
312 CMYK,
313 };
314
315 int writeImage(const QByteArray &data, int width, int height, WriteImageOption option,
316 int maskObject, int softMaskObject, bool dct = false, bool isMono = false);
317 void writePage();
318
319 int addXrefEntry(int object, bool printostr = true);
320 void printString(QStringView string);
321 void xprintf(const char* fmt, ...);
322 inline void write(const QByteArray &data) {
323 stream->writeRawData(data.constData(), data.size());
324 streampos += data.size();
325 }
326
327 int writeCompressed(const char *src, int len);
328 inline int writeCompressed(const QByteArray &data) { return writeCompressed(data.constData(), data.size()); }
329 int writeCompressed(QIODevice *dev);
330
331 struct AttachmentInfo
332 {
333 AttachmentInfo (const QString &fileName, const QByteArray &data, const QString &mimeType)
338 };
339
340 struct DestInfo
341 {
342 QString anchor;
343 uint pageObj;
345 };
346
347 // various PDF objects
348 int pageRoot, namesRoot, destsRoot, attachmentsRoot, catalog, info;
349 int graphicsState;
350 int patternColorSpaceRGB;
351 int patternColorSpaceGrayscale;
352 int patternColorSpaceCMYK;
353 QList<uint> pages;
354 QHash<qint64, uint> imageCache;
355 QHash<QPair<uint, uint>, uint > alphaCache;
356 QList<DestInfo> destCache;
357 QList<AttachmentInfo> fileCache;
358 QByteArray xmpDocumentMetadata;
359};
360
362
363#endif // QT_NO_PDF
364
365#endif // QPDF_P_H
366
\inmodule QtGui
Definition qbrush.h:30
\inmodule QtCore
Definition qbytearray.h:57
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtGui
Definition qbrush.h:135
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtGui
Definition qimage.h:37
\inmodule QtCore\compares equality \compareswith equality QLine \endcompareswith
Definition qline.h:192
\inmodule QtGui
Definition qbrush.h:394
\inmodule QtCore
Definition qmargins.h:270
\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
PolygonDrawMode
\value OddEvenMode The polygon should be drawn using OddEven fill rule.
\inmodule QtGui
uint requestObject()
Definition qpdf_p.h:219
QString creator
Definition qpdf_p.h:264
QString title
Definition qpdf_p.h:263
QPageLayout m_pageLayout
Definition qpdf_p.h:269
bool needsTransform
Definition qpdf_p.h:248
QPdf::Stroker stroker
Definition qpdf_p.h:237
QList< QPainterPath > clips
Definition qpdf_p.h:242
QHash< QFontEngine::FaceId, QFontSubset * > fonts
Definition qpdf_p.h:253
QPdfEngine::PdfVersion pdfVersion
Definition qpdf_p.h:250
QPdfPage * currentPage
Definition qpdf_p.h:236
QPdfEngine::ColorModel colorModel
Definition qpdf_p.h:251
QString outputFileName
Definition qpdf_p.h:262
QPointF brushOrigin
Definition qpdf_p.h:239
QPaintDevice * pdev
Definition qpdf_p.h:255
QIODevice * outDevice
Definition qpdf_p.h:258
void setColorModel(ColorModel model)
ColorModel colorModel() const
@ Version_1_4
Definition qpdf_p.h:135
@ Version_A1b
Definition qpdf_p.h:136
~QPdfEngine()
Definition qpdf_p.h:142
QSize pageSize
Definition qpdf_p.h:120
QList< uint > patterns
Definition qpdf_p.h:114
QList< uint > fonts
Definition qpdf_p.h:115
QList< uint > images
Definition qpdf_p.h:112
void streamImage(int w, int h, uint object)
Definition qpdf.cpp:748
QList< uint > graphicStates
Definition qpdf_p.h:113
QList< uint > annotations
Definition qpdf_p.h:116
QPdfPage()
Definition qpdf.cpp:743
\inmodule QtGui
Definition qpdfwriter.h:21
ByteStream & operator<<(char chr)
Definition qpdf.cpp:201
ByteStream(bool fileBacking=false)
Definition qpdf.cpp:187
static int chunkSize()
Definition qpdf_p.h:61
QIODevice * stream()
Definition qpdf.cpp:262
static int maxMemorySize()
Definition qpdf_p.h:60
\inmodule QtGui
Definition qpen.h:28
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:217
\inmodule QtGui
Definition qbrush.h:412
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
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:177
const char * toHex(ushort u, char *buffer)
Definition qpdf.cpp:710
QByteArray generatePath(const QPainterPath &path, const QTransform &matrix, PathFlags flags)
Definition qpdf.cpp:303
PathFlags
Definition qpdf_p.h:74
@ StrokePath
Definition qpdf_p.h:77
@ FillAndStrokePath
Definition qpdf_p.h:78
@ FillPath
Definition qpdf_p.h:76
@ ClipPath
Definition qpdf_p.h:75
QByteArray ascii85Encode(const QByteArray &input)
Definition qpdf.cpp:654
QByteArray generateDashes(const QPen &pen)
Definition qpdf.cpp:379
QByteArray patternForBrush(const QBrush &b)
Definition qpdf.cpp:555
QByteArray generateMatrix(const QTransform &matrix)
Definition qpdf.cpp:365
Combined button and popup list for selecting options.
@ AutoColor
Definition qnamespace.h:478
ClipOperation
Definition image.cpp:4
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
EGLStreamKHR stream
const char * mimeType
GLboolean GLboolean GLboolean b
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean r
[2]
GLuint GLuint end
GLsizei const GLubyte GLsizei GLenum const void * coords
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum src
GLenum GLuint buffer
GLint GLsizei width
GLuint color
[2]
GLenum type
GLenum GLuint GLenum GLsizei const GLchar * buf
GLbitfield flags
GLfloat units
GLfloat GLfloat GLfloat GLfloat h
GLfixed GLfixed GLint GLint GLfixed points
GLuint GLfloat * val
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
GLuint GLenum matrix
GLsizei const GLchar *const * path
GLfloat GLfloat p
[1]
GLuint GLenum option
GLenum GLsizei len
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:152
QT_BEGIN_NAMESPACE const char * qt_real_to_string(qreal val, char *buf)
Definition qpdf.cpp:100
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static void setPen(QPainter *p, const QPen &defaultPen, const QTextCharFormat &chf)
unsigned char uchar
Definition qtypes.h:32
unsigned int uint
Definition qtypes.h:34
long long qint64
Definition qtypes.h:60
unsigned short ushort
Definition qtypes.h:33
double qreal
Definition qtypes.h:187
QVideoFrameFormat::PixelFormat fmt
QSqlQueryModel * model
[16]
p drawImage(offset, thumbnail)
QByteArray ba
[0]
gzip write("uncompressed data")
QUrl url("example.com")
[constructor-url-reference]
widget render & pixmap
QHostInfo info
[0]
bool first
Definition qpdf_p.h:90
bool cosmeticPen
Definition qpdf_p.h:92
ByteStream * stream
Definition qpdf_p.h:89
QTransform matrix
Definition qpdf_p.h:91
void setPen(const QPen &pen, QPainter::RenderHints hints)
Definition qpdf.cpp:613
void strokePath(const QPainterPath &path)
Definition qpdf.cpp:644
Definition moc.h:23