From 7aaa7debc455516cbb1b1f536e990b9154272f64 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 23 May 2018 10:17:53 +0200 Subject: QWin32PrintEngine: Fix crash in drawPixmap(), drawImage() Use the printer's HDC instead of the screen HDC for StretchBlt(). Patch as contributed via bug report. Task-number: QTBUG-59689 Task-number: QTBUG-66325 Change-Id: I9b5d6ddd3f0e9e68f2a003ca9ed20ece20dccef8 Reviewed-by: Andy Shaw --- src/printsupport/kernel/qprintengine_win.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/printsupport/kernel') diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index ca4d1d0bd6..6f263e5ea8 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -587,12 +587,9 @@ void QWin32PrintEngine::drawPixmap(const QRectF &targetRect, QPixmap p = QPixmap::fromImage(img); HBITMAP hbitmap = qt_pixmapToWinHBITMAP(p, HBitmapNoAlpha); - HDC display_dc = GetDC(0); - HDC hbitmap_hdc = CreateCompatibleDC(display_dc); + HDC hbitmap_hdc = CreateCompatibleDC(d->hdc); HGDIOBJ null_bitmap = SelectObject(hbitmap_hdc, hbitmap); - ReleaseDC(0, display_dc); - if (!StretchBlt(d->hdc, qRound(tposx - xform_offset_x), qRound(tposy - xform_offset_y), width, height, hbitmap_hdc, 0, 0, p.width(), p.height(), SRCCOPY)) qErrnoWarning("QWin32PrintEngine::drawPixmap, StretchBlt failed"); @@ -620,13 +617,10 @@ void QWin32PrintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pm, cons } else { int dc_state = SaveDC(d->hdc); - HDC display_dc = GetDC(0); HBITMAP hbitmap = qt_pixmapToWinHBITMAP(pm, HBitmapNoAlpha); - HDC hbitmap_hdc = CreateCompatibleDC(display_dc); + HDC hbitmap_hdc = CreateCompatibleDC(d->hdc); HGDIOBJ null_bitmap = SelectObject(hbitmap_hdc, hbitmap); - ReleaseDC(0, display_dc); - QRectF trect = d->painterMatrix.mapRect(r); int tx = int(trect.left() * d->stretch_x + d->origin_x); int ty = int(trect.top() * d->stretch_y + d->origin_y); -- cgit v1.2.3