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
49QT_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
54enum 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
186static 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
226struct 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
243static const StandardPageSize qt_pageSizes[] = {
244
245 // Old Qt sizes including ISO, US, ANSI and other standards
246 {QPageSize::Letter , DMPAPER_LETTER , QPageSize::Inch , 612, 792, 215.9, 279.4, 8.5 , 11 , "Letter"},
247 {QPageSize::Legal , DMPAPER_LEGAL , QPageSize::Inch , 612, 1008, 215.9, 355.6, 8.5 , 14 , "Legal"},
248 {QPageSize::Executive , DMPAPER_NONE , QPageSize::Inch , 540, 720, 190.5, 254 , 7.5 , 10 , "Executive.7.5x10in"}, // Qt size differs from Postscript / Windows
249 {QPageSize::A0 , DMPAPER_NONE , QPageSize::Millimeter, 2384, 3370, 841 , 1189 , 33.11, 46.81, "A0"},
250 {QPageSize::A1 , DMPAPER_NONE , QPageSize::Millimeter, 1684, 2384, 594 , 841 , 23.39, 33.11, "A1"},
251 {QPageSize::A2 , DMPAPER_A2 , QPageSize::Millimeter, 1191, 1684, 420 , 594 , 16.54, 23.39, "A2"},
252 {QPageSize::A3 , DMPAPER_A3 , QPageSize::Millimeter, 842, 1191, 297 , 420 , 11.69, 16.54, "A3"},
253 {QPageSize::A4 , DMPAPER_A4 , QPageSize::Millimeter, 595, 842, 210 , 297 , 8.27, 11.69, "A4"},
254 {QPageSize::A5 , DMPAPER_A5 , QPageSize::Millimeter, 420, 595, 148 , 210 , 5.83, 8.27, "A5"},
255 {QPageSize::A6 , DMPAPER_A6 , QPageSize::Millimeter, 297, 420, 105 , 148 , 4.13, 5.83, "A6"},
256 {QPageSize::A7 , DMPAPER_NONE , QPageSize::Millimeter, 210, 297, 74 , 105 , 2.91, 4.13, "A7"},
257 {QPageSize::A8 , DMPAPER_NONE , QPageSize::Millimeter, 148, 210, 52 , 74 , 2.05, 2.91, "A8"},
258 {QPageSize::A9 , DMPAPER_NONE , QPageSize::Millimeter, 105, 148, 37 , 52 , 1.46, 2.05, "A9"},
259 {QPageSize::A10 , DMPAPER_NONE , QPageSize::Millimeter, 73, 105, 26 , 37 , 1.02, 1.46, "A10"},
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::B2 , DMPAPER_NONE , QPageSize::Millimeter, 1417, 2004, 500 , 707 , 19.68, 27.83, "ISOB2"},
263 {QPageSize::B3 , DMPAPER_NONE , QPageSize::Millimeter, 1001, 1417, 353 , 500 , 13.9 , 19.68, "ISOB3"},
264 {QPageSize::B4 , DMPAPER_ISO_B4 , QPageSize::Millimeter, 709, 1001, 250 , 353 , 9.84, 13.9 , "ISOB4"},
265 {QPageSize::B5 , DMPAPER_NONE , QPageSize::Millimeter, 499, 709, 176 , 250 , 6.9 , 9.8 , "ISOB5"},
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::B10 , DMPAPER_NONE , QPageSize::Millimeter, 88, 125, 31 , 44 , 1.22, 1.73, "ISOB10"},
271 {QPageSize::C5E , DMPAPER_ENV_C5 , QPageSize::Millimeter, 459, 649, 162 , 229 , 6.38, 9.02, "EnvC5"},
272 {QPageSize::Comm10E , DMPAPER_ENV_10 , QPageSize::Inch , 297, 684, 104.8, 241.3, 4.12, 9.5 , "Env10"},
273 {QPageSize::DLE , DMPAPER_ENV_DL , QPageSize::Millimeter, 312, 624, 110 , 220 , 4.33, 8.66, "EnvDL"},
274 {QPageSize::Folio , DMPAPER_NONE , QPageSize::Millimeter, 595, 935, 210 , 330 , 8.27, 13 , "Folio"},
275 {QPageSize::Ledger , DMPAPER_LEDGER , QPageSize::Inch , 1224, 792, 431.8, 279.4, 17 , 11 , "Ledger"},
276 {QPageSize::Tabloid , DMPAPER_TABLOID , QPageSize::Inch , 792, 1224, 279.4, 431.8, 11 , 17 , "Tabloid"},
277 {QPageSize::Custom , DMPAPER_USER , QPageSize::Millimeter, -1, -1, -1. , -1 , -1 , -1 , "Custom"}, // Special case to keep in sync with QPageSize::PageSizeId
278
279 // ISO Standard Sizes
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
387static const int pageSizesCount = int(sizeof(qt_pageSizes) / sizeof(qt_pageSizes[0]));
388static_assert(pageSizesCount == QPageSize::LastPageSize + 1);
389
390// Return key name for PageSize
391static QString qt_keyForPageSizeId(QPageSize::PageSizeId id)
392{
393 return QString::fromLatin1(qt_pageSizes[id].mediaOption);
394}
395
396// Return id name for PPD Key
397static QPageSize::PageSizeId qt_idForPpdKey(const QString &ppdKey, QSize *match = nullptr)
398{
399 if (ppdKey.isEmpty())
400 return QPageSize::Custom;
401 QStringView 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
418static 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
443static 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
472static 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.
506static 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.
526Q_GUI_EXPORT qreal qt_pixelMultiplier(int resolution)
527{
528 return resolution <= 0 ? 1.0 : 72.0 / resolution;
529}
530
531static 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
540static 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
563static 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
570static 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
578static 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
589static 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
608static 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
674static 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
712class QPageSizePrivate : public QSharedData
713{
714public:
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
735private:
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
751QPageSizePrivate::QPageSizePrivate()
752 : m_id(QPageSize::Custom),
753 m_windowsId(0),
754 m_units(QPageSize::Point)
755{
756}
757
758QPageSizePrivate::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
767QPageSizePrivate::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
778QPageSizePrivate::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
790QPageSizePrivate::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
805QPageSizePrivate::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
820QPageSizePrivate::~QPageSizePrivate()
821{
822}
823
824// Init a standard PageSizeId
825void 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
837void 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
849void 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
863bool 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
871bool QPageSizePrivate::isEquivalentTo(const QPageSizePrivate &other) const
872{
873 return m_pointSize == other.m_pointSize;
874}
875
876bool QPageSizePrivate::isValid() const
877{
878 return m_pointSize.isValid() && !m_key.isEmpty() && !m_name.isEmpty();
879}
880
881QSizeF 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
899QSize 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
1083 Due to historic reasons QPageSize::Executive is not the same as the standard
1084 Postscript and Windows Executive size, use QPageSize::ExecutiveStandard instead.
1085
1086 The Postscript standard size QPageSize::Folio is different to the Windows
1087 DMPAPER_FOLIO size, use the Postscript standard size QPageSize::FanFoldGermanLegal
1088 if needed.
1089*/
1090
1091/*!
1092 \enum QPageSize::Unit
1093
1094 This enum type is used to specify the measurement unit for page sizes.
1095
1096 \value Millimeter
1097 \value Point 1/72th of an inch
1098 \value Inch
1099 \value Pica 1/72th of a foot, 1/6th of an inch, 12 Points
1100 \value Didot 1/72th of a French inch, 0.375 mm
1101 \value Cicero 1/6th of a French inch, 12 Didot, 4.5mm
1102*/
1103
1104/*!
1105 \enum QPageSize::SizeMatchPolicy
1106
1107 \value FuzzyMatch Match to a standard page size if within the margin of tolerance.
1108 \value FuzzyOrientationMatch Match to a standard page size if within the margin of tolerance regardless of orientation.
1109 \value ExactMatch Only match to a standard page size if the sizes match exactly.
1110*/
1111
1112/*!
1113 Creates a null QPageSize.
1114*/
1115
1116QPageSize::QPageSize()
1117 : d(new QPageSizePrivate())
1118{
1119}
1120
1121/*!
1122 Creates a QPageSize of the standard \a pageSize.
1123
1124 If \a pageSize is QPageSize::Custom then the resulting QPageSize will not
1125 be valid. Use the custom size constructor instead.
1126*/
1127
1128QPageSize::QPageSize(PageSizeId pageSize)
1129 : d(new QPageSizePrivate(pageSize))
1130{
1131}
1132
1133/*!
1134 Creates a QPageSize of the given \a pointSize in Points using the matching \a matchPolicy.
1135
1136 If the given \a pointSize matches a standard QPageSize::PageSizeId, then that page
1137 size will be used. Note that if the \a matchPolicy is FuzzyMatch this may result
1138 in the \a pointSize being adjusted to the standard size. To prevent this happening
1139 use a \a matchPolicy of ExactMatch instead.
1140
1141 If the given \a pointSize is not a standard QPageSize::PageSizeId then a QPageSize::Custom
1142 size will be created.
1143
1144 If \a name is null then the standard localized name will be used. If a custom page
1145 size then a custom name in the format "Custom (width x height)" will be created.
1146
1147 The \a matchPolicy defaults to FuzzyMatch.
1148*/
1149
1150QPageSize::QPageSize(const QSize &pointSize, const QString &name, SizeMatchPolicy matchPolicy)
1151 : d(new QPageSizePrivate(pointSize, name, matchPolicy))
1152{
1153}
1154
1155/*!
1156 Creates a custom page of the given \a size in \a units.
1157
1158 If the given \a size matches a standard QPageSize::PageSizeId, then that page
1159 size will be used. Note that if the \a matchPolicy is FuzzyMatch this may result
1160 in the \a size being adjusted to the standard size. To prevent this happening
1161 use a \a matchPolicy of ExactMatch instead.
1162
1163 If the given \a size is not a standard QPageSize::PageSizeId then a QPageSize::Custom
1164 size will be created. The original unit size will be preserved and used as the
1165 base for all other unit size calculations.
1166
1167 If \a name is null then a custom name will be created in the form
1168 "Custom (width x height)" where the size is expressed in units provided.
1169*/
1170
1171QPageSize::QPageSize(const QSizeF &size, Unit units,
1172 const QString &name, SizeMatchPolicy matchPolicy)
1173 : d(new QPageSizePrivate(size, units, name, matchPolicy))
1174{
1175}
1176
1177/*!
1178 \internal
1179
1180 Create page with given key, size and name, for use by printer plugin.
1181*/
1182
1183QPageSize::QPageSize(const QString &key, const QSize &pointSize, const QString &name)
1184 : d(new QPageSizePrivate(key, pointSize, name))
1185{
1186}
1187
1188/*!
1189 \internal
1190
1191 Create page with given windows ID, size and name, for use by printer plugin.
1192*/
1193
1194QPageSize::QPageSize(int windowsId, const QSize &pointSize, const QString &name)
1195 : d(new QPageSizePrivate(windowsId, pointSize, name))
1196{
1197}
1198
1199/*!
1200 \internal
1201
1202 Create page with given private backend
1203*/
1204
1205QPageSize::QPageSize(QPageSizePrivate &dd)
1206 : d(&dd)
1207{
1208}
1209
1210/*!
1211 Copy constructor, copies \a other to this.
1212*/
1213
1214QPageSize::QPageSize(const QPageSize &other)
1215 : d(other.d)
1216{
1217}
1218
1219/*!
1220 Destroys the page.
1221*/
1222
1223QPageSize::~QPageSize()
1224{
1225}
1226
1227/*!
1228 Assignment operator, assigns \a other to this.
1229*/
1230
1231QPageSize &QPageSize::operator=(const QPageSize &other)
1232{
1233 d = other.d;
1234 return *this;
1235}
1236
1237/*!
1238 \fn void QPageSize::swap(QPageSize &other)
1239
1240 Swaps this QPageSize with \a other. This function is very fast and
1241 never fails.
1242*/
1243
1244/*!
1245 \fn QPageSize &QPageSize::operator=(QPageSize &&other)
1246
1247 Move-assigns \a other to this QPageSize instance, transferring the
1248 ownership of the managed pointer to this instance.
1249*/
1250
1251/*!
1252 \relates QPageSize
1253
1254 Returns \c true if page size \a lhs is equal to page size \a rhs,
1255 i.e. if the page sizes have the same attributes. Current
1256 attributes are size and name.
1257*/
1258
1259bool operator==(const QPageSize &lhs, const QPageSize &rhs)
1260{
1261 return lhs.d == rhs.d || *lhs.d == *rhs.d;
1262}
1263/*!
1264 \fn bool operator!=(const QPageSize &lhs, const QPageSize &rhs)
1265 \relates QPageSize
1266
1267 Returns \c true if page size \a lhs is unequal to page size \a
1268 rhs, i.e. if the page size has different attributes. Current
1269 attributes are size and name.
1270*/
1271
1272/*!
1273 Returns \c true if this page is equivalent to the \a other page, i.e. if the
1274 page has the same size regardless of other attributes like name.
1275*/
1276
1277bool QPageSize::isEquivalentTo(const QPageSize &other) const
1278{
1279 if (d == other.d)
1280 return true;
1281 return d && other.d && d->isEquivalentTo(*other.d);
1282}
1283
1284/*!
1285 Returns \c true if this page size is valid.
1286
1287 The page size may be invalid if created with an invalid PageSizeId, or a
1288 negative or invalid QSize or QSizeF, or the null constructor.
1289*/
1290
1291bool QPageSize::isValid() const
1292{
1293 return d && d->isValid();
1294}
1295
1296/*!
1297 Returns the unique key of the page size.
1298
1299 By default this is the PPD standard mediaOption keyword for the page size,
1300 or the PPD custom format key. If the QPageSize instance was obtained from
1301 a print device then this will be the key provided by the print device and
1302 may differ from the standard key.
1303
1304 If the QPageSize is invalid then the key will be an empty string.
1305
1306 This key should never be shown to end users, it is an internal key only.
1307 For a human-readable name use name().
1308
1309 \sa name()
1310*/
1311
1312QString QPageSize::key() const
1313{
1314 return isValid() ? d->m_key : QString();
1315}
1316
1317/*!
1318 Returns a localized human-readable name for the page size.
1319
1320 If the QPageSize instance was obtained from a print device then the name
1321 used is that provided by the print device. Note that a print device may
1322 not support the current default locale language.
1323
1324 If the QPageSize is invalid then the name will be an empty string.
1325*/
1326
1327QString QPageSize::name() const
1328{
1329 return isValid() ? d->m_name : QString();
1330}
1331
1332/*!
1333 Returns the standard QPageSize::PageSizeId of the page, or QPageSize::Custom.
1334
1335 If the QPageSize is invalid then the ID will be QPageSize::Custom.
1336*/
1337
1338QPageSize::PageSizeId QPageSize::id() const
1339{
1340 return isValid() ? d->m_id : Custom;
1341}
1342
1343/*!
1344 Returns the Windows DMPAPER enum value for the page size.
1345
1346 Not all valid PPD page sizes have a Windows equivalent, in which case 0
1347 will be returned.
1348
1349 If the QPageSize is invalid then the Windows ID will be 0.
1350
1351 \sa id()
1352*/
1353
1354int QPageSize::windowsId() const
1355{
1356 if (!isValid())
1357 return 0;
1358 return d->m_windowsId > 0 ? d->m_windowsId : windowsId(d->m_id);
1359}
1360
1361/*!
1362 Returns the definition size of the page size.
1363
1364 For a standard page size this will be the size as defined in the relevant
1365 standard, i.e. ISO A4 will be defined in millimeters while ANSI Letter will
1366 be defined in inches.
1367
1368 For a custom page size this will be the original size used to create the
1369 page size object.
1370
1371 If the QPageSize is invalid then the QSizeF will be invalid.
1372
1373 \sa definitionUnits()
1374*/
1375
1376QSizeF QPageSize::definitionSize() const
1377{
1378 return isValid() ? d->m_size : QSizeF();
1379}
1380
1381/*!
1382 Returns the definition units of the page size.
1383
1384 For a standard page size this will be the units as defined in the relevant
1385 standard, i.e. ISO A4 will be defined in millimeters while ANSI Letter will
1386 be defined in inches.
1387
1388 For a custom page size this will be the original units used to create the
1389 page size object.
1390
1391 If the QPageSize is invalid then the QPageSize::Unit will be invalid.
1392
1393 \sa definitionSize()
1394*/
1395
1396QPageSize::Unit QPageSize::definitionUnits() const
1397{
1398 return isValid() ? d->m_units : Unit(-1);
1399}
1400
1401/*!
1402 Returns the size of the page in the required \a units.
1403
1404 If the QPageSize is invalid then the QSizeF will be invalid.
1405*/
1406
1407QSizeF QPageSize::size(Unit units) const
1408{
1409 return isValid() ? d->size(units) : QSize();
1410}
1411
1412/*!
1413 Returns the size of the page in Postscript Points (1/72 of an inch).
1414
1415 If the QPageSize is invalid then the QSize will be invalid.
1416*/
1417
1418QSize QPageSize::sizePoints() const
1419{
1420 return isValid() ? d->m_pointSize : QSize();
1421}
1422
1423/*!
1424 Returns the size of the page in Device Pixels at the given \a resolution.
1425
1426 If the QPageSize is invalid then the QSize will be invalid.
1427*/
1428
1429QSize QPageSize::sizePixels(int resolution) const
1430{
1431 return isValid() ? d->sizePixels(resolution) : QSize();
1432}
1433
1434/*!
1435 Returns the page rectangle in the required \a units.
1436
1437 If the QPageSize is invalid then the QRect will be invalid.
1438*/
1439
1440QRectF QPageSize::rect(Unit units) const
1441{
1442 return isValid() ? QRectF(QPointF(0, 0), d->size(units)) : QRectF();
1443}
1444
1445/*!
1446 Returns the page rectangle in Postscript Points (1/72 of an inch).
1447
1448 If the QPageSize is invalid then the QRect will be invalid.
1449*/
1450
1451QRect QPageSize::rectPoints() const
1452{
1453 return isValid() ? QRect(QPoint(0, 0), d->m_pointSize) : QRect();
1454}
1455
1456/*!
1457 Returns the page rectangle in Device Pixels at the given \a resolution.
1458
1459 If the QPageSize is invalid then the QRect will be invalid.
1460*/
1461
1462QRect QPageSize::rectPixels(int resolution) const
1463{
1464 return isValid() ? QRect(QPoint(0, 0), d->sizePixels(resolution)) : QRect();
1465}
1466
1467// Statics
1468
1469/*!
1470 Returns the PPD mediaOption keyword of the standard \a pageSizeId.
1471
1472 If the QPageSize is invalid then the key will be empty.
1473*/
1474
1475QString QPageSize::key(PageSizeId pageSizeId)
1476{
1477 if (unsigned(pageSizeId) > unsigned(LastPageSize))
1478 return QString();
1479 return QString::fromUtf8(qt_pageSizes[pageSizeId].mediaOption);
1480}
1481
1482static QString msgImperialPageSizeInch(int width, int height)
1483{
1484 //: Page size in 'Inch'.
1485 return QCoreApplication::translate("QPageSize", "%1 x %2 in").arg(width).arg(height);
1486}
1487
1488/*!
1489 Returns the localized name of the standard \a pageSizeId.
1490
1491 If the QPageSize is invalid then the name will be empty.
1492*/
1493
1494QString QPageSize::name(PageSizeId pageSizeId)
1495{
1496 if (unsigned(pageSizeId) > unsigned(LastPageSize))
1497 return QString();
1498
1499 switch (pageSizeId) {
1500 case A0:
1501 return QCoreApplication::translate("QPageSize", "A0");
1502 case A1:
1503 return QCoreApplication::translate("QPageSize", "A1");
1504 case A2:
1505 return QCoreApplication::translate("QPageSize", "A2");
1506 case A3:
1507 return QCoreApplication::translate("QPageSize", "A3");
1508 case A4:
1509 return QCoreApplication::translate("QPageSize", "A4");
1510 case A5:
1511 return QCoreApplication::translate("QPageSize", "A5");
1512 case A6:
1513 return QCoreApplication::translate("QPageSize", "A6");
1514 case A7:
1515 return QCoreApplication::translate("QPageSize", "A7");
1516 case A8:
1517 return QCoreApplication::translate("QPageSize", "A8");
1518 case A9:
1519 return QCoreApplication::translate("QPageSize", "A9");
1520 case A10:
1521 return QCoreApplication::translate("QPageSize", "A10");
1522 case B0:
1523 return QCoreApplication::translate("QPageSize", "B0");
1524 case B1:
1525 return QCoreApplication::translate("QPageSize", "B1");
1526 case B2:
1527 return QCoreApplication::translate("QPageSize", "B2");
1528 case B3:
1529 return QCoreApplication::translate("QPageSize", "B3");
1530 case B4:
1531 return QCoreApplication::translate("QPageSize", "B4");
1532 case B5:
1533 return QCoreApplication::translate("QPageSize", "B5");
1534 case B6:
1535 return QCoreApplication::translate("QPageSize", "B6");
1536 case B7:
1537 return QCoreApplication::translate("QPageSize", "B7");
1538 case B8:
1539 return QCoreApplication::translate("QPageSize", "B8");
1540 case B9:
1541 return QCoreApplication::translate("QPageSize", "B9");
1542 case B10:
1543 return QCoreApplication::translate("QPageSize", "B10");
1544 case Executive:
1545 return QCoreApplication::translate("QPageSize", "Executive (7.5 x 10 in)");
1546 case ExecutiveStandard:
1547 return QCoreApplication::translate("QPageSize", "Executive (7.25 x 10.5 in)");
1548 case Folio:
1549 return QCoreApplication::translate("QPageSize", "Folio (8.27 x 13 in)");
1550 case Legal:
1551 return QCoreApplication::translate("QPageSize", "Legal");
1552 case Letter:
1553 return QCoreApplication::translate("QPageSize", "Letter / ANSI A");
1554 case Tabloid:
1555 return QCoreApplication::translate("QPageSize", "Tabloid / ANSI B");
1556 case Ledger:
1557 return QCoreApplication::translate("QPageSize", "Ledger / ANSI B");
1558 case Custom:
1559 return QCoreApplication::translate("QPageSize", "Custom");
1560 case A3Extra:
1561 return QCoreApplication::translate("QPageSize", "A3 Extra");
1562 case A4Extra:
1563 return QCoreApplication::translate("QPageSize", "A4 Extra");
1564 case A4Plus:
1565 return QCoreApplication::translate("QPageSize", "A4 Plus");
1566 case A4Small:
1567 return QCoreApplication::translate("QPageSize", "A4 Small");
1568 case A5Extra:
1569 return QCoreApplication::translate("QPageSize", "A5 Extra");
1570 case B5Extra:
1571 return QCoreApplication::translate("QPageSize", "B5 Extra");
1572 case JisB0:
1573 return QCoreApplication::translate("QPageSize", "JIS B0");
1574 case JisB1:
1575 return QCoreApplication::translate("QPageSize", "JIS B1");
1576 case JisB2:
1577 return QCoreApplication::translate("QPageSize", "JIS B2");
1578 case JisB3:
1579 return QCoreApplication::translate("QPageSize", "JIS B3");
1580 case JisB4:
1581 return QCoreApplication::translate("QPageSize", "JIS B4");
1582 case JisB5:
1583 return QCoreApplication::translate("QPageSize", "JIS B5");
1584 case JisB6:
1585 return QCoreApplication::translate("QPageSize", "JIS B6");
1586 case JisB7:
1587 return QCoreApplication::translate("QPageSize", "JIS B7");
1588 case JisB8:
1589 return QCoreApplication::translate("QPageSize", "JIS B8");
1590 case JisB9:
1591 return QCoreApplication::translate("QPageSize", "JIS B9");
1592 case JisB10:
1593 return QCoreApplication::translate("QPageSize", "JIS B10");
1594 case AnsiC:
1595 return QCoreApplication::translate("QPageSize", "ANSI C");
1596 case AnsiD:
1597 return QCoreApplication::translate("QPageSize", "ANSI D");
1598 case AnsiE:
1599 return QCoreApplication::translate("QPageSize", "ANSI E");
1600 case LegalExtra:
1601 return QCoreApplication::translate("QPageSize", "Legal Extra");
1602 case LetterExtra:
1603 return QCoreApplication::translate("QPageSize", "Letter Extra");
1604 case LetterPlus:
1605 return QCoreApplication::translate("QPageSize", "Letter Plus");
1606 case LetterSmall:
1607 return QCoreApplication::translate("QPageSize", "Letter Small");
1608 case TabloidExtra:
1609 return QCoreApplication::translate("QPageSize", "Tabloid Extra");
1610 case ArchA:
1611 return QCoreApplication::translate("QPageSize", "Architect A");
1612 case ArchB:
1613 return QCoreApplication::translate("QPageSize", "Architect B");
1614 case ArchC:
1615 return QCoreApplication::translate("QPageSize", "Architect C");
1616 case ArchD:
1617 return QCoreApplication::translate("QPageSize", "Architect D");
1618 case ArchE:
1619 return QCoreApplication::translate("QPageSize", "Architect E");
1620 case Imperial7x9:
1621 return msgImperialPageSizeInch(7, 9);
1622 case Imperial8x10:
1623 return msgImperialPageSizeInch(8, 10);
1624 case Imperial9x11:
1625 return msgImperialPageSizeInch(9, 11);
1626 case Imperial9x12:
1627 return msgImperialPageSizeInch(9, 12);
1628 case Imperial10x11:
1629 return msgImperialPageSizeInch(10, 11);
1630 case Imperial10x13:
1631 return msgImperialPageSizeInch(10, 13);
1632 case Imperial10x14:
1633 return msgImperialPageSizeInch(10, 14);
1634 case Imperial12x11:
1635 return msgImperialPageSizeInch(12, 11);
1636 case Imperial15x11:
1637 return msgImperialPageSizeInch(15, 11);
1638 case Note:
1639 return QCoreApplication::translate("QPageSize", "Note");
1640 case Quarto:
1641 return QCoreApplication::translate("QPageSize", "Quarto");
1642 case Statement:
1643 return QCoreApplication::translate("QPageSize", "Statement");
1644 case SuperA:
1645 return QCoreApplication::translate("QPageSize", "Super A");
1646 case SuperB:
1647 return QCoreApplication::translate("QPageSize", "Super B");
1648 case Postcard:
1649 return QCoreApplication::translate("QPageSize", "Postcard");
1650 case DoublePostcard:
1651 return QCoreApplication::translate("QPageSize", "Double Postcard");
1652 case Prc16K:
1653 return QCoreApplication::translate("QPageSize", "PRC 16K");
1654 case Prc32K:
1655 return QCoreApplication::translate("QPageSize", "PRC 32K");
1656 case Prc32KBig:
1657 return QCoreApplication::translate("QPageSize", "PRC 32K Big");
1658 case FanFoldUS:
1659 return QCoreApplication::translate("QPageSize", "Fan-fold US (14.875 x 11 in)");
1660 case FanFoldGerman:
1661 return QCoreApplication::translate("QPageSize", "Fan-fold German (8.5 x 12 in)");
1662 case FanFoldGermanLegal:
1663 return QCoreApplication::translate("QPageSize", "Fan-fold German Legal (8.5 x 13 in)");
1664 case EnvelopeB4:
1665 return QCoreApplication::translate("QPageSize", "Envelope B4");
1666 case EnvelopeB5:
1667 return QCoreApplication::translate("QPageSize", "Envelope B5");
1668 case EnvelopeB6:
1669 return QCoreApplication::translate("QPageSize", "Envelope B6");
1670 case EnvelopeC0:
1671 return QCoreApplication::translate("QPageSize", "Envelope C0");
1672 case EnvelopeC1:
1673 return QCoreApplication::translate("QPageSize", "Envelope C1");
1674 case EnvelopeC2:
1675 return QCoreApplication::translate("QPageSize", "Envelope C2");
1676 case EnvelopeC3:
1677 return QCoreApplication::translate("QPageSize", "Envelope C3");
1678 case EnvelopeC4:
1679 return QCoreApplication::translate("QPageSize", "Envelope C4");
1680 case EnvelopeC5: // C5E
1681 return QCoreApplication::translate("QPageSize", "Envelope C5");
1682 case EnvelopeC6:
1683 return QCoreApplication::translate("QPageSize", "Envelope C6");
1684 case EnvelopeC65:
1685 return QCoreApplication::translate("QPageSize", "Envelope C65");
1686 case EnvelopeC7:
1687 return QCoreApplication::translate("QPageSize", "Envelope C7");
1688 case EnvelopeDL: // DLE:
1689 return QCoreApplication::translate("QPageSize", "Envelope DL");
1690 case Envelope9:
1691 return QCoreApplication::translate("QPageSize", "Envelope US 9");
1692 case Envelope10: // Comm10E
1693 return QCoreApplication::translate("QPageSize", "Envelope US 10");
1694 case Envelope11:
1695 return QCoreApplication::translate("QPageSize", "Envelope US 11");
1696 case Envelope12:
1697 return QCoreApplication::translate("QPageSize", "Envelope US 12");
1698 case Envelope14:
1699 return QCoreApplication::translate("QPageSize", "Envelope US 14");
1700 case EnvelopeMonarch:
1701 return QCoreApplication::translate("QPageSize", "Envelope Monarch");
1702 case EnvelopePersonal:
1703 return QCoreApplication::translate("QPageSize", "Envelope Personal");
1704 case EnvelopeChou3:
1705 return QCoreApplication::translate("QPageSize", "Envelope Chou 3");
1706 case EnvelopeChou4:
1707 return QCoreApplication::translate("QPageSize", "Envelope Chou 4");
1708 case EnvelopeInvite:
1709 return QCoreApplication::translate("QPageSize", "Envelope Invite");
1710 case EnvelopeItalian:
1711 return QCoreApplication::translate("QPageSize", "Envelope Italian");
1712 case EnvelopeKaku2:
1713 return QCoreApplication::translate("QPageSize", "Envelope Kaku 2");
1714 case EnvelopeKaku3:
1715 return QCoreApplication::translate("QPageSize", "Envelope Kaku 3");
1716 case EnvelopePrc1:
1717 return QCoreApplication::translate("QPageSize", "Envelope PRC 1");
1718 case EnvelopePrc2:
1719 return QCoreApplication::translate("QPageSize", "Envelope PRC 2");
1720 case EnvelopePrc3:
1721 return QCoreApplication::translate("QPageSize", "Envelope PRC 3");
1722 case EnvelopePrc4:
1723 return QCoreApplication::translate("QPageSize", "Envelope PRC 4");
1724 case EnvelopePrc5:
1725 return QCoreApplication::translate("QPageSize", "Envelope PRC 5");
1726 case EnvelopePrc6:
1727 return QCoreApplication::translate("QPageSize", "Envelope PRC 6");
1728 case EnvelopePrc7:
1729 return QCoreApplication::translate("QPageSize", "Envelope PRC 7");
1730 case EnvelopePrc8:
1731 return QCoreApplication::translate("QPageSize", "Envelope PRC 8");
1732 case EnvelopePrc9:
1733 return QCoreApplication::translate("QPageSize", "Envelope PRC 9");
1734 case EnvelopePrc10:
1735 return QCoreApplication::translate("QPageSize", "Envelope PRC 10");
1736 case EnvelopeYou4:
1737 return QCoreApplication::translate("QPageSize", "Envelope You 4");
1738 }
1739 return QString();
1740}
1741
1742/*!
1743 Returns the standard QPageSize::PageSizeId of the given \a pointSize in
1744 points using the given \a matchPolicy.
1745
1746 If using FuzzyMatch then the point size of the PageSizeId returned may not
1747 exactly match the \a pointSize you passed in. You should call
1748 QPageSize::sizePoints() using the returned PageSizeId to find out the actual
1749 point size of the PageSizeId before using it in any calculations.
1750*/
1751
1752QPageSize::PageSizeId QPageSize::id(const QSize &pointSize, SizeMatchPolicy matchPolicy)
1753{
1754 return qt_idForPointSize(pointSize, matchPolicy, nullptr);
1755}
1756
1757/*!
1758 Returns the standard QPageSize::PageSizeId of the given \a size in \a units
1759 using the given \a matchPolicy.
1760
1761 If using FuzzyMatch then the unit size of the PageSizeId returned may not
1762 exactly match the \a size you passed in. You should call
1763 QPageSize::size() using the returned PageSizeId to find out the actual
1764 unit size of the PageSizeId before using it in any calculations.
1765*/
1766
1767QPageSize::PageSizeId QPageSize::id(const QSizeF &size, Unit units,
1768 SizeMatchPolicy matchPolicy)
1769{
1770 return qt_idForSize(size, units, matchPolicy, nullptr);
1771}
1772
1773/*!
1774 Returns the PageSizeId for the given Windows DMPAPER enum value \a windowsId.
1775
1776 If there is no matching PageSizeId then QPageSize::Custom is returned.
1777*/
1778
1779QPageSize::PageSizeId QPageSize::id(int windowsId)
1780{
1781 return qt_idForWindowsID(windowsId);
1782}
1783
1784/*!
1785 Returns the Windows DMPAPER enum value of the standard \a pageSizeId.
1786
1787 Not all valid PPD page sizes have a Windows equivalent, in which case 0
1788 will be returned.
1789*/
1790
1791int QPageSize::windowsId(PageSizeId pageSizeId)
1792{
1793 return qt_pageSizes[pageSizeId].windowsId;
1794}
1795
1796/*!
1797 Returns the definition size of the standard \a pageSizeId.
1798
1799 To obtain the definition units, call QPageSize::definitionUnits().
1800*/
1801
1802QSizeF QPageSize::definitionSize(PageSizeId pageSizeId)
1803{
1804 if (pageSizeId == Custom)
1805 return QSizeF();
1806 return qt_definitionSize(pageSizeId);
1807}
1808
1809/*!
1810 Returns the definition units of the standard \a pageSizeId.
1811
1812 To obtain the definition size, call QPageSize::definitionSize().
1813*/
1814
1815QPageSize::Unit QPageSize::definitionUnits(PageSizeId pageSizeId)
1816{
1817 if (pageSizeId == Custom)
1818 return Unit(-1);
1819 return qt_pageSizes[pageSizeId].definitionUnits;
1820}
1821
1822/*!
1823 Returns the size of the standard \a pageSizeId in the requested \a units.
1824*/
1825
1826QSizeF QPageSize::size(PageSizeId pageSizeId, Unit units)
1827{
1828 if (pageSizeId == Custom)
1829 return QSizeF();
1830 return qt_unitSize(pageSizeId, units);
1831}
1832
1833/*!
1834 Returns the size of the standard \a pageSizeId in Points.
1835*/
1836
1837QSize QPageSize::sizePoints(PageSizeId pageSizeId)
1838{
1839 if (pageSizeId == Custom)
1840 return QSize();
1841 return QSize(qt_pageSizes[pageSizeId].widthPoints, qt_pageSizes[pageSizeId].heightPoints);
1842}
1843
1844/*!
1845 Returns the size of the standard \a pageSizeId in Device Pixels
1846 for the given \a resolution.
1847*/
1848
1849QSize QPageSize::sizePixels(PageSizeId pageSizeId, int resolution)
1850{
1851 if (pageSizeId == Custom)
1852 return QSize();
1853 return qt_convertPointsToPixels(sizePoints(pageSizeId), resolution);
1854}
1855
1856#ifndef QT_NO_DEBUG_STREAM
1857QDebug operator<<(QDebug dbg, const QPageSize &pageSize)
1858{
1859 QDebugStateSaver saver(dbg);
1860 dbg.nospace();
1861 dbg.noquote();
1862 dbg << "QPageSize(";
1863 if (pageSize.isValid()) {
1864 dbg << '"' << pageSize.name() << "\", key=\"" << pageSize.key()
1865 << "\", " << pageSize.sizePoints().width() << 'x'
1866 << pageSize.sizePoints().height() << "pt, id=" << pageSize.id();
1867 } else {
1868 dbg.nospace() << "QPageSize()";
1869 }
1870 dbg << ')';
1871 return dbg;
1872}
1873#endif
1874
1875QT_END_NAMESPACE
1876