1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mgl/font.cpp
3 // Author: Vaclav Slavik
5 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // ============================================================================
11 // ============================================================================
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
26 #include "wx/private/fontmgr.h"
28 // ============================================================================
30 // ============================================================================
32 typedef wxFontMgrFontRefData wxFontRefData
;
33 #define M_FONTDATA ((wxFontRefData*)m_refData)
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
41 bool wxFont::Create(const wxNativeFontInfo
& info
)
43 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
44 info
.underlined
, info
.faceName
, info
.encoding
);
47 bool wxFont::Create(int pointSize
,
53 wxFontEncoding encoding
)
55 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
56 underlined
, face
, encoding
);
60 wxGDIRefData
*wxFont::CreateGDIRefData() const
62 return new wxFontRefData
;
65 wxGDIRefData
*wxFont::CloneGDIRefData(const wxGDIRefData
*data
) const
67 return new wxFontRefData(*(wxFontRefData
*)data
);
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 struct font_t
*wxFont::GetMGLfont_t(float scale
, bool antialiased
)
77 wxCHECK_MSG( Ok(), NULL
, wxT("invalid font") );
79 // we don't support DC scaling yet, so use scale=1
80 wxFontInstance
*i
= M_FONTDATA
->GetFontInstance(1.0, antialiased
);
81 return i
? i
->GetMGLfont_t() : NULL
;
84 int wxFont::GetPointSize() const
86 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
88 return M_FONTDATA
->GetPointSize();
91 wxString
wxFont::GetFaceName() const
93 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid font") );
95 return M_FONTDATA
->GetFaceName();
98 wxFontFamily
wxFont::DoGetFamily() const
100 return M_FONTDATA
->GetFamily();
103 wxFontStyle
wxFont::GetStyle() const
105 wxCHECK_MSG( Ok(), wxFONTSTYLE_MAX
, wxT("invalid font") );
107 return M_FONTDATA
->GetStyle();
110 wxFontWeight
wxFont::GetWeight() const
112 wxCHECK_MSG( Ok(), wxFONTWEIGHT_MAX
, wxT("invalid font") );
114 return M_FONTDATA
->GetWeight();
117 bool wxFont::GetUnderlined() const
119 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
121 return M_FONTDATA
->GetUnderlined();
125 wxFontEncoding
wxFont::GetEncoding() const
127 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT
, wxT("invalid font") );
129 return M_FONTDATA
->GetEncoding();
132 bool wxFont::IsFixedWidth() const
134 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
136 return M_FONTDATA
->IsFixedWidth();
139 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
141 wxCHECK_MSG( Ok(), NULL
, wxT("invalid font") );
143 return M_FONTDATA
->GetNativeFontInfo();
146 // ----------------------------------------------------------------------------
147 // change font attributes
148 // ----------------------------------------------------------------------------
150 void wxFont::SetPointSize(int pointSize
)
153 M_FONTDATA
->SetPointSize(pointSize
);
156 void wxFont::SetFamily(wxFontFamily family
)
159 M_FONTDATA
->SetFamily(family
);
162 void wxFont::SetStyle(wxFontStyle style
)
165 M_FONTDATA
->SetStyle(style
);
168 void wxFont::SetWeight(wxFontWeight weight
)
171 M_FONTDATA
->SetWeight(weight
);
174 bool wxFont::SetFaceName(const wxString
& faceName
)
177 M_FONTDATA
->SetFaceName(faceName
);
178 return wxFontBase::SetFaceName(faceName
);
181 void wxFont::SetUnderlined(bool underlined
)
184 M_FONTDATA
->SetUnderlined(underlined
);
187 void wxFont::SetEncoding(wxFontEncoding encoding
)
190 M_FONTDATA
->SetEncoding(encoding
);