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 // the face name returned by GetOutlineTextMetrics() may have
193 // these suffixes which we don't count as part of face name
194 // because we have separate fields for them so remove them
196 if ( facename
.EndsWith(wxS(" Italic"), &basename
) ||
197 facename
.EndsWith(wxS(" Bold"), &basename
) )
200 // cache the face name, it shouldn't change unless the family
201 // does and wxNativeFontInfo::SetFamily() resets the face name
202 const_cast<wxFontRefData
*>(this)->SetFaceName(facename
);
209 wxFontEncoding
GetEncoding() const
211 return m_nativeFontInfo
.GetEncoding();
214 WXHFONT
GetHFONT() const
218 return (WXHFONT
)m_hFont
;
221 bool HasHFONT() const
226 // ... and setters: notice that all of them invalidate the currently
227 // allocated HFONT, if any, so that the next call to GetHFONT() recreates a
229 void SetPointSize(int pointSize
)
233 m_nativeFontInfo
.SetPointSize(pointSize
);
234 m_sizeUsingPixels
= false;
237 void SetPixelSize(const wxSize
& pixelSize
)
239 wxCHECK_RET( pixelSize
.GetWidth() >= 0, "negative font width" );
240 wxCHECK_RET( pixelSize
.GetHeight() != 0, "zero font height" );
244 m_nativeFontInfo
.SetPixelSize(pixelSize
);
245 m_sizeUsingPixels
= true;
248 void SetFamily(wxFontFamily family
)
252 m_nativeFontInfo
.SetFamily(family
);
255 void SetStyle(wxFontStyle style
)
259 m_nativeFontInfo
.SetStyle(style
);
262 void SetWeight(wxFontWeight weight
)
266 m_nativeFontInfo
.SetWeight(weight
);
269 bool SetFaceName(const wxString
& faceName
)
273 return m_nativeFontInfo
.SetFaceName(faceName
);
276 void SetUnderlined(bool underlined
)
280 m_nativeFontInfo
.SetUnderlined(underlined
);
283 void SetEncoding(wxFontEncoding encoding
)
287 m_nativeFontInfo
.SetEncoding(encoding
);
290 const wxNativeFontInfo
& GetNativeFontInfo() const
292 // we need to create the font now to get the corresponding LOGFONT if
293 // it hadn't been done yet
296 // ensure that we have a valid face name in our font information:
297 // GetFaceName() will try to retrieve it from our HFONT and save it if
301 return m_nativeFontInfo
;
304 void SetNativeFontInfo(const wxNativeFontInfo
& nativeFontInfo
)
308 m_nativeFontInfo
= nativeFontInfo
;
312 // common part of all ctors
314 const wxSize
& pixelSize
,
315 bool sizeUsingPixels
,
320 const wxString
& faceName
,
321 wxFontEncoding encoding
);
323 void Init(const wxNativeFontInfo
& info
, WXHFONT hFont
= 0);
325 void AllocIfNeeded() const
328 const_cast<wxFontRefData
*>(this)->Alloc();
331 // retrieve the face name really being used by the font: this is used to
332 // get the face name selected by the system when we don't specify it (but
333 // use just the family for example)
334 wxString
GetMSWFaceName() const
337 SelectInHDC
selectFont(hdc
, m_hFont
);
339 UINT otmSize
= GetOutlineTextMetrics(hdc
, 0, NULL
);
342 wxLogLastError("GetOutlineTextMetrics(NULL)");
346 OUTLINETEXTMETRIC
* const
347 otm
= static_cast<OUTLINETEXTMETRIC
*>(malloc(otmSize
));
348 wxON_BLOCK_EXIT1( free
, otm
);
350 otm
->otmSize
= otmSize
;
351 if ( !GetOutlineTextMetrics(hdc
, otmSize
, otm
) )
353 wxLogLastError("GetOutlineTextMetrics()");
357 // in spite of its type, the otmpFaceName field of OUTLINETEXTMETRIC
358 // gives an offset in _bytes_ of the face name from the struct start
359 // while the name itself is an array of TCHARs
360 return reinterpret_cast<wxChar
*>(otm
) +
361 wxPtrToUInt(otm
->otmpFaceName
)/sizeof(wxChar
);
364 // are we using m_nativeFontInfo.lf.lfHeight for point size or pixel size?
365 bool m_sizeUsingPixels
;
367 // Windows font handle, created on demand in GetHFONT()
371 wxNativeFontInfo m_nativeFontInfo
;
374 #define M_FONTDATA ((wxFontRefData*)m_refData)
376 // ============================================================================
378 // ============================================================================
380 // ----------------------------------------------------------------------------
382 // ----------------------------------------------------------------------------
384 void wxFontRefData::Init(int pointSize
,
385 const wxSize
& pixelSize
,
386 bool sizeUsingPixels
,
391 const wxString
& faceName
,
392 wxFontEncoding encoding
)
396 m_sizeUsingPixels
= sizeUsingPixels
;
397 if ( m_sizeUsingPixels
)
398 SetPixelSize(pixelSize
);
400 SetPointSize(pointSize
);
404 SetUnderlined(underlined
);
406 // set the family/facename
408 if ( !faceName
.empty() )
409 SetFaceName(faceName
);
411 // deal with encoding now (it may override the font family and facename
412 // so do it after setting them)
413 SetEncoding(encoding
);
416 void wxFontRefData::Init(const wxNativeFontInfo
& info
, WXHFONT hFont
)
418 // hFont may be zero, or it be passed in case we really want to
419 // use the exact font created in the underlying system
420 // (for example where we can't guarantee conversion from HFONT
421 // to LOGFONT back to HFONT)
422 m_hFont
= (HFONT
)hFont
;
423 m_nativeFontInfo
= info
;
425 // TODO: m_sizeUsingPixels?
428 wxFontRefData::~wxFontRefData()
433 bool wxFontRefData::Alloc()
435 m_hFont
= ::CreateFontIndirect(&m_nativeFontInfo
.lf
);
438 wxLogLastError(wxT("CreateFont"));
445 void wxFontRefData::Free()
449 if ( !::DeleteObject(m_hFont
) )
451 wxLogLastError(wxT("DeleteObject(font)"));
458 // ----------------------------------------------------------------------------
460 // ----------------------------------------------------------------------------
462 void wxNativeFontInfo::Init()
466 // we get better font quality if we use PROOF_QUALITY instead of
467 // DEFAULT_QUALITY but some fonts (e.g. "Terminal 6pt") are not available
468 // then so we allow to set a global option to choose between quality and
469 // wider font selection
471 lf
.lfQuality
= CLEARTYPE_QUALITY
;
473 lf
.lfQuality
= wxSystemOptions::GetOptionInt("msw.font.no-proof-quality")
479 int wxNativeFontInfo::GetPointSize() const
481 // FIXME: using the screen here results in incorrect font size calculation
483 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
485 // BC++ 2007 doesn't provide abs(long) overload, hence the cast
486 return (int) (((72.0*abs((int)lf
.lfHeight
)) / (double) ppInch
) + 0.5);
489 wxSize
wxNativeFontInfo::GetPixelSize() const
492 ret
.SetHeight(abs((int)lf
.lfHeight
));
493 ret
.SetWidth(lf
.lfWidth
);
497 wxFontStyle
wxNativeFontInfo::GetStyle() const
499 return lf
.lfItalic
? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
;
502 wxFontWeight
wxNativeFontInfo::GetWeight() const
504 if ( lf
.lfWeight
<= 300 )
505 return wxFONTWEIGHT_LIGHT
;
507 if ( lf
.lfWeight
>= 600 )
508 return wxFONTWEIGHT_BOLD
;
510 return wxFONTWEIGHT_NORMAL
;
513 bool wxNativeFontInfo::GetUnderlined() const
515 return lf
.lfUnderline
!= 0;
518 wxString
wxNativeFontInfo::GetFaceName() const
520 return lf
.lfFaceName
;
523 wxFontFamily
wxNativeFontInfo::GetFamily() const
527 // extract family from pitch-and-family
528 switch ( lf
.lfPitchAndFamily
& ~PITCH_MASK
)
531 family
= wxFONTFAMILY_UNKNOWN
;
535 family
= wxFONTFAMILY_ROMAN
;
539 family
= wxFONTFAMILY_SWISS
;
543 family
= wxFONTFAMILY_SCRIPT
;
547 family
= wxFONTFAMILY_MODERN
;
551 family
= wxFONTFAMILY_DECORATIVE
;
555 wxFAIL_MSG( "unknown LOGFONT::lfFamily value" );
556 family
= wxFONTFAMILY_UNKNOWN
;
557 // just to avoid a warning
563 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
565 return wxGetFontEncFromCharSet(lf
.lfCharSet
);
568 void wxNativeFontInfo::SetPointSize(int pointsize
)
570 // FIXME: using the screen here results in incorrect font size calculation
572 const int ppInch
= ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY
);
574 lf
.lfHeight
= -(int)((pointsize
*((double)ppInch
)/72.0) + 0.5);
577 void wxNativeFontInfo::SetPixelSize(const wxSize
& pixelSize
)
579 // MSW accepts both positive and negative heights here but they mean
580 // different things: positive specifies the cell height while negative
581 // specifies the character height. We used to just pass the value to MSW
582 // unchanged but changed the behaviour for positive values in 2.9.1 to
583 // match other ports and, more importantly, the expected behaviour. So now
584 // passing the negative height doesn't make sense at all any more but we
585 // still accept it for compatibility with the existing code which worked
586 // around the wrong interpretation of the height argument in older wxMSW
587 // versions by passing a negative value explicitly itself.
588 lf
.lfHeight
= -abs(pixelSize
.GetHeight());
589 lf
.lfWidth
= pixelSize
.GetWidth();
592 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
597 wxFAIL_MSG( "unknown font style" );
600 case wxFONTSTYLE_NORMAL
:
604 case wxFONTSTYLE_ITALIC
:
605 case wxFONTSTYLE_SLANT
:
611 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
616 wxFAIL_MSG( "unknown font weight" );
619 case wxFONTWEIGHT_NORMAL
:
620 lf
.lfWeight
= FW_NORMAL
;
623 case wxFONTWEIGHT_LIGHT
:
624 lf
.lfWeight
= FW_LIGHT
;
627 case wxFONTWEIGHT_BOLD
:
628 lf
.lfWeight
= FW_BOLD
;
633 void wxNativeFontInfo::SetUnderlined(bool underlined
)
635 lf
.lfUnderline
= underlined
;
638 bool wxNativeFontInfo::SetFaceName(const wxString
& facename
)
640 wxStrlcpy(lf
.lfFaceName
, facename
.c_str(), WXSIZEOF(lf
.lfFaceName
));
644 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
646 BYTE ff_family
= FF_DONTCARE
;
650 case wxFONTFAMILY_SCRIPT
:
651 ff_family
= FF_SCRIPT
;
654 case wxFONTFAMILY_DECORATIVE
:
655 ff_family
= FF_DECORATIVE
;
658 case wxFONTFAMILY_ROMAN
:
659 ff_family
= FF_ROMAN
;
662 case wxFONTFAMILY_TELETYPE
:
663 case wxFONTFAMILY_MODERN
:
664 ff_family
= FF_MODERN
;
667 case wxFONTFAMILY_SWISS
:
668 case wxFONTFAMILY_DEFAULT
:
669 ff_family
= FF_SWISS
;
673 wxCHECK_RET( ff_family
!= FF_DONTCARE
, "unknown wxFontFamily" );
675 lf
.lfPitchAndFamily
= (BYTE
)(DEFAULT_PITCH
) | ff_family
;
677 // reset the facename so that CreateFontIndirect() will automatically choose a
678 // face name based only on the font family.
679 lf
.lfFaceName
[0] = '\0';
682 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
684 wxNativeEncodingInfo info
;
685 if ( !wxGetNativeFontEncoding(encoding
, &info
) )
688 if ( wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
690 if ( !info
.facename
.empty() )
692 // if we have this encoding only in some particular facename, use
693 // the facename - it is better to show the correct characters in a
694 // wrong facename than unreadable text in a correct one
695 SetFaceName(info
.facename
);
699 #endif // wxUSE_FONTMAP
701 // unsupported encoding, replace with the default
702 info
.charset
= DEFAULT_CHARSET
;
706 lf
.lfCharSet
= (BYTE
)info
.charset
;
709 bool wxNativeFontInfo::FromString(const wxString
& s
)
713 wxStringTokenizer
tokenizer(s
, wxS(";"), wxTOKEN_RET_EMPTY_ALL
);
716 wxString token
= tokenizer
.GetNextToken();
717 if ( token
!= wxS('0') )
720 token
= tokenizer
.GetNextToken();
721 if ( !token
.ToLong(&l
) )
725 token
= tokenizer
.GetNextToken();
726 if ( !token
.ToLong(&l
) )
730 token
= tokenizer
.GetNextToken();
731 if ( !token
.ToLong(&l
) )
735 token
= tokenizer
.GetNextToken();
736 if ( !token
.ToLong(&l
) )
738 lf
.lfOrientation
= l
;
740 token
= tokenizer
.GetNextToken();
741 if ( !token
.ToLong(&l
) )
745 token
= tokenizer
.GetNextToken();
746 if ( !token
.ToLong(&l
) )
748 lf
.lfItalic
= (BYTE
)l
;
750 token
= tokenizer
.GetNextToken();
751 if ( !token
.ToLong(&l
) )
753 lf
.lfUnderline
= (BYTE
)l
;
755 token
= tokenizer
.GetNextToken();
756 if ( !token
.ToLong(&l
) )
758 lf
.lfStrikeOut
= (BYTE
)l
;
760 token
= tokenizer
.GetNextToken();
761 if ( !token
.ToLong(&l
) )
763 lf
.lfCharSet
= (BYTE
)l
;
765 token
= tokenizer
.GetNextToken();
766 if ( !token
.ToLong(&l
) )
768 lf
.lfOutPrecision
= (BYTE
)l
;
770 token
= tokenizer
.GetNextToken();
771 if ( !token
.ToLong(&l
) )
773 lf
.lfClipPrecision
= (BYTE
)l
;
775 token
= tokenizer
.GetNextToken();
776 if ( !token
.ToLong(&l
) )
778 lf
.lfQuality
= (BYTE
)l
;
780 token
= tokenizer
.GetNextToken();
781 if ( !token
.ToLong(&l
) )
783 lf
.lfPitchAndFamily
= (BYTE
)l
;
785 if ( !tokenizer
.HasMoreTokens() )
788 // the face name may be empty
789 SetFaceName(tokenizer
.GetNextToken());
794 wxString
wxNativeFontInfo::ToString() const
798 s
.Printf(wxS("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
799 0, // version, in case we want to change the format later
818 // ----------------------------------------------------------------------------
820 // ----------------------------------------------------------------------------
822 wxFont::wxFont(const wxString
& fontdesc
)
824 wxNativeFontInfo info
;
825 if ( info
.FromString(fontdesc
) )
829 bool wxFont::Create(const wxNativeFontInfo
& info
, WXHFONT hFont
)
833 m_refData
= new wxFontRefData(info
, hFont
);
835 return RealizeResource();
838 bool wxFont::DoCreate(int pointSize
,
839 const wxSize
& pixelSize
,
840 bool sizeUsingPixels
,
845 const wxString
& faceName
,
846 wxFontEncoding encoding
)
850 // wxDEFAULT is a valid value for the font size too so we must treat it
851 // specially here (otherwise the size would be 70 == wxDEFAULT value)
852 if ( pointSize
== wxDEFAULT
)
854 pointSize
= wxNORMAL_FONT
->GetPointSize();
857 m_refData
= new wxFontRefData(pointSize
, pixelSize
, sizeUsingPixels
,
858 family
, style
, weight
,
859 underlined
, faceName
, encoding
);
861 return RealizeResource();
868 // ----------------------------------------------------------------------------
869 // real implementation
870 // ----------------------------------------------------------------------------
872 wxGDIRefData
*wxFont::CreateGDIRefData() const
874 return new wxFontRefData();
877 wxGDIRefData
*wxFont::CloneGDIRefData(const wxGDIRefData
*data
) const
879 return new wxFontRefData(*static_cast<const wxFontRefData
*>(data
));
882 bool wxFont::RealizeResource()
884 // NOTE: the GetHFONT() call automatically triggers a reallocation of
885 // the HFONT if necessary (will do nothing if we already have the resource);
886 // it returns NULL only if there is a failure in wxFontRefData::Alloc()...
887 return GetHFONT() != NULL
;
890 bool wxFont::FreeResource(bool WXUNUSED(force
))
900 WXHANDLE
wxFont::GetResourceHandle() const
902 return (WXHANDLE
)GetHFONT();
905 WXHFONT
wxFont::GetHFONT() const
907 // NOTE: wxFontRefData::GetHFONT() will automatically call
908 // wxFontRefData::Alloc() if necessary
909 return M_FONTDATA
? M_FONTDATA
->GetHFONT() : 0;
912 bool wxFont::IsFree() const
914 return M_FONTDATA
&& !M_FONTDATA
->HasHFONT();
917 // ----------------------------------------------------------------------------
918 // change font attribute: we recreate font when doing it
919 // ----------------------------------------------------------------------------
921 void wxFont::SetPointSize(int pointSize
)
926 M_FONTDATA
->SetPointSize(pointSize
);
929 void wxFont::SetPixelSize(const wxSize
& pixelSize
)
933 M_FONTDATA
->SetPixelSize(pixelSize
);
936 void wxFont::SetFamily(wxFontFamily family
)
940 M_FONTDATA
->SetFamily(family
);
943 void wxFont::SetStyle(wxFontStyle style
)
947 M_FONTDATA
->SetStyle(style
);
950 void wxFont::SetWeight(wxFontWeight weight
)
954 M_FONTDATA
->SetWeight(weight
);
957 bool wxFont::SetFaceName(const wxString
& faceName
)
961 if ( !M_FONTDATA
->SetFaceName(faceName
) )
964 // NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
965 // to retrieve a LOGFONT and then compare lf.lfFaceName
966 // with given facename is not reliable at all:
967 // Windows copies the facename given to ::CreateFontIndirect()
968 // without any validity check.
969 // Thus we use wxFontBase::SetFaceName to check if facename
971 return wxFontBase::SetFaceName(faceName
);
974 void wxFont::SetUnderlined(bool underlined
)
978 M_FONTDATA
->SetUnderlined(underlined
);
981 void wxFont::SetEncoding(wxFontEncoding encoding
)
985 M_FONTDATA
->SetEncoding(encoding
);
988 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo
& info
)
992 M_FONTDATA
->SetNativeFontInfo(info
);
995 // ----------------------------------------------------------------------------
997 // ----------------------------------------------------------------------------
999 int wxFont::GetPointSize() const
1001 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
1003 return M_FONTDATA
->GetPointSize();
1006 wxSize
wxFont::GetPixelSize() const
1008 wxCHECK_MSG( IsOk(), wxDefaultSize
, wxT("invalid font") );
1010 return M_FONTDATA
->GetPixelSize();
1013 bool wxFont::IsUsingSizeInPixels() const
1015 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
1017 return M_FONTDATA
->IsUsingSizeInPixels();
1020 wxFontFamily
wxFont::GetFamily() const
1022 wxCHECK_MSG( IsOk(), wxFONTFAMILY_MAX
, wxT("invalid font") );
1024 return M_FONTDATA
->GetFamily();
1027 wxFontStyle
wxFont::GetStyle() const
1029 wxCHECK_MSG( IsOk(), wxFONTSTYLE_MAX
, wxT("invalid font") );
1031 return M_FONTDATA
->GetStyle();
1034 wxFontWeight
wxFont::GetWeight() const
1036 wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX
, wxT("invalid font") );
1038 return M_FONTDATA
->GetWeight();
1041 bool wxFont::GetUnderlined() const
1043 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
1045 return M_FONTDATA
->GetUnderlined();
1048 wxString
wxFont::GetFaceName() const
1050 wxCHECK_MSG( IsOk(), wxEmptyString
, wxT("invalid font") );
1052 return M_FONTDATA
->GetFaceName();
1055 wxFontEncoding
wxFont::GetEncoding() const
1057 wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
1059 return M_FONTDATA
->GetEncoding();
1062 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
1064 return IsOk() ? &(M_FONTDATA
->GetNativeFontInfo()) : NULL
;
1067 bool wxFont::IsFixedWidth() const
1069 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
1071 // the two low-order bits specify the pitch of the font, the rest is
1074 (BYTE
)(M_FONTDATA
->GetNativeFontInfo().lf
.lfPitchAndFamily
& PITCH_MASK
);
1076 return pitch
== FIXED_PITCH
;