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