]> git.saurik.com Git - wxWidgets.git/blob - src/mac/font.cpp
fixes to the sizers behaviour necessary to make the log dialog work again
[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 }
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 //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);
124 /*
125 status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
126 kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
127 */
128 wxASSERT_MSG( status == noErr , "couldn't retrieve font identifier" ) ;
129 }
130
131 // ----------------------------------------------------------------------------
132 // wxFont
133 // ----------------------------------------------------------------------------
134
135 void wxFont::Init()
136 {
137 }
138
139 bool 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
145 wxFont::wxFont(const wxString& fontdesc)
146 {
147 wxNativeFontInfo info;
148 if ( info.FromString(fontdesc) )
149 (void)Create(info);
150 }
151
152 bool wxFont::Create(int pointSize,
153 int family,
154 int style,
155 int weight,
156 bool underlined,
157 const wxString& faceName,
158 wxFontEncoding encoding)
159 {
160 UnRef();
161 m_refData = new wxFontRefData(pointSize, family, style, weight,
162 underlined, faceName, encoding);
163
164 RealizeResource();
165
166 return TRUE;
167 }
168
169 wxFont::~wxFont()
170 {
171 }
172
173 bool wxFont::RealizeResource()
174 {
175 M_FONTDATA->MacFindFont() ;
176 return TRUE;
177 }
178
179 void wxFont::SetEncoding(wxFontEncoding encoding)
180 {
181 Unshare();
182
183 M_FONTDATA->m_encoding = encoding;
184
185 RealizeResource();
186 }
187
188 void wxFont::Unshare()
189 {
190 // Don't change shared data
191 if (!m_refData)
192 {
193 m_refData = new wxFontRefData();
194 }
195 else
196 {
197 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
198 UnRef();
199 m_refData = ref;
200 }
201 }
202
203 void wxFont::SetPointSize(int pointSize)
204 {
205 Unshare();
206
207 M_FONTDATA->m_pointSize = pointSize;
208
209 RealizeResource();
210 }
211
212 void wxFont::SetFamily(int family)
213 {
214 Unshare();
215
216 M_FONTDATA->m_family = family;
217
218 RealizeResource();
219 }
220
221 void wxFont::SetStyle(int style)
222 {
223 Unshare();
224
225 M_FONTDATA->m_style = style;
226
227 RealizeResource();
228 }
229
230 void wxFont::SetWeight(int weight)
231 {
232 Unshare();
233
234 M_FONTDATA->m_weight = weight;
235
236 RealizeResource();
237 }
238
239 void wxFont::SetFaceName(const wxString& faceName)
240 {
241 Unshare();
242
243 M_FONTDATA->m_faceName = faceName;
244
245 RealizeResource();
246 }
247
248 void wxFont::SetUnderlined(bool underlined)
249 {
250 Unshare();
251
252 M_FONTDATA->m_underlined = underlined;
253
254 RealizeResource();
255 }
256
257 // ----------------------------------------------------------------------------
258 // accessors
259 // ----------------------------------------------------------------------------
260
261 int wxFont::GetPointSize() const
262 {
263 return M_FONTDATA->m_pointSize;
264 }
265
266 int wxFont::GetFamily() const
267 {
268 return M_FONTDATA->m_family;
269 }
270
271 int wxFont::GetStyle() const
272 {
273 return M_FONTDATA->m_style;
274 }
275
276 int wxFont::GetWeight() const
277 {
278 return M_FONTDATA->m_weight;
279 }
280
281 bool wxFont::GetUnderlined() const
282 {
283 return M_FONTDATA->m_underlined;
284 }
285
286 wxString wxFont::GetFaceName() const
287 {
288 wxString str;
289 if ( M_FONTDATA )
290 str = M_FONTDATA->m_faceName ;
291 return str;
292 }
293
294 wxFontEncoding wxFont::GetEncoding() const
295 {
296 return M_FONTDATA->m_encoding;
297 }
298