1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/font.cpp
3 // Purpose: wxFont class
4 // Author: Julian Smart
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/msw/private.h"
39 #include "wx/fontutil.h"
40 #include "wx/fontmap.h"
42 #include "wx/tokenzr.h"
44 #if wxUSE_EXTENDED_RTTI
46 wxBEGIN_ENUM( wxFontFamily
)
47 wxENUM_MEMBER( wxDEFAULT
)
48 wxENUM_MEMBER( wxDECORATIVE
)
49 wxENUM_MEMBER( wxROMAN
)
50 wxENUM_MEMBER( wxSCRIPT
)
51 wxENUM_MEMBER( wxSWISS
)
52 wxENUM_MEMBER( wxMODERN
)
53 wxENUM_MEMBER( wxTELETYPE
)
54 wxEND_ENUM( wxFontFamily
)
56 wxBEGIN_ENUM( wxFontStyle
)
57 wxENUM_MEMBER( wxNORMAL
)
58 wxENUM_MEMBER( wxITALIC
)
59 wxENUM_MEMBER( wxSLANT
)
60 wxEND_ENUM( wxFontStyle
)
62 wxBEGIN_ENUM( wxFontWeight
)
63 wxENUM_MEMBER( wxNORMAL
)
64 wxENUM_MEMBER( wxLIGHT
)
65 wxENUM_MEMBER( wxBOLD
)
66 wxEND_ENUM( wxFontWeight
)
68 IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont
, wxGDIObject
,"wx/font.h")
70 wxBEGIN_PROPERTIES_TABLE(wxFont
)
71 wxPROPERTY( Size
,int, SetPointSize
, GetPointSize
, 12 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
72 wxPROPERTY( Family
, int , SetFamily
, GetFamily
, (int)wxDEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontFamily
73 wxPROPERTY( Style
, int , SetStyle
, GetStyle
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontStyle
74 wxPROPERTY( Weight
, int , SetWeight
, GetWeight
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontWeight
75 wxPROPERTY( Underlined
, bool , SetUnderlined
, GetUnderlined
, false , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
76 wxPROPERTY( Face
, wxString
, SetFaceName
, GetFaceName
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
77 wxPROPERTY( Encoding
, wxFontEncoding
, SetEncoding
, GetEncoding
, wxFONTENCODING_DEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
78 wxEND_PROPERTIES_TABLE()
80 wxCONSTRUCTOR_6( wxFont
, int , Size
, int , Family
, int , Style
, int , Weight
, bool , Underlined
, wxString
, Face
)
82 wxBEGIN_HANDLERS_TABLE(wxFont
)
83 wxEND_HANDLERS_TABLE()
86 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 // the mask used to extract the pitch from LOGFONT::lfPitchAndFamily field
95 static const int PITCH_MASK
= FIXED_PITCH
| VARIABLE_PITCH
;
97 // ----------------------------------------------------------------------------
98 // wxFontRefData - the internal description of the font
99 // ----------------------------------------------------------------------------
101 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
107 Init(-1, wxSize(0,0), false, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
,
108 wxFONTWEIGHT_NORMAL
, false, wxEmptyString
,
109 wxFONTENCODING_DEFAULT
);
112 wxFontRefData(int size
,
113 const wxSize
& pixelSize
,
114 bool sizeUsingPixels
,
119 const wxString
& faceName
,
120 wxFontEncoding encoding
)
122 Init(size
, pixelSize
, sizeUsingPixels
, family
, style
, weight
,
123 underlined
, faceName
, encoding
);
126 wxFontRefData(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0)
131 wxFontRefData(const wxFontRefData
& data
) : wxGDIRefData()
133 if ( data
.m_nativeFontInfoOk
)
135 Init(data
.m_nativeFontInfo
);
139 Init(data
.m_pointSize
, data
.m_pixelSize
, data
.m_sizeUsingPixels
,
140 data
.m_family
, data
.m_style
, data
.m_weight
,
141 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
145 virtual ~wxFontRefData();
148 bool Alloc(const wxFont
*font
);
152 // all wxFont accessors
153 int GetPointSize() const
155 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetPointSize()
159 wxSize
GetPixelSize() const
161 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetPixelSize()
165 bool IsUsingSizeInPixels() const
167 return m_nativeFontInfoOk
? true : m_sizeUsingPixels
;
170 int GetFamily() const
177 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetStyle()
181 int GetWeight() const
183 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetWeight()
187 bool GetUnderlined() const
189 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetUnderlined()
193 wxString
GetFaceName() const
196 if ( m_nativeFontInfoOk
)
197 s
= m_nativeFontInfo
.GetFaceName();
204 wxFontEncoding
GetEncoding() const
206 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetEncoding()
210 WXHFONT
GetHFONT(const wxFont
*font
) const
213 wx_const_cast(wxFontRefData
*, this)->Alloc(font
);
215 return (WXHFONT
)m_hFont
;
218 bool HasHFONT() const
223 // ... and setters: notice that all of them invalidate the currently
224 // allocated HFONT, if any, so that the next call to GetHFONT() recreates a
226 void SetPointSize(int pointSize
)
230 if ( m_nativeFontInfoOk
)
232 m_nativeFontInfo
.SetPointSize(pointSize
);
236 m_pointSize
= pointSize
;
237 m_sizeUsingPixels
= false;
241 void SetPixelSize(const wxSize
& pixelSize
)
245 if ( m_nativeFontInfoOk
)
247 m_nativeFontInfo
.SetPixelSize(pixelSize
);
251 m_pixelSize
= pixelSize
;
252 m_sizeUsingPixels
= true;
256 void SetFamily(int family
)
263 void SetStyle(int style
)
267 if ( m_nativeFontInfoOk
)
268 m_nativeFontInfo
.SetStyle((wxFontStyle
)style
);
273 void SetWeight(int weight
)
277 if ( m_nativeFontInfoOk
)
278 m_nativeFontInfo
.SetWeight((wxFontWeight
)weight
);
283 bool SetFaceName(const wxString
& faceName
)
287 if ( m_nativeFontInfoOk
)
288 return m_nativeFontInfo
.SetFaceName(faceName
);
290 m_faceName
= faceName
;
294 void SetUnderlined(bool underlined
)
298 if ( m_nativeFontInfoOk
)
299 m_nativeFontInfo
.SetUnderlined(underlined
);
301 m_underlined
= underlined
;
304 void SetEncoding(wxFontEncoding encoding
)
308 if ( m_nativeFontInfoOk
)
309 m_nativeFontInfo
.SetEncoding(encoding
);
311 m_encoding
= encoding
;
315 bool HasNativeFontInfo() const { return m_nativeFontInfoOk
; }
317 const wxNativeFontInfo
& GetNativeFontInfo() const
318 { return m_nativeFontInfo
; }
320 void SetNativeFontInfo(const wxNativeFontInfo
& nativeFontInfo
)
321 { Free(); m_nativeFontInfo
= nativeFontInfo
; }
324 // common part of all ctors
326 const wxSize
& pixelSize
,
327 bool sizeUsingPixels
,
332 const wxString
& faceName
,
333 wxFontEncoding encoding
);
335 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
337 // font characteristics
340 bool m_sizeUsingPixels
;
346 wxFontEncoding m_encoding
;
348 // Windows font handle, created on demand in GetHFONT()
352 wxNativeFontInfo m_nativeFontInfo
;
353 bool m_nativeFontInfoOk
;
356 #define M_FONTDATA ((wxFontRefData*)m_refData)
358 // ============================================================================
360 // ============================================================================
362 // ----------------------------------------------------------------------------
364 // ----------------------------------------------------------------------------
366 void wxFontRefData::Init(int pointSize
,
367 const wxSize
& pixelSize
,
368 bool sizeUsingPixels
,
373 const wxString
& faceName
,
374 wxFontEncoding encoding
)
377 m_pointSize
= pointSize
== -1 ? wxNORMAL_FONT
->GetPointSize() : pointSize
;
378 m_pixelSize
= pixelSize
;
379 m_sizeUsingPixels
= sizeUsingPixels
;
383 m_underlined
= underlined
;
384 m_faceName
= faceName
;
385 m_encoding
= encoding
;
389 m_nativeFontInfoOk
= false;
392 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
394 // hFont may be zero, or it be passed in case we really want to
395 // use the exact font created in the underlying system
396 // (for example where we can't guarantee conversion from HFONT
397 // to LOGFONT back to HFONT)
398 m_hFont
= (HFONT
)hFont
;
400 m_nativeFontInfoOk
= true;
401 m_nativeFontInfo
= info
;
402 // This is the best we can do since we don't have the
403 // correct information at this point.
407 wxFontRefData::~wxFontRefData()
412 bool wxFontRefData::Alloc(const wxFont
*font
)
414 if ( !m_nativeFontInfoOk
)
416 wxFillLogFont(&m_nativeFontInfo
.lf
, font
);
417 m_nativeFontInfoOk
= true;
420 m_hFont
= ::CreateFontIndirect(&m_nativeFontInfo
.lf
);
423 wxLogLastError(wxT("CreateFont"));
430 void wxFontRefData::Free()
434 if ( !::DeleteObject(m_hFont
) )
436 wxLogLastError(wxT("DeleteObject(font)"));
443 // ----------------------------------------------------------------------------
445 // ----------------------------------------------------------------------------
447 void wxNativeFontInfo::Init()
451 // we get better font quality if we use this instead of DEFAULT_QUALITY
452 // apparently without any drawbacks
454 lf
.lfQuality
= CLEARTYPE_QUALITY
;
456 lf
.lfQuality
= PROOF_QUALITY
;
460 int wxNativeFontInfo::GetPointSize() const
462 // FIXME: using the screen here results in incorrect font size calculation
464 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
466 return (int) (((72.0*(double)abs(lf
.lfHeight
)) / (double) ppInch
) + 0.5);
469 wxSize
wxNativeFontInfo::GetPixelSize() const
472 ret
.SetHeight(lf
.lfHeight
);
473 ret
.SetWidth(lf
.lfWidth
);
477 wxFontStyle
wxNativeFontInfo::GetStyle() const
479 return lf
.lfItalic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
;
482 wxFontWeight
wxNativeFontInfo::GetWeight() const
484 if ( lf
.lfWeight
<= 300 )
485 return wxFONTWEIGHT_LIGHT
;
487 if ( lf
.lfWeight
>= 600 )
488 return wxFONTWEIGHT_BOLD
;
490 return wxFONTWEIGHT_NORMAL
;
493 bool wxNativeFontInfo::GetUnderlined() const
495 return lf
.lfUnderline
!= 0;
498 wxString
wxNativeFontInfo::GetFaceName() const
500 return lf
.lfFaceName
;
503 wxFontFamily
wxNativeFontInfo::GetFamily() const
507 // extract family from pitch-and-family
508 switch ( lf
.lfPitchAndFamily
& ~PITCH_MASK
)
511 family
= wxFONTFAMILY_ROMAN
;
515 wxFAIL_MSG( _T("unknown LOGFONT::lfFamily value") );
519 family
= wxFONTFAMILY_SWISS
;
523 family
= wxFONTFAMILY_SCRIPT
;
527 family
= wxFONTFAMILY_MODERN
;
531 family
= wxFONTFAMILY_DECORATIVE
;
538 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
540 return wxGetFontEncFromCharSet(lf
.lfCharSet
);
543 void wxNativeFontInfo::SetPointSize(int pointsize
)
545 // FIXME: using the screen here results in incorrect font size calculation
547 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
549 lf
.lfHeight
= -(int)((pointsize
*((double)ppInch
)/72.0) + 0.5);
552 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
554 lf
.lfHeight
= pixelSize
.GetHeight();
555 lf
.lfWidth
= pixelSize
.GetWidth();
559 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
564 wxFAIL_MSG( _T("unknown font style") );
567 case wxFONTSTYLE_NORMAL
:
571 case wxFONTSTYLE_ITALIC
:
572 case wxFONTSTYLE_SLANT
:
578 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
583 wxFAIL_MSG( _T("unknown font weight") );
586 case wxFONTWEIGHT_NORMAL
:
587 lf
.lfWeight
= FW_NORMAL
;
590 case wxFONTWEIGHT_LIGHT
:
591 lf
.lfWeight
= FW_LIGHT
;
594 case wxFONTWEIGHT_BOLD
:
595 lf
.lfWeight
= FW_BOLD
;
600 void wxNativeFontInfo::SetUnderlined(bool underlined
)
602 lf
.lfUnderline
= underlined
;
605 bool wxNativeFontInfo::SetFaceName(const wxString
& facename
)
607 size_t len
= WXSIZEOF(lf
.lfFaceName
);
608 wxStrncpy(lf
.lfFaceName
, facename
, len
);
609 lf
.lfFaceName
[len
- 1] = '\0'; // truncate the face name
613 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
616 wxArrayString facename
;
618 // the list of fonts associated with a family was partially
619 // taken from http://www.codestyle.org/css/font-family
624 ff_family
= FF_SCRIPT
;
625 facename
.Add(_T("Script"));
626 facename
.Add(_T("Brush Script MT"));
627 facename
.Add(_T("Comic Sans MS"));
628 facename
.Add(_T("Lucida Handwriting"));
632 ff_family
= FF_DECORATIVE
;
633 facename
.Add(_T("Old English Text MT"));
634 facename
.Add(_T("Comic Sans MS"));
635 facename
.Add(_T("Lucida Handwriting"));
639 ff_family
= FF_ROMAN
;
640 facename
.Add(_T("Times New Roman"));
641 facename
.Add(_T("Georgia"));
642 facename
.Add(_T("Garamond"));
643 facename
.Add(_T("Bookman Old Style"));
644 facename
.Add(_T("Book Antiqua"));
649 ff_family
= FF_MODERN
;
650 facename
.Add(_T("Courier New"));
651 facename
.Add(_T("Lucida Console"));
652 facename
.Add(_T("Andale Mono"));
653 facename
.Add(_T("OCR A Extended"));
654 facename
.Add(_T("Terminal"));
658 ff_family
= FF_SWISS
;
659 facename
.Add(_T("Arial"));
660 facename
.Add(_T("Century Gothic"));
661 facename
.Add(_T("Lucida Sans Unicode"));
662 facename
.Add(_T("Tahoma"));
663 facename
.Add(_T("Trebuchet MS"));
664 facename
.Add(_T("Verdana"));
670 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
671 // is returned as default GUI font for compatibility
673 ff_family
= FF_SWISS
;
674 if(wxGetOsVersion(&verMaj
) == wxOS_WINDOWS_NT
&& verMaj
>= 5)
675 facename
.Add(_T("MS Shell Dlg 2"));
677 facename
.Add(_T("MS Shell Dlg"));
680 // "MS Shell Dlg is a mapping mechanism that enables
681 // U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
682 // support locales that have characters that are not contained in code
683 // page 1252. It is not a font but a face name for a nonexistent font."
687 lf
.lfPitchAndFamily
= (BYTE
)(DEFAULT_PITCH
) | ff_family
;
689 if ( !wxStrlen(lf
.lfFaceName
) )
691 SetFaceName(facename
);
695 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
697 wxNativeEncodingInfo info
;
698 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
701 if ( wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
703 if ( !info
.facename
.empty() )
705 // if we have this encoding only in some particular facename, use
706 // the facename - it is better to show the correct characters in a
707 // wrong facename than unreadable text in a correct one
708 SetFaceName(info
.facename
);
712 #endif // wxUSE_FONTMAP
714 // unsupported encoding, replace with the default
715 info
.charset
= DEFAULT_CHARSET
;
719 lf
.lfCharSet
= (BYTE
)info
.charset
;
722 bool wxNativeFontInfo::FromString(const wxString
& s
)
726 wxStringTokenizer
tokenizer(s
, _T(";"));
729 wxString token
= tokenizer
.GetNextToken();
730 if ( token
!= _T('0') )
733 token
= tokenizer
.GetNextToken();
734 if ( !token
.ToLong(&l
) )
738 token
= tokenizer
.GetNextToken();
739 if ( !token
.ToLong(&l
) )
743 token
= tokenizer
.GetNextToken();
744 if ( !token
.ToLong(&l
) )
748 token
= tokenizer
.GetNextToken();
749 if ( !token
.ToLong(&l
) )
751 lf
.lfOrientation
= l
;
753 token
= tokenizer
.GetNextToken();
754 if ( !token
.ToLong(&l
) )
758 token
= tokenizer
.GetNextToken();
759 if ( !token
.ToLong(&l
) )
761 lf
.lfItalic
= (BYTE
)l
;
763 token
= tokenizer
.GetNextToken();
764 if ( !token
.ToLong(&l
) )
766 lf
.lfUnderline
= (BYTE
)l
;
768 token
= tokenizer
.GetNextToken();
769 if ( !token
.ToLong(&l
) )
771 lf
.lfStrikeOut
= (BYTE
)l
;
773 token
= tokenizer
.GetNextToken();
774 if ( !token
.ToLong(&l
) )
776 lf
.lfCharSet
= (BYTE
)l
;
778 token
= tokenizer
.GetNextToken();
779 if ( !token
.ToLong(&l
) )
781 lf
.lfOutPrecision
= (BYTE
)l
;
783 token
= tokenizer
.GetNextToken();
784 if ( !token
.ToLong(&l
) )
786 lf
.lfClipPrecision
= (BYTE
)l
;
788 token
= tokenizer
.GetNextToken();
789 if ( !token
.ToLong(&l
) )
791 lf
.lfQuality
= (BYTE
)l
;
793 token
= tokenizer
.GetNextToken();
794 if ( !token
.ToLong(&l
) )
796 lf
.lfPitchAndFamily
= (BYTE
)l
;
798 token
= tokenizer
.GetNextToken();
801 wxStrcpy(lf
.lfFaceName
, token
.c_str());
806 wxString
wxNativeFontInfo::ToString() const
810 s
.Printf(_T("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
811 0, // version, in case we want to change the format later
825 (const wxChar
*)lf
.lfFaceName
);
830 // ----------------------------------------------------------------------------
832 // ----------------------------------------------------------------------------
834 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
838 m_refData
= new wxFontRefData(info
, hFont
);
840 return RealizeResource();
843 wxFont::wxFont(const wxString
& fontdesc
)
845 wxNativeFontInfo info
;
846 if ( info
.FromString(fontdesc
) )
850 bool wxFont::DoCreate(int pointSize
,
851 const wxSize
& pixelSize
,
852 bool sizeUsingPixels
,
857 const wxString
& faceName
,
858 wxFontEncoding encoding
)
862 // wxDEFAULT is a valid value for the font size too so we must treat it
863 // specially here (otherwise the size would be 70 == wxDEFAULT value)
864 if ( pointSize
== wxDEFAULT
)
866 pointSize
= wxNORMAL_FONT
->GetPointSize();
869 m_refData
= new wxFontRefData(pointSize
, pixelSize
, sizeUsingPixels
,
870 family
, style
, weight
,
871 underlined
, faceName
, encoding
);
873 return RealizeResource();
880 // ----------------------------------------------------------------------------
881 // real implementation
882 // ----------------------------------------------------------------------------
884 wxObjectRefData
*wxFont::CreateRefData() const
886 return new wxFontRefData();
889 wxObjectRefData
*wxFont::CloneRefData(const wxObjectRefData
*data
) const
891 return new wxFontRefData(*wx_static_cast(const wxFontRefData
*, data
));
894 bool wxFont::RealizeResource()
896 // don't do anything if we already have a valid font
900 return M_FONTDATA
->Alloc(this);
903 bool wxFont::FreeResource(bool WXUNUSED(force
))
913 WXHANDLE
wxFont::GetResourceHandle() const
915 return (WXHANDLE
)GetHFONT();
918 WXHFONT
wxFont::GetHFONT() const
920 return M_FONTDATA
? M_FONTDATA
->GetHFONT(this) : 0;
923 bool wxFont::IsFree() const
925 return M_FONTDATA
&& !M_FONTDATA
->HasHFONT();
928 // ----------------------------------------------------------------------------
929 // change font attribute: we recreate font when doing it
930 // ----------------------------------------------------------------------------
932 void wxFont::SetPointSize(int pointSize
)
937 M_FONTDATA
->SetPointSize(pointSize
);
940 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
944 M_FONTDATA
->SetPixelSize(pixelSize
);
947 void wxFont::SetFamily(int family
)
951 M_FONTDATA
->SetFamily(family
);
954 void wxFont::SetStyle(int style
)
958 M_FONTDATA
->SetStyle(style
);
961 void wxFont::SetWeight(int weight
)
965 M_FONTDATA
->SetWeight(weight
);
968 bool wxFont::SetFaceName(const wxString
& faceName
)
972 if ( !M_FONTDATA
->SetFaceName(faceName
) )
975 // NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
976 // to retrieve a LOGFONT and then compare lf.lfFaceName
977 // with given facename is not reliable at all:
978 // Windows copies the facename given to ::CreateFontIndirect()
979 // without any validity check.
980 // Thus we use wxFontBase::SetFaceName to check if facename
982 return wxFontBase::SetFaceName(faceName
);
985 void wxFont::SetUnderlined(bool underlined
)
989 M_FONTDATA
->SetUnderlined(underlined
);
992 void wxFont::SetEncoding(wxFontEncoding encoding
)
996 M_FONTDATA
->SetEncoding(encoding
);
999 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
1003 M_FONTDATA
->SetNativeFontInfo(info
);
1006 // ----------------------------------------------------------------------------
1008 // ----------------------------------------------------------------------------
1010 int wxFont::GetPointSize() const
1012 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1014 return M_FONTDATA
->GetPointSize();
1017 wxSize
wxFont::GetPixelSize() const
1019 wxCHECK_MSG( Ok(), wxDefaultSize
, wxT("invalid font") );
1021 return M_FONTDATA
->GetPixelSize();
1024 bool wxFont::IsUsingSizeInPixels() const
1026 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1028 return M_FONTDATA
->IsUsingSizeInPixels();
1031 int wxFont::GetFamily() const
1033 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1035 return M_FONTDATA
->GetFamily();
1038 int wxFont::GetStyle() const
1040 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1042 return M_FONTDATA
->GetStyle();
1045 int wxFont::GetWeight() const
1047 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1049 return M_FONTDATA
->GetWeight();
1052 bool wxFont::GetUnderlined() const
1054 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
1056 return M_FONTDATA
->GetUnderlined();
1059 wxString
wxFont::GetFaceName() const
1061 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
1063 return M_FONTDATA
->GetFaceName();
1066 wxFontEncoding
wxFont::GetEncoding() const
1068 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
1070 return M_FONTDATA
->GetEncoding();
1073 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
1075 return Ok() && M_FONTDATA
->HasNativeFontInfo() ? &(M_FONTDATA
->GetNativeFontInfo())
1079 wxString
wxFont::GetNativeFontInfoDesc() const
1081 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
1083 // be sure we have an HFONT associated...
1084 wxConstCast(this, wxFont
)->RealizeResource();
1085 return wxFontBase::GetNativeFontInfoDesc();
1088 wxString
wxFont::GetNativeFontInfoUserDesc() const
1090 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
1092 // be sure we have an HFONT associated...
1093 wxConstCast(this, wxFont
)->RealizeResource();
1094 return wxFontBase::GetNativeFontInfoUserDesc();
1097 bool wxFont::IsFixedWidth() const
1099 if ( M_FONTDATA
->HasNativeFontInfo() )
1101 // the two low-order bits specify the pitch of the font, the rest is
1104 (BYTE
)(M_FONTDATA
->GetNativeFontInfo().lf
.lfPitchAndFamily
& PITCH_MASK
);
1106 return pitch
== FIXED_PITCH
;
1109 return wxFontBase::IsFixedWidth();