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"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 class wxFontRefData
: public wxObjectRefData
44 wxFontRefData(int size
= wxDEFAULT
,
45 int family
= wxDEFAULT
,
46 int style
= wxDEFAULT
,
47 int weight
= wxDEFAULT
,
48 bool underlined
= FALSE
,
49 const wxString
& faceName
= wxEmptyString
,
50 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
51 wxFontRefData(const wxFontRefData
& data
);
52 virtual ~wxFontRefData();
55 // common part of all ctors
56 void Init(int pointSize
,
61 const wxString
& faceName
,
62 wxFontEncoding encoding
);
71 wxFontEncoding m_encoding
;
73 wxMGLFontLibrary
*m_library
;
79 // ============================================================================
81 // ============================================================================
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 void wxFontRefData::Init(int pointSize
,
92 const wxString
& faceName
,
93 wxFontEncoding encoding
)
95 if ( family
== wxDEFAULT
)
100 m_faceName
= faceName
;
102 if ( style
== wxDEFAULT
)
107 if ( weight
== wxDEFAULT
)
112 if ( pointSize
== wxDEFAULT
)
115 m_pointSize
= pointSize
;
117 m_underlined
= underlined
;
118 m_encoding
= encoding
;
124 wxFontRefData::wxFontRefData(const wxFontRefData
& data
)
126 Init(data
.m_pointSize
, data
.m_family
, data
.m_style
, data
.m_weight
,
127 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
129 m_library
= data
.m_library
;
130 m_valid
= data
.m_valid
;
133 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
136 wxFontRefData::wxFontRefData(int size
, int family
, int style
,
137 int weight
, bool underlined
,
138 const wxString
& faceName
,
139 wxFontEncoding encoding
)
141 Init(size
, family
, style
, weight
, underlined
, faceName
, encoding
);
142 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
145 wxFontRefData::~wxFontRefData()
147 wxLogTrace("mgl_font", "destructing fntrefdata %p, library is %p", this, m_library
);
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
156 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
158 bool wxFont::Create(const wxNativeFontInfo
& info
)
160 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
161 info
.underlined
, info
.faceName
, info
.encoding
);
164 bool wxFont::Create(int pointSize
,
169 const wxString
& face
,
170 wxFontEncoding encoding
)
172 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
173 underlined
, face
, encoding
);
177 struct font_t
*wxFont::GetMGLfont_t(float scale
, bool antialiased
)
179 if ( !M_FONTDATA
->m_valid
)
181 wxMGLFontLibrary
*old
= M_FONTDATA
->m_library
;
182 M_FONTDATA
->m_library
= wxTheFontsManager
->GetFontLibrary(this);
183 M_FONTDATA
->m_library
->IncRef();
188 wxMGLFontInstance
*instance
=
189 M_FONTDATA
->m_library
->GetFontInstance(this, scale
, antialiased
);
191 return instance
->GetMGLfont_t();
194 void wxFont::Unshare()
198 m_refData
= new wxFontRefData();
202 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 int wxFont::GetPointSize() const
214 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
216 return M_FONTDATA
->m_pointSize
;
219 wxString
wxFont::GetFaceName() const
221 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
223 return M_FONTDATA
->m_faceName
;
226 int wxFont::GetFamily() const
228 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
230 return M_FONTDATA
->m_family
;
233 int wxFont::GetStyle() const
235 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
237 return M_FONTDATA
->m_style
;
240 int wxFont::GetWeight() const
242 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
244 return M_FONTDATA
->m_weight
;
247 bool wxFont::GetUnderlined() const
249 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
251 return M_FONTDATA
->m_underlined
;
255 wxFontEncoding
wxFont::GetEncoding() const
257 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
259 return M_FONTDATA
->m_encoding
;
263 // ----------------------------------------------------------------------------
264 // change font attributes
265 // ----------------------------------------------------------------------------
267 void wxFont::SetPointSize(int pointSize
)
271 M_FONTDATA
->m_pointSize
= pointSize
;
272 M_FONTDATA
->m_valid
= FALSE
;
275 void wxFont::SetFamily(int family
)
279 M_FONTDATA
->m_family
= family
;
280 M_FONTDATA
->m_valid
= FALSE
;
283 void wxFont::SetStyle(int style
)
287 M_FONTDATA
->m_style
= style
;
288 M_FONTDATA
->m_valid
= FALSE
;
291 void wxFont::SetWeight(int weight
)
295 M_FONTDATA
->m_weight
= weight
;
296 M_FONTDATA
->m_valid
= FALSE
;
299 void wxFont::SetFaceName(const wxString
& faceName
)
303 M_FONTDATA
->m_faceName
= faceName
;
304 M_FONTDATA
->m_valid
= FALSE
;
307 void wxFont::SetUnderlined(bool underlined
)
311 M_FONTDATA
->m_underlined
= underlined
;
314 void wxFont::SetEncoding(wxFontEncoding encoding
)
318 M_FONTDATA
->m_encoding
= encoding
;
319 M_FONTDATA
->m_valid
= FALSE
;