4#include <ApplicationServices/ApplicationServices.h>
9#include <QtCore/qmimedatabase.h>
13#include <QtCore/private/qcore_mac_p.h>
22#pragma clang diagnostic push
23#pragma clang diagnostic ignored "-Wdeprecated-declarations"
27 if (
mode == kPMDuplexTumble)
29 else if (
mode == kPMDuplexNoTumble)
50 m_printer = PMPrinterCreateFromPrinterID(
id.toCFString());
52 m_name = QString::fromCFString(PMPrinterGetName(m_printer));
53 m_location = QString::fromCFString(PMPrinterGetLocation(m_printer));
54 CFStringRef cfMakeAndModel;
55 if (PMPrinterGetMakeAndModelName(m_printer, &cfMakeAndModel) == noErr)
58 if (PMPrinterIsRemote(m_printer, &
isRemote) == noErr)
60 if (PMCreateSession(&m_session) == noErr)
61 PMSessionSetCurrentPMPrinter(m_session, m_printer);
68 ppd_option_t *collate = ppdFindOption(m_ppd,
"Collate");
74 m_customMargins =
QMarginsF(m_ppd->custom_margins[0], m_ppd->custom_margins[3],
75 m_ppd->custom_margins[2], m_ppd->custom_margins[1]);
85 for (PMPaper paper : m_macPapers)
96 return m_printer ? true :
false;
101 return PMPrinterIsDefault(m_printer);
106 PMPrinterState
state;
107 if (PMPrinterGetState(m_printer, &
state) == noErr) {
108 if (
state == kPMPrinterIdle)
110 else if (
state == kPMPrinterProcessing)
112 else if (
state == kPMPrinterStopped)
118QPageSize QCocoaPrintDevice::createPageSize(
const PMPaper &paper)
const
123 CFStringRef localizedName;
124 if (PMPaperGetPPDPaperName(paper, &
key) == noErr
125 && PMPaperGetWidth(paper, &
width) == noErr
126 && PMPaperGetHeight(paper, &
height) == noErr
127 && PMPaperCreateLocalizedName(paper, m_printer, &localizedName) == noErr) {
129 QString::fromCFString(localizedName));
130 CFRelease(localizedName);
139 for (PMPaper paper : m_macPapers)
142 m_printableMargins.
clear();
143 CFArrayRef paperSizes;
144 if (PMPrinterGetPaperList(m_printer, &paperSizes) == noErr) {
145 int count = CFArrayGetCount(paperSizes);
147 PMPaper paper =
static_cast<PMPaper
>(
const_cast<void *
>(CFArrayGetValueAtIndex(paperSizes,
i)));
148 QPageSize pageSize = createPageSize(paper);
152 m_macPapers.
insert(pageSize.
key(), paper);
153 PMPaperMargins printMargins;
154 PMPaperGetMargins(paper, &printMargins);
155 m_printableMargins.
insert(pageSize.
key(),
QMarginsF(printMargins.left, printMargins.top,
156 printMargins.right, printMargins.bottom));
166 PMPageFormat pageFormat;
168 if (PMCreatePageFormat(&pageFormat) == noErr) {
169 if (PMSessionDefaultPageFormat(m_session, pageFormat) == noErr
170 && PMGetPageFormatPaper(pageFormat, &paper) == noErr) {
171 pageSize = createPageSize(paper);
173 PMRelease(pageFormat);
180 int resolution)
const
187 return m_printableMargins.
value(pageSize.
key());
188 return m_customMargins;
195 if (PMPrinterGetPrinterResolutionCount(m_printer, &
count) == noErr) {
197 for (UInt32
i = 1;
i <=
count; ++
i) {
198 PMResolution resolution;
199 if (PMPrinterGetIndexedPrinterResolution(m_printer,
i, &resolution) == noErr)
210 if (PMCreatePrintSettings(&
settings) == noErr) {
211 PMResolution resolution;
212 if (PMSessionDefaultPrintSettings(m_session,
settings) == noErr
213 && PMPrinterGetOutputResolution(m_printer,
settings, &resolution) == noErr) {
240 ppd_option_t *inputSlots = ppdFindOption(m_ppd,
"InputSlot");
242 for (
int i = 0;
i < inputSlots->num_choices; ++
i)
247 inputSlots = ppdFindOption(m_ppd,
"DefaultInputSlot");
264 ppd_option_t *inputSlot = ppdFindOption(m_ppd,
"DefaultInputSlot");
266 return QPrintUtils::ppdChoiceToInputSlot(inputSlot->choices[0]);
268 ppd_choice_t *defaultChoice = ppdFindMarkedChoice(m_ppd,
"InputSlot");
270 return QPrintUtils::ppdChoiceToInputSlot(*defaultChoice);
282 ppd_option_t *outputBins = ppdFindOption(m_ppd,
"OutputBin");
284 for (
int i = 0;
i < outputBins->num_choices; ++
i)
289 outputBins = ppdFindOption(m_ppd,
"DefaultOutputBin");
306 ppd_option_t *outputBin = ppdFindOption(m_ppd,
"DefaultOutputBin");
308 return QPrintUtils::ppdChoiceToOutputBin(outputBin->choices[0]);
310 ppd_choice_t *defaultChoice = ppdFindMarkedChoice(m_ppd,
"OutputBin");
312 return QPrintUtils::ppdChoiceToOutputBin(*defaultChoice);
325 ppd_option_t *duplexModes = ppdFindOption(m_ppd,
"Duplex");
327 for (
int i = 0;
i < duplexModes->num_choices; ++
i)
332 duplexModes = ppdFindOption(m_ppd,
"DefaultDuplex");
350 if (PMCreatePrintSettings(&
settings) == noErr) {
351 PMDuplexMode duplexMode;
352 if (PMSessionDefaultPrintSettings(m_session,
settings) == noErr
353 && PMGetDuplex(
settings, &duplexMode) == noErr) {
366 if (!m_ppd || (m_ppd && m_ppd->color_device))
378 ppd_option_t *colorModel = ppdFindOption(m_ppd,
"DefaultColorModel");
380 colorModel = ppdFindOption(m_ppd,
"ColorModel");
381 if (!colorModel ||
qstrcmp(colorModel->defchoice,
"Gray") != 0)
387#if QT_CONFIG(mimetype)
388void QCocoaPrintDevice::loadMimeTypes()
const
394 if (PMCreatePrintSettings(&
settings) == noErr) {
395 CFArrayRef mimeTypes;
396 if (PMPrinterGetMimeTypes(m_printer,
settings, &mimeTypes) == noErr) {
397 int count = CFArrayGetCount(mimeTypes);
399 CFStringRef mimeName =
static_cast<CFStringRef
>(
const_cast<void *
>(CFArrayGetValueAtIndex(mimeTypes,
i)));
407 m_haveMimeTypes =
true;
411bool QCocoaPrintDevice::openPpdFile()
416 CFURLRef ppdURL =
nullptr;
417 char ppdPath[MAXPATHLEN];
418 if (PMPrinterCopyDescriptionURL(m_printer, kPMPPDDescriptionType, &ppdURL) == noErr
420 if (CFURLGetFileSystemRepresentation(ppdURL,
true, (UInt8*)ppdPath,
sizeof(ppdPath)))
421 m_ppd = ppdOpenFile(ppdPath);
424 return m_ppd ? true :
false;
440 return m_macPapers.
value(pageSize.
key());
442 PMPaper paper =
nullptr;
443 PMPaperMargins paperMargins;
444 paperMargins.left = m_customMargins.
left();
445 paperMargins.right = m_customMargins.
right();
446 paperMargins.top = m_customMargins.
top();
447 paperMargins.bottom = m_customMargins.
bottom();
450 &paperMargins, &paper);
451 m_macPapers.
insert(pageSize.
key(), paper);
455#pragma clang diagnostic pop
AVFCameraSession * m_session
virtual ~QCocoaPrintDevice()
int defaultResolution() const override
QPrint::OutputBin defaultOutputBin() const override
void loadResolutions() const override
QPageSize defaultPageSize() const override
void loadOutputBins() const override
void loadColorModes() const override
QPrint::DeviceState state() const override
PMPrinter macPrinter() const
QPrint::DuplexMode defaultDuplexMode() const override
QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation, int resolution) const override
void loadDuplexModes() const override
QPrint::InputSlot defaultInputSlot() const override
bool isDefault() const override
PMPaper macPaper(const QPageSize &pageSize) const
bool isValid() const override
QPrint::ColorMode defaultColorMode() const override
void loadPageSizes() const override
void loadInputSlots() const override
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
T value(const Key &key) const noexcept
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
qsizetype count() const noexcept
void append(parameter_type t)
constexpr qreal right() const noexcept
Returns the right margin.
constexpr qreal left() const noexcept
Returns the left margin.
constexpr qreal top() const noexcept
Returns the top margin.
constexpr qreal bottom() const noexcept
Returns the bottom margin.
QMimeType mimeTypeForName(const QString &nameOrAlias) const
Returns a MIME type for nameOrAlias or an invalid one if none found.
Orientation
This enum type defines the page orientation.
bool isValid() const
Returns true if this page size is valid.
QString key() const
Returns the unique key of the page size.
QString name() const
Returns a localized human-readable name for the page size.
QSize sizePoints() const
Returns the size of the page in Postscript Points (1/72 of an inch).
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Combined button and popup list for selecting options.
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
static QT_BEGIN_NAMESPACE QPrint::DuplexMode macToDuplexMode(const PMDuplexMode &mode)
static bool contains(const QJsonArray &haystack, unsigned needle)
GLint GLsizei GLsizei height
GLenum GLenum GLsizei count
QSettings settings("MySoft", "Star Runner")
[0]
bool contains(const AT &t) const noexcept