X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df898907bbea0033859ef497daa016522036f726..7a0a6cc8f61cb53ce1c76897489e1e363d1a1fa5:/src/msw/font.cpp diff --git a/src/msw/font.cpp b/src/msw/font.cpp index d99d2f8f64..d8d678fe8f 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -264,9 +264,6 @@ public: m_nativeFontInfo.SetEncoding(encoding); } - // native font info - bool HasNativeFontInfo() const { return true; } - const wxNativeFontInfo& GetNativeFontInfo() const { return m_nativeFontInfo; } @@ -291,7 +288,7 @@ protected: void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0); - // are we using m_nativeFontInfo.lf.lfHeight for point size or pixel size? + // are we using m_nativeFontInfo.lf.lfHeight for point size or pixel size? bool m_sizeUsingPixels; // Windows font handle, created on demand in GetHFONT() @@ -321,26 +318,26 @@ void wxFontRefData::Init(int pointSize, const wxString& faceName, wxFontEncoding encoding) { - m_sizeUsingPixels = sizeUsingPixels; - if ( m_sizeUsingPixels ) - SetPixelSize(pixelSize); - else - SetPointSize(pointSize); - - SetStyle(style); - SetWeight(weight); - SetUnderlined(underlined); - m_hFont = NULL; - // set the family/facename - SetFamily(family); - if ( !faceName.empty() ) - SetFaceName(faceName); - - // deal with encoding now (it may override the font family and facename - // so do it after setting them) - SetEncoding(encoding); + m_sizeUsingPixels = sizeUsingPixels; + if ( m_sizeUsingPixels ) + SetPixelSize(pixelSize); + else + SetPointSize(pointSize); + + SetStyle(style); + SetWeight(weight); + SetUnderlined(underlined); + + // set the family/facename + SetFamily(family); + if ( !faceName.empty() ) + SetFaceName(faceName); + + // deal with encoding now (it may override the font family and facename + // so do it after setting them) + SetEncoding(encoding); } void wxFontRefData::Init(const wxNativeFontInfo& info, WXHFONT hFont) @@ -511,7 +508,7 @@ void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize) // here if we get a negative height: wxCHECK_RET( pixelSize.GetWidth() >= 0 && pixelSize.GetHeight() > 0, "Negative values for the pixel size or zero pixel height are not allowed" ); - + lf.lfHeight = pixelSize.GetHeight(); lf.lfWidth = pixelSize.GetWidth(); } @@ -644,10 +641,9 @@ void wxNativeFontInfo::SetFamily(wxFontFamily family) lf.lfPitchAndFamily = (BYTE)(DEFAULT_PITCH) | ff_family; - if ( !wxStrlen(lf.lfFaceName) ) - { - SetFaceName(facename); - } + // reset the facename so that CreateFontIndirect() will automatically choose a + // face name based only on the font family. + lf.lfFaceName[0] = '\0'; } void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding) @@ -681,7 +677,7 @@ bool wxNativeFontInfo::FromString(const wxString& s) { long l; - wxStringTokenizer tokenizer(s, wxS(";")); + wxStringTokenizer tokenizer(s, wxS(";"), wxTOKEN_RET_EMPTY_ALL); // first the version wxString token = tokenizer.GetNextToken(); @@ -753,10 +749,11 @@ bool wxNativeFontInfo::FromString(const wxString& s) return false; lf.lfPitchAndFamily = (BYTE)l; - token = tokenizer.GetNextToken(); - if(!token) + if ( !tokenizer.HasMoreTokens() ) return false; - wxStrcpy(lf.lfFaceName, token.c_str()); + + // the face name may be empty + wxStrcpy(lf.lfFaceName, tokenizer.GetNextToken()); return true; } @@ -780,7 +777,7 @@ wxString wxNativeFontInfo::ToString() const lf.lfClipPrecision, lf.lfQuality, lf.lfPitchAndFamily, - (const wxChar*)lf.lfFaceName); + lf.lfFaceName); return s; } @@ -852,7 +849,7 @@ wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const bool wxFont::RealizeResource() { // NOTE: the GetHFONT() call automatically triggers a reallocation of - // the HFONT if necessary (will do nothing if we already have the resource); + // the HFONT if necessary (will do nothing if we already have the resource); // it returns NULL only if there is a failure in wxFontRefData::Alloc()... return GetHFONT() != NULL; } @@ -1031,8 +1028,7 @@ wxFontEncoding wxFont::GetEncoding() const const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { - return IsOk() && M_FONTDATA->HasNativeFontInfo() ? &(M_FONTDATA->GetNativeFontInfo()) - : NULL; + return IsOk() ? &(M_FONTDATA->GetNativeFontInfo()) : NULL; } wxString wxFont::GetNativeFontInfoDesc() const @@ -1057,15 +1053,10 @@ bool wxFont::IsFixedWidth() const { wxCHECK_MSG( IsOk(), false, wxT("invalid font") ); - if ( M_FONTDATA->HasNativeFontInfo() ) - { - // 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); - - return pitch == FIXED_PITCH; - } + // 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); - return wxFontBase::IsFixedWidth(); + return pitch == FIXED_PITCH; }