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 <andy.shaw@qt.io>
This commit is contained in:
Friedemann Kleint 2018-05-23 10:17:53 +02:00
parent 4deea4b905
commit 7aaa7debc4

View File

@ -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);