X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/64932e4105654e784d0276671f5ac28f9bdb4ee9..b4572569856d405eb80c305674a9aeb8839e87d8:/src/msw/font.cpp diff --git a/src/msw/font.cpp b/src/msw/font.cpp index 832ce661a8..0acbf1aae6 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -189,14 +189,6 @@ public: facename = GetMSWFaceName(); if ( !facename.empty() ) { - // the face name returned by GetOutlineTextMetrics() may have - // these suffixes which we don't count as part of face name - // because we have separate fields for them so remove them - wxString basename; - if ( facename.EndsWith(wxS(" Italic"), &basename) || - facename.EndsWith(wxS(" Bold"), &basename) ) - facename = basename; - // cache the face name, it shouldn't change unless the family // does and wxNativeFontInfo::SetFamily() resets the face name const_cast(this)->SetFaceName(facename); @@ -354,11 +346,14 @@ protected: return wxString(); } - // in spite 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 + // in spite of its type, the otmpFamilyName field of OUTLINETEXTMETRIC + // gives an offset in _bytes_ of the face (not family!) name from the + // struct start while the name itself is an array of TCHARs + // + // FWIW otmpFaceName contains the same thing as otmpFamilyName followed + // by a possible " Italic" or " Bold" or something else suffix return reinterpret_cast(otm) + - wxPtrToUInt(otm->otmpFaceName)/sizeof(wxChar); + wxPtrToUInt(otm->otmpFamilyName)/sizeof(wxChar); } // are we using m_nativeFontInfo.lf.lfHeight for point size or pixel size? @@ -668,6 +663,10 @@ void wxNativeFontInfo::SetFamily(wxFontFamily family) case wxFONTFAMILY_DEFAULT: ff_family = FF_SWISS; break; + + case wxFONTFAMILY_UNKNOWN: + wxFAIL_MSG( "invalid font family" ); + return; } wxCHECK_RET( ff_family != FF_DONTCARE, "unknown wxFontFamily" ); @@ -1017,10 +1016,8 @@ bool wxFont::IsUsingSizeInPixels() const return M_FONTDATA->IsUsingSizeInPixels(); } -wxFontFamily wxFont::GetFamily() const +wxFontFamily wxFont::DoGetFamily() const { - wxCHECK_MSG( IsOk(), wxFONTFAMILY_MAX, wxT("invalid font") ); - return M_FONTDATA->GetFamily(); } @@ -1068,10 +1065,19 @@ bool wxFont::IsFixedWidth() const { wxCHECK_MSG( IsOk(), false, wxT("invalid font") ); - // the two low-order bits specify the pitch of the font, the rest is - // family - BYTE pitch = - (BYTE)(M_FONTDATA->GetNativeFontInfo().lf.lfPitchAndFamily & PITCH_MASK); + // LOGFONT doesn't contain the correct pitch information so we need to call + // GetTextMetrics() to get it + ScreenHDC hdc; + SelectInHDC selectFont(hdc, M_FONTDATA->GetHFONT()); + + TEXTMETRIC tm; + if ( !::GetTextMetrics(hdc, &tm) ) + { + wxLogLastError(wxT("GetTextMetrics")); + return false; + } - return pitch == FIXED_PITCH; + // Quoting MSDN description of TMPF_FIXED_PITCH: "Note very carefully that + // those meanings are the opposite of what the constant name implies." + return !(tm.tmPitchAndFamily & TMPF_FIXED_PITCH); }