diff options
Diffstat (limited to 'src/printsupport/kernel/qprintengine_win.cpp')
-rw-r--r-- | src/printsupport/kernel/qprintengine_win.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index 97453f2e0e..7c67fd2845 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -1596,6 +1596,46 @@ QList<QPrinter::PaperSize> QWin32PrintEngine::supportedPaperSizes(const QPrinter return returnList; } +static inline uint qwcsnlen(const wchar_t *str, uint maxlen) +{ + uint length = 0; + if (str) { + while (length < maxlen && *str++) + length++; + } + return length; +} + +QList<QPair<QString, QSizeF> > QWin32PrintEngine::supportedSizesWithNames(const QPrinterInfo &printerInfo) +{ + QList<QPair<QString, QSizeF> > paperSizes; + if (printerInfo.isNull()) + return paperSizes; + DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), + NULL, DC_PAPERNAMES, NULL, NULL); + if ((int)size > 0) { + wchar_t *papers = new wchar_t[size*64]; + size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), + NULL, DC_PAPERNAMES, papers, NULL); + DWORD size2 = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), + NULL, DC_PAPERSIZE, NULL, NULL); + if ((int)size2 > 0) { + POINT *points = new POINT[size2*sizeof(POINT)]; + + size2 = DeviceCapabilities(reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16()), + NULL, DC_PAPERSIZE, (wchar_t *)points, NULL); + for (int i=0;i<(int)size;i++) { + wchar_t *paper = papers + (i * 64); + QString str = QString::fromWCharArray(paper, qwcsnlen(paper, 64)); + paperSizes << qMakePair(str, QSizeF(points[i].x / 10, points[i].y / 10)); + } + delete [] points; + } + delete [] papers; + } + return paperSizes; +} + void QWin32PrintEngine::queryDefaultPrinter(QString &name, QString &program, QString &port) { /* Read the default printer name, driver and port with the intuitive function |