1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFontBase class: the interface of wxFont
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_FONT_H_BASE_
13 #define _WX_FONT_H_BASE_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
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
24 // ----------------------------------------------------------------------------
25 // forward declarations
26 // ----------------------------------------------------------------------------
28 class WXDLLIMPEXP_FWD_CORE wxFont
;
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
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
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
,
48 wxFONTFAMILY_UNKNOWN
= wxFONTFAMILY_MAX
54 wxFONTSTYLE_NORMAL
= wxNORMAL
,
55 wxFONTSTYLE_ITALIC
= wxITALIC
,
56 wxFONTSTYLE_SLANT
= wxSLANT
,
63 wxFONTWEIGHT_NORMAL
= wxNORMAL
,
64 wxFONTWEIGHT_LIGHT
= wxLIGHT
,
65 wxFONTWEIGHT_BOLD
= wxBOLD
,
69 // the font flag bits for the new font ctor accepting one combined flags word
72 // no special flags: font with default weight/slant/anti-aliasing
73 wxFONTFLAG_DEFAULT
= 0,
75 // slant flags (default: no slant)
76 wxFONTFLAG_ITALIC
= 1 << 0,
77 wxFONTFLAG_SLANT
= 1 << 1,
79 // weight flags (default: medium)
80 wxFONTFLAG_LIGHT
= 1 << 2,
81 wxFONTFLAG_BOLD
= 1 << 3,
83 // anti-aliasing flag: force on or off (default: the current system default)
84 wxFONTFLAG_ANTIALIASED
= 1 << 4,
85 wxFONTFLAG_NOT_ANTIALIASED
= 1 << 5,
87 // underlined/strikethrough flags (default: no lines)
88 wxFONTFLAG_UNDERLINED
= 1 << 6,
89 wxFONTFLAG_STRIKETHROUGH
= 1 << 7,
91 // the mask of all currently used flags
92 wxFONTFLAG_MASK
= wxFONTFLAG_ITALIC
|
96 wxFONTFLAG_ANTIALIASED
|
97 wxFONTFLAG_NOT_ANTIALIASED
|
98 wxFONTFLAG_UNDERLINED
|
99 wxFONTFLAG_STRIKETHROUGH
102 // ----------------------------------------------------------------------------
103 // wxFontBase represents a font object
104 // ----------------------------------------------------------------------------
106 class WXDLLIMPEXP_FWD_CORE wxNativeFontInfo
;
108 class WXDLLIMPEXP_CORE wxFontBase
: public wxGDIObject
112 derived classes should provide the following ctors:
115 wxFont(const wxString& nativeFontInfoString);
116 wxFont(const wxNativeFontInfo& info);
121 bool underlined = false,
122 const wxString& face = wxEmptyString,
123 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
124 wxFont(const wxSize& pixelSize,
128 bool underlined = false,
129 const wxString& face = wxEmptyString,
130 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
134 virtual ~wxFontBase();
137 #if FUTURE_WXWIN_COMPATIBILITY_3_0
138 // from the font components
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
); }
150 // from the font components
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
); }
163 // from the font components
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, ...
173 // from the font components
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, ...
183 // from the font components but using the font flags instead of separate
184 // parameters for each flag
185 static wxFont
*New(int pointSize
,
187 int flags
= wxFONTFLAG_DEFAULT
,
188 const wxString
& face
= wxEmptyString
,
189 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
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
,
196 int flags
= wxFONTFLAG_DEFAULT
,
197 const wxString
& face
= wxEmptyString
,
198 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
200 // from the (opaque) native font description object
201 static wxFont
*New(const wxNativeFontInfo
& nativeFontDesc
);
203 // from the string representation of wxNativeFontInfo
204 static wxFont
*New(const wxString
& strNativeFontDesc
);
207 bool operator==(const wxFont
& font
) const;
208 bool operator!=(const wxFont
& font
) const { return !(*this == font
); }
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;
222 virtual bool IsFixedWidth() const;
224 wxString
GetNativeFontInfoDesc() const;
225 wxString
GetNativeFontInfoUserDesc() const;
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;
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
); }
240 bool SetNativeFontInfo(const wxString
& info
);
241 bool SetNativeFontInfoUserDesc(const wxString
& info
);
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;
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
);
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
261 // the function called by both overloads of SetNativeFontInfo()
262 virtual void DoSetNativeFontInfo(const wxNativeFontInfo
& info
);
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;
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
;
276 // wxFontBase <-> wxString utilities, used by wxConfig
277 WXDLLIMPEXP_CORE wxString
wxToString(const wxFontBase
& font
);
278 WXDLLIMPEXP_CORE
bool wxFromString(const wxString
& str
, wxFontBase
* font
);
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); }
296 #define wxDECLARE_FONT_COMPAT_SETTER /*empty*/
299 // this macro must be used in all derived wxFont classes declarations
300 #define wxDECLARE_COMMON_FONT_METHODS() \
301 wxDECLARE_FONT_COMPAT_SETTER \
303 /* functions for modifying font in place */ \
304 wxFont& MakeBold(); \
305 wxFont& MakeItalic(); \
306 wxFont& MakeUnderlined(); \
307 wxFont& MakeLarger() { return Scale(1.2f); } \
308 wxFont& MakeSmaller() { return Scale(1/1.2f); } \
309 wxFont& Scale(float x); \
310 /* functions for creating fonts based on this one */ \
311 wxFont Bold() const; \
312 wxFont Italic() const; \
313 wxFont Underlined() const; \
314 wxFont Larger() const { return Scaled(1.2f); } \
315 wxFont Smaller() const { return Scaled(1/1.2f); } \
316 wxFont Scaled(float x) const
318 // include the real class declaration
319 #if defined(__WXPALMOS__)
320 #include "wx/palmos/font.h"
321 #elif defined(__WXMSW__)
322 #include "wx/msw/font.h"
323 #elif defined(__WXMOTIF__)
324 #include "wx/motif/font.h"
325 #elif defined(__WXGTK20__)
326 #include "wx/gtk/font.h"
327 #elif defined(__WXGTK__)
328 #include "wx/gtk1/font.h"
329 #elif defined(__WXX11__)
330 #include "wx/x11/font.h"
331 #elif defined(__WXMGL__)
332 #include "wx/mgl/font.h"
333 #elif defined(__WXDFB__)
334 #include "wx/dfb/font.h"
335 #elif defined(__WXMAC__)
336 #include "wx/osx/font.h"
337 #elif defined(__WXCOCOA__)
338 #include "wx/cocoa/font.h"
339 #elif defined(__WXPM__)
340 #include "wx/os2/font.h"
343 class WXDLLIMPEXP_CORE wxFontList
: public wxGDIObjListBase
346 wxFont
*FindOrCreateFont(int pointSize
,
350 bool underline
= false,
351 const wxString
& face
= wxEmptyString
,
352 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
354 #if FUTURE_WXWIN_COMPATIBILITY_3_0
355 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
356 bool underline
= false,
357 const wxString
& face
= wxEmptyString
,
358 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
)
359 { return FindOrCreateFont(pointSize
, (wxFontFamily
)family
, (wxFontStyle
)style
,
360 (wxFontWeight
)weight
, underline
, face
, encoding
); }
363 #if WXWIN_COMPATIBILITY_2_6
364 wxDEPRECATED( void AddFont(wxFont
*) );
365 wxDEPRECATED( void RemoveFont(wxFont
*) );
369 extern WXDLLIMPEXP_DATA_CORE(wxFontList
*) wxTheFontList
;
372 // provide comparison operators to allow code such as
374 // if ( font.GetStyle() == wxFONTSTYLE_SLANT )
376 // to compile without warnings which it would otherwise provoke from some
377 // compilers as it compares elements of different enums
378 #if FUTURE_WXWIN_COMPATIBILITY_3_0
380 // Unfortunately some compilers have ambiguity issues when enum comparisons are
381 // overloaded so we have to disable the overloads in this case, see
382 // wxCOMPILER_NO_OVERLOAD_ON_ENUM definition in wx/platform.h for more details.
383 #ifndef wxCOMPILER_NO_OVERLOAD_ON_ENUM
385 inline bool operator==(wxFontFamily s
, wxDeprecatedGUIConstants t
)
386 { return static_cast<int>(s
) == static_cast<int>(t
); }
387 inline bool operator!=(wxFontFamily s
, wxDeprecatedGUIConstants t
)
388 { return !(s
== t
); }
389 inline bool operator==(wxFontStyle s
, wxDeprecatedGUIConstants t
)
390 { return static_cast<int>(s
) == static_cast<int>(t
); }
391 inline bool operator!=(wxFontStyle s
, wxDeprecatedGUIConstants t
)
392 { return !(s
== t
); }
393 inline bool operator==(wxFontWeight s
, wxDeprecatedGUIConstants t
)
394 { return static_cast<int>(s
) == static_cast<int>(t
); }
395 inline bool operator!=(wxFontWeight s
, wxDeprecatedGUIConstants t
)
396 { return !(s
== t
); }
398 #endif // // wxCOMPILER_NO_OVERLOAD_ON_ENUM
400 #endif // FUTURE_WXWIN_COMPATIBILITY_3_0