]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/font.cpp
treectrl -> treetest
[wxWidgets.git] / src / mgl / font.cpp
CommitLineData
32b8ec41
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: font.cpp
3// Author: Vaclav Slavik
4// Id: $Id$
c41c20a5 5// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
32b8ec41
VZ
6// Licence: wxWindows licence
7/////////////////////////////////////////////////////////////////////////////
8
9// ============================================================================
10// declarations
11// ============================================================================
12
13// ----------------------------------------------------------------------------
14// headers
15// ----------------------------------------------------------------------------
16
17#ifdef __GNUG__
18 #pragma implementation "font.h"
19#endif
20
a246f95e
VS
21// For compilers that support precompilation, includes "wx.h".
22#include "wx/wxprec.h"
23
24#ifdef __BORLANDC__
25 #pragma hdrstop
26#endif
27
32b8ec41
VZ
28#include "wx/font.h"
29#include "wx/fontutil.h"
30#include "wx/cmndata.h"
31#include "wx/utils.h"
32#include "wx/log.h"
33#include "wx/gdicmn.h"
34#include "wx/tokenzr.h"
35#include "wx/settings.h"
f3437beb 36#include "wx/mgl/private.h"
32b8ec41 37
32b8ec41
VZ
38// ----------------------------------------------------------------------------
39// wxFontRefData
40// ----------------------------------------------------------------------------
41
42class wxFontRefData : public wxObjectRefData
43{
44public:
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();
54
55protected:
56 // common part of all ctors
57 void Init(int pointSize,
58 int family,
59 int style,
60 int weight,
61 bool underlined,
62 const wxString& faceName,
63 wxFontEncoding encoding);
64
65private:
66 int m_pointSize;
67 int m_family,
68 m_style,
69 m_weight;
70 bool m_underlined;
71 wxString m_faceName;
72 wxFontEncoding m_encoding;
73
74 wxMGLFontLibrary *m_library;
75 bool m_valid;
76
77 friend class wxFont;
78};
79
80// ============================================================================
81// implementation
82// ============================================================================
83
84// ----------------------------------------------------------------------------
85// wxFontRefData
86// ----------------------------------------------------------------------------
87
88void wxFontRefData::Init(int pointSize,
89 int family,
90 int style,
91 int weight,
92 bool underlined,
93 const wxString& faceName,
94 wxFontEncoding encoding)
95{
96 if ( family == wxDEFAULT )
97 m_family = wxSWISS;
98 else
99 m_family = family;
100
101 m_faceName = faceName;
102
103 if ( style == wxDEFAULT )
104 m_style = wxNORMAL;
105 else
106 m_style = style;
107
108 if ( weight == wxDEFAULT )
109 m_weight = wxNORMAL;
110 else
111 m_weight = weight;
112
113 if ( pointSize == wxDEFAULT )
114 m_pointSize = 12;
115 else
116 m_pointSize = pointSize;
117
118 m_underlined = underlined;
119 m_encoding = encoding;
120
121 m_library = NULL;
122 m_valid = FALSE;
123}
124
125wxFontRefData::wxFontRefData(const wxFontRefData& data)
126{
127 Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
128 data.m_underlined, data.m_faceName, data.m_encoding);
129
130 m_library = data.m_library;
131 m_valid = data.m_valid;
132 if ( m_library )
133 m_library->IncRef();
ef344ff8 134 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library);
32b8ec41
VZ
135}
136
137wxFontRefData::wxFontRefData(int size, int family, int style,
138 int weight, bool underlined,
139 const wxString& faceName,
140 wxFontEncoding encoding)
141{
142 Init(size, family, style, weight, underlined, faceName, encoding);
ef344ff8 143 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library);
32b8ec41
VZ
144}
145
146wxFontRefData::~wxFontRefData()
147{
ef344ff8 148 wxLogTrace("mgl_font", "destructing fntrefdata %p, library is %p", this, m_library);
32b8ec41
VZ
149 if ( m_library )
150 m_library->DecRef();
151}
152
153// ----------------------------------------------------------------------------
154// wxFont
155// ----------------------------------------------------------------------------
156
157IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
158
32b8ec41
VZ
159bool wxFont::Create(const wxNativeFontInfo& info)
160{
161 return Create(info.pointSize, info.family, info.style, info.weight,
162 info.underlined, info.faceName, info.encoding);
163}
164
165bool wxFont::Create(int pointSize,
166 int family,
167 int style,
168 int weight,
169 bool underlined,
170 const wxString& face,
171 wxFontEncoding encoding)
172{
173 m_refData = new wxFontRefData(pointSize, family, style, weight,
174 underlined, face, encoding);
175 return TRUE;
176}
177
178struct font_t *wxFont::GetMGLfont_t(float scale, bool antialiased)
179{
180 if ( !M_FONTDATA->m_valid )
181 {
182 wxMGLFontLibrary *old = M_FONTDATA->m_library;
183 M_FONTDATA->m_library = wxTheFontsManager->GetFontLibrary(this);
184 M_FONTDATA->m_library->IncRef();
185 if ( old )
186 old->DecRef();
187 }
188
189 wxMGLFontInstance *instance =
190 M_FONTDATA->m_library->GetFontInstance(this, scale, antialiased);
191
192 return instance->GetMGLfont_t();
193}
194
6d7ee9e8 195wxObjectRefData *wxFont::CreateRefData() const
32b8ec41 196{
6d7ee9e8 197 return new wxFontRefData;
32b8ec41
VZ
198}
199
6d7ee9e8
VS
200wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const
201{
202 return new wxFontRefData(*(wxFontRefData *)data);
203}
204
205
32b8ec41
VZ
206// ----------------------------------------------------------------------------
207// accessors
208// ----------------------------------------------------------------------------
209
210int wxFont::GetPointSize() const
211{
212 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
213
214 return M_FONTDATA->m_pointSize;
215}
216
217wxString wxFont::GetFaceName() const
218{
219 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
220
221 return M_FONTDATA->m_faceName;
222}
223
224int wxFont::GetFamily() const
225{
226 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
227
228 return M_FONTDATA->m_family;
229}
230
231int wxFont::GetStyle() const
232{
233 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
234
235 return M_FONTDATA->m_style;
236}
237
238int wxFont::GetWeight() const
239{
240 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
241
242 return M_FONTDATA->m_weight;
243}
244
245bool wxFont::GetUnderlined() const
246{
247 wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
248
249 return M_FONTDATA->m_underlined;
250}
251
252
253wxFontEncoding wxFont::GetEncoding() const
254{
255 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
256
257 return M_FONTDATA->m_encoding;
258}
259
f3437beb
VS
260bool wxFont::IsFixedWidth() const
261{
262 wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
263
264 return (bool)(M_FONTDATA->m_library->GetFamily()->GetInfo()->isFixed);
265}
266
32b8ec41
VZ
267
268// ----------------------------------------------------------------------------
269// change font attributes
270// ----------------------------------------------------------------------------
271
272void wxFont::SetPointSize(int pointSize)
273{
6d7ee9e8 274 AllocExclusive();
32b8ec41
VZ
275
276 M_FONTDATA->m_pointSize = pointSize;
277 M_FONTDATA->m_valid = FALSE;
278}
279
280void wxFont::SetFamily(int family)
281{
6d7ee9e8 282 AllocExclusive();
32b8ec41
VZ
283
284 M_FONTDATA->m_family = family;
285 M_FONTDATA->m_valid = FALSE;
286}
287
288void wxFont::SetStyle(int style)
289{
6d7ee9e8 290 AllocExclusive();
32b8ec41
VZ
291
292 M_FONTDATA->m_style = style;
293 M_FONTDATA->m_valid = FALSE;
294}
295
296void wxFont::SetWeight(int weight)
297{
6d7ee9e8 298 AllocExclusive();
32b8ec41
VZ
299
300 M_FONTDATA->m_weight = weight;
301 M_FONTDATA->m_valid = FALSE;
302}
303
304void wxFont::SetFaceName(const wxString& faceName)
305{
6d7ee9e8 306 AllocExclusive();
32b8ec41
VZ
307
308 M_FONTDATA->m_faceName = faceName;
309 M_FONTDATA->m_valid = FALSE;
310}
311
312void wxFont::SetUnderlined(bool underlined)
313{
6d7ee9e8 314 AllocExclusive();
32b8ec41
VZ
315
316 M_FONTDATA->m_underlined = underlined;
317}
318
319void wxFont::SetEncoding(wxFontEncoding encoding)
320{
6d7ee9e8 321 AllocExclusive();
32b8ec41
VZ
322
323 M_FONTDATA->m_encoding = encoding;
324 M_FONTDATA->m_valid = FALSE;
325}