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