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
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
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.
14static 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
33static 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
41namespace QPrintUtils {
42
44{
45 for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
46 if (inputSlotMap[i].key == key)
47 return inputSlotMap[i].id;
48 }
50}
51
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
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
71{
72 for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
73 if (outputBinMap[i].key == key)
74 return outputBinMap[i].id;
75 }
77}
78
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
88QPrint::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;
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
115{
121 return input;
122}
123
125{
130 return output;
131}
132
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
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
160QT_END_NAMESPACE
int inputSlotIdToWindowsId(QPrint::InputSlotId id)
Definition qprint.cpp:61
QPrint::InputSlotId inputSlotKeyToInputSlotId(const QByteArray &key)
Definition qprint.cpp:43
QByteArray outputBinIdToOutputBinKey(QPrint::OutputBinId id)
Definition qprint.cpp:79
QByteArray inputSlotIdToInputSlotKey(QPrint::InputSlotId id)
Definition qprint.cpp:52
QPrint::InputSlot paperBinToInputSlot(int windowsId, const QString &name)
Definition qprint.cpp:88
QPrint::OutputBinId outputBinKeyToOutputBinId(const QByteArray &key)
Definition qprint.cpp:70
InputSlotId
Definition qprint_p.h:80
@ CustomInputSlot
Definition qprint_p.h:95
@ FormSource
Definition qprint_p.h:93
@ OnlyOne
Definition qprint_p.h:97
@ Envelope
Definition qprint_p.h:85
@ EnvelopeManual
Definition qprint_p.h:86
@ LargeCapacity
Definition qprint_p.h:91
@ LargeFormat
Definition qprint_p.h:90
@ Cassette
Definition qprint_p.h:92
@ Lower
Definition qprint_p.h:82
@ Upper
Definition qprint_p.h:81
@ Middle
Definition qprint_p.h:83
@ SmallFormat
Definition qprint_p.h:89
@ Tractor
Definition qprint_p.h:88
@ Auto
Definition qprint_p.h:87
@ Manual
Definition qprint_p.h:84
OutputBinId
Definition qprint_p.h:107
@ LowerBin
Definition qprint_p.h:110
@ RearBin
Definition qprint_p.h:111
@ UpperBin
Definition qprint_p.h:109
@ CustomOutputBin
Definition qprint_p.h:112
@ AutoOutputBin
Definition qprint_p.h:108
static const OutputBinMap outputBinMap[]
Definition qprint.cpp:33
static QT_BEGIN_NAMESPACE const InputSlotMap inputSlotMap[]
Definition qprint.cpp:14
#define DMBIN_FORMSOURCE
Definition qprint_p.h:50
#define DMBIN_ONLYONE
Definition qprint_p.h:38
#define DMBIN_ENVELOPE
Definition qprint_p.h:42
#define DMBIN_CASSETTE
Definition qprint_p.h:49
#define DMBIN_TRACTOR
Definition qprint_p.h:45
#define DMBIN_AUTO
Definition qprint_p.h:44
#define DMBIN_LOWER
Definition qprint_p.h:39
#define DMBIN_SMALLFMT
Definition qprint_p.h:46
#define DMBIN_UPPER
Definition qprint_p.h:37
#define DMBIN_ENVMANUAL
Definition qprint_p.h:43
#define DMBIN_USER
Definition qprint_p.h:51
#define DMBIN_MIDDLE
Definition qprint_p.h:40
#define DMBIN_MANUAL
Definition qprint_p.h:41
#define DMBIN_LARGECAPACITY
Definition qprint_p.h:48
#define DMBIN_LARGEFMT
Definition qprint_p.h:47
QPrint::InputSlotId id
Definition qprint_p.h:125
const char * key
Definition qprint_p.h:127
QPrint::OutputBinId id
Definition qprint_p.h:131
const char * key
Definition qprint_p.h:132
QPrint::InputSlotId id
Definition qprint_p.h:103