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(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 { return m_hFont
; }
213 void SetPointSize(int pointSize
)
215 if ( m_nativeFontInfoOk
)
217 m_nativeFontInfo
.SetPointSize(pointSize
);
221 m_pointSize
= pointSize
;
222 m_sizeUsingPixels
= false;
226 void SetPixelSize(const wxSize
& pixelSize
)
228 if ( m_nativeFontInfoOk
)
230 m_nativeFontInfo
.SetPixelSize(pixelSize
);
234 m_pixelSize
= pixelSize
;
235 m_sizeUsingPixels
= true;
239 void SetFamily(int family
)
244 void SetStyle(int style
)
246 if ( m_nativeFontInfoOk
)
247 m_nativeFontInfo
.SetStyle((wxFontStyle
)style
);
252 void SetWeight(int weight
)
254 if ( m_nativeFontInfoOk
)
255 m_nativeFontInfo
.SetWeight((wxFontWeight
)weight
);
260 bool SetFaceName(const wxString
& faceName
)
262 if ( m_nativeFontInfoOk
)
263 return m_nativeFontInfo
.SetFaceName(faceName
);
265 m_faceName
= faceName
;
269 void SetUnderlined(bool underlined
)
271 if ( m_nativeFontInfoOk
)
272 m_nativeFontInfo
.SetUnderlined(underlined
);
274 m_underlined
= underlined
;
277 void SetEncoding(wxFontEncoding encoding
)
279 if ( m_nativeFontInfoOk
)
280 m_nativeFontInfo
.SetEncoding(encoding
);
282 m_encoding
= encoding
;
285 // native font info tests
286 bool HasNativeFontInfo() const { return m_nativeFontInfoOk
; }
288 const wxNativeFontInfo
& GetNativeFontInfo() const
289 { return m_nativeFontInfo
; }
292 // common part of all ctors
294 const wxSize
& pixelSize
,
295 bool sizeUsingPixels
,
300 const wxString
& faceName
,
301 wxFontEncoding encoding
);
303 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
305 // font characterstics
308 bool m_sizeUsingPixels
;
314 wxFontEncoding m_encoding
;
316 // Windows font handle
320 wxNativeFontInfo m_nativeFontInfo
;
321 bool m_nativeFontInfoOk
;
324 #define M_FONTDATA ((wxFontRefData*)m_refData)
326 // ============================================================================
328 // ============================================================================
330 // ----------------------------------------------------------------------------
332 // ----------------------------------------------------------------------------
334 void wxFontRefData::Init(int pointSize
,
335 const wxSize
& pixelSize
,
336 bool sizeUsingPixels
,
341 const wxString
& faceName
,
342 wxFontEncoding encoding
)
345 m_pointSize
= pointSize
== -1 ? wxNORMAL_FONT
->GetPointSize() : pointSize
;
346 m_pixelSize
= pixelSize
;
347 m_sizeUsingPixels
= sizeUsingPixels
;
351 m_underlined
= underlined
;
352 m_faceName
= faceName
;
353 m_encoding
= encoding
;
357 m_nativeFontInfoOk
= false;
360 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
362 // hFont may be zero, or it be passed in case we really want to
363 // use the exact font created in the underlying system
364 // (for example where we can't guarantee conversion from HFONT
365 // to LOGFONT back to HFONT)
368 m_nativeFontInfoOk
= true;
369 m_nativeFontInfo
= info
;
370 // This is the best we can do since we don't have the
371 // correct information at this point.
375 wxFontRefData::~wxFontRefData()
380 bool wxFontRefData::Alloc(wxFont
*font
)
382 if ( !m_nativeFontInfoOk
)
384 wxFillLogFont(&m_nativeFontInfo
.lf
, font
);
385 m_nativeFontInfoOk
= true;
388 HFONT hfont
= ::CreateFontIndirect(&m_nativeFontInfo
.lf
);
391 wxLogLastError(wxT("CreateFont"));
395 m_hFont
= (WXHFONT
)hfont
;
399 void wxFontRefData::Free()
403 if ( !::DeleteObject((HFONT
) m_hFont
) )
405 wxLogLastError(wxT("DeleteObject(font)"));
412 // ----------------------------------------------------------------------------
414 // ----------------------------------------------------------------------------
416 void wxNativeFontInfo::Init()
420 // we get better font quality if we use this instead of DEFAULT_QUALITY
421 // apparently without any drawbacks
423 lf
.lfQuality
= CLEARTYPE_QUALITY
;
425 lf
.lfQuality
= PROOF_QUALITY
;
429 int wxNativeFontInfo::GetPointSize() const
431 // FIXME: using the screen here results in incorrect font size calculation
433 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
435 return (int) (((72.0*(double)abs(lf
.lfHeight
)) / (double) ppInch
) + 0.5);
438 wxSize
wxNativeFontInfo::GetPixelSize() const
441 ret
.SetHeight(lf
.lfHeight
);
442 ret
.SetWidth(lf
.lfWidth
);
446 wxFontStyle
wxNativeFontInfo::GetStyle() const
448 return lf
.lfItalic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
;
451 wxFontWeight
wxNativeFontInfo::GetWeight() const
453 if ( lf
.lfWeight
<= 300 )
454 return wxFONTWEIGHT_LIGHT
;
456 if ( lf
.lfWeight
>= 600 )
457 return wxFONTWEIGHT_BOLD
;
459 return wxFONTWEIGHT_NORMAL
;
462 bool wxNativeFontInfo::GetUnderlined() const
464 return lf
.lfUnderline
!= 0;
467 wxString
wxNativeFontInfo::GetFaceName() const
469 return lf
.lfFaceName
;
472 wxFontFamily
wxNativeFontInfo::GetFamily() const
476 // extract family from pitch-and-family
477 switch ( lf
.lfPitchAndFamily
& ~PITCH_MASK
)
480 family
= wxFONTFAMILY_ROMAN
;
484 wxFAIL_MSG( _T("unknown LOGFONT::lfFamily value") );
488 family
= wxFONTFAMILY_SWISS
;
492 family
= wxFONTFAMILY_SCRIPT
;
496 family
= wxFONTFAMILY_MODERN
;
500 family
= wxFONTFAMILY_DECORATIVE
;
507 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
509 return wxGetFontEncFromCharSet(lf
.lfCharSet
);
512 void wxNativeFontInfo::SetPointSize(int pointsize
)
514 // FIXME: using the screen here results in incorrect font size calculation
516 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
518 lf
.lfHeight
= -(int)((pointsize
*((double)ppInch
)/72.0) + 0.5);
521 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
523 lf
.lfHeight
= pixelSize
.GetHeight();
524 lf
.lfWidth
= pixelSize
.GetWidth();
528 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
533 wxFAIL_MSG( _T("unknown font style") );
536 case wxFONTSTYLE_NORMAL
:
540 case wxFONTSTYLE_ITALIC
:
541 case wxFONTSTYLE_SLANT
:
547 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
552 wxFAIL_MSG( _T("unknown font weight") );
555 case wxFONTWEIGHT_NORMAL
:
556 lf
.lfWeight
= FW_NORMAL
;
559 case wxFONTWEIGHT_LIGHT
:
560 lf
.lfWeight
= FW_LIGHT
;
563 case wxFONTWEIGHT_BOLD
:
564 lf
.lfWeight
= FW_BOLD
;
569 void wxNativeFontInfo::SetUnderlined(bool underlined
)
571 lf
.lfUnderline
= underlined
;
574 bool wxNativeFontInfo::SetFaceName(const wxString
& facename
)
576 size_t len
= WXSIZEOF(lf
.lfFaceName
);
577 wxStrncpy(lf
.lfFaceName
, facename
, len
);
578 lf
.lfFaceName
[len
- 1] = '\0'; // truncate the face name
582 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
585 wxArrayString facename
;
587 // the list of fonts associated with a family was partially
588 // taken from http://www.codestyle.org/css/font-family
593 ff_family
= FF_SCRIPT
;
594 facename
.Add(_T("Script"));
595 facename
.Add(_T("Brush Script MT"));
596 facename
.Add(_T("Comic Sans MS"));
597 facename
.Add(_T("Lucida Handwriting"));
601 ff_family
= FF_DECORATIVE
;
602 facename
.Add(_T("Old English Text MT"));
603 facename
.Add(_T("Comic Sans MS"));
604 facename
.Add(_T("Lucida Handwriting"));
608 ff_family
= FF_ROMAN
;
609 facename
.Add(_T("Times New Roman"));
610 facename
.Add(_T("Georgia"));
611 facename
.Add(_T("Garamond"));
612 facename
.Add(_T("Bookman Old Style"));
613 facename
.Add(_T("Book Antiqua"));
618 ff_family
= FF_MODERN
;
619 facename
.Add(_T("Courier New"));
620 facename
.Add(_T("Lucida Console"));
621 facename
.Add(_T("Andale Mono"));
622 facename
.Add(_T("OCR A Extended"));
623 facename
.Add(_T("Terminal"));
627 ff_family
= FF_SWISS
;
628 facename
.Add(_T("Arial"));
629 facename
.Add(_T("Century Gothic"));
630 facename
.Add(_T("Lucida Sans Unicode"));
631 facename
.Add(_T("Tahoma"));
632 facename
.Add(_T("Trebuchet MS"));
633 facename
.Add(_T("Verdana"));
639 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
640 // is returned as default GUI font for compatibility
642 ff_family
= FF_SWISS
;
643 if(wxGetOsVersion(&verMaj
) == wxOS_WINDOWS_NT
&& verMaj
>= 5)
644 facename
.Add(_T("MS Shell Dlg 2"));
646 facename
.Add(_T("MS Shell Dlg"));
649 // "MS Shell Dlg is a mapping mechanism that enables
650 // U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
651 // support locales that have characters that are not contained in code
652 // page 1252. It is not a font but a face name for a nonexistent font."
656 lf
.lfPitchAndFamily
= (BYTE
)(DEFAULT_PITCH
) | ff_family
;
658 if ( !wxStrlen(lf
.lfFaceName
) )
660 SetFaceName(facename
);
664 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
666 wxNativeEncodingInfo info
;
667 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
670 if ( wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
672 if ( !info
.facename
.empty() )
674 // if we have this encoding only in some particular facename, use
675 // the facename - it is better to show the correct characters in a
676 // wrong facename than unreadable text in a correct one
677 SetFaceName(info
.facename
);
681 #endif // wxUSE_FONTMAP
683 // unsupported encoding, replace with the default
684 info
.charset
= DEFAULT_CHARSET
;
688 lf
.lfCharSet
= (BYTE
)info
.charset
;
691 bool wxNativeFontInfo::FromString(const wxString
& s
)
695 wxStringTokenizer
tokenizer(s
, _T(";"));
698 wxString token
= tokenizer
.GetNextToken();
699 if ( token
!= _T('0') )
702 token
= tokenizer
.GetNextToken();
703 if ( !token
.ToLong(&l
) )
707 token
= tokenizer
.GetNextToken();
708 if ( !token
.ToLong(&l
) )
712 token
= tokenizer
.GetNextToken();
713 if ( !token
.ToLong(&l
) )
717 token
= tokenizer
.GetNextToken();
718 if ( !token
.ToLong(&l
) )
720 lf
.lfOrientation
= l
;
722 token
= tokenizer
.GetNextToken();
723 if ( !token
.ToLong(&l
) )
727 token
= tokenizer
.GetNextToken();
728 if ( !token
.ToLong(&l
) )
730 lf
.lfItalic
= (BYTE
)l
;
732 token
= tokenizer
.GetNextToken();
733 if ( !token
.ToLong(&l
) )
735 lf
.lfUnderline
= (BYTE
)l
;
737 token
= tokenizer
.GetNextToken();
738 if ( !token
.ToLong(&l
) )
740 lf
.lfStrikeOut
= (BYTE
)l
;
742 token
= tokenizer
.GetNextToken();
743 if ( !token
.ToLong(&l
) )
745 lf
.lfCharSet
= (BYTE
)l
;
747 token
= tokenizer
.GetNextToken();
748 if ( !token
.ToLong(&l
) )
750 lf
.lfOutPrecision
= (BYTE
)l
;
752 token
= tokenizer
.GetNextToken();
753 if ( !token
.ToLong(&l
) )
755 lf
.lfClipPrecision
= (BYTE
)l
;
757 token
= tokenizer
.GetNextToken();
758 if ( !token
.ToLong(&l
) )
760 lf
.lfQuality
= (BYTE
)l
;
762 token
= tokenizer
.GetNextToken();
763 if ( !token
.ToLong(&l
) )
765 lf
.lfPitchAndFamily
= (BYTE
)l
;
767 token
= tokenizer
.GetNextToken();
770 wxStrcpy(lf
.lfFaceName
, token
.c_str());
775 wxString
wxNativeFontInfo::ToString() const
779 s
.Printf(_T("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
780 0, // version, in case we want to change the format later
799 // ----------------------------------------------------------------------------
801 // ----------------------------------------------------------------------------
803 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
807 m_refData
= new wxFontRefData(info
, hFont
);
814 wxFont::wxFont(const wxString
& fontdesc
)
816 wxNativeFontInfo info
;
817 if ( info
.FromString(fontdesc
) )
821 /* Constructor for a font. Note that the real construction is done
822 * in wxDC::SetFont, when information is available about scaling etc.
824 bool wxFont::DoCreate(int pointSize
,
825 const wxSize
& pixelSize
,
826 bool sizeUsingPixels
,
831 const wxString
& faceName
,
832 wxFontEncoding encoding
)
836 // wxDEFAULT is a valid value for the font size too so we must treat it
837 // specially here (otherwise the size would be 70 == wxDEFAULT value)
838 if ( pointSize
== wxDEFAULT
)
840 pointSize
= wxNORMAL_FONT
->GetPointSize();
843 m_refData
= new wxFontRefData(pointSize
, pixelSize
, sizeUsingPixels
,
844 family
, style
, weight
,
845 underlined
, faceName
, encoding
);
856 // ----------------------------------------------------------------------------
857 // real implementation
858 // ----------------------------------------------------------------------------
860 wxObjectRefData
*wxFont::CreateRefData() const
862 return new wxFontRefData();
865 wxObjectRefData
*wxFont::CloneRefData(const wxObjectRefData
*data
) const
867 return new wxFontRefData(*wx_static_cast(const wxFontRefData
*, data
));
870 bool wxFont::RealizeResource()
872 if ( GetResourceHandle() )
874 // VZ: the old code returned false in this case, but it doesn't seem
875 // to make sense because the font _was_ created
879 return M_FONTDATA
->Alloc(this);
882 bool wxFont::FreeResource(bool WXUNUSED(force
))
884 if ( GetResourceHandle() )
894 WXHANDLE
wxFont::GetResourceHandle() const
896 return (WXHANDLE
)GetHFONT();
899 WXHFONT
wxFont::GetHFONT() const
901 return M_FONTDATA
? M_FONTDATA
->GetHFONT() : 0;
904 bool wxFont::IsFree() const
906 return M_FONTDATA
&& (M_FONTDATA
->GetHFONT() == 0);
909 // ----------------------------------------------------------------------------
910 // change font attribute: we recreate font when doing it
911 // ----------------------------------------------------------------------------
913 void wxFont::SetPointSize(int pointSize
)
917 M_FONTDATA
->SetPointSize(pointSize
);
922 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
926 M_FONTDATA
->SetPixelSize(pixelSize
);
931 void wxFont::SetFamily(int family
)
935 M_FONTDATA
->SetFamily(family
);
940 void wxFont::SetStyle(int style
)
944 M_FONTDATA
->SetStyle(style
);
949 void wxFont::SetWeight(int weight
)
953 M_FONTDATA
->SetWeight(weight
);
958 bool wxFont::SetFaceName(const wxString
& faceName
)
962 bool refdataok
= M_FONTDATA
->SetFaceName(faceName
);
966 // NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
967 // to retrieve a LOGFONT and then compare lf.lfFaceName
968 // with given facename is not reliable at all:
969 // Windows copies the facename given to ::CreateFontIndirect()
970 // without any validity check.
971 // Thus we use wxFontBase::SetFaceName to check if facename
973 return refdataok
&& wxFontBase::SetFaceName(faceName
);
976 void wxFont::SetUnderlined(bool underlined
)
980 M_FONTDATA
->SetUnderlined(underlined
);
985 void wxFont::SetEncoding(wxFontEncoding encoding
)
989 M_FONTDATA
->SetEncoding(encoding
);
994 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
998 *M_FONTDATA
= wxFontRefData(info
);
1003 // ----------------------------------------------------------------------------
1005 // ----------------------------------------------------------------------------
1007 int wxFont::GetPointSize() const
1009 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1011 return M_FONTDATA
->GetPointSize();
1014 wxSize
wxFont::GetPixelSize() const
1016 wxCHECK_MSG( Ok(), wxDefaultSize
, wxT("invalid font") );
1018 return M_FONTDATA
->GetPixelSize();
1021 bool wxFont::IsUsingSizeInPixels() const
1023 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1025 return M_FONTDATA
->IsUsingSizeInPixels();
1028 int wxFont::GetFamily() const
1030 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1032 return M_FONTDATA
->GetFamily();
1035 int wxFont::GetStyle() const
1037 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1039 return M_FONTDATA
->GetStyle();
1042 int wxFont::GetWeight() const
1044 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
1046 return M_FONTDATA
->GetWeight();
1049 bool wxFont::GetUnderlined() const
1051 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
1053 return M_FONTDATA
->GetUnderlined();
1056 wxString
wxFont::GetFaceName() const
1058 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
1060 return M_FONTDATA
->GetFaceName();
1063 wxFontEncoding
wxFont::GetEncoding() const
1065 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
1067 return M_FONTDATA
->GetEncoding();
1070 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
1072 return Ok() && M_FONTDATA
->HasNativeFontInfo() ? &(M_FONTDATA
->GetNativeFontInfo())
1076 wxString
wxFont::GetNativeFontInfoDesc() const
1078 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
1080 // be sure we have an HFONT associated...
1081 wxConstCast(this, wxFont
)->RealizeResource();
1082 return wxFontBase::GetNativeFontInfoDesc();
1085 wxString
wxFont::GetNativeFontInfoUserDesc() const
1087 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
1089 // be sure we have an HFONT associated...
1090 wxConstCast(this, wxFont
)->RealizeResource();
1091 return wxFontBase::GetNativeFontInfoUserDesc();
1094 bool wxFont::IsFixedWidth() const
1096 if ( M_FONTDATA
->HasNativeFontInfo() )
1098 // the two low-order bits specify the pitch of the font, the rest is
1101 (BYTE
)(M_FONTDATA
->GetNativeFontInfo().lf
.lfPitchAndFamily
& PITCH_MASK
);
1103 return pitch
== FIXED_PITCH
;
1106 return wxFontBase::IsFixedWidth();