]> git.saurik.com Git - wxWidgets.git/blame - src/mac/font.cpp
Applied patch [ 735304 ] wxDisplay::ChangeMode - does not resize full-screen windows
[wxWidgets.git] / src / mac / font.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: font.cpp
3// Purpose: wxFont class
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
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{
427ff662 70 if( m_faceName.Length() == 0 )
e40298d5
JS
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 ) ;
427ff662 95 m_faceName = wxMacMakeStringFromPascal( name ) ;
e40298d5
JS
96 }
97 else
98 {
427ff662 99 if ( m_faceName == wxT("systemfont") )
e40298d5 100 m_macFontNum = ::GetSysFont() ;
427ff662 101 else if ( m_faceName == wxT("applicationfont") )
e40298d5
JS
102 m_macFontNum = ::GetAppFont() ;
103 else
104 {
105 Str255 fontname ;
106 wxMacStringToPascal( m_faceName , fontname ) ;
107 ::GetFNum( fontname, &m_macFontNum);
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 //TODO:if we supply the style as an additional parameter we must make a testing
121 //sequence in order to degrade gracefully while trying to maintain most of the style
122 //information, meanwhile we just take the normal font and apply the features after
123 OSStatus status = ::ATSUFONDtoFontID(m_macFontNum, normal /*qdStyle*/, (UInt32*)&m_macATSUFontID);
5a981902
SC
124 /*
125 status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
e40298d5 126 kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
5a981902 127 */
427ff662 128 wxASSERT_MSG( status == noErr , wxT("couldn't retrieve font identifier") ) ;
519cb848
SC
129}
130
e7549107
SC
131// ----------------------------------------------------------------------------
132// wxFont
133// ----------------------------------------------------------------------------
e9576ca5 134
e7549107 135void wxFont::Init()
e9576ca5 136{
e9576ca5
SC
137}
138
5b781a67
SC
139bool wxFont::Create(const wxNativeFontInfo& info)
140{
141 return Create(info.pointSize, info.family, info.style, info.weight,
142 info.underlined, info.faceName, info.encoding);
143}
144
3b7e6277
GD
145wxFont::wxFont(const wxString& fontdesc)
146{
147 wxNativeFontInfo info;
148 if ( info.FromString(fontdesc) )
149 (void)Create(info);
150}
151
e7549107
SC
152bool wxFont::Create(int pointSize,
153 int family,
154 int style,
155 int weight,
156 bool underlined,
157 const wxString& faceName,
158 wxFontEncoding encoding)
e9576ca5
SC
159{
160 UnRef();
e7549107
SC
161 m_refData = new wxFontRefData(pointSize, family, style, weight,
162 underlined, faceName, encoding);
e9576ca5
SC
163
164 RealizeResource();
165
166 return TRUE;
167}
168
169wxFont::~wxFont()
170{
e9576ca5
SC
171}
172
173bool wxFont::RealizeResource()
174{
e40298d5 175 M_FONTDATA->MacFindFont() ;
519cb848 176 return TRUE;
e9576ca5
SC
177}
178
51abe921
SC
179void wxFont::SetEncoding(wxFontEncoding encoding)
180{
181 Unshare();
182
183 M_FONTDATA->m_encoding = encoding;
184
185 RealizeResource();
186}
187
e9576ca5
SC
188void wxFont::Unshare()
189{
e40298d5
JS
190 // Don't change shared data
191 if (!m_refData)
e9576ca5 192 {
e40298d5
JS
193 m_refData = new wxFontRefData();
194 }
e9576ca5
SC
195 else
196 {
e40298d5
JS
197 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
198 UnRef();
199 m_refData = ref;
200 }
e9576ca5
SC
201}
202
203void wxFont::SetPointSize(int pointSize)
204{
205 Unshare();
206
207 M_FONTDATA->m_pointSize = pointSize;
208
209 RealizeResource();
210}
211
212void wxFont::SetFamily(int family)
213{
214 Unshare();
215
216 M_FONTDATA->m_family = family;
217
218 RealizeResource();
219}
220
221void wxFont::SetStyle(int style)
222{
223 Unshare();
224
225 M_FONTDATA->m_style = style;
226
227 RealizeResource();
228}
229
230void wxFont::SetWeight(int weight)
231{
232 Unshare();
233
234 M_FONTDATA->m_weight = weight;
235
236 RealizeResource();
237}
238
239void wxFont::SetFaceName(const wxString& faceName)
240{
241 Unshare();
242
243 M_FONTDATA->m_faceName = faceName;
244
245 RealizeResource();
246}
247
248void wxFont::SetUnderlined(bool underlined)
249{
250 Unshare();
251
252 M_FONTDATA->m_underlined = underlined;
253
254 RealizeResource();
255}
256
ac17f9b1
SC
257void wxFont::SetNoAntiAliasing( bool no )
258{
259 Unshare();
260
261 M_FONTDATA->SetNoAntiAliasing( no );
262
263 RealizeResource();
264}
265
e7549107
SC
266// ----------------------------------------------------------------------------
267// accessors
268// ----------------------------------------------------------------------------
269
270int wxFont::GetPointSize() const
e9576ca5 271{
e7549107 272 return M_FONTDATA->m_pointSize;
e9576ca5
SC
273}
274
e7549107 275int wxFont::GetFamily() const
e9576ca5 276{
e7549107 277 return M_FONTDATA->m_family;
e9576ca5
SC
278}
279
e7549107 280int wxFont::GetStyle() const
e9576ca5 281{
e7549107
SC
282 return M_FONTDATA->m_style;
283}
284
285int wxFont::GetWeight() const
286{
287 return M_FONTDATA->m_weight;
288}
289
290bool wxFont::GetUnderlined() const
291{
292 return M_FONTDATA->m_underlined;
293}
294
295wxString wxFont::GetFaceName() const
296{
297 wxString str;
298 if ( M_FONTDATA )
299 str = M_FONTDATA->m_faceName ;
300 return str;
301}
302
303wxFontEncoding wxFont::GetEncoding() const
304{
305 return M_FONTDATA->m_encoding;
e9576ca5
SC
306}
307
ac17f9b1
SC
308bool wxFont::GetNoAntiAliasing()
309{
310 return M_FONTDATA->m_noAA;
311}
312