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"
43 #include "wx/sysopt.h"
46 #include "wx/tokenzr.h"
48 #if wxUSE_EXTENDED_RTTI
50 wxBEGIN_ENUM( wxFontFamily
)
51 wxENUM_MEMBER( wxDEFAULT
)
52 wxENUM_MEMBER( wxDECORATIVE
)
53 wxENUM_MEMBER( wxROMAN
)
54 wxENUM_MEMBER( wxSCRIPT
)
55 wxENUM_MEMBER( wxSWISS
)
56 wxENUM_MEMBER( wxMODERN
)
57 wxENUM_MEMBER( wxTELETYPE
)
58 wxEND_ENUM( wxFontFamily
)
60 wxBEGIN_ENUM( wxFontStyle
)
61 wxENUM_MEMBER( wxNORMAL
)
62 wxENUM_MEMBER( wxITALIC
)
63 wxENUM_MEMBER( wxSLANT
)
64 wxEND_ENUM( wxFontStyle
)
66 wxBEGIN_ENUM( wxFontWeight
)
67 wxENUM_MEMBER( wxNORMAL
)
68 wxENUM_MEMBER( wxLIGHT
)
69 wxENUM_MEMBER( wxBOLD
)
70 wxEND_ENUM( wxFontWeight
)
72 IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont
, wxGDIObject
,"wx/font.h")
74 wxBEGIN_PROPERTIES_TABLE(wxFont
)
75 wxPROPERTY( Size
,int, SetPointSize
, GetPointSize
, 12 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
76 wxPROPERTY( Family
, int , SetFamily
, GetFamily
, (int)wxDEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontFamily
77 wxPROPERTY( Style
, int , SetStyle
, GetStyle
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontStyle
78 wxPROPERTY( Weight
, int , SetWeight
, GetWeight
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontWeight
79 wxPROPERTY( Underlined
, bool , SetUnderlined
, GetUnderlined
, false , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
80 wxPROPERTY( Face
, wxString
, SetFaceName
, GetFaceName
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
81 wxPROPERTY( Encoding
, wxFontEncoding
, SetEncoding
, GetEncoding
, wxFONTENCODING_DEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
82 wxEND_PROPERTIES_TABLE()
84 wxCONSTRUCTOR_6( wxFont
, int , Size
, int , Family
, int , Style
, int , Weight
, bool , Underlined
, wxString
, Face
)
86 wxBEGIN_HANDLERS_TABLE(wxFont
)
87 wxEND_HANDLERS_TABLE()
90 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 // the mask used to extract the pitch from LOGFONT::lfPitchAndFamily field
99 static const int PITCH_MASK
= FIXED_PITCH
| VARIABLE_PITCH
;
101 // ----------------------------------------------------------------------------
102 // wxFontRefData - the internal description of the font
103 // ----------------------------------------------------------------------------
105 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
111 Init(-1, wxSize(0,0), false, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
,
112 wxFONTWEIGHT_NORMAL
, false, wxEmptyString
,
113 wxFONTENCODING_DEFAULT
);
116 wxFontRefData(int size
,
117 const wxSize
& pixelSize
,
118 bool sizeUsingPixels
,
123 const wxString
& faceName
,
124 wxFontEncoding encoding
)
126 Init(size
, pixelSize
, sizeUsingPixels
, family
, style
, weight
,
127 underlined
, faceName
, encoding
);
130 wxFontRefData(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0)
135 wxFontRefData(const wxFontRefData
& data
) : wxGDIRefData()
137 if ( data
.m_nativeFontInfoOk
)
139 Init(data
.m_nativeFontInfo
);
143 Init(data
.m_pointSize
, data
.m_pixelSize
, data
.m_sizeUsingPixels
,
144 data
.m_family
, data
.m_style
, data
.m_weight
,
145 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
149 virtual ~wxFontRefData();
152 bool Alloc(const wxFont
*font
);
156 // all wxFont accessors
157 int GetPointSize() const
159 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetPointSize()
163 wxSize
GetPixelSize() const
165 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetPixelSize()
169 bool IsUsingSizeInPixels() const
171 return m_nativeFontInfoOk
? true : m_sizeUsingPixels
;
174 int GetFamily() const
181 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetStyle()
185 int GetWeight() const
187 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetWeight()
191 bool GetUnderlined() const
193 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetUnderlined()
197 wxString
GetFaceName() const
200 if ( m_nativeFontInfoOk
)
201 s
= m_nativeFontInfo
.GetFaceName();
208 wxFontEncoding
GetEncoding() const
210 return m_nativeFontInfoOk
? m_nativeFontInfo
.GetEncoding()
214 WXHFONT
GetHFONT(const wxFont
*font
) const
217 wx_const_cast(wxFontRefData
*, this)->Alloc(font
);
219 return (WXHFONT
)m_hFont
;
222 bool HasHFONT() const
227 // ... and setters: notice that all of them invalidate the currently
228 // allocated HFONT, if any, so that the next call to GetHFONT() recreates a
230 void SetPointSize(int pointSize
)
234 if ( m_nativeFontInfoOk
)
236 m_nativeFontInfo
.SetPointSize(pointSize
);
240 m_pointSize
= pointSize
;
241 m_sizeUsingPixels
= false;
245 void SetPixelSize(const wxSize
& pixelSize
)
249 if ( m_nativeFontInfoOk
)
251 m_nativeFontInfo
.SetPixelSize(pixelSize
);
255 m_pixelSize
= pixelSize
;
256 m_sizeUsingPixels
= true;
260 void SetFamily(int family
)
267 void SetStyle(int style
)
271 if ( m_nativeFontInfoOk
)
272 m_nativeFontInfo
.SetStyle((wxFontStyle
)style
);
277 void SetWeight(int weight
)
281 if ( m_nativeFontInfoOk
)
282 m_nativeFontInfo
.SetWeight((wxFontWeight
)weight
);
287 bool SetFaceName(const wxString
& faceName
)
291 if ( m_nativeFontInfoOk
)
292 return m_nativeFontInfo
.SetFaceName(faceName
);
294 m_faceName
= faceName
;
298 void SetUnderlined(bool underlined
)
302 if ( m_nativeFontInfoOk
)
303 m_nativeFontInfo
.SetUnderlined(underlined
);
305 m_underlined
= underlined
;
308 void SetEncoding(wxFontEncoding encoding
)
312 if ( m_nativeFontInfoOk
)
313 m_nativeFontInfo
.SetEncoding(encoding
);
315 m_encoding
= encoding
;
319 bool HasNativeFontInfo() const { return m_nativeFontInfoOk
; }
321 const wxNativeFontInfo
& GetNativeFontInfo() const
322 { return m_nativeFontInfo
; }
324 void SetNativeFontInfo(const wxNativeFontInfo
& nativeFontInfo
)
328 m_nativeFontInfo
= nativeFontInfo
;
329 m_nativeFontInfoOk
= true;
333 // common part of all ctors
335 const wxSize
& pixelSize
,
336 bool sizeUsingPixels
,
341 const wxString
& faceName
,
342 wxFontEncoding encoding
);
344 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
346 // font characteristics
349 bool m_sizeUsingPixels
;
355 wxFontEncoding m_encoding
;
357 // Windows font handle, created on demand in GetHFONT()
361 wxNativeFontInfo m_nativeFontInfo
;
362 bool m_nativeFontInfoOk
;
365 #define M_FONTDATA ((wxFontRefData*)m_refData)
367 // ============================================================================
369 // ============================================================================
371 // ----------------------------------------------------------------------------
373 // ----------------------------------------------------------------------------
375 void wxFontRefData::Init(int pointSize
,
376 const wxSize
& pixelSize
,
377 bool sizeUsingPixels
,
382 const wxString
& faceName
,
383 wxFontEncoding encoding
)
386 m_pointSize
= pointSize
== -1 ? wxNORMAL_FONT
->GetPointSize() : pointSize
;
387 m_pixelSize
= pixelSize
;
388 m_sizeUsingPixels
= sizeUsingPixels
;
392 m_underlined
= underlined
;
393 m_faceName
= faceName
;
394 m_encoding
= encoding
;
398 m_nativeFontInfoOk
= false;
401 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
403 // hFont may be zero, or it be passed in case we really want to
404 // use the exact font created in the underlying system
405 // (for example where we can't guarantee conversion from HFONT
406 // to LOGFONT back to HFONT)
407 m_hFont
= (HFONT
)hFont
;
409 m_nativeFontInfoOk
= true;
410 m_nativeFontInfo
= info
;
411 // This is the best we can do since we don't have the
412 // correct information at this point.
416 wxFontRefData::~wxFontRefData()
421 bool wxFontRefData::Alloc(const wxFont
*font
)
423 if ( !m_nativeFontInfoOk
)
425 wxFillLogFont(&m_nativeFontInfo
.lf
, font
);
426 m_nativeFontInfoOk
= true;
429 m_hFont
= ::CreateFontIndirect(&m_nativeFontInfo
.lf
);
432 wxLogLastError(wxT("CreateFont"));
439 void wxFontRefData::Free()
443 if ( !::DeleteObject(m_hFont
) )
445 wxLogLastError(wxT("DeleteObject(font)"));
452 // ----------------------------------------------------------------------------
454 // ----------------------------------------------------------------------------
456 void wxNativeFontInfo::Init()
460 // we get better font quality if we use PROOF_QUALITY instead of
461 // DEFAULT_QUALITY but some fonts (e.g. "Terminal 6pt") are not available
462 // then so we allow to set a global option to choose between quality and
463 // wider font selection
465 lf
.lfQuality
= CLEARTYPE_QUALITY
;
467 lf
.lfQuality
= wxSystemOptions::GetOptionInt(_T("msw.font.no-proof-quality"))
473 int wxNativeFontInfo::GetPointSize() const
475 // FIXME: using the screen here results in incorrect font size calculation
477 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
479 // BC++ 2007 doesn't provide abs(long) overload, hence the cast
480 return (int) (((72.0*abs((int)lf
.lfHeight
)) / (double) ppInch
) + 0.5);
483 wxSize
wxNativeFontInfo::GetPixelSize() const
486 ret
.SetHeight(lf
.lfHeight
);
487 ret
.SetWidth(lf
.lfWidth
);
491 wxFontStyle
wxNativeFontInfo::GetStyle() const
493 return lf
.lfItalic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
;
496 wxFontWeight
wxNativeFontInfo::GetWeight() const
498 if ( lf
.lfWeight
<= 300 )
499 return wxFONTWEIGHT_LIGHT
;
501 if ( lf
.lfWeight
>= 600 )
502 return wxFONTWEIGHT_BOLD
;
504 return wxFONTWEIGHT_NORMAL
;
507 bool wxNativeFontInfo::GetUnderlined() const
509 return lf
.lfUnderline
!= 0;
512 wxString
wxNativeFontInfo::GetFaceName() const
514 return lf
.lfFaceName
;
517 wxFontFamily
wxNativeFontInfo::GetFamily() const
521 // extract family from pitch-and-family
522 switch ( lf
.lfPitchAndFamily
& ~PITCH_MASK
)
525 family
= wxFONTFAMILY_ROMAN
;
529 wxFAIL_MSG( _T("unknown LOGFONT::lfFamily value") );
533 family
= wxFONTFAMILY_SWISS
;
537 family
= wxFONTFAMILY_SCRIPT
;
541 family
= wxFONTFAMILY_MODERN
;
545 family
= wxFONTFAMILY_DECORATIVE
;
552 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
554 return wxGetFontEncFromCharSet(lf
.lfCharSet
);
557 void wxNativeFontInfo::SetPointSize(int pointsize
)
559 // FIXME: using the screen here results in incorrect font size calculation
561 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
563 lf
.lfHeight
= -(int)((pointsize
*((double)ppInch
)/72.0) + 0.5);
566 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
568 lf
.lfHeight
= pixelSize
.GetHeight();
569 lf
.lfWidth
= pixelSize
.GetWidth();
573 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
578 wxFAIL_MSG( _T("unknown font style") );
581 case wxFONTSTYLE_NORMAL
:
585 case wxFONTSTYLE_ITALIC
:
586 case wxFONTSTYLE_SLANT
:
592 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
597 wxFAIL_MSG( _T("unknown font weight") );
600 case wxFONTWEIGHT_NORMAL
:
601 lf
.lfWeight
= FW_NORMAL
;
604 case wxFONTWEIGHT_LIGHT
:
605 lf
.lfWeight
= FW_LIGHT
;
608 case wxFONTWEIGHT_BOLD
:
609 lf
.lfWeight
= FW_BOLD
;
614 void wxNativeFontInfo::SetUnderlined(bool underlined
)
616 lf
.lfUnderline
= underlined
;
619 bool wxNativeFontInfo::SetFaceName(const wxString
& facename
)
621 size_t len
= WXSIZEOF(lf
.lfFaceName
);
622 wxStrncpy(lf
.lfFaceName
, facename
, len
);
623 lf
.lfFaceName
[len
- 1] = '\0'; // truncate the face name
627 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
630 wxArrayString facename
;
632 // the list of fonts associated with a family was partially
633 // taken from http://www.codestyle.org/css/font-family
638 ff_family
= FF_SCRIPT
;
639 facename
.Add(_T("Script"));
640 facename
.Add(_T("Brush Script MT"));
641 facename
.Add(_T("Comic Sans MS"));
642 facename
.Add(_T("Lucida Handwriting"));
646 ff_family
= FF_DECORATIVE
;
647 facename
.Add(_T("Old English Text MT"));
648 facename
.Add(_T("Comic Sans MS"));
649 facename
.Add(_T("Lucida Handwriting"));
653 ff_family
= FF_ROMAN
;
654 facename
.Add(_T("Times New Roman"));
655 facename
.Add(_T("Georgia"));
656 facename
.Add(_T("Garamond"));
657 facename
.Add(_T("Bookman Old Style"));
658 facename
.Add(_T("Book Antiqua"));
663 ff_family
= FF_MODERN
;
664 facename
.Add(_T("Courier New"));
665 facename
.Add(_T("Lucida Console"));
666 facename
.Add(_T("Andale Mono"));
667 facename
.Add(_T("OCR A Extended"));
668 facename
.Add(_T("Terminal"));
672 ff_family
= FF_SWISS
;
673 facename
.Add(_T("Arial"));
674 facename
.Add(_T("Century Gothic"));
675 facename
.Add(_T("Lucida Sans Unicode"));
676 facename
.Add(_T("Tahoma"));
677 facename
.Add(_T("Trebuchet MS"));
678 facename
.Add(_T("Verdana"));
684 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
685 // is returned as default GUI font for compatibility
687 ff_family
= FF_SWISS
;
688 if(wxGetOsVersion(&verMaj
) == wxOS_WINDOWS_NT
&& verMaj
>= 5)
689 facename
.Add(_T("MS Shell Dlg 2"));
691 facename
.Add(_T("MS Shell Dlg"));
694 // "MS Shell Dlg is a mapping mechanism that enables
695 // U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
696 // support locales that have characters that are not contained in code
697 // page 1252. It is not a font but a face name for a nonexistent font."
701 lf
.lfPitchAndFamily
= (BYTE
)(DEFAULT_PITCH
) | ff_family
;
703 if ( !wxStrlen(lf
.lfFaceName
) )
705 SetFaceName(facename
);
709 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
711 wxNativeEncodingInfo info
;
712 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
715 if ( wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
717 if ( !info
.facename
.empty() )
719 // if we have this encoding only in some particular facename, use
720 // the facename - it is better to show the correct characters in a
721 // wrong facename than unreadable text in a correct one
722 SetFaceName(info
.facename
);
726 #endif // wxUSE_FONTMAP
728 // unsupported encoding, replace with the default
729 info
.charset
= DEFAULT_CHARSET
;
733 lf
.lfCharSet
= (BYTE
)info
.charset
;
736 bool wxNativeFontInfo::FromString(const wxString
& s
)
740 wxStringTokenizer
tokenizer(s
, _T(";"));
743 wxString token
= tokenizer
.GetNextToken();
744 if ( token
!= _T('0') )
747 token
= tokenizer
.GetNextToken();
748 if ( !token
.ToLong(&l
) )
752 token
= tokenizer
.GetNextToken();
753 if ( !token
.ToLong(&l
) )
757 token
= tokenizer
.GetNextToken();
758 if ( !token
.ToLong(&l
) )
762 token
= tokenizer
.GetNextToken();
763 if ( !token
.ToLong(&l
) )
765 lf
.lfOrientation
= l
;
767 token
= tokenizer
.GetNextToken();
768 if ( !token
.ToLong(&l
) )
772 token
= tokenizer
.GetNextToken();
773 if ( !token
.ToLong(&l
) )
775 lf
.lfItalic
= (BYTE
)l
;
777 token
= tokenizer
.GetNextToken();
778 if ( !token
.ToLong(&l
) )
780 lf
.lfUnderline
= (BYTE
)l
;
782 token
= tokenizer
.GetNextToken();
783 if ( !token
.ToLong(&l
) )
785 lf
.lfStrikeOut
= (BYTE
)l
;
787 token
= tokenizer
.GetNextToken();
788 if ( !token
.ToLong(&l
) )
790 lf
.lfCharSet
= (BYTE
)l
;
792 token
= tokenizer
.GetNextToken();
793 if ( !token
.ToLong(&l
) )
795 lf
.lfOutPrecision
= (BYTE
)l
;
797 token
= tokenizer
.GetNextToken();
798 if ( !token
.ToLong(&l
) )
800 lf
.lfClipPrecision
= (BYTE
)l
;
802 token
= tokenizer
.GetNextToken();
803 if ( !token
.ToLong(&l
) )
805 lf
.lfQuality
= (BYTE
)l
;
807 token
= tokenizer
.GetNextToken();
808 if ( !token
.ToLong(&l
) )
810 lf
.lfPitchAndFamily
= (BYTE
)l
;
812 token
= tokenizer
.GetNextToken();
815 wxStrcpy(lf
.lfFaceName
, token
.c_str());
820 wxString
wxNativeFontInfo::ToString() const
824 s
.Printf(_T("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
825 0, // version, in case we want to change the format later
839 (const wxChar
*)lf
.lfFaceName
);
844 // ----------------------------------------------------------------------------
846 // ----------------------------------------------------------------------------
848 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
852 m_refData
= new wxFontRefData(info
, hFont
);
854 return RealizeResource();
857 wxFont::wxFont(const wxString
& fontdesc
)
859 wxNativeFontInfo info
;
860 if ( info
.FromString(fontdesc
) )
864 bool wxFont::DoCreate(int pointSize
,
865 const wxSize
& pixelSize
,
866 bool sizeUsingPixels
,
871 const wxString
& faceName
,
872 wxFontEncoding encoding
)
876 // wxDEFAULT is a valid value for the font size too so we must treat it
877 // specially here (otherwise the size would be 70 == wxDEFAULT value)
878 if ( pointSize
== wxDEFAULT
)
880 pointSize
= wxNORMAL_FONT
->GetPointSize();
883 m_refData
= new wxFontRefData(pointSize
, pixelSize
, sizeUsingPixels
,
884 family
, style
, weight
,
885 underlined
, faceName
, encoding
);
887 return RealizeResource();
894 // ----------------------------------------------------------------------------
895 // real implementation
896 // ----------------------------------------------------------------------------
898 wxObjectRefData
*wxFont::CreateRefData() const
900 return new wxFontRefData();
903 wxObjectRefData
*wxFont::CloneRefData(const wxObjectRefData
*data
) const
905 return new wxFontRefData(*wx_static_cast(const wxFontRefData
*, data
));
908 bool wxFont::RealizeResource()
910 // don't do anything if we already have a valid font
914 return M_FONTDATA
->Alloc(this);
917 bool wxFont::FreeResource(bool WXUNUSED(force
))
927 WXHANDLE
wxFont::GetResourceHandle() const
929 return (WXHANDLE
)GetHFONT();
932 WXHFONT
wxFont::GetHFONT() const
934 return M_FONTDATA
? M_FONTDATA
->GetHFONT(this) : 0;
937 bool wxFont::IsFree() const
939 return M_FONTDATA
&& !M_FONTDATA
->HasHFONT();
942 // ----------------------------------------------------------------------------
943 // change font attribute: we recreate font when doing it
944 // ----------------------------------------------------------------------------
946 void wxFont::SetPointSize(int pointSize
)
951 M_FONTDATA
->SetPointSize(pointSize
);
954 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
958 M_FONTDATA
->SetPixelSize(pixelSize
);
961 void wxFont::SetFamily(int family
)
965 M_FONTDATA
->SetFamily(family
);
968 void wxFont::SetStyle(int style
)
972 M_FONTDATA
->SetStyle(style
);
975 void wxFont::SetWeight(int weight
)
979 M_FONTDATA
->SetWeight(weight
);
982 bool wxFont::SetFaceName(const wxString
& faceName
)
986 if ( !M_FONTDATA
->SetFaceName(faceName
) )
989 // NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
990 // to retrieve a LOGFONT and then compare lf.lfFaceName
991 // with given facename is not reliable at all:
992 // Windows copies the facename given to ::CreateFontIndirect()
993 // without any validity check.
994 // Thus we use wxFontBase::SetFaceName to check if facename
996 return wxFontBase::SetFaceName(faceName
);
999 void wxFont::SetUnderlined(bool underlined
)
1003 M_FONTDATA
->SetUnderlined(underlined
);
1006 void wxFont::SetEncoding(wxFontEncoding encoding
)
1010 M_FONTDATA
->SetEncoding(encoding
);
1013 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
1017 M_FONTDATA
->SetNativeFontInfo(info
);
1020 // ----------------------------------------------------------------------------
1022 // ----------------------------------------------------------------------------
1024 int wxFont::GetPointSize() const
1026 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1028 return M_FONTDATA
->GetPointSize();
1031 wxSize
wxFont::GetPixelSize() const
1033 wxCHECK_MSG( Ok(), wxDefaultSize
, wxT("invalid font") );
1035 return M_FONTDATA
->GetPixelSize();
1038 bool wxFont::IsUsingSizeInPixels() const
1040 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1042 return M_FONTDATA
->IsUsingSizeInPixels();
1045 int wxFont::GetFamily() const
1047 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1049 return M_FONTDATA
->GetFamily();
1052 int wxFont::GetStyle() const
1054 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1056 return M_FONTDATA
->GetStyle();
1059 int wxFont::GetWeight() const
1061 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1063 return M_FONTDATA
->GetWeight();
1066 bool wxFont::GetUnderlined() const
1068 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
1070 return M_FONTDATA
->GetUnderlined();
1073 wxString
wxFont::GetFaceName() const
1075 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
1077 return M_FONTDATA
->GetFaceName();
1080 wxFontEncoding
wxFont::GetEncoding() const
1082 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
1084 return M_FONTDATA
->GetEncoding();
1087 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
1089 return Ok() && M_FONTDATA
->HasNativeFontInfo() ? &(M_FONTDATA
->GetNativeFontInfo())
1093 wxString
wxFont::GetNativeFontInfoDesc() 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::GetNativeFontInfoDesc();
1102 wxString
wxFont::GetNativeFontInfoUserDesc() const
1104 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
1106 // be sure we have an HFONT associated...
1107 wxConstCast(this, wxFont
)->RealizeResource();
1108 return wxFontBase::GetNativeFontInfoUserDesc();
1111 bool wxFont::IsFixedWidth() const
1113 if ( M_FONTDATA
->HasNativeFontInfo() )
1115 // the two low-order bits specify the pitch of the font, the rest is
1118 (BYTE
)(M_FONTDATA
->GetNativeFontInfo().lf
.lfPitchAndFamily
& PITCH_MASK
);
1120 return pitch
== FIXED_PITCH
;
1123 return wxFontBase::IsFixedWidth();