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
)
219 wxCHECK_RET( pixelSize
.GetWidth() >= 0, "negative font width" );
220 wxCHECK_RET( pixelSize
.GetHeight() != 0, "zero font height" );
224 m_nativeFontInfo
.SetPixelSize(pixelSize
);
225 m_sizeUsingPixels
= true;
228 void SetFamily(wxFontFamily family
)
232 m_nativeFontInfo
.SetFamily(family
);
235 void SetStyle(wxFontStyle style
)
239 m_nativeFontInfo
.SetStyle(style
);
242 void SetWeight(wxFontWeight weight
)
246 m_nativeFontInfo
.SetWeight(weight
);
249 bool SetFaceName(const wxString
& faceName
)
253 return m_nativeFontInfo
.SetFaceName(faceName
);
256 void SetUnderlined(bool underlined
)
260 m_nativeFontInfo
.SetUnderlined(underlined
);
263 void SetEncoding(wxFontEncoding encoding
)
267 m_nativeFontInfo
.SetEncoding(encoding
);
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 // MSW accepts both positive and negative heights here but they mean
510 // different things: positive specifies the cell height while negative
511 // specifies the character height. We used to just pass the value to MSW
512 // unchanged but changed the behaviour for positive values in 2.9.1 to
513 // match other ports and, more importantly, the expected behaviour. So now
514 // passing the negative height doesn't make sense at all any more but we
515 // still accept it for compatibility with the existing code which worked
516 // around the wrong interpretation of the height argument in older wxMSW
517 // versions by passing a negative value explicitly itself.
518 lf
.lfHeight
= -abs(pixelSize
.GetHeight());
519 lf
.lfWidth
= pixelSize
.GetWidth();
522 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
527 wxFAIL_MSG( "unknown font style" );
530 case wxFONTSTYLE_NORMAL
:
534 case wxFONTSTYLE_ITALIC
:
535 case wxFONTSTYLE_SLANT
:
541 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
546 wxFAIL_MSG( "unknown font weight" );
549 case wxFONTWEIGHT_NORMAL
:
550 lf
.lfWeight
= FW_NORMAL
;
553 case wxFONTWEIGHT_LIGHT
:
554 lf
.lfWeight
= FW_LIGHT
;
557 case wxFONTWEIGHT_BOLD
:
558 lf
.lfWeight
= FW_BOLD
;
563 void wxNativeFontInfo::SetUnderlined(bool underlined
)
565 lf
.lfUnderline
= underlined
;
568 bool wxNativeFontInfo::SetFaceName(const wxString
& facename
)
570 wxStrlcpy(lf
.lfFaceName
, facename
.c_str(), WXSIZEOF(lf
.lfFaceName
));
574 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
577 wxArrayString facename
;
579 // the list of fonts associated with a family was partially
580 // taken from http://www.codestyle.org/css/font-family
584 case wxFONTFAMILY_SCRIPT
:
585 ff_family
= FF_SCRIPT
;
586 facename
.Add(wxS("Script"));
587 facename
.Add(wxS("Brush Script MT"));
588 facename
.Add(wxS("Comic Sans MS"));
589 facename
.Add(wxS("Lucida Handwriting"));
592 case wxFONTFAMILY_DECORATIVE
:
593 ff_family
= FF_DECORATIVE
;
594 facename
.Add(wxS("Old English Text MT"));
595 facename
.Add(wxS("Comic Sans MS"));
596 facename
.Add(wxS("Lucida Handwriting"));
599 case wxFONTFAMILY_ROMAN
:
600 ff_family
= FF_ROMAN
;
601 facename
.Add(wxS("Times New Roman"));
602 facename
.Add(wxS("Georgia"));
603 facename
.Add(wxS("Garamond"));
604 facename
.Add(wxS("Bookman Old Style"));
605 facename
.Add(wxS("Book Antiqua"));
608 case wxFONTFAMILY_TELETYPE
:
609 case wxFONTFAMILY_MODERN
:
610 ff_family
= FF_MODERN
;
611 facename
.Add(wxS("Courier New"));
612 facename
.Add(wxS("Lucida Console"));
613 facename
.Add(wxS("Andale Mono"));
614 facename
.Add(wxS("OCR A Extended"));
615 facename
.Add(wxS("Terminal"));
618 case wxFONTFAMILY_SWISS
:
619 ff_family
= FF_SWISS
;
620 facename
.Add(wxS("Arial"));
621 facename
.Add(wxS("Century Gothic"));
622 facename
.Add(wxS("Lucida Sans Unicode"));
623 facename
.Add(wxS("Tahoma"));
624 facename
.Add(wxS("Trebuchet MS"));
625 facename
.Add(wxS("Verdana"));
628 case wxFONTFAMILY_DEFAULT
:
631 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
632 // is returned as default GUI font for compatibility
634 ff_family
= FF_SWISS
;
635 if(wxGetOsVersion(&verMaj
) == wxOS_WINDOWS_NT
&& verMaj
>= 5)
636 facename
.Add(wxS("MS Shell Dlg 2"));
638 facename
.Add(wxS("MS Shell Dlg"));
641 // "MS Shell Dlg is a mapping mechanism that enables
642 // U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
643 // support locales that have characters that are not contained in code
644 // page 1252. It is not a font but a face name for a nonexistent font."
648 lf
.lfPitchAndFamily
= (BYTE
)(DEFAULT_PITCH
) | ff_family
;
650 // reset the facename so that CreateFontIndirect() will automatically choose a
651 // face name based only on the font family.
652 lf
.lfFaceName
[0] = '\0';
655 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
657 wxNativeEncodingInfo info
;
658 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
661 if ( wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
663 if ( !info
.facename
.empty() )
665 // if we have this encoding only in some particular facename, use
666 // the facename - it is better to show the correct characters in a
667 // wrong facename than unreadable text in a correct one
668 SetFaceName(info
.facename
);
672 #endif // wxUSE_FONTMAP
674 // unsupported encoding, replace with the default
675 info
.charset
= DEFAULT_CHARSET
;
679 lf
.lfCharSet
= (BYTE
)info
.charset
;
682 bool wxNativeFontInfo::FromString(const wxString
& s
)
686 wxStringTokenizer
tokenizer(s
, wxS(";"), wxTOKEN_RET_EMPTY_ALL
);
689 wxString token
= tokenizer
.GetNextToken();
690 if ( token
!= wxS('0') )
693 token
= tokenizer
.GetNextToken();
694 if ( !token
.ToLong(&l
) )
698 token
= tokenizer
.GetNextToken();
699 if ( !token
.ToLong(&l
) )
703 token
= tokenizer
.GetNextToken();
704 if ( !token
.ToLong(&l
) )
708 token
= tokenizer
.GetNextToken();
709 if ( !token
.ToLong(&l
) )
711 lf
.lfOrientation
= l
;
713 token
= tokenizer
.GetNextToken();
714 if ( !token
.ToLong(&l
) )
718 token
= tokenizer
.GetNextToken();
719 if ( !token
.ToLong(&l
) )
721 lf
.lfItalic
= (BYTE
)l
;
723 token
= tokenizer
.GetNextToken();
724 if ( !token
.ToLong(&l
) )
726 lf
.lfUnderline
= (BYTE
)l
;
728 token
= tokenizer
.GetNextToken();
729 if ( !token
.ToLong(&l
) )
731 lf
.lfStrikeOut
= (BYTE
)l
;
733 token
= tokenizer
.GetNextToken();
734 if ( !token
.ToLong(&l
) )
736 lf
.lfCharSet
= (BYTE
)l
;
738 token
= tokenizer
.GetNextToken();
739 if ( !token
.ToLong(&l
) )
741 lf
.lfOutPrecision
= (BYTE
)l
;
743 token
= tokenizer
.GetNextToken();
744 if ( !token
.ToLong(&l
) )
746 lf
.lfClipPrecision
= (BYTE
)l
;
748 token
= tokenizer
.GetNextToken();
749 if ( !token
.ToLong(&l
) )
751 lf
.lfQuality
= (BYTE
)l
;
753 token
= tokenizer
.GetNextToken();
754 if ( !token
.ToLong(&l
) )
756 lf
.lfPitchAndFamily
= (BYTE
)l
;
758 if ( !tokenizer
.HasMoreTokens() )
761 // the face name may be empty
762 wxStrcpy(lf
.lfFaceName
, tokenizer
.GetNextToken());
767 wxString
wxNativeFontInfo::ToString() const
771 s
.Printf(wxS("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
772 0, // version, in case we want to change the format later
791 // ----------------------------------------------------------------------------
793 // ----------------------------------------------------------------------------
795 wxFont::wxFont(const wxString
& fontdesc
)
797 wxNativeFontInfo info
;
798 if ( info
.FromString(fontdesc
) )
802 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
806 m_refData
= new wxFontRefData(info
, hFont
);
808 return RealizeResource();
811 bool wxFont::DoCreate(int pointSize
,
812 const wxSize
& pixelSize
,
813 bool sizeUsingPixels
,
818 const wxString
& faceName
,
819 wxFontEncoding encoding
)
823 // wxDEFAULT is a valid value for the font size too so we must treat it
824 // specially here (otherwise the size would be 70 == wxDEFAULT value)
825 if ( pointSize
== wxDEFAULT
)
827 pointSize
= wxNORMAL_FONT
->GetPointSize();
830 m_refData
= new wxFontRefData(pointSize
, pixelSize
, sizeUsingPixels
,
831 family
, style
, weight
,
832 underlined
, faceName
, encoding
);
834 return RealizeResource();
841 // ----------------------------------------------------------------------------
842 // real implementation
843 // ----------------------------------------------------------------------------
845 wxGDIRefData
*wxFont::CreateGDIRefData() const
847 return new wxFontRefData();
850 wxGDIRefData
*wxFont::CloneGDIRefData(const wxGDIRefData
*data
) const
852 return new wxFontRefData(*static_cast<const wxFontRefData
*>(data
));
855 bool wxFont::RealizeResource()
857 // NOTE: the GetHFONT() call automatically triggers a reallocation of
858 // the HFONT if necessary (will do nothing if we already have the resource);
859 // it returns NULL only if there is a failure in wxFontRefData::Alloc()...
860 return GetHFONT() != NULL
;
863 bool wxFont::FreeResource(bool WXUNUSED(force
))
873 WXHANDLE
wxFont::GetResourceHandle() const
875 return (WXHANDLE
)GetHFONT();
878 WXHFONT
wxFont::GetHFONT() const
880 // NOTE: wxFontRefData::GetHFONT() will automatically call
881 // wxFontRefData::Alloc() if necessary
882 return M_FONTDATA
? M_FONTDATA
->GetHFONT() : 0;
885 bool wxFont::IsFree() const
887 return M_FONTDATA
&& !M_FONTDATA
->HasHFONT();
890 // ----------------------------------------------------------------------------
891 // change font attribute: we recreate font when doing it
892 // ----------------------------------------------------------------------------
894 void wxFont::SetPointSize(int pointSize
)
899 M_FONTDATA
->SetPointSize(pointSize
);
902 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
906 M_FONTDATA
->SetPixelSize(pixelSize
);
909 void wxFont::SetFamily(wxFontFamily family
)
913 M_FONTDATA
->SetFamily(family
);
916 void wxFont::SetStyle(wxFontStyle style
)
920 M_FONTDATA
->SetStyle(style
);
923 void wxFont::SetWeight(wxFontWeight weight
)
927 M_FONTDATA
->SetWeight(weight
);
930 bool wxFont::SetFaceName(const wxString
& faceName
)
934 if ( !M_FONTDATA
->SetFaceName(faceName
) )
937 // NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
938 // to retrieve a LOGFONT and then compare lf.lfFaceName
939 // with given facename is not reliable at all:
940 // Windows copies the facename given to ::CreateFontIndirect()
941 // without any validity check.
942 // Thus we use wxFontBase::SetFaceName to check if facename
944 return wxFontBase::SetFaceName(faceName
);
947 void wxFont::SetUnderlined(bool underlined
)
951 M_FONTDATA
->SetUnderlined(underlined
);
954 void wxFont::SetEncoding(wxFontEncoding encoding
)
958 M_FONTDATA
->SetEncoding(encoding
);
961 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
965 M_FONTDATA
->SetNativeFontInfo(info
);
968 // ----------------------------------------------------------------------------
970 // ----------------------------------------------------------------------------
972 int wxFont::GetPointSize() const
974 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
976 return M_FONTDATA
->GetPointSize();
979 wxSize
wxFont::GetPixelSize() const
981 wxCHECK_MSG( IsOk(), wxDefaultSize
, wxT("invalid font") );
983 return M_FONTDATA
->GetPixelSize();
986 bool wxFont::IsUsingSizeInPixels() const
988 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
990 return M_FONTDATA
->IsUsingSizeInPixels();
993 wxFontFamily
wxFont::GetFamily() const
995 wxCHECK_MSG( IsOk(), wxFONTFAMILY_MAX
, wxT("invalid font") );
997 return M_FONTDATA
->GetFamily();
1000 wxFontStyle
wxFont::GetStyle() const
1002 wxCHECK_MSG( IsOk(), wxFONTSTYLE_MAX
, wxT("invalid font") );
1004 return M_FONTDATA
->GetStyle();
1007 wxFontWeight
wxFont::GetWeight() const
1009 wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX
, wxT("invalid font") );
1011 return M_FONTDATA
->GetWeight();
1014 bool wxFont::GetUnderlined() const
1016 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
1018 return M_FONTDATA
->GetUnderlined();
1021 wxString
wxFont::GetFaceName() const
1023 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
1025 return M_FONTDATA
->GetFaceName();
1028 wxFontEncoding
wxFont::GetEncoding() const
1030 wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
1032 return M_FONTDATA
->GetEncoding();
1035 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
1037 return IsOk() ? &(M_FONTDATA
->GetNativeFontInfo()) : NULL
;
1040 wxString
wxFont::GetNativeFontInfoDesc() const
1042 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
1044 // be sure we have an HFONT associated...
1045 const_cast<wxFont
*>(this)->RealizeResource();
1046 return wxFontBase::GetNativeFontInfoDesc();
1049 wxString
wxFont::GetNativeFontInfoUserDesc() const
1051 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
1053 // be sure we have an HFONT associated...
1054 const_cast<wxFont
*>(this)->RealizeResource();
1055 return wxFontBase::GetNativeFontInfoUserDesc();
1058 bool wxFont::IsFixedWidth() const
1060 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
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
;