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
23 // ----------------------------------------------------------------------------
24 // forward declarations
25 // ----------------------------------------------------------------------------
27 class WXDLLIMPEXP_FWD_CORE wxFontData
;
28 class WXDLLIMPEXP_FWD_CORE wxFontBase
;
29 class WXDLLIMPEXP_FWD_CORE wxFont
;
30 class WXDLLIMPEXP_FWD_CORE wxSize
;
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 // standard font families: these may be used only for the font creation, it
37 // doesn't make sense to query an existing font for its font family as,
38 // especially if the font had been created from a native font description, it
42 wxFONTFAMILY_DEFAULT
= wxDEFAULT
,
43 wxFONTFAMILY_DECORATIVE
= wxDECORATIVE
,
44 wxFONTFAMILY_ROMAN
= wxROMAN
,
45 wxFONTFAMILY_SCRIPT
= wxSCRIPT
,
46 wxFONTFAMILY_SWISS
= wxSWISS
,
47 wxFONTFAMILY_MODERN
= wxMODERN
,
48 wxFONTFAMILY_TELETYPE
= wxTELETYPE
,
50 wxFONTFAMILY_UNKNOWN
= wxFONTFAMILY_MAX
56 wxFONTSTYLE_NORMAL
= wxNORMAL
,
57 wxFONTSTYLE_ITALIC
= wxITALIC
,
58 wxFONTSTYLE_SLANT
= wxSLANT
,
65 wxFONTWEIGHT_NORMAL
= wxNORMAL
,
66 wxFONTWEIGHT_LIGHT
= wxLIGHT
,
67 wxFONTWEIGHT_BOLD
= wxBOLD
,
71 // the font flag bits for the new font ctor accepting one combined flags word
74 // no special flags: font with default weight/slant/anti-aliasing
75 wxFONTFLAG_DEFAULT
= 0,
77 // slant flags (default: no slant)
78 wxFONTFLAG_ITALIC
= 1 << 0,
79 wxFONTFLAG_SLANT
= 1 << 1,
81 // weight flags (default: medium)
82 wxFONTFLAG_LIGHT
= 1 << 2,
83 wxFONTFLAG_BOLD
= 1 << 3,
85 // anti-aliasing flag: force on or off (default: the current system default)
86 wxFONTFLAG_ANTIALIASED
= 1 << 4,
87 wxFONTFLAG_NOT_ANTIALIASED
= 1 << 5,
89 // underlined/strikethrough flags (default: no lines)
90 wxFONTFLAG_UNDERLINED
= 1 << 6,
91 wxFONTFLAG_STRIKETHROUGH
= 1 << 7,
93 // the mask of all currently used flags
94 wxFONTFLAG_MASK
= wxFONTFLAG_ITALIC
|
98 wxFONTFLAG_ANTIALIASED
|
99 wxFONTFLAG_NOT_ANTIALIASED
|
100 wxFONTFLAG_UNDERLINED
|
101 wxFONTFLAG_STRIKETHROUGH
104 // ----------------------------------------------------------------------------
105 // wxFontBase represents a font object
106 // ----------------------------------------------------------------------------
108 class WXDLLIMPEXP_FWD_CORE wxNativeFontInfo
;
110 class WXDLLEXPORT wxFontBase
: public wxGDIObject
114 virtual ~wxFontBase();
116 // from the font components
118 int pointSize
, // size of the font in points
119 int family
, // see wxFontFamily enum
120 int style
, // see wxFontStyle enum
121 int weight
, // see wxFontWeight enum
122 bool underlined
= false, // not underlined by default
123 const wxString
& face
= wxEmptyString
, // facename
124 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
); // ISO8859-X, ...
126 // from the font components but using the font flags instead of separate
127 // parameters for each flag
128 static wxFont
*New(int pointSize
,
130 int flags
= wxFONTFLAG_DEFAULT
,
131 const wxString
& face
= wxEmptyString
,
132 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
134 // from the font components
136 const wxSize
& pixelSize
, // size of the font in pixels
137 int family
, // see wxFontFamily enum
138 int style
, // see wxFontStyle enum
139 int weight
, // see wxFontWeight enum
140 bool underlined
= false, // not underlined by default
141 const wxString
& face
= wxEmptyString
, // facename
142 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
); // ISO8859-X, ...
144 // from the font components but using the font flags instead of separate
145 // parameters for each flag
146 static wxFont
*New(const wxSize
& pixelSize
,
148 int flags
= wxFONTFLAG_DEFAULT
,
149 const wxString
& face
= wxEmptyString
,
150 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
152 // from the (opaque) native font description object
153 static wxFont
*New(const wxNativeFontInfo
& nativeFontDesc
);
155 // from the string representation of wxNativeFontInfo
156 static wxFont
*New(const wxString
& strNativeFontDesc
);
158 // was the font successfully created?
159 bool Ok() const { return IsOk(); }
160 bool IsOk() const { return m_refData
!= NULL
; }
163 bool operator == (const wxFont
& font
) const;
164 bool operator != (const wxFont
& font
) const;
166 // accessors: get the font characteristics
167 virtual int GetPointSize() const = 0;
168 virtual wxSize
GetPixelSize() const;
169 virtual bool IsUsingSizeInPixels() const;
170 virtual int GetFamily() const = 0;
171 virtual int GetStyle() const = 0;
172 virtual int GetWeight() const = 0;
173 virtual bool GetUnderlined() const = 0;
174 virtual wxString
GetFaceName() const = 0;
175 virtual wxFontEncoding
GetEncoding() const = 0;
176 virtual const wxNativeFontInfo
*GetNativeFontInfo() const = 0;
178 virtual bool IsFixedWidth() const;
180 wxString
GetNativeFontInfoDesc() const;
181 wxString
GetNativeFontInfoUserDesc() const;
183 // change the font characteristics
184 virtual void SetPointSize( int pointSize
) = 0;
185 virtual void SetPixelSize( const wxSize
& pixelSize
);
186 virtual void SetFamily( int family
) = 0;
187 virtual void SetStyle( int style
) = 0;
188 virtual void SetWeight( int weight
) = 0;
189 virtual void SetUnderlined( bool underlined
) = 0;
190 virtual void SetEncoding(wxFontEncoding encoding
) = 0;
191 virtual bool SetFaceName( const wxString
& faceName
);
192 void SetNativeFontInfo(const wxNativeFontInfo
& info
)
193 { DoSetNativeFontInfo(info
); }
195 bool SetNativeFontInfo(const wxString
& info
);
196 bool SetNativeFontInfoUserDesc(const wxString
& info
);
198 // translate the fonts into human-readable string (i.e. GetStyleString()
199 // will return "wxITALIC" for an italic font, ...)
200 wxString
GetFamilyString() const;
201 wxString
GetStyleString() const;
202 wxString
GetWeightString() const;
204 // Unofficial API, don't use
205 virtual void SetNoAntiAliasing( bool WXUNUSED(no
) = true ) { }
206 virtual bool GetNoAntiAliasing() const { return false; }
208 // the default encoding is used for creating all fonts with default
209 // encoding parameter
210 static wxFontEncoding
GetDefaultEncoding() { return ms_encodingDefault
; }
211 static void SetDefaultEncoding(wxFontEncoding encoding
);
214 // the function called by both overloads of SetNativeFontInfo()
215 virtual void DoSetNativeFontInfo(const wxNativeFontInfo
& info
);
218 // the currently default encoding: by default, it's the default system
219 // encoding, but may be changed by the application using
220 // SetDefaultEncoding() to make all subsequent fonts created without
221 // specifying encoding parameter using this encoding
222 static wxFontEncoding ms_encodingDefault
;
225 // wxFontBase <-> wxString utilities, used by wxConfig
226 WXDLLIMPEXP_CORE wxString
wxToString(const wxFontBase
& font
);
227 WXDLLIMPEXP_CORE
bool wxFromString(const wxString
& str
, wxFontBase
* font
);
231 // include the real class declaration
232 #if defined(__WXPALMOS__)
233 #include "wx/palmos/font.h"
234 #elif defined(__WXMSW__)
235 #include "wx/msw/font.h"
236 #elif defined(__WXMOTIF__)
237 #include "wx/motif/font.h"
238 #elif defined(__WXGTK20__)
239 #include "wx/gtk/font.h"
240 #elif defined(__WXGTK__)
241 #include "wx/gtk1/font.h"
242 #elif defined(__WXX11__)
243 #include "wx/x11/font.h"
244 #elif defined(__WXMGL__)
245 #include "wx/mgl/font.h"
246 #elif defined(__WXDFB__)
247 #include "wx/dfb/font.h"
248 #elif defined(__WXMAC__)
249 #include "wx/mac/font.h"
250 #elif defined(__WXCOCOA__)
251 #include "wx/cocoa/font.h"
252 #elif defined(__WXPM__)
253 #include "wx/os2/font.h"