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