1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Vaclav Slavik
5 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // ============================================================================
11 // ============================================================================
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
18 #pragma implementation "font.h"
22 #include "wx/fontutil.h"
23 #include "wx/cmndata.h"
26 #include "wx/gdicmn.h"
27 #include "wx/tokenzr.h"
28 #include "wx/settings.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 class wxFontRefData
: public wxObjectRefData
39 wxFontRefData(int size
= wxDEFAULT
,
40 int family
= wxDEFAULT
,
41 int style
= wxDEFAULT
,
42 int weight
= wxDEFAULT
,
43 bool underlined
= FALSE
,
44 const wxString
& faceName
= wxEmptyString
,
45 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
46 wxFontRefData(const wxFontRefData
& data
);
47 virtual ~wxFontRefData();
50 // common part of all ctors
51 void Init(int pointSize
,
56 const wxString
& faceName
,
57 wxFontEncoding encoding
);
66 wxFontEncoding m_encoding
;
68 wxMGLFontLibrary
*m_library
;
74 // ============================================================================
76 // ============================================================================
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 void wxFontRefData::Init(int pointSize
,
87 const wxString
& faceName
,
88 wxFontEncoding encoding
)
90 if ( family
== wxDEFAULT
)
95 m_faceName
= faceName
;
97 if ( style
== wxDEFAULT
)
102 if ( weight
== wxDEFAULT
)
107 if ( pointSize
== wxDEFAULT
)
110 m_pointSize
= pointSize
;
112 m_underlined
= underlined
;
113 m_encoding
= encoding
;
119 wxFontRefData::wxFontRefData(const wxFontRefData
& data
)
121 Init(data
.m_pointSize
, data
.m_family
, data
.m_style
, data
.m_weight
,
122 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
124 m_library
= data
.m_library
;
125 m_valid
= data
.m_valid
;
128 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
131 wxFontRefData::wxFontRefData(int size
, int family
, int style
,
132 int weight
, bool underlined
,
133 const wxString
& faceName
,
134 wxFontEncoding encoding
)
136 Init(size
, family
, style
, weight
, underlined
, faceName
, encoding
);
137 wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library
);
140 wxFontRefData::~wxFontRefData()
142 wxLogTrace("mgl_font", "destructing fntrefdata %p, library is %p", this, m_library
);
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
156 wxTheFontList
->Append(this);
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 // FIXME_MGL -- no antialiasing for fonts smaller than certain treshold!
181 if ( !M_FONTDATA
->m_valid
)
183 wxMGLFontLibrary
*old
= M_FONTDATA
->m_library
;
184 M_FONTDATA
->m_library
= wxTheFontsManager
->GetFontLibrary(this);
185 M_FONTDATA
->m_library
->IncRef();
190 wxMGLFontInstance
*instance
=
191 M_FONTDATA
->m_library
->GetFontInstance(this, scale
, antialiased
);
193 return instance
->GetMGLfont_t();
196 void wxFont::Unshare()
200 m_refData
= new wxFontRefData();
204 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
213 wxTheFontList
->DeleteObject(this);
216 // ----------------------------------------------------------------------------
218 // ----------------------------------------------------------------------------
220 int wxFont::GetPointSize() const
222 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
224 return M_FONTDATA
->m_pointSize
;
227 wxString
wxFont::GetFaceName() const
229 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
231 return M_FONTDATA
->m_faceName
;
234 int wxFont::GetFamily() const
236 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
238 return M_FONTDATA
->m_family
;
241 int wxFont::GetStyle() const
243 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
245 return M_FONTDATA
->m_style
;
248 int wxFont::GetWeight() const
250 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
252 return M_FONTDATA
->m_weight
;
255 bool wxFont::GetUnderlined() const
257 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
259 return M_FONTDATA
->m_underlined
;
263 wxFontEncoding
wxFont::GetEncoding() const
265 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
267 return M_FONTDATA
->m_encoding
;
271 // ----------------------------------------------------------------------------
272 // change font attributes
273 // ----------------------------------------------------------------------------
275 void wxFont::SetPointSize(int pointSize
)
279 M_FONTDATA
->m_pointSize
= pointSize
;
280 M_FONTDATA
->m_valid
= FALSE
;
283 void wxFont::SetFamily(int family
)
287 M_FONTDATA
->m_family
= family
;
288 M_FONTDATA
->m_valid
= FALSE
;
291 void wxFont::SetStyle(int style
)
295 M_FONTDATA
->m_style
= style
;
296 M_FONTDATA
->m_valid
= FALSE
;
299 void wxFont::SetWeight(int weight
)
303 M_FONTDATA
->m_weight
= weight
;
304 M_FONTDATA
->m_valid
= FALSE
;
307 void wxFont::SetFaceName(const wxString
& faceName
)
311 M_FONTDATA
->m_faceName
= faceName
;
312 M_FONTDATA
->m_valid
= FALSE
;
315 void wxFont::SetUnderlined(bool underlined
)
319 M_FONTDATA
->m_underlined
= underlined
;
322 void wxFont::SetEncoding(wxFontEncoding encoding
)
326 M_FONTDATA
->m_encoding
= encoding
;
327 M_FONTDATA
->m_valid
= FALSE
;