1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/font.cpp
3 // Purpose: wxFont implementation
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
32 #include "wx/fontutil.h"
33 #include "wx/dfb/private.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // FIXME: for now, always use single font
40 static wxIDirectFBFontPtr gs_font
= NULL
;
41 static unsigned gs_fontRefCnt
= 0;
43 class wxFontRefData
: public wxObjectRefData
46 wxFontRefData(int size
= wxDEFAULT
,
47 int family
= wxDEFAULT
,
48 int style
= wxDEFAULT
,
49 int weight
= wxDEFAULT
,
50 bool underlined
= false,
51 const wxString
& faceName
= wxEmptyString
,
52 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
)
54 if ( family
== wxDEFAULT
)
56 if ( style
== wxDEFAULT
)
58 if ( weight
== wxDEFAULT
)
60 if ( size
== wxDEFAULT
)
63 m_info
.family
= (wxFontFamily
)family
;
64 m_info
.faceName
= faceName
;
65 m_info
.style
= (wxFontStyle
)style
;
66 m_info
.weight
= (wxFontWeight
)weight
;
67 m_info
.pointSize
= size
;
68 m_info
.underlined
= underlined
;
69 m_info
.encoding
= encoding
;
71 // FIXME: always use default font for now
74 DFBFontDescription desc
;
75 desc
.flags
= (DFBFontDescriptionFlags
)0;
76 wxIDirectFBFontPtr
f(wxIDirectFB::Get()->CreateFont(NULL
, &desc
));
80 if ( gs_font
) // the above may fail
87 wxFontRefData(const wxFontRefData
& data
)
99 if ( --gs_fontRefCnt
== 0 )
104 wxNativeFontInfo m_info
;
105 wxIDirectFBFontPtr m_font
;
109 // ----------------------------------------------------------------------------
111 // ----------------------------------------------------------------------------
113 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
115 bool wxFont::Create(const wxNativeFontInfo
& info
)
117 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
118 info
.underlined
, info
.faceName
, info
.encoding
);
121 bool wxFont::Create(int pointSize
,
126 const wxString
& face
,
127 wxFontEncoding encoding
)
129 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
130 underlined
, face
, encoding
);
134 wxObjectRefData
*wxFont::CreateRefData() const
136 return new wxFontRefData
;
139 wxObjectRefData
*wxFont::CloneRefData(const wxObjectRefData
*data
) const
141 return new wxFontRefData(*(wxFontRefData
*)data
);
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 wxIDirectFBFontPtr
wxFont::GetDirectFBFont() const
151 wxCHECK_MSG( Ok(), NULL
, wxT("invalid font") );
153 return M_FONTDATA
->m_font
;
156 int wxFont::GetPointSize() const
158 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
160 return M_FONTDATA
->m_info
.pointSize
;
163 wxString
wxFont::GetFaceName() const
165 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
167 return M_FONTDATA
->m_info
.faceName
;
170 int wxFont::GetFamily() const
172 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
174 return M_FONTDATA
->m_info
.family
;
177 int wxFont::GetStyle() const
179 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
181 return M_FONTDATA
->m_info
.style
;
184 int wxFont::GetWeight() const
186 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
188 return M_FONTDATA
->m_info
.weight
;
191 bool wxFont::GetUnderlined() const
193 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
195 return M_FONTDATA
->m_info
.underlined
;
199 wxFontEncoding
wxFont::GetEncoding() const
201 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
203 return M_FONTDATA
->m_info
.encoding
;
206 bool wxFont::IsFixedWidth() const
208 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
210 return true; // FIXME_DFB
213 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
215 wxCHECK_MSG( Ok(), NULL
, wxT("invalid font") );
217 return &(M_FONTDATA
->m_info
);
220 // ----------------------------------------------------------------------------
221 // change font attributes
222 // ----------------------------------------------------------------------------
224 void wxFont::SetPointSize(int pointSize
)
228 M_FONTDATA
->m_info
.pointSize
= pointSize
;
231 void wxFont::SetFamily(int family
)
235 M_FONTDATA
->m_info
.family
= (wxFontFamily
)family
;
238 void wxFont::SetStyle(int style
)
242 M_FONTDATA
->m_info
.style
= (wxFontStyle
)style
;
245 void wxFont::SetWeight(int weight
)
249 M_FONTDATA
->m_info
.weight
= (wxFontWeight
)weight
;
252 bool wxFont::SetFaceName(const wxString
& faceName
)
256 M_FONTDATA
->m_info
.faceName
= faceName
;
258 return wxFontBase::SetFaceName(faceName
);
261 void wxFont::SetUnderlined(bool underlined
)
265 M_FONTDATA
->m_info
.underlined
= underlined
;
268 void wxFont::SetEncoding(wxFontEncoding encoding
)
272 M_FONTDATA
->m_info
.encoding
= encoding
;