]>
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 | ||
d84afea9 GD |
57 | m_macFontNum = 0 ; |
58 | m_macFontSize = 0; | |
59 | m_macFontStyle = 0; | |
e7549107 | 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 | } | |
2b5f62a0 VZ |
92 | Str255 name ; |
93 | GetFontName( m_macFontNum , name ) ; | |
94 | CopyPascalStringToC( name , (char*) name ) ; | |
95 | m_faceName = (char*) name ; | |
519cb848 SC |
96 | } |
97 | else | |
98 | { | |
99 | if ( m_faceName == "systemfont" ) | |
100 | m_macFontNum = ::GetSysFont() ; | |
101 | else if ( m_faceName == "applicationfont" ) | |
102 | m_macFontNum = ::GetAppFont() ; | |
103 | else | |
104 | { | |
03e11df5 GD |
105 | #if TARGET_CARBON |
106 | c2pstrcpy( (StringPtr) wxBuffer, m_faceName ) ; | |
107 | #else | |
108 | strcpy( (char *) wxBuffer, m_faceName ) ; | |
109 | c2pstr( (char *) wxBuffer ) ; | |
110 | #endif | |
111 | ::GetFNum( (StringPtr) wxBuffer, &m_macFontNum); | |
519cb848 SC |
112 | } |
113 | } | |
114 | ||
115 | m_macFontStyle = 0; | |
116 | if (m_weight == wxBOLD) | |
117 | m_macFontStyle |= bold; | |
118 | if (m_style == wxITALIC || m_style == wxSLANT) | |
119 | m_macFontStyle |= italic; | |
120 | if (m_underlined) | |
121 | m_macFontStyle |= underline; | |
122 | m_macFontSize = m_pointSize ; | |
66a09d47 SC |
123 | |
124 | //TODO:if we supply the style as an additional parameter we must make a testing | |
125 | //sequence in order to degrade gracefully while trying to maintain most of the style | |
126 | //information, meanwhile we just take the normal font and apply the features after | |
127 | OSStatus status = ::ATSUFONDtoFontID(m_macFontNum, normal /*qdStyle*/, (UInt32*)&m_macATSUFontID); | |
5a981902 SC |
128 | /* |
129 | status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) , | |
130 | kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ; | |
131 | */ | |
66a09d47 | 132 | wxASSERT_MSG( status == noErr , "couldn't retrieve font identifier" ) ; |
519cb848 SC |
133 | } |
134 | ||
e7549107 SC |
135 | // ---------------------------------------------------------------------------- |
136 | // wxFont | |
137 | // ---------------------------------------------------------------------------- | |
e9576ca5 | 138 | |
e7549107 | 139 | void wxFont::Init() |
e9576ca5 | 140 | { |
e9576ca5 SC |
141 | } |
142 | ||
5b781a67 SC |
143 | bool wxFont::Create(const wxNativeFontInfo& info) |
144 | { | |
145 | return Create(info.pointSize, info.family, info.style, info.weight, | |
146 | info.underlined, info.faceName, info.encoding); | |
147 | } | |
148 | ||
3b7e6277 GD |
149 | wxFont::wxFont(const wxString& fontdesc) |
150 | { | |
151 | wxNativeFontInfo info; | |
152 | if ( info.FromString(fontdesc) ) | |
153 | (void)Create(info); | |
154 | } | |
155 | ||
e7549107 SC |
156 | bool wxFont::Create(int pointSize, |
157 | int family, | |
158 | int style, | |
159 | int weight, | |
160 | bool underlined, | |
161 | const wxString& faceName, | |
162 | wxFontEncoding encoding) | |
e9576ca5 SC |
163 | { |
164 | UnRef(); | |
e7549107 SC |
165 | m_refData = new wxFontRefData(pointSize, family, style, weight, |
166 | underlined, faceName, encoding); | |
e9576ca5 SC |
167 | |
168 | RealizeResource(); | |
169 | ||
170 | return TRUE; | |
171 | } | |
172 | ||
173 | wxFont::~wxFont() | |
174 | { | |
e9576ca5 SC |
175 | } |
176 | ||
177 | bool wxFont::RealizeResource() | |
178 | { | |
519cb848 SC |
179 | M_FONTDATA->MacFindFont() ; |
180 | return TRUE; | |
e9576ca5 SC |
181 | } |
182 | ||
51abe921 SC |
183 | void wxFont::SetEncoding(wxFontEncoding encoding) |
184 | { | |
185 | Unshare(); | |
186 | ||
187 | M_FONTDATA->m_encoding = encoding; | |
188 | ||
189 | RealizeResource(); | |
190 | } | |
191 | ||
e9576ca5 SC |
192 | void wxFont::Unshare() |
193 | { | |
194 | // Don't change shared data | |
195 | if (!m_refData) | |
196 | { | |
197 | m_refData = new wxFontRefData(); | |
198 | } | |
199 | else | |
200 | { | |
201 | wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); | |
202 | UnRef(); | |
203 | m_refData = ref; | |
204 | } | |
205 | } | |
206 | ||
207 | void wxFont::SetPointSize(int pointSize) | |
208 | { | |
209 | Unshare(); | |
210 | ||
211 | M_FONTDATA->m_pointSize = pointSize; | |
212 | ||
213 | RealizeResource(); | |
214 | } | |
215 | ||
216 | void wxFont::SetFamily(int family) | |
217 | { | |
218 | Unshare(); | |
219 | ||
220 | M_FONTDATA->m_family = family; | |
221 | ||
222 | RealizeResource(); | |
223 | } | |
224 | ||
225 | void wxFont::SetStyle(int style) | |
226 | { | |
227 | Unshare(); | |
228 | ||
229 | M_FONTDATA->m_style = style; | |
230 | ||
231 | RealizeResource(); | |
232 | } | |
233 | ||
234 | void wxFont::SetWeight(int weight) | |
235 | { | |
236 | Unshare(); | |
237 | ||
238 | M_FONTDATA->m_weight = weight; | |
239 | ||
240 | RealizeResource(); | |
241 | } | |
242 | ||
243 | void wxFont::SetFaceName(const wxString& faceName) | |
244 | { | |
245 | Unshare(); | |
246 | ||
247 | M_FONTDATA->m_faceName = faceName; | |
248 | ||
249 | RealizeResource(); | |
250 | } | |
251 | ||
252 | void wxFont::SetUnderlined(bool underlined) | |
253 | { | |
254 | Unshare(); | |
255 | ||
256 | M_FONTDATA->m_underlined = underlined; | |
257 | ||
258 | RealizeResource(); | |
259 | } | |
260 | ||
e7549107 SC |
261 | // ---------------------------------------------------------------------------- |
262 | // accessors | |
263 | // ---------------------------------------------------------------------------- | |
264 | ||
265 | int wxFont::GetPointSize() const | |
e9576ca5 | 266 | { |
e7549107 | 267 | return M_FONTDATA->m_pointSize; |
e9576ca5 SC |
268 | } |
269 | ||
e7549107 | 270 | int wxFont::GetFamily() const |
e9576ca5 | 271 | { |
e7549107 | 272 | return M_FONTDATA->m_family; |
e9576ca5 SC |
273 | } |
274 | ||
e7549107 | 275 | int wxFont::GetStyle() const |
e9576ca5 | 276 | { |
e7549107 SC |
277 | return M_FONTDATA->m_style; |
278 | } | |
279 | ||
280 | int wxFont::GetWeight() const | |
281 | { | |
282 | return M_FONTDATA->m_weight; | |
283 | } | |
284 | ||
285 | bool wxFont::GetUnderlined() const | |
286 | { | |
287 | return M_FONTDATA->m_underlined; | |
288 | } | |
289 | ||
290 | wxString wxFont::GetFaceName() const | |
291 | { | |
292 | wxString str; | |
293 | if ( M_FONTDATA ) | |
294 | str = M_FONTDATA->m_faceName ; | |
295 | return str; | |
296 | } | |
297 | ||
298 | wxFontEncoding wxFont::GetEncoding() const | |
299 | { | |
300 | return M_FONTDATA->m_encoding; | |
e9576ca5 SC |
301 | } |
302 |