1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/font.cpp
3 // Purpose: wxFont class
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
34 #include "wx/encinfo.h"
37 #include "wx/fontutil.h"
38 #include "wx/fontmap.h"
40 #include "wx/tokenzr.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
47 // wxFontRefData - the internal description of the font
48 // ----------------------------------------------------------------------------
50 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
56 Init(-1, wxSize(0, 0), false, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
,
57 wxFONTWEIGHT_NORMAL
, false, wxEmptyString
,
58 wxFONTENCODING_DEFAULT
);
61 wxFontRefData(int size
,
62 const wxSize
& pixelSize
,
68 const wxString
& faceName
,
69 wxFontEncoding encoding
)
71 Init(size
, pixelSize
, sizeUsingPixels
, family
, style
, weight
,
72 underlined
, faceName
, encoding
);
75 wxFontRefData(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0)
80 wxFontRefData(const wxFontRefData
& data
)
82 if ( data
.m_nativeFontInfoOk
)
84 Init(data
.m_nativeFontInfo
);
88 Init(data
.m_pointSize
, data
.m_pixelSize
, data
.m_sizeUsingPixels
,
89 data
.m_family
, data
.m_style
, data
.m_weight
,
90 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
94 virtual ~wxFontRefData();
97 bool Alloc(wxFont
*font
);
101 // all wxFont accessors
102 int GetPointSize() const
104 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetPointSize()
108 wxSize
GetPixelSize() const
110 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetPixelSize()
114 bool IsUsingSizeInPixels() const
116 return m_nativeFontInfoOk
? true : m_sizeUsingPixels
;
119 int GetFamily() const
126 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetStyle()
130 int GetWeight() const
132 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetWeight()
136 bool GetUnderlined() const
138 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetUnderlined()
142 wxString
GetFaceName() const
145 if ( m_nativeFontInfoOk
)
146 s
= m_nativeFontInfo
.GetFaceName();
153 wxFontEncoding
GetEncoding() const
155 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetEncoding()
159 WXHFONT
GetHFONT() const { return m_hFont
; }
162 void SetPointSize(int pointSize
)
164 if ( m_nativeFontInfoOk
)
166 m_nativeFontInfo
.SetPointSize(pointSize
);
170 m_pointSize
= pointSize
;
171 m_sizeUsingPixels
= false;
175 void SetPixelSize(const wxSize
& pixelSize
)
177 if ( m_nativeFontInfoOk
)
179 m_nativeFontInfo
.SetPixelSize(pixelSize
);
183 m_pixelSize
= pixelSize
;
184 m_sizeUsingPixels
= true;
188 void SetFamily(wxFontFamily family
)
193 void SetStyle(wxFontStyle style
)
195 if ( m_nativeFontInfoOk
)
196 m_nativeFontInfo
.SetStyle((wxFontStyle
)style
);
201 void SetWeight(wxFontWeight weight
)
203 if ( m_nativeFontInfoOk
)
204 m_nativeFontInfo
.SetWeight((wxFontWeight
)weight
);
209 bool SetFaceName(const wxString
& faceName
)
211 if ( m_nativeFontInfoOk
)
212 m_nativeFontInfo
.SetFaceName(faceName
);
214 m_faceName
= faceName
;
217 void SetUnderlined(bool underlined
)
219 if ( m_nativeFontInfoOk
)
220 m_nativeFontInfo
.SetUnderlined(underlined
);
222 m_underlined
= underlined
;
225 void SetEncoding(wxFontEncoding encoding
)
227 if ( m_nativeFontInfoOk
)
228 m_nativeFontInfo
.SetEncoding(encoding
);
230 m_encoding
= encoding
;
233 // native font info tests
234 bool HasNativeFontInfo() const { return m_nativeFontInfoOk
; }
236 const wxNativeFontInfo
& GetNativeFontInfo() const
237 { return m_nativeFontInfo
; }
240 // common part of all ctors
242 const wxSize
& pixelSize
,
243 bool sizeUsingPixels
,
248 const wxString
& faceName
,
249 wxFontEncoding encoding
);
251 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
253 // font characterstics
256 bool m_sizeUsingPixels
;
257 wxFontFamily m_family
;
259 wxFontWeight m_weight
;
262 wxFontEncoding m_encoding
;
264 // Windows font handle
268 wxNativeFontInfo m_nativeFontInfo
;
269 bool m_nativeFontInfoOk
;
272 #define M_FONTDATA ((wxFontRefData*)m_refData)
274 // ============================================================================
276 // ============================================================================
278 // ----------------------------------------------------------------------------
280 // ----------------------------------------------------------------------------
282 void wxFontRefData::Init(int pointSize
,
283 const wxSize
& pixelSize
,
284 bool sizeUsingPixels
,
289 const wxString
& faceName
,
290 wxFontEncoding encoding
)
294 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
298 wxFontRefData::~wxFontRefData()
302 bool wxFontRefData::Alloc(wxFont
*font
)
307 void wxFontRefData::Free()
311 // ----------------------------------------------------------------------------
313 // ----------------------------------------------------------------------------
315 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
319 // ----------------------------------------------------------------------------
321 // ----------------------------------------------------------------------------
323 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
328 wxFont::wxFont(const wxString
& fontdesc
)
332 /* Constructor for a font. Note that the real construction is done
333 * in wxDC::SetFont, when information is available about scaling etc.
335 bool wxFont::DoCreate(int pointSize
,
336 const wxSize
& pixelSize
,
337 bool sizeUsingPixels
,
342 const wxString
& faceName
,
343 wxFontEncoding encoding
)
352 // ----------------------------------------------------------------------------
353 // real implementation
354 // ----------------------------------------------------------------------------
355 wxGDIRefData
*wxFont::CreateGDIRefData() const
357 return new wxFontRefData();
360 wxGDIRefData
*wxFont::CloneGDIRefData(const wxGDIRefData
*data
) const
362 return new wxFontRefData(*static_cast<const wxFontRefData
*>(data
));
365 bool wxFont::RealizeResource()
370 bool wxFont::FreeResource(bool WXUNUSED(force
))
375 WXHANDLE
wxFont::GetResourceHandle() const
380 bool wxFont::IsFree() const
385 // ----------------------------------------------------------------------------
386 // change font attribute: we recreate font when doing it
387 // ----------------------------------------------------------------------------
389 void wxFont::SetPointSize(int pointSize
)
393 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
397 void wxFont::SetFamily(wxFontFamily family
)
401 void wxFont::SetStyle(wxFontStyle style
)
405 void wxFont::SetWeight(wxFontWeight weight
)
409 bool wxFont::SetFaceName(const wxString
& faceName
)
414 void wxFont::SetUnderlined(bool underlined
)
418 void wxFont::SetEncoding(wxFontEncoding encoding
)
422 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
426 // ----------------------------------------------------------------------------
428 // ----------------------------------------------------------------------------
430 int wxFont::GetPointSize() const
435 wxSize
wxFont::GetPixelSize() const
440 bool wxFont::IsUsingSizeInPixels() const
445 wxFontFamily
wxFont::DoGetFamily() const
447 return wxFONTFAMILY_ROMAN
;
450 wxFontStyle
wxFont::GetStyle() const
452 return wxFONTSTYLE_NORMAL
;
455 wxFontWeight
wxFont::GetWeight() const
457 return wxFONTWEIGHT_NORMAL
;
460 bool wxFont::GetUnderlined() const
465 wxString
wxFont::GetFaceName() const
467 return wxEmptyString
;
470 wxFontEncoding
wxFont::GetEncoding() const
472 return wxFONTENCODING_SYSTEM
;
475 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
480 wxString
wxFont::GetNativeFontInfoDesc() const
482 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
484 // be sure we have an HFONT associated...
485 wxConstCast(this, wxFont
)->RealizeResource();
486 return wxFontBase::GetNativeFontInfoDesc();
489 wxString
wxFont::GetNativeFontInfoUserDesc() const
491 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
493 // be sure we have an HFONT associated...
494 wxConstCast(this, wxFont
)->RealizeResource();
495 return wxFontBase::GetNativeFontInfoUserDesc();
498 bool wxFont::IsFixedWidth() const