diff options
author | Oliver Wolff <oliver.wolff@nokia.com> | 2011-10-24 09:25:32 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-25 15:55:10 +0200 |
commit | 318a274381c441b13ce67517cad3fd74985c73a8 (patch) | |
tree | 3b845a73ea431267f565a4d4a88b5aeb16ff9672 /src | |
parent | 54c132480b171518328f39bcf3f0faf0ea50ef0b (diff) |
Readded PrintSupport for Windows
The prepared plugin architecture for
printing support was used as much as
possible but some functionality had to
be done in src/printsupport.
Change-Id: Ic8446cb8018a0970b4da97c1912ba6dc20d2a09f
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Diffstat (limited to 'src')
17 files changed, 436 insertions, 85 deletions
diff --git a/src/modules/qt_printsupport.pri b/src/modules/qt_printsupport.pri index 898f8b82b6..85603296a6 100644 --- a/src/modules/qt_printsupport.pri +++ b/src/modules/qt_printsupport.pri @@ -12,5 +12,3 @@ QT.printsupport.plugins = $$QT_MODULE_PLUGIN_BASE QT.printsupport.imports = $$QT_MODULE_IMPORT_BASE QT.printsupport.depends = core gui widgets QT.printsupport.DEFINES = QT_PRINTSUPPORT_LIB -# To be implemented: -win32: QT.printsupport.DEFINES *= QT_NO_PRINTER diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index f47c000dfb..19fa8711bb 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -13,4 +13,5 @@ symbian:SUBDIRS += s60 qpa: { SUBDIRS += platforms SUBDIRS += platforminputcontexts + SUBDIRS += printsupport } diff --git a/src/plugins/printsupport/printsupport.pro b/src/plugins/printsupport/printsupport.pro new file mode 100644 index 0000000000..9298e7981f --- /dev/null +++ b/src/plugins/printsupport/printsupport.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs + +win32: SUBDIRS += windows diff --git a/src/plugins/printsupport/windows/main.cpp b/src/plugins/printsupport/windows/main.cpp new file mode 100644 index 0000000000..1ed8f6d0ad --- /dev/null +++ b/src/plugins/printsupport/windows/main.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtPrintSupport/qplatformprintplugin_qpa.h> +#include <QtCore/QStringList> + +#include "qwindowsprintersupport.h" + +QT_BEGIN_NAMESPACE + +class QWindowsPrinterSupportPlugin : public QPlatformPrinterSupportPlugin +{ + Q_OBJECT +public: + QStringList keys() const; + QPlatformPrinterSupport *create(const QString &); +}; + +QStringList QWindowsPrinterSupportPlugin::keys() const +{ + return QStringList(QStringLiteral("windowsprintsupport")); +} + +QPlatformPrinterSupport *QWindowsPrinterSupportPlugin::create(const QString &key) +{ + if (key.compare(key, QStringLiteral("windowsprintsupport"), Qt::CaseInsensitive) == 0) + return new QWindowsPrinterSupport; + return 0; +} + +Q_EXPORT_PLUGIN2(windowsprint, QWindowsPrinterSupportPlugin) + +QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/printsupport/windows/qwindowsprinterinfo.cpp b/src/plugins/printsupport/windows/qwindowsprinterinfo.cpp new file mode 100644 index 0000000000..09ae632587 --- /dev/null +++ b/src/plugins/printsupport/windows/qwindowsprinterinfo.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qprinterinfo.h" +#include "qprinterinfo_p.h" + +#include <qstringlist.h> + +#include <qt_windows.h> + +QT_BEGIN_NAMESPACE + +#ifndef QT_NO_PRINTER + +extern QPrinter::PaperSize mapDevmodePaperSize(int s); + +//QList<QPrinterInfo> QPrinterInfo::availablePrinters() +//{ +// QList<QPrinterInfo> printers; + +// DWORD needed = 0; +// DWORD returned = 0; +// if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, 0, 0, &needed, &returned)) { +// LPBYTE buffer = new BYTE[needed]; +// if (EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, buffer, needed, &needed, &returned)) { +// PPRINTER_INFO_4 infoList = reinterpret_cast<PPRINTER_INFO_4>(buffer); +// QPrinterInfo defPrn = defaultPrinter(); +// for (uint i = 0; i < returned; ++i) { +// QString printerName(QString::fromWCharArray(infoList[i].pPrinterName)); + +// QPrinterInfo printerInfo(printerName); +// if (printerInfo.printerName() == defPrn.printerName()) +// printerInfo.d_ptr->isDefault = true; +// printers.append(printerInfo); +// } +// } +// delete [] buffer; +// } + +// return printers; +//} + +//QPrinterInfo QPrinterInfo::defaultPrinter() +//{ +// QString noPrinters(QLatin1String("qt_no_printers")); +// wchar_t buffer[256]; +// GetProfileString(L"windows", L"device", (wchar_t*)noPrinters.utf16(), buffer, 256); +// QString output = QString::fromWCharArray(buffer); +// if (output != noPrinters) { +// // Filter out the name of the printer, which should be everything before a comma. +// QString printerName = output.split(QLatin1Char(',')).value(0); +// QPrinterInfo printerInfo(printerName); +// printerInfo.d_ptr->isDefault = true; +// return printerInfo; +// } + +// return QPrinterInfo(); +//} + +//QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const +//{ +// const Q_D(QPrinterInfo); + +// QList<QPrinter::PaperSize> paperSizes; +// if (isNull()) +// return paperSizes; + +// DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), +// NULL, DC_PAPERS, NULL, NULL); +// if ((int)size != -1) { +// wchar_t *papers = new wchar_t[size]; +// size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), +// NULL, DC_PAPERS, papers, NULL); +// for (int c = 0; c < (int)size; ++c) +// paperSizes.append(mapDevmodePaperSize(papers[c])); +// delete [] papers; +// } + +// return paperSizes; +//} + +#endif // QT_NO_PRINTER + +QT_END_NAMESPACE diff --git a/src/widgets/platforms/win/qprinterinfo_win.cpp b/src/plugins/printsupport/windows/qwindowsprintersupport.cpp index cc0cd0232d..f7033733e1 100644 --- a/src/widgets/platforms/win/qprinterinfo_win.cpp +++ b/src/plugins/printsupport/windows/qwindowsprintersupport.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the QtGui module of the Qt Toolkit. +** This file is part of the plugins of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** GNU Lesser General Public License Usage @@ -39,23 +39,17 @@ ** ****************************************************************************/ -#include "qprinterinfo.h" -#include "qprinterinfo_p.h" +#include "qwindowsprintersupport.h" -#include <qstringlist.h> +#include <QtCore/QList> +#include <QtPrintSupport/QPrinterInfo> +#include <qprintengine_win_p.h> +#include <private/qpaintengine_alpha_p.h> +#include <private/qprinterinfo_p.h> -#include <qt_windows.h> - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_PRINTER - -extern QPrinter::PaperSize mapDevmodePaperSize(int s); - -QList<QPrinterInfo> QPrinterInfo::availablePrinters() +QWindowsPrinterSupport::QWindowsPrinterSupport() + : QPlatformPrinterSupport() { - QList<QPrinterInfo> printers; - DWORD needed = 0; DWORD returned = 0; if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, 0, 0, &needed, &returned)) { @@ -69,54 +63,40 @@ QList<QPrinterInfo> QPrinterInfo::availablePrinters() QPrinterInfo printerInfo(printerName); if (printerInfo.printerName() == defPrn.printerName()) printerInfo.d_ptr->isDefault = true; - printers.append(printerInfo); + mPrinterList.append(printerInfo); } } delete [] buffer; } - - return printers; } -QPrinterInfo QPrinterInfo::defaultPrinter() +QWindowsPrinterSupport::~QWindowsPrinterSupport() { - QString noPrinters(QLatin1String("qt_no_printers")); - wchar_t buffer[256]; - GetProfileString(L"windows", L"device", (wchar_t*)noPrinters.utf16(), buffer, 256); - QString output = QString::fromWCharArray(buffer); - if (output != noPrinters) { - // Filter out the name of the printer, which should be everything before a comma. - QString printerName = output.split(QLatin1Char(',')).value(0); - QPrinterInfo printerInfo(printerName); - printerInfo.d_ptr->isDefault = true; - return printerInfo; - } - - return QPrinterInfo(); } -QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const +QPrintEngine *QWindowsPrinterSupport::createNativePrintEngine(QPrinter::PrinterMode printerMode) { - const Q_D(QPrinterInfo); + return new QWin32PrintEngine(printerMode); +} - QList<QPrinter::PaperSize> paperSizes; - if (isNull()) - return paperSizes; +QPaintEngine *QWindowsPrinterSupport::createPaintEngine(QPrintEngine *engine, QPrinter::PrinterMode printerMode) +{ + Q_UNUSED(printerMode) + return static_cast<QWin32PrintEngine *>(engine); +} - DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), - NULL, DC_PAPERS, NULL, NULL); - if ((int)size != -1) { - wchar_t *papers = new wchar_t[size]; - size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()), - NULL, DC_PAPERS, papers, NULL); - for (int c = 0; c < (int)size; ++c) - paperSizes.append(mapDevmodePaperSize(papers[c])); - delete [] papers; +QList<QPrinter::PaperSize> QWindowsPrinterSupport::supportedPaperSizes(const QPrinterInfo &) const +{ + QList<QPrinter::PaperSize> returnList; + foreach (const QPrinterInfo &info, mPrinterList) { + foreach (const QPrinter::PaperSize supportedSize, info.supportedPaperSizes()) + if (!returnList.contains(supportedSize)) + returnList.append(supportedSize); } - - return paperSizes; + return returnList; } -#endif // QT_NO_PRINTER - -QT_END_NAMESPACE +QList<QPrinterInfo> QWindowsPrinterSupport::availablePrinters() +{ + return mPrinterList; +} diff --git a/src/plugins/printsupport/windows/qwindowsprintersupport.h b/src/plugins/printsupport/windows/qwindowsprintersupport.h new file mode 100644 index 0000000000..c45e79587a --- /dev/null +++ b/src/plugins/printsupport/windows/qwindowsprintersupport.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOWSPRINTERSUPPORT_H +#define WINDOWSPRINTERSUPPORT_H + +#include <QtCore/QList> +#include <QtPrintSupport/QPlatformPrinterSupport> + + +class QWin32PrintEngine; + +class QWindowsPrinterSupport : public QPlatformPrinterSupport +{ +public: + QWindowsPrinterSupport(); + ~QWindowsPrinterSupport(); + + virtual QPrintEngine *createNativePrintEngine(QPrinter::PrinterMode printerMode); + virtual QPaintEngine *createPaintEngine(QPrintEngine *printEngine, QPrinter::PrinterMode); + virtual QList<QPrinter::PaperSize> supportedPaperSizes(const QPrinterInfo &) const; + + virtual QList<QPrinterInfo> availablePrinters(); +private: + + QList<QPrinterInfo> mPrinterList; + QPrinter::PrinterMode mCurrentMode; +}; + +#endif // WINDOWSPRINTERSUPPORT_H diff --git a/src/plugins/printsupport/windows/windows.pro b/src/plugins/printsupport/windows/windows.pro new file mode 100644 index 0000000000..2032125f4b --- /dev/null +++ b/src/plugins/printsupport/windows/windows.pro @@ -0,0 +1,20 @@ +TARGET = windows +load(qt_plugin) + +QT *= core-private +QT *= gui-private +QT *= printsupport-private + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/printsupport +INCLUDEPATH *= $$QT_SOURCE_TREE/src/printsupport/kernel + +SOURCES += \ + main.cpp \ + qwindowsprintersupport.cpp + +HEADERS += \ + qwindowsprintersupport.h + +target.path += $$[QT_INSTALL_PLUGINS]/printsupport +INSTALLS += target +LIBS += -lWinspool -lComdlg32 diff --git a/src/printsupport/dialogs/dialogs.pri b/src/printsupport/dialogs/dialogs.pri index 5dbaa9fec3..8d4f7b83ef 100644 --- a/src/printsupport/dialogs/dialogs.pri +++ b/src/printsupport/dialogs/dialogs.pri @@ -16,8 +16,6 @@ HEADERS += \ } win32 { - qpa:DEFINES += QT_NO_PRINTDIALOG - SOURCES += dialogs/qpagesetupdialog_win.cpp \ dialogs/qprintdialog_win.cpp } diff --git a/src/printsupport/dialogs/qpagesetupdialog_win.cpp b/src/printsupport/dialogs/qpagesetupdialog_win.cpp index 2e7cf860fc..d21bbb1a36 100644 --- a/src/printsupport/dialogs/qpagesetupdialog_win.cpp +++ b/src/printsupport/dialogs/qpagesetupdialog_win.cpp @@ -44,8 +44,10 @@ #ifndef QT_NO_PRINTDIALOG #include <qapplication.h> -#include <private/qprintengine_win_p.h> -#include <private/qabstractpagesetupdialog_p.h> +#include "../kernel/qprintengine_win_p.h" +#include "qabstractpagesetupdialog_p.h" +#include "qprinter.h" +#include <QtGui/qplatformnativeinterface_qpa.h> QT_BEGIN_NAMESPACE @@ -99,7 +101,9 @@ int QPageSetupDialog::exec() QWidget *parent = parentWidget(); parent = parent ? parent->window() : QApplication::activeWindow(); Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created)); - psd.hwndOwner = parent ? parent->winId() : 0; + + QWindow *parentWindow = parent->windowHandle(); + psd.hwndOwner = parentWindow ? (HWND)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", parentWindow) : 0; QRect paperRect = d->printer->paperRect(); QRect pageRect = d->printer->pageRect(); diff --git a/src/printsupport/dialogs/qprintdialog_win.cpp b/src/printsupport/dialogs/qprintdialog_win.cpp index c8d92d45f2..d413faeb18 100644 --- a/src/printsupport/dialogs/qprintdialog_win.cpp +++ b/src/printsupport/dialogs/qprintdialog_win.cpp @@ -48,9 +48,9 @@ #include <qmessagebox.h> #include <private/qapplication_p.h> -#include <private/qabstractprintdialog_p.h> -#include <private/qprintengine_win_p.h> -#include <private/qprinter_p.h> +#include "qabstractprintdialog_p.h" +#include "../kernel/qprintengine_win_p.h" +#include "../kernel/qprinter_p.h" #if !defined(PD_NOCURRENTPAGE) #define PD_NOCURRENTPAGE 0x00800000 @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE -extern void qt_win_eatMouseMove(); +//extern void qt_win_eatMouseMove(); class QPrintDialogPrivate : public QAbstractPrintDialogPrivate { @@ -142,7 +142,8 @@ static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent, if (d->ep->printToFile) pd->Flags |= PD_PRINTTOFILE; Q_ASSERT(parent); - pd->hwndOwner = parent->window()->winId(); + QWindow *parentWindow = parent->windowHandle(); + pd->hwndOwner = parentWindow ? (HWND)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", parentWindow) : 0; pd->lpPageRanges[0].nFromPage = qMax(pdlg->fromPage(), pdlg->minPage()); pd->lpPageRanges[0].nToPage = (pdlg->toPage() > 0) ? qMin(pdlg->toPage(), pdlg->maxPage()) : 1; pd->nCopies = d->ep->num_copies; @@ -275,7 +276,7 @@ int QPrintDialogPrivate::openWindowsPrintDialogModally() QApplicationPrivate::leaveModal(&modal_widget); - qt_win_eatMouseMove(); +// qt_win_eatMouseMove(); // write values back... if (result && (pd.dwResultAction == PD_RESULT_PRINT diff --git a/src/printsupport/dialogs/qprintpreviewdialog.cpp b/src/printsupport/dialogs/qprintpreviewdialog.cpp index 90e29ac7ca..7e5c7dac94 100644 --- a/src/printsupport/dialogs/qprintpreviewdialog.cpp +++ b/src/printsupport/dialogs/qprintpreviewdialog.cpp @@ -331,7 +331,7 @@ void QPrintPreviewDialogPrivate::init(QPrinter *_printer) q->setWindowTitle(caption); if (!printer->isValid() -#if defined(Q_WS_WIN) || defined(Q_WS_MAC) +#if defined(Q_OS_WIN) || defined(Q_OS_MAC) || printer->outputFormat() != QPrinter::NativeFormat #endif ) @@ -560,7 +560,7 @@ void QPrintPreviewDialogPrivate::_q_print() { Q_Q(QPrintPreviewDialog); -#if defined(Q_WS_WIN) || defined(Q_WS_MAC) +#if defined(Q_OS_WIN) || defined(Q_WS_MAC) if (printer->outputFormat() != QPrinter::NativeFormat) { QString title; QString suffix; diff --git a/src/printsupport/kernel/kernel.pri b/src/printsupport/kernel/kernel.pri index 3868d9e212..cf6add54d9 100644 --- a/src/printsupport/kernel/kernel.pri +++ b/src/printsupport/kernel/kernel.pri @@ -25,6 +25,13 @@ unix:!symbian { $$PWD/qprinterinfo_unix.cpp } +win32 { + HEADERS += \ + $$PWD/qprintengine_win_p.h + SOURCES += \ + $$PWD/qprintengine_win.cpp + LIBS += -lWinspool -lComdlg32 +} x11|qpa:!win32 { SOURCES += $$PWD/qcups.cpp diff --git a/src/printsupport/kernel/qpaintengine_alpha_p.h b/src/printsupport/kernel/qpaintengine_alpha_p.h index 5694e2a5bc..b662c166e8 100644 --- a/src/printsupport/kernel/qpaintengine_alpha_p.h +++ b/src/printsupport/kernel/qpaintengine_alpha_p.h @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE class QAlphaPaintEnginePrivate; -class QAlphaPaintEngine : public QPaintEngine +class Q_PRINTSUPPORT_EXPORT QAlphaPaintEngine : public QPaintEngine { Q_DECLARE_PRIVATE(QAlphaPaintEngine) public: diff --git a/src/widgets/platforms/win/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index 5ba33c043c..438d893efc 100644 --- a/src/widgets/platforms/win/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -41,11 +41,11 @@ #ifndef QT_NO_PRINTER -#include "qprinter_p.h" #include "qprintengine_win_p.h" #include <limits.h> +#include <private/qprinter_p.h> #include <private/qfont_p.h> #include <private/qfontengine_p.h> #include <private/qpainter_p.h> @@ -54,7 +54,9 @@ #include <qdebug.h> #include <qvector.h> #include <qpicture.h> +#include <qplatformpixmap_qpa.h> #include <private/qpicture_p.h> +#include <private/qpixmap_raster_p.h> QT_BEGIN_NAMESPACE @@ -347,6 +349,7 @@ void QWin32PrintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem || ti.fontEngine->type() != QFontEngine::Win; +#if 0 if (!fallBack) { QFontEngineWin *fe = static_cast<QFontEngineWin *>(ti.fontEngine); @@ -360,6 +363,7 @@ void QWin32PrintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem != QString::fromWCharArray(fe->logfont.lfFaceName); } } +#endif if (fallBack) { @@ -579,14 +583,17 @@ void QWin32PrintEngine::updateClipPath(const QPainterPath &clipPath, Qt::ClipOpe QPainterPath xformed = clipPath * d->matrix; if (xformed.isEmpty()) { - QRegion empty(-0x1000000, -0x1000000, 1, 1); - SelectClipRgn(d->hdc, empty.handle()); +// QRegion empty(-0x1000000, -0x1000000, 1, 1); + HRGN empty = CreateRectRgn(-0x1000000, -0x1000000, -0x0fffffff, -0x0ffffff); + SelectClipRgn(d->hdc, empty); + DeleteObject(empty); } else { d->composeGdiPath(xformed); const int ops[] = { -1, // Qt::NoClip, covered above RGN_COPY, // Qt::ReplaceClip - RGN_AND // Qt::IntersectClip + RGN_AND, // Qt::IntersectClip + RGN_OR // Qt::UniteClip }; Q_ASSERT(op > 0 && unsigned(op) <= sizeof(ops) / sizeof(int)); SelectClipPath(d->hdc, ops[op]); @@ -612,6 +619,71 @@ void QWin32PrintEngine::updateMatrix(const QTransform &m) d->complex_xform = (d->txop > QTransform::TxScale); } +enum HBitmapFormat +{ + HBitmapNoAlpha, + HBitmapPremultipliedAlpha, + HBitmapAlpha +}; + +HBITMAP qPixmapToWinHBITMAP(const QPixmap &p, HBitmapFormat format) +{ + if (p.isNull()) + return 0; + + HBITMAP bitmap = 0; + if (p.handle()->classId() != QPlatformPixmap::RasterClass) { + QRasterPlatformPixmap *data = new QRasterPlatformPixmap(p.depth() == 1 ? + QRasterPlatformPixmap::BitmapType : QRasterPlatformPixmap::PixmapType); + data->fromImage(p.toImage(), Qt::AutoColor); + return qPixmapToWinHBITMAP(QPixmap(data), format); + } + + QRasterPlatformPixmap *d = static_cast<QRasterPlatformPixmap*>(p.handle()); + const QImage *rasterImage = d->buffer(); + const int w = rasterImage->width(); + const int h = rasterImage->height(); + + HDC display_dc = GetDC(0); + + // Define the header + BITMAPINFO bmi; + memset(&bmi, 0, sizeof(bmi)); + bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bmi.bmiHeader.biWidth = w; + bmi.bmiHeader.biHeight = -h; + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biBitCount = 32; + bmi.bmiHeader.biCompression = BI_RGB; + bmi.bmiHeader.biSizeImage = w * h * 4; + + // Create the pixmap + uchar *pixels = 0; + bitmap = CreateDIBSection(display_dc, &bmi, DIB_RGB_COLORS, (void **) &pixels, 0, 0); + ReleaseDC(0, display_dc); + if (!bitmap) { + qErrnoWarning("%s, failed to create dibsection", __FUNCTION__); + return 0; + } + if (!pixels) { + qErrnoWarning("%s, did not allocate pixel data", __FUNCTION__); + return 0; + } + + // Copy over the data + QImage::Format imageFormat = QImage::Format_ARGB32; + if (format == HBitmapAlpha) + imageFormat = QImage::Format_RGB32; + else if (format == HBitmapPremultipliedAlpha) + imageFormat = QImage::Format_ARGB32_Premultiplied; + const QImage image = rasterImage->convertToFormat(imageFormat); + const int bytes_per_line = w * 4; + for (int y=0; y < h; ++y) + memcpy(pixels + y * bytes_per_line, image.scanLine(y), bytes_per_line); + + return bitmap; +} + void QWin32PrintEngine::drawPixmap(const QRectF &targetRect, const QPixmap &originalPixmap, const QRectF &sourceRect) @@ -688,7 +760,7 @@ void QWin32PrintEngine::drawPixmap(const QRectF &targetRect, } QPixmap p = pixmap.copy(tileSize * x, tileSize * y, imgw, imgh); - HBITMAP hbitmap = p.toWinHBITMAP(QPixmap::NoAlpha); + HBITMAP hbitmap = qPixmapToWinHBITMAP(p, HBitmapNoAlpha); HDC display_dc = GetDC(0); HDC hbitmap_hdc = CreateCompatibleDC(display_dc); HGDIOBJ null_bitmap = SelectObject(hbitmap_hdc, hbitmap); @@ -723,7 +795,7 @@ void QWin32PrintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pm, cons int dc_state = SaveDC(d->hdc); HDC display_dc = GetDC(0); - HBITMAP hbitmap = pm.toWinHBITMAP(QPixmap::NoAlpha); + HBITMAP hbitmap = qPixmapToWinHBITMAP(pm, HBitmapNoAlpha); HDC hbitmap_hdc = CreateCompatibleDC(display_dc); HGDIOBJ null_bitmap = SelectObject(hbitmap_hdc, hbitmap); @@ -1642,17 +1714,18 @@ static void draw_text_item_win(const QPointF &pos, const QTextItemInt &ti, HDC h SetBkMode(hdc, TRANSPARENT); bool has_kerning = ti.f && ti.f->kerning(); - QFontEngineWin *winfe = (fe->type() == QFontEngine::Win) ? static_cast<QFontEngineWin *>(fe) : 0; +// ### TODO +// QFontEngineWin *winfe = (fe->type() == QFontEngine::Win) ? static_cast<QFontEngineWin *>(fe) : 0; HFONT hfont; bool ttf = false; - if (winfe) { - hfont = winfe->hfont; - ttf = winfe->ttf; - } else { +// if (winfe) { +// hfont = winfe->hfont; +// ttf = winfe->ttf; +// } else { hfont = (HFONT)GetStockObject(ANSI_VAR_FONT); - } +// } HGDIOBJ old_font = SelectObject(hdc, hfont); unsigned int options = (ttf && !convertToText) ? ETO_GLYPH_INDEX : 0; diff --git a/src/widgets/platforms/win/qprintengine_win_p.h b/src/printsupport/kernel/qprintengine_win_p.h index eeb097fd17..566e42ea2f 100644 --- a/src/widgets/platforms/win/qprintengine_win_p.h +++ b/src/printsupport/kernel/qprintengine_win_p.h @@ -55,11 +55,12 @@ #ifndef QT_NO_PRINTER -#include "QtGui/qprinter.h" -#include "QtGui/qprintengine.h" -#include "QtGui/qpaintengine.h" -#include "QtCore/qt_windows.h" -#include "private/qpaintengine_alpha_p.h" +#include "qt_windows.h" + +#include <QtGui/qpaintengine.h> +#include <QtPrintSupport/QPrintEngine> +#include <QtPrintSupport/QPrinter> +#include <private/qpaintengine_alpha_p.h> QT_BEGIN_NAMESPACE @@ -67,7 +68,7 @@ class QWin32PrintEnginePrivate; class QPrinterPrivate; class QPainterState; -class QWin32PrintEngine : public QAlphaPaintEngine, public QPrintEngine +class Q_PRINTSUPPORT_EXPORT QWin32PrintEngine : public QAlphaPaintEngine, public QPrintEngine { Q_DECLARE_PRIVATE(QWin32PrintEngine) public: diff --git a/src/printsupport/kernel/qprinterinfo.h b/src/printsupport/kernel/qprinterinfo.h index 535c29c4d6..59e6f2c138 100644 --- a/src/printsupport/kernel/qprinterinfo.h +++ b/src/printsupport/kernel/qprinterinfo.h @@ -78,6 +78,7 @@ private: private: friend class QPlatformPrinterSupport; + friend class QWindowsPrinterSupport; Q_DECLARE_PRIVATE(QPrinterInfo) QScopedPointer<QPrinterInfoPrivate, QPrinterInfoPrivateDeleter> d_ptr; }; |