1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/font.cpp
3 // Purpose: wxFont class
4 // Author: William Osborne
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "font.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
38 #include "wx/encinfo.h"
41 #include "wx/fontutil.h"
42 #include "wx/fontmap.h"
44 #include "wx/tokenzr.h"
46 #if wxUSE_EXTENDED_RTTI
48 wxBEGIN_ENUM( wxFontFamily
)
49 wxENUM_MEMBER( wxDEFAULT
)
50 wxENUM_MEMBER( wxDECORATIVE
)
51 wxENUM_MEMBER( wxROMAN
)
52 wxENUM_MEMBER( wxSCRIPT
)
53 wxENUM_MEMBER( wxSWISS
)
54 wxENUM_MEMBER( wxMODERN
)
55 wxENUM_MEMBER( wxTELETYPE
)
56 wxEND_ENUM( wxFontFamily
)
58 wxBEGIN_ENUM( wxFontStyle
)
59 wxENUM_MEMBER( wxNORMAL
)
60 wxENUM_MEMBER( wxITALIC
)
61 wxENUM_MEMBER( wxSLANT
)
62 wxEND_ENUM( wxFontStyle
)
64 wxBEGIN_ENUM( wxFontWeight
)
65 wxENUM_MEMBER( wxNORMAL
)
66 wxENUM_MEMBER( wxLIGHT
)
67 wxENUM_MEMBER( wxBOLD
)
68 wxEND_ENUM( wxFontWeight
)
70 IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont
, wxGDIObject
,"wx/font.h")
72 wxBEGIN_PROPERTIES_TABLE(wxFont
)
73 wxPROPERTY( Size
,int, SetPointSize
, GetPointSize
, 12 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
74 wxPROPERTY( Family
, int , SetFamily
, GetFamily
, (int)wxDEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontFamily
75 wxPROPERTY( Style
, int , SetStyle
, GetStyle
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontStyle
76 wxPROPERTY( Weight
, int , SetWeight
, GetWeight
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontWeight
77 wxPROPERTY( Underlined
, bool , SetUnderlined
, GetUnderlined
, false , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
78 wxPROPERTY( Face
, wxString
, SetFaceName
, GetFaceName
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
79 wxPROPERTY( Encoding
, wxFontEncoding
, SetEncoding
, GetEncoding
, wxFONTENCODING_DEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
80 wxEND_PROPERTIES_TABLE()
82 wxCONSTRUCTOR_6( wxFont
, int , Size
, int , Family
, int , Style
, int , Weight
, bool , Underlined
, wxString
, Face
)
84 wxBEGIN_HANDLERS_TABLE(wxFont
)
85 wxEND_HANDLERS_TABLE()
88 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
97 // wxFontRefData - the internal description of the font
98 // ----------------------------------------------------------------------------
100 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
106 Init(-1, wxSize(0, 0), FALSE
, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
,
107 wxFONTWEIGHT_NORMAL
, FALSE
, wxEmptyString
,
108 wxFONTENCODING_DEFAULT
);
111 wxFontRefData(int size
,
112 const wxSize
& pixelSize
,
113 bool sizeUsingPixels
,
118 const wxString
& faceName
,
119 wxFontEncoding encoding
)
121 Init(size
, pixelSize
, sizeUsingPixels
, family
, style
, weight
,
122 underlined
, faceName
, encoding
);
125 wxFontRefData(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0)
130 wxFontRefData(const wxFontRefData
& data
)
132 if ( data
.m_nativeFontInfoOk
)
134 Init(data
.m_nativeFontInfo
);
138 Init(data
.m_pointSize
, data
.m_pixelSize
, data
.m_sizeUsingPixels
,
139 data
.m_family
, data
.m_style
, data
.m_weight
,
140 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
144 virtual ~wxFontRefData();
147 bool Alloc(wxFont
*font
);
151 // all wxFont accessors
152 int GetPointSize() const
154 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetPointSize()
158 wxSize
GetPixelSize() const
160 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetPixelSize()
164 bool IsUsingSizeInPixels() const
166 return m_nativeFontInfoOk
? true : m_sizeUsingPixels
;
169 int GetFamily() const
176 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetStyle()
180 int GetWeight() const
182 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetWeight()
186 bool GetUnderlined() const
188 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetUnderlined()
192 wxString
GetFaceName() const
195 if ( m_nativeFontInfoOk
)
196 s
= m_nativeFontInfo
.GetFaceName();
203 wxFontEncoding
GetEncoding() const
205 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetEncoding()
209 WXHFONT
GetHFONT() const { return m_hFont
; }
212 void SetPointSize(int pointSize
)
214 if ( m_nativeFontInfoOk
)
216 m_nativeFontInfo
.SetPointSize(pointSize
);
220 m_pointSize
= pointSize
;
221 m_sizeUsingPixels
= FALSE
;
225 void SetPixelSize(const wxSize
& pixelSize
)
227 if ( m_nativeFontInfoOk
)
229 m_nativeFontInfo
.SetPixelSize(pixelSize
);
233 m_pixelSize
= pixelSize
;
234 m_sizeUsingPixels
= TRUE
;
238 void SetFamily(int family
)
243 void SetStyle(int style
)
245 if ( m_nativeFontInfoOk
)
246 m_nativeFontInfo
.SetStyle((wxFontStyle
)style
);
251 void SetWeight(int weight
)
253 if ( m_nativeFontInfoOk
)
254 m_nativeFontInfo
.SetWeight((wxFontWeight
)weight
);
259 void SetFaceName(const wxString
& faceName
)
261 if ( m_nativeFontInfoOk
)
262 m_nativeFontInfo
.SetFaceName(faceName
);
264 m_faceName
= faceName
;
267 void SetUnderlined(bool underlined
)
269 if ( m_nativeFontInfoOk
)
270 m_nativeFontInfo
.SetUnderlined(underlined
);
272 m_underlined
= underlined
;
275 void SetEncoding(wxFontEncoding encoding
)
277 if ( m_nativeFontInfoOk
)
278 m_nativeFontInfo
.SetEncoding(encoding
);
280 m_encoding
= encoding
;
283 // native font info tests
284 bool HasNativeFontInfo() const { return m_nativeFontInfoOk
; }
286 const wxNativeFontInfo
& GetNativeFontInfo() const
287 { return m_nativeFontInfo
; }
290 // common part of all ctors
292 const wxSize
& pixelSize
,
293 bool sizeUsingPixels
,
298 const wxString
& faceName
,
299 wxFontEncoding encoding
);
301 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
303 // font characterstics
306 bool m_sizeUsingPixels
;
312 wxFontEncoding m_encoding
;
314 // Windows font handle
318 wxNativeFontInfo m_nativeFontInfo
;
319 bool m_nativeFontInfoOk
;
322 // ============================================================================
324 // ============================================================================
326 // ----------------------------------------------------------------------------
328 // ----------------------------------------------------------------------------
330 void wxFontRefData::Init(int pointSize
,
331 const wxSize
& pixelSize
,
332 bool sizeUsingPixels
,
337 const wxString
& faceName
,
338 wxFontEncoding encoding
)
342 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
346 wxFontRefData::~wxFontRefData()
350 bool wxFontRefData::Alloc(wxFont
*font
)
355 void wxFontRefData::Free()
359 // ----------------------------------------------------------------------------
361 // ----------------------------------------------------------------------------
363 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
367 // ----------------------------------------------------------------------------
369 // ----------------------------------------------------------------------------
375 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
380 wxFont::wxFont(const wxString
& fontdesc
)
384 /* Constructor for a font. Note that the real construction is done
385 * in wxDC::SetFont, when information is available about scaling etc.
387 bool wxFont::DoCreate(int pointSize
,
388 const wxSize
& pixelSize
,
389 bool sizeUsingPixels
,
394 const wxString
& faceName
,
395 wxFontEncoding encoding
)
404 // ----------------------------------------------------------------------------
405 // real implementation
406 // ----------------------------------------------------------------------------
408 bool wxFont::RealizeResource()
413 bool wxFont::FreeResource(bool WXUNUSED(force
))
418 WXHANDLE
wxFont::GetResourceHandle() const
423 WXHFONT
wxFont::GetHFONT() const
428 bool wxFont::IsFree() const
433 void wxFont::Unshare()
437 // ----------------------------------------------------------------------------
438 // change font attribute: we recreate font when doing it
439 // ----------------------------------------------------------------------------
441 void wxFont::SetPointSize(int pointSize
)
445 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
449 void wxFont::SetFamily(int family
)
453 void wxFont::SetStyle(int style
)
457 void wxFont::SetWeight(int weight
)
461 void wxFont::SetFaceName(const wxString
& faceName
)
465 void wxFont::SetUnderlined(bool underlined
)
469 void wxFont::SetEncoding(wxFontEncoding encoding
)
473 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
477 // ----------------------------------------------------------------------------
479 // ----------------------------------------------------------------------------
481 int wxFont::GetPointSize() const
486 wxSize
wxFont::GetPixelSize() const
491 bool wxFont::IsUsingSizeInPixels() const
496 int wxFont::GetFamily() const
498 return wxFONTFAMILY_ROMAN
;
501 int wxFont::GetStyle() const
503 return wxFONTSTYLE_NORMAL
;
506 int wxFont::GetWeight() const
508 return wxFONTWEIGHT_NORMAL
;
511 bool wxFont::GetUnderlined() const
516 wxString
wxFont::GetFaceName() const
518 return wxEmptyString
;
521 wxFontEncoding
wxFont::GetEncoding() const
523 return wxFONTENCODING_SYSTEM
;
526 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
531 bool wxFont::IsFixedWidth() const