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
)
324 m_nativeFontInfo
= nativeFontInfo
;
325 m_nativeFontInfoOk
= true;
329 // common part of all ctors
331 const wxSize
& pixelSize
,
332 bool sizeUsingPixels
,
337 const wxString
& faceName
,
338 wxFontEncoding encoding
);
340 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
342 // font characteristics
345 bool m_sizeUsingPixels
;
351 wxFontEncoding m_encoding
;
353 // Windows font handle, created on demand in GetHFONT()
357 wxNativeFontInfo m_nativeFontInfo
;
358 bool m_nativeFontInfoOk
;
361 #define M_FONTDATA ((wxFontRefData*)m_refData)
363 // ============================================================================
365 // ============================================================================
367 // ----------------------------------------------------------------------------
369 // ----------------------------------------------------------------------------
371 void wxFontRefData::Init(int pointSize
,
372 const wxSize
& pixelSize
,
373 bool sizeUsingPixels
,
378 const wxString
& faceName
,
379 wxFontEncoding encoding
)
382 m_pointSize
= pointSize
== -1 ? wxNORMAL_FONT
->GetPointSize() : pointSize
;
383 m_pixelSize
= pixelSize
;
384 m_sizeUsingPixels
= sizeUsingPixels
;
388 m_underlined
= underlined
;
389 m_faceName
= faceName
;
390 m_encoding
= encoding
;
394 m_nativeFontInfoOk
= false;
397 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
399 // hFont may be zero, or it be passed in case we really want to
400 // use the exact font created in the underlying system
401 // (for example where we can't guarantee conversion from HFONT
402 // to LOGFONT back to HFONT)
403 m_hFont
= (HFONT
)hFont
;
405 m_nativeFontInfoOk
= true;
406 m_nativeFontInfo
= info
;
407 // This is the best we can do since we don't have the
408 // correct information at this point.
412 wxFontRefData::~wxFontRefData()
417 bool wxFontRefData::Alloc(const wxFont
*font
)
419 if ( !m_nativeFontInfoOk
)
421 wxFillLogFont(&m_nativeFontInfo
.lf
, font
);
422 m_nativeFontInfoOk
= true;
425 m_hFont
= ::CreateFontIndirect(&m_nativeFontInfo
.lf
);
428 wxLogLastError(wxT("CreateFont"));
435 void wxFontRefData::Free()
439 if ( !::DeleteObject(m_hFont
) )
441 wxLogLastError(wxT("DeleteObject(font)"));
448 // ----------------------------------------------------------------------------
450 // ----------------------------------------------------------------------------
452 void wxNativeFontInfo::Init()
456 // we get better font quality if we use this instead of DEFAULT_QUALITY
457 // apparently without any drawbacks
459 lf
.lfQuality
= CLEARTYPE_QUALITY
;
461 lf
.lfQuality
= PROOF_QUALITY
;
465 int wxNativeFontInfo::GetPointSize() const
467 // FIXME: using the screen here results in incorrect font size calculation
469 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
471 return (int) (((72.0*(double)abs(lf
.lfHeight
)) / (double) ppInch
) + 0.5);
474 wxSize
wxNativeFontInfo::GetPixelSize() const
477 ret
.SetHeight(lf
.lfHeight
);
478 ret
.SetWidth(lf
.lfWidth
);
482 wxFontStyle
wxNativeFontInfo::GetStyle() const
484 return lf
.lfItalic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
;
487 wxFontWeight
wxNativeFontInfo::GetWeight() const
489 if ( lf
.lfWeight
<= 300 )
490 return wxFONTWEIGHT_LIGHT
;
492 if ( lf
.lfWeight
>= 600 )
493 return wxFONTWEIGHT_BOLD
;
495 return wxFONTWEIGHT_NORMAL
;
498 bool wxNativeFontInfo::GetUnderlined() const
500 return lf
.lfUnderline
!= 0;
503 wxString
wxNativeFontInfo::GetFaceName() const
505 return lf
.lfFaceName
;
508 wxFontFamily
wxNativeFontInfo::GetFamily() const
512 // extract family from pitch-and-family
513 switch ( lf
.lfPitchAndFamily
& ~PITCH_MASK
)
516 family
= wxFONTFAMILY_ROMAN
;
520 wxFAIL_MSG( _T("unknown LOGFONT::lfFamily value") );
524 family
= wxFONTFAMILY_SWISS
;
528 family
= wxFONTFAMILY_SCRIPT
;
532 family
= wxFONTFAMILY_MODERN
;
536 family
= wxFONTFAMILY_DECORATIVE
;
543 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
545 return wxGetFontEncFromCharSet(lf
.lfCharSet
);
548 void wxNativeFontInfo::SetPointSize(int pointsize
)
550 // FIXME: using the screen here results in incorrect font size calculation
552 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
554 lf
.lfHeight
= -(int)((pointsize
*((double)ppInch
)/72.0) + 0.5);
557 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
559 lf
.lfHeight
= pixelSize
.GetHeight();
560 lf
.lfWidth
= pixelSize
.GetWidth();
564 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
569 wxFAIL_MSG( _T("unknown font style") );
572 case wxFONTSTYLE_NORMAL
:
576 case wxFONTSTYLE_ITALIC
:
577 case wxFONTSTYLE_SLANT
:
583 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
588 wxFAIL_MSG( _T("unknown font weight") );
591 case wxFONTWEIGHT_NORMAL
:
592 lf
.lfWeight
= FW_NORMAL
;
595 case wxFONTWEIGHT_LIGHT
:
596 lf
.lfWeight
= FW_LIGHT
;
599 case wxFONTWEIGHT_BOLD
:
600 lf
.lfWeight
= FW_BOLD
;
605 void wxNativeFontInfo::SetUnderlined(bool underlined
)
607 lf
.lfUnderline
= underlined
;
610 bool wxNativeFontInfo::SetFaceName(const wxString
& facename
)
612 size_t len
= WXSIZEOF(lf
.lfFaceName
);
613 wxStrncpy(lf
.lfFaceName
, facename
, len
);
614 lf
.lfFaceName
[len
- 1] = '\0'; // truncate the face name
618 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
621 wxArrayString facename
;
623 // the list of fonts associated with a family was partially
624 // taken from http://www.codestyle.org/css/font-family
629 ff_family
= FF_SCRIPT
;
630 facename
.Add(_T("Script"));
631 facename
.Add(_T("Brush Script MT"));
632 facename
.Add(_T("Comic Sans MS"));
633 facename
.Add(_T("Lucida Handwriting"));
637 ff_family
= FF_DECORATIVE
;
638 facename
.Add(_T("Old English Text MT"));
639 facename
.Add(_T("Comic Sans MS"));
640 facename
.Add(_T("Lucida Handwriting"));
644 ff_family
= FF_ROMAN
;
645 facename
.Add(_T("Times New Roman"));
646 facename
.Add(_T("Georgia"));
647 facename
.Add(_T("Garamond"));
648 facename
.Add(_T("Bookman Old Style"));
649 facename
.Add(_T("Book Antiqua"));
654 ff_family
= FF_MODERN
;
655 facename
.Add(_T("Courier New"));
656 facename
.Add(_T("Lucida Console"));
657 facename
.Add(_T("Andale Mono"));
658 facename
.Add(_T("OCR A Extended"));
659 facename
.Add(_T("Terminal"));
663 ff_family
= FF_SWISS
;
664 facename
.Add(_T("Arial"));
665 facename
.Add(_T("Century Gothic"));
666 facename
.Add(_T("Lucida Sans Unicode"));
667 facename
.Add(_T("Tahoma"));
668 facename
.Add(_T("Trebuchet MS"));
669 facename
.Add(_T("Verdana"));
675 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
676 // is returned as default GUI font for compatibility
678 ff_family
= FF_SWISS
;
679 if(wxGetOsVersion(&verMaj
) == wxOS_WINDOWS_NT
&& verMaj
>= 5)
680 facename
.Add(_T("MS Shell Dlg 2"));
682 facename
.Add(_T("MS Shell Dlg"));
685 // "MS Shell Dlg is a mapping mechanism that enables
686 // U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
687 // support locales that have characters that are not contained in code
688 // page 1252. It is not a font but a face name for a nonexistent font."
692 lf
.lfPitchAndFamily
= (BYTE
)(DEFAULT_PITCH
) | ff_family
;
694 if ( !wxStrlen(lf
.lfFaceName
) )
696 SetFaceName(facename
);
700 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
702 wxNativeEncodingInfo info
;
703 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
706 if ( wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
708 if ( !info
.facename
.empty() )
710 // if we have this encoding only in some particular facename, use
711 // the facename - it is better to show the correct characters in a
712 // wrong facename than unreadable text in a correct one
713 SetFaceName(info
.facename
);
717 #endif // wxUSE_FONTMAP
719 // unsupported encoding, replace with the default
720 info
.charset
= DEFAULT_CHARSET
;
724 lf
.lfCharSet
= (BYTE
)info
.charset
;
727 bool wxNativeFontInfo::FromString(const wxString
& s
)
731 wxStringTokenizer
tokenizer(s
, _T(";"));
734 wxString token
= tokenizer
.GetNextToken();
735 if ( token
!= _T('0') )
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
) )
753 token
= tokenizer
.GetNextToken();
754 if ( !token
.ToLong(&l
) )
756 lf
.lfOrientation
= l
;
758 token
= tokenizer
.GetNextToken();
759 if ( !token
.ToLong(&l
) )
763 token
= tokenizer
.GetNextToken();
764 if ( !token
.ToLong(&l
) )
766 lf
.lfItalic
= (BYTE
)l
;
768 token
= tokenizer
.GetNextToken();
769 if ( !token
.ToLong(&l
) )
771 lf
.lfUnderline
= (BYTE
)l
;
773 token
= tokenizer
.GetNextToken();
774 if ( !token
.ToLong(&l
) )
776 lf
.lfStrikeOut
= (BYTE
)l
;
778 token
= tokenizer
.GetNextToken();
779 if ( !token
.ToLong(&l
) )
781 lf
.lfCharSet
= (BYTE
)l
;
783 token
= tokenizer
.GetNextToken();
784 if ( !token
.ToLong(&l
) )
786 lf
.lfOutPrecision
= (BYTE
)l
;
788 token
= tokenizer
.GetNextToken();
789 if ( !token
.ToLong(&l
) )
791 lf
.lfClipPrecision
= (BYTE
)l
;
793 token
= tokenizer
.GetNextToken();
794 if ( !token
.ToLong(&l
) )
796 lf
.lfQuality
= (BYTE
)l
;
798 token
= tokenizer
.GetNextToken();
799 if ( !token
.ToLong(&l
) )
801 lf
.lfPitchAndFamily
= (BYTE
)l
;
803 token
= tokenizer
.GetNextToken();
806 wxStrcpy(lf
.lfFaceName
, token
.c_str());
811 wxString
wxNativeFontInfo::ToString() const
815 s
.Printf(_T("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
816 0, // version, in case we want to change the format later
830 (const wxChar
*)lf
.lfFaceName
);
835 // ----------------------------------------------------------------------------
837 // ----------------------------------------------------------------------------
839 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
843 m_refData
= new wxFontRefData(info
, hFont
);
845 return RealizeResource();
848 wxFont::wxFont(const wxString
& fontdesc
)
850 wxNativeFontInfo info
;
851 if ( info
.FromString(fontdesc
) )
855 bool wxFont::DoCreate(int pointSize
,
856 const wxSize
& pixelSize
,
857 bool sizeUsingPixels
,
862 const wxString
& faceName
,
863 wxFontEncoding encoding
)
867 // wxDEFAULT is a valid value for the font size too so we must treat it
868 // specially here (otherwise the size would be 70 == wxDEFAULT value)
869 if ( pointSize
== wxDEFAULT
)
871 pointSize
= wxNORMAL_FONT
->GetPointSize();
874 m_refData
= new wxFontRefData(pointSize
, pixelSize
, sizeUsingPixels
,
875 family
, style
, weight
,
876 underlined
, faceName
, encoding
);
878 return RealizeResource();
885 // ----------------------------------------------------------------------------
886 // real implementation
887 // ----------------------------------------------------------------------------
889 wxObjectRefData
*wxFont::CreateRefData() const
891 return new wxFontRefData();
894 wxObjectRefData
*wxFont::CloneRefData(const wxObjectRefData
*data
) const
896 return new wxFontRefData(*wx_static_cast(const wxFontRefData
*, data
));
899 bool wxFont::RealizeResource()
901 // don't do anything if we already have a valid font
905 return M_FONTDATA
->Alloc(this);
908 bool wxFont::FreeResource(bool WXUNUSED(force
))
918 WXHANDLE
wxFont::GetResourceHandle() const
920 return (WXHANDLE
)GetHFONT();
923 WXHFONT
wxFont::GetHFONT() const
925 return M_FONTDATA
? M_FONTDATA
->GetHFONT(this) : 0;
928 bool wxFont::IsFree() const
930 return M_FONTDATA
&& !M_FONTDATA
->HasHFONT();
933 // ----------------------------------------------------------------------------
934 // change font attribute: we recreate font when doing it
935 // ----------------------------------------------------------------------------
937 void wxFont::SetPointSize(int pointSize
)
942 M_FONTDATA
->SetPointSize(pointSize
);
945 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
949 M_FONTDATA
->SetPixelSize(pixelSize
);
952 void wxFont::SetFamily(int family
)
956 M_FONTDATA
->SetFamily(family
);
959 void wxFont::SetStyle(int style
)
963 M_FONTDATA
->SetStyle(style
);
966 void wxFont::SetWeight(int weight
)
970 M_FONTDATA
->SetWeight(weight
);
973 bool wxFont::SetFaceName(const wxString
& faceName
)
977 if ( !M_FONTDATA
->SetFaceName(faceName
) )
980 // NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
981 // to retrieve a LOGFONT and then compare lf.lfFaceName
982 // with given facename is not reliable at all:
983 // Windows copies the facename given to ::CreateFontIndirect()
984 // without any validity check.
985 // Thus we use wxFontBase::SetFaceName to check if facename
987 return wxFontBase::SetFaceName(faceName
);
990 void wxFont::SetUnderlined(bool underlined
)
994 M_FONTDATA
->SetUnderlined(underlined
);
997 void wxFont::SetEncoding(wxFontEncoding encoding
)
1001 M_FONTDATA
->SetEncoding(encoding
);
1004 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
1008 M_FONTDATA
->SetNativeFontInfo(info
);
1011 // ----------------------------------------------------------------------------
1013 // ----------------------------------------------------------------------------
1015 int wxFont::GetPointSize() const
1017 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1019 return M_FONTDATA
->GetPointSize();
1022 wxSize
wxFont::GetPixelSize() const
1024 wxCHECK_MSG( Ok(), wxDefaultSize
, wxT("invalid font") );
1026 return M_FONTDATA
->GetPixelSize();
1029 bool wxFont::IsUsingSizeInPixels() const
1031 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1033 return M_FONTDATA
->IsUsingSizeInPixels();
1036 int wxFont::GetFamily() const
1038 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1040 return M_FONTDATA
->GetFamily();
1043 int wxFont::GetStyle() const
1045 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1047 return M_FONTDATA
->GetStyle();
1050 int wxFont::GetWeight() const
1052 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1054 return M_FONTDATA
->GetWeight();
1057 bool wxFont::GetUnderlined() const
1059 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
1061 return M_FONTDATA
->GetUnderlined();
1064 wxString
wxFont::GetFaceName() const
1066 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
1068 return M_FONTDATA
->GetFaceName();
1071 wxFontEncoding
wxFont::GetEncoding() const
1073 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
1075 return M_FONTDATA
->GetEncoding();
1078 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
1080 return Ok() && M_FONTDATA
->HasNativeFontInfo() ? &(M_FONTDATA
->GetNativeFontInfo())
1084 wxString
wxFont::GetNativeFontInfoDesc() const
1086 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
1088 // be sure we have an HFONT associated...
1089 wxConstCast(this, wxFont
)->RealizeResource();
1090 return wxFontBase::GetNativeFontInfoDesc();
1093 wxString
wxFont::GetNativeFontInfoUserDesc() const
1095 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
1097 // be sure we have an HFONT associated...
1098 wxConstCast(this, wxFont
)->RealizeResource();
1099 return wxFontBase::GetNativeFontInfoUserDesc();
1102 bool wxFont::IsFixedWidth() const
1104 if ( M_FONTDATA
->HasNativeFontInfo() )
1106 // the two low-order bits specify the pitch of the font, the rest is
1109 (BYTE
)(M_FONTDATA
->GetNativeFontInfo().lf
.lfPitchAndFamily
& PITCH_MASK
);
1111 return pitch
== FIXED_PITCH
;
1114 return wxFontBase::IsFixedWidth();