]> git.saurik.com Git - wxWidgets.git/blob - src/mac/font.cpp
Only call use uppercase letter if control, alt, or shift is held down,
[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 Str255 fontname ;
107 wxMacStringToPascal( m_faceName , fontname ) ;
108 ::GetFNum( fontname, &m_macFontNum);
109 }
110 }
111
112 m_macFontStyle = 0;
113 if (m_weight == wxBOLD)
114 m_macFontStyle |= bold;
115 if (m_style == wxITALIC || m_style == wxSLANT)
116 m_macFontStyle |= italic;
117 if (m_underlined)
118 m_macFontStyle |= underline;
119 m_macFontSize = m_pointSize ;
120
121 //TODO:if we supply the style as an additional parameter we must make a testing
122 //sequence in order to degrade gracefully while trying to maintain most of the style
123 //information, meanwhile we just take the normal font and apply the features after
124 OSStatus status = ::ATSUFONDtoFontID(m_macFontNum, normal /*qdStyle*/, (UInt32*)&m_macATSUFontID);
125 /*
126 status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
127 kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
128 */
129 wxASSERT_MSG( status == noErr , "couldn't retrieve font identifier" ) ;
130 }
131
132 // ----------------------------------------------------------------------------
133 // wxFont
134 // ----------------------------------------------------------------------------
135
136 void wxFont::Init()
137 {
138 }
139
140 bool wxFont::Create(const wxNativeFontInfo& info)
141 {
142 return Create(info.pointSize, info.family, info.style, info.weight,
143 info.underlined, info.faceName, info.encoding);
144 }
145
146 wxFont::wxFont(const wxString& fontdesc)
147 {
148 wxNativeFontInfo info;
149 if ( info.FromString(fontdesc) )
150 (void)Create(info);
151 }
152
153 bool wxFont::Create(int pointSize,
154 int family,
155 int style,
156 int weight,
157 bool underlined,
158 const wxString& faceName,
159 wxFontEncoding encoding)
160 {
161 UnRef();
162 m_refData = new wxFontRefData(pointSize, family, style, weight,
163 underlined, faceName, encoding);
164
165 RealizeResource();
166
167 return TRUE;
168 }
169
170 wxFont::~wxFont()
171 {
172 }
173
174 bool wxFont::RealizeResource()
175 {
176 M_FONTDATA->MacFindFont() ;
177 return TRUE;
178 }
179
180 void wxFont::SetEncoding(wxFontEncoding encoding)
181 {
182 Unshare();
183
184 M_FONTDATA->m_encoding = encoding;
185
186 RealizeResource();
187 }
188
189 void wxFont::Unshare()
190 {
191 // Don't change shared data
192 if (!m_refData)
193 {
194 m_refData = new wxFontRefData();
195 }
196 else
197 {
198 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
199 UnRef();
200 m_refData = ref;
201 }
202 }
203
204 void wxFont::SetPointSize(int pointSize)
205 {
206 Unshare();
207
208 M_FONTDATA->m_pointSize = pointSize;
209
210 RealizeResource();
211 }
212
213 void wxFont::SetFamily(int family)
214 {
215 Unshare();
216
217 M_FONTDATA->m_family = family;
218
219 RealizeResource();
220 }
221
222 void wxFont::SetStyle(int style)
223 {
224 Unshare();
225
226 M_FONTDATA->m_style = style;
227
228 RealizeResource();
229 }
230
231 void wxFont::SetWeight(int weight)
232 {
233 Unshare();
234
235 M_FONTDATA->m_weight = weight;
236
237 RealizeResource();
238 }
239
240 void wxFont::SetFaceName(const wxString& faceName)
241 {
242 Unshare();
243
244 M_FONTDATA->m_faceName = faceName;
245
246 RealizeResource();
247 }
248
249 void wxFont::SetUnderlined(bool underlined)
250 {
251 Unshare();
252
253 M_FONTDATA->m_underlined = underlined;
254
255 RealizeResource();
256 }
257
258 void wxFont::SetNoAntiAliasing( bool no )
259 {
260 Unshare();
261
262 M_FONTDATA->SetNoAntiAliasing( no );
263
264 RealizeResource();
265 }
266
267 // ----------------------------------------------------------------------------
268 // accessors
269 // ----------------------------------------------------------------------------
270
271 int wxFont::GetPointSize() const
272 {
273 return M_FONTDATA->m_pointSize;
274 }
275
276 int wxFont::GetFamily() const
277 {
278 return M_FONTDATA->m_family;
279 }
280
281 int wxFont::GetStyle() const
282 {
283 return M_FONTDATA->m_style;
284 }
285
286 int wxFont::GetWeight() const
287 {
288 return M_FONTDATA->m_weight;
289 }
290
291 bool wxFont::GetUnderlined() const
292 {
293 return M_FONTDATA->m_underlined;
294 }
295
296 wxString wxFont::GetFaceName() const
297 {
298 wxString str;
299 if ( M_FONTDATA )
300 str = M_FONTDATA->m_faceName ;
301 return str;
302 }
303
304 wxFontEncoding wxFont::GetEncoding() const
305 {
306 return M_FONTDATA->m_encoding;
307 }
308
309 bool wxFont::GetNoAntiAliasing()
310 {
311 return M_FONTDATA->m_noAA;
312 }
313