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 #if wxUSE_EXTENDED_RTTI
44 wxBEGIN_ENUM( wxFontFamily
)
45 wxENUM_MEMBER( wxDEFAULT
)
46 wxENUM_MEMBER( wxDECORATIVE
)
47 wxENUM_MEMBER( wxROMAN
)
48 wxENUM_MEMBER( wxSCRIPT
)
49 wxENUM_MEMBER( wxSWISS
)
50 wxENUM_MEMBER( wxMODERN
)
51 wxENUM_MEMBER( wxTELETYPE
)
52 wxEND_ENUM( wxFontFamily
)
54 wxBEGIN_ENUM( wxFontStyle
)
55 wxENUM_MEMBER( wxNORMAL
)
56 wxENUM_MEMBER( wxITALIC
)
57 wxENUM_MEMBER( wxSLANT
)
58 wxEND_ENUM( wxFontStyle
)
60 wxBEGIN_ENUM( wxFontWeight
)
61 wxENUM_MEMBER( wxNORMAL
)
62 wxENUM_MEMBER( wxLIGHT
)
63 wxENUM_MEMBER( wxBOLD
)
64 wxEND_ENUM( wxFontWeight
)
66 IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont
, wxGDIObject
,"wx/font.h")
68 wxBEGIN_PROPERTIES_TABLE(wxFont
)
69 wxPROPERTY( Size
,int, SetPointSize
, GetPointSize
, 12 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
70 wxPROPERTY( Family
, int , SetFamily
, GetFamily
, (int)wxDEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontFamily
71 wxPROPERTY( Style
, int , SetStyle
, GetStyle
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontStyle
72 wxPROPERTY( Weight
, int , SetWeight
, GetWeight
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontWeight
73 wxPROPERTY( Underlined
, bool , SetUnderlined
, GetUnderlined
, false , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
74 wxPROPERTY( Face
, wxString
, SetFaceName
, GetFaceName
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
75 wxPROPERTY( Encoding
, wxFontEncoding
, SetEncoding
, GetEncoding
, wxFONTENCODING_DEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
76 wxEND_PROPERTIES_TABLE()
78 wxCONSTRUCTOR_6( wxFont
, int , Size
, int , Family
, int , Style
, int , Weight
, bool , Underlined
, wxString
, Face
)
80 wxBEGIN_HANDLERS_TABLE(wxFont
)
81 wxEND_HANDLERS_TABLE()
84 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
93 // wxFontRefData - the internal description of the font
94 // ----------------------------------------------------------------------------
96 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
102 Init(-1, wxSize(0, 0), false, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
,
103 wxFONTWEIGHT_NORMAL
, false, wxEmptyString
,
104 wxFONTENCODING_DEFAULT
);
107 wxFontRefData(int size
,
108 const wxSize
& pixelSize
,
109 bool sizeUsingPixels
,
114 const wxString
& faceName
,
115 wxFontEncoding encoding
)
117 Init(size
, pixelSize
, sizeUsingPixels
, family
, style
, weight
,
118 underlined
, faceName
, encoding
);
121 wxFontRefData(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0)
126 wxFontRefData(const wxFontRefData
& data
)
128 if ( data
.m_nativeFontInfoOk
)
130 Init(data
.m_nativeFontInfo
);
134 Init(data
.m_pointSize
, data
.m_pixelSize
, data
.m_sizeUsingPixels
,
135 data
.m_family
, data
.m_style
, data
.m_weight
,
136 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
140 virtual ~wxFontRefData();
143 bool Alloc(wxFont
*font
);
147 // all wxFont accessors
148 int GetPointSize() const
150 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetPointSize()
154 wxSize
GetPixelSize() const
156 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetPixelSize()
160 bool IsUsingSizeInPixels() const
162 return m_nativeFontInfoOk
? true : m_sizeUsingPixels
;
165 int GetFamily() const
172 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetStyle()
176 int GetWeight() const
178 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetWeight()
182 bool GetUnderlined() const
184 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetUnderlined()
188 wxString
GetFaceName() const
191 if ( m_nativeFontInfoOk
)
192 s
= m_nativeFontInfo
.GetFaceName();
199 wxFontEncoding
GetEncoding() const
201 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetEncoding()
205 WXHFONT
GetHFONT() const { return m_hFont
; }
208 void SetPointSize(int pointSize
)
210 if ( m_nativeFontInfoOk
)
212 m_nativeFontInfo
.SetPointSize(pointSize
);
216 m_pointSize
= pointSize
;
217 m_sizeUsingPixels
= false;
221 void SetPixelSize(const wxSize
& pixelSize
)
223 if ( m_nativeFontInfoOk
)
225 m_nativeFontInfo
.SetPixelSize(pixelSize
);
229 m_pixelSize
= pixelSize
;
230 m_sizeUsingPixels
= true;
234 void SetFamily(wxFontFamily family
)
239 void SetStyle(wxFontStyle style
)
241 if ( m_nativeFontInfoOk
)
242 m_nativeFontInfo
.SetStyle((wxFontStyle
)style
);
247 void SetWeight(wxFontWeight weight
)
249 if ( m_nativeFontInfoOk
)
250 m_nativeFontInfo
.SetWeight((wxFontWeight
)weight
);
255 bool SetFaceName(const wxString
& faceName
)
257 if ( m_nativeFontInfoOk
)
258 m_nativeFontInfo
.SetFaceName(faceName
);
260 m_faceName
= faceName
;
263 void SetUnderlined(bool underlined
)
265 if ( m_nativeFontInfoOk
)
266 m_nativeFontInfo
.SetUnderlined(underlined
);
268 m_underlined
= underlined
;
271 void SetEncoding(wxFontEncoding encoding
)
273 if ( m_nativeFontInfoOk
)
274 m_nativeFontInfo
.SetEncoding(encoding
);
276 m_encoding
= encoding
;
279 // native font info tests
280 bool HasNativeFontInfo() const { return m_nativeFontInfoOk
; }
282 const wxNativeFontInfo
& GetNativeFontInfo() const
283 { return m_nativeFontInfo
; }
286 // common part of all ctors
288 const wxSize
& pixelSize
,
289 bool sizeUsingPixels
,
294 const wxString
& faceName
,
295 wxFontEncoding encoding
);
297 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
299 // font characterstics
302 bool m_sizeUsingPixels
;
303 wxFontFamily m_family
;
305 wxFontWeight m_weight
;
308 wxFontEncoding m_encoding
;
310 // Windows font handle
314 wxNativeFontInfo m_nativeFontInfo
;
315 bool m_nativeFontInfoOk
;
318 #define M_FONTDATA ((wxFontRefData*)m_refData)
320 // ============================================================================
322 // ============================================================================
324 // ----------------------------------------------------------------------------
326 // ----------------------------------------------------------------------------
328 void wxFontRefData::Init(int pointSize
,
329 const wxSize
& pixelSize
,
330 bool sizeUsingPixels
,
335 const wxString
& faceName
,
336 wxFontEncoding encoding
)
340 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
344 wxFontRefData::~wxFontRefData()
348 bool wxFontRefData::Alloc(wxFont
*font
)
353 void wxFontRefData::Free()
357 // ----------------------------------------------------------------------------
359 // ----------------------------------------------------------------------------
361 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
365 // ----------------------------------------------------------------------------
367 // ----------------------------------------------------------------------------
369 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
374 wxFont::wxFont(const wxString
& fontdesc
)
378 /* Constructor for a font. Note that the real construction is done
379 * in wxDC::SetFont, when information is available about scaling etc.
381 bool wxFont::DoCreate(int pointSize
,
382 const wxSize
& pixelSize
,
383 bool sizeUsingPixels
,
388 const wxString
& faceName
,
389 wxFontEncoding encoding
)
398 // ----------------------------------------------------------------------------
399 // real implementation
400 // ----------------------------------------------------------------------------
401 wxGDIRefData
*wxFont::CreateGDIRefData() const
403 return new wxFontRefData();
406 wxGDIRefData
*wxFont::CloneGDIRefData(const wxGDIRefData
*data
) const
408 return new wxFontRefData(*static_cast<const wxFontRefData
*>(data
));
411 bool wxFont::RealizeResource()
416 bool wxFont::FreeResource(bool WXUNUSED(force
))
421 WXHANDLE
wxFont::GetResourceHandle() const
426 bool wxFont::IsFree() const
431 // ----------------------------------------------------------------------------
432 // change font attribute: we recreate font when doing it
433 // ----------------------------------------------------------------------------
435 void wxFont::SetPointSize(int pointSize
)
439 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
443 void wxFont::SetFamily(wxFontFamily family
)
447 void wxFont::SetStyle(wxFontStyle style
)
451 void wxFont::SetWeight(wxFontWeight weight
)
455 bool wxFont::SetFaceName(const wxString
& faceName
)
460 void wxFont::SetUnderlined(bool underlined
)
464 void wxFont::SetEncoding(wxFontEncoding encoding
)
468 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
472 // ----------------------------------------------------------------------------
474 // ----------------------------------------------------------------------------
476 int wxFont::GetPointSize() const
481 wxSize
wxFont::GetPixelSize() const
486 bool wxFont::IsUsingSizeInPixels() const
491 wxFontFamily
wxFont::DoGetFamily() const
493 return wxFONTFAMILY_ROMAN
;
496 wxFontStyle
wxFont::GetStyle() const
498 return wxFONTSTYLE_NORMAL
;
501 wxFontWeight
wxFont::GetWeight() const
503 return wxFONTWEIGHT_NORMAL
;
506 bool wxFont::GetUnderlined() const
511 wxString
wxFont::GetFaceName() const
513 return wxEmptyString
;
516 wxFontEncoding
wxFont::GetEncoding() const
518 return wxFONTENCODING_SYSTEM
;
521 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
526 wxString
wxFont::GetNativeFontInfoDesc() const
528 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
530 // be sure we have an HFONT associated...
531 wxConstCast(this, wxFont
)->RealizeResource();
532 return wxFontBase::GetNativeFontInfoDesc();
535 wxString
wxFont::GetNativeFontInfoUserDesc() const
537 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
539 // be sure we have an HFONT associated...
540 wxConstCast(this, wxFont
)->RealizeResource();
541 return wxFontBase::GetNativeFontInfoUserDesc();
544 bool wxFont::IsFixedWidth() const