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
)
153 bool wxFont::Create(const wxNativeFontInfo
& info
)
155 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
156 info
.underlined
, info
.faceName
, info
.encoding
);
159 bool wxFont::Create(int pointSize
,
164 const wxString
& face
,
165 wxFontEncoding encoding
)
167 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
168 underlined
, face
, encoding
);
172 struct font_t
*wxFont::GetMGLfont_t(float scale
, bool antialiased
)
174 if ( !M_FONTDATA
->m_valid
)
176 wxMGLFontLibrary
*old
= M_FONTDATA
->m_library
;
177 M_FONTDATA
->m_library
= wxTheFontsManager
->GetFontLibrary(this);
178 M_FONTDATA
->m_library
->IncRef();
183 wxMGLFontInstance
*instance
=
184 M_FONTDATA
->m_library
->GetFontInstance(this, scale
, antialiased
);
186 return instance
->GetMGLfont_t();
189 void wxFont::Unshare()
193 m_refData
= new wxFontRefData();
197 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
203 // ----------------------------------------------------------------------------
205 // ----------------------------------------------------------------------------
207 int wxFont::GetPointSize() const
209 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
211 return M_FONTDATA
->m_pointSize
;
214 wxString
wxFont::GetFaceName() const
216 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
218 return M_FONTDATA
->m_faceName
;
221 int wxFont::GetFamily() const
223 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
225 return M_FONTDATA
->m_family
;
228 int wxFont::GetStyle() const
230 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
232 return M_FONTDATA
->m_style
;
235 int wxFont::GetWeight() const
237 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
239 return M_FONTDATA
->m_weight
;
242 bool wxFont::GetUnderlined() const
244 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid font") );
246 return M_FONTDATA
->m_underlined
;
250 wxFontEncoding
wxFont::GetEncoding() const
252 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
254 return M_FONTDATA
->m_encoding
;
258 // ----------------------------------------------------------------------------
259 // change font attributes
260 // ----------------------------------------------------------------------------
262 void wxFont::SetPointSize(int pointSize
)
266 M_FONTDATA
->m_pointSize
= pointSize
;
267 M_FONTDATA
->m_valid
= FALSE
;
270 void wxFont::SetFamily(int family
)
274 M_FONTDATA
->m_family
= family
;
275 M_FONTDATA
->m_valid
= FALSE
;
278 void wxFont::SetStyle(int style
)
282 M_FONTDATA
->m_style
= style
;
283 M_FONTDATA
->m_valid
= FALSE
;
286 void wxFont::SetWeight(int weight
)
290 M_FONTDATA
->m_weight
= weight
;
291 M_FONTDATA
->m_valid
= FALSE
;
294 void wxFont::SetFaceName(const wxString
& faceName
)
298 M_FONTDATA
->m_faceName
= faceName
;
299 M_FONTDATA
->m_valid
= FALSE
;
302 void wxFont::SetUnderlined(bool underlined
)
306 M_FONTDATA
->m_underlined
= underlined
;
309 void wxFont::SetEncoding(wxFontEncoding encoding
)
313 M_FONTDATA
->m_encoding
= encoding
;
314 M_FONTDATA
->m_valid
= FALSE
;