]>
git.saurik.com Git - wxWidgets.git/blob - src/dfb/font.cpp
e954b9faf356ceaef5b8934bf82fa8a6871f3aeb
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 IDirectFBFontPtr 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 IDirectFBPtr
dfb(wxTheApp
->GetDirectFBInterface());
76 DFBFontDescription desc
;
77 desc
.flags
= (DFBFontDescriptionFlags
)0;
79 if ( DFB_CALL( dfb
->CreateFont(dfb
, NULL
, &desc
, &f
) ) )
82 if ( gs_font
) // the above may fail
89 wxFontRefData(const wxFontRefData
& data
)
101 if ( --gs_fontRefCnt
== 0 )
106 wxNativeFontInfo m_info
;
107 IDirectFBFontPtr m_font
;
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
117 bool wxFont::Create(const wxNativeFontInfo
& info
)
119 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
120 info
.underlined
, info
.faceName
, info
.encoding
);
123 bool wxFont::Create(int pointSize
,
128 const wxString
& face
,
129 wxFontEncoding encoding
)
131 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
132 underlined
, face
, encoding
);
136 wxObjectRefData
*wxFont::CreateRefData() const
138 return new wxFontRefData
;
141 wxObjectRefData
*wxFont::CloneRefData(const wxObjectRefData
*data
) const
143 return new wxFontRefData(*(wxFontRefData
*)data
);
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 IDirectFBFontPtr
wxFont::GetDirectFBFont() const
153 wxCHECK_MSG( Ok(), NULL
, wxT("invalid font") );
155 return M_FONTDATA
->m_font
;
158 int wxFont::GetPointSize() const
160 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
162 return M_FONTDATA
->m_info
.pointSize
;
165 wxString
wxFont::GetFaceName() const
167 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
169 return M_FONTDATA
->m_info
.faceName
;
172 int wxFont::GetFamily() const
174 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
176 return M_FONTDATA
->m_info
.family
;
179 int wxFont::GetStyle() const
181 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
183 return M_FONTDATA
->m_info
.style
;
186 int wxFont::GetWeight() const
188 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
190 return M_FONTDATA
->m_info
.weight
;
193 bool wxFont::GetUnderlined() const
195 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
197 return M_FONTDATA
->m_info
.underlined
;
201 wxFontEncoding
wxFont::GetEncoding() const
203 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
205 return M_FONTDATA
->m_info
.encoding
;
208 bool wxFont::IsFixedWidth() const
210 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
212 return true; // FIXME_DFB
215 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
217 wxCHECK_MSG( Ok(), NULL
, wxT("invalid font") );
219 return &(M_FONTDATA
->m_info
);
222 // ----------------------------------------------------------------------------
223 // change font attributes
224 // ----------------------------------------------------------------------------
226 void wxFont::SetPointSize(int pointSize
)
230 M_FONTDATA
->m_info
.pointSize
= pointSize
;
233 void wxFont::SetFamily(int family
)
237 M_FONTDATA
->m_info
.family
= (wxFontFamily
)family
;
240 void wxFont::SetStyle(int style
)
244 M_FONTDATA
->m_info
.style
= (wxFontStyle
)style
;
247 void wxFont::SetWeight(int weight
)
251 M_FONTDATA
->m_info
.weight
= (wxFontWeight
)weight
;
254 bool wxFont::SetFaceName(const wxString
& faceName
)
258 M_FONTDATA
->m_info
.faceName
= faceName
;
260 return wxFontBase::SetFaceName(faceName
);
263 void wxFont::SetUnderlined(bool underlined
)
267 M_FONTDATA
->m_info
.underlined
= underlined
;
270 void wxFont::SetEncoding(wxFontEncoding encoding
)
274 M_FONTDATA
->m_info
.encoding
= encoding
;