1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Vaclav Slavik
5 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // ============================================================================
11 // ============================================================================
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
18 #pragma implementation "font.h"
22 #include "wx/fontutil.h"
23 #include "wx/cmndata.h"
26 #include "wx/gdicmn.h"
27 #include "wx/tokenzr.h"
28 #include "wx/settings.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 class wxFontRefData
: public wxObjectRefData
39 wxFontRefData(int size
= wxDEFAULT
,
40 int family
= wxDEFAULT
,
41 int style
= wxDEFAULT
,
42 int weight
= wxDEFAULT
,
43 bool underlined
= FALSE
,
44 const wxString
& faceName
= wxEmptyString
,
45 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
46 wxFontRefData(const wxFontRefData
& data
);
47 virtual ~wxFontRefData();
50 // common part of all ctors
51 void Init(int pointSize
,
56 const wxString
& faceName
,
57 wxFontEncoding encoding
);
66 wxFontEncoding m_encoding
;
68 wxMGLFontLibrary
*m_library
;
74 // ============================================================================
76 // ============================================================================
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 void wxFontRefData::Init(int pointSize
,
87 const wxString
& faceName
,
88 wxFontEncoding encoding
)
90 if ( family
== wxDEFAULT
)
95 m_faceName
= faceName
;
97 if ( style
== wxDEFAULT
)
102 if ( weight
== wxDEFAULT
)
107 if ( pointSize
== wxDEFAULT
)
110 m_pointSize
= pointSize
;
112 m_underlined
= underlined
;
113 m_encoding
= encoding
;
119 wxFontRefData::wxFontRefData(const wxFontRefData
& data
)
121 Init(data
.m_pointSize
, data
.m_family
, data
.m_style
, data
.m_weight
,
122 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
124 m_library
= data
.m_library
;
125 m_valid
= data
.m_valid
;
130 wxFontRefData::wxFontRefData(int size
, int family
, int style
,
131 int weight
, bool underlined
,
132 const wxString
& faceName
,
133 wxFontEncoding encoding
)
135 Init(size
, family
, style
, weight
, underlined
, faceName
, encoding
);
138 wxFontRefData::~wxFontRefData()
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
153 wxTheFontList
->Append(this);
156 bool wxFont::Create(const wxNativeFontInfo
& info
)
158 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
159 info
.underlined
, info
.faceName
, info
.encoding
);
162 bool wxFont::Create(int pointSize
,
167 const wxString
& face
,
168 wxFontEncoding encoding
)
170 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
171 underlined
, face
, encoding
);
175 struct font_t
*wxFont::GetMGLfont_t(float scale
, bool antialiased
)
177 if ( !M_FONTDATA
->m_valid
)
179 wxMGLFontLibrary
*old
= M_FONTDATA
->m_library
;
180 M_FONTDATA
->m_library
= wxTheFontsManager
->GetFontLibrary(this);
181 M_FONTDATA
->m_library
->IncRef();
186 wxMGLFontInstance
*instance
=
187 M_FONTDATA
->m_library
->GetFontInstance(this, scale
, antialiased
);
189 return instance
->GetMGLfont_t();
192 void wxFont::Unshare()
196 m_refData
= new wxFontRefData();
200 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
209 wxTheFontList
->DeleteObject(this);
212 // ----------------------------------------------------------------------------
214 // ----------------------------------------------------------------------------
216 int wxFont::GetPointSize() const
218 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
220 return M_FONTDATA
->m_pointSize
;
223 wxString
wxFont::GetFaceName() const
225 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
227 return M_FONTDATA
->m_faceName
;
230 int wxFont::GetFamily() const
232 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
234 return M_FONTDATA
->m_family
;
237 int wxFont::GetStyle() const
239 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
241 return M_FONTDATA
->m_style
;
244 int wxFont::GetWeight() const
246 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
248 return M_FONTDATA
->m_weight
;
251 bool wxFont::GetUnderlined() const
253 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
255 return M_FONTDATA
->m_underlined
;
259 wxFontEncoding
wxFont::GetEncoding() const
261 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
263 return M_FONTDATA
->m_encoding
;
267 // ----------------------------------------------------------------------------
268 // change font attributes
269 // ----------------------------------------------------------------------------
271 void wxFont::SetPointSize(int pointSize
)
275 M_FONTDATA
->m_pointSize
= pointSize
;
276 M_FONTDATA
->m_valid
= FALSE
;
279 void wxFont::SetFamily(int family
)
283 M_FONTDATA
->m_family
= family
;
284 M_FONTDATA
->m_valid
= FALSE
;
287 void wxFont::SetStyle(int style
)
291 M_FONTDATA
->m_style
= style
;
292 M_FONTDATA
->m_valid
= FALSE
;
295 void wxFont::SetWeight(int weight
)
299 M_FONTDATA
->m_weight
= weight
;
300 M_FONTDATA
->m_valid
= FALSE
;
303 void wxFont::SetFaceName(const wxString
& faceName
)
307 M_FONTDATA
->m_faceName
= faceName
;
308 M_FONTDATA
->m_valid
= FALSE
;
311 void wxFont::SetUnderlined(bool underlined
)
315 M_FONTDATA
->m_underlined
= underlined
;
318 void wxFont::SetEncoding(wxFontEncoding encoding
)
322 M_FONTDATA
->m_encoding
= encoding
;
323 M_FONTDATA
->m_valid
= FALSE
;