]> git.saurik.com Git - wxWidgets.git/blame - src/mac/font.cpp
Only call use uppercase letter if control, alt, or shift is held down,
[wxWidgets.git] / src / mac / font.cpp
CommitLineData
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 29IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
2f1ae414 30#endif
e9576ca5 31
e7549107
SC
32// ============================================================================
33// implementation
34// ============================================================================
35
36// ----------------------------------------------------------------------------
37// wxFontRefData
38// ----------------------------------------------------------------------------
39
40void 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
64wxFontRefData::~wxFontRefData()
65{
e9576ca5
SC
66}
67
519cb848
SC
68void 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 {
233d603a
SC
106 Str255 fontname ;
107 wxMacStringToPascal( m_faceName , fontname ) ;
108 ::GetFNum( fontname, &m_macFontNum);
519cb848
SC
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 ;
66a09d47
SC
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);
5a981902
SC
125 /*
126 status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
127 kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
128 */
66a09d47 129 wxASSERT_MSG( status == noErr , "couldn't retrieve font identifier" ) ;
519cb848
SC
130}
131
e7549107
SC
132// ----------------------------------------------------------------------------
133// wxFont
134// ----------------------------------------------------------------------------
e9576ca5 135
e7549107 136void wxFont::Init()
e9576ca5 137{
e9576ca5
SC
138}
139
5b781a67
SC
140bool 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
3b7e6277
GD
146wxFont::wxFont(const wxString& fontdesc)
147{
148 wxNativeFontInfo info;
149 if ( info.FromString(fontdesc) )
150 (void)Create(info);
151}
152
e7549107
SC
153bool wxFont::Create(int pointSize,
154 int family,
155 int style,
156 int weight,
157 bool underlined,
158 const wxString& faceName,
159 wxFontEncoding encoding)
e9576ca5
SC
160{
161 UnRef();
e7549107
SC
162 m_refData = new wxFontRefData(pointSize, family, style, weight,
163 underlined, faceName, encoding);
e9576ca5
SC
164
165 RealizeResource();
166
167 return TRUE;
168}
169
170wxFont::~wxFont()
171{
e9576ca5
SC
172}
173
174bool wxFont::RealizeResource()
175{
519cb848
SC
176 M_FONTDATA->MacFindFont() ;
177 return TRUE;
e9576ca5
SC
178}
179
51abe921
SC
180void wxFont::SetEncoding(wxFontEncoding encoding)
181{
182 Unshare();
183
184 M_FONTDATA->m_encoding = encoding;
185
186 RealizeResource();
187}
188
e9576ca5
SC
189void 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
204void wxFont::SetPointSize(int pointSize)
205{
206 Unshare();
207
208 M_FONTDATA->m_pointSize = pointSize;
209
210 RealizeResource();
211}
212
213void wxFont::SetFamily(int family)
214{
215 Unshare();
216
217 M_FONTDATA->m_family = family;
218
219 RealizeResource();
220}
221
222void wxFont::SetStyle(int style)
223{
224 Unshare();
225
226 M_FONTDATA->m_style = style;
227
228 RealizeResource();
229}
230
231void wxFont::SetWeight(int weight)
232{
233 Unshare();
234
235 M_FONTDATA->m_weight = weight;
236
237 RealizeResource();
238}
239
240void wxFont::SetFaceName(const wxString& faceName)
241{
242 Unshare();
243
244 M_FONTDATA->m_faceName = faceName;
245
246 RealizeResource();
247}
248
249void wxFont::SetUnderlined(bool underlined)
250{
251 Unshare();
252
253 M_FONTDATA->m_underlined = underlined;
254
255 RealizeResource();
256}
257
ac17f9b1
SC
258void wxFont::SetNoAntiAliasing( bool no )
259{
260 Unshare();
261
262 M_FONTDATA->SetNoAntiAliasing( no );
263
264 RealizeResource();
265}
266
e7549107
SC
267// ----------------------------------------------------------------------------
268// accessors
269// ----------------------------------------------------------------------------
270
271int wxFont::GetPointSize() const
e9576ca5 272{
e7549107 273 return M_FONTDATA->m_pointSize;
e9576ca5
SC
274}
275
e7549107 276int wxFont::GetFamily() const
e9576ca5 277{
e7549107 278 return M_FONTDATA->m_family;
e9576ca5
SC
279}
280
e7549107 281int wxFont::GetStyle() const
e9576ca5 282{
e7549107
SC
283 return M_FONTDATA->m_style;
284}
285
286int wxFont::GetWeight() const
287{
288 return M_FONTDATA->m_weight;
289}
290
291bool wxFont::GetUnderlined() const
292{
293 return M_FONTDATA->m_underlined;
294}
295
296wxString wxFont::GetFaceName() const
297{
298 wxString str;
299 if ( M_FONTDATA )
300 str = M_FONTDATA->m_faceName ;
301 return str;
302}
303
304wxFontEncoding wxFont::GetEncoding() const
305{
306 return M_FONTDATA->m_encoding;
e9576ca5
SC
307}
308
ac17f9b1
SC
309bool wxFont::GetNoAntiAliasing()
310{
311 return M_FONTDATA->m_noAA;
312}
313