// local data
//-----------------------------------------------------------------------------
-static char *wx_font_family [] = {
- "wxDEFAULT", "wxDECORATIVE", "wxMODERN", "wxROMAN", "wxSCRIPT",
- "wxSWISS", "wxTELETYPE",
-};
-
-static char *wx_font_style [] = {
- "wxDEFAULT", "wxNORMAL", "wxSLANT", "wxITALIC",
-};
-
-static char *wx_font_weight [] = {
- "wxDEFAULT", "wxNORMAL", "wxBOLD", "wxLIGHT",
-};
-
extern wxFontNameDirectory *wxTheFontNameDirectory;
//-----------------------------------------------------------------------------
wxFontRefData::wxFontRefData(void) : m_scaled_xfonts(wxKEY_INTEGER)
{
m_byXFontName = FALSE;
- m_pointSize = -1;
- m_family = -1;
- m_style = -1;
- m_weight = -1;
+ m_pointSize = 12;
+ m_family = wxSWISS;
+ m_style = wxNORMAL;
+ m_weight = wxNORMAL;
m_underlined = FALSE;
m_fontId = 0;
m_faceName = (char *) NULL;
M_FONTDATA->m_fontId = FontIdOrFamily;
M_FONTDATA->m_family = wxTheFontNameDirectory->GetFamily( FontIdOrFamily );
}
+ if (Style == wxDEFAULT) Style = wxSWISS;
M_FONTDATA->m_style = Style;
+ if (Weight == wxDEFAULT) Weight = wxNORMAL;
M_FONTDATA->m_weight = Weight;
+ if (PointSize == wxDEFAULT) PointSize = 10;
M_FONTDATA->m_pointSize = PointSize;
M_FONTDATA->m_underlined = Underlined;
return m_refData != font.m_refData;
}
-bool wxFont::Ok()
+bool wxFont::Ok() const
{
return (m_refData != NULL);
}
int wxFont::GetPointSize(void) const
{
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid font" );
+ return 0;
+ }
+
return M_FONTDATA->m_pointSize;
}
wxString wxFont::GetFaceString(void) const
{
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid font" );
+ return "";
+ }
+
wxString s = wxTheFontNameDirectory->GetFontName( M_FONTDATA->m_fontId );
return s;
}
wxString wxFont::GetFaceName(void) const
{
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid font" );
+ return "";
+ }
+
wxString s = wxTheFontNameDirectory->GetFontName( M_FONTDATA->m_fontId );
return s;
}
int wxFont::GetFamily(void) const
{
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid font" );
+ return 0;
+ }
+
return M_FONTDATA->m_family;
}
wxString wxFont::GetFamilyString(void) const
{
- wxString s = wx_font_family[M_FONTDATA->m_family];
- return s;
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid font" );
+ return "wxDEFAULT";
+ }
+
+ switch (M_FONTDATA->m_family)
+ {
+ case wxDECORATIVE: return wxString("wxDECORATIVE");
+ case wxROMAN: return wxString("wxROMAN");
+ case wxSCRIPT: return wxString("wxSCRIPT");
+ case wxSWISS: return wxString("wxSWISS");
+ case wxMODERN: return wxString("wxMODERN");
+ case wxTELETYPE: return wxString("wxTELETYPE");
+ default: return "wxDEFAULT";
+ }
+
+ return "wxDEFAULT";
}
int wxFont::GetFontId(void) const
{
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid font" );
+ return 0;
+ }
+
return M_FONTDATA->m_fontId; // stub
}
int wxFont::GetStyle(void) const
{
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid font" );
+ return 0;
+ }
+
return M_FONTDATA->m_style;
}
wxString wxFont::GetStyleString(void) const
{
- wxString s = wx_font_style[M_FONTDATA->m_style];
- return s;
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid font" );
+ return "wxDEFAULT";
+ }
+
+ switch (M_FONTDATA->m_style)
+ {
+ case wxNORMAL: return wxString("wxNORMAL");
+ case wxSLANT: return wxString("wxSLANT");
+ case wxITALIC: return wxString("wxITALIC");
+ default: return wxString("wxDEFAULT");
+ }
+
+ return wxString("wxDEFAULT");
}
int wxFont::GetWeight(void) const
{
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid font" );
+ return 0;
+ }
+
return M_FONTDATA->m_weight;
}
wxString wxFont::GetWeightString(void) const
{
- wxString s = wx_font_weight[M_FONTDATA->m_weight];
- return s;
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid font" );
+ return "wxDEFAULT";
+ }
+
+ switch (M_FONTDATA->m_weight)
+ {
+ case wxNORMAL: return wxString("wxNORMAL");
+ case wxBOLD: return wxString("wxBOLD");
+ case wxLIGHT: return wxString("wxLIGHT");
+ default: return wxString("wxDEFAULT");
+ }
+
+ return wxString("wxDEFAULT");
}
bool wxFont::GetUnderlined(void) const
{
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid font" );
+ return FALSE;
+ }
+
return M_FONTDATA->m_underlined;
}
GdkFont *wxFont::GetInternalFont(float scale) const
{
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid font" );
+ return (GdkFont*) NULL;
+ }
+
if (M_FONTDATA->m_byXFontName) return M_FONTDATA->m_font;
long int_scale = long(scale * 100.0 + 0.5); // key for fontlist