]>
Commit | Line | Data |
---|---|---|
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 | ||
76a5e5d2 | 25 | #include "wx/mac/private.h" |
66a09d47 | 26 | #include "ATSUnicode.h" |
76a5e5d2 | 27 | |
2f1ae414 | 28 | #if !USE_SHARED_LIBRARIES |
e9576ca5 | 29 | IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) |
2f1ae414 | 30 | #endif |
e9576ca5 | 31 | |
e7549107 SC |
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) | |
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 | ||
57 | m_macFontNum = 0 ; | |
58 | m_macFontSize = 0; | |
59 | m_macFontStyle = 0; | |
60 | m_fontId = 0; | |
e9576ca5 SC |
61 | } |
62 | ||
63 | wxFontRefData::~wxFontRefData() | |
64 | { | |
e9576ca5 SC |
65 | } |
66 | ||
519cb848 SC |
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 : | |
2f1ae414 | 86 | ::GetFNum( "\pGeneva" , &m_macFontNum) ; |
519cb848 SC |
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 | { | |
03e11df5 GD |
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); | |
519cb848 SC |
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 ; | |
66a09d47 SC |
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 | wxASSERT_MSG( status == noErr , "couldn't retrieve font identifier" ) ; | |
519cb848 SC |
125 | } |
126 | ||
e7549107 SC |
127 | // ---------------------------------------------------------------------------- |
128 | // wxFont | |
129 | // ---------------------------------------------------------------------------- | |
e9576ca5 | 130 | |
e7549107 | 131 | void wxFont::Init() |
e9576ca5 | 132 | { |
e9576ca5 SC |
133 | } |
134 | ||
5b781a67 SC |
135 | bool wxFont::Create(const wxNativeFontInfo& info) |
136 | { | |
137 | return Create(info.pointSize, info.family, info.style, info.weight, | |
138 | info.underlined, info.faceName, info.encoding); | |
139 | } | |
140 | ||
3b7e6277 GD |
141 | wxFont::wxFont(const wxString& fontdesc) |
142 | { | |
143 | wxNativeFontInfo info; | |
144 | if ( info.FromString(fontdesc) ) | |
145 | (void)Create(info); | |
146 | } | |
147 | ||
e7549107 SC |
148 | bool wxFont::Create(int pointSize, |
149 | int family, | |
150 | int style, | |
151 | int weight, | |
152 | bool underlined, | |
153 | const wxString& faceName, | |
154 | wxFontEncoding encoding) | |
e9576ca5 SC |
155 | { |
156 | UnRef(); | |
e7549107 SC |
157 | m_refData = new wxFontRefData(pointSize, family, style, weight, |
158 | underlined, faceName, encoding); | |
e9576ca5 SC |
159 | |
160 | RealizeResource(); | |
161 | ||
162 | return TRUE; | |
163 | } | |
164 | ||
165 | wxFont::~wxFont() | |
166 | { | |
e9576ca5 SC |
167 | } |
168 | ||
169 | bool wxFont::RealizeResource() | |
170 | { | |
519cb848 SC |
171 | M_FONTDATA->MacFindFont() ; |
172 | return TRUE; | |
e9576ca5 SC |
173 | } |
174 | ||
51abe921 SC |
175 | void wxFont::SetEncoding(wxFontEncoding encoding) |
176 | { | |
177 | Unshare(); | |
178 | ||
179 | M_FONTDATA->m_encoding = encoding; | |
180 | ||
181 | RealizeResource(); | |
182 | } | |
183 | ||
e9576ca5 SC |
184 | void wxFont::Unshare() |
185 | { | |
186 | // Don't change shared data | |
187 | if (!m_refData) | |
188 | { | |
189 | m_refData = new wxFontRefData(); | |
190 | } | |
191 | else | |
192 | { | |
193 | wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); | |
194 | UnRef(); | |
195 | m_refData = ref; | |
196 | } | |
197 | } | |
198 | ||
199 | void wxFont::SetPointSize(int pointSize) | |
200 | { | |
201 | Unshare(); | |
202 | ||
203 | M_FONTDATA->m_pointSize = pointSize; | |
204 | ||
205 | RealizeResource(); | |
206 | } | |
207 | ||
208 | void wxFont::SetFamily(int family) | |
209 | { | |
210 | Unshare(); | |
211 | ||
212 | M_FONTDATA->m_family = family; | |
213 | ||
214 | RealizeResource(); | |
215 | } | |
216 | ||
217 | void wxFont::SetStyle(int style) | |
218 | { | |
219 | Unshare(); | |
220 | ||
221 | M_FONTDATA->m_style = style; | |
222 | ||
223 | RealizeResource(); | |
224 | } | |
225 | ||
226 | void wxFont::SetWeight(int weight) | |
227 | { | |
228 | Unshare(); | |
229 | ||
230 | M_FONTDATA->m_weight = weight; | |
231 | ||
232 | RealizeResource(); | |
233 | } | |
234 | ||
235 | void wxFont::SetFaceName(const wxString& faceName) | |
236 | { | |
237 | Unshare(); | |
238 | ||
239 | M_FONTDATA->m_faceName = faceName; | |
240 | ||
241 | RealizeResource(); | |
242 | } | |
243 | ||
244 | void wxFont::SetUnderlined(bool underlined) | |
245 | { | |
246 | Unshare(); | |
247 | ||
248 | M_FONTDATA->m_underlined = underlined; | |
249 | ||
250 | RealizeResource(); | |
251 | } | |
252 | ||
e7549107 SC |
253 | // ---------------------------------------------------------------------------- |
254 | // accessors | |
255 | // ---------------------------------------------------------------------------- | |
256 | ||
257 | int wxFont::GetPointSize() const | |
e9576ca5 | 258 | { |
e7549107 | 259 | return M_FONTDATA->m_pointSize; |
e9576ca5 SC |
260 | } |
261 | ||
e7549107 | 262 | int wxFont::GetFamily() const |
e9576ca5 | 263 | { |
e7549107 | 264 | return M_FONTDATA->m_family; |
e9576ca5 SC |
265 | } |
266 | ||
e7549107 | 267 | int wxFont::GetStyle() const |
e9576ca5 | 268 | { |
e7549107 SC |
269 | return M_FONTDATA->m_style; |
270 | } | |
271 | ||
272 | int wxFont::GetWeight() const | |
273 | { | |
274 | return M_FONTDATA->m_weight; | |
275 | } | |
276 | ||
277 | bool wxFont::GetUnderlined() const | |
278 | { | |
279 | return M_FONTDATA->m_underlined; | |
280 | } | |
281 | ||
282 | wxString wxFont::GetFaceName() const | |
283 | { | |
284 | wxString str; | |
285 | if ( M_FONTDATA ) | |
286 | str = M_FONTDATA->m_faceName ; | |
287 | return str; | |
288 | } | |
289 | ||
290 | wxFontEncoding wxFont::GetEncoding() const | |
291 | { | |
292 | return M_FONTDATA->m_encoding; | |
e9576ca5 SC |
293 | } |
294 |