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
);
267 const wxNativeFontInfo
& GetNativeFontInfo() const
268 { return m_nativeFontInfo
; }
270 void SetNativeFontInfo(const wxNativeFontInfo
& nativeFontInfo
)
274 m_nativeFontInfo
= nativeFontInfo
;
278 // common part of all ctors
280 const wxSize
& pixelSize
,
281 bool sizeUsingPixels
,
286 const wxString
& faceName
,
287 wxFontEncoding encoding
);
289 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
291 // are we using m_nativeFontInfo.lf.lfHeight for point size or pixel size?
292 bool m_sizeUsingPixels
;
294 // Windows font handle, created on demand in GetHFONT()
298 wxNativeFontInfo m_nativeFontInfo
;
301 #define M_FONTDATA ((wxFontRefData*)m_refData)
303 // ============================================================================
305 // ============================================================================
307 // ----------------------------------------------------------------------------
309 // ----------------------------------------------------------------------------
311 void wxFontRefData::Init(int pointSize
,
312 const wxSize
& pixelSize
,
313 bool sizeUsingPixels
,
318 const wxString
& faceName
,
319 wxFontEncoding encoding
)
323 m_sizeUsingPixels
= sizeUsingPixels
;
324 if ( m_sizeUsingPixels
)
325 SetPixelSize(pixelSize
);
327 SetPointSize(pointSize
);
331 SetUnderlined(underlined
);
333 // set the family/facename
335 if ( !faceName
.empty() )
336 SetFaceName(faceName
);
338 // deal with encoding now (it may override the font family and facename
339 // so do it after setting them)
340 SetEncoding(encoding
);
343 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
345 // hFont may be zero, or it be passed in case we really want to
346 // use the exact font created in the underlying system
347 // (for example where we can't guarantee conversion from HFONT
348 // to LOGFONT back to HFONT)
349 m_hFont
= (HFONT
)hFont
;
350 m_nativeFontInfo
= info
;
352 // TODO: m_sizeUsingPixels?
355 wxFontRefData::~wxFontRefData()
360 bool wxFontRefData::Alloc()
362 m_hFont
= ::CreateFontIndirect(&m_nativeFontInfo
.lf
);
365 wxLogLastError(wxT("CreateFont"));
372 void wxFontRefData::Free()
376 if ( !::DeleteObject(m_hFont
) )
378 wxLogLastError(wxT("DeleteObject(font)"));
385 // ----------------------------------------------------------------------------
387 // ----------------------------------------------------------------------------
389 void wxNativeFontInfo::Init()
393 // we get better font quality if we use PROOF_QUALITY instead of
394 // DEFAULT_QUALITY but some fonts (e.g. "Terminal 6pt") are not available
395 // then so we allow to set a global option to choose between quality and
396 // wider font selection
398 lf
.lfQuality
= CLEARTYPE_QUALITY
;
400 lf
.lfQuality
= wxSystemOptions::GetOptionInt("msw.font.no-proof-quality")
406 int wxNativeFontInfo::GetPointSize() const
408 // FIXME: using the screen here results in incorrect font size calculation
410 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
412 // BC++ 2007 doesn't provide abs(long) overload, hence the cast
413 return (int) (((72.0*abs((int)lf
.lfHeight
)) / (double) ppInch
) + 0.5);
416 wxSize
wxNativeFontInfo::GetPixelSize() const
419 ret
.SetHeight(abs((int)lf
.lfHeight
));
420 ret
.SetWidth(lf
.lfWidth
);
424 wxFontStyle
wxNativeFontInfo::GetStyle() const
426 return lf
.lfItalic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
;
429 wxFontWeight
wxNativeFontInfo::GetWeight() const
431 if ( lf
.lfWeight
<= 300 )
432 return wxFONTWEIGHT_LIGHT
;
434 if ( lf
.lfWeight
>= 600 )
435 return wxFONTWEIGHT_BOLD
;
437 return wxFONTWEIGHT_NORMAL
;
440 bool wxNativeFontInfo::GetUnderlined() const
442 return lf
.lfUnderline
!= 0;
445 wxString
wxNativeFontInfo::GetFaceName() const
447 return lf
.lfFaceName
;
450 wxFontFamily
wxNativeFontInfo::GetFamily() const
454 // extract family from pitch-and-family
455 switch ( lf
.lfPitchAndFamily
& ~PITCH_MASK
)
458 family
= wxFONTFAMILY_UNKNOWN
;
462 family
= wxFONTFAMILY_ROMAN
;
466 family
= wxFONTFAMILY_SWISS
;
470 family
= wxFONTFAMILY_SCRIPT
;
474 family
= wxFONTFAMILY_MODERN
;
478 family
= wxFONTFAMILY_DECORATIVE
;
482 wxFAIL_MSG( "unknown LOGFONT::lfFamily value" );
483 family
= wxFONTFAMILY_UNKNOWN
;
484 // just to avoid a warning
490 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
492 return wxGetFontEncFromCharSet(lf
.lfCharSet
);
495 void wxNativeFontInfo::SetPointSize(int pointsize
)
497 // FIXME: using the screen here results in incorrect font size calculation
499 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
501 lf
.lfHeight
= -(int)((pointsize
*((double)ppInch
)/72.0) + 0.5);
504 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
506 // NOTE: although the MSW port allows for negative pixel size heights,
507 // other ports don't and since it's a very useful feature assert
508 // here if we get a negative height:
509 wxCHECK_RET( pixelSize
.GetWidth() >= 0 && pixelSize
.GetHeight() > 0,
510 "Negative values for the pixel size or zero pixel height are not allowed" );
512 lf
.lfHeight
= pixelSize
.GetHeight();
513 lf
.lfWidth
= pixelSize
.GetWidth();
516 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
521 wxFAIL_MSG( "unknown font style" );
524 case wxFONTSTYLE_NORMAL
:
528 case wxFONTSTYLE_ITALIC
:
529 case wxFONTSTYLE_SLANT
:
535 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
540 wxFAIL_MSG( "unknown font weight" );
543 case wxFONTWEIGHT_NORMAL
:
544 lf
.lfWeight
= FW_NORMAL
;
547 case wxFONTWEIGHT_LIGHT
:
548 lf
.lfWeight
= FW_LIGHT
;
551 case wxFONTWEIGHT_BOLD
:
552 lf
.lfWeight
= FW_BOLD
;
557 void wxNativeFontInfo::SetUnderlined(bool underlined
)
559 lf
.lfUnderline
= underlined
;
562 bool wxNativeFontInfo::SetFaceName(const wxString
& facename
)
564 wxStrlcpy(lf
.lfFaceName
, facename
.c_str(), WXSIZEOF(lf
.lfFaceName
));
568 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
571 wxArrayString facename
;
573 // the list of fonts associated with a family was partially
574 // taken from http://www.codestyle.org/css/font-family
578 case wxFONTFAMILY_SCRIPT
:
579 ff_family
= FF_SCRIPT
;
580 facename
.Add(wxS("Script"));
581 facename
.Add(wxS("Brush Script MT"));
582 facename
.Add(wxS("Comic Sans MS"));
583 facename
.Add(wxS("Lucida Handwriting"));
586 case wxFONTFAMILY_DECORATIVE
:
587 ff_family
= FF_DECORATIVE
;
588 facename
.Add(wxS("Old English Text MT"));
589 facename
.Add(wxS("Comic Sans MS"));
590 facename
.Add(wxS("Lucida Handwriting"));
593 case wxFONTFAMILY_ROMAN
:
594 ff_family
= FF_ROMAN
;
595 facename
.Add(wxS("Times New Roman"));
596 facename
.Add(wxS("Georgia"));
597 facename
.Add(wxS("Garamond"));
598 facename
.Add(wxS("Bookman Old Style"));
599 facename
.Add(wxS("Book Antiqua"));
602 case wxFONTFAMILY_TELETYPE
:
603 case wxFONTFAMILY_MODERN
:
604 ff_family
= FF_MODERN
;
605 facename
.Add(wxS("Courier New"));
606 facename
.Add(wxS("Lucida Console"));
607 facename
.Add(wxS("Andale Mono"));
608 facename
.Add(wxS("OCR A Extended"));
609 facename
.Add(wxS("Terminal"));
612 case wxFONTFAMILY_SWISS
:
613 ff_family
= FF_SWISS
;
614 facename
.Add(wxS("Arial"));
615 facename
.Add(wxS("Century Gothic"));
616 facename
.Add(wxS("Lucida Sans Unicode"));
617 facename
.Add(wxS("Tahoma"));
618 facename
.Add(wxS("Trebuchet MS"));
619 facename
.Add(wxS("Verdana"));
622 case wxFONTFAMILY_DEFAULT
:
625 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
626 // is returned as default GUI font for compatibility
628 ff_family
= FF_SWISS
;
629 if(wxGetOsVersion(&verMaj
) == wxOS_WINDOWS_NT
&& verMaj
>= 5)
630 facename
.Add(wxS("MS Shell Dlg 2"));
632 facename
.Add(wxS("MS Shell Dlg"));
635 // "MS Shell Dlg is a mapping mechanism that enables
636 // U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
637 // support locales that have characters that are not contained in code
638 // page 1252. It is not a font but a face name for a nonexistent font."
642 lf
.lfPitchAndFamily
= (BYTE
)(DEFAULT_PITCH
) | ff_family
;
644 // reset the facename so that CreateFontIndirect() will automatically choose a
645 // face name based only on the font family.
646 lf
.lfFaceName
[0] = '\0';
649 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
651 wxNativeEncodingInfo info
;
652 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
655 if ( wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
657 if ( !info
.facename
.empty() )
659 // if we have this encoding only in some particular facename, use
660 // the facename - it is better to show the correct characters in a
661 // wrong facename than unreadable text in a correct one
662 SetFaceName(info
.facename
);
666 #endif // wxUSE_FONTMAP
668 // unsupported encoding, replace with the default
669 info
.charset
= DEFAULT_CHARSET
;
673 lf
.lfCharSet
= (BYTE
)info
.charset
;
676 bool wxNativeFontInfo::FromString(const wxString
& s
)
680 wxStringTokenizer
tokenizer(s
, wxS(";"));
683 wxString token
= tokenizer
.GetNextToken();
684 if ( token
!= wxS('0') )
687 token
= tokenizer
.GetNextToken();
688 if ( !token
.ToLong(&l
) )
692 token
= tokenizer
.GetNextToken();
693 if ( !token
.ToLong(&l
) )
697 token
= tokenizer
.GetNextToken();
698 if ( !token
.ToLong(&l
) )
702 token
= tokenizer
.GetNextToken();
703 if ( !token
.ToLong(&l
) )
705 lf
.lfOrientation
= l
;
707 token
= tokenizer
.GetNextToken();
708 if ( !token
.ToLong(&l
) )
712 token
= tokenizer
.GetNextToken();
713 if ( !token
.ToLong(&l
) )
715 lf
.lfItalic
= (BYTE
)l
;
717 token
= tokenizer
.GetNextToken();
718 if ( !token
.ToLong(&l
) )
720 lf
.lfUnderline
= (BYTE
)l
;
722 token
= tokenizer
.GetNextToken();
723 if ( !token
.ToLong(&l
) )
725 lf
.lfStrikeOut
= (BYTE
)l
;
727 token
= tokenizer
.GetNextToken();
728 if ( !token
.ToLong(&l
) )
730 lf
.lfCharSet
= (BYTE
)l
;
732 token
= tokenizer
.GetNextToken();
733 if ( !token
.ToLong(&l
) )
735 lf
.lfOutPrecision
= (BYTE
)l
;
737 token
= tokenizer
.GetNextToken();
738 if ( !token
.ToLong(&l
) )
740 lf
.lfClipPrecision
= (BYTE
)l
;
742 token
= tokenizer
.GetNextToken();
743 if ( !token
.ToLong(&l
) )
745 lf
.lfQuality
= (BYTE
)l
;
747 token
= tokenizer
.GetNextToken();
748 if ( !token
.ToLong(&l
) )
750 lf
.lfPitchAndFamily
= (BYTE
)l
;
752 token
= tokenizer
.GetNextToken();
755 wxStrcpy(lf
.lfFaceName
, token
.c_str());
760 wxString
wxNativeFontInfo::ToString() const
764 s
.Printf(wxS("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
765 0, // version, in case we want to change the format later
779 (const wxChar
*)lf
.lfFaceName
);
784 // ----------------------------------------------------------------------------
786 // ----------------------------------------------------------------------------
788 wxFont::wxFont(const wxString
& fontdesc
)
790 wxNativeFontInfo info
;
791 if ( info
.FromString(fontdesc
) )
795 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
799 m_refData
= new wxFontRefData(info
, hFont
);
801 return RealizeResource();
804 bool wxFont::DoCreate(int pointSize
,
805 const wxSize
& pixelSize
,
806 bool sizeUsingPixels
,
811 const wxString
& faceName
,
812 wxFontEncoding encoding
)
816 // wxDEFAULT is a valid value for the font size too so we must treat it
817 // specially here (otherwise the size would be 70 == wxDEFAULT value)
818 if ( pointSize
== wxDEFAULT
)
820 pointSize
= wxNORMAL_FONT
->GetPointSize();
823 m_refData
= new wxFontRefData(pointSize
, pixelSize
, sizeUsingPixels
,
824 family
, style
, weight
,
825 underlined
, faceName
, encoding
);
827 return RealizeResource();
834 // ----------------------------------------------------------------------------
835 // real implementation
836 // ----------------------------------------------------------------------------
838 wxGDIRefData
*wxFont::CreateGDIRefData() const
840 return new wxFontRefData();
843 wxGDIRefData
*wxFont::CloneGDIRefData(const wxGDIRefData
*data
) const
845 return new wxFontRefData(*static_cast<const wxFontRefData
*>(data
));
848 bool wxFont::RealizeResource()
850 // NOTE: the GetHFONT() call automatically triggers a reallocation of
851 // the HFONT if necessary (will do nothing if we already have the resource);
852 // it returns NULL only if there is a failure in wxFontRefData::Alloc()...
853 return GetHFONT() != NULL
;
856 bool wxFont::FreeResource(bool WXUNUSED(force
))
866 WXHANDLE
wxFont::GetResourceHandle() const
868 return (WXHANDLE
)GetHFONT();
871 WXHFONT
wxFont::GetHFONT() const
873 // NOTE: wxFontRefData::GetHFONT() will automatically call
874 // wxFontRefData::Alloc() if necessary
875 return M_FONTDATA
? M_FONTDATA
->GetHFONT() : 0;
878 bool wxFont::IsFree() const
880 return M_FONTDATA
&& !M_FONTDATA
->HasHFONT();
883 // ----------------------------------------------------------------------------
884 // change font attribute: we recreate font when doing it
885 // ----------------------------------------------------------------------------
887 void wxFont::SetPointSize(int pointSize
)
892 M_FONTDATA
->SetPointSize(pointSize
);
895 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
899 M_FONTDATA
->SetPixelSize(pixelSize
);
902 void wxFont::SetFamily(wxFontFamily family
)
906 M_FONTDATA
->SetFamily(family
);
909 void wxFont::SetStyle(wxFontStyle style
)
913 M_FONTDATA
->SetStyle(style
);
916 void wxFont::SetWeight(wxFontWeight weight
)
920 M_FONTDATA
->SetWeight(weight
);
923 bool wxFont::SetFaceName(const wxString
& faceName
)
927 if ( !M_FONTDATA
->SetFaceName(faceName
) )
930 // NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
931 // to retrieve a LOGFONT and then compare lf.lfFaceName
932 // with given facename is not reliable at all:
933 // Windows copies the facename given to ::CreateFontIndirect()
934 // without any validity check.
935 // Thus we use wxFontBase::SetFaceName to check if facename
937 return wxFontBase::SetFaceName(faceName
);
940 void wxFont::SetUnderlined(bool underlined
)
944 M_FONTDATA
->SetUnderlined(underlined
);
947 void wxFont::SetEncoding(wxFontEncoding encoding
)
951 M_FONTDATA
->SetEncoding(encoding
);
954 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
958 M_FONTDATA
->SetNativeFontInfo(info
);
961 // ----------------------------------------------------------------------------
963 // ----------------------------------------------------------------------------
965 int wxFont::GetPointSize() const
967 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
969 return M_FONTDATA
->GetPointSize();
972 wxSize
wxFont::GetPixelSize() const
974 wxCHECK_MSG( IsOk(), wxDefaultSize
, wxT("invalid font") );
976 return M_FONTDATA
->GetPixelSize();
979 bool wxFont::IsUsingSizeInPixels() const
981 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
983 return M_FONTDATA
->IsUsingSizeInPixels();
986 wxFontFamily
wxFont::GetFamily() const
988 wxCHECK_MSG( IsOk(), wxFONTFAMILY_MAX
, wxT("invalid font") );
990 return M_FONTDATA
->GetFamily();
993 wxFontStyle
wxFont::GetStyle() const
995 wxCHECK_MSG( IsOk(), wxFONTSTYLE_MAX
, wxT("invalid font") );
997 return M_FONTDATA
->GetStyle();
1000 wxFontWeight
wxFont::GetWeight() const
1002 wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX
, wxT("invalid font") );
1004 return M_FONTDATA
->GetWeight();
1007 bool wxFont::GetUnderlined() const
1009 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
1011 return M_FONTDATA
->GetUnderlined();
1014 wxString
wxFont::GetFaceName() const
1016 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
1018 return M_FONTDATA
->GetFaceName();
1021 wxFontEncoding
wxFont::GetEncoding() const
1023 wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
1025 return M_FONTDATA
->GetEncoding();
1028 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
1030 return IsOk() ? &(M_FONTDATA
->GetNativeFontInfo()) : NULL
;
1033 wxString
wxFont::GetNativeFontInfoDesc() const
1035 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
1037 // be sure we have an HFONT associated...
1038 const_cast<wxFont
*>(this)->RealizeResource();
1039 return wxFontBase::GetNativeFontInfoDesc();
1042 wxString
wxFont::GetNativeFontInfoUserDesc() const
1044 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
1046 // be sure we have an HFONT associated...
1047 const_cast<wxFont
*>(this)->RealizeResource();
1048 return wxFontBase::GetNativeFontInfoUserDesc();
1051 bool wxFont::IsFixedWidth() const
1053 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
1055 // the two low-order bits specify the pitch of the font, the rest is
1058 (BYTE
)(M_FONTDATA
->GetNativeFontInfo().lf
.lfPitchAndFamily
& PITCH_MASK
);
1060 return pitch
== FIXED_PITCH
;