summaryrefslogtreecommitdiffstats
path: root/src/printsupport/kernel/qprintengine_win.cpp
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2012-12-29 17:08:12 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-12 09:16:42 +0100
commit39a902c0081f442141353c466ada09d62036c04e (patch)
tree6a203f89bd6a4b781acfb27ea7672c6d68471e94 /src/printsupport/kernel/qprintengine_win.cpp
parent62fe32b37c173f9dc82f4f95ae50b2e95a719d77 (diff)
Add support for setting/getting the paper name on the QPrinter
This adds support for specifying a paper name which will be set on the printer if it is available for the driver. Change-Id: Id7fd0c8cf68745db3d7a8de7e2ac98d3e2ba9b79 Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'src/printsupport/kernel/qprintengine_win.cpp')
-rw-r--r--src/printsupport/kernel/qprintengine_win.cpp87
1 files changed, 76 insertions, 11 deletions
diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp
index 7c67fd2845..c798ac0c7f 100644
--- a/src/printsupport/kernel/qprintengine_win.cpp
+++ b/src/printsupport/kernel/qprintengine_win.cpp
@@ -167,6 +167,16 @@ static int mapPaperSourceDevmode(QPrinter::PaperSource s)
return sources[i].winSourceName ? sources[i].winSourceName : s;
}
+static inline uint qwcsnlen(const wchar_t *str, uint maxlen)
+{
+ uint length = 0;
+ if (str) {
+ while (length < maxlen && *str++)
+ length++;
+ }
+ return length;
+}
+
QWin32PrintEngine::QWin32PrintEngine(QPrinter::PrinterMode mode)
: QAlphaPaintEngine(*(new QWin32PrintEnginePrivate),
PaintEngineFeatures(PrimitiveTransform
@@ -1285,7 +1295,39 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
d->has_custom_paper_size = (QPrinter::PaperSize(value.toInt()) == QPrinter::Custom);
d->doReinit();
break;
-
+ case PPK_PaperName:
+ {
+ if (!d->devMode)
+ break;
+ DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()),
+ NULL, DC_PAPERNAMES, NULL, NULL);
+ if ((int)size > 0) {
+ wchar_t *paperNames = new wchar_t[size*64];
+ size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()),
+ NULL, DC_PAPERNAMES, paperNames, NULL);
+ int paperPos = -1;
+ for (int i=0;i<(int)size;i++) {
+ wchar_t *copyOfPaper = paperNames + (i * 64);
+ if (value.toString() == QString::fromWCharArray(copyOfPaper, qwcsnlen(copyOfPaper, 64))) {
+ paperPos = i;
+ break;
+ }
+ }
+ delete [] paperNames;
+ size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()),
+ NULL, DC_PAPERS, NULL, NULL);
+ if ((int)size > 0) {
+ wchar_t *papers = new wchar_t[size];
+ size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()),
+ NULL, DC_PAPERS, papers, NULL);
+ d->has_custom_paper_size = false;
+ d->devMode->dmPaperSize = papers[paperPos];
+ d->doReinit();
+ delete [] papers;
+ }
+ }
+ }
+ break;
case PPK_PaperSource:
{
if (!d->devMode)
@@ -1479,7 +1521,40 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const
value = QTransform(1/d->stretch_x, 0, 0, 1/d->stretch_y, 0, 0).mapRect(d->devPaperRect);
}
break;
+ case PPK_PaperName:
+ if (!d->devMode) {
+ value = QLatin1String("A4");
+ } else {
+ DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()),
+ NULL, DC_PAPERS, NULL, NULL);
+ int paperSizePos = -1;
+ if ((int)size > 0) {
+ wchar_t *papers = new wchar_t[size];
+ size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()),
+ NULL, DC_PAPERS, papers, NULL);
+ for (int i=0;i<(int)size;i++) {
+ if (papers[i] == d->devMode->dmPaperSize) {
+ paperSizePos = i;
+ break;
+ }
+ }
+ delete [] papers;
+ }
+ if (paperSizePos != -1) {
+ size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.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*>(d->name.utf16()),
+ NULL, DC_PAPERNAMES, papers, NULL);
+ wchar_t *copyOfPaper = papers + (paperSizePos * 64);
+ value = QString::fromWCharArray(copyOfPaper, qwcsnlen(copyOfPaper, 64));
+ delete [] papers;
+ }
+ }
+ }
+ break;
case PPK_PaperSource:
if (!d->devMode) {
value = QPrinter::Auto;
@@ -1596,16 +1671,6 @@ 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;