]>
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 | 25 | #include "wx/mac/private.h" |
66a09d47 | 26 | #include "ATSUnicode.h" |
76a5e5d2 | 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 | ||
d84afea9 GD |
57 | m_macFontNum = 0 ; |
58 | m_macFontSize = 0; | |
59 | m_macFontStyle = 0; | |
e7549107 | 60 | m_fontId = 0; |
ac17f9b1 | 61 | m_noAA = FALSE; |
e9576ca5 SC |
62 | } |
63 | ||
64 | wxFontRefData::~wxFontRefData() | |
65 | { | |
e9576ca5 SC |
66 | } |
67 | ||
519cb848 SC |
68 | void wxFontRefData::MacFindFont() |
69 | { | |
70 | if( m_faceName == "" ) | |
71 | { | |
72 | switch( m_family ) | |
73 | { | |
74 | case wxDEFAULT : | |
75 | m_macFontNum = ::GetAppFont() ; | |
76 | break ; | |
77 | case wxDECORATIVE : | |
78 | ::GetFNum( "\pTimes" , &m_macFontNum) ; | |
79 | break ; | |
80 | case wxROMAN : | |
81 | ::GetFNum( "\pTimes" , &m_macFontNum) ; | |
82 | break ; | |
83 | case wxSCRIPT : | |
84 | ::GetFNum( "\pTimes" , &m_macFontNum) ; | |
85 | break ; | |
86 | case wxSWISS : | |
2f1ae414 | 87 | ::GetFNum( "\pGeneva" , &m_macFontNum) ; |
519cb848 SC |
88 | break ; |
89 | case wxMODERN : | |
90 | ::GetFNum( "\pMonaco" , &m_macFontNum) ; | |
91 | break ; | |
92 | } | |
2b5f62a0 VZ |
93 | Str255 name ; |
94 | GetFontName( m_macFontNum , name ) ; | |
95 | CopyPascalStringToC( name , (char*) name ) ; | |
96 | m_faceName = (char*) name ; | |
519cb848 SC |
97 | } |
98 | else | |
99 | { | |
100 | if ( m_faceName == "systemfont" ) | |
101 | m_macFontNum = ::GetSysFont() ; | |
102 | else if ( m_faceName == "applicationfont" ) | |
103 | m_macFontNum = ::GetAppFont() ; | |
104 | else | |
105 | { | |
03e11df5 GD |
106 | #if TARGET_CARBON |
107 | c2pstrcpy( (StringPtr) wxBuffer, m_faceName ) ; | |
108 | #else | |
109 | strcpy( (char *) wxBuffer, m_faceName ) ; | |
110 | c2pstr( (char *) wxBuffer ) ; | |
111 | #endif | |
112 | ::GetFNum( (StringPtr) wxBuffer, &m_macFontNum); | |
519cb848 SC |
113 | } |
114 | } | |
115 | ||
116 | m_macFontStyle = 0; | |
117 | if (m_weight == wxBOLD) | |
118 | m_macFontStyle |= bold; | |
119 | if (m_style == wxITALIC || m_style == wxSLANT) | |
120 | m_macFontStyle |= italic; | |
121 | if (m_underlined) | |
122 | m_macFontStyle |= underline; | |
123 | m_macFontSize = m_pointSize ; | |
66a09d47 SC |
124 | |
125 | //TODO:if we supply the style as an additional parameter we must make a testing | |
126 | //sequence in order to degrade gracefully while trying to maintain most of the style | |
127 | //information, meanwhile we just take the normal font and apply the features after | |
128 | OSStatus status = ::ATSUFONDtoFontID(m_macFontNum, normal /*qdStyle*/, (UInt32*)&m_macATSUFontID); | |
5a981902 SC |
129 | /* |
130 | status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) , | |
131 | kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ; | |
132 | */ | |
66a09d47 | 133 | wxASSERT_MSG( status == noErr , "couldn't retrieve font identifier" ) ; |
519cb848 SC |
134 | } |
135 | ||
e7549107 SC |
136 | // ---------------------------------------------------------------------------- |
137 | // wxFont | |
138 | // ---------------------------------------------------------------------------- | |
e9576ca5 | 139 | |
e7549107 | 140 | void wxFont::Init() |
e9576ca5 | 141 | { |
e9576ca5 SC |
142 | } |
143 | ||
5b781a67 SC |
144 | bool wxFont::Create(const wxNativeFontInfo& info) |
145 | { | |
146 | return Create(info.pointSize, info.family, info.style, info.weight, | |
147 | info.underlined, info.faceName, info.encoding); | |
148 | } | |
149 | ||
3b7e6277 GD |
150 | wxFont::wxFont(const wxString& fontdesc) |
151 | { | |
152 | wxNativeFontInfo info; | |
153 | if ( info.FromString(fontdesc) ) | |
154 | (void)Create(info); | |
155 | } | |
156 | ||
e7549107 SC |
157 | bool wxFont::Create(int pointSize, |
158 | int family, | |
159 | int style, | |
160 | int weight, | |
161 | bool underlined, | |
162 | const wxString& faceName, | |
163 | wxFontEncoding encoding) | |
e9576ca5 SC |
164 | { |
165 | UnRef(); | |
e7549107 SC |
166 | m_refData = new wxFontRefData(pointSize, family, style, weight, |
167 | underlined, faceName, encoding); | |
e9576ca5 SC |
168 | |
169 | RealizeResource(); | |
170 | ||
171 | return TRUE; | |
172 | } | |
173 | ||
174 | wxFont::~wxFont() | |
175 | { | |
e9576ca5 SC |
176 | } |
177 | ||
178 | bool wxFont::RealizeResource() | |
179 | { | |
519cb848 SC |
180 | M_FONTDATA->MacFindFont() ; |
181 | return TRUE; | |
e9576ca5 SC |
182 | } |
183 | ||
51abe921 SC |
184 | void wxFont::SetEncoding(wxFontEncoding encoding) |
185 | { | |
186 | Unshare(); | |
187 | ||
188 | M_FONTDATA->m_encoding = encoding; | |
189 | ||
190 | RealizeResource(); | |
191 | } | |
192 | ||
e9576ca5 SC |
193 | void wxFont::Unshare() |
194 | { | |
195 | // Don't change shared data | |
196 | if (!m_refData) | |
197 | { | |
198 | m_refData = new wxFontRefData(); | |
199 | } | |
200 | else | |
201 | { | |
202 | wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); | |
203 | UnRef(); | |
204 | m_refData = ref; | |
205 | } | |
206 | } | |
207 | ||
208 | void wxFont::SetPointSize(int pointSize) | |
209 | { | |
210 | Unshare(); | |
211 | ||
212 | M_FONTDATA->m_pointSize = pointSize; | |
213 | ||
214 | RealizeResource(); | |
215 | } | |
216 | ||
217 | void wxFont::SetFamily(int family) | |
218 | { | |
219 | Unshare(); | |
220 | ||
221 | M_FONTDATA->m_family = family; | |
222 | ||
223 | RealizeResource(); | |
224 | } | |
225 | ||
226 | void wxFont::SetStyle(int style) | |
227 | { | |
228 | Unshare(); | |
229 | ||
230 | M_FONTDATA->m_style = style; | |
231 | ||
232 | RealizeResource(); | |
233 | } | |
234 | ||
235 | void wxFont::SetWeight(int weight) | |
236 | { | |
237 | Unshare(); | |
238 | ||
239 | M_FONTDATA->m_weight = weight; | |
240 | ||
241 | RealizeResource(); | |
242 | } | |
243 | ||
244 | void wxFont::SetFaceName(const wxString& faceName) | |
245 | { | |
246 | Unshare(); | |
247 | ||
248 | M_FONTDATA->m_faceName = faceName; | |
249 | ||
250 | RealizeResource(); | |
251 | } | |
252 | ||
253 | void wxFont::SetUnderlined(bool underlined) | |
254 | { | |
255 | Unshare(); | |
256 | ||
257 | M_FONTDATA->m_underlined = underlined; | |
258 | ||
259 | RealizeResource(); | |
260 | } | |
261 | ||
ac17f9b1 SC |
262 | void wxFont::SetNoAntiAliasing( bool no ) |
263 | { | |
264 | Unshare(); | |
265 | ||
266 | M_FONTDATA->SetNoAntiAliasing( no ); | |
267 | ||
268 | RealizeResource(); | |
269 | } | |
270 | ||
e7549107 SC |
271 | // ---------------------------------------------------------------------------- |
272 | // accessors | |
273 | // ---------------------------------------------------------------------------- | |
274 | ||
275 | int wxFont::GetPointSize() const | |
e9576ca5 | 276 | { |
e7549107 | 277 | return M_FONTDATA->m_pointSize; |
e9576ca5 SC |
278 | } |
279 | ||
e7549107 | 280 | int wxFont::GetFamily() const |
e9576ca5 | 281 | { |
e7549107 | 282 | return M_FONTDATA->m_family; |
e9576ca5 SC |
283 | } |
284 | ||
e7549107 | 285 | int wxFont::GetStyle() const |
e9576ca5 | 286 | { |
e7549107 SC |
287 | return M_FONTDATA->m_style; |
288 | } | |
289 | ||
290 | int wxFont::GetWeight() const | |
291 | { | |
292 | return M_FONTDATA->m_weight; | |
293 | } | |
294 | ||
295 | bool wxFont::GetUnderlined() const | |
296 | { | |
297 | return M_FONTDATA->m_underlined; | |
298 | } | |
299 | ||
300 | wxString wxFont::GetFaceName() const | |
301 | { | |
302 | wxString str; | |
303 | if ( M_FONTDATA ) | |
304 | str = M_FONTDATA->m_faceName ; | |
305 | return str; | |
306 | } | |
307 | ||
308 | wxFontEncoding wxFont::GetEncoding() const | |
309 | { | |
310 | return M_FONTDATA->m_encoding; | |
e9576ca5 SC |
311 | } |
312 | ||
ac17f9b1 SC |
313 | bool wxFont::GetNoAntiAliasing() |
314 | { | |
315 | return M_FONTDATA->m_noAA; | |
316 | } | |
317 |