]> git.saurik.com Git - wxWidgets.git/blame - src/mac/font.cpp
Copied/merged from the 2.2 branch.
[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
2f1ae414 25#if !USE_SHARED_LIBRARIES
e9576ca5 26IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
2f1ae414 27#endif
e9576ca5 28
e7549107
SC
29// ============================================================================
30// implementation
31// ============================================================================
32
33// ----------------------------------------------------------------------------
34// wxFontRefData
35// ----------------------------------------------------------------------------
36
37void wxFontRefData::Init(int pointSize,
38 int family,
39 int style,
40 int weight,
41 bool underlined,
42 const wxString& faceName,
43 wxFontEncoding encoding)
e9576ca5 44{
e7549107
SC
45 m_style = style;
46 m_pointSize = pointSize;
47 m_family = family;
48 m_style = style;
49 m_weight = weight;
50 m_underlined = underlined;
51 m_faceName = faceName;
52 m_encoding = encoding;
53
54 m_macFontNum = 0 ;
55 m_macFontSize = 0;
56 m_macFontStyle = 0;
57 m_fontId = 0;
e9576ca5
SC
58}
59
60wxFontRefData::~wxFontRefData()
61{
e9576ca5
SC
62}
63
519cb848
SC
64void wxFontRefData::MacFindFont()
65{
66 if( m_faceName == "" )
67 {
68 switch( m_family )
69 {
70 case wxDEFAULT :
71 m_macFontNum = ::GetAppFont() ;
72 break ;
73 case wxDECORATIVE :
74 ::GetFNum( "\pTimes" , &m_macFontNum) ;
75 break ;
76 case wxROMAN :
77 ::GetFNum( "\pTimes" , &m_macFontNum) ;
78 break ;
79 case wxSCRIPT :
80 ::GetFNum( "\pTimes" , &m_macFontNum) ;
81 break ;
82 case wxSWISS :
2f1ae414 83 ::GetFNum( "\pGeneva" , &m_macFontNum) ;
519cb848
SC
84 break ;
85 case wxMODERN :
86 ::GetFNum( "\pMonaco" , &m_macFontNum) ;
87 break ;
88 }
89 }
90 else
91 {
92 if ( m_faceName == "systemfont" )
93 m_macFontNum = ::GetSysFont() ;
94 else if ( m_faceName == "applicationfont" )
95 m_macFontNum = ::GetAppFont() ;
96 else
97 {
03e11df5
GD
98#if TARGET_CARBON
99 c2pstrcpy( (StringPtr) wxBuffer, m_faceName ) ;
100#else
101 strcpy( (char *) wxBuffer, m_faceName ) ;
102 c2pstr( (char *) wxBuffer ) ;
103#endif
104 ::GetFNum( (StringPtr) wxBuffer, &m_macFontNum);
519cb848
SC
105 }
106 }
107
108 m_macFontStyle = 0;
109 if (m_weight == wxBOLD)
110 m_macFontStyle |= bold;
111 if (m_style == wxITALIC || m_style == wxSLANT)
112 m_macFontStyle |= italic;
113 if (m_underlined)
114 m_macFontStyle |= underline;
115 m_macFontSize = m_pointSize ;
116}
117
e7549107
SC
118// ----------------------------------------------------------------------------
119// wxFont
120// ----------------------------------------------------------------------------
e9576ca5 121
e7549107 122void wxFont::Init()
e9576ca5 123{
e9576ca5
SC
124 if ( wxTheFontList )
125 wxTheFontList->Append(this);
126}
127
5b781a67
SC
128bool wxFont::Create(const wxNativeFontInfo& info)
129{
130 return Create(info.pointSize, info.family, info.style, info.weight,
131 info.underlined, info.faceName, info.encoding);
132}
133
3b7e6277
GD
134wxFont::wxFont(const wxString& fontdesc)
135{
136 wxNativeFontInfo info;
137 if ( info.FromString(fontdesc) )
138 (void)Create(info);
139}
140
e7549107
SC
141bool wxFont::Create(int pointSize,
142 int family,
143 int style,
144 int weight,
145 bool underlined,
146 const wxString& faceName,
147 wxFontEncoding encoding)
e9576ca5
SC
148{
149 UnRef();
e7549107
SC
150 m_refData = new wxFontRefData(pointSize, family, style, weight,
151 underlined, faceName, encoding);
e9576ca5
SC
152
153 RealizeResource();
154
155 return TRUE;
156}
157
158wxFont::~wxFont()
159{
160 if (wxTheFontList)
161 wxTheFontList->DeleteObject(this);
162}
163
164bool wxFont::RealizeResource()
165{
519cb848
SC
166 M_FONTDATA->MacFindFont() ;
167 return TRUE;
e9576ca5
SC
168}
169
51abe921
SC
170void wxFont::SetEncoding(wxFontEncoding encoding)
171{
172 Unshare();
173
174 M_FONTDATA->m_encoding = encoding;
175
176 RealizeResource();
177}
178
e9576ca5
SC
179void wxFont::Unshare()
180{
181 // Don't change shared data
182 if (!m_refData)
183 {
184 m_refData = new wxFontRefData();
185 }
186 else
187 {
188 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
189 UnRef();
190 m_refData = ref;
191 }
192}
193
194void wxFont::SetPointSize(int pointSize)
195{
196 Unshare();
197
198 M_FONTDATA->m_pointSize = pointSize;
199
200 RealizeResource();
201}
202
203void wxFont::SetFamily(int family)
204{
205 Unshare();
206
207 M_FONTDATA->m_family = family;
208
209 RealizeResource();
210}
211
212void wxFont::SetStyle(int style)
213{
214 Unshare();
215
216 M_FONTDATA->m_style = style;
217
218 RealizeResource();
219}
220
221void wxFont::SetWeight(int weight)
222{
223 Unshare();
224
225 M_FONTDATA->m_weight = weight;
226
227 RealizeResource();
228}
229
230void wxFont::SetFaceName(const wxString& faceName)
231{
232 Unshare();
233
234 M_FONTDATA->m_faceName = faceName;
235
236 RealizeResource();
237}
238
239void wxFont::SetUnderlined(bool underlined)
240{
241 Unshare();
242
243 M_FONTDATA->m_underlined = underlined;
244
245 RealizeResource();
246}
247
e7549107
SC
248// ----------------------------------------------------------------------------
249// accessors
250// ----------------------------------------------------------------------------
251
252int wxFont::GetPointSize() const
e9576ca5 253{
e7549107 254 return M_FONTDATA->m_pointSize;
e9576ca5
SC
255}
256
e7549107 257int wxFont::GetFamily() const
e9576ca5 258{
e7549107 259 return M_FONTDATA->m_family;
e9576ca5
SC
260}
261
e7549107 262int wxFont::GetStyle() const
e9576ca5 263{
e7549107
SC
264 return M_FONTDATA->m_style;
265}
266
267int wxFont::GetWeight() const
268{
269 return M_FONTDATA->m_weight;
270}
271
272bool wxFont::GetUnderlined() const
273{
274 return M_FONTDATA->m_underlined;
275}
276
277wxString wxFont::GetFaceName() const
278{
279 wxString str;
280 if ( M_FONTDATA )
281 str = M_FONTDATA->m_faceName ;
282 return str;
283}
284
285wxFontEncoding wxFont::GetEncoding() const
286{
287 return M_FONTDATA->m_encoding;
e9576ca5
SC
288}
289