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