]> git.saurik.com Git - wxWidgets.git/blame - include/wx/font.h
remove unused variable assignment, closes #14928
[wxWidgets.git] / include / wx / font.h
CommitLineData
0c5d3e1c
VZ
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$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
0c5d3e1c
VZ
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_FONT_H_BASE_
13#define _WX_FONT_H_BASE_
c801d85f 14
0c5d3e1c
VZ
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19#include "wx/defs.h" // for wxDEFAULT &c
f6bcfd97 20#include "wx/fontenc.h" // the font encoding constants
0c5d3e1c 21#include "wx/gdiobj.h" // the base class
9d7a8e4a 22#include "wx/gdicmn.h" // for wxGDIObjListBase
0c5d3e1c
VZ
23
24// ----------------------------------------------------------------------------
25// forward declarations
26// ----------------------------------------------------------------------------
27
b5dbe15d 28class WXDLLIMPEXP_FWD_CORE wxFont;
0c5d3e1c
VZ
29
30// ----------------------------------------------------------------------------
31// font constants
32// ----------------------------------------------------------------------------
33
409d5a58
VZ
34// standard font families: these may be used only for the font creation, it
35// doesn't make sense to query an existing font for its font family as,
36// especially if the font had been created from a native font description, it
37// may be unknown
0c5d3e1c
VZ
38enum wxFontFamily
39{
40 wxFONTFAMILY_DEFAULT = wxDEFAULT,
41 wxFONTFAMILY_DECORATIVE = wxDECORATIVE,
42 wxFONTFAMILY_ROMAN = wxROMAN,
43 wxFONTFAMILY_SCRIPT = wxSCRIPT,
44 wxFONTFAMILY_SWISS = wxSWISS,
45 wxFONTFAMILY_MODERN = wxMODERN,
46 wxFONTFAMILY_TELETYPE = wxTELETYPE,
409d5a58
VZ
47 wxFONTFAMILY_MAX,
48 wxFONTFAMILY_UNKNOWN = wxFONTFAMILY_MAX
0c5d3e1c
VZ
49};
50
51// font styles
52enum wxFontStyle
53{
54 wxFONTSTYLE_NORMAL = wxNORMAL,
55 wxFONTSTYLE_ITALIC = wxITALIC,
56 wxFONTSTYLE_SLANT = wxSLANT,
57 wxFONTSTYLE_MAX
58};
59
60// font weights
61enum wxFontWeight
62{
63 wxFONTWEIGHT_NORMAL = wxNORMAL,
64 wxFONTWEIGHT_LIGHT = wxLIGHT,
65 wxFONTWEIGHT_BOLD = wxBOLD,
66 wxFONTWEIGHT_MAX
67};
68
19da7aaa
VZ
69// Symbolic font sizes as defined in CSS specification.
70enum wxFontSymbolicSize
71{
72 wxFONTSIZE_XX_SMALL = -3,
73 wxFONTSIZE_X_SMALL,
74 wxFONTSIZE_SMALL,
75 wxFONTSIZE_MEDIUM,
76 wxFONTSIZE_LARGE,
77 wxFONTSIZE_X_LARGE,
78 wxFONTSIZE_XX_LARGE
79};
80
01cb1c26 81// the font flag bits for the new font ctor accepting one combined flags word
0b70c946 82enum wxFontFlag
01cb1c26
VZ
83{
84 // no special flags: font with default weight/slant/anti-aliasing
85 wxFONTFLAG_DEFAULT = 0,
86
87 // slant flags (default: no slant)
88 wxFONTFLAG_ITALIC = 1 << 0,
89 wxFONTFLAG_SLANT = 1 << 1,
90
91 // weight flags (default: medium)
92 wxFONTFLAG_LIGHT = 1 << 2,
93 wxFONTFLAG_BOLD = 1 << 3,
94
95 // anti-aliasing flag: force on or off (default: the current system default)
96 wxFONTFLAG_ANTIALIASED = 1 << 4,
97 wxFONTFLAG_NOT_ANTIALIASED = 1 << 5,
98
99 // underlined/strikethrough flags (default: no lines)
100 wxFONTFLAG_UNDERLINED = 1 << 6,
101 wxFONTFLAG_STRIKETHROUGH = 1 << 7,
102
103 // the mask of all currently used flags
104 wxFONTFLAG_MASK = wxFONTFLAG_ITALIC |
105 wxFONTFLAG_SLANT |
106 wxFONTFLAG_LIGHT |
107 wxFONTFLAG_BOLD |
108 wxFONTFLAG_ANTIALIASED |
109 wxFONTFLAG_NOT_ANTIALIASED |
110 wxFONTFLAG_UNDERLINED |
111 wxFONTFLAG_STRIKETHROUGH
112};
113
0c5d3e1c
VZ
114// ----------------------------------------------------------------------------
115// wxFontBase represents a font object
116// ----------------------------------------------------------------------------
117
b5dbe15d 118class WXDLLIMPEXP_FWD_CORE wxNativeFontInfo;
4d85bcd1 119
53a2db12 120class WXDLLIMPEXP_CORE wxFontBase : public wxGDIObject
0c5d3e1c
VZ
121{
122public:
b5791cc7
FM
123 /*
124 derived classes should provide the following ctors:
03647350 125
b5791cc7
FM
126 wxFont();
127 wxFont(const wxString& nativeFontInfoString);
128 wxFont(const wxNativeFontInfo& info);
129 wxFont(int size,
130 wxFontFamily family,
131 wxFontStyle style,
132 wxFontWeight weight,
133 bool underlined = false,
134 const wxString& face = wxEmptyString,
135 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
136 wxFont(const wxSize& pixelSize,
137 wxFontFamily family,
138 wxFontStyle style,
139 wxFontWeight weight,
140 bool underlined = false,
141 const wxString& face = wxEmptyString,
142 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
143 */
03647350 144
0c5d3e1c 145 // creator function
799ea011 146 virtual ~wxFontBase();
7826e2dd 147
0c14b6c3
FM
148
149#if FUTURE_WXWIN_COMPATIBILITY_3_0
7826e2dd 150 // from the font components
0c5d3e1c
VZ
151 static wxFont *New(
152 int pointSize, // size of the font in points
153 int family, // see wxFontFamily enum
154 int style, // see wxFontStyle enum
155 int weight, // see wxFontWeight enum
a62848fd 156 bool underlined = false, // not underlined by default
0c5d3e1c 157 const wxString& face = wxEmptyString, // facename
0c14b6c3
FM
158 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) // ISO8859-X, ...
159 { return New(pointSize, (wxFontFamily)family, (wxFontStyle)style,
160 (wxFontWeight)weight, underlined, face, encoding); }
01cb1c26 161
544229d1
VZ
162 // from the font components
163 static wxFont *New(
164 const wxSize& pixelSize, // size of the font in pixels
165 int family, // see wxFontFamily enum
166 int style, // see wxFontStyle enum
167 int weight, // see wxFontWeight enum
4055ed82 168 bool underlined = false, // not underlined by default
544229d1 169 const wxString& face = wxEmptyString, // facename
0c14b6c3
FM
170 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) // ISO8859-X, ...
171 { return New(pixelSize, (wxFontFamily)family, (wxFontStyle)style,
172 (wxFontWeight)weight, underlined, face, encoding); }
173#endif
174
175 // from the font components
176 static wxFont *New(
177 int pointSize, // size of the font in points
178 wxFontFamily family, // see wxFontFamily enum
179 wxFontStyle style, // see wxFontStyle enum
180 wxFontWeight weight, // see wxFontWeight enum
181 bool underlined = false, // not underlined by default
182 const wxString& face = wxEmptyString, // facename
544229d1
VZ
183 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ...
184
0c14b6c3
FM
185 // from the font components
186 static wxFont *New(
187 const wxSize& pixelSize, // size of the font in pixels
188 wxFontFamily family, // see wxFontFamily enum
189 wxFontStyle style, // see wxFontStyle enum
190 wxFontWeight weight, // see wxFontWeight enum
191 bool underlined = false, // not underlined by default
192 const wxString& face = wxEmptyString, // facename
193 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ...
194
195 // from the font components but using the font flags instead of separate
196 // parameters for each flag
197 static wxFont *New(int pointSize,
198 wxFontFamily family,
199 int flags = wxFONTFLAG_DEFAULT,
200 const wxString& face = wxEmptyString,
201 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
202
203
544229d1
VZ
204 // from the font components but using the font flags instead of separate
205 // parameters for each flag
206 static wxFont *New(const wxSize& pixelSize,
207 wxFontFamily family,
208 int flags = wxFONTFLAG_DEFAULT,
209 const wxString& face = wxEmptyString,
210 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
211
7826e2dd
VZ
212 // from the (opaque) native font description object
213 static wxFont *New(const wxNativeFontInfo& nativeFontDesc);
214
215 // from the string representation of wxNativeFontInfo
216 static wxFont *New(const wxString& strNativeFontDesc);
0c5d3e1c 217
0c5d3e1c 218 // comparison
8f884a0d
VZ
219 bool operator==(const wxFont& font) const;
220 bool operator!=(const wxFont& font) const { return !(*this == font); }
0c5d3e1c
VZ
221
222 // accessors: get the font characteristics
223 virtual int GetPointSize() const = 0;
544229d1
VZ
224 virtual wxSize GetPixelSize() const;
225 virtual bool IsUsingSizeInPixels() const;
59b7da02 226 wxFontFamily GetFamily() const;
0c14b6c3
FM
227 virtual wxFontStyle GetStyle() const = 0;
228 virtual wxFontWeight GetWeight() const = 0;
0c5d3e1c 229 virtual bool GetUnderlined() const = 0;
c7a49742 230 virtual bool GetStrikethrough() const { return false; }
0c5d3e1c
VZ
231 virtual wxString GetFaceName() const = 0;
232 virtual wxFontEncoding GetEncoding() const = 0;
3bf5a59b 233 virtual const wxNativeFontInfo *GetNativeFontInfo() const = 0;
ab5fe833 234
53f6aab7
VZ
235 virtual bool IsFixedWidth() const;
236
7826e2dd 237 wxString GetNativeFontInfoDesc() const;
ab5fe833 238 wxString GetNativeFontInfoUserDesc() const;
0c5d3e1c
VZ
239
240 // change the font characteristics
241 virtual void SetPointSize( int pointSize ) = 0;
544229d1 242 virtual void SetPixelSize( const wxSize& pixelSize );
0c14b6c3
FM
243 virtual void SetFamily( wxFontFamily family ) = 0;
244 virtual void SetStyle( wxFontStyle style ) = 0;
245 virtual void SetWeight( wxFontWeight weight ) = 0;
246
0c5d3e1c 247 virtual void SetUnderlined( bool underlined ) = 0;
c7a49742 248 virtual void SetStrikethrough( bool WXUNUSED(strikethrough) ) {}
0c5d3e1c 249 virtual void SetEncoding(wxFontEncoding encoding) = 0;
85ab460e 250 virtual bool SetFaceName( const wxString& faceName );
9045ad9d
VZ
251 void SetNativeFontInfo(const wxNativeFontInfo& info)
252 { DoSetNativeFontInfo(info); }
ab5fe833 253
85ab460e
VZ
254 bool SetNativeFontInfo(const wxString& info);
255 bool SetNativeFontInfoUserDesc(const wxString& info);
7826e2dd 256
19da7aaa
VZ
257 // Symbolic font sizes support: set the font size to "large" or "very
258 // small" either absolutely (i.e. compared to the default font size) or
259 // relatively to the given font size.
260 void SetSymbolicSize(wxFontSymbolicSize size);
261 void SetSymbolicSizeRelativeTo(wxFontSymbolicSize size, int base)
262 {
263 SetPointSize(AdjustToSymbolicSize(size, base));
264 }
265
266 // Adjust the base size in points according to symbolic size.
267 static int AdjustToSymbolicSize(wxFontSymbolicSize size, int base);
268
269
0c5d3e1c
VZ
270 // translate the fonts into human-readable string (i.e. GetStyleString()
271 // will return "wxITALIC" for an italic font, ...)
272 wxString GetFamilyString() const;
273 wxString GetStyleString() const;
274 wxString GetWeightString() const;
275
276 // the default encoding is used for creating all fonts with default
277 // encoding parameter
cafbf6fb
VZ
278 static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
279 static void SetDefaultEncoding(wxFontEncoding encoding);
0c5d3e1c 280
8462a84b 281 // this doesn't do anything and is kept for compatibility only
7bc57fd9 282#if WXWIN_COMPATIBILITY_2_8
8462a84b
VZ
283 wxDEPRECATED_INLINE(void SetNoAntiAliasing(bool no = true), wxUnusedVar(no););
284 wxDEPRECATED_INLINE(bool GetNoAntiAliasing() const, return false;)
285#endif // WXWIN_COMPATIBILITY_2_8
286
0c5d3e1c 287protected:
9045ad9d
VZ
288 // the function called by both overloads of SetNativeFontInfo()
289 virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info);
290
59b7da02
VZ
291 // The function called by public GetFamily(): it can return
292 // wxFONTFAMILY_UNKNOWN unlike the public method (see comment there).
293 virtual wxFontFamily DoGetFamily() const = 0;
294
0634700a
VZ
295
296 // Helper functions to recover wxFONTSTYLE/wxFONTWEIGHT and underlined flg
297 // values from flags containing a combination of wxFONTFLAG_XXX.
298 static wxFontStyle GetStyleFromFlags(int flags)
299 {
300 return flags & wxFONTFLAG_ITALIC
301 ? wxFONTSTYLE_ITALIC
302 : flags & wxFONTFLAG_SLANT
303 ? wxFONTSTYLE_SLANT
304 : wxFONTSTYLE_NORMAL;
305 }
306
307 static wxFontWeight GetWeightFromFlags(int flags)
308 {
309 return flags & wxFONTFLAG_LIGHT
310 ? wxFONTWEIGHT_LIGHT
311 : flags & wxFONTFLAG_BOLD
312 ? wxFONTWEIGHT_BOLD
313 : wxFONTWEIGHT_NORMAL;
314 }
315
316 static bool GetUnderlinedFromFlags(int flags)
317 {
318 return (flags & wxFONTFLAG_UNDERLINED) != 0;
319 }
320
cba4e486
VZ
321 static bool GetStrikethroughFromFlags(int flags)
322 {
323 return (flags & wxFONTFLAG_STRIKETHROUGH) != 0;
324 }
0634700a 325
0c5d3e1c
VZ
326private:
327 // the currently default encoding: by default, it's the default system
328 // encoding, but may be changed by the application using
329 // SetDefaultEncoding() to make all subsequent fonts created without
3103e8a9 330 // specifying encoding parameter using this encoding
0c5d3e1c
VZ
331 static wxFontEncoding ms_encodingDefault;
332};
333
fc9361e3
VZ
334// wxFontBase <-> wxString utilities, used by wxConfig
335WXDLLIMPEXP_CORE wxString wxToString(const wxFontBase& font);
336WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxFontBase* font);
337
338
0c14b6c3 339#if FUTURE_WXWIN_COMPATIBILITY_3_0
f76c0758 340#define wxDECLARE_FONT_COMPAT_SETTER \
0c14b6c3
FM
341 wxDEPRECATED_FUTURE( void SetFamily(int family) ) \
342 { SetFamily((wxFontFamily)family); } \
343 wxDEPRECATED_FUTURE( void SetStyle(int style) ) \
344 { SetStyle((wxFontStyle)style); } \
345 wxDEPRECATED_FUTURE( void SetWeight(int weight) ) \
346 { SetWeight((wxFontWeight)weight); } \
347 wxDEPRECATED_FUTURE( void SetFamily(wxDeprecatedGUIConstants family) ) \
348 { SetFamily((wxFontFamily)family); } \
349 wxDEPRECATED_FUTURE( void SetStyle(wxDeprecatedGUIConstants style) ) \
350 { SetStyle((wxFontStyle)style); } \
351 wxDEPRECATED_FUTURE( void SetWeight(wxDeprecatedGUIConstants weight) ) \
352 { SetWeight((wxFontWeight)weight); }
353#else
f76c0758 354#define wxDECLARE_FONT_COMPAT_SETTER /*empty*/
0c14b6c3 355#endif
fc9361e3 356
f76c0758
VZ
357// this macro must be used in all derived wxFont classes declarations
358#define wxDECLARE_COMMON_FONT_METHODS() \
359 wxDECLARE_FONT_COMPAT_SETTER \
360 \
6e7d2550
VZ
361 /* functions for modifying font in place */ \
362 wxFont& MakeBold(); \
363 wxFont& MakeItalic(); \
801423ee 364 wxFont& MakeUnderlined(); \
c7a49742 365 wxFont& MakeStrikethrough(); \
6e7d2550
VZ
366 wxFont& MakeLarger() { return Scale(1.2f); } \
367 wxFont& MakeSmaller() { return Scale(1/1.2f); } \
368 wxFont& Scale(float x); \
f76c0758 369 /* functions for creating fonts based on this one */ \
6e7d2550
VZ
370 wxFont Bold() const; \
371 wxFont Italic() const; \
801423ee 372 wxFont Underlined() const; \
c7a49742 373 wxFont Strikethrough() const; \
6e7d2550
VZ
374 wxFont Larger() const { return Scaled(1.2f); } \
375 wxFont Smaller() const { return Scaled(1/1.2f); } \
376 wxFont Scaled(float x) const
f76c0758 377
0c5d3e1c 378// include the real class declaration
bd362275 379#if defined(__WXMSW__)
0c5d3e1c 380 #include "wx/msw/font.h"
2049ba38 381#elif defined(__WXMOTIF__)
0c5d3e1c 382 #include "wx/motif/font.h"
1be7a35c 383#elif defined(__WXGTK20__)
0c5d3e1c 384 #include "wx/gtk/font.h"
1be7a35c
MR
385#elif defined(__WXGTK__)
386 #include "wx/gtk1/font.h"
83df96d6
JS
387#elif defined(__WXX11__)
388 #include "wx/x11/font.h"
b3c86150
VS
389#elif defined(__WXDFB__)
390 #include "wx/dfb/font.h"
34138703 391#elif defined(__WXMAC__)
ef0e9220 392 #include "wx/osx/font.h"
e64df9bc
DE
393#elif defined(__WXCOCOA__)
394 #include "wx/cocoa/font.h"
1777b9bb 395#elif defined(__WXPM__)
0c5d3e1c 396 #include "wx/os2/font.h"
c801d85f
KB
397#endif
398
82cddbd9
FM
399class WXDLLIMPEXP_CORE wxFontList: public wxGDIObjListBase
400{
401public:
402 wxFont *FindOrCreateFont(int pointSize,
403 wxFontFamily family,
404 wxFontStyle style,
405 wxFontWeight weight,
406 bool underline = false,
407 const wxString& face = wxEmptyString,
408 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
020eeaa8
FM
409
410#if FUTURE_WXWIN_COMPATIBILITY_3_0
411 wxFont *FindOrCreateFont(int pointSize, int family, int style, int weight,
412 bool underline = false,
413 const wxString& face = wxEmptyString,
414 wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
415 { return FindOrCreateFont(pointSize, (wxFontFamily)family, (wxFontStyle)style,
416 (wxFontWeight)weight, underline, face, encoding); }
417#endif
418
82cddbd9
FM
419#if WXWIN_COMPATIBILITY_2_6
420 wxDEPRECATED( void AddFont(wxFont*) );
421 wxDEPRECATED( void RemoveFont(wxFont*) );
422#endif
423};
424
53a2db12 425extern WXDLLIMPEXP_DATA_CORE(wxFontList*) wxTheFontList;
82cddbd9 426
0c14b6c3
FM
427
428// provide comparison operators to allow code such as
429//
430// if ( font.GetStyle() == wxFONTSTYLE_SLANT )
431//
432// to compile without warnings which it would otherwise provoke from some
433// compilers as it compares elements of different enums
434#if FUTURE_WXWIN_COMPATIBILITY_3_0
435
25859335
VZ
436// Unfortunately some compilers have ambiguity issues when enum comparisons are
437// overloaded so we have to disable the overloads in this case, see
438// wxCOMPILER_NO_OVERLOAD_ON_ENUM definition in wx/platform.h for more details.
439#ifndef wxCOMPILER_NO_OVERLOAD_ON_ENUM
440
0c14b6c3
FM
441inline bool operator==(wxFontFamily s, wxDeprecatedGUIConstants t)
442{ return static_cast<int>(s) == static_cast<int>(t); }
443inline bool operator!=(wxFontFamily s, wxDeprecatedGUIConstants t)
444{ return !(s == t); }
445inline bool operator==(wxFontStyle s, wxDeprecatedGUIConstants t)
446{ return static_cast<int>(s) == static_cast<int>(t); }
447inline bool operator!=(wxFontStyle s, wxDeprecatedGUIConstants t)
448{ return !(s == t); }
449inline bool operator==(wxFontWeight s, wxDeprecatedGUIConstants t)
450{ return static_cast<int>(s) == static_cast<int>(t); }
451inline bool operator!=(wxFontWeight s, wxDeprecatedGUIConstants t)
452{ return !(s == t); }
453
25859335
VZ
454#endif // // wxCOMPILER_NO_OVERLOAD_ON_ENUM
455
0c14b6c3
FM
456#endif // FUTURE_WXWIN_COMPATIBILITY_3_0
457
c801d85f 458#endif
34138703 459 // _WX_FONT_H_BASE_