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"
33 #include "wx/encinfo.h"
36 #include "wx/msw/private.h"
38 #include "wx/fontutil.h"
39 #include "wx/fontmap.h"
41 #include "wx/tokenzr.h"
43 #if wxUSE_EXTENDED_RTTI
45 wxBEGIN_ENUM( wxFontFamily
)
46 wxENUM_MEMBER( wxDEFAULT
)
47 wxENUM_MEMBER( wxDECORATIVE
)
48 wxENUM_MEMBER( wxROMAN
)
49 wxENUM_MEMBER( wxSCRIPT
)
50 wxENUM_MEMBER( wxSWISS
)
51 wxENUM_MEMBER( wxMODERN
)
52 wxENUM_MEMBER( wxTELETYPE
)
53 wxEND_ENUM( wxFontFamily
)
55 wxBEGIN_ENUM( wxFontStyle
)
56 wxENUM_MEMBER( wxNORMAL
)
57 wxENUM_MEMBER( wxITALIC
)
58 wxENUM_MEMBER( wxSLANT
)
59 wxEND_ENUM( wxFontStyle
)
61 wxBEGIN_ENUM( wxFontWeight
)
62 wxENUM_MEMBER( wxNORMAL
)
63 wxENUM_MEMBER( wxLIGHT
)
64 wxENUM_MEMBER( wxBOLD
)
65 wxEND_ENUM( wxFontWeight
)
67 IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont
, wxGDIObject
,"wx/font.h")
69 wxBEGIN_PROPERTIES_TABLE(wxFont
)
70 wxPROPERTY( Size
,int, SetPointSize
, GetPointSize
, 12 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
71 wxPROPERTY( Family
, int , SetFamily
, GetFamily
, (int)wxDEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontFamily
72 wxPROPERTY( Style
, int , SetStyle
, GetStyle
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontStyle
73 wxPROPERTY( Weight
, int , SetWeight
, GetWeight
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontWeight
74 wxPROPERTY( Underlined
, bool , SetUnderlined
, GetUnderlined
, false , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
75 wxPROPERTY( Face
, wxString
, SetFaceName
, GetFaceName
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
76 wxPROPERTY( Encoding
, wxFontEncoding
, SetEncoding
, GetEncoding
, wxFONTENCODING_DEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
77 wxEND_PROPERTIES_TABLE()
79 wxCONSTRUCTOR_6( wxFont
, int , Size
, int , Family
, int , Style
, int , Weight
, bool , Underlined
, wxString
, Face
)
81 wxBEGIN_HANDLERS_TABLE(wxFont
)
82 wxEND_HANDLERS_TABLE()
85 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 // the mask used to extract the pitch from LOGFONT::lfPitchAndFamily field
94 static const int PITCH_MASK
= FIXED_PITCH
| VARIABLE_PITCH
;
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
) : wxGDIRefData()
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 bool SetFaceName(const wxString
& faceName
)
261 if ( m_nativeFontInfoOk
)
262 return m_nativeFontInfo
.SetFaceName(faceName
);
264 m_faceName
= faceName
;
268 void SetUnderlined(bool underlined
)
270 if ( m_nativeFontInfoOk
)
271 m_nativeFontInfo
.SetUnderlined(underlined
);
273 m_underlined
= underlined
;
276 void SetEncoding(wxFontEncoding encoding
)
278 if ( m_nativeFontInfoOk
)
279 m_nativeFontInfo
.SetEncoding(encoding
);
281 m_encoding
= encoding
;
284 // native font info tests
285 bool HasNativeFontInfo() const { return m_nativeFontInfoOk
; }
287 const wxNativeFontInfo
& GetNativeFontInfo() const
288 { return m_nativeFontInfo
; }
291 // common part of all ctors
293 const wxSize
& pixelSize
,
294 bool sizeUsingPixels
,
299 const wxString
& faceName
,
300 wxFontEncoding encoding
);
302 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
304 // font characterstics
307 bool m_sizeUsingPixels
;
313 wxFontEncoding m_encoding
;
315 // Windows font handle
319 wxNativeFontInfo m_nativeFontInfo
;
320 bool m_nativeFontInfoOk
;
323 // ============================================================================
325 // ============================================================================
327 // ----------------------------------------------------------------------------
329 // ----------------------------------------------------------------------------
331 void wxFontRefData::Init(int pointSize
,
332 const wxSize
& pixelSize
,
333 bool sizeUsingPixels
,
338 const wxString
& faceName
,
339 wxFontEncoding encoding
)
342 m_pointSize
= pointSize
== -1 ? wxNORMAL_FONT
->GetPointSize() : pointSize
;
343 m_pixelSize
= pixelSize
;
344 m_sizeUsingPixels
= sizeUsingPixels
;
348 m_underlined
= underlined
;
349 m_faceName
= faceName
;
350 m_encoding
= encoding
;
354 m_nativeFontInfoOk
= false;
357 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
359 // hFont may be zero, or it be passed in case we really want to
360 // use the exact font created in the underlying system
361 // (for example where we can't guarantee conversion from HFONT
362 // to LOGFONT back to HFONT)
365 m_nativeFontInfoOk
= true;
366 m_nativeFontInfo
= info
;
367 // This is the best we can do since we don't have the
368 // correct information at this point.
372 wxFontRefData::~wxFontRefData()
377 bool wxFontRefData::Alloc(wxFont
*font
)
379 if ( !m_nativeFontInfoOk
)
381 wxFillLogFont(&m_nativeFontInfo
.lf
, font
);
382 m_nativeFontInfoOk
= true;
385 HFONT hfont
= ::CreateFontIndirect(&m_nativeFontInfo
.lf
);
388 wxLogLastError(wxT("CreateFont"));
392 m_hFont
= (WXHFONT
)hfont
;
396 void wxFontRefData::Free()
400 if ( !::DeleteObject((HFONT
) m_hFont
) )
402 wxLogLastError(wxT("DeleteObject(font)"));
409 // ----------------------------------------------------------------------------
411 // ----------------------------------------------------------------------------
413 void wxNativeFontInfo::Init()
418 int wxNativeFontInfo::GetPointSize() const
420 // FIXME: using the screen here results in incorrect font size calculation
422 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
424 return (int) (((72.0*(double)abs(lf
.lfHeight
)) / (double) ppInch
) + 0.5);
427 wxSize
wxNativeFontInfo::GetPixelSize() const
430 ret
.SetHeight(lf
.lfHeight
);
431 ret
.SetWidth(lf
.lfWidth
);
435 wxFontStyle
wxNativeFontInfo::GetStyle() const
437 return lf
.lfItalic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
;
440 wxFontWeight
wxNativeFontInfo::GetWeight() const
442 if ( lf
.lfWeight
<= 300 )
443 return wxFONTWEIGHT_LIGHT
;
445 if ( lf
.lfWeight
>= 600 )
446 return wxFONTWEIGHT_BOLD
;
448 return wxFONTWEIGHT_NORMAL
;
451 bool wxNativeFontInfo::GetUnderlined() const
453 return lf
.lfUnderline
!= 0;
456 wxString
wxNativeFontInfo::GetFaceName() const
458 return lf
.lfFaceName
;
461 wxFontFamily
wxNativeFontInfo::GetFamily() const
465 // extract family from pitch-and-family
466 switch ( lf
.lfPitchAndFamily
& ~PITCH_MASK
)
469 family
= wxFONTFAMILY_ROMAN
;
473 wxFAIL_MSG( _T("unknown LOGFONT::lfFamily value") );
477 family
= wxFONTFAMILY_SWISS
;
481 family
= wxFONTFAMILY_SCRIPT
;
485 family
= wxFONTFAMILY_MODERN
;
489 family
= wxFONTFAMILY_DECORATIVE
;
496 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
498 return wxGetFontEncFromCharSet(lf
.lfCharSet
);
501 void wxNativeFontInfo::SetPointSize(int pointsize
)
503 // FIXME: using the screen here results in incorrect font size calculation
505 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
507 lf
.lfHeight
= -(int)((pointsize
*((double)ppInch
)/72.0) + 0.5);
510 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
512 lf
.lfHeight
= pixelSize
.GetHeight();
513 lf
.lfWidth
= pixelSize
.GetWidth();
517 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
522 wxFAIL_MSG( _T("unknown font style") );
525 case wxFONTSTYLE_NORMAL
:
529 case wxFONTSTYLE_ITALIC
:
530 case wxFONTSTYLE_SLANT
:
536 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
541 wxFAIL_MSG( _T("unknown font weight") );
544 case wxFONTWEIGHT_NORMAL
:
545 lf
.lfWeight
= FW_NORMAL
;
548 case wxFONTWEIGHT_LIGHT
:
549 lf
.lfWeight
= FW_LIGHT
;
552 case wxFONTWEIGHT_BOLD
:
553 lf
.lfWeight
= FW_BOLD
;
558 void wxNativeFontInfo::SetUnderlined(bool underlined
)
560 lf
.lfUnderline
= underlined
;
563 bool wxNativeFontInfo::SetFaceName(const wxString
& facename
)
565 size_t len
= WXSIZEOF(lf
.lfFaceName
);
566 wxStrncpy(lf
.lfFaceName
, facename
, len
);
567 lf
.lfFaceName
[len
- 1] = '\0'; // truncate the face name
571 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
574 wxArrayString facename
;
576 // the list of fonts associated with a family was partially
577 // taken from http://www.codestyle.org/css/font-family
582 ff_family
= FF_SCRIPT
;
583 facename
.Add(_T("Script"));
584 facename
.Add(_T("Brush Script MT"));
585 facename
.Add(_T("Comic Sans MS"));
586 facename
.Add(_T("Lucida Handwriting"));
590 ff_family
= FF_DECORATIVE
;
591 facename
.Add(_T("Old English Text MT"));
592 facename
.Add(_T("Comic Sans MS"));
593 facename
.Add(_T("Lucida Handwriting"));
597 ff_family
= FF_ROMAN
;
598 facename
.Add(_T("Times New Roman"));
599 facename
.Add(_T("Georgia"));
600 facename
.Add(_T("Garamond"));
601 facename
.Add(_T("Bookman Old Style"));
602 facename
.Add(_T("Book Antiqua"));
607 ff_family
= FF_MODERN
;
608 facename
.Add(_T("Courier New"));
609 facename
.Add(_T("Lucida Console"));
610 facename
.Add(_T("Andale Mono"));
611 facename
.Add(_T("OCR A Extended"));
612 facename
.Add(_T("Terminal"));
616 ff_family
= FF_SWISS
;
617 facename
.Add(_T("Arial"));
618 facename
.Add(_T("Century Gothic"));
619 facename
.Add(_T("Lucida Sans Unicode"));
620 facename
.Add(_T("Tahoma"));
621 facename
.Add(_T("Trebuchet MS"));
622 facename
.Add(_T("Verdana"));
628 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
629 // is returned as default GUI font for compatibility
631 ff_family
= FF_SWISS
;
632 if(wxGetOsVersion(&verMaj
) == wxWINDOWS_NT
&& verMaj
>= 5)
633 facename
.Add(_T("MS Shell Dlg 2"));
635 facename
.Add(_T("MS Shell Dlg"));
638 // "MS Shell Dlg is a mapping mechanism that enables
639 // U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
640 // support locales that have characters that are not contained in code
641 // page 1252. It is not a font but a face name for a nonexistent font."
645 lf
.lfPitchAndFamily
= (BYTE
)(DEFAULT_PITCH
) | ff_family
;
647 if ( !wxStrlen(lf
.lfFaceName
) )
649 SetFaceName(facename
);
653 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
655 wxNativeEncodingInfo info
;
656 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
659 if ( wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
661 if ( !info
.facename
.empty() )
663 // if we have this encoding only in some particular facename, use
664 // the facename - it is better to show the correct characters in a
665 // wrong facename than unreadable text in a correct one
666 SetFaceName(info
.facename
);
670 #endif // wxUSE_FONTMAP
672 // unsupported encoding, replace with the default
673 info
.charset
= DEFAULT_CHARSET
;
677 lf
.lfCharSet
= (BYTE
)info
.charset
;
680 bool wxNativeFontInfo::FromString(const wxString
& s
)
684 wxStringTokenizer
tokenizer(s
, _T(";"));
687 wxString token
= tokenizer
.GetNextToken();
688 if ( token
!= _T('0') )
691 token
= tokenizer
.GetNextToken();
692 if ( !token
.ToLong(&l
) )
696 token
= tokenizer
.GetNextToken();
697 if ( !token
.ToLong(&l
) )
701 token
= tokenizer
.GetNextToken();
702 if ( !token
.ToLong(&l
) )
706 token
= tokenizer
.GetNextToken();
707 if ( !token
.ToLong(&l
) )
709 lf
.lfOrientation
= l
;
711 token
= tokenizer
.GetNextToken();
712 if ( !token
.ToLong(&l
) )
716 token
= tokenizer
.GetNextToken();
717 if ( !token
.ToLong(&l
) )
719 lf
.lfItalic
= (BYTE
)l
;
721 token
= tokenizer
.GetNextToken();
722 if ( !token
.ToLong(&l
) )
724 lf
.lfUnderline
= (BYTE
)l
;
726 token
= tokenizer
.GetNextToken();
727 if ( !token
.ToLong(&l
) )
729 lf
.lfStrikeOut
= (BYTE
)l
;
731 token
= tokenizer
.GetNextToken();
732 if ( !token
.ToLong(&l
) )
734 lf
.lfCharSet
= (BYTE
)l
;
736 token
= tokenizer
.GetNextToken();
737 if ( !token
.ToLong(&l
) )
739 lf
.lfOutPrecision
= (BYTE
)l
;
741 token
= tokenizer
.GetNextToken();
742 if ( !token
.ToLong(&l
) )
744 lf
.lfClipPrecision
= (BYTE
)l
;
746 token
= tokenizer
.GetNextToken();
747 if ( !token
.ToLong(&l
) )
749 lf
.lfQuality
= (BYTE
)l
;
751 token
= tokenizer
.GetNextToken();
752 if ( !token
.ToLong(&l
) )
754 lf
.lfPitchAndFamily
= (BYTE
)l
;
756 token
= tokenizer
.GetNextToken();
759 wxStrcpy(lf
.lfFaceName
, token
.c_str());
764 wxString
wxNativeFontInfo::ToString() const
768 s
.Printf(_T("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
769 0, // version, in case we want to change the format later
788 // ----------------------------------------------------------------------------
790 // ----------------------------------------------------------------------------
792 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
796 m_refData
= new wxFontRefData(info
, hFont
);
803 wxFont::wxFont(const wxString
& fontdesc
)
805 wxNativeFontInfo info
;
806 if ( info
.FromString(fontdesc
) )
810 /* Constructor for a font. Note that the real construction is done
811 * in wxDC::SetFont, when information is available about scaling etc.
813 bool wxFont::DoCreate(int pointSize
,
814 const wxSize
& pixelSize
,
815 bool sizeUsingPixels
,
820 const wxString
& faceName
,
821 wxFontEncoding encoding
)
825 // wxDEFAULT is a valid value for the font size too so we must treat it
826 // specially here (otherwise the size would be 70 == wxDEFAULT value)
827 if ( pointSize
== wxDEFAULT
)
829 pointSize
= wxNORMAL_FONT
->GetPointSize();
832 m_refData
= new wxFontRefData(pointSize
, pixelSize
, sizeUsingPixels
,
833 family
, style
, weight
,
834 underlined
, faceName
, encoding
);
845 // ----------------------------------------------------------------------------
846 // real implementation
847 // ----------------------------------------------------------------------------
849 bool wxFont::RealizeResource()
851 if ( GetResourceHandle() )
853 // VZ: the old code returned false in this case, but it doesn't seem
854 // to make sense because the font _was_ created
858 return M_FONTDATA
->Alloc(this);
861 bool wxFont::FreeResource(bool WXUNUSED(force
))
863 if ( GetResourceHandle() )
873 WXHANDLE
wxFont::GetResourceHandle() const
875 return (WXHANDLE
)GetHFONT();
878 WXHFONT
wxFont::GetHFONT() const
880 return M_FONTDATA
? M_FONTDATA
->GetHFONT() : 0;
883 bool wxFont::IsFree() const
885 return M_FONTDATA
&& (M_FONTDATA
->GetHFONT() == 0);
888 void wxFont::Unshare()
890 // Don't change shared data
893 m_refData
= new wxFontRefData();
897 wxFontRefData
* ref
= new wxFontRefData(*M_FONTDATA
);
903 // ----------------------------------------------------------------------------
904 // change font attribute: we recreate font when doing it
905 // ----------------------------------------------------------------------------
907 void wxFont::SetPointSize(int pointSize
)
911 M_FONTDATA
->SetPointSize(pointSize
);
916 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
920 M_FONTDATA
->SetPixelSize(pixelSize
);
925 void wxFont::SetFamily(int family
)
929 M_FONTDATA
->SetFamily(family
);
934 void wxFont::SetStyle(int style
)
938 M_FONTDATA
->SetStyle(style
);
943 void wxFont::SetWeight(int weight
)
947 M_FONTDATA
->SetWeight(weight
);
952 bool wxFont::SetFaceName(const wxString
& faceName
)
956 bool refdataok
= M_FONTDATA
->SetFaceName(faceName
);
960 // NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
961 // to retrieve a LOGFONT and then compare lf.lfFaceName
962 // with given facename is not reliable at all:
963 // Windows copies the facename given to ::CreateFontIndirect()
964 // without any validity check.
965 // Thus we use wxFontBase::SetFaceName to check if facename
967 return refdataok
&& wxFontBase::SetFaceName(faceName
);
970 void wxFont::SetUnderlined(bool underlined
)
974 M_FONTDATA
->SetUnderlined(underlined
);
979 void wxFont::SetEncoding(wxFontEncoding encoding
)
983 M_FONTDATA
->SetEncoding(encoding
);
988 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
994 *M_FONTDATA
= wxFontRefData(info
);
999 // ----------------------------------------------------------------------------
1001 // ----------------------------------------------------------------------------
1003 int wxFont::GetPointSize() const
1005 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1007 return M_FONTDATA
->GetPointSize();
1010 wxSize
wxFont::GetPixelSize() const
1012 return M_FONTDATA
->GetPixelSize();
1015 bool wxFont::IsUsingSizeInPixels() const
1017 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1019 return M_FONTDATA
->IsUsingSizeInPixels();
1022 int wxFont::GetFamily() const
1024 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1026 return M_FONTDATA
->GetFamily();
1029 int wxFont::GetStyle() const
1031 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1033 return M_FONTDATA
->GetStyle();
1036 int wxFont::GetWeight() const
1038 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1040 return M_FONTDATA
->GetWeight();
1043 bool wxFont::GetUnderlined() const
1045 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
1047 return M_FONTDATA
->GetUnderlined();
1050 wxString
wxFont::GetFaceName() const
1052 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
1054 return M_FONTDATA
->GetFaceName();
1057 wxFontEncoding
wxFont::GetEncoding() const
1059 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
1061 return M_FONTDATA
->GetEncoding();
1064 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
1066 return M_FONTDATA
->HasNativeFontInfo() ? &(M_FONTDATA
->GetNativeFontInfo())
1070 wxString
wxFont::GetNativeFontInfoDesc() const
1072 // be sure we have an HFONT associated...
1073 wxConstCast(this, wxFont
)->RealizeResource();
1074 return wxFontBase::GetNativeFontInfoDesc();
1077 wxString
wxFont::GetNativeFontInfoUserDesc() const
1079 // be sure we have an HFONT associated...
1080 wxConstCast(this, wxFont
)->RealizeResource();
1081 return wxFontBase::GetNativeFontInfoUserDesc();
1084 bool wxFont::IsFixedWidth() const
1086 if ( M_FONTDATA
->HasNativeFontInfo() )
1088 // the two low-order bits specify the pitch of the font, the rest is
1091 (BYTE
)(M_FONTDATA
->GetNativeFontInfo().lf
.lfPitchAndFamily
& PITCH_MASK
);
1093 return pitch
== FIXED_PITCH
;
1096 return wxFontBase::IsFixedWidth();