Lots of work to set PangoFontDescription as the

native font info data. WIP.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16379 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2002-08-06 16:41:31 +00:00
parent b720b24da8
commit db16cab461
11 changed files with 514 additions and 27 deletions

View File

@@ -1785,7 +1785,7 @@ enum wxPrintMode
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// define this macro if font handling is done using the X font names // define this macro if font handling is done using the X font names
#if defined(__WXGTK__) || defined(__X__) #if (defined(__WXGTK__) && !defined(__WXGTK20__)) || defined(__X__)
#define _WX_X_FONTLIKE #define _WX_X_FONTLIKE
#endif #endif

View File

@@ -113,6 +113,9 @@ struct WXDLLEXPORT wxNativeEncodingInfo
#elif defined(_WX_X_FONTLIKE) #elif defined(_WX_X_FONTLIKE)
wxString xregistry, wxString xregistry,
xencoding; xencoding;
#elif defined(__WXGTK20__)
// No way to specify this in Pango as this
// seems to be handled internally.
#elif defined(__WXMGL__) #elif defined(__WXMGL__)
int mglEncoding; int mglEncoding;
#else #else

View File

@@ -113,6 +113,8 @@ public:
FATTRS fa; FATTRS fa;
FONTMETRICS fm; FONTMETRICS fm;
FACENAMEDESC fn; FACENAMEDESC fn;
#elif defined(__WXGTK20__)
PangoFontDescription *description;
#else // other platforms #else // other platforms
// //
// This is a generic implementation that should work on all ports // This is a generic implementation that should work on all ports

View File

@@ -20,6 +20,7 @@
#include "wx/image.h" #include "wx/image.h"
#include "wx/module.h" #include "wx/module.h"
#include "wx/log.h" #include "wx/log.h"
#include "wx/fontutil.h"
#include "wx/gtk/win_gtk.h" #include "wx/gtk/win_gtk.h"
@@ -1656,7 +1657,7 @@ void wxWindowDC::SetFont( const wxFont &font )
m_font = font; m_font = font;
#ifdef __WXGTK20__ #ifdef __WXGTK20__
// fix fontdesc? m_fontdesc = m_font.GetNativeFontInfo()->description;
#endif #endif
} }

View File

@@ -78,7 +78,11 @@ public:
// do we have the native font info? // do we have the native font info?
bool HasNativeFont() const bool HasNativeFont() const
{ {
#ifdef __WXGTK20__
return TRUE; // ?
#else
return !m_nativeFontInfo.IsDefault(); return !m_nativeFontInfo.IsDefault();
#endif
} }
// setters: all of them also take care to modify m_nativeFontInfo if we // setters: all of them also take care to modify m_nativeFontInfo if we
@@ -95,7 +99,7 @@ public:
// //
// VZ: I need this as my gdb either shows wildly wrong values or crashes // VZ: I need this as my gdb either shows wildly wrong values or crashes
// when I ask it to "p fontRefData" :-( // when I ask it to "p fontRefData" :-(
#ifdef __WXDEBUG__ #if defined(__WXDEBUG__) && !defined(__WXGTK20__)
void Dump() const void Dump() const
{ {
wxPrintf(_T("%s-%s-%s-%d-%d\n"), wxPrintf(_T("%s-%s-%s-%d-%d\n"),
@@ -122,8 +126,10 @@ protected:
wxFontEncoding encoding); wxFontEncoding encoding);
private: private:
#ifndef __WXGTK20__
// the map of font sizes to "GdkFont *" // the map of font sizes to "GdkFont *"
wxScaledFontList m_scaled_xfonts; wxScaledFontList m_scaled_xfonts;
#endif
// the broken down font parameters // the broken down font parameters
int m_pointSize; int m_pointSize;
@@ -132,9 +138,10 @@ private:
m_weight; m_weight;
bool m_underlined; bool m_underlined;
wxString m_faceName; wxString m_faceName;
wxFontEncoding m_encoding; wxFontEncoding m_encoding; // Unused under GTK 2.0
// the native font info, basicly an XFLD // The native font info, basicly an XFLD under GTK 1.2 and
// the pango font description under GTK 2.0.
wxNativeFontInfo m_nativeFontInfo; wxNativeFontInfo m_nativeFontInfo;
friend class wxFont; friend class wxFont;
@@ -199,6 +206,71 @@ wxFontRefData::wxFontRefData(int size, int family, int style,
wxFontRefData::wxFontRefData(const wxString& fontname) wxFontRefData::wxFontRefData(const wxString& fontname)
{ {
#ifdef __WXGTK20__
m_nativeFontInfo.FromString( fontname );
// Get native info
PangoFontDescription *desc = m_nativeFontInfo.description;
// init fields
m_faceName = wxGTK_CONV_BACK( pango_font_description_get_family( desc ) );
m_pointSize = pango_font_description_get_size( desc ) / PANGO_SCALE;
switch (pango_font_description_get_style( desc ))
{
case PANGO_STYLE_NORMAL:
m_style = wxFONTSTYLE_NORMAL;
break;
case PANGO_STYLE_ITALIC:
m_style = wxFONTSTYLE_ITALIC;
break;
case PANGO_STYLE_OBLIQUE:
m_style = wxFONTSTYLE_SLANT;
break;
}
switch (pango_font_description_get_weight( desc ))
{
case PANGO_WEIGHT_ULTRALIGHT:
m_weight = wxFONTWEIGHT_LIGHT;
break;
case PANGO_WEIGHT_LIGHT:
m_weight = wxFONTWEIGHT_LIGHT;
break;
case PANGO_WEIGHT_NORMAL:
m_weight = wxFONTWEIGHT_NORMAL;
break;
case PANGO_WEIGHT_BOLD:
m_weight = wxFONTWEIGHT_BOLD;
break;
case PANGO_WEIGHT_ULTRABOLD:
m_weight = wxFONTWEIGHT_BOLD;
break;
case PANGO_WEIGHT_HEAVY:
m_weight = wxFONTWEIGHT_BOLD;
break;
}
if (m_faceName == wxT("monospaced"))
{
m_family = wxFONTFAMILY_TELETYPE;
}
else if (m_faceName == wxT("sans"))
{
m_family = wxFONTFAMILY_SWISS;
}
else
{
m_family = wxFONTFAMILY_UNKNOWN;
}
// Pango description are never underlined (?)
m_underlined = FALSE;
// Cannot we choose that
m_encoding = wxFONTENCODING_SYSTEM;
#else
// remember the X font name // remember the X font name
m_nativeFontInfo.SetXFontName(fontname); m_nativeFontInfo.SetXFontName(fontname);
@@ -299,10 +371,12 @@ wxFontRefData::wxFontRefData(const wxString& fontname)
// may be give a warning here? // may be give a warning here?
m_encoding = wxFONTENCODING_SYSTEM; m_encoding = wxFONTENCODING_SYSTEM;
} }
#endif
} }
wxFontRefData::~wxFontRefData() wxFontRefData::~wxFontRefData()
{ {
#ifndef __WXGTK20__
wxNode *node = m_scaled_xfonts.First(); wxNode *node = m_scaled_xfonts.First();
while (node) while (node)
{ {
@@ -311,6 +385,7 @@ wxFontRefData::~wxFontRefData()
gdk_font_unref( font ); gdk_font_unref( font );
node = next; node = next;
} }
#endif
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -321,6 +396,12 @@ void wxFontRefData::SetPointSize(int pointSize)
{ {
m_pointSize = pointSize; m_pointSize = pointSize;
#ifdef __WXGTK20__
// Get native info
PangoFontDescription *desc = m_nativeFontInfo.description;
pango_font_description_set_size( desc, m_pointSize * PANGO_SCALE );
#else
if ( HasNativeFont() ) if ( HasNativeFont() )
{ {
wxString size; wxString size;
@@ -331,6 +412,7 @@ void wxFontRefData::SetPointSize(int pointSize)
m_nativeFontInfo.SetXFontComponent(wxXLFD_POINTSIZE, size); m_nativeFontInfo.SetXFontComponent(wxXLFD_POINTSIZE, size);
} }
#endif
} }
void wxFontRefData::SetFamily(int family) void wxFontRefData::SetFamily(int family)
@@ -344,6 +426,26 @@ void wxFontRefData::SetStyle(int style)
{ {
m_style = style; m_style = style;
#ifdef __WXGTK20__
// Get native info
PangoFontDescription *desc = m_nativeFontInfo.description;
switch ( style )
{
case wxFONTSTYLE_ITALIC:
pango_font_description_set_style( desc, PANGO_STYLE_ITALIC );
break;
case wxFONTSTYLE_SLANT:
pango_font_description_set_style( desc, PANGO_STYLE_OBLIQUE );
break;
default:
wxFAIL_MSG( _T("unknown font style") );
// fall through
case wxFONTSTYLE_NORMAL:
pango_font_description_set_style( desc, PANGO_STYLE_NORMAL );
break;
}
#else
if ( HasNativeFont() ) if ( HasNativeFont() )
{ {
wxString slant; wxString slant;
@@ -367,12 +469,14 @@ void wxFontRefData::SetStyle(int style)
m_nativeFontInfo.SetXFontComponent(wxXLFD_SLANT, slant); m_nativeFontInfo.SetXFontComponent(wxXLFD_SLANT, slant);
} }
#endif
} }
void wxFontRefData::SetWeight(int weight) void wxFontRefData::SetWeight(int weight)
{ {
m_weight = weight; m_weight = weight;
#ifndef __WXGTK20__
if ( HasNativeFont() ) if ( HasNativeFont() )
{ {
wxString boldness; wxString boldness;
@@ -397,6 +501,7 @@ void wxFontRefData::SetWeight(int weight)
m_nativeFontInfo.SetXFontComponent(wxXLFD_WEIGHT, boldness); m_nativeFontInfo.SetXFontComponent(wxXLFD_WEIGHT, boldness);
} }
#endif
} }
void wxFontRefData::SetUnderlined(bool underlined) void wxFontRefData::SetUnderlined(bool underlined)
@@ -410,16 +515,19 @@ void wxFontRefData::SetFaceName(const wxString& facename)
{ {
m_faceName = facename; m_faceName = facename;
#ifndef __WXGTK20__
if ( HasNativeFont() ) if ( HasNativeFont() )
{ {
m_nativeFontInfo.SetXFontComponent(wxXLFD_FAMILY, facename); m_nativeFontInfo.SetXFontComponent(wxXLFD_FAMILY, facename);
} }
#endif
} }
void wxFontRefData::SetEncoding(wxFontEncoding encoding) void wxFontRefData::SetEncoding(wxFontEncoding encoding)
{ {
m_encoding = encoding; m_encoding = encoding;
#ifndef __WXGTK20__
if ( HasNativeFont() ) if ( HasNativeFont() )
{ {
wxNativeEncodingInfo info; wxNativeEncodingInfo info;
@@ -429,6 +537,7 @@ void wxFontRefData::SetEncoding(wxFontEncoding encoding)
m_nativeFontInfo.SetXFontComponent(wxXLFD_ENCODING, info.xencoding); m_nativeFontInfo.SetXFontComponent(wxXLFD_ENCODING, info.xencoding);
} }
} }
#endif
} }
// ============================================================================ // ============================================================================
@@ -449,7 +558,17 @@ wxFont::wxFont(const wxNativeFontInfo& info)
{ {
Init(); Init();
#ifdef __WXGTK20__
Create( info.GetPointSize(),
info.GetFamily(),
info.GetStyle(),
info.GetWeight(),
info.GetUnderlined(),
info.GetFaceName(),
info.GetEncoding() );
#else
Create(info.GetXFontName()); Create(info.GetXFontName());
#endif
} }
bool wxFont::Create( int pointSize, bool wxFont::Create( int pointSize,
@@ -559,8 +678,10 @@ wxNativeFontInfo *wxFont::GetNativeFontInfo() const
{ {
wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") ); wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") );
#ifndef __WXGTK20__ // ???
if ( M_FONTDATA->m_nativeFontInfo.GetXFontName().empty() ) if ( M_FONTDATA->m_nativeFontInfo.GetXFontName().empty() )
GetInternalFont(); GetInternalFont();
#endif
return new wxNativeFontInfo(M_FONTDATA->m_nativeFontInfo); return new wxNativeFontInfo(M_FONTDATA->m_nativeFontInfo);
} }
@@ -569,6 +690,7 @@ bool wxFont::IsFixedWidth() const
{ {
wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") ); wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
#ifndef __WXGTK20__
if ( M_FONTDATA->HasNativeFont() ) if ( M_FONTDATA->HasNativeFont() )
{ {
// the monospace fonts are supposed to have "M" in the spacing field // the monospace fonts are supposed to have "M" in the spacing field
@@ -577,6 +699,7 @@ bool wxFont::IsFixedWidth() const
return spacing.Upper() == _T('M'); return spacing.Upper() == _T('M');
} }
#endif
return wxFontBase::IsFixedWidth(); return wxFontBase::IsFixedWidth();
} }
@@ -588,7 +711,7 @@ bool wxFont::IsFixedWidth() const
void wxFont::SetPointSize(int pointSize) void wxFont::SetPointSize(int pointSize)
{ {
Unshare(); Unshare();
M_FONTDATA->SetPointSize(pointSize); M_FONTDATA->SetPointSize(pointSize);
} }
@@ -681,7 +804,19 @@ GdkFont *wxFont::GetInternalFont( float scale ) const
wxCHECK_MSG( Ok(), font, wxT("invalid font") ) wxCHECK_MSG( Ok(), font, wxT("invalid font") )
long int_scale = long(scale * 100.0 + 0.5); /* key for fontlist */ #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
long int_scale = long(scale * 100.0 + 0.5); // key for fontlist
int point_scale = (int)((M_FONTDATA->m_pointSize * 10 * int_scale) / 100); int point_scale = (int)((M_FONTDATA->m_pointSize * 10 * int_scale) / 100);
wxNode *node = M_FONTDATA->m_scaled_xfonts.Find(int_scale); wxNode *node = M_FONTDATA->m_scaled_xfonts.Find(int_scale);
@@ -728,6 +863,7 @@ GdkFont *wxFont::GetInternalFont( float scale ) const
M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font ); M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font );
} }
} }
#endif // GTK 2.0
// it's quite useless to make it a wxCHECK because we're going to crash // it's quite useless to make it a wxCHECK because we're going to crash
// anyhow... // anyhow...

View File

@@ -74,6 +74,8 @@ void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dial
} }
gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg); gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
// printf( "font %s\n", fontname );
dialog->SetChosenFont(fontname); dialog->SetChosenFont(fontname);
@@ -145,6 +147,7 @@ bool wxFontDialog::DoCreate(wxWindow *parent)
gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this ); GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
#ifndef __WXGTK20__
wxFont font = m_fontData.GetInitialFont(); wxFont font = m_fontData.GetInitialFont();
if( font.Ok() ) if( font.Ok() )
{ {
@@ -167,6 +170,7 @@ bool wxFontDialog::DoCreate(wxWindow *parent)
wxFAIL_MSG(_T("font is ok but no native font info?")); wxFAIL_MSG(_T("font is ok but no native font info?"));
} }
} }
#endif
return TRUE; return TRUE;
} }

View File

@@ -20,6 +20,7 @@
#include "wx/image.h" #include "wx/image.h"
#include "wx/module.h" #include "wx/module.h"
#include "wx/log.h" #include "wx/log.h"
#include "wx/fontutil.h"
#include "wx/gtk/win_gtk.h" #include "wx/gtk/win_gtk.h"
@@ -1656,7 +1657,7 @@ void wxWindowDC::SetFont( const wxFont &font )
m_font = font; m_font = font;
#ifdef __WXGTK20__ #ifdef __WXGTK20__
// fix fontdesc? m_fontdesc = m_font.GetNativeFontInfo()->description;
#endif #endif
} }

View File

@@ -78,7 +78,11 @@ public:
// do we have the native font info? // do we have the native font info?
bool HasNativeFont() const bool HasNativeFont() const
{ {
#ifdef __WXGTK20__
return TRUE; // ?
#else
return !m_nativeFontInfo.IsDefault(); return !m_nativeFontInfo.IsDefault();
#endif
} }
// setters: all of them also take care to modify m_nativeFontInfo if we // setters: all of them also take care to modify m_nativeFontInfo if we
@@ -95,7 +99,7 @@ public:
// //
// VZ: I need this as my gdb either shows wildly wrong values or crashes // VZ: I need this as my gdb either shows wildly wrong values or crashes
// when I ask it to "p fontRefData" :-( // when I ask it to "p fontRefData" :-(
#ifdef __WXDEBUG__ #if defined(__WXDEBUG__) && !defined(__WXGTK20__)
void Dump() const void Dump() const
{ {
wxPrintf(_T("%s-%s-%s-%d-%d\n"), wxPrintf(_T("%s-%s-%s-%d-%d\n"),
@@ -122,8 +126,10 @@ protected:
wxFontEncoding encoding); wxFontEncoding encoding);
private: private:
#ifndef __WXGTK20__
// the map of font sizes to "GdkFont *" // the map of font sizes to "GdkFont *"
wxScaledFontList m_scaled_xfonts; wxScaledFontList m_scaled_xfonts;
#endif
// the broken down font parameters // the broken down font parameters
int m_pointSize; int m_pointSize;
@@ -132,9 +138,10 @@ private:
m_weight; m_weight;
bool m_underlined; bool m_underlined;
wxString m_faceName; wxString m_faceName;
wxFontEncoding m_encoding; wxFontEncoding m_encoding; // Unused under GTK 2.0
// the native font info, basicly an XFLD // The native font info, basicly an XFLD under GTK 1.2 and
// the pango font description under GTK 2.0.
wxNativeFontInfo m_nativeFontInfo; wxNativeFontInfo m_nativeFontInfo;
friend class wxFont; friend class wxFont;
@@ -199,6 +206,71 @@ wxFontRefData::wxFontRefData(int size, int family, int style,
wxFontRefData::wxFontRefData(const wxString& fontname) wxFontRefData::wxFontRefData(const wxString& fontname)
{ {
#ifdef __WXGTK20__
m_nativeFontInfo.FromString( fontname );
// Get native info
PangoFontDescription *desc = m_nativeFontInfo.description;
// init fields
m_faceName = wxGTK_CONV_BACK( pango_font_description_get_family( desc ) );
m_pointSize = pango_font_description_get_size( desc ) / PANGO_SCALE;
switch (pango_font_description_get_style( desc ))
{
case PANGO_STYLE_NORMAL:
m_style = wxFONTSTYLE_NORMAL;
break;
case PANGO_STYLE_ITALIC:
m_style = wxFONTSTYLE_ITALIC;
break;
case PANGO_STYLE_OBLIQUE:
m_style = wxFONTSTYLE_SLANT;
break;
}
switch (pango_font_description_get_weight( desc ))
{
case PANGO_WEIGHT_ULTRALIGHT:
m_weight = wxFONTWEIGHT_LIGHT;
break;
case PANGO_WEIGHT_LIGHT:
m_weight = wxFONTWEIGHT_LIGHT;
break;
case PANGO_WEIGHT_NORMAL:
m_weight = wxFONTWEIGHT_NORMAL;
break;
case PANGO_WEIGHT_BOLD:
m_weight = wxFONTWEIGHT_BOLD;
break;
case PANGO_WEIGHT_ULTRABOLD:
m_weight = wxFONTWEIGHT_BOLD;
break;
case PANGO_WEIGHT_HEAVY:
m_weight = wxFONTWEIGHT_BOLD;
break;
}
if (m_faceName == wxT("monospaced"))
{
m_family = wxFONTFAMILY_TELETYPE;
}
else if (m_faceName == wxT("sans"))
{
m_family = wxFONTFAMILY_SWISS;
}
else
{
m_family = wxFONTFAMILY_UNKNOWN;
}
// Pango description are never underlined (?)
m_underlined = FALSE;
// Cannot we choose that
m_encoding = wxFONTENCODING_SYSTEM;
#else
// remember the X font name // remember the X font name
m_nativeFontInfo.SetXFontName(fontname); m_nativeFontInfo.SetXFontName(fontname);
@@ -299,10 +371,12 @@ wxFontRefData::wxFontRefData(const wxString& fontname)
// may be give a warning here? // may be give a warning here?
m_encoding = wxFONTENCODING_SYSTEM; m_encoding = wxFONTENCODING_SYSTEM;
} }
#endif
} }
wxFontRefData::~wxFontRefData() wxFontRefData::~wxFontRefData()
{ {
#ifndef __WXGTK20__
wxNode *node = m_scaled_xfonts.First(); wxNode *node = m_scaled_xfonts.First();
while (node) while (node)
{ {
@@ -311,6 +385,7 @@ wxFontRefData::~wxFontRefData()
gdk_font_unref( font ); gdk_font_unref( font );
node = next; node = next;
} }
#endif
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -321,6 +396,12 @@ void wxFontRefData::SetPointSize(int pointSize)
{ {
m_pointSize = pointSize; m_pointSize = pointSize;
#ifdef __WXGTK20__
// Get native info
PangoFontDescription *desc = m_nativeFontInfo.description;
pango_font_description_set_size( desc, m_pointSize * PANGO_SCALE );
#else
if ( HasNativeFont() ) if ( HasNativeFont() )
{ {
wxString size; wxString size;
@@ -331,6 +412,7 @@ void wxFontRefData::SetPointSize(int pointSize)
m_nativeFontInfo.SetXFontComponent(wxXLFD_POINTSIZE, size); m_nativeFontInfo.SetXFontComponent(wxXLFD_POINTSIZE, size);
} }
#endif
} }
void wxFontRefData::SetFamily(int family) void wxFontRefData::SetFamily(int family)
@@ -344,6 +426,26 @@ void wxFontRefData::SetStyle(int style)
{ {
m_style = style; m_style = style;
#ifdef __WXGTK20__
// Get native info
PangoFontDescription *desc = m_nativeFontInfo.description;
switch ( style )
{
case wxFONTSTYLE_ITALIC:
pango_font_description_set_style( desc, PANGO_STYLE_ITALIC );
break;
case wxFONTSTYLE_SLANT:
pango_font_description_set_style( desc, PANGO_STYLE_OBLIQUE );
break;
default:
wxFAIL_MSG( _T("unknown font style") );
// fall through
case wxFONTSTYLE_NORMAL:
pango_font_description_set_style( desc, PANGO_STYLE_NORMAL );
break;
}
#else
if ( HasNativeFont() ) if ( HasNativeFont() )
{ {
wxString slant; wxString slant;
@@ -367,12 +469,14 @@ void wxFontRefData::SetStyle(int style)
m_nativeFontInfo.SetXFontComponent(wxXLFD_SLANT, slant); m_nativeFontInfo.SetXFontComponent(wxXLFD_SLANT, slant);
} }
#endif
} }
void wxFontRefData::SetWeight(int weight) void wxFontRefData::SetWeight(int weight)
{ {
m_weight = weight; m_weight = weight;
#ifndef __WXGTK20__
if ( HasNativeFont() ) if ( HasNativeFont() )
{ {
wxString boldness; wxString boldness;
@@ -397,6 +501,7 @@ void wxFontRefData::SetWeight(int weight)
m_nativeFontInfo.SetXFontComponent(wxXLFD_WEIGHT, boldness); m_nativeFontInfo.SetXFontComponent(wxXLFD_WEIGHT, boldness);
} }
#endif
} }
void wxFontRefData::SetUnderlined(bool underlined) void wxFontRefData::SetUnderlined(bool underlined)
@@ -410,16 +515,19 @@ void wxFontRefData::SetFaceName(const wxString& facename)
{ {
m_faceName = facename; m_faceName = facename;
#ifndef __WXGTK20__
if ( HasNativeFont() ) if ( HasNativeFont() )
{ {
m_nativeFontInfo.SetXFontComponent(wxXLFD_FAMILY, facename); m_nativeFontInfo.SetXFontComponent(wxXLFD_FAMILY, facename);
} }
#endif
} }
void wxFontRefData::SetEncoding(wxFontEncoding encoding) void wxFontRefData::SetEncoding(wxFontEncoding encoding)
{ {
m_encoding = encoding; m_encoding = encoding;
#ifndef __WXGTK20__
if ( HasNativeFont() ) if ( HasNativeFont() )
{ {
wxNativeEncodingInfo info; wxNativeEncodingInfo info;
@@ -429,6 +537,7 @@ void wxFontRefData::SetEncoding(wxFontEncoding encoding)
m_nativeFontInfo.SetXFontComponent(wxXLFD_ENCODING, info.xencoding); m_nativeFontInfo.SetXFontComponent(wxXLFD_ENCODING, info.xencoding);
} }
} }
#endif
} }
// ============================================================================ // ============================================================================
@@ -449,7 +558,17 @@ wxFont::wxFont(const wxNativeFontInfo& info)
{ {
Init(); Init();
#ifdef __WXGTK20__
Create( info.GetPointSize(),
info.GetFamily(),
info.GetStyle(),
info.GetWeight(),
info.GetUnderlined(),
info.GetFaceName(),
info.GetEncoding() );
#else
Create(info.GetXFontName()); Create(info.GetXFontName());
#endif
} }
bool wxFont::Create( int pointSize, bool wxFont::Create( int pointSize,
@@ -559,8 +678,10 @@ wxNativeFontInfo *wxFont::GetNativeFontInfo() const
{ {
wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") ); wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") );
#ifndef __WXGTK20__ // ???
if ( M_FONTDATA->m_nativeFontInfo.GetXFontName().empty() ) if ( M_FONTDATA->m_nativeFontInfo.GetXFontName().empty() )
GetInternalFont(); GetInternalFont();
#endif
return new wxNativeFontInfo(M_FONTDATA->m_nativeFontInfo); return new wxNativeFontInfo(M_FONTDATA->m_nativeFontInfo);
} }
@@ -569,6 +690,7 @@ bool wxFont::IsFixedWidth() const
{ {
wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") ); wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
#ifndef __WXGTK20__
if ( M_FONTDATA->HasNativeFont() ) if ( M_FONTDATA->HasNativeFont() )
{ {
// the monospace fonts are supposed to have "M" in the spacing field // the monospace fonts are supposed to have "M" in the spacing field
@@ -577,6 +699,7 @@ bool wxFont::IsFixedWidth() const
return spacing.Upper() == _T('M'); return spacing.Upper() == _T('M');
} }
#endif
return wxFontBase::IsFixedWidth(); return wxFontBase::IsFixedWidth();
} }
@@ -588,7 +711,7 @@ bool wxFont::IsFixedWidth() const
void wxFont::SetPointSize(int pointSize) void wxFont::SetPointSize(int pointSize)
{ {
Unshare(); Unshare();
M_FONTDATA->SetPointSize(pointSize); M_FONTDATA->SetPointSize(pointSize);
} }
@@ -681,7 +804,19 @@ GdkFont *wxFont::GetInternalFont( float scale ) const
wxCHECK_MSG( Ok(), font, wxT("invalid font") ) wxCHECK_MSG( Ok(), font, wxT("invalid font") )
long int_scale = long(scale * 100.0 + 0.5); /* key for fontlist */ #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
long int_scale = long(scale * 100.0 + 0.5); // key for fontlist
int point_scale = (int)((M_FONTDATA->m_pointSize * 10 * int_scale) / 100); int point_scale = (int)((M_FONTDATA->m_pointSize * 10 * int_scale) / 100);
wxNode *node = M_FONTDATA->m_scaled_xfonts.Find(int_scale); wxNode *node = M_FONTDATA->m_scaled_xfonts.Find(int_scale);
@@ -728,6 +863,7 @@ GdkFont *wxFont::GetInternalFont( float scale ) const
M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font ); M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font );
} }
} }
#endif // GTK 2.0
// it's quite useless to make it a wxCHECK because we're going to crash // it's quite useless to make it a wxCHECK because we're going to crash
// anyhow... // anyhow...

View File

@@ -74,6 +74,8 @@ void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dial
} }
gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg); gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
// printf( "font %s\n", fontname );
dialog->SetChosenFont(fontname); dialog->SetChosenFont(fontname);
@@ -145,6 +147,7 @@ bool wxFontDialog::DoCreate(wxWindow *parent)
gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this ); GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
#ifndef __WXGTK20__
wxFont font = m_fontData.GetInitialFont(); wxFont font = m_fontData.GetInitialFont();
if( font.Ok() ) if( font.Ok() )
{ {
@@ -167,6 +170,7 @@ bool wxFontDialog::DoCreate(wxWindow *parent)
wxFAIL_MSG(_T("font is ok but no native font info?")); wxFAIL_MSG(_T("font is ok but no native font info?"));
} }
} }
#endif
return TRUE; return TRUE;
} }

View File

@@ -31,6 +31,63 @@
#include "wx/fontenum.h" #include "wx/fontenum.h"
#include "wx/fontutil.h" #include "wx/fontutil.h"
// ----------------------------------------------------------------------------
// GTK 2.0
// ----------------------------------------------------------------------------
#ifdef __WXGTK20__
#include "wx/gtk/private.h"
extern GtkWidget *wxGetRootWindow();
static int
cmp_families (const void *a, const void *b)
{
const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
return g_utf8_collate (a_name, b_name);
}
// I admit I don't yet understand encodings with Pango
bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
bool fixedWidthOnly)
{
if ( fixedWidthOnly )
{
OnFacename( wxT("monospaced") );
}
else
{
PangoFontFamily **families = NULL;
gint n_families = 0;
pango_context_list_families (
gtk_widget_get_pango_context( wxGetRootWindow() ),
&families, &n_families );
qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
for (int i=0; i<n_families; i++)
{
const gchar *name = pango_font_family_get_name( families[i] );
wxString tmp( name, wxConvUTF8 );
OnFacename( tmp );
}
}
return TRUE;
}
bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
{
return FALSE;
}
#else
// GTK 2.0
#ifdef __VMS__ // Xlib.h for VMS is not (yet) compatible with C++ #ifdef __VMS__ // Xlib.h for VMS is not (yet) compatible with C++
// The resulting warnings are switched off here // The resulting warnings are switched off here
#pragma message disable nosimpint #pragma message disable nosimpint
@@ -107,12 +164,7 @@ static bool ProcessFamiliesFromFontList(wxFontEnumerator *This,
{ {
char *font = fonts[n]; char *font = fonts[n];
#if wxUSE_REGEX #if wxUSE_REGEX
#if wxUSE_UNICODE
wxString sfont( wxConvLocal.cMB2WC( font ) );
if ( !re.Matches(sfont) )
#else
if ( !re.Matches(font) ) if ( !re.Matches(font) )
#endif
#else // !wxUSE_REGEX #else // !wxUSE_REGEX
if ( !wxString(font).Matches(wxT("-*-*-*-*-*-*-*-*-*-*-*-*-*-*")) ) if ( !wxString(font).Matches(wxT("-*-*-*-*-*-*-*-*-*-*-*-*-*-*")) )
#endif // wxUSE_REGEX/!wxUSE_REGEX #endif // wxUSE_REGEX/!wxUSE_REGEX
@@ -125,11 +177,7 @@ static bool ProcessFamiliesFromFontList(wxFontEnumerator *This,
char *family = dash + 1; char *family = dash + 1;
dash = strchr(family, '-'); dash = strchr(family, '-');
*dash = '\0'; // !NULL because Matches() above succeeded *dash = '\0'; // !NULL because Matches() above succeeded
#if wxUSE_UNICODE
wxString fam( wxConvLocal.cMB2WC( family ) );
#else
wxString fam(family); wxString fam(family);
#endif
if ( families.Index(fam) == wxNOT_FOUND ) if ( families.Index(fam) == wxNOT_FOUND )
{ {
@@ -279,3 +327,6 @@ bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
#endif #endif
// wxUSE_NANOX // wxUSE_NANOX
} }
#endif
// __WXGTK20__

View File

@@ -31,6 +31,156 @@
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#endif // PCH #endif // PCH
#include "wx/fontutil.h"
#include "wx/fontmap.h"
#include "wx/tokenzr.h"
#include "wx/hash.h"
#include "wx/module.h"
#ifdef __WXGTK20__
#include "wx/gtk/private.h"
// ----------------------------------------------------------------------------
// wxNativeFontInfo
// ----------------------------------------------------------------------------
void wxNativeFontInfo::Init()
{
description = NULL;
}
int wxNativeFontInfo::GetPointSize() const
{
return pango_font_description_get_size( description ) / PANGO_SCALE;
}
wxFontStyle wxNativeFontInfo::GetStyle() const
{
wxFontStyle m_style = wxFONTSTYLE_NORMAL;
switch (pango_font_description_get_style( description ))
{
case PANGO_STYLE_NORMAL:
m_style = wxFONTSTYLE_NORMAL;
break;
case PANGO_STYLE_ITALIC:
m_style = wxFONTSTYLE_ITALIC;
break;
case PANGO_STYLE_OBLIQUE:
m_style = wxFONTSTYLE_SLANT;
break;
}
return m_style;
}
wxFontWeight wxNativeFontInfo::GetWeight() const
{
wxFontWeight m_weight = wxFONTWEIGHT_NORMAL;
switch (pango_font_description_get_weight( description ))
{
case PANGO_WEIGHT_ULTRALIGHT:
m_weight = wxFONTWEIGHT_LIGHT;
break;
case PANGO_WEIGHT_LIGHT:
m_weight = wxFONTWEIGHT_LIGHT;
break;
case PANGO_WEIGHT_NORMAL:
m_weight = wxFONTWEIGHT_NORMAL;
break;
case PANGO_WEIGHT_BOLD:
m_weight = wxFONTWEIGHT_BOLD;
break;
case PANGO_WEIGHT_ULTRABOLD:
m_weight = wxFONTWEIGHT_BOLD;
break;
case PANGO_WEIGHT_HEAVY:
m_weight = wxFONTWEIGHT_BOLD;
break;
}
return m_weight;
}
bool wxNativeFontInfo::GetUnderlined() const
{
return FALSE;
}
wxString wxNativeFontInfo::GetFaceName() const
{
wxString tmp = wxGTK_CONV_BACK( pango_font_description_get_family( description ) );
return tmp;
}
wxFontFamily wxNativeFontInfo::GetFamily() const
{
return wxFONTFAMILY_SWISS;
}
wxFontEncoding wxNativeFontInfo::GetEncoding() const
{
return wxFONTENCODING_SYSTEM;
}
bool wxNativeFontInfo::FromString(const wxString& s)
{
if (description)
pango_font_description_free( description );
description = pango_font_description_from_string( wxGTK_CONV( s ) );
return TRUE;
}
wxString wxNativeFontInfo::ToString() const
{
wxString tmp = wxGTK_CONV_BACK( pango_font_description_to_string( description ) );
return tmp;
}
bool wxNativeFontInfo::FromUserString(const wxString& s)
{
return FromString( s );
}
wxString wxNativeFontInfo::ToUserString() const
{
return ToString();
}
// ----------------------------------------------------------------------------
// wxNativeEncodingInfo
// ----------------------------------------------------------------------------
bool wxNativeEncodingInfo::FromString(const wxString& s)
{
return FALSE;
}
wxString wxNativeEncodingInfo::ToString() const
{
return wxEmptyString;
}
bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
{
return TRUE;
}
bool wxGetNativeFontEncoding(wxFontEncoding encoding,
wxNativeEncodingInfo *info)
{
return FALSE;
}
#else
// __WXGTK20__
#ifdef __X__ #ifdef __X__
#ifdef __VMS__ #ifdef __VMS__
#pragma message disable nosimpint #pragma message disable nosimpint
@@ -53,11 +203,6 @@
#include <gdk/gdk.h> #include <gdk/gdk.h>
#endif #endif
#include "wx/fontutil.h"
#include "wx/fontmap.h"
#include "wx/tokenzr.h"
#include "wx/hash.h"
#include "wx/module.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// private data // private data
@@ -892,3 +1037,7 @@ void wxFontModule::OnExit()
g_fontHash = (wxHashTable *)NULL; g_fontHash = (wxHashTable *)NULL;
} }
#endif
// not GTK 2.0