From d78aa51b17c8d218d6392c7a4985a60d4a596c46 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 1 Nov 2012 17:15:19 +0000 Subject: [PATCH] Always set the font to use in wxMSW wxTextMeasure when using a window. The default window HDC font is not the same as the wxWindow font, so we need to always set the font explicitly in this case (when using a wxDC, its HDC does have the current wxDC font already selected into it, so doing it once again would be unnecessarily wasteful). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72845 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/textmeasure.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/msw/textmeasure.cpp b/src/msw/textmeasure.cpp index e25eeac859..48af0cf499 100644 --- a/src/msw/textmeasure.cpp +++ b/src/msw/textmeasure.cpp @@ -69,8 +69,12 @@ void wxTextMeasure::BeginMeasuring() m_hdc = ::GetDC(GetHwndOf(m_win)); } - if ( m_font ) - m_hfontOld = (HFONT)::SelectObject(m_hdc, GetHfontOf(*m_font)); + // We need to set the font if it's explicitly specified, of course, but + // also if we're associated with a window because the window HDC created + // above has the default font selected into it and not the font of the + // window. + if ( m_font || m_win ) + m_hfontOld = (HFONT)::SelectObject(m_hdc, GetHfontOf(GetFont())); } void wxTextMeasure::EndMeasuring() -- 2.45.2