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/msw/private.h"
37 #include "wx/encinfo.h"
38 #include "wx/fontutil.h"
39 #include "wx/fontmap.h"
42 #include "wx/sysopt.h"
45 #include "wx/scopeguard.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 wxString facename
= m_nativeFontInfo
.GetFaceName();
186 if ( facename
.empty() )
188 facename
= GetMSWFaceName();
189 if ( !facename
.empty() )
191 // cache the face name, it shouldn't change unless the family
192 // does and wxNativeFontInfo::SetFamily() resets the face name
193 const_cast<wxFontRefData
*>(this)->SetFaceName(facename
);
200 wxFontEncoding
GetEncoding() const
202 return m_nativeFontInfo
.GetEncoding();
205 WXHFONT
GetHFONT() const
209 return (WXHFONT
)m_hFont
;
212 bool HasHFONT() const
217 // ... and setters: notice that all of them invalidate the currently
218 // allocated HFONT, if any, so that the next call to GetHFONT() recreates a
220 void SetPointSize(int pointSize
)
224 m_nativeFontInfo
.SetPointSize(pointSize
);
225 m_sizeUsingPixels
= false;
228 void SetPixelSize(const wxSize
& pixelSize
)
230 wxCHECK_RET( pixelSize
.GetWidth() >= 0, "negative font width" );
231 wxCHECK_RET( pixelSize
.GetHeight() != 0, "zero font height" );
235 m_nativeFontInfo
.SetPixelSize(pixelSize
);
236 m_sizeUsingPixels
= true;
239 void SetFamily(wxFontFamily family
)
243 m_nativeFontInfo
.SetFamily(family
);
246 void SetStyle(wxFontStyle style
)
250 m_nativeFontInfo
.SetStyle(style
);
253 void SetWeight(wxFontWeight weight
)
257 m_nativeFontInfo
.SetWeight(weight
);
260 bool SetFaceName(const wxString
& faceName
)
264 return m_nativeFontInfo
.SetFaceName(faceName
);
267 void SetUnderlined(bool underlined
)
271 m_nativeFontInfo
.SetUnderlined(underlined
);
274 void SetEncoding(wxFontEncoding encoding
)
278 m_nativeFontInfo
.SetEncoding(encoding
);
281 const wxNativeFontInfo
& GetNativeFontInfo() const
283 // we need to create the font now to get the corresponding LOGFONT if
284 // it hadn't been done yet
287 // ensure that we have a valid face name in our font information:
288 // GetFaceName() will try to retrieve it from our HFONT and save it if
292 return m_nativeFontInfo
;
295 void SetNativeFontInfo(const wxNativeFontInfo
& nativeFontInfo
)
299 m_nativeFontInfo
= nativeFontInfo
;
303 // common part of all ctors
305 const wxSize
& pixelSize
,
306 bool sizeUsingPixels
,
311 const wxString
& faceName
,
312 wxFontEncoding encoding
);
314 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
316 void AllocIfNeeded() const
319 const_cast<wxFontRefData
*>(this)->Alloc();
322 // retrieve the face name really being used by the font: this is used to
323 // get the face name selected by the system when we don't specify it (but
324 // use just the family for example)
325 wxString
GetMSWFaceName() const
328 SelectInHDC
selectFont(hdc
, m_hFont
);
330 UINT otmSize
= GetOutlineTextMetrics(hdc
, 0, NULL
);
333 wxLogLastError("GetOutlineTextMetrics(NULL)");
337 OUTLINETEXTMETRIC
* const
338 otm
= static_cast<OUTLINETEXTMETRIC
*>(malloc(otmSize
));
339 wxON_BLOCK_EXIT1( free
, otm
);
341 otm
->otmSize
= otmSize
;
342 if ( !GetOutlineTextMetrics(hdc
, otmSize
, otm
) )
344 wxLogLastError("GetOutlineTextMetrics()");
348 // in spite of its type, the otmpFamilyName field of OUTLINETEXTMETRIC
349 // gives an offset in _bytes_ of the face (not family!) name from the
350 // struct start while the name itself is an array of TCHARs
352 // FWIW otmpFaceName contains the same thing as otmpFamilyName followed
353 // by a possible " Italic" or " Bold" or something else suffix
354 return reinterpret_cast<wxChar
*>(otm
) +
355 wxPtrToUInt(otm
->otmpFamilyName
)/sizeof(wxChar
);
358 // are we using m_nativeFontInfo.lf.lfHeight for point size or pixel size?
359 bool m_sizeUsingPixels
;
361 // Windows font handle, created on demand in GetHFONT()
365 wxNativeFontInfo m_nativeFontInfo
;
368 #define M_FONTDATA ((wxFontRefData*)m_refData)
370 // ============================================================================
372 // ============================================================================
374 // ----------------------------------------------------------------------------
376 // ----------------------------------------------------------------------------
378 void wxFontRefData::Init(int pointSize
,
379 const wxSize
& pixelSize
,
380 bool sizeUsingPixels
,
385 const wxString
& faceName
,
386 wxFontEncoding encoding
)
390 m_sizeUsingPixels
= sizeUsingPixels
;
391 if ( m_sizeUsingPixels
)
392 SetPixelSize(pixelSize
);
394 SetPointSize(pointSize
);
398 SetUnderlined(underlined
);
400 // set the family/facename
402 if ( !faceName
.empty() )
403 SetFaceName(faceName
);
405 // deal with encoding now (it may override the font family and facename
406 // so do it after setting them)
407 SetEncoding(encoding
);
410 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
412 // hFont may be zero, or it be passed in case we really want to
413 // use the exact font created in the underlying system
414 // (for example where we can't guarantee conversion from HFONT
415 // to LOGFONT back to HFONT)
416 m_hFont
= (HFONT
)hFont
;
417 m_nativeFontInfo
= info
;
419 // TODO: m_sizeUsingPixels?
422 wxFontRefData::~wxFontRefData()
427 bool wxFontRefData::Alloc()
429 m_hFont
= ::CreateFontIndirect(&m_nativeFontInfo
.lf
);
432 wxLogLastError(wxT("CreateFont"));
439 void wxFontRefData::Free()
443 if ( !::DeleteObject(m_hFont
) )
445 wxLogLastError(wxT("DeleteObject(font)"));
452 // ----------------------------------------------------------------------------
454 // ----------------------------------------------------------------------------
456 void wxNativeFontInfo::Init()
460 // we get better font quality if we use PROOF_QUALITY instead of
461 // DEFAULT_QUALITY but some fonts (e.g. "Terminal 6pt") are not available
462 // then so we allow to set a global option to choose between quality and
463 // wider font selection
465 lf
.lfQuality
= CLEARTYPE_QUALITY
;
467 lf
.lfQuality
= wxSystemOptions::GetOptionInt("msw.font.no-proof-quality")
473 int wxNativeFontInfo::GetPointSize() const
475 // FIXME: using the screen here results in incorrect font size calculation
477 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
479 // BC++ 2007 doesn't provide abs(long) overload, hence the cast
480 return (int) (((72.0*abs((int)lf
.lfHeight
)) / (double) ppInch
) + 0.5);
483 wxSize
wxNativeFontInfo::GetPixelSize() const
486 ret
.SetHeight(abs((int)lf
.lfHeight
));
487 ret
.SetWidth(lf
.lfWidth
);
491 wxFontStyle
wxNativeFontInfo::GetStyle() const
493 return lf
.lfItalic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
;
496 wxFontWeight
wxNativeFontInfo::GetWeight() const
498 if ( lf
.lfWeight
<= 300 )
499 return wxFONTWEIGHT_LIGHT
;
501 if ( lf
.lfWeight
>= 600 )
502 return wxFONTWEIGHT_BOLD
;
504 return wxFONTWEIGHT_NORMAL
;
507 bool wxNativeFontInfo::GetUnderlined() const
509 return lf
.lfUnderline
!= 0;
512 wxString
wxNativeFontInfo::GetFaceName() const
514 return lf
.lfFaceName
;
517 wxFontFamily
wxNativeFontInfo::GetFamily() const
521 // extract family from pitch-and-family
522 switch ( lf
.lfPitchAndFamily
& ~PITCH_MASK
)
525 family
= wxFONTFAMILY_UNKNOWN
;
529 family
= wxFONTFAMILY_ROMAN
;
533 family
= wxFONTFAMILY_SWISS
;
537 family
= wxFONTFAMILY_SCRIPT
;
541 family
= wxFONTFAMILY_MODERN
;
545 family
= wxFONTFAMILY_DECORATIVE
;
549 wxFAIL_MSG( "unknown LOGFONT::lfFamily value" );
550 family
= wxFONTFAMILY_UNKNOWN
;
551 // just to avoid a warning
557 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
559 return wxGetFontEncFromCharSet(lf
.lfCharSet
);
562 void wxNativeFontInfo::SetPointSize(int pointsize
)
564 // FIXME: using the screen here results in incorrect font size calculation
566 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
568 lf
.lfHeight
= -(int)((pointsize
*((double)ppInch
)/72.0) + 0.5);
571 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
573 // MSW accepts both positive and negative heights here but they mean
574 // different things: positive specifies the cell height while negative
575 // specifies the character height. We used to just pass the value to MSW
576 // unchanged but changed the behaviour for positive values in 2.9.1 to
577 // match other ports and, more importantly, the expected behaviour. So now
578 // passing the negative height doesn't make sense at all any more but we
579 // still accept it for compatibility with the existing code which worked
580 // around the wrong interpretation of the height argument in older wxMSW
581 // versions by passing a negative value explicitly itself.
582 lf
.lfHeight
= -abs(pixelSize
.GetHeight());
583 lf
.lfWidth
= pixelSize
.GetWidth();
586 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
591 wxFAIL_MSG( "unknown font style" );
594 case wxFONTSTYLE_NORMAL
:
598 case wxFONTSTYLE_ITALIC
:
599 case wxFONTSTYLE_SLANT
:
605 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
610 wxFAIL_MSG( "unknown font weight" );
613 case wxFONTWEIGHT_NORMAL
:
614 lf
.lfWeight
= FW_NORMAL
;
617 case wxFONTWEIGHT_LIGHT
:
618 lf
.lfWeight
= FW_LIGHT
;
621 case wxFONTWEIGHT_BOLD
:
622 lf
.lfWeight
= FW_BOLD
;
627 void wxNativeFontInfo::SetUnderlined(bool underlined
)
629 lf
.lfUnderline
= underlined
;
632 bool wxNativeFontInfo::SetFaceName(const wxString
& facename
)
634 wxStrlcpy(lf
.lfFaceName
, facename
.c_str(), WXSIZEOF(lf
.lfFaceName
));
638 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
640 BYTE ff_family
= FF_DONTCARE
;
644 case wxFONTFAMILY_SCRIPT
:
645 ff_family
= FF_SCRIPT
;
648 case wxFONTFAMILY_DECORATIVE
:
649 ff_family
= FF_DECORATIVE
;
652 case wxFONTFAMILY_ROMAN
:
653 ff_family
= FF_ROMAN
;
656 case wxFONTFAMILY_TELETYPE
:
657 case wxFONTFAMILY_MODERN
:
658 ff_family
= FF_MODERN
;
661 case wxFONTFAMILY_SWISS
:
662 case wxFONTFAMILY_DEFAULT
:
663 ff_family
= FF_SWISS
;
666 case wxFONTFAMILY_UNKNOWN
:
667 wxFAIL_MSG( "invalid font family" );
671 wxCHECK_RET( ff_family
!= FF_DONTCARE
, "unknown wxFontFamily" );
673 lf
.lfPitchAndFamily
= (BYTE
)(DEFAULT_PITCH
) | ff_family
;
675 // reset the facename so that CreateFontIndirect() will automatically choose a
676 // face name based only on the font family.
677 lf
.lfFaceName
[0] = '\0';
680 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
682 wxNativeEncodingInfo info
;
683 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
686 if ( wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
688 if ( !info
.facename
.empty() )
690 // if we have this encoding only in some particular facename, use
691 // the facename - it is better to show the correct characters in a
692 // wrong facename than unreadable text in a correct one
693 SetFaceName(info
.facename
);
697 #endif // wxUSE_FONTMAP
699 // unsupported encoding, replace with the default
700 info
.charset
= DEFAULT_CHARSET
;
704 lf
.lfCharSet
= (BYTE
)info
.charset
;
707 bool wxNativeFontInfo::FromString(const wxString
& s
)
711 wxStringTokenizer
tokenizer(s
, wxS(";"), wxTOKEN_RET_EMPTY_ALL
);
714 wxString token
= tokenizer
.GetNextToken();
715 if ( token
!= wxS('0') )
718 token
= tokenizer
.GetNextToken();
719 if ( !token
.ToLong(&l
) )
723 token
= tokenizer
.GetNextToken();
724 if ( !token
.ToLong(&l
) )
728 token
= tokenizer
.GetNextToken();
729 if ( !token
.ToLong(&l
) )
733 token
= tokenizer
.GetNextToken();
734 if ( !token
.ToLong(&l
) )
736 lf
.lfOrientation
= l
;
738 token
= tokenizer
.GetNextToken();
739 if ( !token
.ToLong(&l
) )
743 token
= tokenizer
.GetNextToken();
744 if ( !token
.ToLong(&l
) )
746 lf
.lfItalic
= (BYTE
)l
;
748 token
= tokenizer
.GetNextToken();
749 if ( !token
.ToLong(&l
) )
751 lf
.lfUnderline
= (BYTE
)l
;
753 token
= tokenizer
.GetNextToken();
754 if ( !token
.ToLong(&l
) )
756 lf
.lfStrikeOut
= (BYTE
)l
;
758 token
= tokenizer
.GetNextToken();
759 if ( !token
.ToLong(&l
) )
761 lf
.lfCharSet
= (BYTE
)l
;
763 token
= tokenizer
.GetNextToken();
764 if ( !token
.ToLong(&l
) )
766 lf
.lfOutPrecision
= (BYTE
)l
;
768 token
= tokenizer
.GetNextToken();
769 if ( !token
.ToLong(&l
) )
771 lf
.lfClipPrecision
= (BYTE
)l
;
773 token
= tokenizer
.GetNextToken();
774 if ( !token
.ToLong(&l
) )
776 lf
.lfQuality
= (BYTE
)l
;
778 token
= tokenizer
.GetNextToken();
779 if ( !token
.ToLong(&l
) )
781 lf
.lfPitchAndFamily
= (BYTE
)l
;
783 if ( !tokenizer
.HasMoreTokens() )
786 // the face name may be empty
787 SetFaceName(tokenizer
.GetNextToken());
792 wxString
wxNativeFontInfo::ToString() const
796 s
.Printf(wxS("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
797 0, // version, in case we want to change the format later
816 // ----------------------------------------------------------------------------
818 // ----------------------------------------------------------------------------
820 wxFont::wxFont(const wxString
& fontdesc
)
822 wxNativeFontInfo info
;
823 if ( info
.FromString(fontdesc
) )
827 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
831 m_refData
= new wxFontRefData(info
, hFont
);
833 return RealizeResource();
836 bool wxFont::DoCreate(int pointSize
,
837 const wxSize
& pixelSize
,
838 bool sizeUsingPixels
,
843 const wxString
& faceName
,
844 wxFontEncoding encoding
)
848 // wxDEFAULT is a valid value for the font size too so we must treat it
849 // specially here (otherwise the size would be 70 == wxDEFAULT value)
850 if ( pointSize
== wxDEFAULT
)
852 pointSize
= wxNORMAL_FONT
->GetPointSize();
855 m_refData
= new wxFontRefData(pointSize
, pixelSize
, sizeUsingPixels
,
856 family
, style
, weight
,
857 underlined
, faceName
, encoding
);
859 return RealizeResource();
866 // ----------------------------------------------------------------------------
867 // real implementation
868 // ----------------------------------------------------------------------------
870 wxGDIRefData
*wxFont::CreateGDIRefData() const
872 return new wxFontRefData();
875 wxGDIRefData
*wxFont::CloneGDIRefData(const wxGDIRefData
*data
) const
877 return new wxFontRefData(*static_cast<const wxFontRefData
*>(data
));
880 bool wxFont::RealizeResource()
882 // NOTE: the GetHFONT() call automatically triggers a reallocation of
883 // the HFONT if necessary (will do nothing if we already have the resource);
884 // it returns NULL only if there is a failure in wxFontRefData::Alloc()...
885 return GetHFONT() != NULL
;
888 bool wxFont::FreeResource(bool WXUNUSED(force
))
898 WXHANDLE
wxFont::GetResourceHandle() const
900 return (WXHANDLE
)GetHFONT();
903 WXHFONT
wxFont::GetHFONT() const
905 // NOTE: wxFontRefData::GetHFONT() will automatically call
906 // wxFontRefData::Alloc() if necessary
907 return M_FONTDATA
? M_FONTDATA
->GetHFONT() : 0;
910 bool wxFont::IsFree() const
912 return M_FONTDATA
&& !M_FONTDATA
->HasHFONT();
915 // ----------------------------------------------------------------------------
916 // change font attribute: we recreate font when doing it
917 // ----------------------------------------------------------------------------
919 void wxFont::SetPointSize(int pointSize
)
924 M_FONTDATA
->SetPointSize(pointSize
);
927 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
931 M_FONTDATA
->SetPixelSize(pixelSize
);
934 void wxFont::SetFamily(wxFontFamily family
)
938 M_FONTDATA
->SetFamily(family
);
941 void wxFont::SetStyle(wxFontStyle style
)
945 M_FONTDATA
->SetStyle(style
);
948 void wxFont::SetWeight(wxFontWeight weight
)
952 M_FONTDATA
->SetWeight(weight
);
955 bool wxFont::SetFaceName(const wxString
& faceName
)
959 if ( !M_FONTDATA
->SetFaceName(faceName
) )
962 // NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
963 // to retrieve a LOGFONT and then compare lf.lfFaceName
964 // with given facename is not reliable at all:
965 // Windows copies the facename given to ::CreateFontIndirect()
966 // without any validity check.
967 // Thus we use wxFontBase::SetFaceName to check if facename
969 return wxFontBase::SetFaceName(faceName
);
972 void wxFont::SetUnderlined(bool underlined
)
976 M_FONTDATA
->SetUnderlined(underlined
);
979 void wxFont::SetEncoding(wxFontEncoding encoding
)
983 M_FONTDATA
->SetEncoding(encoding
);
986 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
990 M_FONTDATA
->SetNativeFontInfo(info
);
993 // ----------------------------------------------------------------------------
995 // ----------------------------------------------------------------------------
997 int wxFont::GetPointSize() const
999 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
1001 return M_FONTDATA
->GetPointSize();
1004 wxSize
wxFont::GetPixelSize() const
1006 wxCHECK_MSG( IsOk(), wxDefaultSize
, wxT("invalid font") );
1008 return M_FONTDATA
->GetPixelSize();
1011 bool wxFont::IsUsingSizeInPixels() const
1013 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
1015 return M_FONTDATA
->IsUsingSizeInPixels();
1018 wxFontFamily
wxFont::DoGetFamily() const
1020 return M_FONTDATA
->GetFamily();
1023 wxFontStyle
wxFont::GetStyle() const
1025 wxCHECK_MSG( IsOk(), wxFONTSTYLE_MAX
, wxT("invalid font") );
1027 return M_FONTDATA
->GetStyle();
1030 wxFontWeight
wxFont::GetWeight() const
1032 wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX
, wxT("invalid font") );
1034 return M_FONTDATA
->GetWeight();
1037 bool wxFont::GetUnderlined() const
1039 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
1041 return M_FONTDATA
->GetUnderlined();
1044 wxString
wxFont::GetFaceName() const
1046 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
1048 return M_FONTDATA
->GetFaceName();
1051 wxFontEncoding
wxFont::GetEncoding() const
1053 wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
1055 return M_FONTDATA
->GetEncoding();
1058 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
1060 return IsOk() ? &(M_FONTDATA
->GetNativeFontInfo()) : NULL
;
1063 bool wxFont::IsFixedWidth() const
1065 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
1067 // LOGFONT doesn't contain the correct pitch information so we need to call
1068 // GetTextMetrics() to get it
1070 SelectInHDC
selectFont(hdc
, M_FONTDATA
->GetHFONT());
1073 if ( !::GetTextMetrics(hdc
, &tm
) )
1075 wxLogLastError(wxT("GetTextMetrics"));
1079 // Quoting MSDN description of TMPF_FIXED_PITCH: "Note very carefully that
1080 // those meanings are the opposite of what the constant name implies."
1081 return !(tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
);