]>
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 SC |
20 | #include "wx/gdicmn.h" |
21 | ||
3b7e6277 GD |
22 | #include "wx/fontutil.h" |
23 | ||
2f1ae414 | 24 | #if !USE_SHARED_LIBRARIES |
e9576ca5 | 25 | IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) |
2f1ae414 | 26 | #endif |
e9576ca5 | 27 | |
e7549107 SC |
28 | // ============================================================================ |
29 | // implementation | |
30 | // ============================================================================ | |
31 | ||
32 | // ---------------------------------------------------------------------------- | |
33 | // wxFontRefData | |
34 | // ---------------------------------------------------------------------------- | |
35 | ||
36 | void wxFontRefData::Init(int pointSize, | |
37 | int family, | |
38 | int style, | |
39 | int weight, | |
40 | bool underlined, | |
41 | const wxString& faceName, | |
42 | wxFontEncoding encoding) | |
e9576ca5 | 43 | { |
e7549107 SC |
44 | m_style = style; |
45 | m_pointSize = pointSize; | |
46 | m_family = family; | |
47 | m_style = style; | |
48 | m_weight = weight; | |
49 | m_underlined = underlined; | |
50 | m_faceName = faceName; | |
51 | m_encoding = encoding; | |
52 | ||
53 | m_macFontNum = 0 ; | |
54 | m_macFontSize = 0; | |
55 | m_macFontStyle = 0; | |
56 | m_fontId = 0; | |
e9576ca5 SC |
57 | } |
58 | ||
59 | wxFontRefData::~wxFontRefData() | |
60 | { | |
e9576ca5 SC |
61 | } |
62 | ||
519cb848 SC |
63 | void wxFontRefData::MacFindFont() |
64 | { | |
65 | if( m_faceName == "" ) | |
66 | { | |
67 | switch( m_family ) | |
68 | { | |
69 | case wxDEFAULT : | |
70 | m_macFontNum = ::GetAppFont() ; | |
71 | break ; | |
72 | case wxDECORATIVE : | |
73 | ::GetFNum( "\pTimes" , &m_macFontNum) ; | |
74 | break ; | |
75 | case wxROMAN : | |
76 | ::GetFNum( "\pTimes" , &m_macFontNum) ; | |
77 | break ; | |
78 | case wxSCRIPT : | |
79 | ::GetFNum( "\pTimes" , &m_macFontNum) ; | |
80 | break ; | |
81 | case wxSWISS : | |
2f1ae414 | 82 | ::GetFNum( "\pGeneva" , &m_macFontNum) ; |
519cb848 SC |
83 | break ; |
84 | case wxMODERN : | |
85 | ::GetFNum( "\pMonaco" , &m_macFontNum) ; | |
86 | break ; | |
87 | } | |
88 | } | |
89 | else | |
90 | { | |
91 | if ( m_faceName == "systemfont" ) | |
92 | m_macFontNum = ::GetSysFont() ; | |
93 | else if ( m_faceName == "applicationfont" ) | |
94 | m_macFontNum = ::GetAppFont() ; | |
95 | else | |
96 | { | |
97 | strcpy(wxBuffer, m_faceName); | |
98 | C2PStr(wxBuffer); | |
99 | ::GetFNum( (unsigned char*) wxBuffer, &m_macFontNum); | |
100 | } | |
101 | } | |
102 | ||
103 | m_macFontStyle = 0; | |
104 | if (m_weight == wxBOLD) | |
105 | m_macFontStyle |= bold; | |
106 | if (m_style == wxITALIC || m_style == wxSLANT) | |
107 | m_macFontStyle |= italic; | |
108 | if (m_underlined) | |
109 | m_macFontStyle |= underline; | |
110 | m_macFontSize = m_pointSize ; | |
111 | } | |
112 | ||
e7549107 SC |
113 | // ---------------------------------------------------------------------------- |
114 | // wxFont | |
115 | // ---------------------------------------------------------------------------- | |
e9576ca5 | 116 | |
e7549107 | 117 | void wxFont::Init() |
e9576ca5 | 118 | { |
e9576ca5 SC |
119 | if ( wxTheFontList ) |
120 | wxTheFontList->Append(this); | |
121 | } | |
122 | ||
5b781a67 SC |
123 | bool wxFont::Create(const wxNativeFontInfo& info) |
124 | { | |
125 | return Create(info.pointSize, info.family, info.style, info.weight, | |
126 | info.underlined, info.faceName, info.encoding); | |
127 | } | |
128 | ||
3b7e6277 GD |
129 | wxFont::wxFont(const wxString& fontdesc) |
130 | { | |
131 | wxNativeFontInfo info; | |
132 | if ( info.FromString(fontdesc) ) | |
133 | (void)Create(info); | |
134 | } | |
135 | ||
e7549107 SC |
136 | bool wxFont::Create(int pointSize, |
137 | int family, | |
138 | int style, | |
139 | int weight, | |
140 | bool underlined, | |
141 | const wxString& faceName, | |
142 | wxFontEncoding encoding) | |
e9576ca5 SC |
143 | { |
144 | UnRef(); | |
e7549107 SC |
145 | m_refData = new wxFontRefData(pointSize, family, style, weight, |
146 | underlined, faceName, encoding); | |
e9576ca5 SC |
147 | |
148 | RealizeResource(); | |
149 | ||
150 | return TRUE; | |
151 | } | |
152 | ||
153 | wxFont::~wxFont() | |
154 | { | |
155 | if (wxTheFontList) | |
156 | wxTheFontList->DeleteObject(this); | |
157 | } | |
158 | ||
159 | bool wxFont::RealizeResource() | |
160 | { | |
519cb848 SC |
161 | M_FONTDATA->MacFindFont() ; |
162 | return TRUE; | |
e9576ca5 SC |
163 | } |
164 | ||
51abe921 SC |
165 | void wxFont::SetEncoding(wxFontEncoding encoding) |
166 | { | |
167 | Unshare(); | |
168 | ||
169 | M_FONTDATA->m_encoding = encoding; | |
170 | ||
171 | RealizeResource(); | |
172 | } | |
173 | ||
e9576ca5 SC |
174 | void wxFont::Unshare() |
175 | { | |
176 | // Don't change shared data | |
177 | if (!m_refData) | |
178 | { | |
179 | m_refData = new wxFontRefData(); | |
180 | } | |
181 | else | |
182 | { | |
183 | wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); | |
184 | UnRef(); | |
185 | m_refData = ref; | |
186 | } | |
187 | } | |
188 | ||
189 | void wxFont::SetPointSize(int pointSize) | |
190 | { | |
191 | Unshare(); | |
192 | ||
193 | M_FONTDATA->m_pointSize = pointSize; | |
194 | ||
195 | RealizeResource(); | |
196 | } | |
197 | ||
198 | void wxFont::SetFamily(int family) | |
199 | { | |
200 | Unshare(); | |
201 | ||
202 | M_FONTDATA->m_family = family; | |
203 | ||
204 | RealizeResource(); | |
205 | } | |
206 | ||
207 | void wxFont::SetStyle(int style) | |
208 | { | |
209 | Unshare(); | |
210 | ||
211 | M_FONTDATA->m_style = style; | |
212 | ||
213 | RealizeResource(); | |
214 | } | |
215 | ||
216 | void wxFont::SetWeight(int weight) | |
217 | { | |
218 | Unshare(); | |
219 | ||
220 | M_FONTDATA->m_weight = weight; | |
221 | ||
222 | RealizeResource(); | |
223 | } | |
224 | ||
225 | void wxFont::SetFaceName(const wxString& faceName) | |
226 | { | |
227 | Unshare(); | |
228 | ||
229 | M_FONTDATA->m_faceName = faceName; | |
230 | ||
231 | RealizeResource(); | |
232 | } | |
233 | ||
234 | void wxFont::SetUnderlined(bool underlined) | |
235 | { | |
236 | Unshare(); | |
237 | ||
238 | M_FONTDATA->m_underlined = underlined; | |
239 | ||
240 | RealizeResource(); | |
241 | } | |
242 | ||
e7549107 SC |
243 | // ---------------------------------------------------------------------------- |
244 | // accessors | |
245 | // ---------------------------------------------------------------------------- | |
246 | ||
247 | int wxFont::GetPointSize() const | |
e9576ca5 | 248 | { |
e7549107 | 249 | return M_FONTDATA->m_pointSize; |
e9576ca5 SC |
250 | } |
251 | ||
e7549107 | 252 | int wxFont::GetFamily() const |
e9576ca5 | 253 | { |
e7549107 | 254 | return M_FONTDATA->m_family; |
e9576ca5 SC |
255 | } |
256 | ||
e7549107 | 257 | int wxFont::GetStyle() const |
e9576ca5 | 258 | { |
e7549107 SC |
259 | return M_FONTDATA->m_style; |
260 | } | |
261 | ||
262 | int wxFont::GetWeight() const | |
263 | { | |
264 | return M_FONTDATA->m_weight; | |
265 | } | |
266 | ||
267 | bool wxFont::GetUnderlined() const | |
268 | { | |
269 | return M_FONTDATA->m_underlined; | |
270 | } | |
271 | ||
272 | wxString wxFont::GetFaceName() const | |
273 | { | |
274 | wxString str; | |
275 | if ( M_FONTDATA ) | |
276 | str = M_FONTDATA->m_faceName ; | |
277 | return str; | |
278 | } | |
279 | ||
280 | wxFontEncoding wxFont::GetEncoding() const | |
281 | { | |
282 | return M_FONTDATA->m_encoding; | |
e9576ca5 SC |
283 | } |
284 |