qpdfwriter.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qpdfwriter.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include <qpdfwriter.h>-
35-
36#ifndef QT_NO_PDF-
37-
38#include "qpagedpaintdevice_p.h"-
39#include <QtCore/private/qobject_p.h>-
40#include "private/qpdf_p.h"-
41#include <QtCore/qfile.h>-
42-
43QT_BEGIN_NAMESPACE-
44-
45class QPdfWriterPrivate : public QObjectPrivate-
46{-
47public:-
48 QPdfWriterPrivate()-
49 : QObjectPrivate()-
50 {-
51 engine = new QPdfEngine();-
52 output = 0;-
53 }
never executed: end of block
0
54 ~QPdfWriterPrivate()-
55 {-
56 delete engine;-
57 delete output;-
58 }
never executed: end of block
0
59-
60 QPdfEngine *engine;-
61 QFile *output;-
62};-
63-
64class QPdfPagedPaintDevicePrivate : public QPagedPaintDevicePrivate-
65{-
66public:-
67 QPdfPagedPaintDevicePrivate(QPdfWriterPrivate *d)-
68 : QPagedPaintDevicePrivate(), pd(d)-
69 {}
never executed: end of block
0
70-
71 virtual ~QPdfPagedPaintDevicePrivate()-
72 {}-
73-
74 bool setPageLayout(const QPageLayout &newPageLayout) Q_DECL_OVERRIDE-
75 {-
76 // Try to set the paint engine page layout-
77 pd->engine->setPageLayout(newPageLayout);-
78 // Set QPagedPaintDevice layout to match the current paint engine layout-
79 m_pageLayout = pd->engine->pageLayout();-
80 return m_pageLayout.isEquivalentTo(newPageLayout);
never executed: return m_pageLayout.isEquivalentTo(newPageLayout);
0
81 }-
82-
83 bool setPageSize(const QPageSize &pageSize) Q_DECL_OVERRIDE-
84 {-
85 // Try to set the paint engine page size-
86 pd->engine->setPageSize(pageSize);-
87 // Set QPagedPaintDevice layout to match the current paint engine layout-
88 m_pageLayout = pd->engine->pageLayout();-
89 return m_pageLayout.pageSize().isEquivalentTo(pageSize);
never executed: return m_pageLayout.pageSize().isEquivalentTo(pageSize);
0
90 }-
91-
92 bool setPageOrientation(QPageLayout::Orientation orientation) Q_DECL_OVERRIDE-
93 {-
94 // Set the print engine value-
95 pd->engine->setPageOrientation(orientation);-
96 // Set QPagedPaintDevice layout to match the current paint engine layout-
97 m_pageLayout = pd->engine->pageLayout();-
98 return m_pageLayout.orientation() == orientation;
never executed: return m_pageLayout.orientation() == orientation;
0
99 }-
100-
101 bool setPageMargins(const QMarginsF &margins) Q_DECL_OVERRIDE-
102 {-
103 return setPageMargins(margins, pageLayout().units());
never executed: return setPageMargins(margins, pageLayout().units());
0
104 }-
105-
106 bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) Q_DECL_OVERRIDE-
107 {-
108 // Try to set engine margins-
109 pd->engine->setPageMargins(margins, units);-
110 // Set QPagedPaintDevice layout to match the current paint engine layout-
111 m_pageLayout = pd->engine->pageLayout();-
112 return m_pageLayout.margins() == margins && m_pageLayout.units() == units;
never executed: return m_pageLayout.margins() == margins && m_pageLayout.units() == units;
m_pageLayout.m...s() == marginsDescription
TRUEnever evaluated
FALSEnever evaluated
m_pageLayout.units() == unitsDescription
TRUEnever evaluated
FALSEnever evaluated
0
113 }-
114-
115 QPageLayout pageLayout() const Q_DECL_OVERRIDE-
116 {-
117 return pd->engine->pageLayout();
never executed: return pd->engine->pageLayout();
0
118 }-
119-
120 QPdfWriterPrivate *pd;-
121};-
122-
123/*! \class QPdfWriter-
124 \inmodule QtGui-
125-
126 \brief The QPdfWriter class is a class to generate PDFs-
127 that can be used as a paint device.-
128-
129 \ingroup painting-
130-
131 QPdfWriter generates PDF out of a series of drawing commands using QPainter.-
132 The newPage() method can be used to create several pages.-
133 */-
134-
135/*!-
136 Constructs a PDF writer that will write the pdf to \a filename.-
137 */-
138QPdfWriter::QPdfWriter(const QString &filename)-
139 : QObject(*new QPdfWriterPrivate),-
140 QPagedPaintDevice(new QPdfPagedPaintDevicePrivate(d_func()))-
141{-
142 Q_D(QPdfWriter);-
143-
144 d->engine->setOutputFilename(filename);-
145-
146 // Set QPagedPaintDevice layout to match the current paint engine layout-
147 devicePageLayout() = d->engine->pageLayout();-
148}
never executed: end of block
0
149-
150/*!-
151 Constructs a PDF writer that will write the pdf to \a device.-
152 */-
153QPdfWriter::QPdfWriter(QIODevice *device)-
154 : QObject(*new QPdfWriterPrivate),-
155 QPagedPaintDevice(new QPdfPagedPaintDevicePrivate(d_func()))-
156{-
157 Q_D(QPdfWriter);-
158-
159 d->engine->d_func()->outDevice = device;-
160-
161 // Set QPagedPaintDevice layout to match the current paint engine layout-
162 devicePageLayout() = d->engine->pageLayout();-
163}
never executed: end of block
0
164-
165/*!-
166 Destroys the pdf writer.-
167 */-
168QPdfWriter::~QPdfWriter()-
169{-
170-
171}-
172-
173/*!-
174 Returns the title of the document.-
175 */-
176QString QPdfWriter::title() const-
177{-
178 Q_D(const QPdfWriter);-
179 return d->engine->d_func()->title;
never executed: return d->engine->d_func()->title;
0
180}-
181-
182/*!-
183 Sets the title of the document being created to \a title.-
184 */-
185void QPdfWriter::setTitle(const QString &title)-
186{-
187 Q_D(QPdfWriter);-
188 d->engine->d_func()->title = title;-
189}
never executed: end of block
0
190-
191/*!-
192 Returns the creator of the document.-
193 */-
194QString QPdfWriter::creator() const-
195{-
196 Q_D(const QPdfWriter);-
197 return d->engine->d_func()->creator;
never executed: return d->engine->d_func()->creator;
0
198}-
199-
200/*!-
201 Sets the creator of the document to \a creator.-
202 */-
203void QPdfWriter::setCreator(const QString &creator)-
204{-
205 Q_D(QPdfWriter);-
206 d->engine->d_func()->creator = creator;-
207}
never executed: end of block
0
208-
209/*!-
210 \reimp-
211 */-
212QPaintEngine *QPdfWriter::paintEngine() const-
213{-
214 Q_D(const QPdfWriter);-
215-
216 return d->engine;
never executed: return d->engine;
0
217}-
218-
219/*!-
220 \since 5.3-
221-
222 Sets the PDF \a resolution in DPI.-
223-
224 This setting affects the coordinate system as returned by, for-
225 example QPainter::viewport().-
226-
227 \sa resolution()-
228*/-
229-
230void QPdfWriter::setResolution(int resolution)-
231{-
232 Q_D(const QPdfWriter);-
233 if (resolution > 0)
resolution > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
234 d->engine->setResolution(resolution);
never executed: d->engine->setResolution(resolution);
0
235}
never executed: end of block
0
236-
237/*!-
238 \since 5.3-
239-
240 Returns the resolution of the PDF in DPI.-
241-
242 \sa setResolution()-
243*/-
244-
245int QPdfWriter::resolution() const-
246{-
247 Q_D(const QPdfWriter);-
248 return d->engine->resolution();
never executed: return d->engine->resolution();
0
249}-
250-
251// Defined in QPagedPaintDevice but non-virtual, add QPdfWriter specific doc here-
252#ifdef Q_QDOC-
253/*!-
254 \fn bool QPdfWriter::setPageLayout(const QPageLayout &newPageLayout)-
255 \since 5.3-
256-
257 Sets the PDF page layout to \a newPageLayout.-
258-
259 You should call this before calling QPainter::begin(), or immediately-
260 before calling newPage() to apply the new page layout to a new page.-
261 You should not call any painting methods between a call to setPageLayout()-
262 and newPage() as the wrong paint metrics may be used.-
263-
264 Returns true if the page layout was successfully set to \a newPageLayout.-
265-
266 \sa pageLayout()-
267*/-
268-
269/*!-
270 \fn bool QPdfWriter::setPageSize(const QPageSize &pageSize)-
271 \since 5.3-
272-
273 Sets the PDF page size to \a pageSize.-
274-
275 To get the current QPageSize use pageLayout().pageSize().-
276-
277 You should call this before calling QPainter::begin(), or immediately-
278 before calling newPage() to apply the new page size to a new page.-
279 You should not call any painting methods between a call to setPageSize()-
280 and newPage() as the wrong paint metrics may be used.-
281-
282 Returns true if the page size was successfully set to \a pageSize.-
283-
284 \sa pageLayout()-
285*/-
286-
287/*!-
288 \fn bool QPdfWriter::setPageOrientation(QPageLayout::Orientation orientation)-
289 \since 5.3-
290-
291 Sets the PDF page \a orientation.-
292-
293 The page orientation is used to define the orientation of the-
294 page size when obtaining the page rect.-
295-
296 You should call this before calling QPainter::begin(), or immediately-
297 before calling newPage() to apply the new orientation to a new page.-
298 You should not call any painting methods between a call to setPageOrientation()-
299 and newPage() as the wrong paint metrics may be used.-
300-
301 To get the current QPageLayout::Orientation use pageLayout().pageOrientation().-
302-
303 Returns true if the page orientation was successfully set to \a orientation.-
304-
305 \sa pageLayout()-
306*/-
307-
308/*!-
309 \fn bool QPdfWriter::setPageMargins(const QMarginsF &margins)-
310 \since 5.3-
311-
312 Set the PDF page \a margins in the current page layout units.-
313-
314 You should call this before calling QPainter::begin(), or immediately-
315 before calling newPage() to apply the new margins to a new page.-
316 You should not call any painting methods between a call to setPageMargins()-
317 and newPage() as the wrong paint metrics may be used.-
318-
319 To get the current page margins use pageLayout().pageMargins().-
320-
321 Returns true if the page margins were successfully set to \a margins.-
322-
323 \sa pageLayout()-
324*/-
325-
326/*!-
327 \fn bool QPdfWriter::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units)-
328 \since 5.3-
329-
330 Set the PDF page \a margins defined in the given \a units.-
331-
332 You should call this before calling QPainter::begin(), or immediately-
333 before calling newPage() to apply the new margins to a new page.-
334 You should not call any painting methods between a call to setPageMargins()-
335 and newPage() as the wrong paint metrics may be used.-
336-
337 To get the current page margins use pageLayout().pageMargins().-
338-
339 Returns true if the page margins were successfully set to \a margins.-
340-
341 \sa pageLayout()-
342*/-
343-
344/*!-
345 \fn QPageLayout QPdfWriter::pageLayout() const-
346 \since 5.3-
347-
348 Returns the current page layout. Use this method to access the current-
349 QPageSize, QPageLayout::Orientation, QMarginsF, fullRect() and paintRect().-
350-
351 Note that you cannot use the setters on the returned object, you must either-
352 call the individual QPdfWriter methods or use setPageLayout().-
353-
354 \sa setPageLayout(), setPageSize(), setPageOrientation(), setPageMargins()-
355*/-
356#endif-
357-
358/*!-
359 \reimp-
360-
361 \obsolete Use setPageSize(QPageSize(id)) instead-
362-
363 \sa setPageSize()-
364*/-
365-
366void QPdfWriter::setPageSize(PageSize size)-
367{-
368 setPageSize(QPageSize(QPageSize::PageSizeId(size)));-
369}
never executed: end of block
0
370-
371/*!-
372 \reimp-
373-
374 \obsolete Use setPageSize(QPageSize(size, QPageSize::Millimeter)) instead-
375-
376 \sa setPageSize()-
377*/-
378-
379void QPdfWriter::setPageSizeMM(const QSizeF &size)-
380{-
381 setPageSize(QPageSize(size, QPageSize::Millimeter));-
382}
never executed: end of block
0
383-
384/*!-
385 \internal-
386-
387 Returns the metric for the given \a id.-
388*/-
389int QPdfWriter::metric(PaintDeviceMetric id) const-
390{-
391 Q_D(const QPdfWriter);-
392 return d->engine->metric(id);
never executed: return d->engine->metric(id);
0
393}-
394-
395/*!-
396 \reimp-
397*/-
398bool QPdfWriter::newPage()-
399{-
400 Q_D(QPdfWriter);-
401-
402 return d->engine->newPage();
never executed: return d->engine->newPage();
0
403}-
404-
405-
406/*!-
407 \reimp-
408-
409 \obsolete Use setPageMargins(QMarginsF(l, t, r, b), QPageLayout::Millimeter) instead-
410-
411 \sa setPageMargins()-
412 */-
413void QPdfWriter::setMargins(const Margins &m)-
414{-
415 setPageMargins(QMarginsF(m.left, m.top, m.right, m.bottom), QPageLayout::Millimeter);-
416}
never executed: end of block
0
417-
418QT_END_NAMESPACE-
419-
420#endif // QT_NO_PDF-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9