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 "qpagedpaintdevice_p.h"
41 #include <qpagedpaintdevice.h>
42 
43 QT_BEGIN_NAMESPACE
44 
45 // ### Qt 6: remove when the deprecated constructor is removed
46 class QDummyPagedPaintDevicePrivate : public QPagedPaintDevicePrivate
47 {
setPageLayout(const QPageLayout & newPageLayout)48     bool setPageLayout(const QPageLayout &newPageLayout) override
49     {
50         m_pageLayout = newPageLayout;
51         return m_pageLayout.isEquivalentTo(newPageLayout);
52     }
53 
setPageSize(const QPageSize & pageSize)54     bool setPageSize(const QPageSize &pageSize) override
55     {
56         m_pageLayout.setPageSize(pageSize);
57         return m_pageLayout.pageSize().isEquivalentTo(pageSize);
58     }
59 
setPageOrientation(QPageLayout::Orientation orientation)60     bool setPageOrientation(QPageLayout::Orientation orientation) override
61     {
62         m_pageLayout.setOrientation(orientation);
63         return m_pageLayout.orientation() == orientation;
64     }
65 
setPageMargins(const QMarginsF & margins,QPageLayout::Unit units)66     bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) override
67     {
68         m_pageLayout.setUnits(units);
69         m_pageLayout.setMargins(margins);
70         return m_pageLayout.margins() == margins && m_pageLayout.units() == units;
71     }
72 
pageLayout() const73     QPageLayout pageLayout() const override
74     {
75         return m_pageLayout;
76     }
77 
78     QPageLayout m_pageLayout;
79 };
80 
~QPagedPaintDevicePrivate()81 QPagedPaintDevicePrivate::~QPagedPaintDevicePrivate()
82 {
83 }
84 
85 /*!
86     \class QPagedPaintDevice
87     \inmodule QtGui
88 
89     \brief The QPagedPaintDevice class represents a paint device that supports
90     multiple pages.
91 
92     \ingroup painting
93 
94     Paged paint devices are used to generate output for printing or for formats like PDF.
95     QPdfWriter and QPrinter inherit from it.
96   */
97 
98 /*!
99   Constructs a new paged paint device.
100 
101   \deprecated
102   */
QPagedPaintDevice()103 QPagedPaintDevice::QPagedPaintDevice()
104     : d(new QDummyPagedPaintDevicePrivate)
105 {
106 }
107 
108 /*!
109     \internal
110     Constructs a new paged paint device with the derived private class.
111 */
QPagedPaintDevice(QPagedPaintDevicePrivate * dd)112 QPagedPaintDevice::QPagedPaintDevice(QPagedPaintDevicePrivate *dd)
113     : d(dd)
114 {
115 }
116 
117 /*!
118   Destroys the object.
119   */
~QPagedPaintDevice()120 QPagedPaintDevice::~QPagedPaintDevice()
121 {
122     delete d;
123 }
124 
125 /*!
126     \internal
127     Returns the QPagedPaintDevicePrivate.
128 */
dd()129 QPagedPaintDevicePrivate *QPagedPaintDevice::dd()
130 {
131     return d;
132 }
133 
134 /*!
135     \enum QPagedPaintDevice::PageSize
136 
137     This enum type lists the available page sizes as defined in the Postscript
138     PPD standard.  These values are duplicated in QPageSize and QPrinter and
139     those types and enum will be merged in Qt 6.
140 
141     The defined sizes are:
142 
143     \value A0 841 x 1189 mm
144     \value A1 594 x 841 mm
145     \value A2 420 x 594 mm
146     \value A3 297 x 420 mm
147     \value A4 210 x 297 mm, 8.26 x 11.69 inches
148     \value A5 148 x 210 mm
149     \value A6 105 x 148 mm
150     \value A7 74 x 105 mm
151     \value A8 52 x 74 mm
152     \value A9 37 x 52 mm
153     \value B0 1000 x 1414 mm
154     \value B1 707 x 1000 mm
155     \value B2 500 x 707 mm
156     \value B3 353 x 500 mm
157     \value B4 250 x 353 mm
158     \value B5 176 x 250 mm, 6.93 x 9.84 inches
159     \value B6 125 x 176 mm
160     \value B7 88 x 125 mm
161     \value B8 62 x 88 mm
162     \value B9 33 x 62 mm
163     \value B10 31 x 44 mm
164     \value C5E 163 x 229 mm
165     \value Comm10E 105 x 241 mm, U.S. Common 10 Envelope
166     \value DLE 110 x 220 mm
167     \value Executive 7.5 x 10 inches, 190.5 x 254 mm
168     \value Folio 210 x 330 mm
169     \value Ledger 431.8 x 279.4 mm
170     \value Legal 8.5 x 14 inches, 215.9 x 355.6 mm
171     \value Letter 8.5 x 11 inches, 215.9 x 279.4 mm
172     \value Tabloid 279.4 x 431.8 mm
173     \value Custom Unknown, or a user defined size.
174     \value A10
175     \value A3Extra
176     \value A4Extra
177     \value A4Plus
178     \value A4Small
179     \value A5Extra
180     \value B5Extra
181     \value JisB0
182     \value JisB1
183     \value JisB2
184     \value JisB3
185     \value JisB4
186     \value JisB5
187     \value JisB6,
188     \value JisB7
189     \value JisB8
190     \value JisB9
191     \value JisB10
192     \value AnsiA = Letter
193     \value AnsiB = Ledger
194     \value AnsiC
195     \value AnsiD
196     \value AnsiE
197     \value LegalExtra
198     \value LetterExtra
199     \value LetterPlus
200     \value LetterSmall
201     \value TabloidExtra
202     \value ArchA
203     \value ArchB
204     \value ArchC
205     \value ArchD
206     \value ArchE
207     \value Imperial7x9
208     \value Imperial8x10
209     \value Imperial9x11
210     \value Imperial9x12
211     \value Imperial10x11
212     \value Imperial10x13
213     \value Imperial10x14
214     \value Imperial12x11
215     \value Imperial15x11
216     \value ExecutiveStandard
217     \value Note
218     \value Quarto
219     \value Statement
220     \value SuperA
221     \value SuperB
222     \value Postcard
223     \value DoublePostcard
224     \value Prc16K
225     \value Prc32K
226     \value Prc32KBig
227     \value FanFoldUS
228     \value FanFoldGerman
229     \value FanFoldGermanLegal
230     \value EnvelopeB4
231     \value EnvelopeB5
232     \value EnvelopeB6
233     \value EnvelopeC0
234     \value EnvelopeC1
235     \value EnvelopeC2
236     \value EnvelopeC3
237     \value EnvelopeC4
238     \value EnvelopeC5 = C5E
239     \value EnvelopeC6
240     \value EnvelopeC65
241     \value EnvelopeC7
242     \value EnvelopeDL = DLE
243     \value Envelope9
244     \value Envelope10 = Comm10E
245     \value Envelope11
246     \value Envelope12
247     \value Envelope14
248     \value EnvelopeMonarch
249     \value EnvelopePersonal
250     \value EnvelopeChou3
251     \value EnvelopeChou4
252     \value EnvelopeInvite
253     \value EnvelopeItalian
254     \value EnvelopeKaku2
255     \value EnvelopeKaku3
256     \value EnvelopePrc1
257     \value EnvelopePrc2
258     \value EnvelopePrc3
259     \value EnvelopePrc4
260     \value EnvelopePrc5
261     \value EnvelopePrc6
262     \value EnvelopePrc7
263     \value EnvelopePrc8
264     \value EnvelopePrc9
265     \value EnvelopePrc10
266     \value EnvelopeYou4
267     \value LastPageSize = EnvelopeYou4
268     \omitvalue NPageSize
269     \omitvalue NPaperSize
270 
271     Due to historic reasons QPageSize::Executive is not the same as the standard
272     Postscript and Windows Executive size, use QPageSize::ExecutiveStandard instead.
273 
274     The Postscript standard size QPageSize::Folio is different to the Windows
275     DMPAPER_FOLIO size, use the Postscript standard size QPageSize::FanFoldGermanLegal
276     if needed.
277 */
278 
279 /*!
280   \fn bool QPagedPaintDevice::newPage()
281 
282   Starts a new page. Returns \c true on success.
283 */
284 
285 /*!
286     \enum QPagedPaintDevice::PdfVersion
287 
288     The PdfVersion enum describes the version of the PDF file that
289     is produced by QPrinter or QPdfWriter.
290 
291     \value PdfVersion_1_4 A PDF 1.4 compatible document is produced.
292 
293     \value PdfVersion_A1b A PDF/A-1b compatible document is produced.
294 
295     \value PdfVersion_1_6 A PDF 1.6 compatible document is produced.
296            This value was added in Qt 5.12.
297 */
298 
299 /*!
300   Sets the size of the a page to \a size.
301 
302   \sa setPageSizeMM()
303   */
setPageSize(PageSize size)304 void QPagedPaintDevice::setPageSize(PageSize size)
305 {
306     d->setPageSize(QPageSize(QPageSize::PageSizeId(size)));
307 }
308 
309 /*!
310   Returns the currently used page size.
311   */
pageSize() const312 QPagedPaintDevice::PageSize QPagedPaintDevice::pageSize() const
313 {
314     return PageSize(d->pageLayout().pageSize().id());
315 }
316 
317 /*!
318     \obsolete Use setPageSize(QPageSize) instead.
319     Sets the page size to \a size. \a size is specified in millimeters.
320 
321     If the size matches a standard QPagedPaintDevice::PageSize then that page
322     size will be used, otherwise QPagedPaintDevice::Custom will be set.
323 */
setPageSizeMM(const QSizeF & size)324 void QPagedPaintDevice::setPageSizeMM(const QSizeF &size)
325 {
326     d->setPageSize(QPageSize(size, QPageSize::Millimeter));
327 }
328 
329 /*!
330   \obsolete Use pageLayout().pageSize() instead.
331 
332   Returns the page size in millimeters.
333   */
pageSizeMM() const334 QSizeF QPagedPaintDevice::pageSizeMM() const
335 {
336     return d->pageLayout().pageSize().size(QPageSize::Millimeter);
337 }
338 
339 /*!
340   \obsolete Use setPageMargins(QMarginsF, QPageLayout::Unit) instead.
341   Sets the margins to be used to \a margins.
342 
343   Margins are specified in millimeters.
344 
345   The margins are purely a hint to the drawing method. They don't affect the
346   coordinate system or clipping.
347 
348   \sa margins()
349   */
setMargins(const Margins & margins)350 void QPagedPaintDevice::setMargins(const Margins &margins)
351 {
352     d->setPageMargins(QMarginsF(margins.left, margins.top, margins.right, margins.bottom), QPageLayout::Millimeter);
353 }
354 
355 /*!
356   \obsolete Use pageLayout().margins() instead.
357   Returns the current margins of the paint device. The default is 0.
358 
359   Margins are specified in millimeters.
360 
361   \sa setMargins()
362   */
margins() const363 QPagedPaintDevice::Margins QPagedPaintDevice::margins() const
364 {
365     QMarginsF margins = d->pageLayout().margins(QPageLayout::Millimeter);
366     Margins result;
367     result.left = margins.left();
368     result.top = margins.top();
369     result.right = margins.right();
370     result.bottom = margins.bottom();
371     return result;
372 }
373 
374 /*!
375     \since 5.3
376 
377     Sets the page layout to \a newPageLayout.
378 
379     You should call this before calling QPainter::begin(), or immediately
380     before calling newPage() to apply the new page layout to a new page.
381     You should not call any painting methods between a call to setPageLayout()
382     and newPage() as the wrong paint metrics may be used.
383 
384     Returns true if the page layout was successfully set to \a newPageLayout.
385 
386     \sa pageLayout()
387 */
388 
setPageLayout(const QPageLayout & newPageLayout)389 bool QPagedPaintDevice::setPageLayout(const QPageLayout &newPageLayout)
390 {
391     return d->setPageLayout(newPageLayout);
392 }
393 
394 /*!
395     \since 5.3
396 
397     Sets the page size to \a pageSize.
398 
399     To get the current QPageSize use pageLayout().pageSize().
400 
401     You should call this before calling QPainter::begin(), or immediately
402     before calling newPage() to apply the new page size to a new page.
403     You should not call any painting methods between a call to setPageSize()
404     and newPage() as the wrong paint metrics may be used.
405 
406     Returns true if the page size was successfully set to \a pageSize.
407 
408     \sa pageLayout()
409 */
410 
setPageSize(const QPageSize & pageSize)411 bool QPagedPaintDevice::setPageSize(const QPageSize &pageSize)
412 {
413     return d->setPageSize(pageSize);
414 }
415 
416 /*!
417     \since 5.3
418 
419     Sets the page \a orientation.
420 
421     The page orientation is used to define the orientation of the
422     page size when obtaining the page rect.
423 
424     You should call this before calling QPainter::begin(), or immediately
425     before calling newPage() to apply the new orientation to a new page.
426     You should not call any painting methods between a call to setPageOrientation()
427     and newPage() as the wrong paint metrics may be used.
428 
429     To get the current QPageLayout::Orientation use pageLayout().orientation().
430 
431     Returns true if the page orientation was successfully set to \a orientation.
432 
433     \sa pageLayout()
434 */
435 
setPageOrientation(QPageLayout::Orientation orientation)436 bool QPagedPaintDevice::setPageOrientation(QPageLayout::Orientation orientation)
437 {
438     return d->setPageOrientation(orientation);
439 }
440 
441 /*!
442     \since 5.3
443 
444     Set the page \a margins in the current page layout units.
445 
446     You should call this before calling QPainter::begin(), or immediately
447     before calling newPage() to apply the new margins to a new page.
448     You should not call any painting methods between a call to setPageMargins()
449     and newPage() as the wrong paint metrics may be used.
450 
451     To get the current page margins use pageLayout().margins().
452 
453     Returns true if the page margins were successfully set to \a margins.
454 
455     \sa pageLayout()
456 */
457 
setPageMargins(const QMarginsF & margins)458 bool QPagedPaintDevice::setPageMargins(const QMarginsF &margins)
459 {
460     return setPageMargins(margins, pageLayout().units());
461 }
462 
463 /*!
464     \since 5.3
465 
466     Set the page \a margins defined in the given \a units.
467 
468     You should call this before calling QPainter::begin(), or immediately
469     before calling newPage() to apply the new margins to a new page.
470     You should not call any painting methods between a call to setPageMargins()
471     and newPage() as the wrong paint metrics may be used.
472 
473     To get the current page margins use pageLayout().margins().
474 
475     Returns true if the page margins were successfully set to \a margins.
476 
477     \sa pageLayout()
478 */
479 
setPageMargins(const QMarginsF & margins,QPageLayout::Unit units)480 bool QPagedPaintDevice::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units)
481 {
482     return d->setPageMargins(margins, units);
483 }
484 
485 /*!
486     \since 5.3
487 
488     Returns the current page layout.  Use this method to access the current
489     QPageSize, QPageLayout::Orientation, QMarginsF, fullRect() and paintRect().
490 
491     Note that you cannot use the setters on the returned object, you must either
492     call the individual QPagedPaintDevice setters or use setPageLayout().
493 
494     \sa setPageLayout(), setPageSize(), setPageOrientation(), setPageMargins()
495 */
496 
pageLayout() const497 QPageLayout QPagedPaintDevice::pageLayout() const
498 {
499     return d->pageLayout();
500 }
501 
502 /*!
503     \internal
504 
505     \deprecated
506 
507     Returns the internal device page layout.
508 */
509 
devicePageLayout() const510 QPageLayout QPagedPaintDevice::devicePageLayout() const
511 {
512     qWarning("QPagedPaintDevice::devicePageLayout() is deprecated, just use QPagedPaintDevice::pageLayout()");
513     return d->pageLayout();
514 }
515 
516 /*!
517     \internal
518 
519     \deprecated
520 
521     Returns the internal device page layout.
522 */
523 
devicePageLayout()524 QPageLayout &QPagedPaintDevice::devicePageLayout()
525 {
526     qWarning("QPagedPaintDevice::devicePageLayout() is deprecated, you shouldn't be using this at all.");
527     static QPageLayout dummy;
528     return dummy;
529 }
530 
531 QT_END_NAMESPACE
532