X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/011ba5ed7eb41a0f404960746212bf67a06a9351..8a094d7ba9913333b49f8561d97b8309d0023663:/src/gtk/font.cpp?ds=sidebyside diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 31345187cb..eef97f198b 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Id: $Id$ -// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem +// Copyright: (c) 1998 Robert Roebling and Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -15,10 +15,13 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "font.h" #endif +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + #include "wx/font.h" #include "wx/fontutil.h" #include "wx/cmndata.h" @@ -83,6 +86,11 @@ public: #endif // GTK 2.0/1.x } +#ifndef __WXGTK20__ + // reinitilize the font with the gived XFLD + void ReInit(const wxString& fontname); +#endif + // setters: all of them also take care to modify m_nativeFontInfo if we // have it so as to not lose the information not carried by our fields void SetPointSize(int pointSize); @@ -93,6 +101,9 @@ public: void SetFaceName(const wxString& facename); void SetEncoding(wxFontEncoding encoding); + void SetNoAntiAliasing( bool no = TRUE ) { m_noAA = no; } + bool GetNoAntiAliasing() { return m_noAA; } + // and this one also modifies all the other font data fields void SetNativeFontInfo(const wxNativeFontInfo& info); @@ -130,17 +141,14 @@ protected: void InitFromNative(); private: -#ifdef __WXGTK20__ - void ClearGdkFonts() { } -#else // GTK 1.x - // clear m_scaled_xfonts + // clear m_scaled_xfonts if any void ClearGdkFonts(); +#ifndef __WXGTK20__ // the map of font sizes to "GdkFont *" wxScaledFontList m_scaled_xfonts; #endif // GTK 2.0/1.x - // the broken down font parameters int m_pointSize; int m_family, m_style, @@ -148,6 +156,7 @@ private: bool m_underlined; wxString m_faceName; wxFontEncoding m_encoding; // Unused under GTK 2.0 + bool m_noAA; // No anti-aliasing // The native font info, basicly an XFLD under GTK 1.2 and // the pango font description under GTK 2.0. @@ -156,12 +165,8 @@ private: friend class wxFont; }; -// ============================================================================ -// wxFontRefData implementation -// ============================================================================ - // ---------------------------------------------------------------------------- -// wxFontRefData creation +// wxFontRefData // ---------------------------------------------------------------------------- void wxFontRefData::Init(int pointSize, @@ -189,24 +194,36 @@ void wxFontRefData::Init(int pointSize, m_underlined = underlined; m_encoding = encoding; + m_noAA = FALSE; + #ifdef __WXGTK20__ // Create native font info m_nativeFontInfo.description = pango_font_description_new(); // And set its values - switch (m_family) - { - case wxFONTFAMILY_MODERN: - case wxFONTFAMILY_TELETYPE: - pango_font_description_set_family( m_nativeFontInfo.description, "monospace" ); - break; - case wxFONTFAMILY_SWISS: - pango_font_description_set_family( m_nativeFontInfo.description, "serif" ); - break; - default: - pango_font_description_set_family( m_nativeFontInfo.description, "sans" ); - break; + if (!m_faceName.empty()) + { + pango_font_description_set_family( m_nativeFontInfo.description, wxGTK_CONV(m_faceName) ); } + else + { + switch (m_family) + { + case wxFONTFAMILY_MODERN: + case wxFONTFAMILY_TELETYPE: + pango_font_description_set_family( m_nativeFontInfo.description, "monospace" ); + break; + case wxFONTFAMILY_ROMAN: + pango_font_description_set_family( m_nativeFontInfo.description, "serif" ); + break; + case wxFONTFAMILY_SWISS: + // SWISS = sans serif + default: + pango_font_description_set_family( m_nativeFontInfo.description, "sans" ); + break; + } + } + SetStyle( m_style ); SetPointSize( m_pointSize ); SetWeight( m_weight ); @@ -215,6 +232,8 @@ void wxFontRefData::Init(int pointSize, void wxFontRefData::InitFromNative() { + m_noAA = FALSE; + #ifdef __WXGTK20__ // Get native info PangoFontDescription *desc = m_nativeFontInfo.description; @@ -267,6 +286,10 @@ void wxFontRefData::InitFromNative() { m_family = wxFONTFAMILY_SWISS; } + else if (m_faceName == wxT("serif")) + { + m_family = wxFONTFAMILY_ROMAN; + } else { m_family = wxFONTFAMILY_UNKNOWN; @@ -391,7 +414,12 @@ wxFontRefData::wxFontRefData( const wxFontRefData& data ) m_faceName = data.m_faceName; m_encoding = data.m_encoding; - m_nativeFontInfo = data.m_nativeFontInfo; + m_noAA = data.m_noAA; + + // Forces a copy of the internal data. wxNativeFontInfo should probably + // have a copy ctor and assignment operator to fix this properly but that + // would break binary compatibility... + m_nativeFontInfo.FromString(data.m_nativeFontInfo.ToString()); } wxFontRefData::wxFontRefData(int size, int family, int style, @@ -415,8 +443,17 @@ wxFontRefData::wxFontRefData(const wxString& fontname) } #ifndef __WXGTK20__ +void wxFontRefData::ReInit(const wxString& fontname) +{ + m_nativeFontInfo.SetXFontName(fontname); + + InitFromNative(); +} +#endif + void wxFontRefData::ClearGdkFonts() { +#ifndef __WXGTK20__ for ( wxScaledFontList::iterator i = m_scaled_xfonts.begin(); i != m_scaled_xfonts.end(); ++i ) @@ -426,8 +463,8 @@ void wxFontRefData::ClearGdkFonts() } m_scaled_xfonts.clear(); -} #endif // GTK 1.x +} wxFontRefData::~wxFontRefData() { @@ -522,7 +559,27 @@ void wxFontRefData::SetWeight(int weight) { m_weight = weight; -#ifndef __WXGTK20__ +#ifdef __WXGTK20__ + PangoFontDescription *desc = m_nativeFontInfo.description; + switch ( weight ) + { + case wxFONTWEIGHT_BOLD: + pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD); + break; + + case wxFONTWEIGHT_LIGHT: + pango_font_description_set_weight(desc, PANGO_WEIGHT_LIGHT); + break; + + default: + wxFAIL_MSG( _T("unknown font weight") ); + // fall through + + case wxFONTWEIGHT_NORMAL: + // unspecified + pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL); + } +#else //!__WXGTK20__ if ( HasNativeFont() ) { wxString boldness; @@ -597,10 +654,6 @@ void wxFontRefData::SetNativeFontInfo(const wxNativeFontInfo& info) InitFromNative(); } -// ============================================================================ -// wxFont implementation -// ============================================================================ - // ---------------------------------------------------------------------------- // wxFont creation // ---------------------------------------------------------------------------- @@ -624,7 +677,7 @@ wxFont::wxFont(const wxNativeFontInfo& info) info.GetFaceName(), info.GetEncoding() ); #else - Create(info.GetXFontName()); + (void) Create(info.GetXFontName()); #endif } @@ -636,6 +689,8 @@ bool wxFont::Create( int pointSize, const wxString& face, wxFontEncoding encoding) { + UnRef(); + m_refData = new wxFontRefData(pointSize, family, style, weight, underlined, face, encoding); @@ -679,9 +734,6 @@ wxFont::~wxFont() // accessors // ---------------------------------------------------------------------------- -// all accessors are just forwarded to wxFontRefData which has everything we -// need - int wxFont::GetPointSize() const { wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); @@ -731,16 +783,23 @@ wxFontEncoding wxFont::GetEncoding() const return M_FONTDATA->m_encoding; } -wxNativeFontInfo *wxFont::GetNativeFontInfo() const +bool wxFont::GetNoAntiAliasing() +{ + wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); + + return M_FONTDATA->m_noAA; +} + +const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") ); -#ifndef __WXGTK20__ // ??? +#ifndef __WXGTK20__ if ( M_FONTDATA->m_nativeFontInfo.GetXFontName().empty() ) GetInternalFont(); #endif - return new wxNativeFontInfo(M_FONTDATA->m_nativeFontInfo); + return &(M_FONTDATA->m_nativeFontInfo); } bool wxFont::IsFixedWidth() const @@ -814,17 +873,25 @@ void wxFont::SetEncoding(wxFontEncoding encoding) M_FONTDATA->SetEncoding(encoding); } -void wxFont::SetNativeFontInfo(const wxNativeFontInfo& info) +void wxFont::DoSetNativeFontInfo( const wxNativeFontInfo& info ) +{ + Unshare(); + + M_FONTDATA->SetNativeFontInfo( info ); +} + +void wxFont::SetNoAntiAliasing( bool no ) { Unshare(); - M_FONTDATA->SetNativeFontInfo(info); + M_FONTDATA->SetNoAntiAliasing( no ); } // ---------------------------------------------------------------------------- // get internal representation of font // ---------------------------------------------------------------------------- +#ifndef __WXGTK20__ static GdkFont *g_systemDefaultGuiFont = (GdkFont*) NULL; // this is also used from tbargtk.cpp and tooltip.cpp, hence extern @@ -836,13 +903,13 @@ extern GdkFont *GtkGetDefaultGuiFont() GtkStyle *def = gtk_rc_get_style( widget ); if (def) { - g_systemDefaultGuiFont = gdk_font_ref( GET_STYLE_FONT(def) ); + g_systemDefaultGuiFont = gdk_font_ref( def->font ); } else { def = gtk_widget_get_default_style(); if (def) - g_systemDefaultGuiFont = gdk_font_ref( GET_STYLE_FONT(def) ); + g_systemDefaultGuiFont = gdk_font_ref( def->font ); } gtk_widget_destroy( widget ); } @@ -861,19 +928,6 @@ GdkFont *wxFont::GetInternalFont( float scale ) const wxCHECK_MSG( Ok(), font, wxT("invalid font") ) -#ifdef __WXGTK20__ - if (*this == wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT)) - { - font = GtkGetDefaultGuiFont(); - } - else - { - PangoFontDescription * - font_description = GetNativeFontInfo()->description; - - font = gdk_font_from_description( font_description ); - } -#else // GTK 1.x long int_scale = long(scale * 100.0 + 0.5); // key for fontlist int point_scale = (int)((M_FONTDATA->m_pointSize * 10 * int_scale) / 100); @@ -912,7 +966,7 @@ GdkFont *wxFont::GetInternalFont( float scale ) const &xfontname); if ( font ) { - M_FONTDATA->m_nativeFontInfo.SetXFontName(xfontname); + M_FONTDATA->ReInit(xfontname); } } } @@ -922,7 +976,6 @@ GdkFont *wxFont::GetInternalFont( float scale ) const list[int_scale] = font; } } -#endif // GTK 2.0/1.x // it's quite useless to make it a wxCHECK because we're going to crash // anyhow... @@ -930,4 +983,5 @@ GdkFont *wxFont::GetInternalFont( float scale ) const return font; } +#endif // not GTK 2.0