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"
33 #include "wx/encinfo.h"
36 #include "wx/fontutil.h"
37 #include "wx/fontmap.h"
39 #include "wx/tokenzr.h"
41 #if wxUSE_EXTENDED_RTTI
43 wxBEGIN_ENUM( wxFontFamily
)
44 wxENUM_MEMBER( wxDEFAULT
)
45 wxENUM_MEMBER( wxDECORATIVE
)
46 wxENUM_MEMBER( wxROMAN
)
47 wxENUM_MEMBER( wxSCRIPT
)
48 wxENUM_MEMBER( wxSWISS
)
49 wxENUM_MEMBER( wxMODERN
)
50 wxENUM_MEMBER( wxTELETYPE
)
51 wxEND_ENUM( wxFontFamily
)
53 wxBEGIN_ENUM( wxFontStyle
)
54 wxENUM_MEMBER( wxNORMAL
)
55 wxENUM_MEMBER( wxITALIC
)
56 wxENUM_MEMBER( wxSLANT
)
57 wxEND_ENUM( wxFontStyle
)
59 wxBEGIN_ENUM( wxFontWeight
)
60 wxENUM_MEMBER( wxNORMAL
)
61 wxENUM_MEMBER( wxLIGHT
)
62 wxENUM_MEMBER( wxBOLD
)
63 wxEND_ENUM( wxFontWeight
)
65 IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont
, wxGDIObject
,"wx/font.h")
67 wxBEGIN_PROPERTIES_TABLE(wxFont
)
68 wxPROPERTY( Size
,int, SetPointSize
, GetPointSize
, 12 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
69 wxPROPERTY( Family
, int , SetFamily
, GetFamily
, (int)wxDEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontFamily
70 wxPROPERTY( Style
, int , SetStyle
, GetStyle
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontStyle
71 wxPROPERTY( Weight
, int , SetWeight
, GetWeight
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontWeight
72 wxPROPERTY( Underlined
, bool , SetUnderlined
, GetUnderlined
, false , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
73 wxPROPERTY( Face
, wxString
, SetFaceName
, GetFaceName
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
74 wxPROPERTY( Encoding
, wxFontEncoding
, SetEncoding
, GetEncoding
, wxFONTENCODING_DEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
75 wxEND_PROPERTIES_TABLE()
77 wxCONSTRUCTOR_6( wxFont
, int , Size
, int , Family
, int , Style
, int , Weight
, bool , Underlined
, wxString
, Face
)
79 wxBEGIN_HANDLERS_TABLE(wxFont
)
80 wxEND_HANDLERS_TABLE()
83 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
87 // ----------------------------------------------------------------------------
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
92 // wxFontRefData - the internal description of the font
93 // ----------------------------------------------------------------------------
95 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
101 Init(-1, wxSize(0, 0), false, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
,
102 wxFONTWEIGHT_NORMAL
, false, wxEmptyString
,
103 wxFONTENCODING_DEFAULT
);
106 wxFontRefData(int size
,
107 const wxSize
& pixelSize
,
108 bool sizeUsingPixels
,
113 const wxString
& faceName
,
114 wxFontEncoding encoding
)
116 Init(size
, pixelSize
, sizeUsingPixels
, family
, style
, weight
,
117 underlined
, faceName
, encoding
);
120 wxFontRefData(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0)
125 wxFontRefData(const wxFontRefData
& data
)
127 if ( data
.m_nativeFontInfoOk
)
129 Init(data
.m_nativeFontInfo
);
133 Init(data
.m_pointSize
, data
.m_pixelSize
, data
.m_sizeUsingPixels
,
134 data
.m_family
, data
.m_style
, data
.m_weight
,
135 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
139 virtual ~wxFontRefData();
142 bool Alloc(wxFont
*font
);
146 // all wxFont accessors
147 int GetPointSize() const
149 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetPointSize()
153 wxSize
GetPixelSize() const
155 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetPixelSize()
159 bool IsUsingSizeInPixels() const
161 return m_nativeFontInfoOk
? true : m_sizeUsingPixels
;
164 int GetFamily() const
171 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetStyle()
175 int GetWeight() const
177 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetWeight()
181 bool GetUnderlined() const
183 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetUnderlined()
187 wxString
GetFaceName() const
190 if ( m_nativeFontInfoOk
)
191 s
= m_nativeFontInfo
.GetFaceName();
198 wxFontEncoding
GetEncoding() const
200 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetEncoding()
204 WXHFONT
GetHFONT() const { return m_hFont
; }
207 void SetPointSize(int pointSize
)
209 if ( m_nativeFontInfoOk
)
211 m_nativeFontInfo
.SetPointSize(pointSize
);
215 m_pointSize
= pointSize
;
216 m_sizeUsingPixels
= false;
220 void SetPixelSize(const wxSize
& pixelSize
)
222 if ( m_nativeFontInfoOk
)
224 m_nativeFontInfo
.SetPixelSize(pixelSize
);
228 m_pixelSize
= pixelSize
;
229 m_sizeUsingPixels
= true;
233 void SetFamily(int family
)
238 void SetStyle(int style
)
240 if ( m_nativeFontInfoOk
)
241 m_nativeFontInfo
.SetStyle((wxFontStyle
)style
);
246 void SetWeight(int weight
)
248 if ( m_nativeFontInfoOk
)
249 m_nativeFontInfo
.SetWeight((wxFontWeight
)weight
);
254 void SetFaceName(const wxString
& faceName
)
256 if ( m_nativeFontInfoOk
)
257 m_nativeFontInfo
.SetFaceName(faceName
);
259 m_faceName
= faceName
;
262 void SetUnderlined(bool underlined
)
264 if ( m_nativeFontInfoOk
)
265 m_nativeFontInfo
.SetUnderlined(underlined
);
267 m_underlined
= underlined
;
270 void SetEncoding(wxFontEncoding encoding
)
272 if ( m_nativeFontInfoOk
)
273 m_nativeFontInfo
.SetEncoding(encoding
);
275 m_encoding
= encoding
;
278 // native font info tests
279 bool HasNativeFontInfo() const { return m_nativeFontInfoOk
; }
281 const wxNativeFontInfo
& GetNativeFontInfo() const
282 { return m_nativeFontInfo
; }
285 // common part of all ctors
287 const wxSize
& pixelSize
,
288 bool sizeUsingPixels
,
293 const wxString
& faceName
,
294 wxFontEncoding encoding
);
296 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
298 // font characterstics
301 bool m_sizeUsingPixels
;
307 wxFontEncoding m_encoding
;
309 // Windows font handle
313 wxNativeFontInfo m_nativeFontInfo
;
314 bool m_nativeFontInfoOk
;
317 // ============================================================================
319 // ============================================================================
321 // ----------------------------------------------------------------------------
323 // ----------------------------------------------------------------------------
325 void wxFontRefData::Init(int pointSize
,
326 const wxSize
& pixelSize
,
327 bool sizeUsingPixels
,
332 const wxString
& faceName
,
333 wxFontEncoding encoding
)
337 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
341 wxFontRefData::~wxFontRefData()
345 bool wxFontRefData::Alloc(wxFont
*font
)
350 void wxFontRefData::Free()
354 // ----------------------------------------------------------------------------
356 // ----------------------------------------------------------------------------
358 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
362 // ----------------------------------------------------------------------------
364 // ----------------------------------------------------------------------------
370 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
375 wxFont::wxFont(const wxString
& fontdesc
)
379 /* Constructor for a font. Note that the real construction is done
380 * in wxDC::SetFont, when information is available about scaling etc.
382 bool wxFont::DoCreate(int pointSize
,
383 const wxSize
& pixelSize
,
384 bool sizeUsingPixels
,
389 const wxString
& faceName
,
390 wxFontEncoding encoding
)
399 // ----------------------------------------------------------------------------
400 // real implementation
401 // ----------------------------------------------------------------------------
403 bool wxFont::RealizeResource()
408 bool wxFont::FreeResource(bool WXUNUSED(force
))
413 WXHANDLE
wxFont::GetResourceHandle() const
418 bool wxFont::IsFree() const
423 void wxFont::Unshare()
427 // ----------------------------------------------------------------------------
428 // change font attribute: we recreate font when doing it
429 // ----------------------------------------------------------------------------
431 void wxFont::SetPointSize(int pointSize
)
435 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
439 void wxFont::SetFamily(int family
)
443 void wxFont::SetStyle(int style
)
447 void wxFont::SetWeight(int weight
)
451 void wxFont::SetFaceName(const wxString
& faceName
)
455 void wxFont::SetUnderlined(bool underlined
)
459 void wxFont::SetEncoding(wxFontEncoding encoding
)
463 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
467 // ----------------------------------------------------------------------------
469 // ----------------------------------------------------------------------------
471 int wxFont::GetPointSize() const
476 wxSize
wxFont::GetPixelSize() const
481 bool wxFont::IsUsingSizeInPixels() const
486 int wxFont::GetFamily() const
488 return wxFONTFAMILY_ROMAN
;
491 int wxFont::GetStyle() const
493 return wxFONTSTYLE_NORMAL
;
496 int wxFont::GetWeight() const
498 return wxFONTWEIGHT_NORMAL
;
501 bool wxFont::GetUnderlined() const
506 wxString
wxFont::GetFaceName() const
508 return wxEmptyString
;
511 wxFontEncoding
wxFont::GetEncoding() const
513 return wxFONTENCODING_SYSTEM
;
516 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
521 bool wxFont::IsFixedWidth() const