From 9bd26720469feeb230da05b30f4c1cf7d9d7e703 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 18 Nov 2009 03:18:16 +0000 Subject: [PATCH] Implement wxFont::GetFaceName() to return the face name being really used. Since the change of r60391 empty face name was returned for all fonts created using the standard wxFont constructor (so basically all fonts except for those created from native font info and the default/normal font which we retrieve from the system). Use Windows GetOutlineTextMetrics() function to get the real face name being used independently of the way the font was created. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62675 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/font.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/msw/font.cpp b/src/msw/font.cpp index f5ac65fc95..f97768a11c 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -32,6 +32,7 @@ #include "wx/app.h" #include "wx/log.h" #include "wx/encinfo.h" + #include "wx/scopeguard.h" #endif // WX_PRECOMP #include "wx/msw/private.h" @@ -182,7 +183,19 @@ public: wxString GetFaceName() const { - return m_nativeFontInfo.GetFaceName(); + wxString facename = m_nativeFontInfo.GetFaceName(); + if ( facename.empty() ) + { + facename = GetMSWFaceName(); + if ( !facename.empty() ) + { + // cache the face name, it shouldn't change unless the family + // does and wxNativeFontInfo::SetFamily() resets the face name + const_cast(this)->SetFaceName(facename); + } + } + + return facename; } wxFontEncoding GetEncoding() const @@ -291,6 +304,39 @@ protected: void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0); + // retrieve the face name really being used by the font: this is used to + // get the face name selected by the system when we don't specify it (but + // use just the family for example) + wxString GetMSWFaceName() const + { + ScreenHDC hdc; + SelectInHDC selectFont(hdc, m_hFont); + + UINT otmSize = GetOutlineTextMetrics(hdc, 0, NULL); + if ( !otmSize ) + { + wxLogLastError("GetOutlineTextMetrics(NULL)"); + return wxString(); + } + + OUTLINETEXTMETRIC * const + otm = static_cast(malloc(otmSize)); + wxON_BLOCK_EXIT1( free, otm ); + + otm->otmSize = otmSize; + if ( !GetOutlineTextMetrics(hdc, otmSize, otm) ) + { + wxLogLastError("GetOutlineTextMetrics()"); + return wxString(); + } + + // in spit of its type, the otmpFaceName field of OUTLINETEXTMETRIC + // gives an offset in _bytes_ of the face name from the struct start + // while the name itself is an array of TCHARs + return reinterpret_cast(otm) + + wxPtrToUInt(otm->otmpFaceName)/sizeof(wxChar); + } + // are we using m_nativeFontInfo.lf.lfHeight for point size or pixel size? bool m_sizeUsingPixels; -- 2.47.2