]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/font.h
XTI updates
[wxWidgets.git] / include / wx / font.h
... / ...
CommitLineData
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
28class WXDLLIMPEXP_FWD_CORE wxFont;
29
30// ----------------------------------------------------------------------------
31// font constants
32// ----------------------------------------------------------------------------
33
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
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,
47 wxFONTFAMILY_MAX,
48 wxFONTFAMILY_UNKNOWN = wxFONTFAMILY_MAX
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
69// the font flag bits for the new font ctor accepting one combined flags word
70enum wxFontFlag
71{
72 // no special flags: font with default weight/slant/anti-aliasing
73 wxFONTFLAG_DEFAULT = 0,
74
75 // slant flags (default: no slant)
76 wxFONTFLAG_ITALIC = 1 << 0,
77 wxFONTFLAG_SLANT = 1 << 1,
78
79 // weight flags (default: medium)
80 wxFONTFLAG_LIGHT = 1 << 2,
81 wxFONTFLAG_BOLD = 1 << 3,
82
83 // anti-aliasing flag: force on or off (default: the current system default)
84 wxFONTFLAG_ANTIALIASED = 1 << 4,
85 wxFONTFLAG_NOT_ANTIALIASED = 1 << 5,
86
87 // underlined/strikethrough flags (default: no lines)
88 wxFONTFLAG_UNDERLINED = 1 << 6,
89 wxFONTFLAG_STRIKETHROUGH = 1 << 7,
90
91 // the mask of all currently used flags
92 wxFONTFLAG_MASK = wxFONTFLAG_ITALIC |
93 wxFONTFLAG_SLANT |
94 wxFONTFLAG_LIGHT |
95 wxFONTFLAG_BOLD |
96 wxFONTFLAG_ANTIALIASED |
97 wxFONTFLAG_NOT_ANTIALIASED |
98 wxFONTFLAG_UNDERLINED |
99 wxFONTFLAG_STRIKETHROUGH
100};
101
102// ----------------------------------------------------------------------------
103// wxFontBase represents a font object
104// ----------------------------------------------------------------------------
105
106class WXDLLIMPEXP_FWD_CORE wxNativeFontInfo;
107
108class WXDLLIMPEXP_CORE wxFontBase : public wxGDIObject
109{
110public:
111 /*
112 derived classes should provide the following ctors:
113
114 wxFont();
115 wxFont(const wxString& nativeFontInfoString);
116 wxFont(const wxNativeFontInfo& info);
117 wxFont(int size,
118 wxFontFamily family,
119 wxFontStyle style,
120 wxFontWeight weight,
121 bool underlined = false,
122 const wxString& face = wxEmptyString,
123 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
124 wxFont(const wxSize& pixelSize,
125 wxFontFamily family,
126 wxFontStyle style,
127 wxFontWeight weight,
128 bool underlined = false,
129 const wxString& face = wxEmptyString,
130 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
131 */
132
133 // creator function
134 virtual ~wxFontBase();
135
136
137#if FUTURE_WXWIN_COMPATIBILITY_3_0
138 // from the font components
139 static wxFont *New(
140 int pointSize, // size of the font in points
141 int family, // see wxFontFamily enum
142 int style, // see wxFontStyle enum
143 int weight, // see wxFontWeight enum
144 bool underlined = false, // not underlined by default
145 const wxString& face = wxEmptyString, // facename
146 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) // ISO8859-X, ...
147 { return New(pointSize, (wxFontFamily)family, (wxFontStyle)style,
148 (wxFontWeight)weight, underlined, face, encoding); }
149
150 // from the font components
151 static wxFont *New(
152 const wxSize& pixelSize, // size of the font in pixels
153 int family, // see wxFontFamily enum
154 int style, // see wxFontStyle enum
155 int weight, // see wxFontWeight enum
156 bool underlined = false, // not underlined by default
157 const wxString& face = wxEmptyString, // facename
158 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) // ISO8859-X, ...
159 { return New(pixelSize, (wxFontFamily)family, (wxFontStyle)style,
160 (wxFontWeight)weight, underlined, face, encoding); }
161#endif
162
163 // from the font components
164 static wxFont *New(
165 int pointSize, // size of the font in points
166 wxFontFamily family, // see wxFontFamily enum
167 wxFontStyle style, // see wxFontStyle enum
168 wxFontWeight weight, // see wxFontWeight enum
169 bool underlined = false, // not underlined by default
170 const wxString& face = wxEmptyString, // facename
171 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ...
172
173 // from the font components
174 static wxFont *New(
175 const wxSize& pixelSize, // size of the font in pixels
176 wxFontFamily family, // see wxFontFamily enum
177 wxFontStyle style, // see wxFontStyle enum
178 wxFontWeight weight, // see wxFontWeight enum
179 bool underlined = false, // not underlined by default
180 const wxString& face = wxEmptyString, // facename
181 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ...
182
183 // from the font components but using the font flags instead of separate
184 // parameters for each flag
185 static wxFont *New(int pointSize,
186 wxFontFamily family,
187 int flags = wxFONTFLAG_DEFAULT,
188 const wxString& face = wxEmptyString,
189 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
190
191
192 // from the font components but using the font flags instead of separate
193 // parameters for each flag
194 static wxFont *New(const wxSize& pixelSize,
195 wxFontFamily family,
196 int flags = wxFONTFLAG_DEFAULT,
197 const wxString& face = wxEmptyString,
198 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
199
200 // from the (opaque) native font description object
201 static wxFont *New(const wxNativeFontInfo& nativeFontDesc);
202
203 // from the string representation of wxNativeFontInfo
204 static wxFont *New(const wxString& strNativeFontDesc);
205
206 // comparison
207 bool operator==(const wxFont& font) const;
208 bool operator!=(const wxFont& font) const { return !(*this == font); }
209
210 // accessors: get the font characteristics
211 virtual int GetPointSize() const = 0;
212 virtual wxSize GetPixelSize() const;
213 virtual bool IsUsingSizeInPixels() const;
214 wxFontFamily GetFamily() const;
215 virtual wxFontStyle GetStyle() const = 0;
216 virtual wxFontWeight GetWeight() const = 0;
217 virtual bool GetUnderlined() const = 0;
218 virtual wxString GetFaceName() const = 0;
219 virtual wxFontEncoding GetEncoding() const = 0;
220 virtual const wxNativeFontInfo *GetNativeFontInfo() const = 0;
221
222 virtual bool IsFixedWidth() const;
223
224 wxString GetNativeFontInfoDesc() const;
225 wxString GetNativeFontInfoUserDesc() const;
226
227 // change the font characteristics
228 virtual void SetPointSize( int pointSize ) = 0;
229 virtual void SetPixelSize( const wxSize& pixelSize );
230 virtual void SetFamily( wxFontFamily family ) = 0;
231 virtual void SetStyle( wxFontStyle style ) = 0;
232 virtual void SetWeight( wxFontWeight weight ) = 0;
233
234 virtual void SetUnderlined( bool underlined ) = 0;
235 virtual void SetEncoding(wxFontEncoding encoding) = 0;
236 virtual bool SetFaceName( const wxString& faceName );
237 void SetNativeFontInfo(const wxNativeFontInfo& info)
238 { DoSetNativeFontInfo(info); }
239
240 bool SetNativeFontInfo(const wxString& info);
241 bool SetNativeFontInfoUserDesc(const wxString& info);
242
243 // translate the fonts into human-readable string (i.e. GetStyleString()
244 // will return "wxITALIC" for an italic font, ...)
245 wxString GetFamilyString() const;
246 wxString GetStyleString() const;
247 wxString GetWeightString() const;
248
249 // the default encoding is used for creating all fonts with default
250 // encoding parameter
251 static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
252 static void SetDefaultEncoding(wxFontEncoding encoding);
253
254 // this doesn't do anything and is kept for compatibility only
255#ifdef WXWIN_COMPATIBILITY_2_8
256 wxDEPRECATED_INLINE(void SetNoAntiAliasing(bool no = true), wxUnusedVar(no););
257 wxDEPRECATED_INLINE(bool GetNoAntiAliasing() const, return false;)
258#endif // WXWIN_COMPATIBILITY_2_8
259
260protected:
261 // the function called by both overloads of SetNativeFontInfo()
262 virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info);
263
264 // The function called by public GetFamily(): it can return
265 // wxFONTFAMILY_UNKNOWN unlike the public method (see comment there).
266 virtual wxFontFamily DoGetFamily() const = 0;
267
268private:
269 // the currently default encoding: by default, it's the default system
270 // encoding, but may be changed by the application using
271 // SetDefaultEncoding() to make all subsequent fonts created without
272 // specifying encoding parameter using this encoding
273 static wxFontEncoding ms_encodingDefault;
274};
275
276// wxFontBase <-> wxString utilities, used by wxConfig
277WXDLLIMPEXP_CORE wxString wxToString(const wxFontBase& font);
278WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxFontBase* font);
279
280
281#if FUTURE_WXWIN_COMPATIBILITY_3_0
282#define wxDECLARE_FONT_COMPAT_SETTER \
283 wxDEPRECATED_FUTURE( void SetFamily(int family) ) \
284 { SetFamily((wxFontFamily)family); } \
285 wxDEPRECATED_FUTURE( void SetStyle(int style) ) \
286 { SetStyle((wxFontStyle)style); } \
287 wxDEPRECATED_FUTURE( void SetWeight(int weight) ) \
288 { SetWeight((wxFontWeight)weight); } \
289 wxDEPRECATED_FUTURE( void SetFamily(wxDeprecatedGUIConstants family) ) \
290 { SetFamily((wxFontFamily)family); } \
291 wxDEPRECATED_FUTURE( void SetStyle(wxDeprecatedGUIConstants style) ) \
292 { SetStyle((wxFontStyle)style); } \
293 wxDEPRECATED_FUTURE( void SetWeight(wxDeprecatedGUIConstants weight) ) \
294 { SetWeight((wxFontWeight)weight); }
295#else
296#define wxDECLARE_FONT_COMPAT_SETTER /*empty*/
297#endif
298
299// this macro must be used in all derived wxFont classes declarations
300#define wxDECLARE_COMMON_FONT_METHODS() \
301 wxDECLARE_FONT_COMPAT_SETTER \
302 \
303 /* functions for modifying font in place */ \
304 wxFont& MakeBold(); \
305 wxFont& MakeItalic(); \
306 wxFont& MakeLarger() { return Scale(1.2f); } \
307 wxFont& MakeSmaller() { return Scale(1/1.2f); } \
308 wxFont& Scale(float x); \
309 /* functions for creating fonts based on this one */ \
310 wxFont Bold() const; \
311 wxFont Italic() const; \
312 wxFont Larger() const { return Scaled(1.2f); } \
313 wxFont Smaller() const { return Scaled(1/1.2f); } \
314 wxFont Scaled(float x) const
315
316// include the real class declaration
317#if defined(__WXPALMOS__)
318 #include "wx/palmos/font.h"
319#elif defined(__WXMSW__)
320 #include "wx/msw/font.h"
321#elif defined(__WXMOTIF__)
322 #include "wx/motif/font.h"
323#elif defined(__WXGTK20__)
324 #include "wx/gtk/font.h"
325#elif defined(__WXGTK__)
326 #include "wx/gtk1/font.h"
327#elif defined(__WXX11__)
328 #include "wx/x11/font.h"
329#elif defined(__WXMGL__)
330 #include "wx/mgl/font.h"
331#elif defined(__WXDFB__)
332 #include "wx/dfb/font.h"
333#elif defined(__WXMAC__)
334 #include "wx/osx/font.h"
335#elif defined(__WXCOCOA__)
336 #include "wx/cocoa/font.h"
337#elif defined(__WXPM__)
338 #include "wx/os2/font.h"
339#endif
340
341class WXDLLIMPEXP_CORE wxFontList: public wxGDIObjListBase
342{
343public:
344 wxFont *FindOrCreateFont(int pointSize,
345 wxFontFamily family,
346 wxFontStyle style,
347 wxFontWeight weight,
348 bool underline = false,
349 const wxString& face = wxEmptyString,
350 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
351
352#if FUTURE_WXWIN_COMPATIBILITY_3_0
353 wxFont *FindOrCreateFont(int pointSize, int family, int style, int weight,
354 bool underline = false,
355 const wxString& face = wxEmptyString,
356 wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
357 { return FindOrCreateFont(pointSize, (wxFontFamily)family, (wxFontStyle)style,
358 (wxFontWeight)weight, underline, face, encoding); }
359#endif
360
361#if WXWIN_COMPATIBILITY_2_6
362 wxDEPRECATED( void AddFont(wxFont*) );
363 wxDEPRECATED( void RemoveFont(wxFont*) );
364#endif
365};
366
367extern WXDLLIMPEXP_DATA_CORE(wxFontList*) wxTheFontList;
368
369
370// provide comparison operators to allow code such as
371//
372// if ( font.GetStyle() == wxFONTSTYLE_SLANT )
373//
374// to compile without warnings which it would otherwise provoke from some
375// compilers as it compares elements of different enums
376#if FUTURE_WXWIN_COMPATIBILITY_3_0
377
378// Unfortunately some compilers have ambiguity issues when enum comparisons are
379// overloaded so we have to disable the overloads in this case, see
380// wxCOMPILER_NO_OVERLOAD_ON_ENUM definition in wx/platform.h for more details.
381#ifndef wxCOMPILER_NO_OVERLOAD_ON_ENUM
382
383inline bool operator==(wxFontFamily s, wxDeprecatedGUIConstants t)
384{ return static_cast<int>(s) == static_cast<int>(t); }
385inline bool operator!=(wxFontFamily s, wxDeprecatedGUIConstants t)
386{ return !(s == t); }
387inline bool operator==(wxFontStyle s, wxDeprecatedGUIConstants t)
388{ return static_cast<int>(s) == static_cast<int>(t); }
389inline bool operator!=(wxFontStyle s, wxDeprecatedGUIConstants t)
390{ return !(s == t); }
391inline bool operator==(wxFontWeight s, wxDeprecatedGUIConstants t)
392{ return static_cast<int>(s) == static_cast<int>(t); }
393inline bool operator!=(wxFontWeight s, wxDeprecatedGUIConstants t)
394{ return !(s == t); }
395
396#endif // // wxCOMPILER_NO_OVERLOAD_ON_ENUM
397
398#endif // FUTURE_WXWIN_COMPATIBILITY_3_0
399
400#endif
401 // _WX_FONT_H_BASE_