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     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
; 
 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 // ---------------------------------------------------------------------------- 
 367 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
) 
 372 wxFont::wxFont(const wxString
& fontdesc
) 
 376 /* Constructor for a font. Note that the real construction is done 
 377  * in wxDC::SetFont, when information is available about scaling etc. 
 379 bool wxFont::DoCreate(int pointSize
, 
 380                       const wxSize
& pixelSize
, 
 381                       bool sizeUsingPixels
, 
 386                       const wxString
& faceName
, 
 387                       wxFontEncoding encoding
) 
 396 // ---------------------------------------------------------------------------- 
 397 // real implementation 
 398 // ---------------------------------------------------------------------------- 
 400 bool wxFont::RealizeResource() 
 405 bool wxFont::FreeResource(bool WXUNUSED(force
)) 
 410 WXHANDLE 
wxFont::GetResourceHandle() const 
 415 bool wxFont::IsFree() const 
 420 void wxFont::Unshare() 
 424 // ---------------------------------------------------------------------------- 
 425 // change font attribute: we recreate font when doing it 
 426 // ---------------------------------------------------------------------------- 
 428 void wxFont::SetPointSize(int pointSize
) 
 432 void wxFont::SetPixelSize(const wxSize
& pixelSize
) 
 436 void wxFont::SetFamily(int family
) 
 440 void wxFont::SetStyle(int style
) 
 444 void wxFont::SetWeight(int weight
) 
 448 bool wxFont::SetFaceName(const wxString
& faceName
) 
 453 void wxFont::SetUnderlined(bool underlined
) 
 457 void wxFont::SetEncoding(wxFontEncoding encoding
) 
 461 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
) 
 465 // ---------------------------------------------------------------------------- 
 467 // ---------------------------------------------------------------------------- 
 469 int wxFont::GetPointSize() const 
 474 wxSize 
wxFont::GetPixelSize() const 
 479 bool wxFont::IsUsingSizeInPixels() const 
 484 int wxFont::GetFamily() const 
 486     return wxFONTFAMILY_ROMAN
; 
 489 int wxFont::GetStyle() const 
 491     return wxFONTSTYLE_NORMAL
; 
 494 int wxFont::GetWeight() const 
 496     return wxFONTWEIGHT_NORMAL
; 
 499 bool wxFont::GetUnderlined() const 
 504 wxString 
wxFont::GetFaceName() const 
 506     return wxEmptyString
; 
 509 wxFontEncoding 
wxFont::GetEncoding() const 
 511     return wxFONTENCODING_SYSTEM
; 
 514 const wxNativeFontInfo 
*wxFont::GetNativeFontInfo() const 
 519 bool wxFont::IsFixedWidth() const