X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a3622daa901777a33969d8bc04e2d62dee14d164..520e470fdd0daef09c77938db642e4583933c90d:/src/gtk1/font.cpp diff --git a/src/gtk1/font.cpp b/src/gtk1/font.cpp index ad4f5e9654..ef95c79be8 100644 --- a/src/gtk1/font.cpp +++ b/src/gtk1/font.cpp @@ -20,17 +20,6 @@ // 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; //----------------------------------------------------------------------------- @@ -60,15 +49,15 @@ class wxFontRefData: public wxObjectRefData 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 = NULL; - m_font = NULL; -}; + m_faceName = (char *) NULL; + m_font = (GdkFont *) NULL; +} wxFontRefData::~wxFontRefData(void) { @@ -79,14 +68,14 @@ wxFontRefData::~wxFontRefData(void) wxNode *next = node->Next(); gdk_font_unref( font ); node = next; - }; + } if (m_faceName) { delete m_faceName; - m_faceName = NULL; - }; + m_faceName = (char *) NULL; + } if (m_font) gdk_font_unref( m_font ); -}; +} //----------------------------------------------------------------------------- @@ -97,7 +86,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) wxFont::wxFont(void) { if (wxTheFontList) wxTheFontList->Append( this ); -}; +} wxFont::wxFont( char *xFontName ) { @@ -107,7 +96,7 @@ wxFont::wxFont( char *xFontName ) M_FONTDATA->m_byXFontName = TRUE; M_FONTDATA->m_font = gdk_font_load( xFontName ); -}; +} wxFont::wxFont(int PointSize, int FontIdOrFamily, int Style, int Weight, bool Underlined, const char* Face) @@ -123,14 +112,17 @@ wxFont::wxFont(int PointSize, int FontIdOrFamily, int Style, int Weight, { 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; if (wxTheFontList) wxTheFontList->Append( this ); -}; +} wxFont::wxFont(int PointSize, const char *Face, int Family, int Style, int Weight, bool Underlined) @@ -146,105 +138,199 @@ wxFont::wxFont(int PointSize, const char *Face, int Family, int Style, M_FONTDATA->m_underlined = Underlined; if (wxTheFontList) wxTheFontList->Append( this ); -}; +} wxFont::wxFont( const wxFont& font ) { Ref( font ); -}; + + if (wxTheFontList) wxTheFontList->Append( this ); +} wxFont::wxFont( const wxFont* font ) { UnRef(); if (font) Ref( *font ); -}; + + if (wxTheFontList) wxTheFontList->Append( this ); +} wxFont::~wxFont(void) { if (wxTheFontList) wxTheFontList->DeleteObject( this ); -}; +} wxFont& wxFont::operator = ( const wxFont& font ) { if (*this == font) return (*this); Ref( font ); return *this; -}; +} bool wxFont::operator == ( const wxFont& font ) { return m_refData == font.m_refData; -}; +} bool wxFont::operator != ( const wxFont& font ) { 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; -}; +} //----------------------------------------------------------------------------- // get internal representation of font @@ -255,13 +341,19 @@ static GdkFont *wxLoadQueryNearestFont(int point_size, int fontid, int style, int weight, bool underlined); -GdkFont *wxFont::GetInternalFont(float scale) +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 int point_scale = (M_FONTDATA->m_pointSize * 10 * int_scale) / 100; - GdkFont *font = NULL; + GdkFont *font = (GdkFont *) NULL; wxNode *node = M_FONTDATA->m_scaled_xfonts.Find(int_scale); if (node) @@ -273,12 +365,12 @@ GdkFont *wxFont::GetInternalFont(float scale) font = wxLoadQueryNearestFont( point_scale, M_FONTDATA->m_fontId, M_FONTDATA->m_style, M_FONTDATA->m_weight, M_FONTDATA->m_underlined ); M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font ); - }; + } if (!font) printf("could not load any font"); // wxError("could not load any font", "wxFont"); return font; -}; +} //----------------------------------------------------------------------------- // local utilities to find a X font @@ -434,7 +526,7 @@ static char *font_defaults[] = { "-${ScreenSwissBase}${ScreenStdSuffix}", "ScreenScript__", "-${ScreenScriptBase}${ScreenStdSuffix}", - NULL + (char *) NULL }; enum {wxWEIGHT_NORMAL, wxWEIGHT_BOLD, wxWEIGHT_LIGHT, wxNUM_WEIGHTS}; @@ -448,7 +540,7 @@ static int WCoordinate(int w) case wxNORMAL: default: return wxWEIGHT_NORMAL; } -} +}; static int SCoordinate(int s) { @@ -458,7 +550,7 @@ static int SCoordinate(int s) case wxNORMAL: default: return wxSTYLE_NORMAL; } -} +}; //----------------------------------------------------------------------------- // wxSuffixMap @@ -488,8 +580,8 @@ static void SearchResource(const char *prefix, const char **names, int count, ch k = 1 << count; - *v = NULL; - internal = NULL; + *v = (char *) NULL; + internal = (char *) NULL; for (i = 0; i < k; i++) { strcpy(resource, prefix); @@ -524,7 +616,7 @@ wxSuffixMap::~wxSuffixMap(void) for (j = 0; j < wxNUM_STYLES; ++j) if (map[k][j]) { delete[] map[k][j]; - map[k][j] = NULL; + map[k][j] = (char *) NULL; } } @@ -567,7 +659,7 @@ void wxSuffixMap::Initialize(const char *resname, const char *devresname) ++i; } else if (v[i] == closer) { int newstrlen; - const char *r = NULL; bool delete_r = FALSE; + const char *r = (char *) NULL; bool delete_r = FALSE; char *name; name = v + startpos + 2; @@ -678,7 +770,7 @@ wxFontNameItem::~wxFontNameItem(void) { if (name) delete[] name; - name = NULL; + name = (char *) NULL; } #if WXDEBUG @@ -734,7 +826,7 @@ void wxFontNameDirectory::Initialize(int fontid, int family, const char *resname char *fam, resource[256]; sprintf(resource, "Family%s", resname); - SearchResource((const char *)resource, NULL, 0, (char **)&fam); + SearchResource((const char *)resource, (const char **) NULL, 0, (char **)&fam); if (fam) { if (!strcmp(fam, "Default")) family = wxDEFAULT; else if (!strcmp(fam, "Roman")) family = wxROMAN; @@ -765,7 +857,7 @@ char *wxFontNameDirectory::GetScreenName(int fontid, int weight, int style) if (item) return item->GetScreenName(weight, style); // font does not exist - return NULL; + return (char *) NULL; } char *wxFontNameDirectory::GetPostScriptName(int fontid, int weight, int style) @@ -774,7 +866,7 @@ char *wxFontNameDirectory::GetPostScriptName(int fontid, int weight, int style) if (item) return item->GetPostScriptName(weight, style); // font does not exist - return NULL; + return (char *) NULL; } char *wxFontNameDirectory::GetAFMName(int fontid, int weight, int style) @@ -783,7 +875,7 @@ char *wxFontNameDirectory::GetAFMName(int fontid, int weight, int style) if (item) return item->GetAFMName(weight, style); // font does not exist - return NULL; + return (char *) NULL; } char *wxFontNameDirectory::GetFontName(int fontid) @@ -792,7 +884,7 @@ char *wxFontNameDirectory::GetFontName(int fontid) if (item) return item->GetName(); // font does not exist - return NULL; + return (char *) NULL; } int wxFontNameDirectory::GetFontId(const char *name)