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"
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
29 #include "wx/fontutil.h"
30 #include "wx/cmndata.h"
33 #include "wx/gdicmn.h"
34 #include "wx/tokenzr.h"
35 #include "wx/settings.h"
36 #include "wx/mgl/private.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 class wxFontRefData
: public wxObjectRefData
45 wxFontRefData(int size
= wxDEFAULT
,
46 int family
= wxDEFAULT
,
47 int style
= wxDEFAULT
,
48 int weight
= wxDEFAULT
,
49 bool underlined
= FALSE
,
50 const wxString
& faceName
= wxEmptyString
,
51 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
52 wxFontRefData(const wxFontRefData
& data
);
53 virtual ~wxFontRefData();
56 // common part of all ctors
57 void Init(int pointSize
,
62 const wxString
& faceName
,
63 wxFontEncoding encoding
);
72 wxFontEncoding m_encoding
;
74 wxMGLFontLibrary
*m_library
;
80 // ============================================================================
82 // ============================================================================
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 void wxFontRefData::Init(int pointSize
,
93 const wxString
& faceName
,
94 wxFontEncoding encoding
)
96 if ( family
== wxDEFAULT
)
101 m_faceName
= faceName
;
103 if ( style
== wxDEFAULT
)
108 if ( weight
== wxDEFAULT
)
113 if ( pointSize
== wxDEFAULT
)
116 m_pointSize
= pointSize
;
118 m_underlined
= underlined
;
119 m_encoding
= encoding
;
125 wxFontRefData::wxFontRefData(const wxFontRefData
& data
)
127 Init(data
.m_pointSize
, data
.m_family
, data
.m_style
, data
.m_weight
,
128 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
130 m_library
= data
.m_library
;
131 m_valid
= data
.m_valid
;
134 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
137 wxFontRefData::wxFontRefData(int size
, int family
, int style
,
138 int weight
, bool underlined
,
139 const wxString
& faceName
,
140 wxFontEncoding encoding
)
142 Init(size
, family
, style
, weight
, underlined
, faceName
, encoding
);
143 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
146 wxFontRefData::~wxFontRefData()
148 wxLogTrace("mgl_font", "destructing fntrefdata %p, library is %p", this, m_library
);
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
159 bool wxFont::Create(const wxNativeFontInfo
& info
)
161 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
162 info
.underlined
, info
.faceName
, info
.encoding
);
165 bool wxFont::Create(int pointSize
,
170 const wxString
& face
,
171 wxFontEncoding encoding
)
173 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
174 underlined
, face
, encoding
);
178 struct font_t
*wxFont::GetMGLfont_t(float scale
, bool antialiased
)
180 if ( !M_FONTDATA
->m_valid
)
182 wxMGLFontLibrary
*old
= M_FONTDATA
->m_library
;
183 M_FONTDATA
->m_library
= wxTheFontsManager
->GetFontLibrary(this);
184 M_FONTDATA
->m_library
->IncRef();
189 wxMGLFontInstance
*instance
=
190 M_FONTDATA
->m_library
->GetFontInstance(this, scale
, antialiased
);
192 return instance
->GetMGLfont_t();
195 void wxFont::Unshare()
199 m_refData
= new wxFontRefData();
203 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
209 // ----------------------------------------------------------------------------
211 // ----------------------------------------------------------------------------
213 int wxFont::GetPointSize() const
215 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
217 return M_FONTDATA
->m_pointSize
;
220 wxString
wxFont::GetFaceName() const
222 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
224 return M_FONTDATA
->m_faceName
;
227 int wxFont::GetFamily() const
229 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
231 return M_FONTDATA
->m_family
;
234 int wxFont::GetStyle() const
236 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
238 return M_FONTDATA
->m_style
;
241 int wxFont::GetWeight() const
243 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
245 return M_FONTDATA
->m_weight
;
248 bool wxFont::GetUnderlined() const
250 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
252 return M_FONTDATA
->m_underlined
;
256 wxFontEncoding
wxFont::GetEncoding() const
258 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
260 return M_FONTDATA
->m_encoding
;
263 bool wxFont::IsFixedWidth() const
265 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
267 return (bool)(M_FONTDATA
->m_library
->GetFamily()->GetInfo()->isFixed
);
271 // ----------------------------------------------------------------------------
272 // change font attributes
273 // ----------------------------------------------------------------------------
275 void wxFont::SetPointSize(int pointSize
)
279 M_FONTDATA
->m_pointSize
= pointSize
;
280 M_FONTDATA
->m_valid
= FALSE
;
283 void wxFont::SetFamily(int family
)
287 M_FONTDATA
->m_family
= family
;
288 M_FONTDATA
->m_valid
= FALSE
;
291 void wxFont::SetStyle(int style
)
295 M_FONTDATA
->m_style
= style
;
296 M_FONTDATA
->m_valid
= FALSE
;
299 void wxFont::SetWeight(int weight
)
303 M_FONTDATA
->m_weight
= weight
;
304 M_FONTDATA
->m_valid
= FALSE
;
307 void wxFont::SetFaceName(const wxString
& faceName
)
311 M_FONTDATA
->m_faceName
= faceName
;
312 M_FONTDATA
->m_valid
= FALSE
;
315 void wxFont::SetUnderlined(bool underlined
)
319 M_FONTDATA
->m_underlined
= underlined
;
322 void wxFont::SetEncoding(wxFontEncoding encoding
)
326 M_FONTDATA
->m_encoding
= encoding
;
327 M_FONTDATA
->m_valid
= FALSE
;