]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: font.cpp | |
3 | // Purpose: wxFont class | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "font.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/defs.h" | |
17 | #include "wx/string.h" | |
18 | #include "wx/font.h" | |
5b781a67 | 19 | #include "wx/fontutil.h" |
e9576ca5 | 20 | #include "wx/gdicmn.h" |
03e11df5 | 21 | #include "wx/utils.h" |
e9576ca5 | 22 | |
3b7e6277 GD |
23 | #include "wx/fontutil.h" |
24 | ||
76a5e5d2 SC |
25 | #include "wx/mac/private.h" |
26 | ||
27 | ||
2f1ae414 | 28 | #if !USE_SHARED_LIBRARIES |
e9576ca5 | 29 | IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) |
2f1ae414 | 30 | #endif |
e9576ca5 | 31 | |
e7549107 SC |
32 | // ============================================================================ |
33 | // implementation | |
34 | // ============================================================================ | |
35 | ||
36 | // ---------------------------------------------------------------------------- | |
37 | // wxFontRefData | |
38 | // ---------------------------------------------------------------------------- | |
39 | ||
40 | void wxFontRefData::Init(int pointSize, | |
41 | int family, | |
42 | int style, | |
43 | int weight, | |
44 | bool underlined, | |
45 | const wxString& faceName, | |
46 | wxFontEncoding encoding) | |
e9576ca5 | 47 | { |
e7549107 SC |
48 | m_style = style; |
49 | m_pointSize = pointSize; | |
50 | m_family = family; | |
51 | m_style = style; | |
52 | m_weight = weight; | |
53 | m_underlined = underlined; | |
54 | m_faceName = faceName; | |
55 | m_encoding = encoding; | |
56 | ||
57 | m_macFontNum = 0 ; | |
58 | m_macFontSize = 0; | |
59 | m_macFontStyle = 0; | |
60 | m_fontId = 0; | |
e9576ca5 SC |
61 | } |
62 | ||
63 | wxFontRefData::~wxFontRefData() | |
64 | { | |
e9576ca5 SC |
65 | } |
66 | ||
519cb848 SC |
67 | void wxFontRefData::MacFindFont() |
68 | { | |
69 | if( m_faceName == "" ) | |
70 | { | |
71 | switch( m_family ) | |
72 | { | |
73 | case wxDEFAULT : | |
74 | m_macFontNum = ::GetAppFont() ; | |
75 | break ; | |
76 | case wxDECORATIVE : | |
77 | ::GetFNum( "\pTimes" , &m_macFontNum) ; | |
78 | break ; | |
79 | case wxROMAN : | |
80 | ::GetFNum( "\pTimes" , &m_macFontNum) ; | |
81 | break ; | |
82 | case wxSCRIPT : | |
83 | ::GetFNum( "\pTimes" , &m_macFontNum) ; | |
84 | break ; | |
85 | case wxSWISS : | |
2f1ae414 | 86 | ::GetFNum( "\pGeneva" , &m_macFontNum) ; |
519cb848 SC |
87 | break ; |
88 | case wxMODERN : | |
89 | ::GetFNum( "\pMonaco" , &m_macFontNum) ; | |
90 | break ; | |
91 | } | |
92 | } | |
93 | else | |
94 | { | |
95 | if ( m_faceName == "systemfont" ) | |
96 | m_macFontNum = ::GetSysFont() ; | |
97 | else if ( m_faceName == "applicationfont" ) | |
98 | m_macFontNum = ::GetAppFont() ; | |
99 | else | |
100 | { | |
03e11df5 GD |
101 | #if TARGET_CARBON |
102 | c2pstrcpy( (StringPtr) wxBuffer, m_faceName ) ; | |
103 | #else | |
104 | strcpy( (char *) wxBuffer, m_faceName ) ; | |
105 | c2pstr( (char *) wxBuffer ) ; | |
106 | #endif | |
107 | ::GetFNum( (StringPtr) wxBuffer, &m_macFontNum); | |
519cb848 SC |
108 | } |
109 | } | |
110 | ||
111 | m_macFontStyle = 0; | |
112 | if (m_weight == wxBOLD) | |
113 | m_macFontStyle |= bold; | |
114 | if (m_style == wxITALIC || m_style == wxSLANT) | |
115 | m_macFontStyle |= italic; | |
116 | if (m_underlined) | |
117 | m_macFontStyle |= underline; | |
118 | m_macFontSize = m_pointSize ; | |
119 | } | |
120 | ||
e7549107 SC |
121 | // ---------------------------------------------------------------------------- |
122 | // wxFont | |
123 | // ---------------------------------------------------------------------------- | |
e9576ca5 | 124 | |
e7549107 | 125 | void wxFont::Init() |
e9576ca5 | 126 | { |
e9576ca5 SC |
127 | } |
128 | ||
5b781a67 SC |
129 | bool wxFont::Create(const wxNativeFontInfo& info) |
130 | { | |
131 | return Create(info.pointSize, info.family, info.style, info.weight, | |
132 | info.underlined, info.faceName, info.encoding); | |
133 | } | |
134 | ||
3b7e6277 GD |
135 | wxFont::wxFont(const wxString& fontdesc) |
136 | { | |
137 | wxNativeFontInfo info; | |
138 | if ( info.FromString(fontdesc) ) | |
139 | (void)Create(info); | |
140 | } | |
141 | ||
e7549107 SC |
142 | bool wxFont::Create(int pointSize, |
143 | int family, | |
144 | int style, | |
145 | int weight, | |
146 | bool underlined, | |
147 | const wxString& faceName, | |
148 | wxFontEncoding encoding) | |
e9576ca5 SC |
149 | { |
150 | UnRef(); | |
e7549107 SC |
151 | m_refData = new wxFontRefData(pointSize, family, style, weight, |
152 | underlined, faceName, encoding); | |
e9576ca5 SC |
153 | |
154 | RealizeResource(); | |
155 | ||
156 | return TRUE; | |
157 | } | |
158 | ||
159 | wxFont::~wxFont() | |
160 | { | |
e9576ca5 SC |
161 | } |
162 | ||
163 | bool wxFont::RealizeResource() | |
164 | { | |
519cb848 SC |
165 | M_FONTDATA->MacFindFont() ; |
166 | return TRUE; | |
e9576ca5 SC |
167 | } |
168 | ||
51abe921 SC |
169 | void wxFont::SetEncoding(wxFontEncoding encoding) |
170 | { | |
171 | Unshare(); | |
172 | ||
173 | M_FONTDATA->m_encoding = encoding; | |
174 | ||
175 | RealizeResource(); | |
176 | } | |
177 | ||
e9576ca5 SC |
178 | void wxFont::Unshare() |
179 | { | |
180 | // Don't change shared data | |
181 | if (!m_refData) | |
182 | { | |
183 | m_refData = new wxFontRefData(); | |
184 | } | |
185 | else | |
186 | { | |
187 | wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); | |
188 | UnRef(); | |
189 | m_refData = ref; | |
190 | } | |
191 | } | |
192 | ||
193 | void wxFont::SetPointSize(int pointSize) | |
194 | { | |
195 | Unshare(); | |
196 | ||
197 | M_FONTDATA->m_pointSize = pointSize; | |
198 | ||
199 | RealizeResource(); | |
200 | } | |
201 | ||
202 | void wxFont::SetFamily(int family) | |
203 | { | |
204 | Unshare(); | |
205 | ||
206 | M_FONTDATA->m_family = family; | |
207 | ||
208 | RealizeResource(); | |
209 | } | |
210 | ||
211 | void wxFont::SetStyle(int style) | |
212 | { | |
213 | Unshare(); | |
214 | ||
215 | M_FONTDATA->m_style = style; | |
216 | ||
217 | RealizeResource(); | |
218 | } | |
219 | ||
220 | void wxFont::SetWeight(int weight) | |
221 | { | |
222 | Unshare(); | |
223 | ||
224 | M_FONTDATA->m_weight = weight; | |
225 | ||
226 | RealizeResource(); | |
227 | } | |
228 | ||
229 | void wxFont::SetFaceName(const wxString& faceName) | |
230 | { | |
231 | Unshare(); | |
232 | ||
233 | M_FONTDATA->m_faceName = faceName; | |
234 | ||
235 | RealizeResource(); | |
236 | } | |
237 | ||
238 | void wxFont::SetUnderlined(bool underlined) | |
239 | { | |
240 | Unshare(); | |
241 | ||
242 | M_FONTDATA->m_underlined = underlined; | |
243 | ||
244 | RealizeResource(); | |
245 | } | |
246 | ||
e7549107 SC |
247 | // ---------------------------------------------------------------------------- |
248 | // accessors | |
249 | // ---------------------------------------------------------------------------- | |
250 | ||
251 | int wxFont::GetPointSize() const | |
e9576ca5 | 252 | { |
e7549107 | 253 | return M_FONTDATA->m_pointSize; |
e9576ca5 SC |
254 | } |
255 | ||
e7549107 | 256 | int wxFont::GetFamily() const |
e9576ca5 | 257 | { |
e7549107 | 258 | return M_FONTDATA->m_family; |
e9576ca5 SC |
259 | } |
260 | ||
e7549107 | 261 | int wxFont::GetStyle() const |
e9576ca5 | 262 | { |
e7549107 SC |
263 | return M_FONTDATA->m_style; |
264 | } | |
265 | ||
266 | int wxFont::GetWeight() const | |
267 | { | |
268 | return M_FONTDATA->m_weight; | |
269 | } | |
270 | ||
271 | bool wxFont::GetUnderlined() const | |
272 | { | |
273 | return M_FONTDATA->m_underlined; | |
274 | } | |
275 | ||
276 | wxString wxFont::GetFaceName() const | |
277 | { | |
278 | wxString str; | |
279 | if ( M_FONTDATA ) | |
280 | str = M_FONTDATA->m_faceName ; | |
281 | return str; | |
282 | } | |
283 | ||
284 | wxFontEncoding wxFont::GetEncoding() const | |
285 | { | |
286 | return M_FONTDATA->m_encoding; | |
e9576ca5 SC |
287 | } |
288 |