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

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