]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/font.cpp
oops, fixed typo breaking iconv constness detection in the previous commit
[wxWidgets.git] / src / mgl / font.cpp
CommitLineData
32b8ec41
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: font.cpp
3// Author: Vaclav Slavik
4// Id: $Id$
8f7b34a8 5// Copyright: (c) 2001 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
195void wxFont::Unshare()
196{
197 if ( !m_refData )
198 {
199 m_refData = new wxFontRefData();
200 }
201 else
202 {
203 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
204 UnRef();
205 m_refData = ref;
206 }
207}
208
32b8ec41
VZ
209// ----------------------------------------------------------------------------
210// accessors
211// ----------------------------------------------------------------------------
212
213int wxFont::GetPointSize() const
214{
215 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
216
217 return M_FONTDATA->m_pointSize;
218}
219
220wxString wxFont::GetFaceName() const
221{
222 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
223
224 return M_FONTDATA->m_faceName;
225}
226
227int wxFont::GetFamily() const
228{
229 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
230
231 return M_FONTDATA->m_family;
232}
233
234int wxFont::GetStyle() const
235{
236 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
237
238 return M_FONTDATA->m_style;
239}
240
241int wxFont::GetWeight() const
242{
243 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
244
245 return M_FONTDATA->m_weight;
246}
247
248bool wxFont::GetUnderlined() const
249{
250 wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
251
252 return M_FONTDATA->m_underlined;
253}
254
255
256wxFontEncoding wxFont::GetEncoding() const
257{
258 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
259
260 return M_FONTDATA->m_encoding;
261}
262
f3437beb
VS
263bool wxFont::IsFixedWidth() const
264{
265 wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
266
267 return (bool)(M_FONTDATA->m_library->GetFamily()->GetInfo()->isFixed);
268}
269
32b8ec41
VZ
270
271// ----------------------------------------------------------------------------
272// change font attributes
273// ----------------------------------------------------------------------------
274
275void wxFont::SetPointSize(int pointSize)
276{
277 Unshare();
278
279 M_FONTDATA->m_pointSize = pointSize;
280 M_FONTDATA->m_valid = FALSE;
281}
282
283void wxFont::SetFamily(int family)
284{
285 Unshare();
286
287 M_FONTDATA->m_family = family;
288 M_FONTDATA->m_valid = FALSE;
289}
290
291void wxFont::SetStyle(int style)
292{
293 Unshare();
294
295 M_FONTDATA->m_style = style;
296 M_FONTDATA->m_valid = FALSE;
297}
298
299void wxFont::SetWeight(int weight)
300{
301 Unshare();
302
303 M_FONTDATA->m_weight = weight;
304 M_FONTDATA->m_valid = FALSE;
305}
306
307void wxFont::SetFaceName(const wxString& faceName)
308{
309 Unshare();
310
311 M_FONTDATA->m_faceName = faceName;
312 M_FONTDATA->m_valid = FALSE;
313}
314
315void wxFont::SetUnderlined(bool underlined)
316{
317 Unshare();
318
319 M_FONTDATA->m_underlined = underlined;
320}
321
322void wxFont::SetEncoding(wxFontEncoding encoding)
323{
324 Unshare();
325
326 M_FONTDATA->m_encoding = encoding;
327 M_FONTDATA->m_valid = FALSE;
328}