summaryrefslogtreecommitdiffstats
path: root/src/printsupport/kernel/qprintengine_win.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/printsupport/kernel/qprintengine_win.cpp')
-rw-r--r--src/printsupport/kernel/qprintengine_win.cpp56
1 files changed, 42 insertions, 14 deletions
diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp
index 9e74de4ab1..910c6c1514 100644
--- a/src/printsupport/kernel/qprintengine_win.cpp
+++ b/src/printsupport/kernel/qprintengine_win.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
@@ -10,9 +10,9 @@
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -23,8 +23,8 @@
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
@@ -89,6 +89,17 @@ QWin32PrintEngine::QWin32PrintEngine(QPrinter::PrinterMode mode)
d->initialize();
}
+static QByteArray msgBeginFailed(const char *function, const DOCINFO &d)
+{
+ QString result;
+ QTextStream str(&result);
+ str << "QWin32PrintEngine::begin: " << function << " failed, document \""
+ << QString::fromWCharArray(d.lpszDocName) << '"';
+ if (d.lpszOutput[0])
+ str << ", file \"" << QString::fromWCharArray(d.lpszOutput) << '"';
+ return result.toLocal8Bit();
+}
+
bool QWin32PrintEngine::begin(QPaintDevice *pdev)
{
Q_D(QWin32PrintEngine);
@@ -123,12 +134,12 @@ bool QWin32PrintEngine::begin(QPaintDevice *pdev)
if (d->printToFile)
di.lpszOutput = d->fileName.isEmpty() ? L"FILE:" : reinterpret_cast<const wchar_t *>(d->fileName.utf16());
if (ok && StartDoc(d->hdc, &di) == SP_ERROR) {
- qErrnoWarning("QWin32PrintEngine::begin: StartDoc failed");
+ qErrnoWarning(msgBeginFailed("StartDoc", di));
ok = false;
}
if (StartPage(d->hdc) <= 0) {
- qErrnoWarning("QWin32PrintEngine::begin: StartPage failed");
+ qErrnoWarning(msgBeginFailed("StartPage", di));
ok = false;
}
@@ -175,8 +186,10 @@ bool QWin32PrintEngine::end()
return true;
if (d->hdc) {
- EndPage(d->hdc); // end; printing done
- EndDoc(d->hdc);
+ if (EndPage(d->hdc) <= 0) // end; printing done
+ qErrnoWarning("QWin32PrintEngine::end: EndPage failed (%p)", d->hdc);
+ if (EndDoc(d->hdc) <= 0)
+ qErrnoWarning("QWin32PrintEngine::end: EndDoc failed");
}
d->state = QPrinter::Idle;
@@ -201,10 +214,8 @@ bool QWin32PrintEngine::newPage()
}
if (d->reinit) {
- if (!d->resetDC()) {
- qErrnoWarning("QWin32PrintEngine::newPage: ResetDC failed");
+ if (!d->resetDC())
return false;
- }
d->reinit = false;
}
@@ -241,6 +252,8 @@ bool QWin32PrintEngine::newPage()
d->reinit = false;
}
success = (StartPage(d->hdc) > 0);
+ if (!success)
+ qErrnoWarning("Win32PrintEngine::newPage: StartPage failed (2)");
}
if (!success) {
d->state = QPrinter::Aborted;
@@ -996,6 +1009,21 @@ void QWin32PrintEnginePrivate::doReinit()
}
}
+bool QWin32PrintEnginePrivate::resetDC()
+{
+ if (!hdc) {
+ qWarning() << "ResetDC() called with null hdc.";
+ return false;
+ }
+ const HDC oldHdc = hdc;
+ const HDC hdc = ResetDC(oldHdc, devMode);
+ if (!hdc) {
+ const int lastError = GetLastError();
+ qErrnoWarning(lastError, "ResetDC() on %p failed (%d)", oldHdc, lastError);
+ }
+ return hdc != 0;
+}
+
static int indexOfId(const QList<QPrint::InputSlot> &inputSlots, QPrint::InputSlotId id)
{
for (int i = 0; i < inputSlots.size(); ++i) {