applied wxNativeFontInfo patch from Derry Bryson (with minor changes)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8934 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
a9c317d27c
commit
30764ab524
@ -67,6 +67,40 @@ enum wxFontWeight
|
||||
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
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -85,6 +119,7 @@ public:
|
||||
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; }
|
||||
@ -101,6 +136,7 @@ public:
|
||||
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;
|
||||
@ -110,6 +146,7 @@ public:
|
||||
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, ...)
|
||||
|
@ -36,7 +36,8 @@ public:
|
||||
// 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);
|
||||
@ -60,7 +61,10 @@ public:
|
||||
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();
|
||||
|
||||
@ -72,6 +76,7 @@ public:
|
||||
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 );
|
||||
@ -80,6 +85,7 @@ public:
|
||||
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();
|
||||
|
@ -36,7 +36,8 @@ public:
|
||||
// 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);
|
||||
@ -60,7 +61,10 @@ public:
|
||||
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();
|
||||
|
||||
@ -72,6 +76,7 @@ public:
|
||||
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 );
|
||||
@ -80,6 +85,7 @@ public:
|
||||
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();
|
||||
|
@ -37,6 +37,14 @@ public:
|
||||
(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,
|
||||
|
@ -40,6 +40,14 @@ public:
|
||||
(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,
|
||||
|
@ -21,12 +21,14 @@
|
||||
#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_
|
||||
|
@ -96,6 +96,8 @@ public:
|
||||
{ DoEnumerateFamilies(TRUE); }
|
||||
void OnEnumerateEncodings(wxCommandEvent& event);
|
||||
|
||||
void OnCheckNativeToFromString(wxCommandEvent& event);
|
||||
|
||||
void OnSize(wxSizeEvent& event);
|
||||
|
||||
protected:
|
||||
@ -136,7 +138,8 @@ enum
|
||||
Font_EnumFamilies,
|
||||
Font_EnumFixedFamilies,
|
||||
Font_EnumEncodings,
|
||||
Font_Max
|
||||
Font_CheckNativeToFromString
|
||||
Font_Max,
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -157,6 +160,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
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()
|
||||
@ -228,6 +232,9 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||
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;
|
||||
@ -382,7 +389,7 @@ void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
|
||||
wxFONTENCODING_CP1252,
|
||||
};
|
||||
|
||||
static const char *encodingNames[] =
|
||||
static const wxString encodingNames[] =
|
||||
{
|
||||
"West European (Latin 1)",
|
||||
"Central European (Latin 2)",
|
||||
@ -397,7 +404,7 @@ void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
|
||||
|
||||
int n = wxGetSingleChoiceIndex("Choose an encoding", "Font demo",
|
||||
WXSIZEOF(encodingNames),
|
||||
(char **)encodingNames,
|
||||
encodingNames,
|
||||
this);
|
||||
|
||||
if ( n != -1 )
|
||||
@ -406,6 +413,27 @@ void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
@ -650,6 +678,13 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
|
||||
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);
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include "wx/font.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/tokenzr.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
@ -54,6 +56,44 @@ wxFont *wxFontBase::New(int size,
|
||||
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 )
|
||||
@ -115,3 +155,75 @@ wxString wxFontBase::GetWeightString() const
|
||||
}
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
|
@ -126,6 +126,7 @@ wxBrush wxNullBrush;
|
||||
wxFont wxNullFont;
|
||||
wxColour wxNullColour;
|
||||
wxPalette wxNullPalette;
|
||||
wxNativeFontInfo wxNullNativeFontInfo;
|
||||
|
||||
/* Default window names */
|
||||
const wxChar *wxControlNameStr = wxT("control");
|
||||
|
106
src/gtk/font.cpp
106
src/gtk/font.cpp
@ -47,7 +47,8 @@ public:
|
||||
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();
|
||||
|
||||
@ -59,7 +60,8 @@ protected:
|
||||
int weight,
|
||||
bool underlined,
|
||||
const wxString& faceName,
|
||||
wxFontEncoding encoding);
|
||||
wxFontEncoding encoding,
|
||||
const wxNativeFontInfo& info);
|
||||
|
||||
private:
|
||||
wxList m_scaled_xfonts;
|
||||
@ -70,6 +72,7 @@ private:
|
||||
bool m_underlined;
|
||||
wxString m_faceName;
|
||||
wxFontEncoding m_encoding;
|
||||
wxNativeFontInfo m_nativeFontInfo;
|
||||
|
||||
friend class wxFont;
|
||||
};
|
||||
@ -88,7 +91,8 @@ void wxFontRefData::Init(int pointSize,
|
||||
int weight,
|
||||
bool underlined,
|
||||
const wxString& faceName,
|
||||
wxFontEncoding encoding)
|
||||
wxFontEncoding encoding,
|
||||
const wxNativeFontInfo& info = wxNullNativeFontInfo)
|
||||
{
|
||||
if (family == wxDEFAULT)
|
||||
m_family = wxSWISS;
|
||||
@ -114,21 +118,24 @@ void wxFontRefData::Init(int pointSize,
|
||||
|
||||
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()
|
||||
@ -143,6 +150,21 @@ wxFontRefData::~wxFontRefData()
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxNativeFontInfo
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxNativeFontInfo::FromString(const wxString& s)
|
||||
{
|
||||
xFontName = s;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxString wxNativeFontInfo::ToString() const
|
||||
{
|
||||
return xFontName;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFont
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -155,14 +177,40 @@ void wxFont::Init()
|
||||
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("-") );
|
||||
@ -170,6 +218,7 @@ wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
|
||||
tn.GetNextToken(); // skip initial empty token
|
||||
tn.GetNextToken(); // foundry
|
||||
|
||||
|
||||
M_FONTDATA->m_faceName = tn.GetNextToken(); // family
|
||||
|
||||
tmp = tn.GetNextToken().MakeUpper(); // weight
|
||||
@ -247,20 +296,9 @@ wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
|
||||
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;
|
||||
}
|
||||
|
||||
@ -338,6 +376,16 @@ wxFontEncoding wxFont::GetEncoding() const
|
||||
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
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -347,6 +395,7 @@ void wxFont::SetPointSize(int pointSize)
|
||||
Unshare();
|
||||
|
||||
M_FONTDATA->m_pointSize = pointSize;
|
||||
M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
|
||||
}
|
||||
|
||||
void wxFont::SetFamily(int family)
|
||||
@ -354,6 +403,7 @@ void wxFont::SetFamily(int family)
|
||||
Unshare();
|
||||
|
||||
M_FONTDATA->m_family = family;
|
||||
M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
|
||||
}
|
||||
|
||||
void wxFont::SetStyle(int style)
|
||||
@ -361,6 +411,7 @@ void wxFont::SetStyle(int style)
|
||||
Unshare();
|
||||
|
||||
M_FONTDATA->m_style = style;
|
||||
M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
|
||||
}
|
||||
|
||||
void wxFont::SetWeight(int weight)
|
||||
@ -368,6 +419,7 @@ 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)
|
||||
@ -375,6 +427,7 @@ 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)
|
||||
@ -389,6 +442,14 @@ void wxFont::SetEncoding(wxFontEncoding encoding)
|
||||
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;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -450,7 +511,8 @@ GdkFont *wxFont::GetInternalFont( float scale ) const
|
||||
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 );
|
||||
|
@ -174,6 +174,16 @@ wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
|
||||
|
||||
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()
|
||||
|
@ -126,6 +126,7 @@ wxBrush wxNullBrush;
|
||||
wxFont wxNullFont;
|
||||
wxColour wxNullColour;
|
||||
wxPalette wxNullPalette;
|
||||
wxNativeFontInfo wxNullNativeFontInfo;
|
||||
|
||||
/* Default window names */
|
||||
const wxChar *wxControlNameStr = wxT("control");
|
||||
|
@ -47,7 +47,8 @@ public:
|
||||
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();
|
||||
|
||||
@ -59,7 +60,8 @@ protected:
|
||||
int weight,
|
||||
bool underlined,
|
||||
const wxString& faceName,
|
||||
wxFontEncoding encoding);
|
||||
wxFontEncoding encoding,
|
||||
const wxNativeFontInfo& info);
|
||||
|
||||
private:
|
||||
wxList m_scaled_xfonts;
|
||||
@ -70,6 +72,7 @@ private:
|
||||
bool m_underlined;
|
||||
wxString m_faceName;
|
||||
wxFontEncoding m_encoding;
|
||||
wxNativeFontInfo m_nativeFontInfo;
|
||||
|
||||
friend class wxFont;
|
||||
};
|
||||
@ -88,7 +91,8 @@ void wxFontRefData::Init(int pointSize,
|
||||
int weight,
|
||||
bool underlined,
|
||||
const wxString& faceName,
|
||||
wxFontEncoding encoding)
|
||||
wxFontEncoding encoding,
|
||||
const wxNativeFontInfo& info = wxNullNativeFontInfo)
|
||||
{
|
||||
if (family == wxDEFAULT)
|
||||
m_family = wxSWISS;
|
||||
@ -114,21 +118,24 @@ void wxFontRefData::Init(int pointSize,
|
||||
|
||||
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()
|
||||
@ -143,6 +150,21 @@ wxFontRefData::~wxFontRefData()
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxNativeFontInfo
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxNativeFontInfo::FromString(const wxString& s)
|
||||
{
|
||||
xFontName = s;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxString wxNativeFontInfo::ToString() const
|
||||
{
|
||||
return xFontName;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFont
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -155,14 +177,40 @@ void wxFont::Init()
|
||||
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("-") );
|
||||
@ -170,6 +218,7 @@ wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
|
||||
tn.GetNextToken(); // skip initial empty token
|
||||
tn.GetNextToken(); // foundry
|
||||
|
||||
|
||||
M_FONTDATA->m_faceName = tn.GetNextToken(); // family
|
||||
|
||||
tmp = tn.GetNextToken().MakeUpper(); // weight
|
||||
@ -247,20 +296,9 @@ wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
|
||||
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;
|
||||
}
|
||||
|
||||
@ -338,6 +376,16 @@ wxFontEncoding wxFont::GetEncoding() const
|
||||
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
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -347,6 +395,7 @@ void wxFont::SetPointSize(int pointSize)
|
||||
Unshare();
|
||||
|
||||
M_FONTDATA->m_pointSize = pointSize;
|
||||
M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
|
||||
}
|
||||
|
||||
void wxFont::SetFamily(int family)
|
||||
@ -354,6 +403,7 @@ void wxFont::SetFamily(int family)
|
||||
Unshare();
|
||||
|
||||
M_FONTDATA->m_family = family;
|
||||
M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
|
||||
}
|
||||
|
||||
void wxFont::SetStyle(int style)
|
||||
@ -361,6 +411,7 @@ void wxFont::SetStyle(int style)
|
||||
Unshare();
|
||||
|
||||
M_FONTDATA->m_style = style;
|
||||
M_FONTDATA->m_nativeFontInfo.xFontName.Clear(); // invalid now
|
||||
}
|
||||
|
||||
void wxFont::SetWeight(int weight)
|
||||
@ -368,6 +419,7 @@ 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)
|
||||
@ -375,6 +427,7 @@ 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)
|
||||
@ -389,6 +442,14 @@ void wxFont::SetEncoding(wxFontEncoding encoding)
|
||||
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;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -450,7 +511,8 @@ GdkFont *wxFont::GetInternalFont( float scale ) const
|
||||
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 );
|
||||
|
@ -174,6 +174,16 @@ wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
|
||||
|
||||
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()
|
||||
|
@ -87,6 +87,7 @@ wxBrush wxNullBrush;
|
||||
wxPalette wxNullPalette;
|
||||
wxFont wxNullFont;
|
||||
wxColour wxNullColour;
|
||||
wxNativeFontInfo wxNullNativeFontInfo;
|
||||
|
||||
// Default window names
|
||||
const char *wxButtonNameStr = "button";
|
||||
|
@ -96,6 +96,7 @@ wxBrush wxNullBrush;
|
||||
wxPalette wxNullPalette;
|
||||
wxFont wxNullFont;
|
||||
wxColour wxNullColour;
|
||||
wxNativeFontInfo wxNullNativeFontInfo;
|
||||
|
||||
// Default window names
|
||||
const wxChar *wxControlNameStr = wxT("control");
|
||||
|
@ -95,7 +95,8 @@ static wxNativeFont wxLoadQueryFont(int pointSize,
|
||||
bool underlined,
|
||||
const wxString& facename,
|
||||
const wxString& xregistry,
|
||||
const wxString& xencoding);
|
||||
const wxString& xencoding,
|
||||
wxString* xFontName);
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
@ -240,7 +241,8 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
|
||||
int weight,
|
||||
bool underlined,
|
||||
const wxString &facename,
|
||||
wxFontEncoding encoding)
|
||||
wxFontEncoding encoding,
|
||||
wxString* xFontName)
|
||||
{
|
||||
if ( encoding == wxFONTENCODING_DEFAULT )
|
||||
{
|
||||
@ -274,9 +276,17 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
|
||||
}
|
||||
|
||||
// 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 )
|
||||
{
|
||||
@ -290,14 +300,16 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
|
||||
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
|
||||
@ -305,7 +317,8 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
|
||||
{
|
||||
font = wxLoadQueryFont(pointSize, wxDEFAULT, style, weight,
|
||||
underlined, facename,
|
||||
info.xregistry, info.xencoding );
|
||||
info.xregistry, info.xencoding,
|
||||
xFontName );
|
||||
}
|
||||
|
||||
// Bogus font I
|
||||
@ -313,7 +326,8 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
|
||||
{
|
||||
font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
|
||||
underlined, facename,
|
||||
info.xregistry, info.xencoding);
|
||||
info.xregistry, info.xencoding,
|
||||
xFontName);
|
||||
}
|
||||
|
||||
// Bogus font II
|
||||
@ -321,7 +335,8 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
|
||||
{
|
||||
font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
|
||||
underlined, wxEmptyString,
|
||||
info.xregistry, info.xencoding);
|
||||
info.xregistry, info.xencoding,
|
||||
xFontName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,7 +386,8 @@ static wxNativeFont wxLoadQueryFont(int pointSize,
|
||||
bool WXUNUSED(underlined),
|
||||
const wxString& facename,
|
||||
const wxString& xregistry,
|
||||
const wxString& xencoding)
|
||||
const wxString& xencoding,
|
||||
wxString* xFontName)
|
||||
{
|
||||
wxString xfamily;
|
||||
switch (family)
|
||||
@ -545,6 +561,9 @@ static wxNativeFont wxLoadQueryFont(int pointSize,
|
||||
xfamily.c_str(), xweight.c_str(), xstyle.c_str(),
|
||||
pointSize, xregistry.c_str(), xencoding.c_str());
|
||||
|
||||
if( xFontName )
|
||||
*xFontName = fontSpec;
|
||||
|
||||
return wxLoadFont(fontSpec);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user