1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/font.cpp
3 // Purpose: wxFont class
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
17 #include "wx/string.h"
18 #include "wx/gdicmn.h"
21 #include "wx/fontutil.h"
22 #include "wx/encinfo.h"
24 class WXDLLEXPORT wxFontRefData: public wxGDIRefData
26 friend class WXDLLIMPEXP_FWD_CORE wxFont;
31 Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE,
32 wxT("Geneva"), wxFONTENCODING_DEFAULT);
35 wxFontRefData(const wxFontRefData& data)
37 , m_fontId(data.m_fontId)
42 wxFontRefData(const wxNativeFontInfo& info)
48 wxFontRefData(int size,
53 const wxString& faceName,
54 wxFontEncoding encoding)
57 Init(size, family, style, weight, underlined, faceName, encoding);
60 virtual ~wxFontRefData();
62 // common part of all ctors
68 const wxString& faceName,
69 wxFontEncoding encoding);
71 // font characterstics
73 wxNativeFontInfo m_info;
78 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
80 void wxFontRefData::Init(int size, int family, int style, int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding)
82 m_info.pointSize = size;
83 m_info.family = static_cast<wxFontFamily>(family);
84 m_info.style = static_cast<wxFontStyle>(style);
85 m_info.weight = static_cast<wxFontWeight>(weight);
86 m_info.underlined = underlined;
87 m_info.faceName = faceName;
88 m_info.encoding = encoding;
91 wxFontRefData::~wxFontRefData()
93 // TODO: delete font data
96 #define M_FONTDATA ((wxFontRefData*)m_refData)
98 bool wxFont::Create(const wxNativeFontInfo& nativeFontInfo)
101 m_refData = new wxFontRefData(nativeFontInfo);
106 void wxFont::SetEncoding(wxFontEncoding)
110 wxFontEncoding wxFont::GetEncoding() const
112 return wxFontEncoding();
115 int wxFont::GetPointSize() const
117 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
118 return M_FONTDATA->m_info.pointSize;
121 bool wxFont::GetUnderlined() const
124 return M_FONTDATA->m_info.underlined;
129 int wxFont::GetStyle() const
131 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
132 return M_FONTDATA->m_info.style;
135 int wxFont::GetFamily() const
137 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
138 return M_FONTDATA->m_info.family;
141 int wxFont::GetWeight() const
143 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
144 return M_FONTDATA->m_info.weight;
147 const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
149 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
150 return &M_FONTDATA->m_info;
153 bool wxFont::Create(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding)
156 m_refData = new wxFontRefData(pointSize, family, style, weight, underlined, faceName, encoding);
167 bool wxFont::RealizeResource()
169 // TODO: create the font (if there is a native font object)
173 void wxFont::Unshare()
175 // Don't change shared data
178 m_refData = new wxFontRefData();
182 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
188 void wxFont::SetPointSize(int pointSize)
192 M_FONTDATA->m_info.pointSize = pointSize;
197 void wxFont::SetFamily(int family)
201 M_FONTDATA->m_info.family = static_cast<wxFontFamily>(family);
206 void wxFont::SetStyle(int style)
210 M_FONTDATA->m_info.style = static_cast<wxFontStyle>(style);
215 void wxFont::SetWeight(int weight)
219 M_FONTDATA->m_info.weight = static_cast<wxFontWeight>(weight);
224 bool wxFont::SetFaceName(const wxString& faceName)
228 M_FONTDATA->m_info.faceName = faceName;
232 return wxFontBase::SetFaceName(faceName);
235 void wxFont::SetUnderlined(bool underlined)
239 M_FONTDATA->m_info.underlined = underlined;
244 /* New font system */
245 wxString wxFont::GetFaceName() const
249 str = M_FONTDATA->m_info.faceName;