]> git.saurik.com Git - wxWidgets.git/blame - src/common/fontcmn.cpp
Fix/hack 1.
[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{
09fcd889 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{
09fcd889 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);
107#endif
108}
109
7826e2dd
VZ
110wxString wxFontBase::GetNativeFontInfoDesc() const
111{
112 wxString fontDesc;
113 wxNativeFontInfo *fontInfo = GetNativeFontInfo();
114 if ( fontInfo )
115 {
116 fontDesc = fontInfo->ToString();
117 delete fontInfo;
118 }
119
120 return fontDesc;
121}
122
0c5d3e1c
VZ
123wxFont& wxFont::operator=(const wxFont& font)
124{
125 if ( this != &font )
126 Ref(font);
127
128 return (wxFont &)*this;
129}
130
131// VZ: is it correct to compare pointers and not the contents? (FIXME)
132bool wxFontBase::operator==(const wxFont& font) const
133{
5e0201ea 134 return GetFontData() == font.GetFontData();
0c5d3e1c
VZ
135}
136
137bool wxFontBase::operator!=(const wxFont& font) const
138{
5e0201ea 139 return GetFontData() != font.GetFontData();
0c5d3e1c
VZ
140}
141
142wxString wxFontBase::GetFamilyString() const
143{
223d09f6 144 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
0c5d3e1c
VZ
145
146 switch ( GetFamily() )
147 {
223d09f6
KB
148 case wxDECORATIVE: return wxT("wxDECORATIVE");
149 case wxROMAN: return wxT("wxROMAN");
150 case wxSCRIPT: return wxT("wxSCRIPT");
151 case wxSWISS: return wxT("wxSWISS");
152 case wxMODERN: return wxT("wxMODERN");
153 case wxTELETYPE: return wxT("wxTELETYPE");
154 default: return wxT("wxDEFAULT");
0c5d3e1c
VZ
155 }
156}
157
158wxString wxFontBase::GetStyleString() const
159{
223d09f6 160 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
0c5d3e1c
VZ
161
162 switch ( GetStyle() )
163 {
223d09f6
KB
164 case wxNORMAL: return wxT("wxNORMAL");
165 case wxSLANT: return wxT("wxSLANT");
166 case wxITALIC: return wxT("wxITALIC");
167 default: return wxT("wxDEFAULT");
0c5d3e1c
VZ
168 }
169}
170
171wxString wxFontBase::GetWeightString() const
172{
223d09f6 173 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
0c5d3e1c
VZ
174
175 switch ( GetWeight() )
176 {
223d09f6
KB
177 case wxNORMAL: return wxT("wxNORMAL");
178 case wxBOLD: return wxT("wxBOLD");
179 case wxLIGHT: return wxT("wxLIGHT");
180 default: return wxT("wxDEFAULT");
0c5d3e1c
VZ
181 }
182}
183
09fcd889 184#if !defined(__WXGTK__) && !defined(__WXMSW__)
30764ab5
VZ
185
186// ----------------------------------------------------------------------------
187// wxNativeFontInfo
188// ----------------------------------------------------------------------------
189
190// These are the generic forms of FromString()/ToString.
191//
192// convert to/from the string representation: format is
09fcd889 193// version;pointsize;family;style;weight;underlined;facename;encoding
30764ab5
VZ
194
195bool wxNativeFontInfo::FromString(const wxString& s)
196{
197 long l;
198
199 wxStringTokenizer tokenizer(s, _T(";"));
200
201 wxString token = tokenizer.GetNextToken();
09fcd889
VZ
202 //
203 // Ignore the version for now
204 //
205
206 token = tokenizer.GetNextToken();
30764ab5
VZ
207 if ( !token.ToLong(&l) )
208 return FALSE;
209 pointSize = (int)l;
210
211 token = tokenizer.GetNextToken();
212 if ( !token.ToLong(&l) )
213 return FALSE;
214 family = (int)l;
215
216 token = tokenizer.GetNextToken();
217 if ( !token.ToLong(&l) )
218 return FALSE;
219 style = (int)l;
220
221 token = tokenizer.GetNextToken();
222 if ( !token.ToLong(&l) )
223 return FALSE;
224 weight = (int)l;
225
226 token = tokenizer.GetNextToken();
227 if ( !token.ToLong(&l) )
228 return FALSE;
189e08b4 229 underlined = l != 0;
30764ab5
VZ
230
231 faceName = tokenizer.GetNextToken();
232 if( !faceName )
233 return FALSE;
234
235 token = tokenizer.GetNextToken();
236 if ( !token.ToLong(&l) )
237 return FALSE;
238 encoding = (wxFontEncoding)l;
239
240 return TRUE;
241}
242
243wxString wxNativeFontInfo::ToString() const
244{
245 wxString s;
246
09fcd889
VZ
247 s.Printf(_T("%d;%d;%d;%d;%d;%d;%s;%d"),
248 0, // version
30764ab5
VZ
249 pointSize,
250 family,
251 style,
252 weight,
253 underlined,
254 faceName.GetData(),
255 (int)encoding);
256
257 return s;
258}
259
7826e2dd 260#endif // generic wxNativeFontInfo implementation
30764ab5 261