]> git.saurik.com Git - wxWidgets.git/blame - src/common/fontcmn.cpp
added conversion to mac native filenames from local filesystem handler
[wxWidgets.git] / src / common / fontcmn.cpp
CommitLineData
0c5d3e1c
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: common/fontcmn.cpp
3// Purpose: implementation of wxFontBase methods
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 20.09.99
7// RCS-ID: $Id$
8// Copyright: (c) wxWindows team
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
1b68e0b5
RR
20#ifdef __GNUG__
21 #pragma implementation "fontbase.h"
22#endif
23
0c5d3e1c
VZ
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
32 #include "wx/font.h"
33#endif // WX_PRECOMP
34
09fcd889 35#include "wx/gdicmn.h"
76e23cdb
VZ
36#include "wx/fontutil.h" // for wxNativeFontInfo
37
30764ab5
VZ
38#include "wx/tokenzr.h"
39
0c5d3e1c
VZ
40// ============================================================================
41// implementation
42// ============================================================================
43
44// ----------------------------------------------------------------------------
45// wxFontBase
46// ----------------------------------------------------------------------------
47
48wxFontEncoding wxFontBase::ms_encodingDefault = wxFONTENCODING_SYSTEM;
49
7beba2fc 50/* static */
0c5d3e1c
VZ
51wxFont *wxFontBase::New(int size,
52 int family,
53 int style,
54 int weight,
55 bool underlined,
56 const wxString& face,
57 wxFontEncoding encoding)
58{
59 return new wxFont(size, family, style, weight, underlined, face, encoding);
60}
61
30764ab5
VZ
62/* static */
63wxFont *wxFontBase::New(const wxNativeFontInfo& info)
64{
65 return new wxFont(info);
66}
67
7826e2dd
VZ
68/* static */
69wxFont *wxFontBase::New(const wxString& strNativeFontDesc)
30764ab5 70{
30764ab5 71 wxNativeFontInfo fontInfo;
7826e2dd 72 if ( !fontInfo.FromString(strNativeFontDesc) )
09fcd889 73 return new wxFont(*wxNORMAL_FONT);
7826e2dd
VZ
74
75 return New(fontInfo);
76}
77
78wxNativeFontInfo *wxFontBase::GetNativeFontInfo() const
79{
6dabdbb4 80#if !defined(__WXGTK__) && !defined(__WXMSW__)
7826e2dd 81 wxNativeFontInfo *fontInfo = new wxNativeFontInfo;
30764ab5 82
7826e2dd
VZ
83 fontInfo->pointSize = GetPointSize();
84 fontInfo->family = GetFamily();
85 fontInfo->style = GetStyle();
86 fontInfo->weight = GetWeight();
87 fontInfo->underlined = GetUnderlined();
88 fontInfo->faceName = GetFaceName();
89 fontInfo->encoding = GetEncoding();
30764ab5
VZ
90
91 return fontInfo;
92#else
7826e2dd 93 return (wxNativeFontInfo *)NULL;
30764ab5
VZ
94#endif
95}
96
97void wxFontBase::SetNativeFontInfo(const wxNativeFontInfo& info)
98{
6dabdbb4 99#if !defined(__WXGTK__) && !defined(__WXMSW__)
30764ab5
VZ
100 SetPointSize(info.pointSize);
101 SetFamily(info.family);
102 SetStyle(info.style);
103 SetWeight(info.weight);
104 SetUnderlined(info.underlined);
105 SetFaceName(info.faceName);
106 SetEncoding(info.encoding);
33ac7e6f 107#else
1e6feb95 108 (void)info;
30764ab5
VZ
109#endif
110}
111
7826e2dd
VZ
112wxString wxFontBase::GetNativeFontInfoDesc() const
113{
114 wxString fontDesc;
115 wxNativeFontInfo *fontInfo = GetNativeFontInfo();
116 if ( fontInfo )
117 {
118 fontDesc = fontInfo->ToString();
119 delete fontInfo;
120 }
121
122 return fontDesc;
123}
124
0c5d3e1c
VZ
125wxFont& wxFont::operator=(const wxFont& font)
126{
127 if ( this != &font )
128 Ref(font);
129
130 return (wxFont &)*this;
131}
132
0c5d3e1c
VZ
133bool wxFontBase::operator==(const wxFont& font) const
134{
8bf30fe9
VZ
135 // either it is the same font, i.e. they share the same common data or they
136 // have different ref datas but still describe the same font
137 return GetFontData() == font.GetFontData() ||
138 (
139 Ok() == font.Ok() &&
140 GetPointSize() == font.GetPointSize() &&
141 GetFamily() == font.GetFamily() &&
142 GetStyle() == font.GetStyle() &&
143 GetUnderlined() == font.GetUnderlined() &&
144 GetFaceName() == font.GetFaceName() &&
145 GetEncoding() == font.GetEncoding()
146 );
0c5d3e1c
VZ
147}
148
149bool wxFontBase::operator!=(const wxFont& font) const
150{
8bf30fe9 151 return !(*this == font);
0c5d3e1c
VZ
152}
153
154wxString wxFontBase::GetFamilyString() const
155{
223d09f6 156 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
0c5d3e1c
VZ
157
158 switch ( GetFamily() )
159 {
223d09f6
KB
160 case wxDECORATIVE: return wxT("wxDECORATIVE");
161 case wxROMAN: return wxT("wxROMAN");
162 case wxSCRIPT: return wxT("wxSCRIPT");
163 case wxSWISS: return wxT("wxSWISS");
164 case wxMODERN: return wxT("wxMODERN");
165 case wxTELETYPE: return wxT("wxTELETYPE");
166 default: return wxT("wxDEFAULT");
0c5d3e1c
VZ
167 }
168}
169
170wxString wxFontBase::GetStyleString() const
171{
223d09f6 172 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
0c5d3e1c
VZ
173
174 switch ( GetStyle() )
175 {
223d09f6
KB
176 case wxNORMAL: return wxT("wxNORMAL");
177 case wxSLANT: return wxT("wxSLANT");
178 case wxITALIC: return wxT("wxITALIC");
179 default: return wxT("wxDEFAULT");
0c5d3e1c
VZ
180 }
181}
182
183wxString wxFontBase::GetWeightString() const
184{
223d09f6 185 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
0c5d3e1c
VZ
186
187 switch ( GetWeight() )
188 {
223d09f6
KB
189 case wxNORMAL: return wxT("wxNORMAL");
190 case wxBOLD: return wxT("wxBOLD");
191 case wxLIGHT: return wxT("wxLIGHT");
192 default: return wxT("wxDEFAULT");
0c5d3e1c
VZ
193 }
194}
195
6dabdbb4 196#if !defined(__WXGTK__) && !defined(__WXMSW__)
30764ab5
VZ
197
198// ----------------------------------------------------------------------------
199// wxNativeFontInfo
200// ----------------------------------------------------------------------------
201
202// These are the generic forms of FromString()/ToString.
203//
204// convert to/from the string representation: format is
09fcd889 205// version;pointsize;family;style;weight;underlined;facename;encoding
30764ab5
VZ
206
207bool wxNativeFontInfo::FromString(const wxString& s)
208{
209 long l;
210
211 wxStringTokenizer tokenizer(s, _T(";"));
212
213 wxString token = tokenizer.GetNextToken();
09fcd889
VZ
214 //
215 // Ignore the version for now
216 //
33ac7e6f 217
09fcd889 218 token = tokenizer.GetNextToken();
30764ab5
VZ
219 if ( !token.ToLong(&l) )
220 return FALSE;
221 pointSize = (int)l;
222
223 token = tokenizer.GetNextToken();
224 if ( !token.ToLong(&l) )
225 return FALSE;
226 family = (int)l;
227
228 token = tokenizer.GetNextToken();
229 if ( !token.ToLong(&l) )
230 return FALSE;
231 style = (int)l;
232
233 token = tokenizer.GetNextToken();
234 if ( !token.ToLong(&l) )
235 return FALSE;
236 weight = (int)l;
237
238 token = tokenizer.GetNextToken();
239 if ( !token.ToLong(&l) )
240 return FALSE;
189e08b4 241 underlined = l != 0;
30764ab5
VZ
242
243 faceName = tokenizer.GetNextToken();
244 if( !faceName )
245 return FALSE;
246
247 token = tokenizer.GetNextToken();
248 if ( !token.ToLong(&l) )
249 return FALSE;
250 encoding = (wxFontEncoding)l;
251
252 return TRUE;
253}
254
255wxString wxNativeFontInfo::ToString() const
256{
257 wxString s;
258
09fcd889
VZ
259 s.Printf(_T("%d;%d;%d;%d;%d;%d;%s;%d"),
260 0, // version
30764ab5
VZ
261 pointSize,
262 family,
263 style,
264 weight,
265 underlined,
266 faceName.GetData(),
267 (int)encoding);
268
269 return s;
270}
271
7826e2dd 272#endif // generic wxNativeFontInfo implementation
30764ab5 273