1///////////////////////////////////////////////////////////////////////////// 2// Name: src/mgl/font.cpp 3// Author: Vaclav Slavik 4// Id: $Id: font.cpp 43547 2006-11-20 16:43:55Z VS $ 5// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) 6// Licence: wxWindows licence 7///////////////////////////////////////////////////////////////////////////// 8 9// ============================================================================ 10// declarations 11// ============================================================================ 12 13// ---------------------------------------------------------------------------- 14// headers 15// ---------------------------------------------------------------------------- 16 17// For compilers that support precompilation, includes "wx.h". 18#include "wx/wxprec.h" 19 20#ifdef __BORLANDC__ 21 #pragma hdrstop 22#endif 23 24#include "wx/font.h" 25 26#include "wx/private/fontmgr.h" 27 28// ============================================================================ 29// implementation 30// ============================================================================ 31 32typedef wxFontMgrFontRefData wxFontRefData; 33#define M_FONTDATA ((wxFontRefData*)m_refData) 34 35// ---------------------------------------------------------------------------- 36// wxFont 37// ---------------------------------------------------------------------------- 38 39IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) 40 41bool wxFont::Create(const wxNativeFontInfo& info) 42{ 43 return Create(info.pointSize, info.family, info.style, info.weight, 44 info.underlined, info.faceName, info.encoding); 45} 46 47bool wxFont::Create(int pointSize, 48 int family, 49 int style, 50 int weight, 51 bool underlined, 52 const wxString& face, 53 wxFontEncoding encoding) 54{ 55 m_refData = new wxFontRefData(pointSize, family, style, weight, 56 underlined, face, encoding); 57 return true; 58} 59 60wxObjectRefData *wxFont::CreateRefData() const 61{ 62 return new wxFontRefData; 63} 64 65wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const 66{ 67 return new wxFontRefData(*(wxFontRefData *)data); 68} 69 70 71// ---------------------------------------------------------------------------- 72// accessors 73// ---------------------------------------------------------------------------- 74 75struct font_t *wxFont::GetMGLfont_t(float scale, bool antialiased) 76{ 77 wxCHECK_MSG( Ok(), NULL, wxT("invalid font") ); 78 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; 82} 83 84int wxFont::GetPointSize() const 85{ 86 wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); 87 88 return M_FONTDATA->GetPointSize(); 89} 90 91wxString wxFont::GetFaceName() const 92{ 93 wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") ); 94 95 return M_FONTDATA->GetFaceName(); 96} 97 98int wxFont::GetFamily() const 99{ 100 wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); 101 102 return M_FONTDATA->GetFamily(); 103} 104 105int wxFont::GetStyle() const 106{ 107 wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); 108 109 return M_FONTDATA->GetStyle(); 110} 111 112int wxFont::GetWeight() const 113{ 114 wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); 115 116 return M_FONTDATA->GetWeight(); 117} 118 119bool wxFont::GetUnderlined() const 120{ 121 wxCHECK_MSG( Ok(), false, wxT("invalid font") ); 122 123 return M_FONTDATA->GetUnderlined(); 124} 125 126 127wxFontEncoding wxFont::GetEncoding() const 128{ 129 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); 130 131 return M_FONTDATA->GetEncoding(); 132} 133 134bool wxFont::IsFixedWidth() const 135{ 136 wxCHECK_MSG( Ok(), false, wxT("invalid font") ); 137 138 return M_FONTDATA->IsFixedWidth(); 139} 140 141const wxNativeFontInfo *wxFont::GetNativeFontInfo() const 142{ 143 wxCHECK_MSG( Ok(), NULL, wxT("invalid font") ); 144 145 return M_FONTDATA->GetNativeFontInfo(); 146} 147 148bool wxFont::GetNoAntiAliasing() const 149{ 150 wxCHECK_MSG( Ok(), false, wxT("invalid font") ); 151 152 return M_FONTDATA->GetNoAntiAliasing(); 153} 154 155// ---------------------------------------------------------------------------- 156// change font attributes 157// ---------------------------------------------------------------------------- 158 159void wxFont::SetPointSize(int pointSize) 160{ 161 AllocExclusive(); 162 M_FONTDATA->SetPointSize(pointSize); 163} 164 165void wxFont::SetFamily(int family) 166{ 167 AllocExclusive(); 168 M_FONTDATA->SetFamily(family); 169} 170 171void wxFont::SetStyle(int style) 172{ 173 AllocExclusive(); 174 M_FONTDATA->SetStyle(style); 175} 176 177void wxFont::SetWeight(int weight) 178{ 179 AllocExclusive(); 180 M_FONTDATA->SetWeight(weight); 181} 182 183bool wxFont::SetFaceName(const wxString& faceName) 184{ 185 AllocExclusive(); 186 M_FONTDATA->SetFaceName(faceName); 187 return wxFontBase::SetFaceName(faceName); 188} 189 190void wxFont::SetUnderlined(bool underlined) 191{ 192 AllocExclusive(); 193 M_FONTDATA->SetUnderlined(underlined); 194} 195 196void wxFont::SetEncoding(wxFontEncoding encoding) 197{ 198 AllocExclusive(); 199 M_FONTDATA->SetEncoding(encoding); 200} 201 202void wxFont::SetNoAntiAliasing(bool no) 203{ 204 AllocExclusive(); 205 M_FONTDATA->SetNoAntiAliasing(no); 206} 207