]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/font.cpp
fixed VC6 compilation
[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)
65571936 6// Licence: wxWindows licence
32b8ec41
VZ
7/////////////////////////////////////////////////////////////////////////////
8
9// ============================================================================
10// declarations
11// ============================================================================
12
13// ----------------------------------------------------------------------------
14// headers
15// ----------------------------------------------------------------------------
16
14f355c2 17#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
32b8ec41
VZ
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
3bf5a59b
VZ
77 wxNativeFontInfo m_info;
78
32b8ec41
VZ
79 friend class wxFont;
80};
81
82// ============================================================================
83// implementation
84// ============================================================================
85
86// ----------------------------------------------------------------------------
87// wxFontRefData
88// ----------------------------------------------------------------------------
89
90void wxFontRefData::Init(int pointSize,
91 int family,
92 int style,
93 int weight,
94 bool underlined,
95 const wxString& faceName,
96 wxFontEncoding encoding)
97{
98 if ( family == wxDEFAULT )
99 m_family = wxSWISS;
100 else
101 m_family = family;
102
103 m_faceName = faceName;
104
105 if ( style == wxDEFAULT )
106 m_style = wxNORMAL;
107 else
108 m_style = style;
109
110 if ( weight == wxDEFAULT )
111 m_weight = wxNORMAL;
112 else
113 m_weight = weight;
114
115 if ( pointSize == wxDEFAULT )
116 m_pointSize = 12;
117 else
118 m_pointSize = pointSize;
119
120 m_underlined = underlined;
121 m_encoding = encoding;
122
123 m_library = NULL;
124 m_valid = FALSE;
125}
126
127wxFontRefData::wxFontRefData(const wxFontRefData& data)
128{
129 Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
130 data.m_underlined, data.m_faceName, data.m_encoding);
131
132 m_library = data.m_library;
133 m_valid = data.m_valid;
134 if ( m_library )
135 m_library->IncRef();
ef344ff8 136 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library);
32b8ec41
VZ
137}
138
139wxFontRefData::wxFontRefData(int size, int family, int style,
140 int weight, bool underlined,
141 const wxString& faceName,
142 wxFontEncoding encoding)
143{
144 Init(size, family, style, weight, underlined, faceName, encoding);
ef344ff8 145 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library);
32b8ec41
VZ
146}
147
148wxFontRefData::~wxFontRefData()
149{
ef344ff8 150 wxLogTrace("mgl_font", "destructing fntrefdata %p, library is %p", this, m_library);
32b8ec41
VZ
151 if ( m_library )
152 m_library->DecRef();
153}
154
155// ----------------------------------------------------------------------------
156// wxFont
157// ----------------------------------------------------------------------------
158
159IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
160
32b8ec41
VZ
161bool wxFont::Create(const wxNativeFontInfo& info)
162{
163 return Create(info.pointSize, info.family, info.style, info.weight,
164 info.underlined, info.faceName, info.encoding);
165}
166
167bool wxFont::Create(int pointSize,
168 int family,
169 int style,
170 int weight,
171 bool underlined,
172 const wxString& face,
173 wxFontEncoding encoding)
174{
175 m_refData = new wxFontRefData(pointSize, family, style, weight,
176 underlined, face, encoding);
177 return TRUE;
178}
179
180struct font_t *wxFont::GetMGLfont_t(float scale, bool antialiased)
181{
182 if ( !M_FONTDATA->m_valid )
183 {
184 wxMGLFontLibrary *old = M_FONTDATA->m_library;
185 M_FONTDATA->m_library = wxTheFontsManager->GetFontLibrary(this);
186 M_FONTDATA->m_library->IncRef();
187 if ( old )
188 old->DecRef();
189 }
190
191 wxMGLFontInstance *instance =
192 M_FONTDATA->m_library->GetFontInstance(this, scale, antialiased);
193
194 return instance->GetMGLfont_t();
195}
196
6d7ee9e8 197wxObjectRefData *wxFont::CreateRefData() const
32b8ec41 198{
6d7ee9e8 199 return new wxFontRefData;
32b8ec41
VZ
200}
201
6d7ee9e8
VS
202wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const
203{
204 return new wxFontRefData(*(wxFontRefData *)data);
205}
206
207
32b8ec41
VZ
208// ----------------------------------------------------------------------------
209// accessors
210// ----------------------------------------------------------------------------
211
212int wxFont::GetPointSize() const
213{
214 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
215
216 return M_FONTDATA->m_pointSize;
217}
218
219wxString wxFont::GetFaceName() const
220{
221 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
222
223 return M_FONTDATA->m_faceName;
224}
225
226int wxFont::GetFamily() const
227{
228 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
229
230 return M_FONTDATA->m_family;
231}
232
233int wxFont::GetStyle() const
234{
235 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
236
237 return M_FONTDATA->m_style;
238}
239
240int wxFont::GetWeight() const
241{
242 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
243
244 return M_FONTDATA->m_weight;
245}
246
247bool wxFont::GetUnderlined() const
248{
249 wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
250
251 return M_FONTDATA->m_underlined;
252}
253
254
255wxFontEncoding wxFont::GetEncoding() const
256{
257 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
258
259 return M_FONTDATA->m_encoding;
260}
261
f3437beb
VS
262bool wxFont::IsFixedWidth() const
263{
264 wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
265
266 return (bool)(M_FONTDATA->m_library->GetFamily()->GetInfo()->isFixed);
267}
268
3bf5a59b
VZ
269const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
270{
271 wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
272
273 M_FONTDATA->m_info.InitFromFont(*this);
274
275 return &(M_FONTDATA->m_info);
276}
32b8ec41
VZ
277
278// ----------------------------------------------------------------------------
279// change font attributes
280// ----------------------------------------------------------------------------
281
282void wxFont::SetPointSize(int pointSize)
283{
6d7ee9e8 284 AllocExclusive();
32b8ec41
VZ
285
286 M_FONTDATA->m_pointSize = pointSize;
287 M_FONTDATA->m_valid = FALSE;
288}
289
290void wxFont::SetFamily(int family)
291{
6d7ee9e8 292 AllocExclusive();
32b8ec41
VZ
293
294 M_FONTDATA->m_family = family;
295 M_FONTDATA->m_valid = FALSE;
296}
297
298void wxFont::SetStyle(int style)
299{
6d7ee9e8 300 AllocExclusive();
32b8ec41
VZ
301
302 M_FONTDATA->m_style = style;
303 M_FONTDATA->m_valid = FALSE;
304}
305
306void wxFont::SetWeight(int weight)
307{
6d7ee9e8 308 AllocExclusive();
32b8ec41
VZ
309
310 M_FONTDATA->m_weight = weight;
311 M_FONTDATA->m_valid = FALSE;
312}
313
314void wxFont::SetFaceName(const wxString& faceName)
315{
6d7ee9e8 316 AllocExclusive();
32b8ec41
VZ
317
318 M_FONTDATA->m_faceName = faceName;
319 M_FONTDATA->m_valid = FALSE;
320}
321
322void wxFont::SetUnderlined(bool underlined)
323{
6d7ee9e8 324 AllocExclusive();
32b8ec41
VZ
325
326 M_FONTDATA->m_underlined = underlined;
327}
328
329void wxFont::SetEncoding(wxFontEncoding encoding)
330{
6d7ee9e8 331 AllocExclusive();
32b8ec41
VZ
332
333 M_FONTDATA->m_encoding = encoding;
334 M_FONTDATA->m_valid = FALSE;
335}