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
;
128 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
131 wxFontRefData::wxFontRefData(int size
, int family
, int style
,
132 int weight
, bool underlined
,
133 const wxString
& faceName
,
134 wxFontEncoding encoding
)
136 Init(size
, family
, style
, weight
, underlined
, faceName
, encoding
);
137 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
140 wxFontRefData::~wxFontRefData()
142 wxLogTrace("mgl_font", "destructing fntrefdata %p, library is %p", this, m_library
);
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
156 wxTheFontList
->Append(this);
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
);
212 wxTheFontList
->DeleteObject(this);
215 // ----------------------------------------------------------------------------
217 // ----------------------------------------------------------------------------
219 int wxFont::GetPointSize() const
221 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
223 return M_FONTDATA
->m_pointSize
;
226 wxString
wxFont::GetFaceName() const
228 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
230 return M_FONTDATA
->m_faceName
;
233 int wxFont::GetFamily() const
235 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
237 return M_FONTDATA
->m_family
;
240 int wxFont::GetStyle() const
242 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
244 return M_FONTDATA
->m_style
;
247 int wxFont::GetWeight() const
249 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
251 return M_FONTDATA
->m_weight
;
254 bool wxFont::GetUnderlined() const
256 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
258 return M_FONTDATA
->m_underlined
;
262 wxFontEncoding
wxFont::GetEncoding() const
264 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
266 return M_FONTDATA
->m_encoding
;
270 // ----------------------------------------------------------------------------
271 // change font attributes
272 // ----------------------------------------------------------------------------
274 void wxFont::SetPointSize(int pointSize
)
278 M_FONTDATA
->m_pointSize
= pointSize
;
279 M_FONTDATA
->m_valid
= FALSE
;
282 void wxFont::SetFamily(int family
)
286 M_FONTDATA
->m_family
= family
;
287 M_FONTDATA
->m_valid
= FALSE
;
290 void wxFont::SetStyle(int style
)
294 M_FONTDATA
->m_style
= style
;
295 M_FONTDATA
->m_valid
= FALSE
;
298 void wxFont::SetWeight(int weight
)
302 M_FONTDATA
->m_weight
= weight
;
303 M_FONTDATA
->m_valid
= FALSE
;
306 void wxFont::SetFaceName(const wxString
& faceName
)
310 M_FONTDATA
->m_faceName
= faceName
;
311 M_FONTDATA
->m_valid
= FALSE
;
314 void wxFont::SetUnderlined(bool underlined
)
318 M_FONTDATA
->m_underlined
= underlined
;
321 void wxFont::SetEncoding(wxFontEncoding encoding
)
325 M_FONTDATA
->m_encoding
= encoding
;
326 M_FONTDATA
->m_valid
= FALSE
;