]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/font.cpp
mac adaptions
[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/gdicmn.h"
20
21 #if !USE_SHARED_LIBRARIES
22 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
23 #endif
24
25
26
27
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)
43 {
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;
57 }
58
59 wxFontRefData::~wxFontRefData()
60 {
61 }
62
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 :
82 ::GetFNum( "\pHelvetica" , &m_macFontNum) ;
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
113 // ----------------------------------------------------------------------------
114 // wxFont
115 // ----------------------------------------------------------------------------
116
117 void wxFont::Init()
118 {
119 if ( wxTheFontList )
120 wxTheFontList->Append(this);
121 }
122
123 bool wxFont::Create(int pointSize,
124 int family,
125 int style,
126 int weight,
127 bool underlined,
128 const wxString& faceName,
129 wxFontEncoding encoding)
130 {
131 UnRef();
132 m_refData = new wxFontRefData(pointSize, family, style, weight,
133 underlined, faceName, encoding);
134
135 RealizeResource();
136
137 return TRUE;
138 }
139
140 wxFont::~wxFont()
141 {
142 if (wxTheFontList)
143 wxTheFontList->DeleteObject(this);
144 }
145
146 bool wxFont::RealizeResource()
147 {
148 M_FONTDATA->MacFindFont() ;
149 return TRUE;
150 }
151
152 void wxFont::Unshare()
153 {
154 // Don't change shared data
155 if (!m_refData)
156 {
157 m_refData = new wxFontRefData();
158 }
159 else
160 {
161 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
162 UnRef();
163 m_refData = ref;
164 }
165 }
166
167 void wxFont::SetPointSize(int pointSize)
168 {
169 Unshare();
170
171 M_FONTDATA->m_pointSize = pointSize;
172
173 RealizeResource();
174 }
175
176 void wxFont::SetFamily(int family)
177 {
178 Unshare();
179
180 M_FONTDATA->m_family = family;
181
182 RealizeResource();
183 }
184
185 void wxFont::SetStyle(int style)
186 {
187 Unshare();
188
189 M_FONTDATA->m_style = style;
190
191 RealizeResource();
192 }
193
194 void wxFont::SetWeight(int weight)
195 {
196 Unshare();
197
198 M_FONTDATA->m_weight = weight;
199
200 RealizeResource();
201 }
202
203 void wxFont::SetFaceName(const wxString& faceName)
204 {
205 Unshare();
206
207 M_FONTDATA->m_faceName = faceName;
208
209 RealizeResource();
210 }
211
212 void wxFont::SetUnderlined(bool underlined)
213 {
214 Unshare();
215
216 M_FONTDATA->m_underlined = underlined;
217
218 RealizeResource();
219 }
220
221 // ----------------------------------------------------------------------------
222 // accessors
223 // ----------------------------------------------------------------------------
224
225 int wxFont::GetPointSize() const
226 {
227 return M_FONTDATA->m_pointSize;
228 }
229
230 int wxFont::GetFamily() const
231 {
232 return M_FONTDATA->m_family;
233 }
234
235 int wxFont::GetFontId() const
236 {
237 return M_FONTDATA->m_fontId;
238 }
239
240 int wxFont::GetStyle() const
241 {
242 return M_FONTDATA->m_style;
243 }
244
245 int wxFont::GetWeight() const
246 {
247 return M_FONTDATA->m_weight;
248 }
249
250 bool wxFont::GetUnderlined() const
251 {
252 return M_FONTDATA->m_underlined;
253 }
254
255 wxString wxFont::GetFaceName() const
256 {
257 wxString str;
258 if ( M_FONTDATA )
259 str = M_FONTDATA->m_faceName ;
260 return str;
261 }
262
263 wxFontEncoding wxFont::GetEncoding() const
264 {
265 return M_FONTDATA->m_encoding;
266 }
267