From 65ae7812156f5738cb9fe760af40613bba95804c Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@digia.com>
Date: Tue, 30 Apr 2013 09:48:43 +0200
Subject: [PATCH] QWindowsFontEngine: Fix warnings about GetGlyphOutline()
 failures.

tst_qglthreads::painterOnPixmapInThread reports

QWinFontEngine: unable to query transformed glyph metrics...

(Desktop OpenGL only).

Task-number: QTBUG-28264
Change-Id: Ib456905a13a95037ec13dfc4cb828f830076ee89
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
---
 .../platforms/windows/qwindowsfontengine.cpp   | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/plugins/platforms/windows/qwindowsfontengine.cpp b/src/plugins/platforms/windows/qwindowsfontengine.cpp
index a410708cebc..792e79df195 100644
--- a/src/plugins/platforms/windows/qwindowsfontengine.cpp
+++ b/src/plugins/platforms/windows/qwindowsfontengine.cpp
@@ -1095,7 +1095,7 @@ QWindowsNativeImage *QWindowsFontEngine::drawGDIGlyph(HFONT font, glyph_t glyph,
         xform.eDx = margin;
         xform.eDy = margin;
 
-        HDC hdc = CreateCompatibleDC(QWindowsContext::instance()->displayContext());
+        const HDC hdc = m_fontEngineData->hdc;
 
         SetGraphicsMode(hdc, GM_ADVANCED);
         SetWorldTransform(hdc, &xform);
@@ -1107,8 +1107,16 @@ QWindowsNativeImage *QWindowsFontEngine::drawGDIGlyph(HFONT font, glyph_t glyph,
         memset(&mat, 0, sizeof(mat));
         mat.eM11.value = mat.eM22.value = 1;
 
-        if (GetGlyphOutline(hdc, glyph, ggo_options, &tgm, 0, 0, &mat) == GDI_ERROR) {
-            qWarning("QWinFontEngine: unable to query transformed glyph metrics...");
+        const DWORD result = GetGlyphOutline(hdc, glyph, ggo_options, &tgm, 0, 0, &mat);
+
+        XFORM identity = {1, 0, 0, 1, 0, 0};
+        SetWorldTransform(hdc, &identity);
+        SetGraphicsMode(hdc, GM_COMPATIBLE);
+        SelectObject(hdc, old_font);
+
+        if (result == GDI_ERROR) {
+            const int errorCode = GetLastError();
+            qErrnoWarning(errorCode, "QWinFontEngine: unable to query transformed glyph metrics (GetGlyphOutline() failed, error %d)...", errorCode);
             return 0;
         }
 
@@ -1117,10 +1125,6 @@ QWindowsNativeImage *QWindowsFontEngine::drawGDIGlyph(HFONT font, glyph_t glyph,
 
         xform.eDx -= tgm.gmptGlyphOrigin.x;
         xform.eDy += tgm.gmptGlyphOrigin.y;
-
-        SetGraphicsMode(hdc, GM_COMPATIBLE);
-        SelectObject(hdc, old_font);
-        DeleteDC(hdc);
     }
 #else // else wince
     unsigned int options = 0;
-- 
GitLab