]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/font.cpp
e954b9faf356ceaef5b8934bf82fa8a6871f3aeb
[wxWidgets.git] / src / dfb / font.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/font.cpp
3 // Purpose: wxFont implementation
4 // Author: Vaclav Slavik
5 // Created: 2006-08-08
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #include "wx/font.h"
27
28 #ifndef WX_PRECOMP
29 #include "wx/app.h"
30 #endif
31
32 #include "wx/fontutil.h"
33 #include "wx/dfb/private.h"
34
35 // ----------------------------------------------------------------------------
36 // wxFontRefData
37 // ----------------------------------------------------------------------------
38
39 // FIXME: for now, always use single font
40 static IDirectFBFontPtr gs_font = NULL;
41 static unsigned gs_fontRefCnt = 0;
42
43 class wxFontRefData : public wxObjectRefData
44 {
45 public:
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)
53 {
54 if ( family == wxDEFAULT )
55 family = wxSWISS;
56 if ( style == wxDEFAULT )
57 style = wxNORMAL;
58 if ( weight == wxDEFAULT )
59 weight = wxNORMAL;
60 if ( size == wxDEFAULT )
61 size = 12;
62
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;
70
71 // FIXME: always use default font for now
72 if ( !gs_font )
73 {
74 IDirectFBPtr dfb(wxTheApp->GetDirectFBInterface());
75
76 DFBFontDescription desc;
77 desc.flags = (DFBFontDescriptionFlags)0;
78 IDirectFBFontPtr f;
79 if ( DFB_CALL( dfb->CreateFont(dfb, NULL, &desc, &f) ) )
80 gs_font = f;
81 }
82 if ( gs_font ) // the above may fail
83 {
84 gs_fontRefCnt++;
85 m_font = gs_font;
86 }
87 }
88
89 wxFontRefData(const wxFontRefData& data)
90 {
91 m_info = data.m_info;
92 m_font = data.m_font;
93 }
94
95 ~wxFontRefData()
96 {
97 if ( m_font )
98 {
99 m_font.Reset();
100 // FIXME
101 if ( --gs_fontRefCnt == 0 )
102 gs_font = NULL;
103 }
104 }
105
106 wxNativeFontInfo m_info;
107 IDirectFBFontPtr m_font;
108 };
109
110
111 // ----------------------------------------------------------------------------
112 // wxFont
113 // ----------------------------------------------------------------------------
114
115 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
116
117 bool wxFont::Create(const wxNativeFontInfo& info)
118 {
119 return Create(info.pointSize, info.family, info.style, info.weight,
120 info.underlined, info.faceName, info.encoding);
121 }
122
123 bool wxFont::Create(int pointSize,
124 int family,
125 int style,
126 int weight,
127 bool underlined,
128 const wxString& face,
129 wxFontEncoding encoding)
130 {
131 m_refData = new wxFontRefData(pointSize, family, style, weight,
132 underlined, face, encoding);
133 return true;
134 }
135
136 wxObjectRefData *wxFont::CreateRefData() const
137 {
138 return new wxFontRefData;
139 }
140
141 wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const
142 {
143 return new wxFontRefData(*(wxFontRefData *)data);
144 }
145
146
147 // ----------------------------------------------------------------------------
148 // accessors
149 // ----------------------------------------------------------------------------
150
151 IDirectFBFontPtr wxFont::GetDirectFBFont() const
152 {
153 wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
154
155 return M_FONTDATA->m_font;
156 }
157
158 int wxFont::GetPointSize() const
159 {
160 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
161
162 return M_FONTDATA->m_info.pointSize;
163 }
164
165 wxString wxFont::GetFaceName() const
166 {
167 wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") );
168
169 return M_FONTDATA->m_info.faceName;
170 }
171
172 int wxFont::GetFamily() const
173 {
174 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
175
176 return M_FONTDATA->m_info.family;
177 }
178
179 int wxFont::GetStyle() const
180 {
181 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
182
183 return M_FONTDATA->m_info.style;
184 }
185
186 int wxFont::GetWeight() const
187 {
188 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
189
190 return M_FONTDATA->m_info.weight;
191 }
192
193 bool wxFont::GetUnderlined() const
194 {
195 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
196
197 return M_FONTDATA->m_info.underlined;
198 }
199
200
201 wxFontEncoding wxFont::GetEncoding() const
202 {
203 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
204
205 return M_FONTDATA->m_info.encoding;
206 }
207
208 bool wxFont::IsFixedWidth() const
209 {
210 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
211
212 return true; // FIXME_DFB
213 }
214
215 const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
216 {
217 wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
218
219 return &(M_FONTDATA->m_info);
220 }
221
222 // ----------------------------------------------------------------------------
223 // change font attributes
224 // ----------------------------------------------------------------------------
225
226 void wxFont::SetPointSize(int pointSize)
227 {
228 AllocExclusive();
229
230 M_FONTDATA->m_info.pointSize = pointSize;
231 }
232
233 void wxFont::SetFamily(int family)
234 {
235 AllocExclusive();
236
237 M_FONTDATA->m_info.family = (wxFontFamily)family;
238 }
239
240 void wxFont::SetStyle(int style)
241 {
242 AllocExclusive();
243
244 M_FONTDATA->m_info.style = (wxFontStyle)style;
245 }
246
247 void wxFont::SetWeight(int weight)
248 {
249 AllocExclusive();
250
251 M_FONTDATA->m_info.weight = (wxFontWeight)weight;
252 }
253
254 bool wxFont::SetFaceName(const wxString& faceName)
255 {
256 AllocExclusive();
257
258 M_FONTDATA->m_info.faceName = faceName;
259
260 return wxFontBase::SetFaceName(faceName);
261 }
262
263 void wxFont::SetUnderlined(bool underlined)
264 {
265 AllocExclusive();
266
267 M_FONTDATA->m_info.underlined = underlined;
268 }
269
270 void wxFont::SetEncoding(wxFontEncoding encoding)
271 {
272 AllocExclusive();
273
274 M_FONTDATA->m_info.encoding = encoding;
275 }