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 Init(data
.m_nativeFontInfo
);
140 virtual ~wxFontRefData();
147 // all wxFont accessors
148 int GetPointSize() const
150 return m_nativeFontInfo
.GetPointSize();
153 wxSize
GetPixelSize() const
155 return m_nativeFontInfo
.GetPixelSize();
158 bool IsUsingSizeInPixels() const
160 return m_sizeUsingPixels
;
163 wxFontFamily
GetFamily() const
165 return m_nativeFontInfo
.GetFamily();
168 wxFontStyle
GetStyle() const
170 return m_nativeFontInfo
.GetStyle();
173 wxFontWeight
GetWeight() const
175 return m_nativeFontInfo
.GetWeight();
178 bool GetUnderlined() const
180 return m_nativeFontInfo
.GetUnderlined();
183 wxString
GetFaceName() const
185 return m_nativeFontInfo
.GetFaceName();
188 wxFontEncoding
GetEncoding() const
190 return m_nativeFontInfo
.GetEncoding();
193 WXHFONT
GetHFONT() const
196 const_cast<wxFontRefData
*>(this)->Alloc();
198 return (WXHFONT
)m_hFont
;
201 bool HasHFONT() const
206 // ... and setters: notice that all of them invalidate the currently
207 // allocated HFONT, if any, so that the next call to GetHFONT() recreates a
209 void SetPointSize(int pointSize
)
213 m_nativeFontInfo
.SetPointSize(pointSize
);
214 m_sizeUsingPixels
= false;
217 void SetPixelSize(const wxSize
& pixelSize
)
221 m_nativeFontInfo
.SetPixelSize(pixelSize
);
222 m_sizeUsingPixels
= true;
225 void SetFamily(wxFontFamily family
)
229 m_nativeFontInfo
.SetFamily(family
);
232 void SetStyle(wxFontStyle style
)
236 m_nativeFontInfo
.SetStyle(style
);
239 void SetWeight(wxFontWeight weight
)
243 m_nativeFontInfo
.SetWeight(weight
);
246 bool SetFaceName(const wxString
& faceName
)
250 return m_nativeFontInfo
.SetFaceName(faceName
);
253 void SetUnderlined(bool underlined
)
257 m_nativeFontInfo
.SetUnderlined(underlined
);
260 void SetEncoding(wxFontEncoding encoding
)
264 m_nativeFontInfo
.SetEncoding(encoding
);
268 bool HasNativeFontInfo() const { return true; }
270 const wxNativeFontInfo
& GetNativeFontInfo() const
271 { return m_nativeFontInfo
; }
273 void SetNativeFontInfo(const wxNativeFontInfo
& nativeFontInfo
)
277 m_nativeFontInfo
= nativeFontInfo
;
281 // common part of all ctors
283 const wxSize
& pixelSize
,
284 bool sizeUsingPixels
,
289 const wxString
& faceName
,
290 wxFontEncoding encoding
);
292 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
294 // are we using m_nativeFontInfo.lf.lfHeight for point size or pixel size?
295 bool m_sizeUsingPixels
;
297 // Windows font handle, created on demand in GetHFONT()
301 wxNativeFontInfo m_nativeFontInfo
;
304 #define M_FONTDATA ((wxFontRefData*)m_refData)
306 // ============================================================================
308 // ============================================================================
310 // ----------------------------------------------------------------------------
312 // ----------------------------------------------------------------------------
314 void wxFontRefData::Init(int pointSize
,
315 const wxSize
& pixelSize
,
316 bool sizeUsingPixels
,
321 const wxString
& faceName
,
322 wxFontEncoding encoding
)
326 m_sizeUsingPixels
= sizeUsingPixels
;
327 if ( m_sizeUsingPixels
)
328 SetPixelSize(pixelSize
);
330 SetPointSize(pointSize
);
334 SetUnderlined(underlined
);
336 // set the family/facename
338 if ( !faceName
.empty() )
339 SetFaceName(faceName
);
341 // deal with encoding now (it may override the font family and facename
342 // so do it after setting them)
343 SetEncoding(encoding
);
346 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
348 // hFont may be zero, or it be passed in case we really want to
349 // use the exact font created in the underlying system
350 // (for example where we can't guarantee conversion from HFONT
351 // to LOGFONT back to HFONT)
352 m_hFont
= (HFONT
)hFont
;
353 m_nativeFontInfo
= info
;
355 // TODO: m_sizeUsingPixels?
358 wxFontRefData::~wxFontRefData()
363 bool wxFontRefData::Alloc()
365 m_hFont
= ::CreateFontIndirect(&m_nativeFontInfo
.lf
);
368 wxLogLastError(wxT("CreateFont"));
375 void wxFontRefData::Free()
379 if ( !::DeleteObject(m_hFont
) )
381 wxLogLastError(wxT("DeleteObject(font)"));
388 // ----------------------------------------------------------------------------
390 // ----------------------------------------------------------------------------
392 void wxNativeFontInfo::Init()
396 // we get better font quality if we use PROOF_QUALITY instead of
397 // DEFAULT_QUALITY but some fonts (e.g. "Terminal 6pt") are not available
398 // then so we allow to set a global option to choose between quality and
399 // wider font selection
401 lf
.lfQuality
= CLEARTYPE_QUALITY
;
403 lf
.lfQuality
= wxSystemOptions::GetOptionInt("msw.font.no-proof-quality")
409 int wxNativeFontInfo::GetPointSize() const
411 // FIXME: using the screen here results in incorrect font size calculation
413 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
415 // BC++ 2007 doesn't provide abs(long) overload, hence the cast
416 return (int) (((72.0*abs((int)lf
.lfHeight
)) / (double) ppInch
) + 0.5);
419 wxSize
wxNativeFontInfo::GetPixelSize() const
422 ret
.SetHeight(abs((int)lf
.lfHeight
));
423 ret
.SetWidth(lf
.lfWidth
);
427 wxFontStyle
wxNativeFontInfo::GetStyle() const
429 return lf
.lfItalic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
;
432 wxFontWeight
wxNativeFontInfo::GetWeight() const
434 if ( lf
.lfWeight
<= 300 )
435 return wxFONTWEIGHT_LIGHT
;
437 if ( lf
.lfWeight
>= 600 )
438 return wxFONTWEIGHT_BOLD
;
440 return wxFONTWEIGHT_NORMAL
;
443 bool wxNativeFontInfo::GetUnderlined() const
445 return lf
.lfUnderline
!= 0;
448 wxString
wxNativeFontInfo::GetFaceName() const
450 return lf
.lfFaceName
;
453 wxFontFamily
wxNativeFontInfo::GetFamily() const
457 // extract family from pitch-and-family
458 switch ( lf
.lfPitchAndFamily
& ~PITCH_MASK
)
461 family
= wxFONTFAMILY_UNKNOWN
;
465 family
= wxFONTFAMILY_ROMAN
;
469 family
= wxFONTFAMILY_SWISS
;
473 family
= wxFONTFAMILY_SCRIPT
;
477 family
= wxFONTFAMILY_MODERN
;
481 family
= wxFONTFAMILY_DECORATIVE
;
485 wxFAIL_MSG( "unknown LOGFONT::lfFamily value" );
486 family
= wxFONTFAMILY_UNKNOWN
;
487 // just to avoid a warning
493 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
495 return wxGetFontEncFromCharSet(lf
.lfCharSet
);
498 void wxNativeFontInfo::SetPointSize(int pointsize
)
500 // FIXME: using the screen here results in incorrect font size calculation
502 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
504 lf
.lfHeight
= -(int)((pointsize
*((double)ppInch
)/72.0) + 0.5);
507 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
509 // NOTE: although the MSW port allows for negative pixel size heights,
510 // other ports don't and since it's a very useful feature assert
511 // here if we get a negative height:
512 wxCHECK_RET( pixelSize
.GetWidth() >= 0 && pixelSize
.GetHeight() > 0,
513 "Negative values for the pixel size or zero pixel height are not allowed" );
515 lf
.lfHeight
= pixelSize
.GetHeight();
516 lf
.lfWidth
= pixelSize
.GetWidth();
519 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
524 wxFAIL_MSG( "unknown font style" );
527 case wxFONTSTYLE_NORMAL
:
531 case wxFONTSTYLE_ITALIC
:
532 case wxFONTSTYLE_SLANT
:
538 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
543 wxFAIL_MSG( "unknown font weight" );
546 case wxFONTWEIGHT_NORMAL
:
547 lf
.lfWeight
= FW_NORMAL
;
550 case wxFONTWEIGHT_LIGHT
:
551 lf
.lfWeight
= FW_LIGHT
;
554 case wxFONTWEIGHT_BOLD
:
555 lf
.lfWeight
= FW_BOLD
;
560 void wxNativeFontInfo::SetUnderlined(bool underlined
)
562 lf
.lfUnderline
= underlined
;
565 bool wxNativeFontInfo::SetFaceName(const wxString
& facename
)
567 wxStrlcpy(lf
.lfFaceName
, facename
.c_str(), WXSIZEOF(lf
.lfFaceName
));
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
581 case wxFONTFAMILY_SCRIPT
:
582 ff_family
= FF_SCRIPT
;
583 facename
.Add(wxS("Script"));
584 facename
.Add(wxS("Brush Script MT"));
585 facename
.Add(wxS("Comic Sans MS"));
586 facename
.Add(wxS("Lucida Handwriting"));
589 case wxFONTFAMILY_DECORATIVE
:
590 ff_family
= FF_DECORATIVE
;
591 facename
.Add(wxS("Old English Text MT"));
592 facename
.Add(wxS("Comic Sans MS"));
593 facename
.Add(wxS("Lucida Handwriting"));
596 case wxFONTFAMILY_ROMAN
:
597 ff_family
= FF_ROMAN
;
598 facename
.Add(wxS("Times New Roman"));
599 facename
.Add(wxS("Georgia"));
600 facename
.Add(wxS("Garamond"));
601 facename
.Add(wxS("Bookman Old Style"));
602 facename
.Add(wxS("Book Antiqua"));
605 case wxFONTFAMILY_TELETYPE
:
606 case wxFONTFAMILY_MODERN
:
607 ff_family
= FF_MODERN
;
608 facename
.Add(wxS("Courier New"));
609 facename
.Add(wxS("Lucida Console"));
610 facename
.Add(wxS("Andale Mono"));
611 facename
.Add(wxS("OCR A Extended"));
612 facename
.Add(wxS("Terminal"));
615 case wxFONTFAMILY_SWISS
:
616 ff_family
= FF_SWISS
;
617 facename
.Add(wxS("Arial"));
618 facename
.Add(wxS("Century Gothic"));
619 facename
.Add(wxS("Lucida Sans Unicode"));
620 facename
.Add(wxS("Tahoma"));
621 facename
.Add(wxS("Trebuchet MS"));
622 facename
.Add(wxS("Verdana"));
625 case wxFONTFAMILY_DEFAULT
:
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
) == wxOS_WINDOWS_NT
&& verMaj
>= 5)
633 facename
.Add(wxS("MS Shell Dlg 2"));
635 facename
.Add(wxS("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
, wxS(";"));
687 wxString token
= tokenizer
.GetNextToken();
688 if ( token
!= wxS('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(wxS("%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
783 (const wxChar
*)lf
.lfFaceName
);
788 // ----------------------------------------------------------------------------
790 // ----------------------------------------------------------------------------
792 wxFont::wxFont(const wxString
& fontdesc
)
794 wxNativeFontInfo info
;
795 if ( info
.FromString(fontdesc
) )
799 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
803 m_refData
= new wxFontRefData(info
, hFont
);
805 return RealizeResource();
808 bool wxFont::DoCreate(int pointSize
,
809 const wxSize
& pixelSize
,
810 bool sizeUsingPixels
,
815 const wxString
& faceName
,
816 wxFontEncoding encoding
)
820 // wxDEFAULT is a valid value for the font size too so we must treat it
821 // specially here (otherwise the size would be 70 == wxDEFAULT value)
822 if ( pointSize
== wxDEFAULT
)
824 pointSize
= wxNORMAL_FONT
->GetPointSize();
827 m_refData
= new wxFontRefData(pointSize
, pixelSize
, sizeUsingPixels
,
828 family
, style
, weight
,
829 underlined
, faceName
, encoding
);
831 return RealizeResource();
838 // ----------------------------------------------------------------------------
839 // real implementation
840 // ----------------------------------------------------------------------------
842 wxGDIRefData
*wxFont::CreateGDIRefData() const
844 return new wxFontRefData();
847 wxGDIRefData
*wxFont::CloneGDIRefData(const wxGDIRefData
*data
) const
849 return new wxFontRefData(*static_cast<const wxFontRefData
*>(data
));
852 bool wxFont::RealizeResource()
854 // NOTE: the GetHFONT() call automatically triggers a reallocation of
855 // the HFONT if necessary (will do nothing if we already have the resource);
856 // it returns NULL only if there is a failure in wxFontRefData::Alloc()...
857 return GetHFONT() != NULL
;
860 bool wxFont::FreeResource(bool WXUNUSED(force
))
870 WXHANDLE
wxFont::GetResourceHandle() const
872 return (WXHANDLE
)GetHFONT();
875 WXHFONT
wxFont::GetHFONT() const
877 // NOTE: wxFontRefData::GetHFONT() will automatically call
878 // wxFontRefData::Alloc() if necessary
879 return M_FONTDATA
? M_FONTDATA
->GetHFONT() : 0;
882 bool wxFont::IsFree() const
884 return M_FONTDATA
&& !M_FONTDATA
->HasHFONT();
887 // ----------------------------------------------------------------------------
888 // change font attribute: we recreate font when doing it
889 // ----------------------------------------------------------------------------
891 void wxFont::SetPointSize(int pointSize
)
896 M_FONTDATA
->SetPointSize(pointSize
);
899 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
903 M_FONTDATA
->SetPixelSize(pixelSize
);
906 void wxFont::SetFamily(wxFontFamily family
)
910 M_FONTDATA
->SetFamily(family
);
913 void wxFont::SetStyle(wxFontStyle style
)
917 M_FONTDATA
->SetStyle(style
);
920 void wxFont::SetWeight(wxFontWeight weight
)
924 M_FONTDATA
->SetWeight(weight
);
927 bool wxFont::SetFaceName(const wxString
& faceName
)
931 if ( !M_FONTDATA
->SetFaceName(faceName
) )
934 // NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
935 // to retrieve a LOGFONT and then compare lf.lfFaceName
936 // with given facename is not reliable at all:
937 // Windows copies the facename given to ::CreateFontIndirect()
938 // without any validity check.
939 // Thus we use wxFontBase::SetFaceName to check if facename
941 return wxFontBase::SetFaceName(faceName
);
944 void wxFont::SetUnderlined(bool underlined
)
948 M_FONTDATA
->SetUnderlined(underlined
);
951 void wxFont::SetEncoding(wxFontEncoding encoding
)
955 M_FONTDATA
->SetEncoding(encoding
);
958 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
962 M_FONTDATA
->SetNativeFontInfo(info
);
965 // ----------------------------------------------------------------------------
967 // ----------------------------------------------------------------------------
969 int wxFont::GetPointSize() const
971 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
973 return M_FONTDATA
->GetPointSize();
976 wxSize
wxFont::GetPixelSize() const
978 wxCHECK_MSG( IsOk(), wxDefaultSize
, wxT("invalid font") );
980 return M_FONTDATA
->GetPixelSize();
983 bool wxFont::IsUsingSizeInPixels() const
985 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
987 return M_FONTDATA
->IsUsingSizeInPixels();
990 wxFontFamily
wxFont::GetFamily() const
992 wxCHECK_MSG( IsOk(), wxFONTFAMILY_MAX
, wxT("invalid font") );
994 return M_FONTDATA
->GetFamily();
997 wxFontStyle
wxFont::GetStyle() const
999 wxCHECK_MSG( IsOk(), wxFONTSTYLE_MAX
, wxT("invalid font") );
1001 return M_FONTDATA
->GetStyle();
1004 wxFontWeight
wxFont::GetWeight() const
1006 wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX
, wxT("invalid font") );
1008 return M_FONTDATA
->GetWeight();
1011 bool wxFont::GetUnderlined() const
1013 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
1015 return M_FONTDATA
->GetUnderlined();
1018 wxString
wxFont::GetFaceName() const
1020 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
1022 return M_FONTDATA
->GetFaceName();
1025 wxFontEncoding
wxFont::GetEncoding() const
1027 wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
1029 return M_FONTDATA
->GetEncoding();
1032 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
1034 return IsOk() && M_FONTDATA
->HasNativeFontInfo() ? &(M_FONTDATA
->GetNativeFontInfo())
1038 wxString
wxFont::GetNativeFontInfoDesc() const
1040 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
1042 // be sure we have an HFONT associated...
1043 const_cast<wxFont
*>(this)->RealizeResource();
1044 return wxFontBase::GetNativeFontInfoDesc();
1047 wxString
wxFont::GetNativeFontInfoUserDesc() const
1049 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
1051 // be sure we have an HFONT associated...
1052 const_cast<wxFont
*>(this)->RealizeResource();
1053 return wxFontBase::GetNativeFontInfoUserDesc();
1056 bool wxFont::IsFixedWidth() const
1058 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
1060 if ( M_FONTDATA
->HasNativeFontInfo() )
1062 // the two low-order bits specify the pitch of the font, the rest is
1065 (BYTE
)(M_FONTDATA
->GetNativeFontInfo().lf
.lfPitchAndFamily
& PITCH_MASK
);
1067 return pitch
== FIXED_PITCH
;
1070 return wxFontBase::IsFixedWidth();