fixed facename comparison inwxFontList::FindOrCreateFont
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7673 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -595,34 +595,75 @@ void wxFontList::RemoveFont (wxFont * font)
|
|||||||
DeleteObject (font);
|
DeleteObject (font);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFont *wxFontList::
|
wxFont *wxFontList::FindOrCreateFont(int pointSize,
|
||||||
FindOrCreateFont (int PointSize, int FamilyOrFontId, int Style, int Weight, bool underline, const wxString& Face, wxFontEncoding encoding)
|
int family,
|
||||||
|
int style,
|
||||||
|
int weight,
|
||||||
|
bool underline,
|
||||||
|
const wxString& facename,
|
||||||
|
wxFontEncoding encoding)
|
||||||
{
|
{
|
||||||
for (wxNode * node = First (); node; node = node->Next ())
|
wxFont *font = (wxFont *)NULL;
|
||||||
|
for ( wxNode * node = First(); node; node = node->Next() )
|
||||||
{
|
{
|
||||||
wxFont *each_font = (wxFont *) node->Data ();
|
font = (wxFont *)node->Data();
|
||||||
if (each_font &&
|
if ( font->GetVisible() &&
|
||||||
each_font->GetVisible() &&
|
font->Ok() &&
|
||||||
each_font->Ok() &&
|
font->GetPointSize () == pointSize &&
|
||||||
each_font->GetPointSize () == PointSize &&
|
font->GetStyle () == style &&
|
||||||
each_font->GetStyle () == Style &&
|
font->GetWeight () == weight &&
|
||||||
each_font->GetWeight () == Weight &&
|
font->GetUnderlined () == underline )
|
||||||
each_font->GetUnderlined () == underline &&
|
{
|
||||||
|
int fontFamily = font->GetFamily();
|
||||||
|
|
||||||
#if defined(__WXGTK__)
|
#if defined(__WXGTK__)
|
||||||
(each_font->GetFamily() == FamilyOrFontId ||
|
// under GTK the default family is wxSWISS, so looking for a font
|
||||||
(each_font->GetFamily() == wxSWISS && FamilyOrFontId == wxDEFAULT)) &&
|
// with wxDEFAULT family should return a wxSWISS one instead of
|
||||||
#else
|
// creating a new one
|
||||||
each_font->GetFamily() == FamilyOrFontId &&
|
bool same = (fontFamily == family) ||
|
||||||
#endif
|
(fontFamily == wxSWISS && family == wxDEFAULT);
|
||||||
((each_font->GetFaceName() == wxT("")) || each_font->GetFaceName() == Face) &&
|
#else // !GTK
|
||||||
(encoding == wxFONTENCODING_DEFAULT || each_font->GetEncoding() == encoding))
|
// VZ: but why elsewhere do we require an exact match? mystery...
|
||||||
return each_font;
|
bool same = fontFamily == family;
|
||||||
|
#endif // GTK/!GTK
|
||||||
|
|
||||||
|
// empty facename matches anything at all: this is bad because
|
||||||
|
// depending on which fonts are already created, we might get back
|
||||||
|
// a different font if we create it with empty facename, but it is
|
||||||
|
// still better than never matching anything in the cache at all
|
||||||
|
// in this case
|
||||||
|
if ( same && !!facename )
|
||||||
|
{
|
||||||
|
const wxString& fontFace = font->GetFaceName();
|
||||||
|
|
||||||
|
// empty facename matches everything
|
||||||
|
same = !fontFace || fontFace == facename;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( same && (encoding != wxFONTENCODING_DEFAULT) )
|
||||||
|
{
|
||||||
|
// have to match the encoding too
|
||||||
|
same = font->GetEncoding() == encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( same )
|
||||||
|
{
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
wxFont *font = new wxFont (PointSize, FamilyOrFontId, Style, Weight, underline, Face, encoding);
|
|
||||||
|
|
||||||
font->SetVisible(TRUE);
|
if ( !node )
|
||||||
|
{
|
||||||
|
// font not found, create the new one
|
||||||
|
font = new wxFont(pointSize, family, style, weight,
|
||||||
|
underline, facename, encoding);
|
||||||
|
|
||||||
return font;
|
// and mark it as being cacheable
|
||||||
|
font->SetVisible(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmapList::AddBitmap(wxBitmap *bitmap)
|
void wxBitmapList::AddBitmap(wxBitmap *bitmap)
|
||||||
|
Reference in New Issue
Block a user