1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Vaclav Slavik
5 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // ============================================================================
11 // ============================================================================
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
17 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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"
36 #include "wx/mgl/private.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 class wxFontRefData
: public wxObjectRefData
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();
56 // common part of all ctors
57 void Init(int pointSize
,
62 const wxString
& faceName
,
63 wxFontEncoding encoding
);
72 wxFontEncoding m_encoding
;
74 wxMGLFontLibrary
*m_library
;
80 // ============================================================================
82 // ============================================================================
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 void wxFontRefData::Init(int pointSize
,
93 const wxString
& faceName
,
94 wxFontEncoding encoding
)
96 if ( family
== wxDEFAULT
)
101 m_faceName
= faceName
;
103 if ( style
== wxDEFAULT
)
108 if ( weight
== wxDEFAULT
)
113 if ( pointSize
== wxDEFAULT
)
116 m_pointSize
= pointSize
;
118 m_underlined
= underlined
;
119 m_encoding
= encoding
;
125 wxFontRefData::wxFontRefData(const wxFontRefData
& data
)
127 Init(data
.m_pointSize
, data
.m_family
, data
.m_style
, data
.m_weight
,
128 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
130 m_library
= data
.m_library
;
131 m_valid
= data
.m_valid
;
134 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
137 wxFontRefData::wxFontRefData(int size
, int family
, int style
,
138 int weight
, bool underlined
,
139 const wxString
& faceName
,
140 wxFontEncoding encoding
)
142 Init(size
, family
, style
, weight
, underlined
, faceName
, encoding
);
143 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
146 wxFontRefData::~wxFontRefData()
148 wxLogTrace("mgl_font", "destructing fntrefdata %p, library is %p", this, m_library
);
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
159 bool wxFont::Create(const wxNativeFontInfo
& info
)
161 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
162 info
.underlined
, info
.faceName
, info
.encoding
);
165 bool wxFont::Create(int pointSize
,
170 const wxString
& face
,
171 wxFontEncoding encoding
)
173 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
174 underlined
, face
, encoding
);
178 struct font_t
*wxFont::GetMGLfont_t(float scale
, bool antialiased
)
180 if ( !M_FONTDATA
->m_valid
)
182 wxMGLFontLibrary
*old
= M_FONTDATA
->m_library
;
183 M_FONTDATA
->m_library
= wxTheFontsManager
->GetFontLibrary(this);
184 M_FONTDATA
->m_library
->IncRef();
189 wxMGLFontInstance
*instance
=
190 M_FONTDATA
->m_library
->GetFontInstance(this, scale
, antialiased
);
192 return instance
->GetMGLfont_t();
195 wxObjectRefData
*wxFont::CreateRefData() const
197 return new wxFontRefData
;
200 wxObjectRefData
*wxFont::CloneRefData(const wxObjectRefData
*data
) const
202 return new wxFontRefData(*(wxFontRefData
*)data
);
206 // ----------------------------------------------------------------------------
208 // ----------------------------------------------------------------------------
210 int wxFont::GetPointSize() const
212 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
214 return M_FONTDATA
->m_pointSize
;
217 wxString
wxFont::GetFaceName() const
219 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
221 return M_FONTDATA
->m_faceName
;
224 int wxFont::GetFamily() const
226 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
228 return M_FONTDATA
->m_family
;
231 int wxFont::GetStyle() const
233 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
235 return M_FONTDATA
->m_style
;
238 int wxFont::GetWeight() const
240 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
242 return M_FONTDATA
->m_weight
;
245 bool wxFont::GetUnderlined() const
247 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
249 return M_FONTDATA
->m_underlined
;
253 wxFontEncoding
wxFont::GetEncoding() const
255 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
257 return M_FONTDATA
->m_encoding
;
260 bool wxFont::IsFixedWidth() const
262 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
264 return (bool)(M_FONTDATA
->m_library
->GetFamily()->GetInfo()->isFixed
);
268 // ----------------------------------------------------------------------------
269 // change font attributes
270 // ----------------------------------------------------------------------------
272 void wxFont::SetPointSize(int pointSize
)
276 M_FONTDATA
->m_pointSize
= pointSize
;
277 M_FONTDATA
->m_valid
= FALSE
;
280 void wxFont::SetFamily(int family
)
284 M_FONTDATA
->m_family
= family
;
285 M_FONTDATA
->m_valid
= FALSE
;
288 void wxFont::SetStyle(int style
)
292 M_FONTDATA
->m_style
= style
;
293 M_FONTDATA
->m_valid
= FALSE
;
296 void wxFont::SetWeight(int weight
)
300 M_FONTDATA
->m_weight
= weight
;
301 M_FONTDATA
->m_valid
= FALSE
;
304 void wxFont::SetFaceName(const wxString
& faceName
)
308 M_FONTDATA
->m_faceName
= faceName
;
309 M_FONTDATA
->m_valid
= FALSE
;
312 void wxFont::SetUnderlined(bool underlined
)
316 M_FONTDATA
->m_underlined
= underlined
;
319 void wxFont::SetEncoding(wxFontEncoding encoding
)
323 M_FONTDATA
->m_encoding
= encoding
;
324 M_FONTDATA
->m_valid
= FALSE
;