From b54d39aecf558ef6ae874abfc3f1f1b17f46fd77 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Mon, 31 Oct 2011 10:58:36 +1100 Subject: When using GDI, make a copy of the font for use in autocompletions so it doesn't get deleted and so use the default font. --- win32/PlatWin.cxx | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 3d9b7e88f..01c36199b 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -192,25 +192,28 @@ struct FormatAndMetrics { }; HFONT FormatAndMetrics::HFont() { + LOGFONTW lf; + memset(&lf, 0, sizeof(lf)); #if defined(USE_D2D) if (technology == SCWIN_TECH_GDI) { - return hfont; + if (0 == ::GetObject(hfont, sizeof(lf), &lf)) { + return 0; + } } else { - LOGFONTW lf; - memset(&lf, 0, sizeof(lf)); - HRESULT hr = pTextFormat->GetFontFamilyName(lf.lfFaceName, LF_FACESIZE); - if (SUCCEEDED(hr)) { - lf.lfWeight = pTextFormat->GetFontWeight(); - lf.lfItalic = pTextFormat->GetFontStyle() == DWRITE_FONT_STYLE_ITALIC; - lf.lfHeight = -static_cast(pTextFormat->GetFontSize()); - return ::CreateFontIndirectW(&lf); + if (!SUCCEEDED(hr)) { + return 0; } + lf.lfWeight = pTextFormat->GetFontWeight(); + lf.lfItalic = pTextFormat->GetFontStyle() == DWRITE_FONT_STYLE_ITALIC; + lf.lfHeight = -static_cast(pTextFormat->GetFontSize()); } - return 0; #else - return hfont; + if (0 == ::GetObject(hfont, sizeof(lf), &lf)) { + return 0; + } #endif + return ::CreateFontIndirectW(&lf); } #ifndef CLEARTYPE_QUALITY -- cgit v1.2.3