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