]> git.saurik.com Git - wxWidgets.git/blob - src/mac/font.cpp
Removed spurious character
[wxWidgets.git] / src / mac / font.cpp
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"
19 #include "wx/fontutil.h"
20 #include "wx/gdicmn.h"
21 #include "wx/utils.h"
22
23 #include "wx/fontutil.h"
24
25 #include "wx/mac/private.h"
26 #include "ATSUnicode.h"
27
28 #if !USE_SHARED_LIBRARIES
29 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
30 #endif
31
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)
47 {
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;
61 m_noAA = FALSE;
62 }
63
64 wxFontRefData::~wxFontRefData()
65 {
66 }
67
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 :
87 ::GetFNum( "\pGeneva" , &m_macFontNum) ;
88 break ;
89 case wxMODERN :
90 ::GetFNum( "\pMonaco" , &m_macFontNum) ;
91 break ;
92 }
93 Str255 name ;
94 GetFontName( m_macFontNum , name ) ;
95 CopyPascalStringToC( name , (char*) name ) ;
96 m_faceName = (char*) name ;
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 {
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);
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 ;
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);
129 /*
130 status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
131 kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
132 */
133 wxASSERT_MSG( status == noErr , "couldn't retrieve font identifier" ) ;
134 }
135
136 // ----------------------------------------------------------------------------
137 // wxFont
138 // ----------------------------------------------------------------------------
139
140 void wxFont::Init()
141 {
142 }
143
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
150 wxFont::wxFont(const wxString& fontdesc)
151 {
152 wxNativeFontInfo info;
153 if ( info.FromString(fontdesc) )
154 (void)Create(info);
155 }
156
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)
164 {
165 UnRef();
166 m_refData = new wxFontRefData(pointSize, family, style, weight,
167 underlined, faceName, encoding);
168
169 RealizeResource();
170
171 return TRUE;
172 }
173
174 wxFont::~wxFont()
175 {
176 }
177
178 bool wxFont::RealizeResource()
179 {
180 M_FONTDATA->MacFindFont() ;
181 return TRUE;
182 }
183
184 void wxFont::SetEncoding(wxFontEncoding encoding)
185 {
186 Unshare();
187
188 M_FONTDATA->m_encoding = encoding;
189
190 RealizeResource();
191 }
192
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
262 void wxFont::SetNoAntiAliasing( bool no )
263 {
264 Unshare();
265
266 M_FONTDATA->SetNoAntiAliasing( no );
267
268 RealizeResource();
269 }
270
271 // ----------------------------------------------------------------------------
272 // accessors
273 // ----------------------------------------------------------------------------
274
275 int wxFont::GetPointSize() const
276 {
277 return M_FONTDATA->m_pointSize;
278 }
279
280 int wxFont::GetFamily() const
281 {
282 return M_FONTDATA->m_family;
283 }
284
285 int wxFont::GetStyle() const
286 {
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;
311 }
312
313 bool wxFont::GetNoAntiAliasing()
314 {
315 return M_FONTDATA->m_noAA;
316 }
317