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/scopeguard.h"
47 #include "wx/tokenzr.h"
49 #if wxUSE_EXTENDED_RTTI
51 wxBEGIN_ENUM( wxFontFamily
)
52 wxENUM_MEMBER( wxDEFAULT
)
53 wxENUM_MEMBER( wxDECORATIVE
)
54 wxENUM_MEMBER( wxROMAN
)
55 wxENUM_MEMBER( wxSCRIPT
)
56 wxENUM_MEMBER( wxSWISS
)
57 wxENUM_MEMBER( wxMODERN
)
58 wxENUM_MEMBER( wxTELETYPE
)
59 wxEND_ENUM( wxFontFamily
)
61 wxBEGIN_ENUM( wxFontStyle
)
62 wxENUM_MEMBER( wxNORMAL
)
63 wxENUM_MEMBER( wxITALIC
)
64 wxENUM_MEMBER( wxSLANT
)
65 wxEND_ENUM( wxFontStyle
)
67 wxBEGIN_ENUM( wxFontWeight
)
68 wxENUM_MEMBER( wxNORMAL
)
69 wxENUM_MEMBER( wxLIGHT
)
70 wxENUM_MEMBER( wxBOLD
)
71 wxEND_ENUM( wxFontWeight
)
73 IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont
, wxGDIObject
,"wx/font.h")
75 wxBEGIN_PROPERTIES_TABLE(wxFont
)
76 wxPROPERTY( Size
,int, SetPointSize
, GetPointSize
, 12 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
77 wxPROPERTY( Family
, int , SetFamily
, GetFamily
, (int)wxDEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontFamily
78 wxPROPERTY( Style
, int , SetStyle
, GetStyle
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontStyle
79 wxPROPERTY( Weight
, int , SetWeight
, GetWeight
, (int)wxNORMAL
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontWeight
80 wxPROPERTY( Underlined
, bool , SetUnderlined
, GetUnderlined
, false , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
81 wxPROPERTY( Face
, wxString
, SetFaceName
, GetFaceName
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
82 wxPROPERTY( Encoding
, wxFontEncoding
, SetEncoding
, GetEncoding
, wxFONTENCODING_DEFAULT
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
83 wxEND_PROPERTIES_TABLE()
85 wxCONSTRUCTOR_6( wxFont
, int , Size
, int , Family
, int , Style
, int , Weight
, bool , Underlined
, wxString
, Face
)
87 wxBEGIN_HANDLERS_TABLE(wxFont
)
88 wxEND_HANDLERS_TABLE()
91 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 // the mask used to extract the pitch from LOGFONT::lfPitchAndFamily field
100 static const int PITCH_MASK
= FIXED_PITCH
| VARIABLE_PITCH
;
102 // ----------------------------------------------------------------------------
103 // wxFontRefData - the internal description of the font
104 // ----------------------------------------------------------------------------
106 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
112 Init(-1, wxSize(0,0), false, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
,
113 wxFONTWEIGHT_NORMAL
, false, wxEmptyString
,
114 wxFONTENCODING_DEFAULT
);
117 wxFontRefData(int size
,
118 const wxSize
& pixelSize
,
119 bool sizeUsingPixels
,
124 const wxString
& faceName
,
125 wxFontEncoding encoding
)
127 Init(size
, pixelSize
, sizeUsingPixels
, family
, style
, weight
,
128 underlined
, faceName
, encoding
);
131 wxFontRefData(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0)
136 wxFontRefData(const wxFontRefData
& data
) : wxGDIRefData()
138 Init(data
.m_nativeFontInfo
);
141 virtual ~wxFontRefData();
148 // all wxFont accessors
149 int GetPointSize() const
151 return m_nativeFontInfo
.GetPointSize();
154 wxSize
GetPixelSize() const
156 return m_nativeFontInfo
.GetPixelSize();
159 bool IsUsingSizeInPixels() const
161 return m_sizeUsingPixels
;
164 wxFontFamily
GetFamily() const
166 return m_nativeFontInfo
.GetFamily();
169 wxFontStyle
GetStyle() const
171 return m_nativeFontInfo
.GetStyle();
174 wxFontWeight
GetWeight() const
176 return m_nativeFontInfo
.GetWeight();
179 bool GetUnderlined() const
181 return m_nativeFontInfo
.GetUnderlined();
184 wxString
GetFaceName() const
186 wxString facename
= m_nativeFontInfo
.GetFaceName();
187 if ( facename
.empty() )
189 facename
= GetMSWFaceName();
190 if ( !facename
.empty() )
192 // cache the face name, it shouldn't change unless the family
193 // does and wxNativeFontInfo::SetFamily() resets the face name
194 const_cast<wxFontRefData
*>(this)->SetFaceName(facename
);
201 wxFontEncoding
GetEncoding() const
203 return m_nativeFontInfo
.GetEncoding();
206 WXHFONT
GetHFONT() const
210 return (WXHFONT
)m_hFont
;
213 bool HasHFONT() const
218 // ... and setters: notice that all of them invalidate the currently
219 // allocated HFONT, if any, so that the next call to GetHFONT() recreates a
221 void SetPointSize(int pointSize
)
225 m_nativeFontInfo
.SetPointSize(pointSize
);
226 m_sizeUsingPixels
= false;
229 void SetPixelSize(const wxSize
& pixelSize
)
231 wxCHECK_RET( pixelSize
.GetWidth() >= 0, "negative font width" );
232 wxCHECK_RET( pixelSize
.GetHeight() != 0, "zero font height" );
236 m_nativeFontInfo
.SetPixelSize(pixelSize
);
237 m_sizeUsingPixels
= true;
240 void SetFamily(wxFontFamily family
)
244 m_nativeFontInfo
.SetFamily(family
);
247 void SetStyle(wxFontStyle style
)
251 m_nativeFontInfo
.SetStyle(style
);
254 void SetWeight(wxFontWeight weight
)
258 m_nativeFontInfo
.SetWeight(weight
);
261 bool SetFaceName(const wxString
& faceName
)
265 return m_nativeFontInfo
.SetFaceName(faceName
);
268 void SetUnderlined(bool underlined
)
272 m_nativeFontInfo
.SetUnderlined(underlined
);
275 void SetEncoding(wxFontEncoding encoding
)
279 m_nativeFontInfo
.SetEncoding(encoding
);
282 const wxNativeFontInfo
& GetNativeFontInfo() const
284 // we need to create the font now to get the corresponding LOGFONT if
285 // it hadn't been done yet
288 // ensure that we have a valid face name in our font information:
289 // GetFaceName() will try to retrieve it from our HFONT and save it if
293 return m_nativeFontInfo
;
296 void SetNativeFontInfo(const wxNativeFontInfo
& nativeFontInfo
)
300 m_nativeFontInfo
= nativeFontInfo
;
304 // common part of all ctors
306 const wxSize
& pixelSize
,
307 bool sizeUsingPixels
,
312 const wxString
& faceName
,
313 wxFontEncoding encoding
);
315 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
317 void AllocIfNeeded() const
320 const_cast<wxFontRefData
*>(this)->Alloc();
323 // retrieve the face name really being used by the font: this is used to
324 // get the face name selected by the system when we don't specify it (but
325 // use just the family for example)
326 wxString
GetMSWFaceName() const
329 SelectInHDC
selectFont(hdc
, m_hFont
);
331 UINT otmSize
= GetOutlineTextMetrics(hdc
, 0, NULL
);
334 wxLogLastError("GetOutlineTextMetrics(NULL)");
338 OUTLINETEXTMETRIC
* const
339 otm
= static_cast<OUTLINETEXTMETRIC
*>(malloc(otmSize
));
340 wxON_BLOCK_EXIT1( free
, otm
);
342 otm
->otmSize
= otmSize
;
343 if ( !GetOutlineTextMetrics(hdc
, otmSize
, otm
) )
345 wxLogLastError("GetOutlineTextMetrics()");
349 // in spite of its type, the otmpFamilyName field of OUTLINETEXTMETRIC
350 // gives an offset in _bytes_ of the face (not family!) name from the
351 // struct start while the name itself is an array of TCHARs
353 // FWIW otmpFaceName contains the same thing as otmpFamilyName followed
354 // by a possible " Italic" or " Bold" or something else suffix
355 return reinterpret_cast<wxChar
*>(otm
) +
356 wxPtrToUInt(otm
->otmpFamilyName
)/sizeof(wxChar
);
359 // are we using m_nativeFontInfo.lf.lfHeight for point size or pixel size?
360 bool m_sizeUsingPixels
;
362 // Windows font handle, created on demand in GetHFONT()
366 wxNativeFontInfo m_nativeFontInfo
;
369 #define M_FONTDATA ((wxFontRefData*)m_refData)
371 // ============================================================================
373 // ============================================================================
375 // ----------------------------------------------------------------------------
377 // ----------------------------------------------------------------------------
379 void wxFontRefData::Init(int pointSize
,
380 const wxSize
& pixelSize
,
381 bool sizeUsingPixels
,
386 const wxString
& faceName
,
387 wxFontEncoding encoding
)
391 m_sizeUsingPixels
= sizeUsingPixels
;
392 if ( m_sizeUsingPixels
)
393 SetPixelSize(pixelSize
);
395 SetPointSize(pointSize
);
399 SetUnderlined(underlined
);
401 // set the family/facename
403 if ( !faceName
.empty() )
404 SetFaceName(faceName
);
406 // deal with encoding now (it may override the font family and facename
407 // so do it after setting them)
408 SetEncoding(encoding
);
411 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
413 // hFont may be zero, or it be passed in case we really want to
414 // use the exact font created in the underlying system
415 // (for example where we can't guarantee conversion from HFONT
416 // to LOGFONT back to HFONT)
417 m_hFont
= (HFONT
)hFont
;
418 m_nativeFontInfo
= info
;
420 // TODO: m_sizeUsingPixels?
423 wxFontRefData::~wxFontRefData()
428 bool wxFontRefData::Alloc()
430 m_hFont
= ::CreateFontIndirect(&m_nativeFontInfo
.lf
);
433 wxLogLastError(wxT("CreateFont"));
440 void wxFontRefData::Free()
444 if ( !::DeleteObject(m_hFont
) )
446 wxLogLastError(wxT("DeleteObject(font)"));
453 // ----------------------------------------------------------------------------
455 // ----------------------------------------------------------------------------
457 void wxNativeFontInfo::Init()
461 // we get better font quality if we use PROOF_QUALITY instead of
462 // DEFAULT_QUALITY but some fonts (e.g. "Terminal 6pt") are not available
463 // then so we allow to set a global option to choose between quality and
464 // wider font selection
466 lf
.lfQuality
= CLEARTYPE_QUALITY
;
468 lf
.lfQuality
= wxSystemOptions::GetOptionInt("msw.font.no-proof-quality")
474 int wxNativeFontInfo::GetPointSize() const
476 // FIXME: using the screen here results in incorrect font size calculation
478 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
480 // BC++ 2007 doesn't provide abs(long) overload, hence the cast
481 return (int) (((72.0*abs((int)lf
.lfHeight
)) / (double) ppInch
) + 0.5);
484 wxSize
wxNativeFontInfo::GetPixelSize() const
487 ret
.SetHeight(abs((int)lf
.lfHeight
));
488 ret
.SetWidth(lf
.lfWidth
);
492 wxFontStyle
wxNativeFontInfo::GetStyle() const
494 return lf
.lfItalic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
;
497 wxFontWeight
wxNativeFontInfo::GetWeight() const
499 if ( lf
.lfWeight
<= 300 )
500 return wxFONTWEIGHT_LIGHT
;
502 if ( lf
.lfWeight
>= 600 )
503 return wxFONTWEIGHT_BOLD
;
505 return wxFONTWEIGHT_NORMAL
;
508 bool wxNativeFontInfo::GetUnderlined() const
510 return lf
.lfUnderline
!= 0;
513 wxString
wxNativeFontInfo::GetFaceName() const
515 return lf
.lfFaceName
;
518 wxFontFamily
wxNativeFontInfo::GetFamily() const
522 // extract family from pitch-and-family
523 switch ( lf
.lfPitchAndFamily
& ~PITCH_MASK
)
526 family
= wxFONTFAMILY_UNKNOWN
;
530 family
= wxFONTFAMILY_ROMAN
;
534 family
= wxFONTFAMILY_SWISS
;
538 family
= wxFONTFAMILY_SCRIPT
;
542 family
= wxFONTFAMILY_MODERN
;
546 family
= wxFONTFAMILY_DECORATIVE
;
550 wxFAIL_MSG( "unknown LOGFONT::lfFamily value" );
551 family
= wxFONTFAMILY_UNKNOWN
;
552 // just to avoid a warning
558 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
560 return wxGetFontEncFromCharSet(lf
.lfCharSet
);
563 void wxNativeFontInfo::SetPointSize(int pointsize
)
565 // FIXME: using the screen here results in incorrect font size calculation
567 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
569 lf
.lfHeight
= -(int)((pointsize
*((double)ppInch
)/72.0) + 0.5);
572 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
574 // MSW accepts both positive and negative heights here but they mean
575 // different things: positive specifies the cell height while negative
576 // specifies the character height. We used to just pass the value to MSW
577 // unchanged but changed the behaviour for positive values in 2.9.1 to
578 // match other ports and, more importantly, the expected behaviour. So now
579 // passing the negative height doesn't make sense at all any more but we
580 // still accept it for compatibility with the existing code which worked
581 // around the wrong interpretation of the height argument in older wxMSW
582 // versions by passing a negative value explicitly itself.
583 lf
.lfHeight
= -abs(pixelSize
.GetHeight());
584 lf
.lfWidth
= pixelSize
.GetWidth();
587 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
592 wxFAIL_MSG( "unknown font style" );
595 case wxFONTSTYLE_NORMAL
:
599 case wxFONTSTYLE_ITALIC
:
600 case wxFONTSTYLE_SLANT
:
606 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
611 wxFAIL_MSG( "unknown font weight" );
614 case wxFONTWEIGHT_NORMAL
:
615 lf
.lfWeight
= FW_NORMAL
;
618 case wxFONTWEIGHT_LIGHT
:
619 lf
.lfWeight
= FW_LIGHT
;
622 case wxFONTWEIGHT_BOLD
:
623 lf
.lfWeight
= FW_BOLD
;
628 void wxNativeFontInfo::SetUnderlined(bool underlined
)
630 lf
.lfUnderline
= underlined
;
633 bool wxNativeFontInfo::SetFaceName(const wxString
& facename
)
635 wxStrlcpy(lf
.lfFaceName
, facename
.c_str(), WXSIZEOF(lf
.lfFaceName
));
639 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
641 BYTE ff_family
= FF_DONTCARE
;
645 case wxFONTFAMILY_SCRIPT
:
646 ff_family
= FF_SCRIPT
;
649 case wxFONTFAMILY_DECORATIVE
:
650 ff_family
= FF_DECORATIVE
;
653 case wxFONTFAMILY_ROMAN
:
654 ff_family
= FF_ROMAN
;
657 case wxFONTFAMILY_TELETYPE
:
658 case wxFONTFAMILY_MODERN
:
659 ff_family
= FF_MODERN
;
662 case wxFONTFAMILY_SWISS
:
663 case wxFONTFAMILY_DEFAULT
:
664 ff_family
= FF_SWISS
;
667 case wxFONTFAMILY_UNKNOWN
:
668 wxFAIL_MSG( "invalid font family" );
672 wxCHECK_RET( ff_family
!= FF_DONTCARE
, "unknown wxFontFamily" );
674 lf
.lfPitchAndFamily
= (BYTE
)(DEFAULT_PITCH
) | ff_family
;
676 // reset the facename so that CreateFontIndirect() will automatically choose a
677 // face name based only on the font family.
678 lf
.lfFaceName
[0] = '\0';
681 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
683 wxNativeEncodingInfo info
;
684 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
687 if ( wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
689 if ( !info
.facename
.empty() )
691 // if we have this encoding only in some particular facename, use
692 // the facename - it is better to show the correct characters in a
693 // wrong facename than unreadable text in a correct one
694 SetFaceName(info
.facename
);
698 #endif // wxUSE_FONTMAP
700 // unsupported encoding, replace with the default
701 info
.charset
= DEFAULT_CHARSET
;
705 lf
.lfCharSet
= (BYTE
)info
.charset
;
708 bool wxNativeFontInfo::FromString(const wxString
& s
)
712 wxStringTokenizer
tokenizer(s
, wxS(";"), wxTOKEN_RET_EMPTY_ALL
);
715 wxString token
= tokenizer
.GetNextToken();
716 if ( token
!= wxS('0') )
719 token
= tokenizer
.GetNextToken();
720 if ( !token
.ToLong(&l
) )
724 token
= tokenizer
.GetNextToken();
725 if ( !token
.ToLong(&l
) )
729 token
= tokenizer
.GetNextToken();
730 if ( !token
.ToLong(&l
) )
734 token
= tokenizer
.GetNextToken();
735 if ( !token
.ToLong(&l
) )
737 lf
.lfOrientation
= l
;
739 token
= tokenizer
.GetNextToken();
740 if ( !token
.ToLong(&l
) )
744 token
= tokenizer
.GetNextToken();
745 if ( !token
.ToLong(&l
) )
747 lf
.lfItalic
= (BYTE
)l
;
749 token
= tokenizer
.GetNextToken();
750 if ( !token
.ToLong(&l
) )
752 lf
.lfUnderline
= (BYTE
)l
;
754 token
= tokenizer
.GetNextToken();
755 if ( !token
.ToLong(&l
) )
757 lf
.lfStrikeOut
= (BYTE
)l
;
759 token
= tokenizer
.GetNextToken();
760 if ( !token
.ToLong(&l
) )
762 lf
.lfCharSet
= (BYTE
)l
;
764 token
= tokenizer
.GetNextToken();
765 if ( !token
.ToLong(&l
) )
767 lf
.lfOutPrecision
= (BYTE
)l
;
769 token
= tokenizer
.GetNextToken();
770 if ( !token
.ToLong(&l
) )
772 lf
.lfClipPrecision
= (BYTE
)l
;
774 token
= tokenizer
.GetNextToken();
775 if ( !token
.ToLong(&l
) )
777 lf
.lfQuality
= (BYTE
)l
;
779 token
= tokenizer
.GetNextToken();
780 if ( !token
.ToLong(&l
) )
782 lf
.lfPitchAndFamily
= (BYTE
)l
;
784 if ( !tokenizer
.HasMoreTokens() )
787 // the face name may be empty
788 SetFaceName(tokenizer
.GetNextToken());
793 wxString
wxNativeFontInfo::ToString() const
797 s
.Printf(wxS("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
798 0, // version, in case we want to change the format later
817 // ----------------------------------------------------------------------------
819 // ----------------------------------------------------------------------------
821 wxFont::wxFont(const wxString
& fontdesc
)
823 wxNativeFontInfo info
;
824 if ( info
.FromString(fontdesc
) )
828 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
832 m_refData
= new wxFontRefData(info
, hFont
);
834 return RealizeResource();
837 bool wxFont::DoCreate(int pointSize
,
838 const wxSize
& pixelSize
,
839 bool sizeUsingPixels
,
844 const wxString
& faceName
,
845 wxFontEncoding encoding
)
849 // wxDEFAULT is a valid value for the font size too so we must treat it
850 // specially here (otherwise the size would be 70 == wxDEFAULT value)
851 if ( pointSize
== wxDEFAULT
)
853 pointSize
= wxNORMAL_FONT
->GetPointSize();
856 m_refData
= new wxFontRefData(pointSize
, pixelSize
, sizeUsingPixels
,
857 family
, style
, weight
,
858 underlined
, faceName
, encoding
);
860 return RealizeResource();
867 // ----------------------------------------------------------------------------
868 // real implementation
869 // ----------------------------------------------------------------------------
871 wxGDIRefData
*wxFont::CreateGDIRefData() const
873 return new wxFontRefData();
876 wxGDIRefData
*wxFont::CloneGDIRefData(const wxGDIRefData
*data
) const
878 return new wxFontRefData(*static_cast<const wxFontRefData
*>(data
));
881 bool wxFont::RealizeResource()
883 // NOTE: the GetHFONT() call automatically triggers a reallocation of
884 // the HFONT if necessary (will do nothing if we already have the resource);
885 // it returns NULL only if there is a failure in wxFontRefData::Alloc()...
886 return GetHFONT() != NULL
;
889 bool wxFont::FreeResource(bool WXUNUSED(force
))
899 WXHANDLE
wxFont::GetResourceHandle() const
901 return (WXHANDLE
)GetHFONT();
904 WXHFONT
wxFont::GetHFONT() const
906 // NOTE: wxFontRefData::GetHFONT() will automatically call
907 // wxFontRefData::Alloc() if necessary
908 return M_FONTDATA
? M_FONTDATA
->GetHFONT() : 0;
911 bool wxFont::IsFree() const
913 return M_FONTDATA
&& !M_FONTDATA
->HasHFONT();
916 // ----------------------------------------------------------------------------
917 // change font attribute: we recreate font when doing it
918 // ----------------------------------------------------------------------------
920 void wxFont::SetPointSize(int pointSize
)
925 M_FONTDATA
->SetPointSize(pointSize
);
928 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
932 M_FONTDATA
->SetPixelSize(pixelSize
);
935 void wxFont::SetFamily(wxFontFamily family
)
939 M_FONTDATA
->SetFamily(family
);
942 void wxFont::SetStyle(wxFontStyle style
)
946 M_FONTDATA
->SetStyle(style
);
949 void wxFont::SetWeight(wxFontWeight weight
)
953 M_FONTDATA
->SetWeight(weight
);
956 bool wxFont::SetFaceName(const wxString
& faceName
)
960 if ( !M_FONTDATA
->SetFaceName(faceName
) )
963 // NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
964 // to retrieve a LOGFONT and then compare lf.lfFaceName
965 // with given facename is not reliable at all:
966 // Windows copies the facename given to ::CreateFontIndirect()
967 // without any validity check.
968 // Thus we use wxFontBase::SetFaceName to check if facename
970 return wxFontBase::SetFaceName(faceName
);
973 void wxFont::SetUnderlined(bool underlined
)
977 M_FONTDATA
->SetUnderlined(underlined
);
980 void wxFont::SetEncoding(wxFontEncoding encoding
)
984 M_FONTDATA
->SetEncoding(encoding
);
987 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
991 M_FONTDATA
->SetNativeFontInfo(info
);
994 // ----------------------------------------------------------------------------
996 // ----------------------------------------------------------------------------
998 int wxFont::GetPointSize() const
1000 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
1002 return M_FONTDATA
->GetPointSize();
1005 wxSize
wxFont::GetPixelSize() const
1007 wxCHECK_MSG( IsOk(), wxDefaultSize
, wxT("invalid font") );
1009 return M_FONTDATA
->GetPixelSize();
1012 bool wxFont::IsUsingSizeInPixels() const
1014 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
1016 return M_FONTDATA
->IsUsingSizeInPixels();
1019 wxFontFamily
wxFont::DoGetFamily() const
1021 return M_FONTDATA
->GetFamily();
1024 wxFontStyle
wxFont::GetStyle() const
1026 wxCHECK_MSG( IsOk(), wxFONTSTYLE_MAX
, wxT("invalid font") );
1028 return M_FONTDATA
->GetStyle();
1031 wxFontWeight
wxFont::GetWeight() const
1033 wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX
, wxT("invalid font") );
1035 return M_FONTDATA
->GetWeight();
1038 bool wxFont::GetUnderlined() const
1040 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
1042 return M_FONTDATA
->GetUnderlined();
1045 wxString
wxFont::GetFaceName() const
1047 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
1049 return M_FONTDATA
->GetFaceName();
1052 wxFontEncoding
wxFont::GetEncoding() const
1054 wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
1056 return M_FONTDATA
->GetEncoding();
1059 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
1061 return IsOk() ? &(M_FONTDATA
->GetNativeFontInfo()) : NULL
;
1064 bool wxFont::IsFixedWidth() const
1066 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
1068 // LOGFONT doesn't contain the correct pitch information so we need to call
1069 // GetTextMetrics() to get it
1071 SelectInHDC
selectFont(hdc
, M_FONTDATA
->GetHFONT());
1074 if ( !::GetTextMetrics(hdc
, &tm
) )
1076 wxLogLastError(wxT("GetTextMetrics"));
1080 // Quoting MSDN description of TMPF_FIXED_PITCH: "Note very carefully that
1081 // those meanings are the opposite of what the constant name implies."
1082 return !(tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
);