1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 John Layt <jlayt@kde.org>
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 "qpagesize.h"
41 
42 #include <QtCore/qcoreapplication.h>
43 #include <QtCore/qdebug.h>
44 #include <QtCore/qpoint.h>
45 #include <QtCore/qrect.h>
46 #include <QtCore/qsize.h>
47 #include <QtCore/qstring.h>
48 
49 QT_BEGIN_NAMESPACE
50 
51 // Define the Windows DMPAPER sizes for use in the look-up table
52 // See http://msdn.microsoft.com/en-us/library/windows/desktop/dd319099.aspx
53 
54 enum WindowsDmPaper {
55     DMPAPER_NONE                            =   0,  // Not a DMPAPER, use for sizes without a DMPAPER value
56     DMPAPER_LETTER                          =   1,
57     DMPAPER_LETTERSMALL                     =   2,
58     DMPAPER_TABLOID                         =   3,
59     DMPAPER_LEDGER                          =   4,
60     DMPAPER_LEGAL                           =   5,
61     DMPAPER_STATEMENT                       =   6,
62     DMPAPER_EXECUTIVE                       =   7,
63     DMPAPER_A3                              =   8,
64     DMPAPER_A4                              =   9,
65     DMPAPER_A4SMALL                         =  10,
66     DMPAPER_A5                              =  11,
67     DMPAPER_B4                              =  12,
68     DMPAPER_B5                              =  13,
69     DMPAPER_FOLIO                           =  14,
70     DMPAPER_QUARTO                          =  15,
71     DMPAPER_10X14                           =  16,
72     DMPAPER_11X17                           =  17,
73     DMPAPER_NOTE                            =  18,
74     DMPAPER_ENV_9                           =  19,
75     DMPAPER_ENV_10                          =  20,
76     DMPAPER_ENV_11                          =  21,
77     DMPAPER_ENV_12                          =  22,
78     DMPAPER_ENV_14                          =  23,
79     DMPAPER_CSHEET                          =  24,
80     DMPAPER_DSHEET                          =  25,
81     DMPAPER_ESHEET                          =  26,
82     DMPAPER_ENV_DL                          =  27,
83     DMPAPER_ENV_C5                          =  28,
84     DMPAPER_ENV_C3                          =  29,
85     DMPAPER_ENV_C4                          =  30,
86     DMPAPER_ENV_C6                          =  31,
87     DMPAPER_ENV_C65                         =  32,
88     DMPAPER_ENV_B4                          =  33,
89     DMPAPER_ENV_B5                          =  34,
90     DMPAPER_ENV_B6                          =  35,
91     DMPAPER_ENV_ITALY                       =  36,
92     DMPAPER_ENV_MONARCH                     =  37,
93     DMPAPER_ENV_PERSONAL                    =  38,
94     DMPAPER_FANFOLD_US                      =  39,
95     DMPAPER_FANFOLD_STD_GERMAN              =  40,
96     DMPAPER_FANFOLD_LGL_GERMAN              =  41,
97     DMPAPER_ISO_B4                          =  42,
98     DMPAPER_JAPANESE_POSTCARD               =  43,
99     DMPAPER_9X11                            =  44,
100     DMPAPER_10X11                           =  45,
101     DMPAPER_15X11                           =  46,
102     DMPAPER_ENV_INVITE                      =  47,
103     DMPAPER_RESERVED_48                     =  48,
104     DMPAPER_RESERVED_49                     =  49,
105     DMPAPER_LETTER_EXTRA                    =  50,
106     DMPAPER_LEGAL_EXTRA                     =  51,
107     DMPAPER_TABLOID_EXTRA                   =  52,
108     DMPAPER_A4_EXTRA                        =  53,
109     DMPAPER_LETTER_TRANSVERSE               =  54,
110     DMPAPER_A4_TRANSVERSE                   =  55,
111     DMPAPER_LETTER_EXTRA_TRANSVERSE         =  56,
112     DMPAPER_A_PLUS                          =  57,
113     DMPAPER_B_PLUS                          =  58,
114     DMPAPER_LETTER_PLUS                     =  59,
115     DMPAPER_A4_PLUS                         =  60,
116     DMPAPER_A5_TRANSVERSE                   =  61,
117     DMPAPER_B5_TRANSVERSE                   =  62,
118     DMPAPER_A3_EXTRA                        =  63,
119     DMPAPER_A5_EXTRA                        =  64,
120     DMPAPER_B5_EXTRA                        =  65,
121     DMPAPER_A2                              =  66,
122     DMPAPER_A3_TRANSVERSE                   =  67,
123     DMPAPER_A3_EXTRA_TRANSVERSE             =  68,
124     DMPAPER_DBL_JAPANESE_POSTCARD           =  69,
125     DMPAPER_A6                              =  70,
126     DMPAPER_JENV_KAKU2                      =  71,
127     DMPAPER_JENV_KAKU3                      =  72,
128     DMPAPER_JENV_CHOU3                      =  73,
129     DMPAPER_JENV_CHOU4                      =  74,
130     DMPAPER_LETTER_ROTATED                  =  75,
131     DMPAPER_A3_ROTATED                      =  76,
132     DMPAPER_A4_ROTATED                      =  77,
133     DMPAPER_A5_ROTATED                      =  78,
134     DMPAPER_B4_JIS_ROTATED                  =  79,
135     DMPAPER_B5_JIS_ROTATED                  =  80,
136     DMPAPER_JAPANESE_POSTCARD_ROTATED       =  81,
137     DMPAPER_DBL_JAPANESE_POSTCARD_ROTATED   =  82,
138     DMPAPER_A6_ROTATED                      =  83,
139     DMPAPER_JENV_KAKU2_ROTATED              =  84,
140     DMPAPER_JENV_KAKU3_ROTATED              =  85,
141     DMPAPER_JENV_CHOU3_ROTATED              =  86,
142     DMPAPER_JENV_CHOU4_ROTATED              =  87,
143     DMPAPER_B6_JIS                          =  88,
144     DMPAPER_B6_JIS_ROTATED                  =  89,
145     DMPAPER_12X11                           =  90,
146     DMPAPER_JENV_YOU4                       =  91,
147     DMPAPER_JENV_YOU4_ROTATED               =  92,
148     DMPAPER_P16K                            =  93,
149     DMPAPER_P32K                            =  94,
150     DMPAPER_P32KBIG                         =  95,
151     DMPAPER_PENV_1                          =  96,
152     DMPAPER_PENV_2                          =  97,
153     DMPAPER_PENV_3                          =  98,
154     DMPAPER_PENV_4                          =  99,
155     DMPAPER_PENV_5                          = 100,
156     DMPAPER_PENV_6                          = 101,
157     DMPAPER_PENV_7                          = 102,
158     DMPAPER_PENV_8                          = 103,
159     DMPAPER_PENV_9                          = 104,
160     DMPAPER_PENV_10                         = 105,
161     DMPAPER_P16K_ROTATED                    = 106,
162     DMPAPER_P32K_ROTATED                    = 107,
163     DMPAPER_P32KBIG_ROTATED                 = 108,
164     DMPAPER_PENV_1_ROTATED                  = 109,
165     DMPAPER_PENV_2_ROTATED                  = 110,
166     DMPAPER_PENV_3_ROTATED                  = 111,
167     DMPAPER_PENV_4_ROTATED                  = 112,
168     DMPAPER_PENV_5_ROTATED                  = 113,
169     DMPAPER_PENV_6_ROTATED                  = 114,
170     DMPAPER_PENV_7_ROTATED                  = 115,
171     DMPAPER_PENV_8_ROTATED                  = 116,
172     DMPAPER_PENV_9_ROTATED                  = 117,
173     DMPAPER_PENV_10_ROTATED                 = 118,
174     DMPAPER_LAST                            = DMPAPER_PENV_10_ROTATED,
175     DMPAPER_USER                            = 256
176 };
177 
178 // Conversion table for historic page size values that we don't support.
179 // These are deprecated in PPD and strongly discouraged from being used,
180 // so convert them to usable page sizes to support older print devices.
181 // The paper source orientation will be handled in the QPrintMedia class,
182 // we're only concerned about the standard size in QPageSize.
183 // _ROTATED = 90 degrees or QPageLayout::Landscape
184 // _TRANSVERSE = 180 degrees or QPageLayout::ReversePortrait
185 
186 static const int qt_windowsConversion[][2] = {
187     {DMPAPER_11X17,                         DMPAPER_TABLOID},  // = DMPAPER_LEDGER rotated
188     {DMPAPER_A3_EXTRA_TRANSVERSE,           DMPAPER_A3_EXTRA},
189     {DMPAPER_A3_ROTATED,                    DMPAPER_A3},
190     {DMPAPER_A3_TRANSVERSE,                 DMPAPER_A3},
191     {DMPAPER_A4_ROTATED,                    DMPAPER_A4},
192     {DMPAPER_A4_TRANSVERSE,                 DMPAPER_A4},
193     {DMPAPER_A5_ROTATED,                    DMPAPER_A5},
194     {DMPAPER_A5_TRANSVERSE,                 DMPAPER_A5},
195     {DMPAPER_A6_ROTATED,                    DMPAPER_A6},
196     {DMPAPER_B4_JIS_ROTATED,                DMPAPER_B4},
197     {DMPAPER_B5_JIS_ROTATED,                DMPAPER_B5},
198     {DMPAPER_B5_TRANSVERSE,                 DMPAPER_B5},
199     {DMPAPER_B6_JIS_ROTATED,                DMPAPER_B6_JIS},
200     {DMPAPER_DBL_JAPANESE_POSTCARD_ROTATED, DMPAPER_DBL_JAPANESE_POSTCARD},
201     {DMPAPER_JAPANESE_POSTCARD_ROTATED,     DMPAPER_JAPANESE_POSTCARD},
202     {DMPAPER_JENV_CHOU3_ROTATED,            DMPAPER_JENV_CHOU3},
203     {DMPAPER_JENV_CHOU4_ROTATED,            DMPAPER_JENV_CHOU4},
204     {DMPAPER_JENV_KAKU2_ROTATED,            DMPAPER_JENV_KAKU2},
205     {DMPAPER_JENV_KAKU3_ROTATED,            DMPAPER_JENV_KAKU3},
206     {DMPAPER_JENV_YOU4_ROTATED,             DMPAPER_JENV_YOU4},
207     {DMPAPER_LETTER_EXTRA_TRANSVERSE,       DMPAPER_LETTER_EXTRA},
208     {DMPAPER_LETTER_ROTATED,                DMPAPER_LETTER},
209     {DMPAPER_LETTER_TRANSVERSE,             DMPAPER_LETTER},
210     {DMPAPER_P16K_ROTATED,                  DMPAPER_P16K},
211     {DMPAPER_P32K_ROTATED,                  DMPAPER_P32K},
212     {DMPAPER_P32KBIG_ROTATED,               DMPAPER_P32KBIG},
213     {DMPAPER_PENV_1_ROTATED,                DMPAPER_PENV_1},
214     {DMPAPER_PENV_2_ROTATED,                DMPAPER_PENV_2},
215     {DMPAPER_PENV_3_ROTATED,                DMPAPER_PENV_3},
216     {DMPAPER_PENV_4_ROTATED,                DMPAPER_PENV_4},
217     {DMPAPER_PENV_5_ROTATED,                DMPAPER_PENV_5},
218     {DMPAPER_PENV_6_ROTATED,                DMPAPER_PENV_6},
219     {DMPAPER_PENV_7_ROTATED,                DMPAPER_PENV_7},
220     {DMPAPER_PENV_8_ROTATED,                DMPAPER_PENV_8},
221     {DMPAPER_PENV_9_ROTATED,                DMPAPER_PENV_9},
222     {DMPAPER_PENV_10_ROTATED,               DMPAPER_PENV_10}  // Is = DMPAPER_LAST, use as loop terminator
223 };
224 
225 // Standard sizes data
226 struct StandardPageSize {
227     QPageSize::PageSizeId id;
228     int windowsId;                  // Windows DMPAPER value
229     QPageSize::Unit definitionUnits;    // Standard definition size, e.g. ISO uses mm, ANSI uses inches
230     int widthPoints;
231     int heightPoints;
232     qreal widthMillimeters;
233     qreal heightMillimeters;
234     qreal widthInches;
235     qreal heightInches;
236     const char *mediaOption;  // PPD standard mediaOption ID
237 };
238 
239 // Standard page sizes taken from the Postscript PPD Standard v4.3
240 // See http://partners.adobe.com/public/developer/en/ps/5003.PPD_Spec_v4.3.pdf
241 // Excludes all Transverse and Rotated sizes
242 // NB! This table needs to be in sync with QPageSize::PageSizeId
243 static const StandardPageSize qt_pageSizes[] = {
244 
245     // Existing Qt sizes including ISO, US, ANSI and other standards
246     {QPageSize::A4                ,   DMPAPER_A4                   ,   QPageSize::Millimeter,    595,  842,      210  ,  297  ,       8.27,  11.69,    "A4"},
247     {QPageSize::B5                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    499,  709,      176  ,  250  ,       6.9 ,   9.8 ,    "ISOB5"},
248     {QPageSize::Letter            ,   DMPAPER_LETTER               ,   QPageSize::Inch      ,    612,  792,      215.9,  279.4,       8.5 ,  11   ,    "Letter"},
249     {QPageSize::Legal             ,   DMPAPER_LEGAL                ,   QPageSize::Inch      ,    612, 1008,      215.9,  355.6,       8.5 ,  14   ,    "Legal"},
250     {QPageSize::Executive         ,   DMPAPER_NONE                 ,   QPageSize::Inch      ,    540,  720,      190.5,  254  ,       7.5 ,  10   ,    "Executive.7.5x10in"}, // Qt size differs from Postscript / Windows
251     {QPageSize::A0                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   2384, 3370,      841  , 1189  ,      33.11,  46.81,    "A0"},
252     {QPageSize::A1                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   1684, 2384,      594  ,  841  ,      23.39,  33.11,    "A1"},
253     {QPageSize::A2                ,   DMPAPER_A2                   ,   QPageSize::Millimeter,   1191, 1684,      420  ,  594  ,      16.54,  23.39,    "A2"},
254     {QPageSize::A3                ,   DMPAPER_A3                   ,   QPageSize::Millimeter,    842, 1191,      297  ,  420  ,      11.69,  16.54,    "A3"},
255     {QPageSize::A5                ,   DMPAPER_A5                   ,   QPageSize::Millimeter,    420,  595,      148  ,  210  ,       5.83,   8.27,    "A5"},
256     {QPageSize::A6                ,   DMPAPER_A6                   ,   QPageSize::Millimeter,    297,  420,      105  ,  148  ,       4.13,   5.83,    "A6"},
257     {QPageSize::A7                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    210,  297,       74  ,  105  ,       2.91,   4.13,    "A7"},
258     {QPageSize::A8                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    148,  210,       52  ,   74  ,       2.05,   2.91,    "A8"},
259     {QPageSize::A9                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    105,  148,       37  ,   52  ,       1.46,   2.05,    "A9"},
260     {QPageSize::B0                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   2835, 4008,     1000  , 1414  ,      39.37,  55.67,    "ISOB0"},
261     {QPageSize::B1                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   2004, 2835,      707  , 1000  ,      27.83,  39.37,    "ISOB1"},
262     {QPageSize::B10               ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,     88,  125,       31  ,   44  ,       1.22,   1.73,    "ISOB10"},
263     {QPageSize::B2                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   1417, 2004,      500  ,  707  ,      19.68,  27.83,    "ISOB2"},
264     {QPageSize::B3                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   1001, 1417,      353  ,  500  ,      13.9 ,  19.68,    "ISOB3"},
265     {QPageSize::B4                ,   DMPAPER_ISO_B4               ,   QPageSize::Millimeter,    709, 1001,      250  ,  353  ,       9.84,  13.9 ,    "ISOB4"},
266     {QPageSize::B6                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    354,  499,      125  ,  176  ,       4.92,   6.93,    "ISOB6"},
267     {QPageSize::B7                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    249,  354,       88  ,  125  ,       3.46,   4.92,    "ISOB7"},
268     {QPageSize::B8                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    176,  249,       62  ,   88  ,       2.44,   3.46,    "ISOB8"},
269     {QPageSize::B9                ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    125,  176,       44  ,   62  ,       1.73,   2.44,    "ISOB9"},
270     {QPageSize::C5E               ,   DMPAPER_ENV_C5               ,   QPageSize::Millimeter,    459,  649,      162  ,  229  ,       6.38,   9.02,    "EnvC5"},
271     {QPageSize::Comm10E           ,   DMPAPER_ENV_10               ,   QPageSize::Inch      ,    297,  684,      104.8,  241.3,       4.12,   9.5 ,    "Env10"},
272     {QPageSize::DLE               ,   DMPAPER_ENV_DL               ,   QPageSize::Millimeter,    312,  624,      110  ,  220  ,       4.33,   8.66,    "EnvDL"},
273     {QPageSize::Folio             ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    595,  935,      210  ,  330  ,       8.27,  13   ,    "Folio"},
274     {QPageSize::Ledger            ,   DMPAPER_LEDGER               ,   QPageSize::Inch      ,   1224,  792,      431.8,  279.4,      17   ,  11   ,    "Ledger"},
275     {QPageSize::Tabloid           ,   DMPAPER_TABLOID              ,   QPageSize::Inch      ,    792, 1224,      279.4,  431.8,      11   ,  17   ,    "Tabloid"},
276     {QPageSize::Custom            ,   DMPAPER_USER                 ,   QPageSize::Millimeter,     -1,   -1,       -1. ,   -1  ,      -1   ,  -1   ,    "Custom"}, // Special case to keep in sync with QPageSize::PageSizeId
277 
278     // ISO Standard Sizes
279     {QPageSize::A10               ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,     73,  105,       26  ,  37   ,       1.02,   1.46,    "A10"},
280     {QPageSize::A3Extra           ,   DMPAPER_A3_EXTRA             ,   QPageSize::Millimeter,    913, 1262,      322  ,  445  ,      12.67,  17.52,    "A3Extra"},
281     {QPageSize::A4Extra           ,   DMPAPER_A4_EXTRA             ,   QPageSize::Millimeter,    667,  914,      235.5,  322.3,       9.27,  12.69,    "A4Extra"},
282     {QPageSize::A4Plus            ,   DMPAPER_A4_PLUS              ,   QPageSize::Millimeter,    595,  936,      210  ,  330  ,       8.27,  13   ,    "A4Plus"},
283     {QPageSize::A4Small           ,   DMPAPER_A4SMALL              ,   QPageSize::Millimeter,    595,  842,      210  ,  297  ,       8.27,  11.69,    "A4Small"},
284     {QPageSize::A5Extra           ,   DMPAPER_A5_EXTRA             ,   QPageSize::Millimeter,    492,  668,      174  ,  235  ,       6.85,   9.25,    "A5Extra"},
285     {QPageSize::B5Extra           ,   DMPAPER_B5_EXTRA             ,   QPageSize::Millimeter,    570,  782,      201  ,  276  ,       7.9 ,  10.8 ,    "ISOB5Extra"},
286 
287     // JIS Standard Sizes
288     {QPageSize::JisB0             ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   2920, 4127,     1030  , 1456  ,      40.55,  57.32,    "B0"},
289     {QPageSize::JisB1             ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   2064, 2920,      728  , 1030  ,      28.66,  40.55,    "B1"},
290     {QPageSize::JisB2             ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   1460, 2064,      515  ,  728  ,      20.28,  28.66,    "B2"},
291     {QPageSize::JisB3             ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   1032, 1460,      364  ,  515  ,      14.33,  20.28,    "B3"},
292     {QPageSize::JisB4             ,   DMPAPER_B4                   ,   QPageSize::Millimeter,    729, 1032,      257  ,  364  ,      10.12,  14.33,    "B4"},
293     {QPageSize::JisB5             ,   DMPAPER_B5                   ,   QPageSize::Millimeter,    516,  729,      182  ,  257  ,       7.17,  10.12,    "B5"},
294     {QPageSize::JisB6             ,   DMPAPER_B6_JIS               ,   QPageSize::Millimeter,    363,  516,      128  ,  182  ,       5.04,   7.17,    "B6"},
295     {QPageSize::JisB7             ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    258,  363,       91  ,  128  ,       3.58,   5.04,    "B7"},
296     {QPageSize::JisB8             ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    181,  258,       64  ,   91  ,       2.52,   3.58,    "B8"},
297     {QPageSize::JisB9             ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    127,  181,       45  ,   64  ,       1.77,   2.52,    "B9"},
298     {QPageSize::JisB10            ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,     91,  127,       32  ,   45  ,       1.26,   1.77,    "B10"},
299 
300     // ANSI / US Standard sizes
301     {QPageSize::AnsiC             ,   DMPAPER_NONE                 ,   QPageSize::Inch      ,   1224, 1584,      431.8,  558.8,      17   ,  22   ,    "AnsiC"},
302     {QPageSize::AnsiD             ,   DMPAPER_NONE                 ,   QPageSize::Inch      ,   1584, 2448,      558.8,  863.6,      22   ,  34   ,    "AnsiD"},
303     {QPageSize::AnsiE             ,   DMPAPER_NONE                 ,   QPageSize::Inch      ,   2448, 3168,      863.6, 1118  ,      34   ,  44   ,    "AnsiE"},
304     {QPageSize::LegalExtra        ,   DMPAPER_LEGAL_EXTRA          ,   QPageSize::Inch      ,    684, 1080,      241.3,  381  ,       9.5 ,  15   ,    "LegalExtra"},
305     {QPageSize::LetterExtra       ,   DMPAPER_LETTER_EXTRA         ,   QPageSize::Inch      ,    684,  864,      241.3,  304.8,       9.5 ,  12   ,    "LetterExtra"},
306     {QPageSize::LetterPlus        ,   DMPAPER_LETTER_PLUS          ,   QPageSize::Inch      ,    612,  914,      215.9,  322.3,       8.5 ,  12.69,    "LetterPlus"},
307     {QPageSize::LetterSmall       ,   DMPAPER_LETTERSMALL          ,   QPageSize::Inch      ,    612,  792,      215.9,  279.4,       8.5 ,  11   ,    "LetterSmall"},
308     {QPageSize::TabloidExtra      ,   DMPAPER_TABLOID_EXTRA        ,   QPageSize::Inch      ,    864, 1296,      304.8,  457.2,      12   ,  18   ,    "TabloidExtra"},
309 
310     // Architectural sizes
311     {QPageSize::ArchA             ,   DMPAPER_NONE                 ,   QPageSize::Inch      ,    648,  864,      228.6,  304.8,       9   ,  12   ,    "ARCHA"},
312     {QPageSize::ArchB             ,   DMPAPER_NONE                 ,   QPageSize::Inch      ,    864, 1296,      304.8,  457.2,      12   ,  18   ,    "ARCHB"},
313     {QPageSize::ArchC             ,   DMPAPER_CSHEET               ,   QPageSize::Inch      ,   1296, 1728,      457.2,  609.6,      18   ,  24   ,    "ARCHC"},
314     {QPageSize::ArchD             ,   DMPAPER_DSHEET               ,   QPageSize::Inch      ,   1728, 2592,      609.6,  914.4,      24   ,  36   ,    "ARCHD"},
315     {QPageSize::ArchE             ,   DMPAPER_ESHEET               ,   QPageSize::Inch      ,   2592, 3456,      914.4, 1219  ,      36   ,  48   ,    "ARCHE"},
316 
317     // Inch-based Sizes
318     {QPageSize::Imperial7x9       ,   DMPAPER_NONE                 ,   QPageSize::Inch      ,    504,  648,      177.8,  228.6,       7   ,   9   ,    "7x9"},
319     {QPageSize::Imperial8x10      ,   DMPAPER_NONE                 ,   QPageSize::Inch      ,    576,  720,      203.2,  254  ,       8   ,  10   ,    "8x10"},
320     {QPageSize::Imperial9x11      ,   DMPAPER_9X11                 ,   QPageSize::Inch      ,    648,  792,      228.6,  279.4,       9   ,  11   ,    "9x11"},
321     {QPageSize::Imperial9x12      ,   DMPAPER_NONE                 ,   QPageSize::Inch      ,    648,  864,      228.6,  304.8,       9   ,  12   ,    "9x12"},
322     {QPageSize::Imperial10x11     ,   DMPAPER_10X11                ,   QPageSize::Inch      ,    720,  792,      254  ,  279.4,      10   ,  11   ,    "10x11"},
323     {QPageSize::Imperial10x13     ,   DMPAPER_NONE                 ,   QPageSize::Inch      ,    720,  936,      254  ,  330.2,      10   ,  13   ,    "10x13"},
324     {QPageSize::Imperial10x14     ,   DMPAPER_10X14                ,   QPageSize::Inch      ,    720, 1008,      254  ,  355.6,      10   ,  14   ,    "10x14"},
325     {QPageSize::Imperial12x11     ,   DMPAPER_12X11                ,   QPageSize::Inch      ,    864,  792,      304.8,  279.4,      12   ,  11   ,    "12x11"},
326     {QPageSize::Imperial15x11     ,   DMPAPER_15X11                ,   QPageSize::Inch      ,   1080,  792,      381  ,  279.4,      15   ,  11   ,    "15x11"},
327 
328     // Other Page Sizes
329     {QPageSize::ExecutiveStandard ,   DMPAPER_EXECUTIVE            ,   QPageSize::Inch      ,    522,  756,      184.2,  266.7,       7.25,  10.5 ,    "Executive"},   // Qt size differs from Postscript / Windows
330     {QPageSize::Note              ,   DMPAPER_NOTE                 ,   QPageSize::Inch      ,    612,  792,      215.9,  279.4,       8.5 ,  11   ,    "Note"},
331     {QPageSize::Quarto            ,   DMPAPER_QUARTO               ,   QPageSize::Inch      ,    610,  780,      215.9,  275.1,       8.5 ,  10.83,    "Quarto"},
332     {QPageSize::Statement         ,   DMPAPER_STATEMENT            ,   QPageSize::Inch      ,    396,  612,      139.7,  215.9,       5.5 ,   8.5 ,    "Statement"},
333     {QPageSize::SuperA            ,   DMPAPER_A_PLUS               ,   QPageSize::Millimeter,    643, 1009,      227  ,  356  ,       8.94,  14   ,    "SuperA"},
334     {QPageSize::SuperB            ,   DMPAPER_B_PLUS               ,   QPageSize::Millimeter,    864, 1380,      305  ,  487  ,      12   ,  19.17,    "SuperB"},
335     {QPageSize::Postcard          ,   DMPAPER_JAPANESE_POSTCARD    ,   QPageSize::Millimeter,    284,  419,      100  ,  148  ,       3.94,   5.83,    "Postcard"},
336     {QPageSize::DoublePostcard    ,   DMPAPER_DBL_JAPANESE_POSTCARD,   QPageSize::Millimeter,    567,  419,      200  ,  148  ,       7.87,   5.83,    "DoublePostcard"},
337     {QPageSize::Prc16K            ,   DMPAPER_P16K                 ,   QPageSize::Millimeter,    414,  610,      146  ,  215  ,       5.75,   8.5 ,    "PRC16K"},
338     {QPageSize::Prc32K            ,   DMPAPER_P32K                 ,   QPageSize::Millimeter,    275,  428,       97  ,  151  ,       3.82,   5.95,    "PRC32K"},
339     {QPageSize::Prc32KBig         ,   DMPAPER_P32KBIG              ,   QPageSize::Millimeter,    275,  428,       97  ,  151  ,       3.82,   5.95,    "PRC32KBig"},
340 
341     // Fan Fold Sizes
342     {QPageSize::FanFoldUS         ,   DMPAPER_FANFOLD_US           ,   QPageSize::Inch      ,   1071,  792,      377.8,  279.4,      14.875, 11   ,    "FanFoldUS"},
343     {QPageSize::FanFoldGerman     ,   DMPAPER_FANFOLD_STD_GERMAN   ,   QPageSize::Inch      ,    612,  864,      215.9,  304.8,       8.5 ,  12   ,    "FanFoldGerman"},
344     {QPageSize::FanFoldGermanLegal,   DMPAPER_FANFOLD_LGL_GERMAN   ,   QPageSize::Inch      ,    612,  936,      215.9,  330  ,       8.5 ,  13   ,    "FanFoldGermanLegal"},
345 
346     // ISO Envelopes
347     {QPageSize::EnvelopeB4        ,   DMPAPER_ENV_B4               ,   QPageSize::Millimeter,    708, 1001,      250  ,  353  ,       9.84,  13.9 ,    "EnvISOB4"},
348     {QPageSize::EnvelopeB5        ,   DMPAPER_ENV_B5               ,   QPageSize::Millimeter,    499,  709,      176  ,  250  ,       6.9 ,   9.8 ,    "EnvISOB5"},
349     {QPageSize::EnvelopeB6        ,   DMPAPER_ENV_B6               ,   QPageSize::Millimeter,    499,  354,      176  ,  125  ,       6.9 ,   4.9 ,    "EnvISOB6"},
350     {QPageSize::EnvelopeC0        ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   2599, 3676,      917  ,  1297 ,      36.1 ,  51.06,    "EnvC0"},
351     {QPageSize::EnvelopeC1        ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   1837, 2599,      648  ,  917  ,      25.51,  36.1 ,    "EnvC1"},
352     {QPageSize::EnvelopeC2        ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,   1298, 1837,      458  ,  648  ,      18.03,  25.51,    "EnvC2"},
353     {QPageSize::EnvelopeC3        ,   DMPAPER_ENV_C3               ,   QPageSize::Millimeter,    918, 1296,      324  ,  458  ,      12.75,  18.03,    "EnvC3"},
354     {QPageSize::EnvelopeC4        ,   DMPAPER_ENV_C4               ,   QPageSize::Millimeter,    649,  918,      229  ,  324  ,       9.02,  12.75,    "EnvC4"},
355     {QPageSize::EnvelopeC6        ,   DMPAPER_ENV_C6               ,   QPageSize::Millimeter,    323,  459,      114  ,  162  ,       4.49,   6.38,    "EnvC6"},
356     {QPageSize::EnvelopeC65       ,   DMPAPER_ENV_C65              ,   QPageSize::Millimeter,    324,  648,      114  ,  229  ,       4.5 ,   9   ,    "EnvC65"},
357     {QPageSize::EnvelopeC7        ,   DMPAPER_NONE                 ,   QPageSize::Millimeter,    230,  323,       81  ,  114  ,       3.19,   4.49,    "EnvC7"},
358 
359     // US Envelopes
360     {QPageSize::Envelope9         ,   DMPAPER_ENV_9                ,   QPageSize::Inch      ,    279,  639,       98.4,  225.4,       3.875,  8.875,   "Env9"},
361     {QPageSize::Envelope11        ,   DMPAPER_ENV_11               ,   QPageSize::Inch      ,    324,  747,      114.3,  263.5,       4.5 ,  10.375,   "Env11"},
362     {QPageSize::Envelope12        ,   DMPAPER_ENV_12               ,   QPageSize::Inch      ,    342,  792,      120.7,  279.4,       4.75,  11   ,    "Env12"},
363     {QPageSize::Envelope14        ,   DMPAPER_ENV_14               ,   QPageSize::Inch      ,    360,  828,      127  ,  292.1,       5   ,  11.5 ,    "Env14"},
364     {QPageSize::EnvelopeMonarch   ,   DMPAPER_ENV_MONARCH          ,   QPageSize::Inch      ,    279,  540,       98.43, 190.5,       3.875,  7.5 ,    "EnvMonarch"},
365     {QPageSize::EnvelopePersonal  ,   DMPAPER_ENV_PERSONAL         ,   QPageSize::Inch      ,    261,  468,       92.08, 165.1,       3.625,  6.5 ,    "EnvPersonal"},
366 
367     // Other Envelopes
368     {QPageSize::EnvelopeChou3     ,   DMPAPER_JENV_CHOU3           ,   QPageSize::Millimeter,    340,  666,      120  ,  235  ,       4.72,   9.25,    "EnvChou3"},
369     {QPageSize::EnvelopeChou4     ,   DMPAPER_JENV_CHOU4           ,   QPageSize::Millimeter,    255,  581,       90  ,  205  ,       3.54,   8   ,    "EnvChou4"},
370     {QPageSize::EnvelopeInvite    ,   DMPAPER_ENV_INVITE           ,   QPageSize::Millimeter,    624,  624,      220  ,  220  ,       8.66,   8.66,    "EnvInvite"},
371     {QPageSize::EnvelopeItalian   ,   DMPAPER_ENV_ITALY            ,   QPageSize::Millimeter,    312,  652,      110  ,  230  ,       4.33,   9   ,    "EnvItalian"},
372     {QPageSize::EnvelopeKaku2     ,   DMPAPER_JENV_KAKU2           ,   QPageSize::Millimeter,    680,  941,      240  ,  332  ,       9.45,  13   ,    "EnvKaku2"},
373     {QPageSize::EnvelopeKaku3     ,   DMPAPER_JENV_KAKU3           ,   QPageSize::Millimeter,    612,  785,      216  ,  277  ,       8.5 ,  10.9 ,    "EnvKaku3"},
374     {QPageSize::EnvelopePrc1      ,   DMPAPER_PENV_1               ,   QPageSize::Millimeter,    289,  468,      102  ,  165  ,       4   ,   6.5 ,    "EnvPRC1"},
375     {QPageSize::EnvelopePrc2      ,   DMPAPER_PENV_2               ,   QPageSize::Millimeter,    289,  499,      102  ,  176  ,       4   ,   6.9 ,    "EnvPRC2"},
376     {QPageSize::EnvelopePrc3      ,   DMPAPER_PENV_3               ,   QPageSize::Millimeter,    354,  499,      125  ,  176  ,       4.9 ,   6.9 ,    "EnvPRC3"},
377     {QPageSize::EnvelopePrc4      ,   DMPAPER_PENV_4               ,   QPageSize::Millimeter,    312,  590,      110  ,  208  ,       4.33,   8.2 ,    "EnvPRC4"},
378     {QPageSize::EnvelopePrc5      ,   DMPAPER_PENV_5               ,   QPageSize::Millimeter,    312,  624,      110  ,  220  ,       4.33,   8.66,    "EnvPRC5"},
379     {QPageSize::EnvelopePrc6      ,   DMPAPER_PENV_6               ,   QPageSize::Millimeter,    340,  652,      120  ,  230  ,       4.7 ,   9   ,    "EnvPRC6"},
380     {QPageSize::EnvelopePrc7      ,   DMPAPER_PENV_7               ,   QPageSize::Millimeter,    454,  652,      160  ,  230  ,       6.3 ,   9   ,    "EnvPRC7"},
381     {QPageSize::EnvelopePrc8      ,   DMPAPER_PENV_8               ,   QPageSize::Millimeter,    340,  876,      120  ,  309  ,       4.7 ,  12.2 ,    "EnvPRC8"},
382     {QPageSize::EnvelopePrc9      ,   DMPAPER_PENV_9               ,   QPageSize::Millimeter,    649,  918,      229  ,  324  ,       9   ,  12.75,    "EnvPRC9"},
383     {QPageSize::EnvelopePrc10     ,   DMPAPER_PENV_10              ,   QPageSize::Millimeter,    918, 1298,      324  ,  458  ,      12.75,  18   ,    "EnvPRC10"},
384     {QPageSize::EnvelopeYou4      ,   DMPAPER_JENV_YOU4            ,   QPageSize::Millimeter,    298,  666,      105  ,  235  ,       4.13,   9.25,    "EnvYou4"}
385 };
386 
387 static const int pageSizesCount = int(sizeof(qt_pageSizes) / sizeof(qt_pageSizes[0]));
388 Q_STATIC_ASSERT(pageSizesCount == QPageSize::LastPageSize + 1);
389 
390 // Return key name for PageSize
qt_keyForPageSizeId(QPageSize::PageSizeId id)391 static QString qt_keyForPageSizeId(QPageSize::PageSizeId id)
392 {
393     return QString::fromLatin1(qt_pageSizes[id].mediaOption);
394 }
395 
396 // Return id name for PPD Key
qt_idForPpdKey(const QString & ppdKey,QSize * match=nullptr)397 static QPageSize::PageSizeId qt_idForPpdKey(const QString &ppdKey, QSize *match = nullptr)
398 {
399     if (ppdKey.isEmpty())
400         return QPageSize::Custom;
401     QStringRef key(&ppdKey);
402     // Remove any Rotated or Tranverse modifiers
403     if (key.endsWith(QLatin1String("Rotated")))
404         key.chop(7);
405     else if (key.endsWith(QLatin1String(".Transverse")))
406         key.chop(11);
407     for (int i = 0; i <= int(QPageSize::LastPageSize); ++i) {
408         if (QLatin1String(qt_pageSizes[i].mediaOption) == key) {
409             if (match)
410                 *match = QSize(qt_pageSizes[i].widthPoints, qt_pageSizes[i].heightPoints);
411             return qt_pageSizes[i].id;
412         }
413     }
414     return QPageSize::Custom;
415 }
416 
417 // Return id name for Windows ID
qt_idForWindowsID(int windowsId,QSize * match=nullptr)418 static QPageSize::PageSizeId qt_idForWindowsID(int windowsId, QSize *match = nullptr)
419 {
420     // If outside known values then is Custom
421     if (windowsId <= DMPAPER_NONE || windowsId > DMPAPER_LAST)
422         return QPageSize::Custom;
423     // Check if one of the unsupported values, convert to valid value if is
424     for (const auto &it : qt_windowsConversion) {
425         if (it[0] == windowsId) {
426             windowsId = it[1];
427             break;
428         }
429     }
430     // Look for the value in our supported size table
431     for (int i = 0; i <= int(QPageSize::LastPageSize); ++i) {
432         if (qt_pageSizes[i].windowsId == windowsId) {
433             if (match)
434                 *match = QSize(qt_pageSizes[i].widthPoints, qt_pageSizes[i].heightPoints);
435             return qt_pageSizes[i].id;
436         }
437     }
438     // Otherwise is Custom
439     return QPageSize::Custom;
440 }
441 
442 // Return key name for custom size
qt_keyForCustomSize(const QSizeF & size,QPageSize::Unit units)443 static QString qt_keyForCustomSize(const QSizeF &size, QPageSize::Unit units)
444 {
445     // PPD custom format
446     QString key = QStringLiteral("Custom.%1x%2%3");
447     QString abbrev;
448     switch (units) {
449     case QPageSize::Millimeter:
450         abbrev = QStringLiteral("mm");
451         break;
452     case QPageSize::Point:
453         break;
454     case QPageSize::Inch:
455         abbrev = QStringLiteral("in");
456         break;
457     case QPageSize::Pica:
458         abbrev = QStringLiteral("pc");
459         break;
460     case QPageSize::Didot:
461         abbrev = QStringLiteral("DD");
462         break;
463     case QPageSize::Cicero:
464         abbrev = QStringLiteral("CC");
465         break;
466     }
467     // Assumes size is already max 2 decimal places
468     return key.arg(size.width()).arg(size.height()).arg(abbrev);
469 }
470 
471 // Return localized name for custom size
qt_nameForCustomSize(const QSizeF & size,QPageSize::Unit units)472 static QString qt_nameForCustomSize(const QSizeF &size, QPageSize::Unit units)
473 {
474     QString name;
475     switch (units) {
476     case QPageSize::Millimeter:
477         //: Custom size name in millimeters
478         name = QCoreApplication::translate("QPageSize", "Custom (%1mm x %2mm)");
479         break;
480     case QPageSize::Point:
481         //: Custom size name in points
482         name = QCoreApplication::translate("QPageSize", "Custom (%1pt x %2pt)");
483         break;
484     case QPageSize::Inch:
485         //: Custom size name in inches
486         name = QCoreApplication::translate("QPageSize", "Custom (%1in x %2in)");
487         break;
488     case QPageSize::Pica:
489         //: Custom size name in picas
490         name = QCoreApplication::translate("QPageSize", "Custom (%1pc x %2pc)");
491         break;
492     case QPageSize::Didot:
493         //: Custom size name in didots
494         name = QCoreApplication::translate("QPageSize", "Custom (%1DD x %2DD)");
495         break;
496     case QPageSize::Cicero:
497         //: Custom size name in ciceros
498         name = QCoreApplication::translate("QPageSize", "Custom (%1CC x %2CC)");
499         break;
500     }
501     // Assumes size is already max 2 decimal places
502     return name.arg(size.width()).arg(size.height());
503 }
504 
505 // Multiplier for converting units to points.
qt_pointMultiplier(QPageSize::Unit unit)506 static qreal qt_pointMultiplier(QPageSize::Unit unit)
507 {
508     switch (unit) {
509     case QPageSize::Millimeter:
510         return 2.83464566929;
511     case QPageSize::Point:
512         return 1.0;
513     case QPageSize::Inch:
514         return 72.0;
515     case QPageSize::Pica:
516         return 12;
517     case QPageSize::Didot:
518         return 1.065826771;
519     case QPageSize::Cicero:
520         return 12.789921252;
521     }
522     return 1.0;
523 }
524 
525 // Multiplier for converting pixels to points.
qt_pixelMultiplier(int resolution)526 Q_GUI_EXPORT qreal qt_pixelMultiplier(int resolution)
527 {
528     return resolution <= 0 ? 1.0 : 72.0 / resolution;
529 }
530 
qt_definitionSize(QPageSize::PageSizeId pageSizeId)531 static QSizeF qt_definitionSize(QPageSize::PageSizeId pageSizeId)
532 {
533     QPageSize::Unit units = qt_pageSizes[pageSizeId].definitionUnits;
534     if (units == QPageSize::Millimeter)
535         return QSizeF(qt_pageSizes[pageSizeId].widthMillimeters, qt_pageSizes[pageSizeId].heightMillimeters);
536     Q_ASSERT(units == QPageSize::Inch);  // We currently only support definitions in mm or inches
537     return QSizeF(qt_pageSizes[pageSizeId].widthInches, qt_pageSizes[pageSizeId].heightInches);
538 }
539 
qt_convertUnits(const QSizeF & size,QPageSize::Unit fromUnits,QPageSize::Unit toUnits)540 static QSizeF qt_convertUnits(const QSizeF &size, QPageSize::Unit fromUnits, QPageSize::Unit toUnits)
541 {
542     if (!size.isValid())
543         return QSizeF();
544 
545     // If the units are the same or the size is 0, then don't need to convert
546     if (fromUnits == toUnits || (qFuzzyIsNull(size.width()) && qFuzzyIsNull(size.height())))
547         return size;
548 
549     QSizeF newSize = size;
550     // First convert to points
551     if (fromUnits != QPageSize::Point) {
552         const qreal multiplier = qt_pointMultiplier(fromUnits);
553         newSize = newSize * multiplier;
554     }
555     // Then convert from points to required units
556     const qreal multiplier = qt_pointMultiplier(toUnits);
557     // Try force to 2 decimal places for consistency
558     const int width = qRound(newSize.width() * 100 / multiplier);
559     const int height = qRound(newSize.height() * 100 / multiplier);
560     return QSizeF(width / 100.0, height / 100.0);
561 }
562 
qt_convertUnitsToPoints(const QSizeF & size,QPageSize::Unit units)563 static QSize qt_convertUnitsToPoints(const QSizeF &size, QPageSize::Unit units)
564 {
565     if (!size.isValid())
566         return QSize();
567     return QSizeF(size * qt_pointMultiplier(units)).toSize();
568 }
569 
qt_convertPointsToPixels(const QSize & size,int resolution)570 static QSize qt_convertPointsToPixels(const QSize &size, int resolution)
571 {
572     if (!size.isValid() || resolution <= 0)
573         return QSize();
574     const qreal multiplier = qt_pixelMultiplier(resolution);
575     return QSize(qRound(size.width() / multiplier), qRound(size.height() / multiplier));
576 }
577 
qt_convertPointsToUnits(const QSize & size,QPageSize::Unit units)578 static QSizeF qt_convertPointsToUnits(const QSize &size, QPageSize::Unit units)
579 {
580     if (!size.isValid())
581         return QSizeF();
582     const qreal multiplier = qt_pointMultiplier(units);
583     // Try force to 2 decimal places for consistency
584     const int width = qRound(size.width() * 100 / multiplier);
585     const int height = qRound(size.height() * 100 / multiplier);
586     return QSizeF(width / 100.0, height / 100.0);
587 }
588 
qt_unitSize(QPageSize::PageSizeId pageSizeId,QPageSize::Unit units)589 static QSizeF qt_unitSize(QPageSize::PageSizeId pageSizeId, QPageSize::Unit units)
590 {
591     switch (units) {
592     case QPageSize::Millimeter:
593         return QSizeF(qt_pageSizes[pageSizeId].widthMillimeters, qt_pageSizes[pageSizeId].heightMillimeters);
594     case QPageSize::Point:
595         return QSizeF(qt_pageSizes[pageSizeId].widthPoints, qt_pageSizes[pageSizeId].heightPoints);
596     case QPageSize::Inch:
597         return QSizeF(qt_pageSizes[pageSizeId].widthInches, qt_pageSizes[pageSizeId].heightInches);
598     case QPageSize::Pica:
599     case QPageSize::Didot:
600     case QPageSize::Cicero:
601         return qt_convertPointsToUnits(QSize(qt_pageSizes[pageSizeId].widthPoints,
602                                              qt_pageSizes[pageSizeId].heightPoints), units);
603     }
604     return QSizeF();
605 }
606 
607 // Find matching standard page size for point size
qt_idForPointSize(const QSize & size,QPageSize::SizeMatchPolicy matchPolicy,QSize * match)608 static QPageSize::PageSizeId qt_idForPointSize(const QSize &size, QPageSize::SizeMatchPolicy matchPolicy, QSize *match)
609 {
610     if (!size.isValid())
611         return QPageSize::Custom;
612 
613     // Try exact match in portrait layout
614     for (int i = 0; i <= int(QPageSize::LastPageSize); ++i) {
615         if (size.width() == qt_pageSizes[i].widthPoints && size.height() == qt_pageSizes[i].heightPoints) {
616             if (match)
617                 *match = QSize(qt_pageSizes[i].widthPoints, qt_pageSizes[i].heightPoints);
618             return qt_pageSizes[i].id;
619         }
620     }
621 
622     // If no exact match only try fuzzy if asked
623     if (matchPolicy != QPageSize::ExactMatch) {
624         // Set up the fuzzy tolerance
625         // TODO Use ISO standard tolerance based on page size?
626         const int tolerance = 3; // = approx 1mm
627         const int minWidth = size.width() - tolerance;
628         const int maxWidth = size.width() + tolerance;
629         const int minHeight = size.height() - tolerance;
630         const int maxHeight = size.height() + tolerance;
631 
632         // First try fuzzy match in portrait layout
633         for (int i = 0; i <= QPageSize::LastPageSize; ++i) {
634             const int width = qt_pageSizes[i].widthPoints;
635             const int height = qt_pageSizes[i].heightPoints;
636             if (width >= minWidth && width <= maxWidth && height >= minHeight && height <= maxHeight) {
637                 if (match)
638                     *match = QSize(qt_pageSizes[i].widthPoints, qt_pageSizes[i].heightPoints);
639                 return qt_pageSizes[i].id;
640             }
641         }
642 
643         // If FuzzyOrientationMatch then try rotated sizes
644         if (matchPolicy == QPageSize::FuzzyOrientationMatch) {
645             // First try exact match in landscape layout
646             for (int i = 0; i <= QPageSize::LastPageSize; ++i) {
647                 if (size.width() == qt_pageSizes[i].heightPoints && size.height() == qt_pageSizes[i].widthPoints) {
648                     if (match)
649                         *match = QSize(qt_pageSizes[i].widthPoints, qt_pageSizes[i].heightPoints);
650                     return qt_pageSizes[i].id;
651                 }
652             }
653 
654             // Then try fuzzy match in landscape layout
655             for (int i = 0; i <= QPageSize::LastPageSize; ++i) {
656                 const int width = qt_pageSizes[i].heightPoints;
657                 const int height = qt_pageSizes[i].widthPoints;
658                 if (width >= minWidth && width <= maxWidth && height >= minHeight && height <= maxHeight) {
659                     if (match)
660                         *match = QSize(qt_pageSizes[i].widthPoints, qt_pageSizes[i].heightPoints);
661                     return qt_pageSizes[i].id;
662                 }
663             }
664         }
665     }
666 
667     if (match)
668         *match = size;
669     // Otherwise no match so Custom
670     return QPageSize::Custom;
671 }
672 
673 // Find matching standard page size for point size
qt_idForSize(const QSizeF & size,QPageSize::Unit units,QPageSize::SizeMatchPolicy matchPolicy,QSize * match)674 static QPageSize::PageSizeId qt_idForSize(const QSizeF &size, QPageSize::Unit units,
675                                           QPageSize::SizeMatchPolicy matchPolicy, QSize *match)
676 {
677     if (!size.isValid())
678         return QPageSize::Custom;
679 
680     // Try exact match if units are the same
681     if (units == QPageSize::Millimeter) {
682         for (int i = 0; i <= QPageSize::LastPageSize; ++i) {
683             if (size.width() == qt_pageSizes[i].widthMillimeters && size.height() == qt_pageSizes[i].heightMillimeters) {
684                 if (match)
685                     *match = QSize(qt_pageSizes[i].widthPoints, qt_pageSizes[i].heightPoints);
686                 return qt_pageSizes[i].id;
687             }
688         }
689     } else if (units == QPageSize::Inch) {
690         for (int i = 0; i <= QPageSize::LastPageSize; ++i) {
691             if (size.width() == qt_pageSizes[i].widthInches && size.height() == qt_pageSizes[i].heightInches) {
692                 if (match)
693                     *match = QSize(qt_pageSizes[i].widthPoints, qt_pageSizes[i].heightPoints);
694                 return qt_pageSizes[i].id;
695             }
696         }
697     } else if (units == QPageSize::Point) {
698         for (int i = 0; i <= QPageSize::LastPageSize; ++i) {
699             if (size.width() == qt_pageSizes[i].widthPoints && size.height() == qt_pageSizes[i].heightPoints) {
700                 if (match)
701                     *match = QSize(qt_pageSizes[i].widthPoints, qt_pageSizes[i].heightPoints);
702                 return qt_pageSizes[i].id;
703             }
704         }
705     }
706 
707     // If no exact match then convert to points and try match those
708     QSize points = qt_convertUnitsToPoints(size, units);
709     return qt_idForPointSize(points, matchPolicy, match);
710 }
711 
712 class QPageSizePrivate : public QSharedData
713 {
714 public:
715     QPageSizePrivate();
716     explicit QPageSizePrivate(QPageSize::PageSizeId pageSizeId);
717     QPageSizePrivate(const QSize &pointSize,
718                      const QString &name,
719                      QPageSize::SizeMatchPolicy matchPolicy);
720     QPageSizePrivate(const QSizeF &size, QPageSize::Unit units,
721                      const QString &name,
722                      QPageSize::SizeMatchPolicy matchPolicy);
723     QPageSizePrivate(const QString &key, const QSize &size, const QString &name);
724     QPageSizePrivate(int windowsId, const QSize &pointSize, const QString &name);
725     ~QPageSizePrivate();
726 
727     bool operator==(const QPageSizePrivate &other) const;
728     bool isEquivalentTo(const QPageSizePrivate &other) const;
729 
730     bool isValid() const;
731 
732     QSizeF size(QPageSize::Unit units) const;
733     QSize sizePixels(int resolution) const;
734 
735 private:
736     friend class QPageSize;
737 
738     void init(QPageSize::PageSizeId id, const QString &name);
739     void init(const QSize &size, const QString &name);
740     void init(const QSizeF &size, QPageSize::Unit units, const QString &name);
741 
742     QString m_key;
743     QPageSize::PageSizeId m_id;
744     QSize m_pointSize;
745     QString m_name;
746     int m_windowsId;
747     QSizeF m_size;
748     QPageSize::Unit m_units;
749 };
750 
QPageSizePrivate()751 QPageSizePrivate::QPageSizePrivate()
752     : m_id(QPageSize::Custom),
753       m_windowsId(0),
754       m_units(QPageSize::Point)
755 {
756 }
757 
QPageSizePrivate(QPageSize::PageSizeId pageSizeId)758 QPageSizePrivate::QPageSizePrivate(QPageSize::PageSizeId pageSizeId)
759     : m_id(QPageSize::Custom),
760       m_windowsId(0),
761       m_units(QPageSize::Point)
762 {
763     if (unsigned(pageSizeId) <= unsigned(QPageSize::LastPageSize))
764         init(pageSizeId, QString());
765 }
766 
QPageSizePrivate(const QSize & pointSize,const QString & name,QPageSize::SizeMatchPolicy matchPolicy)767 QPageSizePrivate::QPageSizePrivate(const QSize &pointSize, const QString &name, QPageSize::SizeMatchPolicy matchPolicy)
768     : m_id(QPageSize::Custom),
769       m_windowsId(0),
770       m_units(QPageSize::Point)
771 {
772     if (pointSize.isValid()) {
773         QPageSize::PageSizeId id = qt_idForPointSize(pointSize, matchPolicy, nullptr);
774         id == QPageSize::Custom ? init(pointSize, name) : init(id, name);
775     }
776 }
777 
QPageSizePrivate(const QSizeF & size,QPageSize::Unit units,const QString & name,QPageSize::SizeMatchPolicy matchPolicy)778 QPageSizePrivate::QPageSizePrivate(const QSizeF &size, QPageSize::Unit units,
779                                    const QString &name, QPageSize::SizeMatchPolicy matchPolicy)
780     : m_id(QPageSize::Custom),
781       m_windowsId(0),
782       m_units(QPageSize::Point)
783 {
784     if (size.isValid()) {
785         QPageSize::PageSizeId id = qt_idForSize(size, units, matchPolicy, nullptr);
786         id == QPageSize::Custom ? init(size, units, name) : init(id, name);
787     }
788 }
789 
QPageSizePrivate(const QString & key,const QSize & pointSize,const QString & name)790 QPageSizePrivate::QPageSizePrivate(const QString &key, const QSize &pointSize, const QString &name)
791     : m_id(QPageSize::Custom),
792       m_windowsId(0),
793       m_units(QPageSize::Point)
794 {
795     if (!key.isEmpty() && pointSize.isValid()) {
796         QPageSize::PageSizeId id = qt_idForPpdKey(key, nullptr);
797         // If not a known PPD key, check if size is a standard PPD size
798         if (id == QPageSize::Custom)
799             id = qt_idForPointSize(pointSize, QPageSize::FuzzyMatch, nullptr);
800         id == QPageSize::Custom ? init(pointSize, name) : init(id, name);
801         m_key = key;
802     }
803 }
804 
QPageSizePrivate(int windowsId,const QSize & pointSize,const QString & name)805 QPageSizePrivate::QPageSizePrivate(int windowsId, const QSize &pointSize, const QString &name)
806     : m_id(QPageSize::Custom),
807       m_windowsId(0),
808       m_units(QPageSize::Point)
809 {
810     if (windowsId > 0 && pointSize.isValid()) {
811         QPageSize::PageSizeId id = qt_idForWindowsID(windowsId, nullptr);
812         // If not a known Windows ID, check if size is a standard PPD size
813         if (id == QPageSize::Custom)
814             id = qt_idForPointSize(pointSize, QPageSize::FuzzyMatch, nullptr);
815         id == QPageSize::Custom ? init(pointSize, name) : init(id, name);
816         m_windowsId = windowsId;
817     }
818 }
819 
~QPageSizePrivate()820 QPageSizePrivate::~QPageSizePrivate()
821 {
822 }
823 
824 // Init a standard PageSizeId
init(QPageSize::PageSizeId id,const QString & name)825 void QPageSizePrivate::init(QPageSize::PageSizeId id, const QString &name)
826 {
827     m_id = id;
828     m_size = qt_definitionSize(id);
829     m_units = qt_pageSizes[id].definitionUnits;
830     m_key = qt_keyForPageSizeId(id);
831     m_name = name.isEmpty() ? QPageSize::name(id) : name;
832     m_windowsId = qt_pageSizes[id].windowsId;
833     m_pointSize = QSize(qt_pageSizes[id].widthPoints, qt_pageSizes[id].heightPoints);
834 }
835 
836 // Init a point size
init(const QSize & size,const QString & name)837 void QPageSizePrivate::init(const QSize &size, const QString &name)
838 {
839     m_id = QPageSize::Custom;
840     m_size = size;
841     m_units = QPageSize::Point;
842     m_key = qt_keyForCustomSize(m_size, m_units);
843     m_name = name.isEmpty() ? qt_nameForCustomSize(m_size, m_units) : name;
844     m_windowsId = 0;
845     m_pointSize = size;
846 }
847 
848 // Init a unit size
init(const QSizeF & size,QPageSize::Unit units,const QString & name)849 void QPageSizePrivate::init(const QSizeF &size, QPageSize::Unit units, const QString &name)
850 {
851     m_id = QPageSize::Custom;
852     m_size = size;
853     m_units = units;
854     m_key = qt_keyForCustomSize(m_size, m_units);
855     if (name.isEmpty())
856         m_name = qt_nameForCustomSize(m_size, m_units);
857     else
858         m_name = name;
859     m_windowsId = 0;
860     m_pointSize = qt_convertUnitsToPoints(m_size, m_units);
861 }
862 
operator ==(const QPageSizePrivate & other) const863 bool QPageSizePrivate::operator==(const QPageSizePrivate &other) const
864 {
865     return m_size == other.m_size
866            && m_units == other.m_units
867            && m_key == other.m_key
868            && m_name == other.m_name;
869 }
870 
isEquivalentTo(const QPageSizePrivate & other) const871 bool QPageSizePrivate::isEquivalentTo(const QPageSizePrivate &other) const
872 {
873     return m_pointSize == other.m_pointSize;
874 }
875 
isValid() const876 bool QPageSizePrivate::isValid() const
877 {
878     return m_pointSize.isValid() && !m_key.isEmpty() && !m_name.isEmpty();
879 }
880 
size(QPageSize::Unit units) const881 QSizeF QPageSizePrivate::size(QPageSize::Unit units) const
882 {
883     // If want units we've stored in, we already have them
884     if (units == m_units)
885         return m_size;
886 
887     // If want points we already have them
888     if (units == QPageSize::Point)
889         return QSizeF(m_pointSize.width(), m_pointSize.height());
890 
891     // If a custom size do a conversion
892     if (m_id == QPageSize::Custom)
893         return qt_convertUnits(m_size, m_units, units);
894 
895     // Otherwise use the standard sizes
896     return qt_unitSize(m_id, units);
897 }
898 
sizePixels(int resolution) const899 QSize QPageSizePrivate::sizePixels(int resolution) const
900 {
901     return qt_convertPointsToPixels(m_pointSize, resolution);;
902 }
903 
904 
905 /*!
906     \class QPageSize
907     \inmodule QtGui
908     \since 5.3
909     \brief The QPageSize class describes the size and name of a defined page size.
910 
911     This class implements support for the set of standard page sizes as defined
912     in the Adobe Postscript PPD Standard v4.3. It defines the standard set of
913     page sizes in points, millimeters and inches and ensures these sizes are
914     consistently used. Other size units can be used but will be calculated
915     results and so may not always be consistent. The defined point sizes are
916     always a integer, all other sizes can be fractions of a unit.
917 
918     The defined size is always in width x height order with no implied page
919     orientation. Note that it is possible for page sizes to be defined where the
920     width is greater than the height, such as QPageSize::Ledger, so you cannot
921     rely on comparing the width and height values to determine page orientation.
922 
923     For example, A4 is defined by the standard as 210mm x 297mm, 8.27in x 11.69in,
924     or 595pt x 842pt.
925 
926     You can also define custom page sizes with custom names in any units you want
927     and this unit size will be preserved and used as the base for all other unit
928     size calculations.
929 
930     When creating a QPageSize using a custom QSize you can choose if you want
931     QPageSize to try match the size to a standard page size. By default
932     QPaperSize uses a FuzzyMatch mode where it will match a given page size to
933     a standard page size if it falls within 3 postscript points of a defined
934     standard size. You can override this to request only an exact match but this
935     is not recommended as conversions between units can easily lose 3 points and
936     result in incorrect page sizes.
937 
938     A QPageSize instance may also be obtained by querying the supported page sizes
939     for a print device. In this case the localized name returned is that defined
940     by the printer itself. Note that the print device may not support the current
941     default locale language.
942 
943     The class also provides convenience methods for converting page size IDs to and from
944     various unit sizes.
945 
946     \sa QPagedPaintDevice, QPdfWriter
947 */
948 
949 /*!
950     \enum QPageSize::PageSizeId
951 
952     This enum type lists the available page sizes as defined in the Postscript
953     PPD standard. These values are duplicated in QPagedPaintDevice and QPrinter.
954 
955     The defined sizes are:
956 
957     \value A0 841 x 1189 mm
958     \value A1 594 x 841 mm
959     \value A2 420 x 594 mm
960     \value A3 297 x 420 mm
961     \value A4 210 x 297 mm, 8.26 x 11.69 inches
962     \value A5 148 x 210 mm
963     \value A6 105 x 148 mm
964     \value A7 74 x 105 mm
965     \value A8 52 x 74 mm
966     \value A9 37 x 52 mm
967     \value B0 1000 x 1414 mm
968     \value B1 707 x 1000 mm
969     \value B2 500 x 707 mm
970     \value B3 353 x 500 mm
971     \value B4 250 x 353 mm
972     \value B5 176 x 250 mm, 6.93 x 9.84 inches
973     \value B6 125 x 176 mm
974     \value B7 88 x 125 mm
975     \value B8 62 x 88 mm
976     \value B9 44 x 62 mm
977     \value B10 31 x 44 mm
978     \value C5E 163 x 229 mm
979     \value Comm10E 105 x 241 mm, U.S. Common 10 Envelope
980     \value DLE 110 x 220 mm
981     \value Executive 7.5 x 10 inches, 190.5 x 254 mm
982     \value Folio 210 x 330 mm
983     \value Ledger 431.8 x 279.4 mm
984     \value Legal 8.5 x 14 inches, 215.9 x 355.6 mm
985     \value Letter 8.5 x 11 inches, 215.9 x 279.4 mm
986     \value Tabloid 279.4 x 431.8 mm
987     \value Custom Unknown, or a user defined size.
988     \value A10
989     \value A3Extra
990     \value A4Extra
991     \value A4Plus
992     \value A4Small
993     \value A5Extra
994     \value B5Extra
995     \value JisB0
996     \value JisB1
997     \value JisB2
998     \value JisB3
999     \value JisB4
1000     \value JisB5
1001     \value JisB6,
1002     \value JisB7
1003     \value JisB8
1004     \value JisB9
1005     \value JisB10
1006     \value AnsiA = Letter
1007     \value AnsiB = Ledger
1008     \value AnsiC
1009     \value AnsiD
1010     \value AnsiE
1011     \value LegalExtra
1012     \value LetterExtra
1013     \value LetterPlus
1014     \value LetterSmall
1015     \value TabloidExtra
1016     \value ArchA
1017     \value ArchB
1018     \value ArchC
1019     \value ArchD
1020     \value ArchE
1021     \value Imperial7x9
1022     \value Imperial8x10
1023     \value Imperial9x11
1024     \value Imperial9x12
1025     \value Imperial10x11
1026     \value Imperial10x13
1027     \value Imperial10x14
1028     \value Imperial12x11
1029     \value Imperial15x11
1030     \value ExecutiveStandard
1031     \value Note
1032     \value Quarto
1033     \value Statement
1034     \value SuperA
1035     \value SuperB
1036     \value Postcard
1037     \value DoublePostcard
1038     \value Prc16K
1039     \value Prc32K
1040     \value Prc32KBig
1041     \value FanFoldUS
1042     \value FanFoldGerman
1043     \value FanFoldGermanLegal
1044     \value EnvelopeB4
1045     \value EnvelopeB5
1046     \value EnvelopeB6
1047     \value EnvelopeC0
1048     \value EnvelopeC1
1049     \value EnvelopeC2
1050     \value EnvelopeC3
1051     \value EnvelopeC4
1052     \value EnvelopeC5 = C5E
1053     \value EnvelopeC6
1054     \value EnvelopeC65
1055     \value EnvelopeC7
1056     \value EnvelopeDL = DLE
1057     \value Envelope9
1058     \value Envelope10 = Comm10E
1059     \value Envelope11
1060     \value Envelope12
1061     \value Envelope14
1062     \value EnvelopeMonarch
1063     \value EnvelopePersonal
1064     \value EnvelopeChou3
1065     \value EnvelopeChou4
1066     \value EnvelopeInvite
1067     \value EnvelopeItalian
1068     \value EnvelopeKaku2
1069     \value EnvelopeKaku3
1070     \value EnvelopePrc1
1071     \value EnvelopePrc2
1072     \value EnvelopePrc3
1073     \value EnvelopePrc4
1074     \value EnvelopePrc5
1075     \value EnvelopePrc6
1076     \value EnvelopePrc7
1077     \value EnvelopePrc8
1078     \value EnvelopePrc9
1079     \value EnvelopePrc10
1080     \value EnvelopeYou4
1081     \value LastPageSize = EnvelopeYou4
1082     \omitvalue NPageSize
1083     \omitvalue NPaperSize
1084 
1085     Due to historic reasons QPageSize::Executive is not the same as the standard
1086     Postscript and Windows Executive size, use QPageSize::ExecutiveStandard instead.
1087 
1088     The Postscript standard size QPageSize::Folio is different to the Windows
1089     DMPAPER_FOLIO size, use the Postscript standard size QPageSize::FanFoldGermanLegal
1090     if needed.
1091 */
1092 
1093 /*!
1094     \enum QPageSize::Unit
1095 
1096     This enum type is used to specify the measurement unit for page sizes.
1097 
1098     \value Millimeter
1099     \value Point  1/72th of an inch
1100     \value Inch
1101     \value Pica  1/72th of a foot, 1/6th of an inch, 12 Points
1102     \value Didot  1/72th of a French inch, 0.375 mm
1103     \value Cicero  1/6th of a French inch, 12 Didot, 4.5mm
1104 */
1105 
1106 /*!
1107     \enum QPageSize::SizeMatchPolicy
1108 
1109     \value FuzzyMatch  Match to a standard page size if within the margin of tolerance.
1110     \value FuzzyOrientationMatch  Match to a standard page size if within the margin of tolerance regardless of orientation.
1111     \value ExactMatch  Only match to a standard page size if the sizes match exactly.
1112 */
1113 
1114 /*!
1115     Creates a null QPageSize.
1116 */
1117 
QPageSize()1118 QPageSize::QPageSize()
1119     : d(new QPageSizePrivate())
1120 {
1121 }
1122 
1123 /*!
1124     Creates a QPageSize of the standard \a pageSize.
1125 
1126     If \a pageSize is QPageSize::Custom then the resulting QPageSize will not
1127     be valid. Use the custom size constructor instead.
1128 */
1129 
QPageSize(PageSizeId pageSize)1130 QPageSize::QPageSize(PageSizeId pageSize)
1131     : d(new QPageSizePrivate(pageSize))
1132 {
1133 }
1134 
1135 /*!
1136     Creates a QPageSize of the given \a pointSize in Points using the matching \a matchPolicy.
1137 
1138     If the given \a pointSize matches a standard QPageSize::PageSizeId, then that page
1139     size will be used.  Note that if the \a matchPolicy is FuzzyMatch this may result
1140     in the \a pointSize being adjusted to the standard size.  To prevent this happening
1141     use a \a matchPolicy of ExactMatch instead.
1142 
1143     If the given \a pointSize is not a standard QPageSize::PageSizeId then a QPageSize::Custom
1144     size will be created.
1145 
1146     If \a name is null then the standard localized name will be used. If a custom page
1147     size then a custom name in the format "Custom (width x height)" will be created.
1148 
1149     The \a matchPolicy defaults to FuzzyMatch.
1150 */
1151 
QPageSize(const QSize & pointSize,const QString & name,SizeMatchPolicy matchPolicy)1152 QPageSize::QPageSize(const QSize &pointSize, const QString &name, SizeMatchPolicy matchPolicy)
1153     : d(new QPageSizePrivate(pointSize, name, matchPolicy))
1154 {
1155 }
1156 
1157 /*!
1158     Creates a custom page of the given \a size in \a units.
1159 
1160     If the given \a size matches a standard QPageSize::PageSizeId, then that page
1161     size will be used. Note that if the \a matchPolicy is FuzzyMatch this may result
1162     in the \a size being adjusted to the standard size. To prevent this happening
1163     use a \a matchPolicy of ExactMatch instead.
1164 
1165     If the given \a size is not a standard QPageSize::PageSizeId then a QPageSize::Custom
1166     size will be created. The original unit size will be preserved and used as the
1167     base for all other unit size calculations.
1168 
1169     If \a name is null then a custom name will be created in the form
1170     "Custom (width x height)" where the size is expressed in units provided.
1171 */
1172 
QPageSize(const QSizeF & size,Unit units,const QString & name,SizeMatchPolicy matchPolicy)1173 QPageSize::QPageSize(const QSizeF &size, Unit units,
1174                      const QString &name, SizeMatchPolicy matchPolicy)
1175     : d(new QPageSizePrivate(size, units, name, matchPolicy))
1176 {
1177 }
1178 
1179 /*!
1180     \internal
1181 
1182     Create page with given key, size and name, for use by printer plugin.
1183 */
1184 
QPageSize(const QString & key,const QSize & pointSize,const QString & name)1185 QPageSize::QPageSize(const QString &key, const QSize &pointSize, const QString &name)
1186     : d(new QPageSizePrivate(key, pointSize, name))
1187 {
1188 }
1189 
1190 /*!
1191     \internal
1192 
1193     Create page with given windows ID, size and name, for use by printer plugin.
1194 */
1195 
QPageSize(int windowsId,const QSize & pointSize,const QString & name)1196 QPageSize::QPageSize(int windowsId, const QSize &pointSize, const QString &name)
1197     : d(new QPageSizePrivate(windowsId, pointSize, name))
1198 {
1199 }
1200 
1201 /*!
1202     \internal
1203 
1204     Create page with given private backend
1205 */
1206 
QPageSize(QPageSizePrivate & dd)1207 QPageSize::QPageSize(QPageSizePrivate &dd)
1208     : d(&dd)
1209 {
1210 }
1211 
1212 /*!
1213     Copy constructor, copies \a other to this.
1214 */
1215 
QPageSize(const QPageSize & other)1216 QPageSize::QPageSize(const QPageSize &other)
1217     : d(other.d)
1218 {
1219 }
1220 
1221 /*!
1222     Destroys the page.
1223 */
1224 
~QPageSize()1225 QPageSize::~QPageSize()
1226 {
1227 }
1228 
1229 /*!
1230     Assignment operator, assigns \a other to this.
1231 */
1232 
operator =(const QPageSize & other)1233 QPageSize &QPageSize::operator=(const QPageSize &other)
1234 {
1235     d = other.d;
1236     return *this;
1237 }
1238 
1239 /*!
1240     \fn void QPageSize::swap(QPageSize &other)
1241 
1242     Swaps this QPageSize with \a other. This function is very fast and
1243     never fails.
1244 */
1245 
1246 /*!
1247     \fn QPageSize &QPageSize::operator=(QPageSize &&other)
1248 
1249     Move-assigns \a other to this QPageSize instance, transferring the
1250     ownership of the managed pointer to this instance.
1251 */
1252 
1253 /*!
1254     \relates QPageSize
1255 
1256     Returns \c true if page size \a lhs is equal to page size \a rhs,
1257     i.e. if the page sizes have the same attributes. Current
1258     attributes are size and name.
1259 */
1260 
operator ==(const QPageSize & lhs,const QPageSize & rhs)1261 bool operator==(const QPageSize &lhs, const QPageSize &rhs)
1262 {
1263     return lhs.d == rhs.d || *lhs.d == *rhs.d;
1264 }
1265 /*!
1266     \fn bool operator!=(const QPageSize &lhs, const QPageSize &rhs)
1267     \relates QPageSize
1268 
1269     Returns \c true if page size \a lhs is unequal to page size \a
1270     rhs, i.e. if the page size has different attributes. Current
1271     attributes are size and name.
1272 */
1273 
1274 /*!
1275     Returns \c true if this page is equivalent to the \a other page, i.e. if the
1276     page has the same size regardless of other attributes like name.
1277 */
1278 
isEquivalentTo(const QPageSize & other) const1279 bool QPageSize::isEquivalentTo(const QPageSize &other) const
1280 {
1281     if (d == other.d)
1282         return true;
1283     return d && other.d && d->isEquivalentTo(*other.d);
1284 }
1285 
1286 /*!
1287     Returns \c true if this page size is valid.
1288 
1289     The page size may be invalid if created with an invalid PageSizeId, or a
1290     negative or invalid QSize or QSizeF, or the null constructor.
1291 */
1292 
isValid() const1293 bool QPageSize::isValid() const
1294 {
1295     return d && d->isValid();
1296 }
1297 
1298 /*!
1299     Returns the unique key of the page size.
1300 
1301     By default this is the PPD standard mediaOption keyword for the page size,
1302     or the PPD custom format key.  If the QPageSize instance was obtained from
1303     a print device then this will be the key provided by the print device and
1304     may differ from the standard key.
1305 
1306     If the QPageSize is invalid then the key will be an empty string.
1307 
1308     This key should never be shown to end users, it is an internal key only.
1309     For a human-readable name use name().
1310 
1311     \sa name()
1312 */
1313 
key() const1314 QString QPageSize::key() const
1315 {
1316     return isValid() ? d->m_key : QString();
1317 }
1318 
1319 /*!
1320     Returns a localized human-readable name for the page size.
1321 
1322     If the QPageSize instance was obtained from a print device then the name
1323     used is that provided by the print device.  Note that a print device may
1324     not support the current default locale language.
1325 
1326     If the QPageSize is invalid then the name will be an empty string.
1327 */
1328 
name() const1329 QString QPageSize::name() const
1330 {
1331     return isValid() ? d->m_name : QString();
1332 }
1333 
1334 /*!
1335     Returns the standard QPageSize::PageSizeId of the page, or QPageSize::Custom.
1336 
1337     If the QPageSize is invalid then the ID will be QPageSize::Custom.
1338 */
1339 
id() const1340 QPageSize::PageSizeId QPageSize::id() const
1341 {
1342     return isValid() ? d->m_id : Custom;
1343 }
1344 
1345 /*!
1346     Returns the Windows DMPAPER enum value for the page size.
1347 
1348     Not all valid PPD page sizes have a Windows equivalent, in which case 0
1349     will be returned.
1350 
1351     If the QPageSize is invalid then the Windows ID will be 0.
1352 
1353     \sa id()
1354 */
1355 
windowsId() const1356 int QPageSize::windowsId() const
1357 {
1358     if (!isValid())
1359         return 0;
1360     return d->m_windowsId > 0 ? d->m_windowsId : windowsId(d->m_id);
1361 }
1362 
1363 /*!
1364     Returns the definition size of the page size.
1365 
1366     For a standard page size this will be the size as defined in the relevant
1367     standard, i.e. ISO A4 will be defined in millimeters while ANSI Letter will
1368     be defined in inches.
1369 
1370     For a custom page size this will be the original size used to create the
1371     page size object.
1372 
1373     If the QPageSize is invalid then the QSizeF will be invalid.
1374 
1375     \sa definitionUnits()
1376 */
1377 
definitionSize() const1378 QSizeF QPageSize::definitionSize() const
1379 {
1380     return isValid() ? d->m_size : QSizeF();
1381 }
1382 
1383 /*!
1384     Returns the definition units of the page size.
1385 
1386     For a standard page size this will be the units as defined in the relevant
1387     standard, i.e. ISO A4 will be defined in millimeters while ANSI Letter will
1388     be defined in inches.
1389 
1390     For a custom page size this will be the original units used to create the
1391     page size object.
1392 
1393     If the QPageSize is invalid then the QPageSize::Unit will be invalid.
1394 
1395     \sa definitionSize()
1396 */
1397 
definitionUnits() const1398 QPageSize::Unit QPageSize::definitionUnits() const
1399 {
1400     return isValid() ? d->m_units : Unit(-1);
1401 }
1402 
1403 /*!
1404     Returns the size of the page in the required \a units.
1405 
1406     If the QPageSize is invalid then the QSizeF will be invalid.
1407 */
1408 
size(Unit units) const1409 QSizeF QPageSize::size(Unit units) const
1410 {
1411     return isValid() ? d->size(units) : QSize();
1412 }
1413 
1414 /*!
1415     Returns the size of the page in Postscript Points (1/72 of an inch).
1416 
1417     If the QPageSize is invalid then the QSize will be invalid.
1418 */
1419 
sizePoints() const1420 QSize QPageSize::sizePoints() const
1421 {
1422     return isValid() ? d->m_pointSize : QSize();
1423 }
1424 
1425 /*!
1426     Returns the size of the page in Device Pixels at the given \a resolution.
1427 
1428     If the QPageSize is invalid then the QSize will be invalid.
1429 */
1430 
sizePixels(int resolution) const1431 QSize QPageSize::sizePixels(int resolution) const
1432 {
1433     return isValid() ? d->sizePixels(resolution) : QSize();
1434 }
1435 
1436 /*!
1437     Returns the page rectangle in the required \a units.
1438 
1439     If the QPageSize is invalid then the QRect will be invalid.
1440 */
1441 
rect(Unit units) const1442 QRectF QPageSize::rect(Unit units) const
1443 {
1444     return isValid() ? QRectF(QPointF(0, 0), d->size(units)) : QRectF();
1445 }
1446 
1447 /*!
1448     Returns the page rectangle in Postscript Points (1/72 of an inch).
1449 
1450     If the QPageSize is invalid then the QRect will be invalid.
1451 */
1452 
rectPoints() const1453 QRect QPageSize::rectPoints() const
1454 {
1455     return isValid() ? QRect(QPoint(0, 0), d->m_pointSize) : QRect();
1456 }
1457 
1458 /*!
1459     Returns the page rectangle in Device Pixels at the given \a resolution.
1460 
1461     If the QPageSize is invalid then the QRect will be invalid.
1462 */
1463 
rectPixels(int resolution) const1464 QRect QPageSize::rectPixels(int resolution) const
1465 {
1466     return isValid() ? QRect(QPoint(0, 0), d->sizePixels(resolution)) : QRect();
1467 }
1468 
1469 // Statics
1470 
1471 /*!
1472     Returns the PPD mediaOption keyword of the standard \a pageSizeId.
1473 
1474     If the QPageSize is invalid then the key will be empty.
1475 */
1476 
key(PageSizeId pageSizeId)1477 QString QPageSize::key(PageSizeId pageSizeId)
1478 {
1479     if (unsigned(pageSizeId) > unsigned(LastPageSize))
1480         return QString();
1481     return QString::fromUtf8(qt_pageSizes[pageSizeId].mediaOption);
1482 }
1483 
msgImperialPageSizeInch(int width,int height)1484 static QString msgImperialPageSizeInch(int width, int height)
1485 {
1486     //: Page size in 'Inch'.
1487     return QCoreApplication::translate("QPageSize", "%1 x %2 in").arg(width).arg(height);
1488 }
1489 
1490 /*!
1491     Returns the localized name of the standard \a pageSizeId.
1492 
1493     If the QPageSize is invalid then the name will be empty.
1494 */
1495 
name(PageSizeId pageSizeId)1496 QString QPageSize::name(PageSizeId pageSizeId)
1497 {
1498     if (unsigned(pageSizeId) > unsigned(LastPageSize))
1499         return QString();
1500 
1501     switch (pageSizeId) {
1502     case A0:
1503         return QCoreApplication::translate("QPageSize", "A0");
1504     case A1:
1505         return QCoreApplication::translate("QPageSize", "A1");
1506     case A2:
1507         return QCoreApplication::translate("QPageSize", "A2");
1508     case A3:
1509         return QCoreApplication::translate("QPageSize", "A3");
1510     case A4:
1511         return QCoreApplication::translate("QPageSize", "A4");
1512     case A5:
1513         return QCoreApplication::translate("QPageSize", "A5");
1514     case A6:
1515         return QCoreApplication::translate("QPageSize", "A6");
1516     case A7:
1517         return QCoreApplication::translate("QPageSize", "A7");
1518     case A8:
1519         return QCoreApplication::translate("QPageSize", "A8");
1520     case A9:
1521         return QCoreApplication::translate("QPageSize", "A9");
1522     case A10:
1523         return QCoreApplication::translate("QPageSize", "A10");
1524     case B0:
1525         return QCoreApplication::translate("QPageSize", "B0");
1526     case B1:
1527         return QCoreApplication::translate("QPageSize", "B1");
1528     case B2:
1529         return QCoreApplication::translate("QPageSize", "B2");
1530     case B3:
1531         return QCoreApplication::translate("QPageSize", "B3");
1532     case B4:
1533         return QCoreApplication::translate("QPageSize", "B4");
1534     case B5:
1535         return QCoreApplication::translate("QPageSize", "B5");
1536     case B6:
1537         return QCoreApplication::translate("QPageSize", "B6");
1538     case B7:
1539         return QCoreApplication::translate("QPageSize", "B7");
1540     case B8:
1541         return QCoreApplication::translate("QPageSize", "B8");
1542     case B9:
1543         return QCoreApplication::translate("QPageSize", "B9");
1544     case B10:
1545         return QCoreApplication::translate("QPageSize", "B10");
1546     case Executive:
1547         return QCoreApplication::translate("QPageSize", "Executive (7.5 x 10 in)");
1548     case ExecutiveStandard:
1549         return QCoreApplication::translate("QPageSize", "Executive (7.25 x 10.5 in)");
1550     case Folio:
1551         return QCoreApplication::translate("QPageSize", "Folio (8.27 x 13 in)");
1552     case Legal:
1553         return QCoreApplication::translate("QPageSize", "Legal");
1554     case Letter:
1555         return QCoreApplication::translate("QPageSize", "Letter / ANSI A");
1556     case Tabloid:
1557         return QCoreApplication::translate("QPageSize", "Tabloid / ANSI B");
1558     case Ledger:
1559         return QCoreApplication::translate("QPageSize", "Ledger / ANSI B");
1560     case Custom:
1561         return QCoreApplication::translate("QPageSize", "Custom");
1562     case A3Extra:
1563         return QCoreApplication::translate("QPageSize", "A3 Extra");
1564     case A4Extra:
1565         return QCoreApplication::translate("QPageSize", "A4 Extra");
1566     case A4Plus:
1567         return QCoreApplication::translate("QPageSize", "A4 Plus");
1568     case A4Small:
1569         return QCoreApplication::translate("QPageSize", "A4 Small");
1570     case A5Extra:
1571         return QCoreApplication::translate("QPageSize", "A5 Extra");
1572     case B5Extra:
1573         return QCoreApplication::translate("QPageSize", "B5 Extra");
1574     case JisB0:
1575         return QCoreApplication::translate("QPageSize", "JIS B0");
1576     case JisB1:
1577         return QCoreApplication::translate("QPageSize", "JIS B1");
1578     case JisB2:
1579         return QCoreApplication::translate("QPageSize", "JIS B2");
1580     case JisB3:
1581         return QCoreApplication::translate("QPageSize", "JIS B3");
1582     case JisB4:
1583         return QCoreApplication::translate("QPageSize", "JIS B4");
1584     case JisB5:
1585         return QCoreApplication::translate("QPageSize", "JIS B5");
1586     case JisB6:
1587         return QCoreApplication::translate("QPageSize", "JIS B6");
1588     case JisB7:
1589         return QCoreApplication::translate("QPageSize", "JIS B7");
1590     case JisB8:
1591         return QCoreApplication::translate("QPageSize", "JIS B8");
1592     case JisB9:
1593         return QCoreApplication::translate("QPageSize", "JIS B9");
1594     case JisB10:
1595         return QCoreApplication::translate("QPageSize", "JIS B10");
1596     case AnsiC:
1597         return QCoreApplication::translate("QPageSize", "ANSI C");
1598     case AnsiD:
1599         return QCoreApplication::translate("QPageSize", "ANSI D");
1600     case AnsiE:
1601         return QCoreApplication::translate("QPageSize", "ANSI E");
1602     case LegalExtra:
1603         return QCoreApplication::translate("QPageSize", "Legal Extra");
1604     case LetterExtra:
1605         return QCoreApplication::translate("QPageSize", "Letter Extra");
1606     case LetterPlus:
1607         return QCoreApplication::translate("QPageSize", "Letter Plus");
1608     case LetterSmall:
1609         return QCoreApplication::translate("QPageSize", "Letter Small");
1610     case TabloidExtra:
1611         return QCoreApplication::translate("QPageSize", "Tabloid Extra");
1612     case ArchA:
1613         return QCoreApplication::translate("QPageSize", "Architect A");
1614     case ArchB:
1615         return QCoreApplication::translate("QPageSize", "Architect B");
1616     case ArchC:
1617         return QCoreApplication::translate("QPageSize", "Architect C");
1618     case ArchD:
1619         return QCoreApplication::translate("QPageSize", "Architect D");
1620     case ArchE:
1621         return QCoreApplication::translate("QPageSize", "Architect E");
1622     case Imperial7x9:
1623         return msgImperialPageSizeInch(7, 9);
1624     case Imperial8x10:
1625         return msgImperialPageSizeInch(8, 10);
1626     case Imperial9x11:
1627         return msgImperialPageSizeInch(9, 11);
1628     case Imperial9x12:
1629         return msgImperialPageSizeInch(9, 12);
1630     case Imperial10x11:
1631         return msgImperialPageSizeInch(10, 11);
1632     case Imperial10x13:
1633         return msgImperialPageSizeInch(10, 13);
1634     case Imperial10x14:
1635         return msgImperialPageSizeInch(10, 14);
1636     case Imperial12x11:
1637         return msgImperialPageSizeInch(12, 11);
1638     case Imperial15x11:
1639         return msgImperialPageSizeInch(15, 11);
1640     case Note:
1641         return QCoreApplication::translate("QPageSize", "Note");
1642     case Quarto:
1643         return QCoreApplication::translate("QPageSize", "Quarto");
1644     case Statement:
1645         return QCoreApplication::translate("QPageSize", "Statement");
1646     case SuperA:
1647         return QCoreApplication::translate("QPageSize", "Super A");
1648     case SuperB:
1649         return QCoreApplication::translate("QPageSize", "Super B");
1650     case Postcard:
1651         return QCoreApplication::translate("QPageSize", "Postcard");
1652     case DoublePostcard:
1653         return QCoreApplication::translate("QPageSize", "Double Postcard");
1654     case Prc16K:
1655         return QCoreApplication::translate("QPageSize", "PRC 16K");
1656     case Prc32K:
1657         return QCoreApplication::translate("QPageSize", "PRC 32K");
1658     case Prc32KBig:
1659         return QCoreApplication::translate("QPageSize", "PRC 32K Big");
1660     case FanFoldUS:
1661         return QCoreApplication::translate("QPageSize", "Fan-fold US (14.875 x 11 in)");
1662     case FanFoldGerman:
1663         return QCoreApplication::translate("QPageSize", "Fan-fold German (8.5 x 12 in)");
1664     case FanFoldGermanLegal:
1665         return QCoreApplication::translate("QPageSize", "Fan-fold German Legal (8.5 x 13 in)");
1666     case EnvelopeB4:
1667         return QCoreApplication::translate("QPageSize", "Envelope B4");
1668     case EnvelopeB5:
1669         return QCoreApplication::translate("QPageSize", "Envelope B5");
1670     case EnvelopeB6:
1671         return QCoreApplication::translate("QPageSize", "Envelope B6");
1672     case EnvelopeC0:
1673         return QCoreApplication::translate("QPageSize", "Envelope C0");
1674     case EnvelopeC1:
1675         return QCoreApplication::translate("QPageSize", "Envelope C1");
1676     case EnvelopeC2:
1677         return QCoreApplication::translate("QPageSize", "Envelope C2");
1678     case EnvelopeC3:
1679         return QCoreApplication::translate("QPageSize", "Envelope C3");
1680     case EnvelopeC4:
1681         return QCoreApplication::translate("QPageSize", "Envelope C4");
1682     case EnvelopeC5: // C5E
1683         return QCoreApplication::translate("QPageSize", "Envelope C5");
1684     case EnvelopeC6:
1685         return QCoreApplication::translate("QPageSize", "Envelope C6");
1686     case EnvelopeC65:
1687         return QCoreApplication::translate("QPageSize", "Envelope C65");
1688     case EnvelopeC7:
1689         return QCoreApplication::translate("QPageSize", "Envelope C7");
1690     case EnvelopeDL: // DLE:
1691         return QCoreApplication::translate("QPageSize", "Envelope DL");
1692     case Envelope9:
1693         return QCoreApplication::translate("QPageSize", "Envelope US 9");
1694     case Envelope10: // Comm10E
1695         return QCoreApplication::translate("QPageSize", "Envelope US 10");
1696     case Envelope11:
1697         return QCoreApplication::translate("QPageSize", "Envelope US 11");
1698     case Envelope12:
1699         return QCoreApplication::translate("QPageSize", "Envelope US 12");
1700     case Envelope14:
1701         return QCoreApplication::translate("QPageSize", "Envelope US 14");
1702     case EnvelopeMonarch:
1703         return QCoreApplication::translate("QPageSize", "Envelope Monarch");
1704     case EnvelopePersonal:
1705         return QCoreApplication::translate("QPageSize", "Envelope Personal");
1706     case EnvelopeChou3:
1707         return QCoreApplication::translate("QPageSize", "Envelope Chou 3");
1708     case EnvelopeChou4:
1709         return QCoreApplication::translate("QPageSize", "Envelope Chou 4");
1710     case EnvelopeInvite:
1711         return QCoreApplication::translate("QPageSize", "Envelope Invite");
1712     case EnvelopeItalian:
1713         return QCoreApplication::translate("QPageSize", "Envelope Italian");
1714     case EnvelopeKaku2:
1715         return QCoreApplication::translate("QPageSize", "Envelope Kaku 2");
1716     case EnvelopeKaku3:
1717         return QCoreApplication::translate("QPageSize", "Envelope Kaku 3");
1718     case EnvelopePrc1:
1719         return QCoreApplication::translate("QPageSize", "Envelope PRC 1");
1720     case EnvelopePrc2:
1721         return QCoreApplication::translate("QPageSize", "Envelope PRC 2");
1722     case EnvelopePrc3:
1723         return QCoreApplication::translate("QPageSize", "Envelope PRC 3");
1724     case EnvelopePrc4:
1725         return QCoreApplication::translate("QPageSize", "Envelope PRC 4");
1726     case EnvelopePrc5:
1727         return QCoreApplication::translate("QPageSize", "Envelope PRC 5");
1728     case EnvelopePrc6:
1729         return QCoreApplication::translate("QPageSize", "Envelope PRC 6");
1730     case EnvelopePrc7:
1731         return QCoreApplication::translate("QPageSize", "Envelope PRC 7");
1732     case EnvelopePrc8:
1733         return QCoreApplication::translate("QPageSize", "Envelope PRC 8");
1734     case EnvelopePrc9:
1735         return QCoreApplication::translate("QPageSize", "Envelope PRC 9");
1736     case EnvelopePrc10:
1737         return QCoreApplication::translate("QPageSize", "Envelope PRC 10");
1738     case EnvelopeYou4:
1739         return QCoreApplication::translate("QPageSize", "Envelope You 4");
1740     }
1741     return QString();
1742 }
1743 
1744 /*!
1745     Returns the standard QPageSize::PageSizeId of the given \a pointSize in
1746     points using the given \a matchPolicy.
1747 
1748     If using FuzzyMatch then the point size of the PageSizeId returned may not
1749     exactly match the \a pointSize you passed in. You should call
1750     QPageSize::sizePoints() using the returned PageSizeId to find out the actual
1751     point size of the PageSizeId before using it in any calculations.
1752 */
1753 
id(const QSize & pointSize,SizeMatchPolicy matchPolicy)1754 QPageSize::PageSizeId QPageSize::id(const QSize &pointSize, SizeMatchPolicy matchPolicy)
1755 {
1756     return qt_idForPointSize(pointSize, matchPolicy, nullptr);
1757 }
1758 
1759 /*!
1760     Returns the standard QPageSize::PageSizeId of the given \a size in \a units
1761     using the given \a matchPolicy.
1762 
1763     If using FuzzyMatch then the unit size of the PageSizeId returned may not
1764     exactly match the \a size you passed in. You should call
1765     QPageSize::size() using the returned PageSizeId to find out the actual
1766     unit size of the PageSizeId before using it in any calculations.
1767 */
1768 
id(const QSizeF & size,Unit units,SizeMatchPolicy matchPolicy)1769 QPageSize::PageSizeId QPageSize::id(const QSizeF &size, Unit units,
1770                                     SizeMatchPolicy matchPolicy)
1771 {
1772     return qt_idForSize(size, units, matchPolicy, nullptr);
1773 }
1774 
1775 /*!
1776     Returns the PageSizeId for the given Windows DMPAPER enum value \a windowsId.
1777 
1778     If there is no matching PageSizeId then QPageSize::Custom is returned.
1779 */
1780 
id(int windowsId)1781 QPageSize::PageSizeId QPageSize::id(int windowsId)
1782 {
1783     return qt_idForWindowsID(windowsId);
1784 }
1785 
1786 /*!
1787     Returns the Windows DMPAPER enum value of the standard \a pageSizeId.
1788 
1789     Not all valid PPD page sizes have a Windows equivalent, in which case 0
1790     will be returned.
1791 */
1792 
windowsId(PageSizeId pageSizeId)1793 int QPageSize::windowsId(PageSizeId pageSizeId)
1794 {
1795     return qt_pageSizes[pageSizeId].windowsId;
1796 }
1797 
1798 /*!
1799     Returns the definition size of the standard \a pageSizeId.
1800 
1801     To obtain the definition units, call QPageSize::definitionUnits().
1802 */
1803 
definitionSize(PageSizeId pageSizeId)1804 QSizeF QPageSize::definitionSize(PageSizeId pageSizeId)
1805 {
1806     if (pageSizeId == Custom)
1807         return QSizeF();
1808     return qt_definitionSize(pageSizeId);
1809 }
1810 
1811 /*!
1812     Returns the definition units of the standard \a pageSizeId.
1813 
1814     To obtain the definition size, call QPageSize::definitionSize().
1815 */
1816 
definitionUnits(PageSizeId pageSizeId)1817 QPageSize::Unit QPageSize::definitionUnits(PageSizeId pageSizeId)
1818 {
1819     if (pageSizeId == Custom)
1820         return Unit(-1);
1821     return qt_pageSizes[pageSizeId].definitionUnits;
1822 }
1823 
1824 /*!
1825     Returns the size of the standard \a pageSizeId in the requested \a units.
1826 */
1827 
size(PageSizeId pageSizeId,Unit units)1828 QSizeF QPageSize::size(PageSizeId pageSizeId, Unit units)
1829 {
1830     if (pageSizeId == Custom)
1831         return QSizeF();
1832     return qt_unitSize(pageSizeId, units);
1833 }
1834 
1835 /*!
1836     Returns the size of the standard \a pageSizeId in Points.
1837 */
1838 
sizePoints(PageSizeId pageSizeId)1839 QSize QPageSize::sizePoints(PageSizeId pageSizeId)
1840 {
1841     if (pageSizeId == Custom)
1842         return QSize();
1843     return QSize(qt_pageSizes[pageSizeId].widthPoints, qt_pageSizes[pageSizeId].heightPoints);
1844 }
1845 
1846 /*!
1847     Returns the size of the standard \a pageSizeId in Device Pixels
1848     for the given \a resolution.
1849 */
1850 
sizePixels(PageSizeId pageSizeId,int resolution)1851 QSize QPageSize::sizePixels(PageSizeId pageSizeId, int resolution)
1852 {
1853     if (pageSizeId == Custom)
1854         return QSize();
1855     return qt_convertPointsToPixels(sizePoints(pageSizeId), resolution);
1856 }
1857 
1858 #ifndef QT_NO_DEBUG_STREAM
operator <<(QDebug dbg,const QPageSize & pageSize)1859 QDebug operator<<(QDebug dbg, const QPageSize &pageSize)
1860 {
1861     QDebugStateSaver saver(dbg);
1862     dbg.nospace();
1863     dbg.noquote();
1864     dbg << "QPageSize(";
1865     if (pageSize.isValid()) {
1866         dbg << '"' << pageSize.name() << "\", key=\"" << pageSize.key()
1867             << "\", " << pageSize.sizePoints().width() << 'x'
1868             << pageSize.sizePoints().height() << "pt, id=" << pageSize.id();
1869     } else {
1870         dbg.nospace() << "QPageSize()";
1871     }
1872     dbg << ')';
1873     return dbg;
1874 }
1875 #endif
1876 
1877 QT_END_NAMESPACE
1878