From 83e6d1fe6006ad8e3cf37d5ca412aedae5aab9a4 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 1 Jan 2013 01:33:42 +0100 Subject: Add support for getting the paper names available for the printer Task-number: QTBUG-27714 Change-Id: I9bc6f1188f262e43f581add058d7895e1b5bd9e3 Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../platforms/cocoa/qcocoaprintersupport.mm | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/plugins/platforms/cocoa/qcocoaprintersupport.mm') diff --git a/src/plugins/platforms/cocoa/qcocoaprintersupport.mm b/src/plugins/platforms/cocoa/qcocoaprintersupport.mm index a48db02949..cfa23b7a30 100644 --- a/src/plugins/platforms/cocoa/qcocoaprintersupport.mm +++ b/src/plugins/platforms/cocoa/qcocoaprintersupport.mm @@ -138,3 +138,34 @@ QPrinterInfo QCocoaPrinterSupport::printerInfoFromPMPrinter(const PMPrinter &pri return createPrinterInfo(name, description, location, makeAndModel, isDefault, 0); } + +QList > QCocoaPrinterSupport::supportedSizesWithNames(const QPrinterInfo &printerInfo) const +{ + QList > returnValue; + if (printerInfo.isNull()) + return returnValue; + + PMPrinter printer = PMPrinterCreateFromPrinterID(QCFString::toCFStringRef(printerInfo.printerName())); + if (!printer) + return returnValue; + + CFArrayRef array; + if (PMPrinterGetPaperList(printer, &array) != noErr) { + PMRelease(printer); + return returnValue; + } + + int count = CFArrayGetCount(array); + for (int i = 0; i < count; ++i) { + PMPaper paper = static_cast(const_cast(CFArrayGetValueAtIndex(array, i))); + double width, height; + if (PMPaperGetWidth(paper, &width) == noErr && PMPaperGetHeight(paper, &height) == noErr) { + static const double OnePointInMillimeters = 1.0 / 72.0 * 25.4; + QCFString paperName; + if (PMPaperCreateLocalizedName(paper, printer, &paperName) == noErr) + returnValue.append(qMakePair(QString(paperName), QSizeF(width * OnePointInMillimeters, height * OnePointInMillimeters))); + } + } + PMRelease(printer); + return returnValue; +} -- cgit v1.2.3