Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qprint.cpp
Go to the documentation of this file.
1
// Copyright (C) 2022 The Qt Company Ltd.
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
"qprint_p.h"
6
7
QT_BEGIN_NAMESPACE
8
9
#
ifndef
QT_NO_PRINTER
10
11
// Note: PPD standard does not define a standard set of InputSlot keywords,
12
// it is a free form text field left to the PPD writer to decide,
13
// but it does suggest some names for consistency with the Windows enum.
14
static
const
InputSlotMap
inputSlotMap
[] = {
15
{
QPrint
::
Upper
,
DMBIN_UPPER
,
"Upper"
},
16
{
QPrint
::
Lower
,
DMBIN_LOWER
,
"Lower"
},
17
{
QPrint
::
Middle
,
DMBIN_MIDDLE
,
"Middle"
},
18
{
QPrint
::
Manual
,
DMBIN_MANUAL
,
"Manual"
},
19
{
QPrint
::
Envelope
,
DMBIN_ENVELOPE
,
"Envelope"
},
20
{
QPrint
::
EnvelopeManual
,
DMBIN_ENVMANUAL
,
"EnvelopeManual"
},
21
{
QPrint
::
Auto
,
DMBIN_AUTO
,
"Auto"
},
22
{
QPrint
::
Tractor
,
DMBIN_TRACTOR
,
"Tractor"
},
23
{
QPrint
::
SmallFormat
,
DMBIN_SMALLFMT
,
"AnySmallFormat"
},
24
{
QPrint
::
LargeFormat
,
DMBIN_LARGEFMT
,
"AnyLargeFormat"
},
25
{
QPrint
::
LargeCapacity
,
DMBIN_LARGECAPACITY
,
"LargeCapacity"
},
26
{
QPrint
::
Cassette
,
DMBIN_CASSETTE
,
"Cassette"
},
27
{
QPrint
::
FormSource
,
DMBIN_FORMSOURCE
,
"FormSource"
},
28
{
QPrint
::
Manual
,
DMBIN_MANUAL
,
"ManualFeed"
},
29
{
QPrint
::
OnlyOne
,
DMBIN_ONLYONE
,
"OnlyOne"
},
// = QPrint::Upper
30
{
QPrint
::
CustomInputSlot
,
DMBIN_USER
,
""
}
// Must always be last row
31
};
32
33
static
const
OutputBinMap
outputBinMap
[] = {
34
{
QPrint
::
AutoOutputBin
,
""
},
// Not a PPD defined value, internal use only
35
{
QPrint
::
UpperBin
,
"Upper"
},
36
{
QPrint
::
LowerBin
,
"Lower"
},
37
{
QPrint
::
RearBin
,
"Rear"
},
38
{
QPrint
::
CustomOutputBin
,
""
}
// Must always be last row
39
};
40
41
namespace
QPrintUtils
{
42
43
QPrint
::
InputSlotId
inputSlotKeyToInputSlotId
(
const
QByteArray &key)
44
{
45
for
(
int
i = 0;
inputSlotMap
[i]
.
id
!=
QPrint
::
CustomInputSlot
; ++i) {
46
if
(
inputSlotMap
[i]
.
key
== key)
47
return
inputSlotMap
[i]
.
id
;
48
}
49
return
QPrint
::
CustomInputSlot
;
50
}
51
52
QByteArray
inputSlotIdToInputSlotKey
(
QPrint
::
InputSlotId
id)
53
{
54
for
(
int
i = 0;
inputSlotMap
[i]
.
id
!=
QPrint
::
CustomInputSlot
; ++i) {
55
if
(
inputSlotMap
[i]
.
id
== id)
56
return
QByteArray(
inputSlotMap
[i]
.
key
);
57
}
58
return
QByteArray();
59
}
60
61
int
inputSlotIdToWindowsId
(
QPrint
::
InputSlotId
id)
62
{
63
for
(
int
i = 0;
inputSlotMap
[i]
.
id
!=
QPrint
::
CustomInputSlot
; ++i) {
64
if
(
inputSlotMap
[i]
.
id
== id)
65
return
inputSlotMap
[i]
.
windowsId
;
66
}
67
return
0;
68
}
69
70
QPrint
::
OutputBinId
outputBinKeyToOutputBinId
(
const
QByteArray &key)
71
{
72
for
(
int
i = 0;
outputBinMap
[i]
.
id
!=
QPrint
::
CustomOutputBin
; ++i) {
73
if
(
outputBinMap
[i]
.
key
== key)
74
return
outputBinMap
[i]
.
id
;
75
}
76
return
QPrint
::
CustomOutputBin
;
77
}
78
79
QByteArray
outputBinIdToOutputBinKey
(
QPrint
::
OutputBinId
id)
80
{
81
for
(
int
i = 0;
outputBinMap
[i]
.
id
!=
QPrint
::
CustomOutputBin
; ++i) {
82
if
(
outputBinMap
[i]
.
id
== id)
83
return
QByteArray(
outputBinMap
[i]
.
key
);
84
}
85
return
QByteArray();
86
}
87
88
QPrint
::
InputSlot
paperBinToInputSlot
(
int
windowsId,
const
QString &name)
89
{
90
QPrint
::
InputSlot
slot;
91
slot.name = name;
92
int
i;
93
for
(i = 0;
inputSlotMap
[i]
.
id
!=
QPrint
::
CustomInputSlot
; ++i) {
94
if
(
inputSlotMap
[i]
.
windowsId
== windowsId) {
95
slot.key =
inputSlotMap
[i]
.
key
;
96
slot
.
id
=
inputSlotMap
[i]
.
id
;
97
slot
.
windowsId
=
inputSlotMap
[i]
.
windowsId
;
98
return
slot;
99
}
100
}
101
slot.key =
inputSlotMap
[i]
.
key
;
102
slot
.
id
=
inputSlotMap
[i]
.
id
;
103
slot
.
windowsId
= windowsId;
104
return
slot;
105
}
106
107
#
if
(
defined
Q_OS_MACOS
)
||
(
defined
Q_OS_UNIX
&&
QT_CONFIG
(
cups
)
)
108
109
// PPD utilities shared by CUPS and Mac plugins requiring CUPS headers
110
// May turn into a proper internal QPpd class if enough shared between Mac and CUPS,
111
// but where would it live? Not in base module as don't want to link to CUPS.
112
// May have to have two copies in plugins to keep in sync.
113
114
QPrint
::
InputSlot
ppdChoiceToInputSlot
(
const
ppd_choice_t
&
choice
)
115
{
116
QPrint
::
InputSlot
input
;
117
input
.
key
=
choice
.
choice
;
118
input
.
name
=
QString
::
fromUtf8
(
choice
.
text
);
119
input
.
id
=
inputSlotKeyToInputSlotId
(
input
.
key
);
120
input
.
windowsId
=
inputSlotMap
[
input
.
id
].
windowsId
;
121
return
input
;
122
}
123
124
QPrint
::
OutputBin
ppdChoiceToOutputBin
(
const
ppd_choice_t
&
choice
)
125
{
126
QPrint
::
OutputBin
output
;
127
output
.
key
=
choice
.
choice
;
128
output
.
name
=
QString
::
fromUtf8
(
choice
.
text
);
129
output
.
id
=
outputBinKeyToOutputBinId
(
output
.
key
);
130
return
output
;
131
}
132
133
int
parsePpdResolution
(
const
QByteArray
&
value
)
134
{
135
if
(
value
.
isEmpty
())
136
return
-1;
137
// value can be in form 600dpi or 600x600dpi
138
QByteArray
result
=
value
.
split
(
'x'
).
at
(0);
139
if
(
result
.
endsWith
(
"dpi"
))
140
result
.
chop
(3);
141
return
result
.
toInt
();
142
}
143
144
QPrint
::
DuplexMode
ppdChoiceToDuplexMode
(
const
QByteArray
&
choice
)
145
{
146
if
(
choice
==
"DuplexTumble"
)
147
return
QPrint
::
DuplexShortSide
;
148
else
if
(
choice
==
"DuplexNoTumble"
)
149
return
QPrint
::
DuplexLongSide
;
150
else
// None or SimplexTumble or SimplexNoTumble
151
return
QPrint
::
DuplexNone
;
152
}
153
154
#
endif
// Mac and CUPS PPD Utilities
155
156
}
157
158
#
endif
// QT_NO_PRINTER
159
160
QT_END_NAMESPACE
QPrintUtils
Definition
qprint.cpp:41
QPrintUtils::inputSlotIdToWindowsId
int inputSlotIdToWindowsId(QPrint::InputSlotId id)
Definition
qprint.cpp:61
QPrintUtils::inputSlotKeyToInputSlotId
QPrint::InputSlotId inputSlotKeyToInputSlotId(const QByteArray &key)
Definition
qprint.cpp:43
QPrintUtils::outputBinIdToOutputBinKey
QByteArray outputBinIdToOutputBinKey(QPrint::OutputBinId id)
Definition
qprint.cpp:79
QPrintUtils::inputSlotIdToInputSlotKey
QByteArray inputSlotIdToInputSlotKey(QPrint::InputSlotId id)
Definition
qprint.cpp:52
QPrintUtils::paperBinToInputSlot
QPrint::InputSlot paperBinToInputSlot(int windowsId, const QString &name)
Definition
qprint.cpp:88
QPrintUtils::outputBinKeyToOutputBinId
QPrint::OutputBinId outputBinKeyToOutputBinId(const QByteArray &key)
Definition
qprint.cpp:70
QPrint
Definition
qprint_p.h:53
QPrint::InputSlotId
InputSlotId
Definition
qprint_p.h:80
QPrint::CustomInputSlot
@ CustomInputSlot
Definition
qprint_p.h:95
QPrint::FormSource
@ FormSource
Definition
qprint_p.h:93
QPrint::OnlyOne
@ OnlyOne
Definition
qprint_p.h:97
QPrint::Envelope
@ Envelope
Definition
qprint_p.h:85
QPrint::EnvelopeManual
@ EnvelopeManual
Definition
qprint_p.h:86
QPrint::LargeCapacity
@ LargeCapacity
Definition
qprint_p.h:91
QPrint::LargeFormat
@ LargeFormat
Definition
qprint_p.h:90
QPrint::Cassette
@ Cassette
Definition
qprint_p.h:92
QPrint::Lower
@ Lower
Definition
qprint_p.h:82
QPrint::Upper
@ Upper
Definition
qprint_p.h:81
QPrint::Middle
@ Middle
Definition
qprint_p.h:83
QPrint::SmallFormat
@ SmallFormat
Definition
qprint_p.h:89
QPrint::Tractor
@ Tractor
Definition
qprint_p.h:88
QPrint::Auto
@ Auto
Definition
qprint_p.h:87
QPrint::Manual
@ Manual
Definition
qprint_p.h:84
QPrint::OutputBinId
OutputBinId
Definition
qprint_p.h:107
QPrint::LowerBin
@ LowerBin
Definition
qprint_p.h:110
QPrint::RearBin
@ RearBin
Definition
qprint_p.h:111
QPrint::UpperBin
@ UpperBin
Definition
qprint_p.h:109
QPrint::CustomOutputBin
@ CustomOutputBin
Definition
qprint_p.h:112
QPrint::AutoOutputBin
@ AutoOutputBin
Definition
qprint_p.h:108
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
outputBinMap
static const OutputBinMap outputBinMap[]
Definition
qprint.cpp:33
inputSlotMap
static QT_BEGIN_NAMESPACE const InputSlotMap inputSlotMap[]
Definition
qprint.cpp:14
DMBIN_FORMSOURCE
#define DMBIN_FORMSOURCE
Definition
qprint_p.h:50
DMBIN_ONLYONE
#define DMBIN_ONLYONE
Definition
qprint_p.h:38
DMBIN_ENVELOPE
#define DMBIN_ENVELOPE
Definition
qprint_p.h:42
DMBIN_CASSETTE
#define DMBIN_CASSETTE
Definition
qprint_p.h:49
DMBIN_TRACTOR
#define DMBIN_TRACTOR
Definition
qprint_p.h:45
DMBIN_AUTO
#define DMBIN_AUTO
Definition
qprint_p.h:44
DMBIN_LOWER
#define DMBIN_LOWER
Definition
qprint_p.h:39
DMBIN_SMALLFMT
#define DMBIN_SMALLFMT
Definition
qprint_p.h:46
DMBIN_UPPER
#define DMBIN_UPPER
Definition
qprint_p.h:37
DMBIN_ENVMANUAL
#define DMBIN_ENVMANUAL
Definition
qprint_p.h:43
DMBIN_USER
#define DMBIN_USER
Definition
qprint_p.h:51
DMBIN_MIDDLE
#define DMBIN_MIDDLE
Definition
qprint_p.h:40
DMBIN_MANUAL
#define DMBIN_MANUAL
Definition
qprint_p.h:41
DMBIN_LARGECAPACITY
#define DMBIN_LARGECAPACITY
Definition
qprint_p.h:48
DMBIN_LARGEFMT
#define DMBIN_LARGEFMT
Definition
qprint_p.h:47
InputSlotMap
Definition
qprint_p.h:124
InputSlotMap::id
QPrint::InputSlotId id
Definition
qprint_p.h:125
InputSlotMap::key
const char * key
Definition
qprint_p.h:127
InputSlotMap::windowsId
int windowsId
Definition
qprint_p.h:126
OutputBinMap
Definition
qprint_p.h:130
OutputBinMap::id
QPrint::OutputBinId id
Definition
qprint_p.h:131
OutputBinMap::key
const char * key
Definition
qprint_p.h:132
QPrint::InputSlot
Definition
qprint_p.h:100
QPrint::InputSlot::windowsId
int windowsId
Definition
qprint_p.h:104
QPrint::InputSlot::id
QPrint::InputSlotId id
Definition
qprint_p.h:103
qtbase
src
printsupport
kernel
qprint.cpp
Generated on
for Qt by
1.18.0