]>
Commit | Line | Data |
---|---|---|
a24aff65 | 1 | ///////////////////////////////////////////////////////////////////////////// |
8898456d | 2 | // Name: src/cocoa/font.cpp |
a24aff65 DE |
3 | // Purpose: wxFont class |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
8898456d | 9 | // Licence: wxWindows licence |
a24aff65 DE |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8898456d WS |
12 | #include "wx/wxprec.h" |
13 | ||
48a1108e WS |
14 | #include "wx/font.h" |
15 | ||
8898456d WS |
16 | #ifndef WX_PRECOMP |
17 | #include "wx/string.h" | |
dd05139a | 18 | #include "wx/gdicmn.h" |
8898456d WS |
19 | #endif |
20 | ||
151b7b73 | 21 | #include "wx/fontutil.h" |
9c6e197f | 22 | #include "wx/encinfo.h" |
a24aff65 | 23 | |
99d21c0e DE |
24 | class WXDLLEXPORT wxFontRefData: public wxGDIRefData |
25 | { | |
26 | friend class WXDLLIMPEXP_FWD_CORE wxFont; | |
27 | public: | |
28 | wxFontRefData() | |
151b7b73 | 29 | : m_fontId(0) |
99d21c0e DE |
30 | { |
31 | Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE, | |
32 | wxT("Geneva"), wxFONTENCODING_DEFAULT); | |
33 | } | |
34 | ||
35 | wxFontRefData(const wxFontRefData& data) | |
151b7b73 DE |
36 | : wxGDIRefData() |
37 | , m_fontId(data.m_fontId) | |
38 | , m_info(data.m_info) | |
99d21c0e | 39 | { |
99d21c0e DE |
40 | } |
41 | ||
05725592 DE |
42 | wxFontRefData(const wxNativeFontInfo& info) |
43 | : wxGDIRefData() | |
44 | , m_fontId(0) | |
45 | , m_info(info) | |
46 | {} | |
47 | ||
99d21c0e DE |
48 | wxFontRefData(int size, |
49 | int family, | |
50 | int style, | |
51 | int weight, | |
52 | bool underlined, | |
53 | const wxString& faceName, | |
54 | wxFontEncoding encoding) | |
151b7b73 | 55 | : m_fontId(0) |
99d21c0e DE |
56 | { |
57 | Init(size, family, style, weight, underlined, faceName, encoding); | |
58 | } | |
59 | ||
60 | virtual ~wxFontRefData(); | |
61 | protected: | |
62 | // common part of all ctors | |
63 | void Init(int size, | |
64 | int family, | |
65 | int style, | |
66 | int weight, | |
67 | bool underlined, | |
68 | const wxString& faceName, | |
69 | wxFontEncoding encoding); | |
70 | ||
71 | // font characterstics | |
72 | int m_fontId; | |
151b7b73 DE |
73 | wxNativeFontInfo m_info; |
74 | ||
99d21c0e DE |
75 | public: |
76 | }; | |
151b7b73 | 77 | |
a24aff65 | 78 | IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) |
a24aff65 DE |
79 | |
80 | void wxFontRefData::Init(int size, int family, int style, int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) | |
81 | { | |
151b7b73 DE |
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; | |
a24aff65 DE |
89 | } |
90 | ||
91 | wxFontRefData::~wxFontRefData() | |
92 | { | |
93 | // TODO: delete font data | |
94 | } | |
95 | ||
68c95704 | 96 | #define M_FONTDATA ((wxFontRefData*)m_refData) |
873fd4af | 97 | |
05725592 | 98 | bool wxFont::Create(const wxNativeFontInfo& nativeFontInfo) |
a24aff65 | 99 | { |
05725592 DE |
100 | UnRef(); |
101 | m_refData = new wxFontRefData(nativeFontInfo); | |
102 | ||
103 | return true; | |
a24aff65 DE |
104 | } |
105 | ||
106 | void wxFont::SetEncoding(wxFontEncoding) | |
107 | { | |
108 | } | |
109 | ||
110 | wxFontEncoding wxFont::GetEncoding() const | |
111 | { | |
112 | return wxFontEncoding(); | |
113 | } | |
114 | ||
115 | int wxFont::GetPointSize() const | |
116 | { | |
05725592 DE |
117 | wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); |
118 | return M_FONTDATA->m_info.pointSize; | |
a24aff65 DE |
119 | } |
120 | ||
121 | bool wxFont::GetUnderlined() const | |
122 | { | |
e7e97a59 | 123 | if(M_FONTDATA) |
151b7b73 | 124 | return M_FONTDATA->m_info.underlined; |
e7e97a59 DE |
125 | else |
126 | return false; | |
a24aff65 DE |
127 | } |
128 | ||
129 | int wxFont::GetStyle() const | |
130 | { | |
05725592 DE |
131 | wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); |
132 | return M_FONTDATA->m_info.style; | |
a24aff65 DE |
133 | } |
134 | ||
135 | int wxFont::GetFamily() const | |
136 | { | |
05725592 DE |
137 | wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); |
138 | return M_FONTDATA->m_info.family; | |
a24aff65 DE |
139 | } |
140 | ||
141 | int wxFont::GetWeight() const | |
142 | { | |
05725592 DE |
143 | wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); |
144 | return M_FONTDATA->m_info.weight; | |
a24aff65 DE |
145 | } |
146 | ||
3bf5a59b VZ |
147 | const wxNativeFontInfo *wxFont::GetNativeFontInfo() const |
148 | { | |
151b7b73 DE |
149 | wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); |
150 | return &M_FONTDATA->m_info; | |
3bf5a59b VZ |
151 | } |
152 | ||
a24aff65 DE |
153 | bool wxFont::Create(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) |
154 | { | |
155 | UnRef(); | |
151b7b73 | 156 | m_refData = new wxFontRefData(pointSize, family, style, weight, underlined, faceName, encoding); |
a24aff65 DE |
157 | |
158 | RealizeResource(); | |
159 | ||
8898456d | 160 | return true; |
a24aff65 DE |
161 | } |
162 | ||
163 | wxFont::~wxFont() | |
164 | { | |
a24aff65 DE |
165 | } |
166 | ||
167 | bool wxFont::RealizeResource() | |
168 | { | |
169 | // TODO: create the font (if there is a native font object) | |
8898456d | 170 | return false; |
a24aff65 DE |
171 | } |
172 | ||
173 | void wxFont::Unshare() | |
174 | { | |
8898456d WS |
175 | // Don't change shared data |
176 | if (!m_refData) | |
a24aff65 | 177 | { |
8898456d WS |
178 | m_refData = new wxFontRefData(); |
179 | } | |
a24aff65 DE |
180 | else |
181 | { | |
8898456d WS |
182 | wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); |
183 | UnRef(); | |
184 | m_refData = ref; | |
185 | } | |
a24aff65 DE |
186 | } |
187 | ||
188 | void wxFont::SetPointSize(int pointSize) | |
189 | { | |
190 | Unshare(); | |
191 | ||
151b7b73 | 192 | M_FONTDATA->m_info.pointSize = pointSize; |
a24aff65 DE |
193 | |
194 | RealizeResource(); | |
195 | } | |
196 | ||
197 | void wxFont::SetFamily(int family) | |
198 | { | |
199 | Unshare(); | |
200 | ||
151b7b73 | 201 | M_FONTDATA->m_info.family = static_cast<wxFontFamily>(family); |
a24aff65 DE |
202 | |
203 | RealizeResource(); | |
204 | } | |
205 | ||
206 | void wxFont::SetStyle(int style) | |
207 | { | |
208 | Unshare(); | |
209 | ||
151b7b73 | 210 | M_FONTDATA->m_info.style = static_cast<wxFontStyle>(style); |
a24aff65 DE |
211 | |
212 | RealizeResource(); | |
213 | } | |
214 | ||
215 | void wxFont::SetWeight(int weight) | |
216 | { | |
217 | Unshare(); | |
218 | ||
151b7b73 | 219 | M_FONTDATA->m_info.weight = static_cast<wxFontWeight>(weight); |
a24aff65 DE |
220 | |
221 | RealizeResource(); | |
222 | } | |
223 | ||
85ab460e | 224 | bool wxFont::SetFaceName(const wxString& faceName) |
a24aff65 DE |
225 | { |
226 | Unshare(); | |
227 | ||
151b7b73 | 228 | M_FONTDATA->m_info.faceName = faceName; |
a24aff65 DE |
229 | |
230 | RealizeResource(); | |
85ab460e VZ |
231 | |
232 | return wxFontBase::SetFaceName(faceName); | |
a24aff65 DE |
233 | } |
234 | ||
235 | void wxFont::SetUnderlined(bool underlined) | |
236 | { | |
237 | Unshare(); | |
238 | ||
151b7b73 | 239 | M_FONTDATA->m_info.underlined = underlined; |
a24aff65 DE |
240 | |
241 | RealizeResource(); | |
242 | } | |
243 | ||
244 | /* New font system */ | |
245 | wxString wxFont::GetFaceName() const | |
246 | { | |
b0c0a393 | 247 | wxString str; |
a24aff65 | 248 | if (M_FONTDATA) |
151b7b73 | 249 | str = M_FONTDATA->m_info.faceName; |
a24aff65 DE |
250 | return str; |
251 | } | |
252 | ||
253 | // vim:sts=4:sw=4:et |