]> git.saurik.com Git - wxWidgets.git/blob - src/mac/font.cpp
copyright update
[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
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 }
62
63 wxFontRefData::~wxFontRefData()
64 {
65 }
66
67 void wxFontRefData::MacFindFont()
68 {
69 if( m_faceName == "" )
70 {
71 switch( m_family )
72 {
73 case wxDEFAULT :
74 m_macFontNum = ::GetAppFont() ;
75 break ;
76 case wxDECORATIVE :
77 ::GetFNum( "\pTimes" , &m_macFontNum) ;
78 break ;
79 case wxROMAN :
80 ::GetFNum( "\pTimes" , &m_macFontNum) ;
81 break ;
82 case wxSCRIPT :
83 ::GetFNum( "\pTimes" , &m_macFontNum) ;
84 break ;
85 case wxSWISS :
86 ::GetFNum( "\pGeneva" , &m_macFontNum) ;
87 break ;
88 case wxMODERN :
89 ::GetFNum( "\pMonaco" , &m_macFontNum) ;
90 break ;
91 }
92 }
93 else
94 {
95 if ( m_faceName == "systemfont" )
96 m_macFontNum = ::GetSysFont() ;
97 else if ( m_faceName == "applicationfont" )
98 m_macFontNum = ::GetAppFont() ;
99 else
100 {
101 #if TARGET_CARBON
102 c2pstrcpy( (StringPtr) wxBuffer, m_faceName ) ;
103 #else
104 strcpy( (char *) wxBuffer, m_faceName ) ;
105 c2pstr( (char *) wxBuffer ) ;
106 #endif
107 ::GetFNum( (StringPtr) wxBuffer, &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
121 // ----------------------------------------------------------------------------
122 // wxFont
123 // ----------------------------------------------------------------------------
124
125 void wxFont::Init()
126 {
127 }
128
129 bool wxFont::Create(const wxNativeFontInfo& info)
130 {
131 return Create(info.pointSize, info.family, info.style, info.weight,
132 info.underlined, info.faceName, info.encoding);
133 }
134
135 wxFont::wxFont(const wxString& fontdesc)
136 {
137 wxNativeFontInfo info;
138 if ( info.FromString(fontdesc) )
139 (void)Create(info);
140 }
141
142 bool wxFont::Create(int pointSize,
143 int family,
144 int style,
145 int weight,
146 bool underlined,
147 const wxString& faceName,
148 wxFontEncoding encoding)
149 {
150 UnRef();
151 m_refData = new wxFontRefData(pointSize, family, style, weight,
152 underlined, faceName, encoding);
153
154 RealizeResource();
155
156 return TRUE;
157 }
158
159 wxFont::~wxFont()
160 {
161 }
162
163 bool wxFont::RealizeResource()
164 {
165 M_FONTDATA->MacFindFont() ;
166 return TRUE;
167 }
168
169 void wxFont::SetEncoding(wxFontEncoding encoding)
170 {
171 Unshare();
172
173 M_FONTDATA->m_encoding = encoding;
174
175 RealizeResource();
176 }
177
178 void wxFont::Unshare()
179 {
180 // Don't change shared data
181 if (!m_refData)
182 {
183 m_refData = new wxFontRefData();
184 }
185 else
186 {
187 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
188 UnRef();
189 m_refData = ref;
190 }
191 }
192
193 void wxFont::SetPointSize(int pointSize)
194 {
195 Unshare();
196
197 M_FONTDATA->m_pointSize = pointSize;
198
199 RealizeResource();
200 }
201
202 void wxFont::SetFamily(int family)
203 {
204 Unshare();
205
206 M_FONTDATA->m_family = family;
207
208 RealizeResource();
209 }
210
211 void wxFont::SetStyle(int style)
212 {
213 Unshare();
214
215 M_FONTDATA->m_style = style;
216
217 RealizeResource();
218 }
219
220 void wxFont::SetWeight(int weight)
221 {
222 Unshare();
223
224 M_FONTDATA->m_weight = weight;
225
226 RealizeResource();
227 }
228
229 void wxFont::SetFaceName(const wxString& faceName)
230 {
231 Unshare();
232
233 M_FONTDATA->m_faceName = faceName;
234
235 RealizeResource();
236 }
237
238 void wxFont::SetUnderlined(bool underlined)
239 {
240 Unshare();
241
242 M_FONTDATA->m_underlined = underlined;
243
244 RealizeResource();
245 }
246
247 // ----------------------------------------------------------------------------
248 // accessors
249 // ----------------------------------------------------------------------------
250
251 int wxFont::GetPointSize() const
252 {
253 return M_FONTDATA->m_pointSize;
254 }
255
256 int wxFont::GetFamily() const
257 {
258 return M_FONTDATA->m_family;
259 }
260
261 int wxFont::GetStyle() const
262 {
263 return M_FONTDATA->m_style;
264 }
265
266 int wxFont::GetWeight() const
267 {
268 return M_FONTDATA->m_weight;
269 }
270
271 bool wxFont::GetUnderlined() const
272 {
273 return M_FONTDATA->m_underlined;
274 }
275
276 wxString wxFont::GetFaceName() const
277 {
278 wxString str;
279 if ( M_FONTDATA )
280 str = M_FONTDATA->m_faceName ;
281 return str;
282 }
283
284 wxFontEncoding wxFont::GetEncoding() const
285 {
286 return M_FONTDATA->m_encoding;
287 }
288