m_nativeFontInfo.SetEncoding(encoding);
}
- // native font info
- bool HasNativeFontInfo() const { return true; }
-
const wxNativeFontInfo& GetNativeFontInfo() const
{ return m_nativeFontInfo; }
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()
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)
// 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();
}
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)
{
long l;
- wxStringTokenizer tokenizer(s, wxS(";"));
+ wxStringTokenizer tokenizer(s, wxS(";"), wxTOKEN_RET_EMPTY_ALL);
// first the version
wxString token = tokenizer.GetNextToken();
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;
}
lf.lfClipPrecision,
lf.lfQuality,
lf.lfPitchAndFamily,
- (const wxChar*)lf.lfFaceName);
+ lf.lfFaceName);
return s;
}
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;
}
const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
{
- return IsOk() && M_FONTDATA->HasNativeFontInfo() ? &(M_FONTDATA->GetNativeFontInfo())
- : NULL;
+ return IsOk() ? &(M_FONTDATA->GetNativeFontInfo()) : NULL;
}
wxString wxFont::GetNativeFontInfoDesc() 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;
}