X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df91131cb0f90ee8bfb194926a13b1a108ca3c6e..63660cba0acbdefc2ac156ef74e899146d98c1c4:/src/motif/font.cpp diff --git a/src/motif/font.cpp b/src/motif/font.cpp index f4653d60ad..a07b6fa920 100644 --- a/src/motif/font.cpp +++ b/src/motif/font.cpp @@ -33,17 +33,15 @@ #ifndef WX_PRECOMP #include "wx/string.h" + #include "wx/utils.h" // for wxGetDisplay() + #include "wx/settings.h" + #include "wx/gdicmn.h" #endif -#include "wx/gdicmn.h" -#include "wx/utils.h" // for wxGetDisplay() #include "wx/fontutil.h" // for wxNativeFontInfo #include "wx/tokenzr.h" -#include "wx/settings.h" #include "wx/motif/private.h" -IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) - // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -54,14 +52,14 @@ class wxXFont : public wxObject { public: wxXFont(); - ~wxXFont(); + virtual ~wxXFont(); #if !wxMOTIF_NEW_FONT_HANDLING WXFontStructPtr m_fontStruct; // XFontStruct #endif -#if !wxMOTIF_USE_RENDER_TABLE && !wxMOTIF_NEW_FONT_HANDLING +#if !wxMOTIF_USE_RENDER_TABLE WXFontList m_fontList; // Motif XmFontList -#else // if wxUSE_RENDER_TABLE +#else // if wxMOTIF_USE_RENDER_TABLE WXRenderTable m_renderTable; // Motif XmRenderTable WXRendition m_rendition; // Motif XmRendition #endif @@ -75,9 +73,9 @@ class wxFontRefData: public wxGDIRefData public: wxFontRefData(int size = wxDEFAULT, - int family = wxDEFAULT, - int style = wxDEFAULT, - int weight = wxDEFAULT, + wxFontFamily family = wxFONTFAMILY_DEFAULT, + wxFontStyle style = wxFONTSTYLE_NORMAL, + wxFontWeight weight = wxFONTWEIGHT_NORMAL, bool underlined = false, const wxString& faceName = wxEmptyString, wxFontEncoding encoding = wxFONTENCODING_DEFAULT) @@ -91,23 +89,23 @@ public: data.m_underlined, data.m_faceName, data.m_encoding); } - ~wxFontRefData(); + virtual ~wxFontRefData(); protected: // common part of all ctors void Init(int size, - int family, - int style, - int weight, + wxFontFamily family, + wxFontStyle style, + wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding); // font attributes int m_pointSize; - int m_family; - int m_style; - int m_weight; + wxFontFamily m_family; + wxFontStyle m_style; + wxFontWeight m_weight; bool m_underlined; wxString m_faceName; wxFontEncoding m_encoding; @@ -131,7 +129,7 @@ wxXFont::wxXFont() #if !wxMOTIF_NEW_FONT_HANDLING m_fontStruct = (WXFontStructPtr) 0; #endif -#if !wxMOTIF_USE_RENDER_TABLE && !wxMOTIF_NEW_FONT_HANDLING +#if !wxMOTIF_USE_RENDER_TABLE m_fontList = (WXFontList) 0; #else // if wxMOTIF_USE_RENDER_TABLE m_renderTable = (WXRenderTable) 0; @@ -147,7 +145,7 @@ wxXFont::~wxXFont() if (m_fontList) XmFontListFree ((XmFontList) m_fontList); m_fontList = NULL; -#else // if wxUSE_RENDER_TABLE +#else // if wxMOTIF_USE_RENDER_TABLE if (m_renderTable) XmRenderTableFree ((XmRenderTable) m_renderTable); m_renderTable = NULL; @@ -166,27 +164,27 @@ wxXFont::~wxXFont() // ---------------------------------------------------------------------------- void wxFontRefData::Init(int pointSize, - int family, - int style, - int weight, + wxFontFamily family, + wxFontStyle style, + wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) { if (family == wxDEFAULT) - m_family = wxSWISS; + m_family = wxFONTFAMILY_SWISS; else m_family = family; m_faceName = faceName; if (style == wxDEFAULT) - m_style = wxNORMAL; + m_style = wxFONTSTYLE_NORMAL; else m_style = style; if (weight == wxDEFAULT) - m_weight = wxNORMAL; + m_weight = wxFONTWEIGHT_NORMAL; else m_weight = weight; @@ -211,6 +209,8 @@ wxFontRefData::~wxFontRefData() m_fonts.Clear(); } +#define M_FONTDATA ((wxFontRefData*)m_refData) + // ---------------------------------------------------------------------------- // wxFont // ---------------------------------------------------------------------------- @@ -221,9 +221,9 @@ wxFont::wxFont(const wxNativeFontInfo& info) } bool wxFont::Create(int pointSize, - int family, - int style, - int weight, + wxFontFamily family, + wxFontStyle style, + wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) @@ -258,18 +258,18 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc) M_FONTDATA->m_faceName = tn.GetNextToken(); // family tmp = tn.GetNextToken().MakeUpper(); // weight - if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxBOLD; - if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxBOLD; - if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxBOLD; - if (tmp == wxT("DEMIBOLD")) M_FONTDATA->m_weight = wxBOLD; - if (tmp == wxT("ULTRABOLD")) M_FONTDATA->m_weight = wxBOLD; + if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD; + if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD; + if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD; + if (tmp == wxT("DEMIBOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD; + if (tmp == wxT("ULTRABOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD; - if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxLIGHT; - if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxLIGHT; + if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxFONTWEIGHT_LIGHT; + if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxFONTWEIGHT_LIGHT; tmp = tn.GetNextToken().MakeUpper(); // slant - if (tmp == wxT("I")) M_FONTDATA->m_style = wxITALIC; - if (tmp == wxT("O")) M_FONTDATA->m_style = wxITALIC; + if (tmp == wxT("I")) M_FONTDATA->m_style = wxFONTSTYLE_ITALIC; + if (tmp == wxT("O")) M_FONTDATA->m_style = wxFONTSTYLE_ITALIC; tn.GetNextToken(); // set width tn.GetNextToken(); // add. style @@ -278,7 +278,7 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc) tmp = tn.GetNextToken(); // pointsize if (tmp != wxT("*")) { - long num = wxStrtol (tmp.c_str(), (wxChar **) NULL, 10); + long num = wxStrtol (tmp.mb_str(), (wxChar **) NULL, 10); M_FONTDATA->m_pointSize = (int)(num / 10); } @@ -288,17 +288,17 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc) tmp = tn.GetNextToken().MakeUpper(); // spacing if (tmp == wxT("M")) - M_FONTDATA->m_family = wxMODERN; + M_FONTDATA->m_family = wxFONTFAMILY_MODERN; else if (M_FONTDATA->m_faceName == wxT("TIMES")) - M_FONTDATA->m_family = wxROMAN; + M_FONTDATA->m_family = wxFONTFAMILY_ROMAN; else if (M_FONTDATA->m_faceName == wxT("HELVETICA")) - M_FONTDATA->m_family = wxSWISS; + M_FONTDATA->m_family = wxFONTFAMILY_SWISS; else if (M_FONTDATA->m_faceName == wxT("LUCIDATYPEWRITER")) - M_FONTDATA->m_family = wxTELETYPE; + M_FONTDATA->m_family = wxFONTFAMILY_TELETYPE; else if (M_FONTDATA->m_faceName == wxT("LUCIDA")) - M_FONTDATA->m_family = wxDECORATIVE; + M_FONTDATA->m_family = wxFONTFAMILY_DECORATIVE; else if (M_FONTDATA->m_faceName == wxT("UTOPIA")) - M_FONTDATA->m_family = wxSCRIPT; + M_FONTDATA->m_family = wxFONTFAMILY_SCRIPT; tn.GetNextToken(); // avg width @@ -309,7 +309,7 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc) wxString registry = tn.GetNextToken().MakeUpper(), encoding = tn.GetNextToken().MakeUpper(); - if ( registry == _T("ISO8859") ) + if ( registry == wxT("ISO8859") ) { int cp; if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 ) @@ -318,7 +318,7 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc) (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1); } } - else if ( registry == _T("MICROSOFT") ) + else if ( registry == wxT("MICROSOFT") ) { int cp; if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 ) @@ -327,7 +327,7 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc) (wxFontEncoding)(wxFONTENCODING_CP1250 + cp); } } - else if ( registry == _T("KOI8") ) + else if ( registry == wxT("KOI8") ) { M_FONTDATA->m_encoding = wxFONTENCODING_KOI8; } @@ -342,6 +342,16 @@ wxFont::~wxFont() { } +wxGDIRefData *wxFont::CreateGDIRefData() const +{ + return new wxFontRefData; +} + +wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxFontRefData(*static_cast(data)); +} + // ---------------------------------------------------------------------------- // change the font attributes // ---------------------------------------------------------------------------- @@ -369,7 +379,7 @@ void wxFont::SetPointSize(int pointSize) M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now } -void wxFont::SetFamily(int family) +void wxFont::SetFamily(wxFontFamily family) { Unshare(); @@ -377,7 +387,7 @@ void wxFont::SetFamily(int family) M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now } -void wxFont::SetStyle(int style) +void wxFont::SetStyle(wxFontStyle style) { Unshare(); @@ -385,7 +395,7 @@ void wxFont::SetStyle(int style) M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now } -void wxFont::SetWeight(int weight) +void wxFont::SetWeight(wxFontWeight weight) { Unshare(); @@ -393,12 +403,14 @@ void wxFont::SetWeight(int weight) 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) @@ -429,56 +441,54 @@ void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info) int wxFont::GetPointSize() const { - wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); + wxCHECK_MSG( IsOk(), 0, wxT("invalid font") ); return M_FONTDATA->m_pointSize; } wxString wxFont::GetFaceName() const { - wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") ); + wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") ); return M_FONTDATA->m_faceName ; } -int wxFont::GetFamily() const +wxFontFamily wxFont::DoGetFamily() const { - wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); - return M_FONTDATA->m_family; } -int wxFont::GetStyle() const +wxFontStyle wxFont::GetStyle() const { - wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); + wxCHECK_MSG( IsOk(), wxFONTSTYLE_MAX, wxT("invalid font") ); return M_FONTDATA->m_style; } -int wxFont::GetWeight() const +wxFontWeight wxFont::GetWeight() const { - wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); + wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") ); return M_FONTDATA->m_weight; } bool wxFont::GetUnderlined() const { - wxCHECK_MSG( Ok(), false, wxT("invalid font") ); + wxCHECK_MSG( IsOk(), false, wxT("invalid font") ); return M_FONTDATA->m_underlined; } wxFontEncoding wxFont::GetEncoding() const { - wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); + wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); return M_FONTDATA->m_encoding; } const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { - wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") ); + wxCHECK_MSG( IsOk(), NULL, wxT("invalid font") ); if(M_FONTDATA->m_nativeFontInfo.GetXFontName().empty()) GetInternalFont(); @@ -495,8 +505,8 @@ const wxNativeFontInfo *wxFont::GetNativeFontInfo() const // font to list in the private data for future reference. wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const { - if ( !Ok() ) - return (wxXFont *)NULL; + if ( !IsOk() ) + return NULL; long intScale = long(scale * 100.0 + 0.5); // key for wxXFont int pointSize = (M_FONTDATA->m_pointSize * 10 * intScale) / 100; @@ -527,7 +537,7 @@ wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const { wxFAIL_MSG( wxT("Could not allocate even a default font -- something is wrong.") ); - return (wxXFont*) NULL; + return NULL; } wxXFont* f = new wxXFont; @@ -546,7 +556,7 @@ wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const int count = 0; #if wxMOTIF_NEW_FONT_HANDLING - wxChar* fontSpec = wxStrdup( xFontSpec.c_str() ); + char* fontSpec = wxStrdup(xFontSpec.mb_str()); XtSetArg( args[count], XmNfontName, fontSpec ); ++count; XtSetArg( args[count], XmNfontType, XmFONT_IS_FONTSET ); ++count; #else @@ -607,18 +617,18 @@ WXRenderTable wxFont::GetRenderTable(WXDisplay* display) const WXFontType wxFont::GetFontType(WXDisplay* display) const { #if wxMOTIF_USE_RENDER_TABLE - return Ok() ? GetRenderTable(display) : NULL; + return IsOk() ? GetRenderTable(display) : NULL; #else - return Ok() ? GetFontList(1.0, display) : NULL; + return IsOk() ? GetFontList(1.0, display) : NULL; #endif } WXFontType wxFont::GetFontTypeC(WXDisplay* display) const { #if wxMOTIF_USE_RENDER_TABLE - return Ok() ? GetRenderTable(display) : NULL; + return IsOk() ? GetRenderTable(display) : NULL; #else - return Ok() ? XmFontListCopy( (XmFontList)GetFontList(1.0, display) ) : NULL; + return IsOk() ? XmFontListCopy( (XmFontList)GetFontList(1.0, display) ) : NULL; #endif } @@ -631,7 +641,7 @@ WXFontType wxFont::GetFontTypeC(WXDisplay* display) const #endif } -#if wxMOTIF_NEW_FONT_HANDLING +#if wxMOTIF_USE_RENDER_TABLE WXFontSet wxFont::GetFontSet(double scale, WXDisplay* display) const { @@ -655,7 +665,7 @@ void wxGetTextExtent(WXDisplay* display, const wxFont& font, double scale, XRectangle ink, logical; WXFontSet fset = font.GetFontSet(scale, display); - XmbTextExtents( (XFontSet)fset, str.c_str(), str.length(), &ink, &logical); + XmbTextExtents( (XFontSet)fset, str.mb_str(), str.length(), &ink, &logical); if( width ) *width = logical.width; if( height ) *height = logical.height; @@ -663,7 +673,7 @@ void wxGetTextExtent(WXDisplay* display, const wxFont& font, double scale, if( descent ) *descent = logical.height + logical.y; } -#else // if !wxMOTIF_NEW_FONT_HANDLING +#else // if !wxMOTIF_USE_RENDER_TABLE void wxGetTextExtent(WXDisplay* display, const wxFont& font, double scale, const wxString& str, @@ -673,9 +683,10 @@ void wxGetTextExtent(WXDisplay* display, const wxFont& font, int direction, ascent2, descent2; XCharStruct overall; - int slen = str.Len(); + int slen = str.length(); - XTextExtents((XFontStruct*) pFontStruct, (char*) str.c_str(), slen, + XTextExtents((XFontStruct*) pFontStruct, + const_cast((const char *)str.mb_str()), slen, &direction, &ascent2, &descent2, &overall); if ( width ) @@ -688,4 +699,4 @@ void wxGetTextExtent(WXDisplay* display, const wxFont& font, *ascent = ascent2; } -#endif // !wxMOTIF_NEW_FONT_HANDLING +#endif // !wxMOTIF_USE_RENDER_TABLE