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(int family
)
239 void SetStyle(int style
)
241 if ( m_nativeFontInfoOk
)
242 m_nativeFontInfo
.SetStyle((wxFontStyle
)style
);
247 void SetWeight(int weight
)
249 if ( m_nativeFontInfoOk
)
250 m_nativeFontInfo
.SetWeight((wxFontWeight
)weight
);
255 void 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
;
308 wxFontEncoding m_encoding
;
310 // Windows font handle
314 wxNativeFontInfo m_nativeFontInfo
;
315 bool m_nativeFontInfoOk
;
318 // ============================================================================
320 // ============================================================================
322 // ----------------------------------------------------------------------------
324 // ----------------------------------------------------------------------------
326 void wxFontRefData::Init(int pointSize
,
327 const wxSize
& pixelSize
,
328 bool sizeUsingPixels
,
333 const wxString
& faceName
,
334 wxFontEncoding encoding
)
338 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
342 wxFontRefData::~wxFontRefData()
346 bool wxFontRefData::Alloc(wxFont
*font
)
351 void wxFontRefData::Free()
355 // ----------------------------------------------------------------------------
357 // ----------------------------------------------------------------------------
359 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
363 // ----------------------------------------------------------------------------
365 // ----------------------------------------------------------------------------
371 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
376 wxFont::wxFont(const wxString
& fontdesc
)
380 /* Constructor for a font. Note that the real construction is done
381 * in wxDC::SetFont, when information is available about scaling etc.
383 bool wxFont::DoCreate(int pointSize
,
384 const wxSize
& pixelSize
,
385 bool sizeUsingPixels
,
390 const wxString
& faceName
,
391 wxFontEncoding encoding
)
400 // ----------------------------------------------------------------------------
401 // real implementation
402 // ----------------------------------------------------------------------------
404 bool wxFont::RealizeResource()
409 bool wxFont::FreeResource(bool WXUNUSED(force
))
414 WXHANDLE
wxFont::GetResourceHandle() const
419 bool wxFont::IsFree() const
424 void wxFont::Unshare()
428 // ----------------------------------------------------------------------------
429 // change font attribute: we recreate font when doing it
430 // ----------------------------------------------------------------------------
432 void wxFont::SetPointSize(int pointSize
)
436 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
440 void wxFont::SetFamily(int family
)
444 void wxFont::SetStyle(int style
)
448 void wxFont::SetWeight(int weight
)
452 void wxFont::SetFaceName(const wxString
& faceName
)
456 void wxFont::SetUnderlined(bool underlined
)
460 void wxFont::SetEncoding(wxFontEncoding encoding
)
464 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
468 // ----------------------------------------------------------------------------
470 // ----------------------------------------------------------------------------
472 int wxFont::GetPointSize() const
477 wxSize
wxFont::GetPixelSize() const
482 bool wxFont::IsUsingSizeInPixels() const
487 int wxFont::GetFamily() const
489 return wxFONTFAMILY_ROMAN
;
492 int wxFont::GetStyle() const
494 return wxFONTSTYLE_NORMAL
;
497 int wxFont::GetWeight() const
499 return wxFONTWEIGHT_NORMAL
;
502 bool wxFont::GetUnderlined() const
507 wxString
wxFont::GetFaceName() const
509 return wxEmptyString
;
512 wxFontEncoding
wxFont::GetEncoding() const
514 return wxFONTENCODING_SYSTEM
;
517 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
522 bool wxFont::IsFixedWidth() const