]> git.saurik.com Git - wxWidgets.git/blob - include/wx/font.h
allow using CPPUNIT_ASSERT_EQUAL(int, wxFileOffset) too
[wxWidgets.git] / include / wx / font.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/font.h
3 // Purpose: wxFontBase class: the interface of wxFont
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 20.09.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FONT_H_BASE_
13 #define _WX_FONT_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/defs.h" // for wxDEFAULT &c
20 #include "wx/fontenc.h" // the font encoding constants
21 #include "wx/gdiobj.h" // the base class
22 #include "wx/gdicmn.h" // for wxGDIObjListBase
23
24 // ----------------------------------------------------------------------------
25 // forward declarations
26 // ----------------------------------------------------------------------------
27
28 class WXDLLIMPEXP_FWD_CORE wxFontData;
29 class WXDLLIMPEXP_FWD_CORE wxFontBase;
30 class WXDLLIMPEXP_FWD_CORE wxFont;
31 class WXDLLIMPEXP_FWD_CORE wxSize;
32
33 // ----------------------------------------------------------------------------
34 // font constants
35 // ----------------------------------------------------------------------------
36
37 // standard font families: these may be used only for the font creation, it
38 // doesn't make sense to query an existing font for its font family as,
39 // especially if the font had been created from a native font description, it
40 // may be unknown
41 enum wxFontFamily
42 {
43 wxFONTFAMILY_DEFAULT = wxDEFAULT,
44 wxFONTFAMILY_DECORATIVE = wxDECORATIVE,
45 wxFONTFAMILY_ROMAN = wxROMAN,
46 wxFONTFAMILY_SCRIPT = wxSCRIPT,
47 wxFONTFAMILY_SWISS = wxSWISS,
48 wxFONTFAMILY_MODERN = wxMODERN,
49 wxFONTFAMILY_TELETYPE = wxTELETYPE,
50 wxFONTFAMILY_MAX,
51 wxFONTFAMILY_UNKNOWN = wxFONTFAMILY_MAX
52 };
53
54 // font styles
55 enum wxFontStyle
56 {
57 wxFONTSTYLE_NORMAL = wxNORMAL,
58 wxFONTSTYLE_ITALIC = wxITALIC,
59 wxFONTSTYLE_SLANT = wxSLANT,
60 wxFONTSTYLE_MAX
61 };
62
63 // font weights
64 enum wxFontWeight
65 {
66 wxFONTWEIGHT_NORMAL = wxNORMAL,
67 wxFONTWEIGHT_LIGHT = wxLIGHT,
68 wxFONTWEIGHT_BOLD = wxBOLD,
69 wxFONTWEIGHT_MAX
70 };
71
72 // the font flag bits for the new font ctor accepting one combined flags word
73 enum wxFontFlag
74 {
75 // no special flags: font with default weight/slant/anti-aliasing
76 wxFONTFLAG_DEFAULT = 0,
77
78 // slant flags (default: no slant)
79 wxFONTFLAG_ITALIC = 1 << 0,
80 wxFONTFLAG_SLANT = 1 << 1,
81
82 // weight flags (default: medium)
83 wxFONTFLAG_LIGHT = 1 << 2,
84 wxFONTFLAG_BOLD = 1 << 3,
85
86 // anti-aliasing flag: force on or off (default: the current system default)
87 wxFONTFLAG_ANTIALIASED = 1 << 4,
88 wxFONTFLAG_NOT_ANTIALIASED = 1 << 5,
89
90 // underlined/strikethrough flags (default: no lines)
91 wxFONTFLAG_UNDERLINED = 1 << 6,
92 wxFONTFLAG_STRIKETHROUGH = 1 << 7,
93
94 // the mask of all currently used flags
95 wxFONTFLAG_MASK = wxFONTFLAG_ITALIC |
96 wxFONTFLAG_SLANT |
97 wxFONTFLAG_LIGHT |
98 wxFONTFLAG_BOLD |
99 wxFONTFLAG_ANTIALIASED |
100 wxFONTFLAG_NOT_ANTIALIASED |
101 wxFONTFLAG_UNDERLINED |
102 wxFONTFLAG_STRIKETHROUGH
103 };
104
105 // ----------------------------------------------------------------------------
106 // wxFontBase represents a font object
107 // ----------------------------------------------------------------------------
108
109 class WXDLLIMPEXP_FWD_CORE wxNativeFontInfo;
110
111 class WXDLLIMPEXP_CORE wxFontBase : public wxGDIObject
112 {
113 public:
114 // creator function
115 virtual ~wxFontBase();
116
117
118 #if FUTURE_WXWIN_COMPATIBILITY_3_0
119 // from the font components
120 static wxFont *New(
121 int pointSize, // size of the font in points
122 int family, // see wxFontFamily enum
123 int style, // see wxFontStyle enum
124 int weight, // see wxFontWeight enum
125 bool underlined = false, // not underlined by default
126 const wxString& face = wxEmptyString, // facename
127 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) // ISO8859-X, ...
128 { return New(pointSize, (wxFontFamily)family, (wxFontStyle)style,
129 (wxFontWeight)weight, underlined, face, encoding); }
130
131 // from the font components
132 static wxFont *New(
133 const wxSize& pixelSize, // size of the font in pixels
134 int family, // see wxFontFamily enum
135 int style, // see wxFontStyle enum
136 int weight, // see wxFontWeight enum
137 bool underlined = false, // not underlined by default
138 const wxString& face = wxEmptyString, // facename
139 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) // ISO8859-X, ...
140 { return New(pixelSize, (wxFontFamily)family, (wxFontStyle)style,
141 (wxFontWeight)weight, underlined, face, encoding); }
142 #endif
143
144 // from the font components
145 static wxFont *New(
146 int pointSize, // size of the font in points
147 wxFontFamily family, // see wxFontFamily enum
148 wxFontStyle style, // see wxFontStyle enum
149 wxFontWeight weight, // see wxFontWeight enum
150 bool underlined = false, // not underlined by default
151 const wxString& face = wxEmptyString, // facename
152 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ...
153
154 // from the font components
155 static wxFont *New(
156 const wxSize& pixelSize, // size of the font in pixels
157 wxFontFamily family, // see wxFontFamily enum
158 wxFontStyle style, // see wxFontStyle enum
159 wxFontWeight weight, // see wxFontWeight enum
160 bool underlined = false, // not underlined by default
161 const wxString& face = wxEmptyString, // facename
162 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ...
163
164 // from the font components but using the font flags instead of separate
165 // parameters for each flag
166 static wxFont *New(int pointSize,
167 wxFontFamily family,
168 int flags = wxFONTFLAG_DEFAULT,
169 const wxString& face = wxEmptyString,
170 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
171
172
173 // from the font components but using the font flags instead of separate
174 // parameters for each flag
175 static wxFont *New(const wxSize& pixelSize,
176 wxFontFamily family,
177 int flags = wxFONTFLAG_DEFAULT,
178 const wxString& face = wxEmptyString,
179 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
180
181 // from the (opaque) native font description object
182 static wxFont *New(const wxNativeFontInfo& nativeFontDesc);
183
184 // from the string representation of wxNativeFontInfo
185 static wxFont *New(const wxString& strNativeFontDesc);
186
187 // comparison
188 bool operator==(const wxFont& font) const;
189 bool operator!=(const wxFont& font) const { return !(*this == font); }
190
191 // accessors: get the font characteristics
192 virtual int GetPointSize() const = 0;
193 virtual wxSize GetPixelSize() const;
194 virtual bool IsUsingSizeInPixels() const;
195 virtual wxFontFamily GetFamily() const = 0;
196 virtual wxFontStyle GetStyle() const = 0;
197 virtual wxFontWeight GetWeight() const = 0;
198 virtual bool GetUnderlined() const = 0;
199 virtual wxString GetFaceName() const = 0;
200 virtual wxFontEncoding GetEncoding() const = 0;
201 virtual const wxNativeFontInfo *GetNativeFontInfo() const = 0;
202
203 virtual bool IsFixedWidth() const;
204
205 wxString GetNativeFontInfoDesc() const;
206 wxString GetNativeFontInfoUserDesc() const;
207
208 // change the font characteristics
209 virtual void SetPointSize( int pointSize ) = 0;
210 virtual void SetPixelSize( const wxSize& pixelSize );
211 virtual void SetFamily( wxFontFamily family ) = 0;
212 virtual void SetStyle( wxFontStyle style ) = 0;
213 virtual void SetWeight( wxFontWeight weight ) = 0;
214
215 virtual void SetUnderlined( bool underlined ) = 0;
216 virtual void SetEncoding(wxFontEncoding encoding) = 0;
217 virtual bool SetFaceName( const wxString& faceName );
218 void SetNativeFontInfo(const wxNativeFontInfo& info)
219 { DoSetNativeFontInfo(info); }
220
221 bool SetNativeFontInfo(const wxString& info);
222 bool SetNativeFontInfoUserDesc(const wxString& info);
223
224 // translate the fonts into human-readable string (i.e. GetStyleString()
225 // will return "wxITALIC" for an italic font, ...)
226 wxString GetFamilyString() const;
227 wxString GetStyleString() const;
228 wxString GetWeightString() const;
229
230 // Unofficial API, don't use
231 virtual void SetNoAntiAliasing( bool WXUNUSED(no) = true ) { }
232 virtual bool GetNoAntiAliasing() const { return false; }
233
234 // the default encoding is used for creating all fonts with default
235 // encoding parameter
236 static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
237 static void SetDefaultEncoding(wxFontEncoding encoding);
238
239 protected:
240 // the function called by both overloads of SetNativeFontInfo()
241 virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info);
242
243 private:
244 // the currently default encoding: by default, it's the default system
245 // encoding, but may be changed by the application using
246 // SetDefaultEncoding() to make all subsequent fonts created without
247 // specifying encoding parameter using this encoding
248 static wxFontEncoding ms_encodingDefault;
249 };
250
251 // wxFontBase <-> wxString utilities, used by wxConfig
252 WXDLLIMPEXP_CORE wxString wxToString(const wxFontBase& font);
253 WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxFontBase* font);
254
255
256 #if FUTURE_WXWIN_COMPATIBILITY_3_0
257 #define WXDECLARE_COMPAT_SETTERS \
258 wxDEPRECATED_FUTURE( void SetFamily(int family) ) \
259 { SetFamily((wxFontFamily)family); } \
260 wxDEPRECATED_FUTURE( void SetStyle(int style) ) \
261 { SetStyle((wxFontStyle)style); } \
262 wxDEPRECATED_FUTURE( void SetWeight(int weight) ) \
263 { SetWeight((wxFontWeight)weight); } \
264 wxDEPRECATED_FUTURE( void SetFamily(wxDeprecatedGUIConstants family) ) \
265 { SetFamily((wxFontFamily)family); } \
266 wxDEPRECATED_FUTURE( void SetStyle(wxDeprecatedGUIConstants style) ) \
267 { SetStyle((wxFontStyle)style); } \
268 wxDEPRECATED_FUTURE( void SetWeight(wxDeprecatedGUIConstants weight) ) \
269 { SetWeight((wxFontWeight)weight); }
270 #else
271 #define WXDECLARE_COMPAT_SETTERS /*empty*/
272 #endif
273
274 // include the real class declaration
275 #if defined(__WXPALMOS__)
276 #include "wx/palmos/font.h"
277 #elif defined(__WXMSW__)
278 #include "wx/msw/font.h"
279 #elif defined(__WXMOTIF__)
280 #include "wx/motif/font.h"
281 #elif defined(__WXGTK20__)
282 #include "wx/gtk/font.h"
283 #elif defined(__WXGTK__)
284 #include "wx/gtk1/font.h"
285 #elif defined(__WXX11__)
286 #include "wx/x11/font.h"
287 #elif defined(__WXMGL__)
288 #include "wx/mgl/font.h"
289 #elif defined(__WXDFB__)
290 #include "wx/dfb/font.h"
291 #elif defined(__WXMAC__)
292 #include "wx/osx/font.h"
293 #elif defined(__WXCOCOA__)
294 #include "wx/cocoa/font.h"
295 #elif defined(__WXPM__)
296 #include "wx/os2/font.h"
297 #endif
298
299 class WXDLLIMPEXP_CORE wxFontList: public wxGDIObjListBase
300 {
301 public:
302 wxFont *FindOrCreateFont(int pointSize,
303 wxFontFamily family,
304 wxFontStyle style,
305 wxFontWeight weight,
306 bool underline = false,
307 const wxString& face = wxEmptyString,
308 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
309
310 #if FUTURE_WXWIN_COMPATIBILITY_3_0
311 wxFont *FindOrCreateFont(int pointSize, int family, int style, int weight,
312 bool underline = false,
313 const wxString& face = wxEmptyString,
314 wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
315 { return FindOrCreateFont(pointSize, (wxFontFamily)family, (wxFontStyle)style,
316 (wxFontWeight)weight, underline, face, encoding); }
317 #endif
318
319 #if WXWIN_COMPATIBILITY_2_6
320 wxDEPRECATED( void AddFont(wxFont*) );
321 wxDEPRECATED( void RemoveFont(wxFont*) );
322 #endif
323 };
324
325 extern WXDLLIMPEXP_DATA_CORE(wxFontList*) wxTheFontList;
326
327
328 // provide comparison operators to allow code such as
329 //
330 // if ( font.GetStyle() == wxFONTSTYLE_SLANT )
331 //
332 // to compile without warnings which it would otherwise provoke from some
333 // compilers as it compares elements of different enums
334 #if FUTURE_WXWIN_COMPATIBILITY_3_0
335
336 inline bool operator==(wxFontFamily s, wxDeprecatedGUIConstants t)
337 { return static_cast<int>(s) == static_cast<int>(t); }
338 inline bool operator!=(wxFontFamily s, wxDeprecatedGUIConstants t)
339 { return !(s == t); }
340 inline bool operator==(wxFontStyle s, wxDeprecatedGUIConstants t)
341 { return static_cast<int>(s) == static_cast<int>(t); }
342 inline bool operator!=(wxFontStyle s, wxDeprecatedGUIConstants t)
343 { return !(s == t); }
344 inline bool operator==(wxFontWeight s, wxDeprecatedGUIConstants t)
345 { return static_cast<int>(s) == static_cast<int>(t); }
346 inline bool operator!=(wxFontWeight s, wxDeprecatedGUIConstants t)
347 { return !(s == t); }
348
349 #endif // FUTURE_WXWIN_COMPATIBILITY_3_0
350
351 #endif
352 // _WX_FONT_H_BASE_