X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/09a1dffa32ae09ea47789eb071a1fdac0d154dda..58c23da1d54bf50d9f892b692b941f2cd20d96d0:/src/x11/font.cpp diff --git a/src/x11/font.cpp b/src/x11/font.cpp index 16aeceff70..675acc54bd 100644 --- a/src/x11/font.cpp +++ b/src/x11/font.cpp @@ -9,6 +9,9 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + // ============================================================================ // declarations // ============================================================================ @@ -17,10 +20,6 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "font.h" -#endif - #ifdef __VMS #pragma message disable nosimpint #include "wx/vms_x_fix.h" @@ -30,14 +29,17 @@ #pragma message enable nosimpint #endif -#include "wx/defs.h" -#include "wx/string.h" #include "wx/font.h" + +#ifndef WX_PRECOMP + #include "wx/string.h" + #include "wx/utils.h" // for wxGetDisplay() + #include "wx/settings.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/x11/private.h" @@ -79,10 +81,10 @@ wxXFont::wxXFont() wxXFont::~wxXFont() { - // TODO: why does freeing the font produce a segv??? - // Note that XFreeFont wasn't called in wxWin 1.68 either. - // XFontStruct* fontStruct = (XFontStruct*) m_fontStruct; - // XFreeFont((Display*) m_display, fontStruct); + // Freeing the font used to produce a segv, but + // appears to be OK now (bug fix in X11?) + XFontStruct* fontStruct = (XFontStruct*) m_fontStruct; + XFreeFont((Display*) m_display, fontStruct); } #endif @@ -99,7 +101,7 @@ public: int family = wxDEFAULT, int style = wxDEFAULT, int weight = wxDEFAULT, - bool underlined = FALSE, + bool underlined = false, const wxString& faceName = wxEmptyString, wxFontEncoding encoding = wxFONTENCODING_DEFAULT); @@ -119,11 +121,11 @@ public: 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; } - bool GetNoAntiAliasing() { return m_noAA; } + void SetNoAntiAliasing( bool no = true ) { m_noAA = no; } + bool GetNoAntiAliasing() const { return m_noAA; } // and this one also modifies all the other font data fields void SetNativeFontInfo(const wxNativeFontInfo& info); @@ -202,7 +204,7 @@ void wxFontRefData::Init(int pointSize, case wxFONTFAMILY_TELETYPE: pango_font_description_set_family( m_nativeFontInfo.description, "monospace" ); break; - case wxFONTFAMILY_SWISS: + case wxFONTFAMILY_ROMAN: pango_font_description_set_family( m_nativeFontInfo.description, "serif" ); break; default: @@ -217,7 +219,7 @@ void wxFontRefData::Init(int pointSize, void wxFontRefData::InitFromNative() { - m_noAA = FALSE; + m_noAA = false; #if wxUSE_UNICODE // Get native info @@ -277,7 +279,7 @@ void wxFontRefData::InitFromNative() } // Pango description are never underlined (?) - m_underlined = FALSE; + m_underlined = false; // Cannot we choose that m_encoding = wxFONTENCODING_SYSTEM; @@ -347,7 +349,7 @@ void wxFontRefData::InitFromNative() } // X fonts are never underlined... - m_underlined = FALSE; + m_underlined = false; // deal with font encoding wxString @@ -424,7 +426,7 @@ void wxFontRefData::ClearX11Fonts() { #if wxUSE_UNICODE #else - wxNode* node = m_fonts.GetFirst(); + wxList::compatibility_iterator node = m_fonts.GetFirst(); while (node) { wxXFont* f = (wxXFont*) node->GetData(); @@ -501,9 +503,10 @@ void wxFontRefData::SetUnderlined(bool underlined) // 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) @@ -526,14 +529,8 @@ void wxFontRefData::SetNativeFontInfo(const wxNativeFontInfo& info) // wxFont // ---------------------------------------------------------------------------- -void wxFont::Init() -{ -} - wxFont::wxFont(const wxNativeFontInfo& info) { - Init(); - #if wxUSE_UNICODE Create( info.GetPointSize(), info.GetFamily(), @@ -560,7 +557,7 @@ bool wxFont::Create(int pointSize, m_refData = new wxFontRefData(pointSize, family, style, weight, underlined, faceName, encoding); - return TRUE; + return true; } #if !wxUSE_UNICODE @@ -570,7 +567,7 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc) if( !fontname ) { *this = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT); - return TRUE; + return true; } m_refData = new wxFontRefData(); @@ -663,9 +660,9 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc) } //else: unknown encoding - may be give a warning here? else - return FALSE; + return false; } - return TRUE; + return true; } #endif // !wxUSE_UNICODE @@ -705,7 +702,7 @@ int wxFont::GetPointSize() const wxString wxFont::GetFaceName() const { - wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") ); + wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") ); return M_FONTDATA->m_faceName; } @@ -733,7 +730,7 @@ int wxFont::GetWeight() const bool wxFont::GetUnderlined() const { - wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") ); + wxCHECK_MSG( Ok(), false, wxT("invalid font") ); return M_FONTDATA->m_underlined; } @@ -745,14 +742,14 @@ wxFontEncoding wxFont::GetEncoding() const return M_FONTDATA->m_encoding; } -bool wxFont::GetNoAntiAliasing() +bool wxFont::GetNoAntiAliasing() const { wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); return M_FONTDATA->m_noAA; } -wxNativeFontInfo *wxFont::GetNativeFontInfo() const +const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") ); @@ -762,17 +759,18 @@ wxNativeFontInfo *wxFont::GetNativeFontInfo() const GetInternalFont(); #endif - return new wxNativeFontInfo(M_FONTDATA->m_nativeFontInfo); + return &(M_FONTDATA->m_nativeFontInfo); } bool wxFont::IsFixedWidth() const { - wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") ); + wxCHECK_MSG( Ok(), false, wxT("invalid font") ); #if wxUSE_UNICODE + return wxFontBase::IsFixedWidth(); #else // Robert, is this right? HasNativeFont doesn't exist. - if ( TRUE ) + if ( true ) // if ( M_FONTDATA->HasNativeFont() ) { // the monospace fonts are supposed to have "M" in the spacing field @@ -781,9 +779,10 @@ bool wxFont::IsFixedWidth() const return spacing.Upper() == _T('M'); } + // Unreaceable code for now + // return wxFontBase::IsFixedWidth(); #endif - return wxFontBase::IsFixedWidth(); } // ---------------------------------------------------------------------------- @@ -818,11 +817,12 @@ void wxFont::SetWeight(int weight) 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) @@ -872,7 +872,7 @@ wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const int pointSize = (M_FONTDATA->m_pointSize * 10 * intScale) / 100; // search existing fonts first - wxNode* node = M_FONTDATA->m_fonts.GetFirst(); + wxList::compatibility_iterator node = M_FONTDATA->m_fonts.GetFirst(); while (node) { wxXFont* f = (wxXFont*) node->GetData(); @@ -881,6 +881,11 @@ wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const node = node->GetNext(); } + wxString xFontName = M_FONTDATA->m_nativeFontInfo.GetXFontName(); + if (xFontName == "-*-*-*-*-*--*-*-*-*-*-*-*-*") + // wxFont constructor not called with native font info parameter => take M_FONTDATA values + xFontName.Clear(); + // not found, create a new one XFontStruct *font = (XFontStruct *) wxLoadQueryNearestFont(pointSize, @@ -889,7 +894,8 @@ wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const M_FONTDATA->m_weight, M_FONTDATA->m_underlined, wxT(""), - M_FONTDATA->m_encoding); + M_FONTDATA->m_encoding, + & xFontName); if ( !font ) {