\constfunc{wxString}{GetNativeFontInfoDesc}{\void}
-Returns the platform-dependent string completely describing this font or an
-empty string if the font wasn't constructed using the native font description.
+Returns the platform-dependent string completely describing this font.
+Returned string is always non-empty.
Note that the returned string is not meant to be shown or edited by the user: a typical
use of this function is for serializing in string-form a wxFont object.
\func{wxString}{GetNativeFontInfoUserDesc}{\void}
-Returns a user-friendly string for this font object. Some examples of the formats of returned strings (which are platform-dependent) are in \helpref{SetNativeFontInfoUserDesc}{wxfontsetnativefontinfouserdesc}.
+Returns a user-friendly string for this font object. Returned string is always non-empty.
+Some examples of the formats of returned strings (which are platform-dependent) are in \helpref{SetNativeFontInfoUserDesc}{wxfontsetnativefontinfouserdesc}.
\wxheading{See also}
\membersection{wxFont::SetFaceName}\label{wxfontsetfacename}
-\func{void}{SetFaceName}{\param{const wxString\& }{faceName}}
+\func{bool}{SetFaceName}{\param{const wxString\& }{faceName}}
Sets the facename for the font.
+Returns \true if the given face name exists; \false otherwise.
\wxheading{Parameters}
\membersection{wxFont::SetNativeFontInfo}\label{wxfontsetnativefontinfo}
-\func{void}{SetNativeFontInfo}{\param{const wxString\& }{info}}
+\func{bool}{SetNativeFontInfo}{\param{const wxString\& }{info}}
-Creates the font corresponding to the given native font description string
+Creates the font corresponding to the given native font description string and returns \true if
+the creation was successful.
which must have been previously returned by
\helpref{GetNativeFontInfoDesc}{wxfontgetnativefontinfodesc}. If the string is
invalid, font is unchanged. This function is typically used for de-serializing a wxFont
\membersection{wxFont::SetNativeFontInfoUserDesc}\label{wxfontsetnativefontinfouserdesc}
-\func{void}{SetNativeFontInfoUserDesc}{\param{const wxString\& }{info}}
+\func{bool}{SetNativeFontInfoUserDesc}{\param{const wxString\& }{info}}
-Creates the font corresponding to the given native font description string.
+Creates the font corresponding to the given native font description string and returns \true if
+the creation was successful.
Unlike \helpref{SetNativeFontInfo}{wxfontsetnativefontinfo}, this function accepts
strings which are user-friendly.
Examples of accepted string formats are:
\helpref{EnumerateFacenames}{wxfontenumeratorenumeratefacenames}.
+\membersection{wxFontEnumerator::IsValidFacename}\label{wxfontenumeratorisvalidfacename}
+
+\func{static bool}{IsValidFacename}{\param{const wxString \&}{ facename}}
+
+Returns \true if the given string is valid face name, i.e. it's the face name of an installed
+font and it can safely be used with \helpref{wxFont::SetFaceName}{wxfontsetfacename}.
+
+
\membersection{wxFontEnumerator::OnFacename}\label{wxfontenumeratoronfacename}
\func{virtual bool}{OnFacename}{\param{const wxString\& }{font}}
virtual void SetFamily(int family);
virtual void SetStyle(int style);
virtual void SetWeight(int weight);
- virtual void SetFaceName(const wxString& faceName);
+ virtual bool SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxFontRefData;
-struct WXDLLEXPORT wxNativeFontInfo;
+class WXDLLEXPORT wxNativeFontInfo;
class WXDLLEXPORT wxFontBase : public wxGDIObject
{
virtual void SetFamily( int family ) = 0;
virtual void SetStyle( int style ) = 0;
virtual void SetWeight( int weight ) = 0;
- virtual void SetFaceName( const wxString& faceName ) = 0;
virtual void SetUnderlined( bool underlined ) = 0;
virtual void SetEncoding(wxFontEncoding encoding) = 0;
+ virtual bool SetFaceName( const wxString& faceName );
void SetNativeFontInfo(const wxNativeFontInfo& info)
{ DoSetNativeFontInfo(info); }
- void SetNativeFontInfo(const wxString& info);
- void SetNativeFontInfoUserDesc(const wxString& info);
+ bool SetNativeFontInfo(const wxString& info);
+ bool SetNativeFontInfoUserDesc(const wxString& info);
// translate the fonts into human-readable string (i.e. GetStyleString()
// will return "wxITALIC" for an italic font, ...)
// convenience function that returns array of all available encodings.
static wxArrayString GetEncodings(const wxString& facename = wxEmptyString);
+ // convenience function that returns true if the given face name exist
+ // in the user's system
+ static bool IsValidFacename(const wxString &str);
+
private:
DECLARE_NO_COPY_CLASS(wxFontEnumerator)
};
// functions, the user code can only get the objects of this type from
// somewhere and pass it somewhere else (possibly save them somewhere using
// ToString() and restore them using FromString())
-//
-// NB: it is a POD currently for max efficiency but if it continues to grow
-// further it might make sense to make it a real class with virtual methods
-struct WXDLLEXPORT wxNativeFontInfo
+class WXDLLEXPORT wxNativeFontInfo
{
+public:
#if wxUSE_PANGO
PangoFontDescription *description;
#elif defined(_WX_X_FONTLIKE)
void SetStyle(wxFontStyle style);
void SetWeight(wxFontWeight weight);
void SetUnderlined(bool underlined);
- void SetFaceName(const wxString& facename);
+ bool SetFaceName(const wxString& facename);
void SetFamily(wxFontFamily family);
void SetEncoding(wxFontEncoding encoding);
+ // sets the first facename in the given array which is found
+ // to be valid. If no valid facename is given, sets the
+ // first valid facename returned by wxFontEnumerator::GetFacenames().
+ // Does not return a bool since it cannot fail.
+ void SetFaceName(const wxArrayString &facenames);
+
+
// it is important to be able to serialize wxNativeFontInfo objects to be
// able to store them (in config file, for example)
bool FromString(const wxString& s);
virtual void SetFamily( int family );
virtual void SetStyle( int style );
virtual void SetWeight( int weight );
- virtual void SetFaceName( const wxString& faceName );
+ virtual bool SetFaceName( const wxString& faceName );
virtual void SetUnderlined( bool underlined );
virtual void SetEncoding(wxFontEncoding encoding);
virtual void SetFamily( int family );
virtual void SetStyle( int style );
virtual void SetWeight( int weight );
- virtual void SetFaceName( const wxString& faceName );
+ virtual bool SetFaceName( const wxString& faceName );
virtual void SetUnderlined( bool underlined );
virtual void SetEncoding(wxFontEncoding encoding);
virtual void SetFamily(int family);
virtual void SetStyle(int style);
virtual void SetWeight(int weight);
- virtual void SetFaceName(const wxString& faceName);
+ virtual bool SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
virtual void SetFamily(int family);
virtual void SetStyle(int style);
virtual void SetWeight(int weight);
- virtual void SetFaceName(const wxString& faceName);
+ virtual bool SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
virtual void SetFamily(int family);
virtual void SetStyle(int style);
virtual void SetWeight(int weight);
- virtual void SetFaceName(const wxString& faceName);
+ virtual bool SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
virtual void SetFamily(int family);
virtual void SetStyle(int style);
virtual void SetWeight(int weight);
- virtual void SetFaceName(const wxString& faceName);
+ virtual bool SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
virtual ~wxFont();
+ // wxFontBase overridden functions
+ virtual wxString GetNativeFontInfoDesc() const;
+ virtual wxString GetNativeFontInfoUserDesc() const;
+
// implement base class pure virtuals
virtual int GetPointSize() const;
virtual wxSize GetPixelSize() const;
virtual void SetFamily(int family);
virtual void SetStyle(int style);
virtual void SetWeight(int weight);
- virtual void SetFaceName(const wxString& faceName);
+ virtual bool SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
virtual void SetFamily(int nFamily);
virtual void SetStyle(int nStyle);
virtual void SetWeight(int nWeight);
- virtual void SetFaceName(const wxString& rsFaceName);
+ virtual bool SetFaceName(const wxString& rsFaceName);
virtual void SetUnderlined(bool bUnderlined);
virtual void SetEncoding(wxFontEncoding vEncoding);
virtual void SetFamily(int family);
virtual void SetStyle(int style);
virtual void SetWeight(int weight);
- virtual void SetFaceName(const wxString& faceName);
+ virtual bool SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
virtual void SetFamily(int family);
virtual void SetStyle(int style);
virtual void SetWeight(int weight);
- virtual void SetFaceName(const wxString& faceName);
+ virtual bool SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
void OnEnumerateEncodings(wxCommandEvent& event);
void OnCheckNativeToFromString(wxCommandEvent& event);
+ void OnCheckNativeToFromUserString(wxCommandEvent& event);
+ void OnCheckFaceName(wxCommandEvent& event);
protected:
bool DoEnumerateFamilies(bool fixedWidthOnly,
Font_EnumFixedFamilies,
Font_EnumEncodings,
Font_CheckNativeToFromString,
+ Font_CheckNativeToFromUserString,
+ Font_CheckFaceName,
Font_Max
};
EVT_MENU(Font_wxITALIC_FONT, MyFrame::OnwxPointerFont)
EVT_MENU(Font_wxSWISS_FONT, MyFrame::OnwxPointerFont)
+
EVT_MENU(Font_CheckNativeToFromString, MyFrame::OnCheckNativeToFromString)
+ EVT_MENU(Font_CheckNativeToFromUserString, MyFrame::OnCheckNativeToFromUserString)
+ EVT_MENU(Font_CheckFaceName, MyFrame::OnCheckFaceName)
EVT_MENU(Font_Choose, MyFrame::OnSelectFont)
EVT_MENU(Font_EnumFamiliesForEncoding, MyFrame::OnEnumerateFamiliesForEncoding)
menuFont->AppendSeparator();
menuFont->Append(Font_CheckNativeToFromString,
wxT("Check Native Font Info To/From String"));
+ menuFont->Append(Font_CheckNativeToFromUserString,
+ wxT("Check Native Font Info User String"));
+ menuFont->Append(Font_CheckFaceName,
+ wxT("Check font face name"));
wxMenu *menuSelect = new wxMenu;
menuSelect->Append(Font_Choose, wxT("&Select font...\tCtrl-S"),
}
}
+void MyFrame::OnCheckFaceName(wxCommandEvent& WXUNUSED(event))
+{
+ wxString facename = GetCanvas()->GetTextFont().GetFaceName();
+ wxString newFaceName = wxGetTextFromUser(
+ wxT("Here you can edit current font face name."),
+ wxT("Input font facename"), facename,
+ this);
+ if (newFaceName.IsEmpty())
+ return; // user clicked "Cancel" - do nothing
+
+ wxFont font(GetCanvas()->GetTextFont());
+ if (font.SetFaceName(newFaceName)) // change facename only
+ {
+ wxASSERT_MSG(font.Ok(), wxT("The font should now be valid"));
+ DoChangeFont(font);
+ }
+ else
+ {
+ wxASSERT_MSG(!font.Ok(), wxT("The font should now be invalid"));
+ wxMessageBox(wxT("There is no font with such face name..."),
+ wxT("Invalid face name"), wxOK|wxICON_ERROR, this);
+ }
+}
+
+void MyFrame::OnCheckNativeToFromUserString(wxCommandEvent& WXUNUSED(event))
+{
+ wxString fontdesc = GetCanvas()->GetTextFont().GetNativeFontInfoUserDesc();
+ wxString fontUserInfo = wxGetTextFromUser(
+ wxT("Here you can edit current font description"),
+ wxT("Input font description"), fontdesc,
+ this);
+ if (fontUserInfo.IsEmpty())
+ return; // user clicked "Cancel" - do nothing
+
+ wxFont font;
+ if (font.SetNativeFontInfoUserDesc(fontUserInfo))
+ {
+ wxASSERT_MSG(font.Ok(), wxT("The font should now be valid"));
+ DoChangeFont(font);
+ }
+ else
+ {
+ wxASSERT_MSG(!font.Ok(), wxT("The font should now be invalid"));
+ wxMessageBox(wxT("Error trying to create a font with such description..."));
+ }
+}
+
void MyFrame::DoResizeFont(int diff)
{
wxFont font = m_canvas->GetTextFont();
default : font = wxFont(*wxNORMAL_FONT); break;
}
- GetMenuBar()->Check(Font_Bold, false);
- GetMenuBar()->Check(Font_Italic, false);
- GetMenuBar()->Check(Font_Underlined, false);
-
DoChangeFont(font);
}
m_textctrl->SetFont(font);
if ( col.Ok() )
m_textctrl->SetForegroundColour(col);
+
+ // update the state of the bold/italic/underlined menu items
+ wxMenuBar *mbar = GetMenuBar();
+ if ( mbar )
+ {
+ mbar->Check(Font_Bold, font.GetWeight() == wxFONTWEIGHT_BOLD);
+ mbar->Check(Font_Italic, font.GetStyle() == wxFONTSTYLE_ITALIC);
+ mbar->Check(Font_Underlined, font.GetUnderlined());
+ }
}
void MyFrame::OnSelectFont(wxCommandEvent& WXUNUSED(event))
wxColour colour = retData.GetColour();
DoChangeFont(font, colour);
-
- // update the state of the bold/italic/underlined menu items
- wxMenuBar *mbar = GetMenuBar();
- if ( mbar )
- {
- mbar->Check(Font_Bold, font.GetWeight() == wxFONTWEIGHT_BOLD);
- mbar->Check(Font_Italic, font.GetStyle() == wxFONTSTYLE_ITALIC);
- mbar->Check(Font_Underlined, font.GetUnderlined());
- }
}
}
RealizeResource();
}
-void wxFont::SetFaceName(const wxString& faceName)
+bool wxFont::SetFaceName(const wxString& faceName)
{
Unshare();
M_FONTDATA->m_faceName = faceName;
RealizeResource();
+
+ return wxFontBase::SetFaceName(faceName);
}
void wxFont::SetUnderlined(bool underlined)
#include "wx/fontutil.h" // for wxNativeFontInfo
#include "wx/fontmap.h"
+#include "wx/fontenum.h"
#include "wx/tokenzr.h"
if ( fontInfo )
{
fontDesc = fontInfo->ToString();
+ wxASSERT_MSG(!fontDesc.IsEmpty(), wxT("This should be a non-empty string!"));
+ }
+ else
+ {
+ wxASSERT_MSG(0, wxT("Derived class should have created the wxNativeFontInfo!"));
}
return fontDesc;
if ( fontInfo )
{
fontDesc = fontInfo->ToUserString();
+ wxASSERT_MSG(!fontDesc.IsEmpty(), wxT("This should be a non-empty string!"));
+ }
+ else
+ {
+ wxASSERT_MSG(0, wxT("Derived class should have created the wxNativeFontInfo!"));
}
return fontDesc;
}
-void wxFontBase::SetNativeFontInfo(const wxString& info)
+bool wxFontBase::SetNativeFontInfo(const wxString& info)
{
wxNativeFontInfo fontInfo;
if ( !info.empty() && fontInfo.FromString(info) )
{
SetNativeFontInfo(fontInfo);
+ return true;
}
+
+ UnRef();
+ return false;
}
-void wxFontBase::SetNativeFontInfoUserDesc(const wxString& info)
+bool wxFontBase::SetNativeFontInfoUserDesc(const wxString& info)
{
wxNativeFontInfo fontInfo;
if ( !info.empty() && fontInfo.FromUserString(info) )
{
SetNativeFontInfo(fontInfo);
+ return true;
}
+
+ UnRef();
+ return false;
}
bool wxFontBase::operator==(const wxFont& font) const
GetStyle() == font.GetStyle() &&
GetWeight() == font.GetWeight() &&
GetUnderlined() == font.GetUnderlined() &&
- GetFaceName() == font.GetFaceName() &&
+ GetFaceName().IsSameAs(font.GetFaceName(), false) &&
GetEncoding() == font.GetEncoding()
);
}
}
}
+bool wxFontBase::SetFaceName(const wxString &facename)
+{
+ if (!wxFontEnumerator::IsValidFacename(facename))
+ {
+ UnRef(); // make Ok() return false
+ return false;
+ }
+
+ return true;
+}
+
+
// ----------------------------------------------------------------------------
// wxNativeFontInfo
// ----------------------------------------------------------------------------
+// Up to now, there are no native implementations of this function:
+void wxNativeFontInfo::SetFaceName(const wxArrayString &facenames)
+{
+ for (size_t i=0; i < facenames.GetCount(); i++)
+ {
+ if (wxFontEnumerator::IsValidFacename(facenames[i]))
+ {
+ SetFaceName(facenames[i]);
+ return;
+ }
+ }
+
+ // set the first valid facename we can find on this system
+ wxString validfacename = wxFontEnumerator::GetFacenames().Item(0);
+ wxLogTrace(wxT("font"), wxT("Falling back to '%s'"), validfacename.c_str());
+ SetFaceName(validfacename);
+}
+
+
#ifdef wxNO_NATIVE_FONTINFO
// These are the generic forms of FromString()/ToString.
underlined = underlined_;
}
-void wxNativeFontInfo::SetFaceName(const wxString& facename_)
+bool wxNativeFontInfo::SetFaceName(const wxString& facename_)
{
faceName = facename_;
+ return true;
}
void wxNativeFontInfo::SetFamily(wxFontFamily family_)
// but what else can we do?
if ( GetUnderlined() )
{
- desc << _("underlined ");
+ desc << _("underlined");
}
switch ( GetWeight() )
break;
case wxFONTWEIGHT_LIGHT:
- desc << _("light ");
+ desc << _(" light");
break;
case wxFONTWEIGHT_BOLD:
- desc << _("bold ");
+ desc << _(" bold");
break;
}
// we don't distinguish between the two for now anyhow...
case wxFONTSTYLE_ITALIC:
case wxFONTSTYLE_SLANT:
- desc << _("italic");
+ desc << _(" italic");
break;
}
}
#endif // wxUSE_FONTMAP
- return desc;
+ return desc.Strip(wxString::both).MakeLower();
}
bool wxNativeFontInfo::FromUserString(const wxString& s)
wxString face;
unsigned long size;
-
-#if wxUSE_FONTMAP
- wxFontEncoding encoding;
-#endif // wxUSE_FONTMAP
+ bool weightfound = false, pointsizefound = false, encodingfound = false;
while ( tokenizer.HasMoreTokens() )
{
else if ( token == _T("light") || token == _("light") )
{
SetWeight(wxFONTWEIGHT_LIGHT);
+ weightfound = true;
}
else if ( token == _T("bold") || token == _("bold") )
{
SetWeight(wxFONTWEIGHT_BOLD);
+ weightfound = true;
}
else if ( token == _T("italic") || token == _("italic") )
{
else if ( token.ToULong(&size) )
{
SetPointSize(size);
+ pointsizefound = true;
}
+ else
+ {
#if wxUSE_FONTMAP
- else if ( (encoding = wxFontMapper::Get()->CharsetToEncoding(token, false))
- != wxFONTENCODING_DEFAULT )
+ // try to interpret this as an encoding
+ wxFontEncoding encoding = wxFontMapper::Get()->CharsetToEncoding(token, false);
+ if ( encoding != wxFONTENCODING_DEFAULT &&
+ encoding != wxFONTENCODING_SYSTEM ) // returned when the recognition failed
{
SetEncoding(encoding);
+ encodingfound = true;
}
-#endif // wxUSE_FONTMAP
- else // assume it is the face name
+ else
{
+#endif // wxUSE_FONTMAP
+
+ // assume it is the face name
if ( !face.empty() )
{
face += _T(' ');
// skip the code which resets face below
continue;
+
+#if wxUSE_FONTMAP
+ }
+#endif // wxUSE_FONTMAP
}
// if we had had the facename, we shouldn't continue appending tokens
// bar")
if ( !face.empty() )
{
- SetFaceName(face);
+ // NB: the check on the facename is implemented in wxFontBase::SetFaceName
+ // and not in wxNativeFontInfo::SetFaceName thus we need to explicitely
+ // call here wxFontEnumerator::IsValidFacename
+ if (!wxFontEnumerator::IsValidFacename(face) ||
+ !SetFaceName(face))
+ SetFaceName(wxNORMAL_FONT->GetFaceName());
face.clear();
}
}
// we might not have flushed it inside the loop
if ( !face.empty() )
{
- SetFaceName(face);
+ // NB: the check on the facename is implemented in wxFontBase::SetFaceName
+ // and not in wxNativeFontInfo::SetFaceName thus we need to explicitely
+ // call here wxFontEnumerator::IsValidFacename
+ if (!wxFontEnumerator::IsValidFacename(face) ||
+ !SetFaceName(face))
+ SetFaceName(wxNORMAL_FONT->GetFaceName());
}
+ // set point size to default value if size was not given
+ if ( !pointsizefound )
+ SetPointSize(wxNORMAL_FONT->GetPointSize());
+
+ // set font weight to default value if weight was not given
+ if ( !weightfound )
+ SetWeight(wxFONTWEIGHT_NORMAL);
+
+#if wxUSE_FONTMAP
+ // set font encoding to default value if encoding was not given
+ if ( !encodingfound )
+ SetEncoding(wxFONTENCODING_SYSTEM);
+#endif // wxUSE_FONTMAP
+
return true;
}
temp.EnumerateEncodings(facename);
return temp.m_arrEncodings;
}
+
+/* static */
+bool wxFontEnumerator::IsValidFacename(const wxString &facename)
+{
+ // we cache the result of wxFontEnumerator::GetFacenames supposing that
+ // the array of face names won't change in the session of this program
+ static wxArrayString s_arr = wxFontEnumerator::GetFacenames();
+
+#ifdef __WXMSW__
+ // Quoting the MSDN:
+ // "MS Shell Dlg is a mapping mechanism that enables
+ // U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
+ // support locales that have characters that are not contained in code
+ // page 1252. It is not a font but a face name for a nonexistent font."
+ // Thus we need to consider "Ms Shell Dlg" and "Ms Shell Dlg 2" as valid
+ // font face names even if they are enumerated by wxFontEnumerator
+ if (facename.IsSameAs(wxT("Ms Shell Dlg"), false) ||
+ facename.IsSameAs(wxT("Ms Shell Dlg 2"), false))
+ return true;
+#endif
+
+ // is given font face name a valid one ?
+ if (s_arr.Index(facename, false) == wxNOT_FOUND)
+ return false;
+
+ return true;
+}
+
void SetStyle(int style);
void SetWeight(int weight);
void SetUnderlined(bool underlined);
- void SetFaceName(const wxString& facename);
+ bool SetFaceName(const wxString& facename);
void SetEncoding(wxFontEncoding encoding);
void SetNoAntiAliasing( bool no = true ) { m_noAA = no; }
// the XLFD doesn't have "underlined" field anyhow
}
-void wxFontRefData::SetFaceName(const wxString& facename)
+bool wxFontRefData::SetFaceName(const wxString& facename)
{
m_faceName = facename;
- m_nativeFontInfo.SetFaceName(facename);
+ return m_nativeFontInfo.SetFaceName(facename);
}
void wxFontRefData::SetEncoding(wxFontEncoding encoding)
M_FONTDATA->SetWeight(weight);
}
-void wxFont::SetFaceName(const wxString& faceName)
+bool wxFont::SetFaceName(const wxString& faceName)
{
Unshare();
- M_FONTDATA->SetFaceName(faceName);
+ return M_FONTDATA->SetFaceName(faceName) &&
+ wxFontBase::SetFaceName(faceName);
}
void wxFont::SetUnderlined(bool underlined)
void SetStyle(int style);
void SetWeight(int weight);
void SetUnderlined(bool underlined);
- void SetFaceName(const wxString& facename);
+ bool SetFaceName(const wxString& facename);
void SetEncoding(wxFontEncoding encoding);
void SetNoAntiAliasing( bool no = true ) { m_noAA = no; }
// the XLFD doesn't have "underlined" field anyhow
}
-void wxFontRefData::SetFaceName(const wxString& facename)
+bool wxFontRefData::SetFaceName(const wxString& facename)
{
m_faceName = facename;
{
m_nativeFontInfo.SetXFontComponent(wxXLFD_FAMILY, facename);
}
+
+ return true;
}
void wxFontRefData::SetEncoding(wxFontEncoding encoding)
M_FONTDATA->SetWeight(weight);
}
-void wxFont::SetFaceName(const wxString& faceName)
+bool wxFont::SetFaceName(const wxString& faceName)
{
Unshare();
- M_FONTDATA->SetFaceName(faceName);
+ return M_FONTDATA->SetFaceName(faceName) &&
+ wxFontBase::SetFaceName(faceName);
}
void wxFont::SetUnderlined(bool underlined)
RealizeResource();
}
-void wxFont::SetFaceName(const wxString& faceName)
+bool wxFont::SetFaceName(const wxString& faceName)
{
Unshare();
M_FONTDATA->m_faceName = faceName;
RealizeResource();
+
+ return wxFontBase::SetFaceName(faceName);
}
void wxFont::SetUnderlined(bool underlined)
RealizeResource();
}
-void wxFont::SetFaceName(const wxString& faceName)
+bool wxFont::SetFaceName(const wxString& faceName)
{
Unshare();
M_FONTDATA->m_faceName = faceName;
RealizeResource();
+
+ return wxFontBase::SetFaceName(faceName);
}
void wxFont::SetUnderlined(bool underlined)
M_FONTDATA->m_valid = false;
}
-void wxFont::SetFaceName(const wxString& faceName)
+bool wxFont::SetFaceName(const wxString& faceName)
{
AllocExclusive();
M_FONTDATA->m_faceName = faceName;
M_FONTDATA->m_valid = false;
+
+ return wxFontBase::SetFaceName(faceName);
}
void wxFont::SetUnderlined(bool underlined)
M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
}
-void wxFont::SetFaceName(const wxString& faceName)
+bool wxFont::SetFaceName(const wxString& faceName)
{
Unshare();
M_FONTDATA->m_faceName = faceName;
M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
+
+ return wxFontBase::SetFaceName(faceName);
}
void wxFont::SetUnderlined(bool underlined)
m_weight = weight;
}
- void SetFaceName(const wxString& faceName)
+ bool SetFaceName(const wxString& faceName)
{
if ( m_nativeFontInfoOk )
- m_nativeFontInfo.SetFaceName(faceName);
- else
+ return m_nativeFontInfo.SetFaceName(faceName);
+
m_faceName = faceName;
+ return true;
}
void SetUnderlined(bool underlined)
if ( !hfont )
{
wxLogLastError(wxT("CreateFont"));
-
return false;
}
m_hFont = (WXHFONT)hfont;
-
return true;
}
lf.lfUnderline = underlined;
}
-void wxNativeFontInfo::SetFaceName(const wxString& facename)
+bool wxNativeFontInfo::SetFaceName(const wxString& facename)
{
- wxStrncpy(lf.lfFaceName, facename, WXSIZEOF(lf.lfFaceName));
+ size_t len = WXSIZEOF(lf.lfFaceName);
+ wxStrncpy(lf.lfFaceName, facename, len);
+ lf.lfFaceName[len - 1] = '\0'; // truncate the face name
+ return true;
}
void wxNativeFontInfo::SetFamily(wxFontFamily family)
{
BYTE ff_family;
- wxString facename;
+ wxArrayString facename;
+
+ // the list of fonts associated with a family was partially
+ // taken from http://www.codestyle.org/css/font-family
switch ( family )
{
case wxSCRIPT:
ff_family = FF_SCRIPT;
- facename = _T("Script");
+ facename.Add(_T("Script"));
+ facename.Add(_T("Brush Script MT"));
+ facename.Add(_T("Comic Sans MS"));
+ facename.Add(_T("Lucida Handwriting"));
break;
case wxDECORATIVE:
ff_family = FF_DECORATIVE;
- facename = _T("Old English Text MT");
+ facename.Add(_T("Old English Text MT"));
+ facename.Add(_T("Comic Sans MS"));
+ facename.Add(_T("Lucida Handwriting"));
break;
case wxROMAN:
ff_family = FF_ROMAN;
- facename = _T("Times New Roman");
+ facename.Add(_T("Times New Roman"));
+ facename.Add(_T("Georgia"));
+ facename.Add(_T("Garamond"));
+ facename.Add(_T("Bookman Old Style"));
+ facename.Add(_T("Book Antiqua"));
break;
case wxTELETYPE:
case wxMODERN:
ff_family = FF_MODERN;
- facename = _T("Courier New");
+ facename.Add(_T("Courier New"));
+ facename.Add(_T("Lucida Console"));
+ facename.Add(_T("Andale Mono"));
+ facename.Add(_T("OCR A Extended"));
+ facename.Add(_T("Terminal"));
break;
case wxSWISS:
ff_family = FF_SWISS;
- facename = _T("Arial");
+ facename.Add(_T("Arial"));
+ facename.Add(_T("Century Gothic"));
+ facename.Add(_T("Lucida Sans Unicode"));
+ facename.Add(_T("Tahoma"));
+ facename.Add(_T("Trebuchet MS"));
+ facename.Add(_T("Verdana"));
break;
case wxDEFAULT:
int verMaj;
ff_family = FF_SWISS;
if(wxGetOsVersion(&verMaj) == wxWINDOWS_NT && verMaj >= 5)
- facename = _T("MS Shell Dlg 2");
+ facename.Add(_T("MS Shell Dlg 2"));
else
- facename = _T("MS Shell Dlg");
+ facename.Add(_T("MS Shell Dlg"));
+
+ // Quoting the MSDN:
+ // "MS Shell Dlg is a mapping mechanism that enables
+ // U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
+ // support locales that have characters that are not contained in code
+ // page 1252. It is not a font but a face name for a nonexistent font."
}
}
RealizeResource();
}
-void wxFont::SetFaceName(const wxString& faceName)
+bool wxFont::SetFaceName(const wxString& faceName)
{
Unshare();
- M_FONTDATA->SetFaceName(faceName);
+ bool refdataok = M_FONTDATA->SetFaceName(faceName);
RealizeResource();
+
+ // NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
+ // to retrieve a LOGFONT and then compare lf.lfFaceName
+ // with given facename is not reliable at all:
+ // Windows copies the facename given to ::CreateFontIndirect()
+ // without any validity check.
+ // Thus we use wxFontBase::SetFaceName to check if facename
+ // is valid...
+ return refdataok && wxFontBase::SetFaceName(faceName);
}
void wxFont::SetUnderlined(bool underlined)
: NULL;
}
+wxString wxFont::GetNativeFontInfoDesc() const
+{
+ // be sure we have an HFONT associated...
+ wxConstCast(this, wxFont)->RealizeResource();
+ return wxFontBase::GetNativeFontInfoDesc();
+}
+
+wxString wxFont::GetNativeFontInfoUserDesc() const
+{
+ // be sure we have an HFONT associated...
+ wxConstCast(this, wxFont)->RealizeResource();
+ return wxFontBase::GetNativeFontInfoUserDesc();
+}
+
bool wxFont::IsFixedWidth() const
{
if ( M_FONTDATA->HasNativeFontInfo() )
return wxFontBase::IsFixedWidth();
}
+
m_nWeight = nWeight;
}
- inline void SetFaceName(const wxString& sFaceName)
+ inline bool SetFaceName(const wxString& sFaceName)
{
if (m_bNativeFontInfoOk)
- m_vNativeFontInfo.SetFaceName(sFaceName);
+ return m_vNativeFontInfo.SetFaceName(sFaceName);
else
m_sFaceName = sFaceName;
+ return true;
}
inline void SetUnderlined(bool bUnderlined)
fa.fsSelection |= FATTR_SEL_UNDERSCORE;
} // end of wxNativeFontInfo::SetUnderlined
-void wxNativeFontInfo::SetFaceName(
+bool wxNativeFontInfo::SetFaceName(
const wxString& sFacename
)
{
wxStrncpy((wxChar*)fa.szFacename, sFacename, WXSIZEOF(fa.szFacename));
+ return true;
} // end of wxNativeFontInfo::SetFaceName
void wxNativeFontInfo::SetFamily(
RealizeResource();
} // end of wxFont::SetWeight
-void wxFont::SetFaceName(
+bool wxFont::SetFaceName(
const wxString& rsFaceName
)
{
Unshare();
- M_FONTDATA->SetFaceName(rsFaceName);
+ bool refdataok = M_FONTDATA->SetFaceName(rsFaceName);
RealizeResource();
+
+ return refdataok && wxFontBase::SetFaceName(rsFaceName);
} // end of wxFont::SetFaceName
void wxFont::SetUnderlined(
m_weight = weight;
}
- void SetFaceName(const wxString& faceName)
+ bool SetFaceName(const wxString& faceName)
{
if ( m_nativeFontInfoOk )
m_nativeFontInfo.SetFaceName(faceName);
{
}
-void wxFont::SetFaceName(const wxString& faceName)
+bool wxFont::SetFaceName(const wxString& faceName)
{
+ return true;
}
void wxFont::SetUnderlined(bool underlined)
#include "wx/fontmap.h"
#include "wx/tokenzr.h"
#include "wx/module.h"
+#include "wx/fontenum.h"
#if wxUSE_PANGO
wxFAIL_MSG( _T("not implemented") );
}
-void wxNativeFontInfo::SetFaceName(const wxString& facename)
+bool wxNativeFontInfo::SetFaceName(const wxString& facename)
{
pango_font_description_set_family(description, wxGTK_CONV_SYS(facename));
+ return true;
}
void wxNativeFontInfo::SetFamily(wxFontFamily WXUNUSED(family))
description = pango_font_description_from_string( wxGTK_CONV_SYS( str ) );
+ // ensure a valid facename is selected
+ if (!wxFontEnumerator::IsValidFacename(GetFaceName()))
+ SetFaceName(wxNORMAL_FONT->GetFaceName());
+
return true;
}
// can't do this under X
}
-void wxNativeFontInfo::SetFaceName(const wxString& facename)
+bool wxNativeFontInfo::SetFaceName(const wxString& facename)
{
SetXFontComponent(wxXLFD_FAMILY, facename);
+ return true;
}
void wxNativeFontInfo::SetFamily(wxFontFamily WXUNUSED(family))
void SetStyle(int style);
void SetWeight(int weight);
void SetUnderlined(bool underlined);
- void SetFaceName(const wxString& facename);
+ bool SetFaceName(const wxString& facename);
void SetEncoding(wxFontEncoding encoding);
void SetNoAntiAliasing( bool no = true ) { m_noAA = no; }
// the XLFD doesn't have "underlined" field anyhow
}
-void wxFontRefData::SetFaceName(const wxString& facename)
+bool wxFontRefData::SetFaceName(const wxString& facename)
{
m_faceName = facename;
+ return true;
}
void wxFontRefData::SetEncoding(wxFontEncoding encoding)
M_FONTDATA->SetWeight(weight);
}
-void wxFont::SetFaceName(const wxString& faceName)
+bool wxFont::SetFaceName(const wxString& faceName)
{
Unshare();
- M_FONTDATA->SetFaceName(faceName);
+ return M_FONTDATA->SetFaceName(faceName) &&
+ wxFontBase::SetFaceName(faceName);
}
void wxFont::SetUnderlined(bool underlined)