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 wxFontData
;
29 class WXDLLIMPEXP_FWD_CORE wxFontBase
;
30 class WXDLLIMPEXP_FWD_CORE wxFont
;
31 class WXDLLIMPEXP_FWD_CORE wxSize
;
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
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
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
,
51 wxFONTFAMILY_UNKNOWN
= wxFONTFAMILY_MAX
57 wxFONTSTYLE_NORMAL
= wxNORMAL
,
58 wxFONTSTYLE_ITALIC
= wxITALIC
,
59 wxFONTSTYLE_SLANT
= wxSLANT
,
66 wxFONTWEIGHT_NORMAL
= wxNORMAL
,
67 wxFONTWEIGHT_LIGHT
= wxLIGHT
,
68 wxFONTWEIGHT_BOLD
= wxBOLD
,
72 // the font flag bits for the new font ctor accepting one combined flags word
75 // no special flags: font with default weight/slant/anti-aliasing
76 wxFONTFLAG_DEFAULT
= 0,
78 // slant flags (default: no slant)
79 wxFONTFLAG_ITALIC
= 1 << 0,
80 wxFONTFLAG_SLANT
= 1 << 1,
82 // weight flags (default: medium)
83 wxFONTFLAG_LIGHT
= 1 << 2,
84 wxFONTFLAG_BOLD
= 1 << 3,
86 // anti-aliasing flag: force on or off (default: the current system default)
87 wxFONTFLAG_ANTIALIASED
= 1 << 4,
88 wxFONTFLAG_NOT_ANTIALIASED
= 1 << 5,
90 // underlined/strikethrough flags (default: no lines)
91 wxFONTFLAG_UNDERLINED
= 1 << 6,
92 wxFONTFLAG_STRIKETHROUGH
= 1 << 7,
94 // the mask of all currently used flags
95 wxFONTFLAG_MASK
= wxFONTFLAG_ITALIC
|
99 wxFONTFLAG_ANTIALIASED
|
100 wxFONTFLAG_NOT_ANTIALIASED
|
101 wxFONTFLAG_UNDERLINED
|
102 wxFONTFLAG_STRIKETHROUGH
105 // ----------------------------------------------------------------------------
106 // wxFontBase represents a font object
107 // ----------------------------------------------------------------------------
109 class WXDLLIMPEXP_FWD_CORE wxNativeFontInfo
;
111 class WXDLLIMPEXP_CORE wxFontBase
: public wxGDIObject
115 derived classes should provide the following ctors:
118 wxFont(const wxString& nativeFontInfoString);
119 wxFont(const wxNativeFontInfo& info);
124 bool underlined = false,
125 const wxString& face = wxEmptyString,
126 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
127 wxFont(const wxSize& pixelSize,
131 bool underlined = false,
132 const wxString& face = wxEmptyString,
133 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
137 virtual ~wxFontBase();
140 #if FUTURE_WXWIN_COMPATIBILITY_3_0
141 // from the font components
143 int pointSize
, // size of the font in points
144 int family
, // see wxFontFamily enum
145 int style
, // see wxFontStyle enum
146 int weight
, // see wxFontWeight enum
147 bool underlined
= false, // not underlined by default
148 const wxString
& face
= wxEmptyString
, // facename
149 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
) // ISO8859-X, ...
150 { return New(pointSize
, (wxFontFamily
)family
, (wxFontStyle
)style
,
151 (wxFontWeight
)weight
, underlined
, face
, encoding
); }
153 // from the font components
155 const wxSize
& pixelSize
, // size of the font in pixels
156 int family
, // see wxFontFamily enum
157 int style
, // see wxFontStyle enum
158 int weight
, // see wxFontWeight enum
159 bool underlined
= false, // not underlined by default
160 const wxString
& face
= wxEmptyString
, // facename
161 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
) // ISO8859-X, ...
162 { return New(pixelSize
, (wxFontFamily
)family
, (wxFontStyle
)style
,
163 (wxFontWeight
)weight
, underlined
, face
, encoding
); }
166 // from the font components
168 int pointSize
, // size of the font in points
169 wxFontFamily family
, // see wxFontFamily enum
170 wxFontStyle style
, // see wxFontStyle enum
171 wxFontWeight weight
, // see wxFontWeight enum
172 bool underlined
= false, // not underlined by default
173 const wxString
& face
= wxEmptyString
, // facename
174 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
); // ISO8859-X, ...
176 // from the font components
178 const wxSize
& pixelSize
, // size of the font in pixels
179 wxFontFamily family
, // see wxFontFamily enum
180 wxFontStyle style
, // see wxFontStyle enum
181 wxFontWeight weight
, // see wxFontWeight enum
182 bool underlined
= false, // not underlined by default
183 const wxString
& face
= wxEmptyString
, // facename
184 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
); // ISO8859-X, ...
186 // from the font components but using the font flags instead of separate
187 // parameters for each flag
188 static wxFont
*New(int pointSize
,
190 int flags
= wxFONTFLAG_DEFAULT
,
191 const wxString
& face
= wxEmptyString
,
192 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
195 // from the font components but using the font flags instead of separate
196 // parameters for each flag
197 static wxFont
*New(const wxSize
& pixelSize
,
199 int flags
= wxFONTFLAG_DEFAULT
,
200 const wxString
& face
= wxEmptyString
,
201 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
203 // from the (opaque) native font description object
204 static wxFont
*New(const wxNativeFontInfo
& nativeFontDesc
);
206 // from the string representation of wxNativeFontInfo
207 static wxFont
*New(const wxString
& strNativeFontDesc
);
210 bool operator==(const wxFont
& font
) const;
211 bool operator!=(const wxFont
& font
) const { return !(*this == font
); }
213 // accessors: get the font characteristics
214 virtual int GetPointSize() const = 0;
215 virtual wxSize
GetPixelSize() const;
216 virtual bool IsUsingSizeInPixels() const;
217 virtual wxFontFamily
GetFamily() const = 0;
218 virtual wxFontStyle
GetStyle() const = 0;
219 virtual wxFontWeight
GetWeight() const = 0;
220 virtual bool GetUnderlined() const = 0;
221 virtual wxString
GetFaceName() const = 0;
222 virtual wxFontEncoding
GetEncoding() const = 0;
223 virtual const wxNativeFontInfo
*GetNativeFontInfo() const = 0;
225 virtual bool IsFixedWidth() const;
227 wxString
GetNativeFontInfoDesc() const;
228 wxString
GetNativeFontInfoUserDesc() const;
230 // change the font characteristics
231 virtual void SetPointSize( int pointSize
) = 0;
232 virtual void SetPixelSize( const wxSize
& pixelSize
);
233 virtual void SetFamily( wxFontFamily family
) = 0;
234 virtual void SetStyle( wxFontStyle style
) = 0;
235 virtual void SetWeight( wxFontWeight weight
) = 0;
237 virtual void SetUnderlined( bool underlined
) = 0;
238 virtual void SetEncoding(wxFontEncoding encoding
) = 0;
239 virtual bool SetFaceName( const wxString
& faceName
);
240 void SetNativeFontInfo(const wxNativeFontInfo
& info
)
241 { DoSetNativeFontInfo(info
); }
243 bool SetNativeFontInfo(const wxString
& info
);
244 bool SetNativeFontInfoUserDesc(const wxString
& info
);
246 // translate the fonts into human-readable string (i.e. GetStyleString()
247 // will return "wxITALIC" for an italic font, ...)
248 wxString
GetFamilyString() const;
249 wxString
GetStyleString() const;
250 wxString
GetWeightString() const;
252 // the default encoding is used for creating all fonts with default
253 // encoding parameter
254 static wxFontEncoding
GetDefaultEncoding() { return ms_encodingDefault
; }
255 static void SetDefaultEncoding(wxFontEncoding encoding
);
257 // this doesn't do anything and is kept for compatibility only
258 #ifdef WXWIN_COMPATIBILITY_2_8
259 wxDEPRECATED_INLINE(void SetNoAntiAliasing(bool no
= true), wxUnusedVar(no
););
260 wxDEPRECATED_INLINE(bool GetNoAntiAliasing() const, return false;)
261 #endif // WXWIN_COMPATIBILITY_2_8
264 // the function called by both overloads of SetNativeFontInfo()
265 virtual void DoSetNativeFontInfo(const wxNativeFontInfo
& info
);
268 // the currently default encoding: by default, it's the default system
269 // encoding, but may be changed by the application using
270 // SetDefaultEncoding() to make all subsequent fonts created without
271 // specifying encoding parameter using this encoding
272 static wxFontEncoding ms_encodingDefault
;
275 // wxFontBase <-> wxString utilities, used by wxConfig
276 WXDLLIMPEXP_CORE wxString
wxToString(const wxFontBase
& font
);
277 WXDLLIMPEXP_CORE
bool wxFromString(const wxString
& str
, wxFontBase
* font
);
280 #if FUTURE_WXWIN_COMPATIBILITY_3_0
281 #define wxDECLARE_FONT_COMPAT_SETTER \
282 wxDEPRECATED_FUTURE( void SetFamily(int family) ) \
283 { SetFamily((wxFontFamily)family); } \
284 wxDEPRECATED_FUTURE( void SetStyle(int style) ) \
285 { SetStyle((wxFontStyle)style); } \
286 wxDEPRECATED_FUTURE( void SetWeight(int weight) ) \
287 { SetWeight((wxFontWeight)weight); } \
288 wxDEPRECATED_FUTURE( void SetFamily(wxDeprecatedGUIConstants family) ) \
289 { SetFamily((wxFontFamily)family); } \
290 wxDEPRECATED_FUTURE( void SetStyle(wxDeprecatedGUIConstants style) ) \
291 { SetStyle((wxFontStyle)style); } \
292 wxDEPRECATED_FUTURE( void SetWeight(wxDeprecatedGUIConstants weight) ) \
293 { SetWeight((wxFontWeight)weight); }
295 #define wxDECLARE_FONT_COMPAT_SETTER /*empty*/
298 // this macro must be used in all derived wxFont classes declarations
299 #define wxDECLARE_COMMON_FONT_METHODS() \
300 wxDECLARE_FONT_COMPAT_SETTER \
302 /* functions for modifying font in place */ \
303 wxFont& MakeBold(); \
304 wxFont& MakeItalic(); \
305 wxFont& MakeLarger() { return Scale(1.2f); } \
306 wxFont& MakeSmaller() { return Scale(1/1.2f); } \
307 wxFont& Scale(float x); \
308 /* functions for creating fonts based on this one */ \
309 wxFont Bold() const; \
310 wxFont Italic() const; \
311 wxFont Larger() const { return Scaled(1.2f); } \
312 wxFont Smaller() const { return Scaled(1/1.2f); } \
313 wxFont Scaled(float x) const
315 // include the real class declaration
316 #if defined(__WXPALMOS__)
317 #include "wx/palmos/font.h"
318 #elif defined(__WXMSW__)
319 #include "wx/msw/font.h"
320 #elif defined(__WXMOTIF__)
321 #include "wx/motif/font.h"
322 #elif defined(__WXGTK20__)
323 #include "wx/gtk/font.h"
324 #elif defined(__WXGTK__)
325 #include "wx/gtk1/font.h"
326 #elif defined(__WXX11__)
327 #include "wx/x11/font.h"
328 #elif defined(__WXMGL__)
329 #include "wx/mgl/font.h"
330 #elif defined(__WXDFB__)
331 #include "wx/dfb/font.h"
332 #elif defined(__WXMAC__)
333 #include "wx/osx/font.h"
334 #elif defined(__WXCOCOA__)
335 #include "wx/cocoa/font.h"
336 #elif defined(__WXPM__)
337 #include "wx/os2/font.h"
340 class WXDLLIMPEXP_CORE wxFontList
: public wxGDIObjListBase
343 wxFont
*FindOrCreateFont(int pointSize
,
347 bool underline
= false,
348 const wxString
& face
= wxEmptyString
,
349 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
351 #if FUTURE_WXWIN_COMPATIBILITY_3_0
352 wxFont
*FindOrCreateFont(int pointSize
, int family
, int style
, int weight
,
353 bool underline
= false,
354 const wxString
& face
= wxEmptyString
,
355 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
)
356 { return FindOrCreateFont(pointSize
, (wxFontFamily
)family
, (wxFontStyle
)style
,
357 (wxFontWeight
)weight
, underline
, face
, encoding
); }
360 #if WXWIN_COMPATIBILITY_2_6
361 wxDEPRECATED( void AddFont(wxFont
*) );
362 wxDEPRECATED( void RemoveFont(wxFont
*) );
366 extern WXDLLIMPEXP_DATA_CORE(wxFontList
*) wxTheFontList
;
369 // provide comparison operators to allow code such as
371 // if ( font.GetStyle() == wxFONTSTYLE_SLANT )
373 // to compile without warnings which it would otherwise provoke from some
374 // compilers as it compares elements of different enums
375 #if FUTURE_WXWIN_COMPATIBILITY_3_0
377 inline bool operator==(wxFontFamily s
, wxDeprecatedGUIConstants t
)
378 { return static_cast<int>(s
) == static_cast<int>(t
); }
379 inline bool operator!=(wxFontFamily s
, wxDeprecatedGUIConstants t
)
380 { return !(s
== t
); }
381 inline bool operator==(wxFontStyle s
, wxDeprecatedGUIConstants t
)
382 { return static_cast<int>(s
) == static_cast<int>(t
); }
383 inline bool operator!=(wxFontStyle s
, wxDeprecatedGUIConstants t
)
384 { return !(s
== t
); }
385 inline bool operator==(wxFontWeight s
, wxDeprecatedGUIConstants t
)
386 { return static_cast<int>(s
) == static_cast<int>(t
); }
387 inline bool operator!=(wxFontWeight s
, wxDeprecatedGUIConstants t
)
388 { return !(s
== t
); }
390 #endif // FUTURE_WXWIN_COMPATIBILITY_3_0