wxFONTWEIGHT_MAX
};
+// ----------------------------------------------------------------------------
+// wxNativeFontInfo is platform-specific font representation
+// ----------------------------------------------------------------------------
+
+// this struct should be considered as opaque font description only used by
+// the native functions, the user code can only get the objects of this type
+// from somewhere and pass it somewhere else (possibly save them somewhere
+// using ToString() and restore them using FromString())
+struct WXDLLEXPORT wxNativeFontInfo
+{
+#if defined(__WXGTK__)
+ wxString xFontName;
+#else // other platforms
+ //
+ // This is a generic implementation that should work on all ports
+ // without specific support by the port.
+ //
+ int pointSize;
+ int family;
+ int style;
+ int weight;
+ bool underlined;
+ wxString faceName;
+ wxFontEncoding encoding;
+#endif // platforms
+
+ // it is important to be able to serialize wxNativeFontInfo objects to be
+ // able to store them (in config file, for example)
+ bool FromString(const wxString& s);
+ wxString ToString() const;
+};
+
+WXDLLEXPORT_DATA(extern wxNativeFontInfo) wxNullNativeFontInfo;
+
// ----------------------------------------------------------------------------
// wxFontBase represents a font object
// ----------------------------------------------------------------------------
bool underlined = FALSE, // not underlined by default
const wxString& face = wxEmptyString, // facename
wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ...
+ static wxFont *New(const wxNativeFontInfo& info);
// was the font successfully created?
bool Ok() const { return m_refData != NULL; }
virtual bool GetUnderlined() const = 0;
virtual wxString GetFaceName() const = 0;
virtual wxFontEncoding GetEncoding() const = 0;
+ virtual wxNativeFontInfo GetNativeFontInfo() const;
// change the font characteristics
virtual void SetPointSize( int pointSize ) = 0;
virtual void SetFaceName( const wxString& faceName ) = 0;
virtual void SetUnderlined( bool underlined ) = 0;
virtual void SetEncoding(wxFontEncoding encoding) = 0;
+ virtual void SetNativeFontInfo(const wxNativeFontInfo& info);
// translate the fonts into human-readable string (i.e. GetStyleString()
// will return "wxITALIC" for an italic font, ...)
// ctors and such
wxFont() { Init(); }
wxFont(const wxFont& font) { Init(); Ref(font); }
- wxFont(const wxString& fontname, const wxFontData& fontdata);
+ wxFont(const wxString& fontname, const wxFontData& fontdata) { Create(fontname, fontdata); }
+ wxFont(const wxNativeFontInfo& info);
// assignment
wxFont& operator=(const wxFont& font);
int weight,
bool underlined = FALSE,
const wxString& face = wxEmptyString,
- wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
+ wxFontEncoding encoding = wxFONTENCODING_DEFAULT,
+ const wxNativeFontInfo& info = wxNullNativeFontInfo);
+
+ bool Create(const wxString& fontname, const wxFontData& fontdata);
~wxFont();
virtual wxString GetFaceName() const;
virtual bool GetUnderlined() const;
virtual wxFontEncoding GetEncoding() const;
+ virtual wxNativeFontInfo GetNativeFontInfo() const;
virtual void SetPointSize( int pointSize );
virtual void SetFamily( int family );
virtual void SetFaceName( const wxString& faceName );
virtual void SetUnderlined( bool underlined );
virtual void SetEncoding(wxFontEncoding encoding);
+ virtual void SetNativeFontInfo( const wxNativeFontInfo& info );
// implementation from now on
void Unshare();
// ctors and such
wxFont() { Init(); }
wxFont(const wxFont& font) { Init(); Ref(font); }
- wxFont(const wxString& fontname, const wxFontData& fontdata);
+ wxFont(const wxString& fontname, const wxFontData& fontdata) { Create(fontname, fontdata); }
+ wxFont(const wxNativeFontInfo& info);
// assignment
wxFont& operator=(const wxFont& font);
int weight,
bool underlined = FALSE,
const wxString& face = wxEmptyString,
- wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
+ wxFontEncoding encoding = wxFONTENCODING_DEFAULT,
+ const wxNativeFontInfo& info = wxNullNativeFontInfo);
+
+ bool Create(const wxString& fontname, const wxFontData& fontdata);
~wxFont();
virtual wxString GetFaceName() const;
virtual bool GetUnderlined() const;
virtual wxFontEncoding GetEncoding() const;
+ virtual wxNativeFontInfo GetNativeFontInfo() const;
virtual void SetPointSize( int pointSize );
virtual void SetFamily( int family );
virtual void SetFaceName( const wxString& faceName );
virtual void SetUnderlined( bool underlined );
virtual void SetEncoding(wxFontEncoding encoding);
+ virtual void SetNativeFontInfo( const wxNativeFontInfo& info );
// implementation from now on
void Unshare();
(void)Create(size, family, style, weight, underlined, face, encoding);
}
+ wxFont(const wxNativeFontInfo& info)
+ {
+ Init();
+
+ (void)Create(info.pointSize, info.family, info.style, info.weight,
+ info.underlined, info.faceName, info.encoding);
+ }
+
bool Create(int size,
int family,
int style,
(void)Create(size, family, style, weight, underlined, face, encoding);
}
+ wxFont(const wxNativeFontInfo& info)
+ {
+ Init();
+
+ (void)Create(info.pointSize, info.family, info.style, info.weight,
+ info.underlined, info.faceName, info.encoding);
+ }
+
bool Create(int size,
int family,
int style,
#endif
// returns the handle of the nearest available font or 0
-extern wxNativeFont wxLoadQueryNearestFont(int pointSize,
- int family,
- int style,
- int weight,
- bool underlined,
- const wxString &facename,
- wxFontEncoding encoding);
+extern wxNativeFont
+wxLoadQueryNearestFont(int pointSize,
+ int family,
+ int style,
+ int weight,
+ bool underlined,
+ const wxString &facename,
+ wxFontEncoding encoding,
+ wxString* xFontName = (wxString *)NULL);
#endif // _WX_UNIX_FONTUTIL_H_
{ DoEnumerateFamilies(TRUE); }
void OnEnumerateEncodings(wxCommandEvent& event);
+ void OnCheckNativeToFromString(wxCommandEvent& event);
+
void OnSize(wxSizeEvent& event);
protected:
Font_EnumFamilies,
Font_EnumFixedFamilies,
Font_EnumEncodings,
- Font_Max
+ Font_CheckNativeToFromString
+ Font_Max,
};
// ----------------------------------------------------------------------------
EVT_MENU(Font_EnumFamilies, MyFrame::OnEnumerateFamilies)
EVT_MENU(Font_EnumFixedFamilies, MyFrame::OnEnumerateFixedFamilies)
EVT_MENU(Font_EnumEncodings, MyFrame::OnEnumerateEncodings)
+ EVT_MENU(Font_CheckNativeToFromString, MyFrame::OnCheckNativeToFromString)
EVT_SIZE(MyFrame::OnSize)
END_EVENT_TABLE()
menuFont->Append(Font_EnumFamiliesForEncoding,
"Find font for en&coding...\tCtrl-C",
"Find font families for given encoding");
+ menuFont->AppendSeparator();
+ menuFont->Append(Font_CheckNativeToFromString,
+ "Check Native Font Info To/From String");
// now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar;
wxFONTENCODING_CP1252,
};
- static const char *encodingNames[] =
+ static const wxString encodingNames[] =
{
"West European (Latin 1)",
"Central European (Latin 2)",
int n = wxGetSingleChoiceIndex("Choose an encoding", "Font demo",
WXSIZEOF(encodingNames),
- (char **)encodingNames,
+ encodingNames,
this);
if ( n != -1 )
}
}
+void MyFrame::OnCheckNativeToFromString(wxCommandEvent& WXUNUSED(event))
+{
+ wxString fontInfo = m_canvas->GetTextFont().GetNativeFontInfo().ToString();
+
+ if(fontInfo.IsEmpty())
+ wxMessageBox("Native font info string is empty!", "Font demo",
+ wxOK);
+ else
+ {
+ wxNativeFontInfo info;
+ info.FromString(fontInfo);
+ wxFont font(info);
+ if(fontInfo == font.GetNativeFontInfo().ToString())
+ wxMessageBox("wxNativeFontInfo ToString()/FromString() works!",
+ "Font demo", wxOK);
+ else
+ wxMessageBox("wxNativeFontInfo ToString()/FromString() doesn't work!",
+ "Font demo", wxOK);
+ }
+}
+
void MyFrame::DoResizeFont(int diff)
{
wxFont fontOld = m_canvas->GetTextFont();
dc.DrawText(fontInfo, 5, 5);
+ if(m_font.Ok())
+ {
+ dc.SetFont(wxFont(m_font.GetNativeFontInfo()));
+ fontInfo.Printf("Native font info: %s", m_font.GetNativeFontInfo().ToString().GetData());
+ dc.DrawText(fontInfo, 5, 5 + dc.GetCharHeight());
+ }
+
// prepare to draw the font
dc.SetFont(m_font);
dc.SetTextForeground(m_colour);
#include "wx/font.h"
#endif // WX_PRECOMP
+#include "wx/tokenzr.h"
+
// ============================================================================
// implementation
// ============================================================================
return new wxFont(size, family, style, weight, underlined, face, encoding);
}
+/* static */
+wxFont *wxFontBase::New(const wxNativeFontInfo& info)
+{
+ return new wxFont(info);
+}
+
+wxNativeFontInfo wxFontBase::GetNativeFontInfo() const
+{
+#if !defined(__WXGTK__)
+ wxNativeFontInfo fontInfo;
+
+ fontInfo.pointSize = GetPointSize();
+ fontInfo.family = GetFamily();
+ fontInfo.style = GetStyle();
+ fontInfo.weight = GetWeight();
+ fontInfo.underlined = GetUnderlined();
+ fontInfo.faceName = GetFaceName();
+ fontInfo.encoding = GetEncoding();
+
+ return fontInfo;
+#else
+ return wxNullNativeFontInfo;
+#endif
+}
+
+void wxFontBase::SetNativeFontInfo(const wxNativeFontInfo& info)
+{
+#if !defined(__WXGTK__)
+ SetPointSize(info.pointSize);
+ SetFamily(info.family);
+ SetStyle(info.style);
+ SetWeight(info.weight);
+ SetUnderlined(info.underlined);
+ SetFaceName(info.faceName);
+ SetEncoding(info.encoding);
+#endif
+}
+
wxFont& wxFont::operator=(const wxFont& font)
{
if ( this != &font )
}
}
+#if !defined(__WXGTK__)
+
+// ----------------------------------------------------------------------------
+// wxNativeFontInfo
+// ----------------------------------------------------------------------------
+
+// These are the generic forms of FromString()/ToString.
+//
+// convert to/from the string representation: format is
+// pointsize;family;style;weight;underlined;facename;encoding
+
+bool wxNativeFontInfo::FromString(const wxString& s)
+{
+ long l;
+
+ wxStringTokenizer tokenizer(s, _T(";"));
+
+ wxString token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return FALSE;
+ pointSize = (int)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return FALSE;
+ family = (int)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return FALSE;
+ style = (int)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return FALSE;
+ weight = (int)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return FALSE;
+ underlined = (int)l;
+
+ faceName = tokenizer.GetNextToken();
+ if( !faceName )
+ return FALSE;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return FALSE;
+ encoding = (wxFontEncoding)l;
+
+ return TRUE;
+}
+
+wxString wxNativeFontInfo::ToString() const
+{
+ wxString s;
+
+ s.Printf("%d;%d;%d;%d;%d;%s;%d",
+ pointSize,
+ family,
+ style,
+ weight,
+ underlined,
+ faceName.GetData(),
+ (int)encoding);
+
+ return s;
+}
+
+#endif
+
wxFont wxNullFont;
wxColour wxNullColour;
wxPalette wxNullPalette;
+wxNativeFontInfo wxNullNativeFontInfo;
/* Default window names */
const wxChar *wxControlNameStr = wxT("control");
int weight = wxDEFAULT,
bool underlined = FALSE,
const wxString& faceName = wxEmptyString,
- wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
+ wxFontEncoding encoding = wxFONTENCODING_DEFAULT,
+ const wxNativeFontInfo& info = wxNullNativeFontInfo);
wxFontRefData( const wxFontRefData& data );
virtual ~wxFontRefData();
int weight,
bool underlined,
const wxString& faceName,
- wxFontEncoding encoding);
+ wxFontEncoding encoding,
+ const wxNativeFontInfo& info);
private:
wxList m_scaled_xfonts;
bool m_underlined;
wxString m_faceName;
wxFontEncoding m_encoding;
+ wxNativeFontInfo m_nativeFontInfo;
friend class wxFont;
};
int weight,
bool underlined,
const wxString& faceName,
- wxFontEncoding encoding)
+ wxFontEncoding encoding,
+ const wxNativeFontInfo& info = wxNullNativeFontInfo)
{
if (family == wxDEFAULT)
m_family = wxSWISS;
m_underlined = underlined;
m_encoding = encoding;
+ m_nativeFontInfo = info;
}
wxFontRefData::wxFontRefData( const wxFontRefData& data )
: m_scaled_xfonts(wxKEY_INTEGER)
{
Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
- data.m_underlined, data.m_faceName, data.m_encoding);
+ data.m_underlined, data.m_faceName, data.m_encoding,
+ data.m_nativeFontInfo );
}
wxFontRefData::wxFontRefData(int size, int family, int style,
- int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding )
+ int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding,
+ const wxNativeFontInfo& info = wxNullNativeFontInfo)
: m_scaled_xfonts(wxKEY_INTEGER)
{
Init(size, family, style, weight,
- underlined, faceName, encoding);
+ underlined, faceName, encoding, info);
}
wxFontRefData::~wxFontRefData()
}
}
+// ----------------------------------------------------------------------------
+// wxNativeFontInfo
+// ----------------------------------------------------------------------------
+
+bool wxNativeFontInfo::FromString(const wxString& s)
+{
+ xFontName = s;
+ return TRUE;
+}
+
+wxString wxNativeFontInfo::ToString() const
+{
+ return xFontName;
+}
+
// ----------------------------------------------------------------------------
// wxFont
// ----------------------------------------------------------------------------
wxTheFontList->Append( this );
}
-wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
+wxFont::wxFont(const wxNativeFontInfo& info)
+{
+ Create(info.xFontName, wxFontData());
+}
+
+bool wxFont::Create( int pointSize,
+ int family,
+ int style,
+ int weight,
+ bool underlined,
+ const wxString& face,
+ wxFontEncoding encoding,
+ const wxNativeFontInfo& info )
+{
+ m_refData = new wxFontRefData(pointSize, family, style, weight,
+ underlined, face, encoding, info);
+
+ return TRUE;
+}
+
+bool wxFont::Create(const wxString& fontname, const wxFontData& fontdata)
{
Init();
- wxCHECK_RET( !!fontname, _T("invalid font spec") );
+ if(!fontname)
+ {
+ *this = wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT);
+ return TRUE;
+ }
m_refData = new wxFontRefData();
+ M_FONTDATA->m_nativeFontInfo.xFontName = fontname; // X font name
+
wxString tmp;
wxStringTokenizer tn( fontname, wxT("-") );
tn.GetNextToken(); // skip initial empty token
tn.GetNextToken(); // foundry
+
M_FONTDATA->m_faceName = tn.GetNextToken(); // family
tmp = tn.GetNextToken().MakeUpper(); // weight
M_FONTDATA->m_encoding = wxFONTENCODING_KOI8;
}
//else: unknown encoding - may be give a warning here?
+ else
+ return FALSE;
}
-}
-
-bool wxFont::Create( int pointSize,
- int family,
- int style,
- int weight,
- bool underlined,
- const wxString& face,
- wxFontEncoding encoding )
-{
- m_refData = new wxFontRefData(pointSize, family, style, weight,
- underlined, face, encoding);
-
return TRUE;
}
return M_FONTDATA->m_encoding;
}
+wxNativeFontInfo wxFont::GetNativeFontInfo() const
+{
+ wxCHECK_MSG( Ok(), wxNullNativeFontInfo, wxT("invalid font") );
+
+ if(M_FONTDATA->m_nativeFontInfo.xFontName.IsEmpty())
+ GetInternalFont();
+ return M_FONTDATA->m_nativeFontInfo;
+}
+
+
// ----------------------------------------------------------------------------
// change font attributes
// ----------------------------------------------------------------------------
Unshare();
M_FONTDATA->m_pointSize = pointSize;
+ M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
}
void wxFont::SetFamily(int family)
Unshare();
M_FONTDATA->m_family = family;
+ M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
}
void wxFont::SetStyle(int style)
Unshare();
M_FONTDATA->m_style = style;
+ M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
}
void wxFont::SetWeight(int weight)
Unshare();
M_FONTDATA->m_weight = weight;
+ M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
}
void wxFont::SetFaceName(const wxString& faceName)
Unshare();
M_FONTDATA->m_faceName = faceName;
+ M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
}
void wxFont::SetUnderlined(bool underlined)
Unshare();
M_FONTDATA->m_encoding = encoding;
+ M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
+}
+
+void wxFont::SetNativeFontInfo(const wxNativeFontInfo& info)
+{
+ Unshare();
+
+ M_FONTDATA->m_nativeFontInfo = info;
}
// ----------------------------------------------------------------------------
M_FONTDATA->m_weight,
M_FONTDATA->m_underlined,
M_FONTDATA->m_faceName,
- M_FONTDATA->m_encoding );
+ M_FONTDATA->m_encoding,
+ &M_FONTDATA->m_nativeFontInfo.xFontName );
}
M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font );
gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
+
+ wxFont font = m_fontData.GetInitialFont();
+ if( font.Ok() )
+ {
+ wxNativeFontInfo info = font.GetNativeFontInfo();
+
+ if( info.xFontName.IsEmpty() )
+ font.GetInternalFont();
+ gtk_font_selection_dialog_set_font_name(sel, wxConvCurrent->cWX2MB(info.xFontName.GetData()));
+ }
}
wxFontDialog::~wxFontDialog()
wxFont wxNullFont;
wxColour wxNullColour;
wxPalette wxNullPalette;
+wxNativeFontInfo wxNullNativeFontInfo;
/* Default window names */
const wxChar *wxControlNameStr = wxT("control");
int weight = wxDEFAULT,
bool underlined = FALSE,
const wxString& faceName = wxEmptyString,
- wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
+ wxFontEncoding encoding = wxFONTENCODING_DEFAULT,
+ const wxNativeFontInfo& info = wxNullNativeFontInfo);
wxFontRefData( const wxFontRefData& data );
virtual ~wxFontRefData();
int weight,
bool underlined,
const wxString& faceName,
- wxFontEncoding encoding);
+ wxFontEncoding encoding,
+ const wxNativeFontInfo& info);
private:
wxList m_scaled_xfonts;
bool m_underlined;
wxString m_faceName;
wxFontEncoding m_encoding;
+ wxNativeFontInfo m_nativeFontInfo;
friend class wxFont;
};
int weight,
bool underlined,
const wxString& faceName,
- wxFontEncoding encoding)
+ wxFontEncoding encoding,
+ const wxNativeFontInfo& info = wxNullNativeFontInfo)
{
if (family == wxDEFAULT)
m_family = wxSWISS;
m_underlined = underlined;
m_encoding = encoding;
+ m_nativeFontInfo = info;
}
wxFontRefData::wxFontRefData( const wxFontRefData& data )
: m_scaled_xfonts(wxKEY_INTEGER)
{
Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
- data.m_underlined, data.m_faceName, data.m_encoding);
+ data.m_underlined, data.m_faceName, data.m_encoding,
+ data.m_nativeFontInfo );
}
wxFontRefData::wxFontRefData(int size, int family, int style,
- int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding )
+ int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding,
+ const wxNativeFontInfo& info = wxNullNativeFontInfo)
: m_scaled_xfonts(wxKEY_INTEGER)
{
Init(size, family, style, weight,
- underlined, faceName, encoding);
+ underlined, faceName, encoding, info);
}
wxFontRefData::~wxFontRefData()
}
}
+// ----------------------------------------------------------------------------
+// wxNativeFontInfo
+// ----------------------------------------------------------------------------
+
+bool wxNativeFontInfo::FromString(const wxString& s)
+{
+ xFontName = s;
+ return TRUE;
+}
+
+wxString wxNativeFontInfo::ToString() const
+{
+ return xFontName;
+}
+
// ----------------------------------------------------------------------------
// wxFont
// ----------------------------------------------------------------------------
wxTheFontList->Append( this );
}
-wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
+wxFont::wxFont(const wxNativeFontInfo& info)
+{
+ Create(info.xFontName, wxFontData());
+}
+
+bool wxFont::Create( int pointSize,
+ int family,
+ int style,
+ int weight,
+ bool underlined,
+ const wxString& face,
+ wxFontEncoding encoding,
+ const wxNativeFontInfo& info )
+{
+ m_refData = new wxFontRefData(pointSize, family, style, weight,
+ underlined, face, encoding, info);
+
+ return TRUE;
+}
+
+bool wxFont::Create(const wxString& fontname, const wxFontData& fontdata)
{
Init();
- wxCHECK_RET( !!fontname, _T("invalid font spec") );
+ if(!fontname)
+ {
+ *this = wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT);
+ return TRUE;
+ }
m_refData = new wxFontRefData();
+ M_FONTDATA->m_nativeFontInfo.xFontName = fontname; // X font name
+
wxString tmp;
wxStringTokenizer tn( fontname, wxT("-") );
tn.GetNextToken(); // skip initial empty token
tn.GetNextToken(); // foundry
+
M_FONTDATA->m_faceName = tn.GetNextToken(); // family
tmp = tn.GetNextToken().MakeUpper(); // weight
M_FONTDATA->m_encoding = wxFONTENCODING_KOI8;
}
//else: unknown encoding - may be give a warning here?
+ else
+ return FALSE;
}
-}
-
-bool wxFont::Create( int pointSize,
- int family,
- int style,
- int weight,
- bool underlined,
- const wxString& face,
- wxFontEncoding encoding )
-{
- m_refData = new wxFontRefData(pointSize, family, style, weight,
- underlined, face, encoding);
-
return TRUE;
}
return M_FONTDATA->m_encoding;
}
+wxNativeFontInfo wxFont::GetNativeFontInfo() const
+{
+ wxCHECK_MSG( Ok(), wxNullNativeFontInfo, wxT("invalid font") );
+
+ if(M_FONTDATA->m_nativeFontInfo.xFontName.IsEmpty())
+ GetInternalFont();
+ return M_FONTDATA->m_nativeFontInfo;
+}
+
+
// ----------------------------------------------------------------------------
// change font attributes
// ----------------------------------------------------------------------------
Unshare();
M_FONTDATA->m_pointSize = pointSize;
+ M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
}
void wxFont::SetFamily(int family)
Unshare();
M_FONTDATA->m_family = family;
+ M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
}
void wxFont::SetStyle(int style)
Unshare();
M_FONTDATA->m_style = style;
+ M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
}
void wxFont::SetWeight(int weight)
Unshare();
M_FONTDATA->m_weight = weight;
+ M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
}
void wxFont::SetFaceName(const wxString& faceName)
Unshare();
M_FONTDATA->m_faceName = faceName;
+ M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
}
void wxFont::SetUnderlined(bool underlined)
Unshare();
M_FONTDATA->m_encoding = encoding;
+ M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
+}
+
+void wxFont::SetNativeFontInfo(const wxNativeFontInfo& info)
+{
+ Unshare();
+
+ M_FONTDATA->m_nativeFontInfo = info;
}
// ----------------------------------------------------------------------------
M_FONTDATA->m_weight,
M_FONTDATA->m_underlined,
M_FONTDATA->m_faceName,
- M_FONTDATA->m_encoding );
+ M_FONTDATA->m_encoding,
+ &M_FONTDATA->m_nativeFontInfo.xFontName );
}
M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font );
gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
+
+ wxFont font = m_fontData.GetInitialFont();
+ if( font.Ok() )
+ {
+ wxNativeFontInfo info = font.GetNativeFontInfo();
+
+ if( info.xFontName.IsEmpty() )
+ font.GetInternalFont();
+ gtk_font_selection_dialog_set_font_name(sel, wxConvCurrent->cWX2MB(info.xFontName.GetData()));
+ }
}
wxFontDialog::~wxFontDialog()
wxPalette wxNullPalette;
wxFont wxNullFont;
wxColour wxNullColour;
+wxNativeFontInfo wxNullNativeFontInfo;
// Default window names
const char *wxButtonNameStr = "button";
wxPalette wxNullPalette;
wxFont wxNullFont;
wxColour wxNullColour;
+wxNativeFontInfo wxNullNativeFontInfo;
// Default window names
const wxChar *wxControlNameStr = wxT("control");
bool underlined,
const wxString& facename,
const wxString& xregistry,
- const wxString& xencoding);
+ const wxString& xencoding,
+ wxString* xFontName);
// ============================================================================
// implementation
int weight,
bool underlined,
const wxString &facename,
- wxFontEncoding encoding)
+ wxFontEncoding encoding,
+ wxString* xFontName)
{
if ( encoding == wxFONTENCODING_DEFAULT )
{
}
// OK, we have the correct xregistry/xencoding in info structure
- wxNativeFont font = wxLoadQueryFont( pointSize, family, style, weight,
+ wxNativeFont font = 0;
+
+ // if we already have the X font name, try to use it
+ if( xFontName && !xFontName->IsEmpty() )
+ font = wxLoadFont(*xFontName);
+
+ if( !font )
+ font = wxLoadQueryFont( pointSize, family, style, weight,
underlined, facename,
- info.xregistry, info.xencoding );
+ info.xregistry, info.xencoding,
+ xFontName );
if ( !font )
{
for ( i = pointSize - 10; !font && i >= 10 && i >= min_size; i -= 10 )
{
font = wxLoadQueryFont(i, family, style, weight, underlined,
- facename, info.xregistry, info.xencoding);
+ facename, info.xregistry, info.xencoding,
+ xFontName);
}
// Search for larger size (approx.)
for ( i = pointSize + 10; !font && i <= max_size; i += 10 )
{
font = wxLoadQueryFont(i, family, style, weight, underlined,
- facename, info.xregistry, info.xencoding);
+ facename, info.xregistry, info.xencoding,
+ xFontName);
}
// Try default family
{
font = wxLoadQueryFont(pointSize, wxDEFAULT, style, weight,
underlined, facename,
- info.xregistry, info.xencoding );
+ info.xregistry, info.xencoding,
+ xFontName );
}
// Bogus font I
{
font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
underlined, facename,
- info.xregistry, info.xencoding);
+ info.xregistry, info.xencoding,
+ xFontName);
}
// Bogus font II
{
font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
underlined, wxEmptyString,
- info.xregistry, info.xencoding);
+ info.xregistry, info.xencoding,
+ xFontName);
}
}
bool WXUNUSED(underlined),
const wxString& facename,
const wxString& xregistry,
- const wxString& xencoding)
+ const wxString& xencoding,
+ wxString* xFontName)
{
wxString xfamily;
switch (family)
xfamily.c_str(), xweight.c_str(), xstyle.c_str(),
pointSize, xregistry.c_str(), xencoding.c_str());
+ if( xFontName )
+ *xFontName = fontSpec;
+
return wxLoadFont(fontSpec);
}