QtBase  v6.3.1
qprint_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 John Layt <jlayt@kde.org>
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtPrintSupport module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QPRINT_P_H
41 #define QPRINT_P_H
42 
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtPrintSupport/private/qtprintsupportglobal_p.h>
55 #include <QtPrintSupport/qprinter.h>
56 
57 #include <QtCore/qstring.h>
58 #include <QtCore/qlist.h>
59 
60 #if (defined Q_OS_MACOS) || (defined Q_OS_UNIX && QT_CONFIG(cups))
61 #include <cups/ppd.h> // Use for type defs only, don't want to actually link in main module
62 Q_DECLARE_METATYPE(ppd_file_t *)
63 #endif
64 
66 
67 #ifndef QT_NO_PRINTER
68 
69 // From windgdi.h
70 #define DMBIN_UPPER 1
71 #define DMBIN_ONLYONE 1
72 #define DMBIN_LOWER 2
73 #define DMBIN_MIDDLE 3
74 #define DMBIN_MANUAL 4
75 #define DMBIN_ENVELOPE 5
76 #define DMBIN_ENVMANUAL 6
77 #define DMBIN_AUTO 7
78 #define DMBIN_TRACTOR 8
79 #define DMBIN_SMALLFMT 9
80 #define DMBIN_LARGEFMT 10
81 #define DMBIN_LARGECAPACITY 11
82 #define DMBIN_CASSETTE 14
83 #define DMBIN_FORMSOURCE 15
84 #define DMBIN_USER 256
85 
86 namespace QPrint {
87 
88  // Note: Keep in sync with QPrinter::PrinterState for now
89  // Replace later with more detailed status reporting
90  enum DeviceState {
94  Error
95  };
96 
97  // Note: Keep in sync with QPrinter::DuplexMode
98  enum DuplexMode {
103  };
104 
105  enum ColorMode {
107  Color
108  };
109 
110  // Note: Keep in sync with QPrinter::PaperSource for now
111  // If/when made public, rearrange and rename
112  enum InputSlotId {
126  MaxPageSource, // Deprecated, kept for compatibility to QPrinter
129  OnlyOne = Upper
130  };
131 
132  struct InputSlot {
137  };
138 
139  enum OutputBinId {
146  };
147 
148  struct OutputBin {
152  };
153 
154 }
155 
156 struct InputSlotMap {
159  const char *key;
160 };
161 
162 // Note: PPD standard does not define a standard set of InputSlot keywords,
163 // it is a free form text field left to the PPD writer to decide,
164 // but it does suggest some names for consistency with the Windows enum.
165 static const InputSlotMap inputSlotMap[] = {
166  { QPrint::Upper, DMBIN_UPPER, "Upper" },
167  { QPrint::Lower, DMBIN_LOWER, "Lower" },
168  { QPrint::Middle, DMBIN_MIDDLE, "Middle" },
169  { QPrint::Manual, DMBIN_MANUAL, "Manual" },
170  { QPrint::Envelope, DMBIN_ENVELOPE, "Envelope" },
171  { QPrint::EnvelopeManual, DMBIN_ENVMANUAL, "EnvelopeManual" },
172  { QPrint::Auto, DMBIN_AUTO, "Auto" },
173  { QPrint::Tractor, DMBIN_TRACTOR, "Tractor" },
174  { QPrint::SmallFormat, DMBIN_SMALLFMT, "AnySmallFormat" },
175  { QPrint::LargeFormat, DMBIN_LARGEFMT, "AnyLargeFormat" },
176  { QPrint::LargeCapacity, DMBIN_LARGECAPACITY, "LargeCapacity" },
177  { QPrint::Cassette, DMBIN_CASSETTE, "Cassette" },
178  { QPrint::FormSource, DMBIN_FORMSOURCE, "FormSource" },
179  { QPrint::Manual, DMBIN_MANUAL, "ManualFeed" },
180  { QPrint::OnlyOne, DMBIN_ONLYONE, "OnlyOne" }, // = QPrint::Upper
181  { QPrint::CustomInputSlot, DMBIN_USER, "" } // Must always be last row
182 };
183 
184 struct OutputBinMap {
186  const char *key;
187 };
188 
189 static const OutputBinMap outputBinMap[] = {
190  { QPrint::AutoOutputBin, "" }, // Not a PPD defined value, internal use only
191  { QPrint::UpperBin, "Upper" },
192  { QPrint::LowerBin, "Lower" },
193  { QPrint::RearBin, "Rear" },
194  { QPrint::CustomOutputBin, "" } // Must always be last row
195 };
196 
197 // Print utilities shared by print plugins
198 
200 {
201 
202 public:
203 
205  {
206  for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
207  if (inputSlotMap[i].key == key)
208  return inputSlotMap[i].id;
209  }
211  }
212 
214  {
215  for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
216  if (inputSlotMap[i].id == id)
217  return QByteArray(inputSlotMap[i].key);
218  }
219  return QByteArray();
220  }
221 
223  {
224  for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
225  if (inputSlotMap[i].id == id)
226  return inputSlotMap[i].windowsId;
227  }
228  return 0;
229  }
230 
232  {
233  for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
234  if (outputBinMap[i].key == key)
235  return outputBinMap[i].id;
236  }
238  }
239 
241  {
242  for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
243  if (outputBinMap[i].id == id)
244  return QByteArray(outputBinMap[i].key);
245  }
246  return QByteArray();
247  }
248 
249 #if (defined Q_OS_MACOS) || (defined Q_OS_UNIX && QT_CONFIG(cups))
250 
251  // PPD utilities shared by CUPS and Mac plugins requiring CUPS headers
252  // May turn into a proper internal QPpd class if enough shared between Mac and CUPS,
253  // but where would it live? Not in base module as don't want to link to CUPS.
254  // May have to have two copies in plugins to keep in sync.
255 
256  static QPrint::InputSlot ppdChoiceToInputSlot(const ppd_choice_t &choice)
257  {
259  input.key = choice.choice;
260  input.name = QString::fromUtf8(choice.text);
262  input.windowsId = inputSlotMap[input.id].windowsId;
263  return input;
264  }
265 
266  static QPrint::OutputBin ppdChoiceToOutputBin(const ppd_choice_t &choice)
267  {
268  QPrint::OutputBin output;
269  output.key = choice.choice;
270  output.name = QString::fromUtf8(choice.text);
271  output.id = outputBinKeyToOutputBinId(output.key);
272  return output;
273  }
274 
275  static int parsePpdResolution(const QByteArray &value)
276  {
277  if (value.isEmpty())
278  return -1;
279  // value can be in form 600dpi or 600x600dpi
280  QByteArray result = value.split('x').at(0);
281  if (result.endsWith("dpi"))
282  result.chop(3);
283  return result.toInt();
284  }
285 
286  static QPrint::DuplexMode ppdChoiceToDuplexMode(const QByteArray &choice)
287  {
288  if (choice == "DuplexTumble")
290  else if (choice == "DuplexNoTumble")
291  return QPrint::DuplexLongSide;
292  else // None or SimplexTumble or SimplexNoTumble
293  return QPrint::DuplexNone;
294  }
295 
296 #endif // Mac and CUPS PPD Utilities
297 
298 };
299 
300 #endif // QT_NO_PRINTER
301 
303 
304 #endif // QPRINT_P_H
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:85
QList< QByteArray > split(char sep) const
void chop(qsizetype n)
const_reference at(qsizetype i) const noexcept
Definition: qlist.h:457
static int inputSlotIdToWindowsId(QPrint::InputSlotId id)
Definition: qprint_p.h:222
static QByteArray outputBinIdToOutputBinKey(QPrint::OutputBinId id)
Definition: qprint_p.h:240
static QByteArray inputSlotIdToInputSlotKey(QPrint::InputSlotId id)
Definition: qprint_p.h:213
static QPrint::InputSlotId inputSlotKeyToInputSlotId(const QByteArray &key)
Definition: qprint_p.h:204
static QPrint::OutputBinId outputBinKeyToOutputBinId(const QByteArray &key)
Definition: qprint_p.h:231
The QString class provides a Unicode character string.
Definition: qstring.h:388
static QString fromUtf8(QByteArrayView utf8)
Definition: qstring.cpp:5632
ColorMode
Definition: qprint_p.h:105
@ Color
Definition: qprint_p.h:107
@ GrayScale
Definition: qprint_p.h:106
DuplexMode
Definition: qprint_p.h:98
@ DuplexLongSide
Definition: qprint_p.h:101
@ DuplexShortSide
Definition: qprint_p.h:102
@ DuplexNone
Definition: qprint_p.h:99
@ DuplexAuto
Definition: qprint_p.h:100
InputSlotId
Definition: qprint_p.h:112
@ CustomInputSlot
Definition: qprint_p.h:127
@ FormSource
Definition: qprint_p.h:125
@ OnlyOne
Definition: qprint_p.h:129
@ Envelope
Definition: qprint_p.h:117
@ EnvelopeManual
Definition: qprint_p.h:118
@ LargeCapacity
Definition: qprint_p.h:123
@ LargeFormat
Definition: qprint_p.h:122
@ Cassette
Definition: qprint_p.h:124
@ Lower
Definition: qprint_p.h:114
@ Upper
Definition: qprint_p.h:113
@ Middle
Definition: qprint_p.h:115
@ SmallFormat
Definition: qprint_p.h:121
@ Tractor
Definition: qprint_p.h:120
@ Auto
Definition: qprint_p.h:119
@ LastInputSlot
Definition: qprint_p.h:128
@ MaxPageSource
Definition: qprint_p.h:126
@ Manual
Definition: qprint_p.h:116
OutputBinId
Definition: qprint_p.h:139
@ LowerBin
Definition: qprint_p.h:142
@ LastOutputBin
Definition: qprint_p.h:145
@ RearBin
Definition: qprint_p.h:143
@ UpperBin
Definition: qprint_p.h:141
@ CustomOutputBin
Definition: qprint_p.h:144
@ AutoOutputBin
Definition: qprint_p.h:140
DeviceState
Definition: qprint_p.h:90
@ Idle
Definition: qprint_p.h:91
@ Error
Definition: qprint_p.h:94
@ Aborted
Definition: qprint_p.h:93
@ Active
Definition: qprint_p.h:92
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
#define Q_DECLARE_METATYPE(TYPE)
Definition: qmetatype.h:1417
GLuint64 key
GLuint64EXT * result
[6]
Definition: qopenglext.h:10932
GLenum GLenum GLenum input
Definition: qopenglext.h:10816
#define DMBIN_FORMSOURCE
Definition: qprint_p.h:83
#define DMBIN_ONLYONE
Definition: qprint_p.h:71
#define DMBIN_ENVELOPE
Definition: qprint_p.h:75
#define DMBIN_CASSETTE
Definition: qprint_p.h:82
#define DMBIN_TRACTOR
Definition: qprint_p.h:78
#define DMBIN_AUTO
Definition: qprint_p.h:77
#define DMBIN_LOWER
Definition: qprint_p.h:72
#define DMBIN_SMALLFMT
Definition: qprint_p.h:79
#define DMBIN_UPPER
Definition: qprint_p.h:70
#define DMBIN_ENVMANUAL
Definition: qprint_p.h:76
#define DMBIN_USER
Definition: qprint_p.h:84
#define DMBIN_MIDDLE
Definition: qprint_p.h:73
#define DMBIN_MANUAL
Definition: qprint_p.h:74
#define DMBIN_LARGECAPACITY
Definition: qprint_p.h:81
#define DMBIN_LARGEFMT
Definition: qprint_p.h:80
QPrint::InputSlotId id
Definition: qprint_p.h:157
const char * key
Definition: qprint_p.h:159
int windowsId
Definition: qprint_p.h:158
QPrint::OutputBinId id
Definition: qprint_p.h:185
const char * key
Definition: qprint_p.h:186
QPrint::InputSlotId id
Definition: qprint_p.h:135
QByteArray key
Definition: qprint_p.h:133
QPrint::OutputBinId id
Definition: qprint_p.h:151
QByteArray key
Definition: qprint_p.h:149