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 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
25 #include "wx/fontutil.h"
26 #include "wx/cmndata.h"
29 #include "wx/gdicmn.h"
30 #include "wx/tokenzr.h"
31 #include "wx/settings.h"
32 #include "wx/mgl/private.h"
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 class wxFontRefData
: public wxObjectRefData
41 wxFontRefData(int size
= wxDEFAULT
,
42 int family
= wxDEFAULT
,
43 int style
= wxDEFAULT
,
44 int weight
= wxDEFAULT
,
45 bool underlined
= FALSE
,
46 const wxString
& faceName
= wxEmptyString
,
47 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
48 wxFontRefData(const wxFontRefData
& data
);
49 virtual ~wxFontRefData();
52 // common part of all ctors
53 void Init(int pointSize
,
58 const wxString
& faceName
,
59 wxFontEncoding encoding
);
68 wxFontEncoding m_encoding
;
70 wxMGLFontLibrary
*m_library
;
73 wxNativeFontInfo m_info
;
78 // ============================================================================
80 // ============================================================================
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 void wxFontRefData::Init(int pointSize
,
91 const wxString
& faceName
,
92 wxFontEncoding encoding
)
94 if ( family
== wxDEFAULT
)
99 m_faceName
= faceName
;
101 if ( style
== wxDEFAULT
)
106 if ( weight
== wxDEFAULT
)
111 if ( pointSize
== wxDEFAULT
)
114 m_pointSize
= pointSize
;
116 m_underlined
= underlined
;
117 m_encoding
= encoding
;
123 wxFontRefData::wxFontRefData(const wxFontRefData
& data
)
125 Init(data
.m_pointSize
, data
.m_family
, data
.m_style
, data
.m_weight
,
126 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
128 m_library
= data
.m_library
;
129 m_valid
= data
.m_valid
;
132 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
135 wxFontRefData::wxFontRefData(int size
, int family
, int style
,
136 int weight
, bool underlined
,
137 const wxString
& faceName
,
138 wxFontEncoding encoding
)
140 Init(size
, family
, style
, weight
, underlined
, faceName
, encoding
);
141 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
144 wxFontRefData::~wxFontRefData()
146 wxLogTrace("mgl_font", "destructing fntrefdata %p, library is %p", this, m_library
);
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
157 bool wxFont::Create(const wxNativeFontInfo
& info
)
159 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
160 info
.underlined
, info
.faceName
, info
.encoding
);
163 bool wxFont::Create(int pointSize
,
168 const wxString
& face
,
169 wxFontEncoding encoding
)
171 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
172 underlined
, face
, encoding
);
176 struct font_t
*wxFont::GetMGLfont_t(float scale
, bool antialiased
)
178 if ( !M_FONTDATA
->m_valid
)
180 wxMGLFontLibrary
*old
= M_FONTDATA
->m_library
;
181 M_FONTDATA
->m_library
= wxTheFontsManager
->GetFontLibrary(this);
182 M_FONTDATA
->m_library
->IncRef();
187 wxMGLFontInstance
*instance
=
188 M_FONTDATA
->m_library
->GetFontInstance(this, scale
, antialiased
);
190 return instance
->GetMGLfont_t();
193 wxObjectRefData
*wxFont::CreateRefData() const
195 return new wxFontRefData
;
198 wxObjectRefData
*wxFont::CloneRefData(const wxObjectRefData
*data
) const
200 return new wxFontRefData(*(wxFontRefData
*)data
);
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
208 int wxFont::GetPointSize() const
210 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
212 return M_FONTDATA
->m_pointSize
;
215 wxString
wxFont::GetFaceName() const
217 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
219 return M_FONTDATA
->m_faceName
;
222 int wxFont::GetFamily() const
224 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
226 return M_FONTDATA
->m_family
;
229 int wxFont::GetStyle() const
231 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
233 return M_FONTDATA
->m_style
;
236 int wxFont::GetWeight() const
238 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
240 return M_FONTDATA
->m_weight
;
243 bool wxFont::GetUnderlined() const
245 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
247 return M_FONTDATA
->m_underlined
;
251 wxFontEncoding
wxFont::GetEncoding() const
253 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
255 return M_FONTDATA
->m_encoding
;
258 bool wxFont::IsFixedWidth() const
260 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
262 return (bool)(M_FONTDATA
->m_library
->GetFamily()->GetInfo()->isFixed
);
265 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
267 wxCHECK_MSG( Ok(), NULL
, wxT("invalid font") );
269 M_FONTDATA
->m_info
.InitFromFont(*this);
271 return &(M_FONTDATA
->m_info
);
274 // ----------------------------------------------------------------------------
275 // change font attributes
276 // ----------------------------------------------------------------------------
278 void wxFont::SetPointSize(int pointSize
)
282 M_FONTDATA
->m_pointSize
= pointSize
;
283 M_FONTDATA
->m_valid
= FALSE
;
286 void wxFont::SetFamily(int family
)
290 M_FONTDATA
->m_family
= family
;
291 M_FONTDATA
->m_valid
= FALSE
;
294 void wxFont::SetStyle(int style
)
298 M_FONTDATA
->m_style
= style
;
299 M_FONTDATA
->m_valid
= FALSE
;
302 void wxFont::SetWeight(int weight
)
306 M_FONTDATA
->m_weight
= weight
;
307 M_FONTDATA
->m_valid
= FALSE
;
310 void wxFont::SetFaceName(const wxString
& faceName
)
314 M_FONTDATA
->m_faceName
= faceName
;
315 M_FONTDATA
->m_valid
= FALSE
;
318 void wxFont::SetUnderlined(bool underlined
)
322 M_FONTDATA
->m_underlined
= underlined
;
325 void wxFont::SetEncoding(wxFontEncoding encoding
)
329 M_FONTDATA
->m_encoding
= encoding
;
330 M_FONTDATA
->m_valid
= FALSE
;