]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/font.cpp
fixes for wxBase RPM
[wxWidgets.git] / src / mac / carbon / 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 #if !USE_SHARED_LIBRARIES
26 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
27 #endif
28
29 // ============================================================================
30 // implementation
31 // ============================================================================
32
33 // ----------------------------------------------------------------------------
34 // wxFontRefData
35 // ----------------------------------------------------------------------------
36
37 void wxFontRefData::Init(int pointSize,
38 int family,
39 int style,
40 int weight,
41 bool underlined,
42 const wxString& faceName,
43 wxFontEncoding encoding)
44 {
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;
58 }
59
60 wxFontRefData::~wxFontRefData()
61 {
62 }
63
64 void 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 :
83 ::GetFNum( "\pGeneva" , &m_macFontNum) ;
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 {
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);
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
118 // ----------------------------------------------------------------------------
119 // wxFont
120 // ----------------------------------------------------------------------------
121
122 void wxFont::Init()
123 {
124 if ( wxTheFontList )
125 wxTheFontList->Append(this);
126 }
127
128 bool 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
134 wxFont::wxFont(const wxString& fontdesc)
135 {
136 wxNativeFontInfo info;
137 if ( info.FromString(fontdesc) )
138 (void)Create(info);
139 }
140
141 bool wxFont::Create(int pointSize,
142 int family,
143 int style,
144 int weight,
145 bool underlined,
146 const wxString& faceName,
147 wxFontEncoding encoding)
148 {
149 UnRef();
150 m_refData = new wxFontRefData(pointSize, family, style, weight,
151 underlined, faceName, encoding);
152
153 RealizeResource();
154
155 return TRUE;
156 }
157
158 wxFont::~wxFont()
159 {
160 if (wxTheFontList)
161 wxTheFontList->DeleteObject(this);
162 }
163
164 bool wxFont::RealizeResource()
165 {
166 M_FONTDATA->MacFindFont() ;
167 return TRUE;
168 }
169
170 void wxFont::SetEncoding(wxFontEncoding encoding)
171 {
172 Unshare();
173
174 M_FONTDATA->m_encoding = encoding;
175
176 RealizeResource();
177 }
178
179 void 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
194 void wxFont::SetPointSize(int pointSize)
195 {
196 Unshare();
197
198 M_FONTDATA->m_pointSize = pointSize;
199
200 RealizeResource();
201 }
202
203 void wxFont::SetFamily(int family)
204 {
205 Unshare();
206
207 M_FONTDATA->m_family = family;
208
209 RealizeResource();
210 }
211
212 void wxFont::SetStyle(int style)
213 {
214 Unshare();
215
216 M_FONTDATA->m_style = style;
217
218 RealizeResource();
219 }
220
221 void wxFont::SetWeight(int weight)
222 {
223 Unshare();
224
225 M_FONTDATA->m_weight = weight;
226
227 RealizeResource();
228 }
229
230 void wxFont::SetFaceName(const wxString& faceName)
231 {
232 Unshare();
233
234 M_FONTDATA->m_faceName = faceName;
235
236 RealizeResource();
237 }
238
239 void wxFont::SetUnderlined(bool underlined)
240 {
241 Unshare();
242
243 M_FONTDATA->m_underlined = underlined;
244
245 RealizeResource();
246 }
247
248 // ----------------------------------------------------------------------------
249 // accessors
250 // ----------------------------------------------------------------------------
251
252 int wxFont::GetPointSize() const
253 {
254 return M_FONTDATA->m_pointSize;
255 }
256
257 int wxFont::GetFamily() const
258 {
259 return M_FONTDATA->m_family;
260 }
261
262 int wxFont::GetStyle() const
263 {
264 return M_FONTDATA->m_style;
265 }
266
267 int wxFont::GetWeight() const
268 {
269 return M_FONTDATA->m_weight;
270 }
271
272 bool wxFont::GetUnderlined() const
273 {
274 return M_FONTDATA->m_underlined;
275 }
276
277 wxString wxFont::GetFaceName() const
278 {
279 wxString str;
280 if ( M_FONTDATA )
281 str = M_FONTDATA->m_faceName ;
282 return str;
283 }
284
285 wxFontEncoding wxFont::GetEncoding() const
286 {
287 return M_FONTDATA->m_encoding;
288 }
289