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
;
77 wxNativeFontInfo m_info
;
82 // ============================================================================
84 // ============================================================================
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 void wxFontRefData::Init(int pointSize
,
95 const wxString
& faceName
,
96 wxFontEncoding encoding
)
98 if ( family
== wxDEFAULT
)
103 m_faceName
= faceName
;
105 if ( style
== wxDEFAULT
)
110 if ( weight
== wxDEFAULT
)
115 if ( pointSize
== wxDEFAULT
)
118 m_pointSize
= pointSize
;
120 m_underlined
= underlined
;
121 m_encoding
= encoding
;
127 wxFontRefData::wxFontRefData(const wxFontRefData
& data
)
129 Init(data
.m_pointSize
, data
.m_family
, data
.m_style
, data
.m_weight
,
130 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
132 m_library
= data
.m_library
;
133 m_valid
= data
.m_valid
;
136 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
139 wxFontRefData::wxFontRefData(int size
, int family
, int style
,
140 int weight
, bool underlined
,
141 const wxString
& faceName
,
142 wxFontEncoding encoding
)
144 Init(size
, family
, style
, weight
, underlined
, faceName
, encoding
);
145 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
148 wxFontRefData::~wxFontRefData()
150 wxLogTrace("mgl_font", "destructing fntrefdata %p, library is %p", this, m_library
);
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
161 bool wxFont::Create(const wxNativeFontInfo
& info
)
163 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
164 info
.underlined
, info
.faceName
, info
.encoding
);
167 bool wxFont::Create(int pointSize
,
172 const wxString
& face
,
173 wxFontEncoding encoding
)
175 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
176 underlined
, face
, encoding
);
180 struct font_t
*wxFont::GetMGLfont_t(float scale
, bool antialiased
)
182 if ( !M_FONTDATA
->m_valid
)
184 wxMGLFontLibrary
*old
= M_FONTDATA
->m_library
;
185 M_FONTDATA
->m_library
= wxTheFontsManager
->GetFontLibrary(this);
186 M_FONTDATA
->m_library
->IncRef();
191 wxMGLFontInstance
*instance
=
192 M_FONTDATA
->m_library
->GetFontInstance(this, scale
, antialiased
);
194 return instance
->GetMGLfont_t();
197 wxObjectRefData
*wxFont::CreateRefData() const
199 return new wxFontRefData
;
202 wxObjectRefData
*wxFont::CloneRefData(const wxObjectRefData
*data
) const
204 return new wxFontRefData(*(wxFontRefData
*)data
);
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 int wxFont::GetPointSize() const
214 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
216 return M_FONTDATA
->m_pointSize
;
219 wxString
wxFont::GetFaceName() const
221 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
223 return M_FONTDATA
->m_faceName
;
226 int wxFont::GetFamily() const
228 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
230 return M_FONTDATA
->m_family
;
233 int wxFont::GetStyle() const
235 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
237 return M_FONTDATA
->m_style
;
240 int wxFont::GetWeight() const
242 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
244 return M_FONTDATA
->m_weight
;
247 bool wxFont::GetUnderlined() const
249 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
251 return M_FONTDATA
->m_underlined
;
255 wxFontEncoding
wxFont::GetEncoding() const
257 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
259 return M_FONTDATA
->m_encoding
;
262 bool wxFont::IsFixedWidth() const
264 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
266 return (bool)(M_FONTDATA
->m_library
->GetFamily()->GetInfo()->isFixed
);
269 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
271 wxCHECK_MSG( Ok(), NULL
, wxT("invalid font") );
273 M_FONTDATA
->m_info
.InitFromFont(*this);
275 return &(M_FONTDATA
->m_info
);
278 // ----------------------------------------------------------------------------
279 // change font attributes
280 // ----------------------------------------------------------------------------
282 void wxFont::SetPointSize(int pointSize
)
286 M_FONTDATA
->m_pointSize
= pointSize
;
287 M_FONTDATA
->m_valid
= FALSE
;
290 void wxFont::SetFamily(int family
)
294 M_FONTDATA
->m_family
= family
;
295 M_FONTDATA
->m_valid
= FALSE
;
298 void wxFont::SetStyle(int style
)
302 M_FONTDATA
->m_style
= style
;
303 M_FONTDATA
->m_valid
= FALSE
;
306 void wxFont::SetWeight(int weight
)
310 M_FONTDATA
->m_weight
= weight
;
311 M_FONTDATA
->m_valid
= FALSE
;
314 void wxFont::SetFaceName(const wxString
& faceName
)
318 M_FONTDATA
->m_faceName
= faceName
;
319 M_FONTDATA
->m_valid
= FALSE
;
322 void wxFont::SetUnderlined(bool underlined
)
326 M_FONTDATA
->m_underlined
= underlined
;
329 void wxFont::SetEncoding(wxFontEncoding encoding
)
333 M_FONTDATA
->m_encoding
= encoding
;
334 M_FONTDATA
->m_valid
= FALSE
;