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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "fontbase.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
23 #include "wx/defs.h" // for wxDEFAULT &c
24 #include "wx/fontenc.h" // the font encoding constants
25 #include "wx/gdiobj.h" // the base class
27 // ----------------------------------------------------------------------------
28 // forward declarations
29 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxFontData
;
32 class WXDLLEXPORT wxFontBase
;
33 class WXDLLEXPORT wxFont
;
34 class WXDLLEXPORT wxSize
;
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 // standard font families: these may be used only for the font creation, it
41 // doesn't make sense to query an existing font for its font family as,
42 // especially if the font had been created from a native font description, it
46 wxFONTFAMILY_DEFAULT
= wxDEFAULT
,
47 wxFONTFAMILY_DECORATIVE
= wxDECORATIVE
,
48 wxFONTFAMILY_ROMAN
= wxROMAN
,
49 wxFONTFAMILY_SCRIPT
= wxSCRIPT
,
50 wxFONTFAMILY_SWISS
= wxSWISS
,
51 wxFONTFAMILY_MODERN
= wxMODERN
,
52 wxFONTFAMILY_TELETYPE
= wxTELETYPE
,
54 wxFONTFAMILY_UNKNOWN
= wxFONTFAMILY_MAX
60 wxFONTSTYLE_NORMAL
= wxNORMAL
,
61 wxFONTSTYLE_ITALIC
= wxITALIC
,
62 wxFONTSTYLE_SLANT
= wxSLANT
,
69 wxFONTWEIGHT_NORMAL
= wxNORMAL
,
70 wxFONTWEIGHT_LIGHT
= wxLIGHT
,
71 wxFONTWEIGHT_BOLD
= wxBOLD
,
75 // the font flag bits for the new font ctor accepting one combined flags word
78 // no special flags: font with default weight/slant/anti-aliasing
79 wxFONTFLAG_DEFAULT
= 0,
81 // slant flags (default: no slant)
82 wxFONTFLAG_ITALIC
= 1 << 0,
83 wxFONTFLAG_SLANT
= 1 << 1,
85 // weight flags (default: medium)
86 wxFONTFLAG_LIGHT
= 1 << 2,
87 wxFONTFLAG_BOLD
= 1 << 3,
89 // anti-aliasing flag: force on or off (default: the current system default)
90 wxFONTFLAG_ANTIALIASED
= 1 << 4,
91 wxFONTFLAG_NOT_ANTIALIASED
= 1 << 5,
93 // underlined/strikethrough flags (default: no lines)
94 wxFONTFLAG_UNDERLINED
= 1 << 6,
95 wxFONTFLAG_STRIKETHROUGH
= 1 << 7,
97 // the mask of all currently used flags
98 wxFONTFLAG_MASK
= wxFONTFLAG_ITALIC
|
102 wxFONTFLAG_ANTIALIASED
|
103 wxFONTFLAG_NOT_ANTIALIASED
|
104 wxFONTFLAG_UNDERLINED
|
105 wxFONTFLAG_STRIKETHROUGH
108 // ----------------------------------------------------------------------------
109 // wxFontBase represents a font object
110 // ----------------------------------------------------------------------------
112 class WXDLLEXPORT wxFontRefData
;
113 struct WXDLLEXPORT wxNativeFontInfo
;
115 class WXDLLEXPORT wxFontBase
: public wxGDIObject
119 virtual ~wxFontBase();
121 // from the font components
123 int pointSize
, // size of the font in points
124 int family
, // see wxFontFamily enum
125 int style
, // see wxFontStyle enum
126 int weight
, // see wxFontWeight enum
127 bool underlined
= false, // not underlined by default
128 const wxString
& face
= wxEmptyString
, // facename
129 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
); // ISO8859-X, ...
131 // from the font components but using the font flags instead of separate
132 // parameters for each flag
133 static wxFont
*New(int pointSize
,
135 int flags
= wxFONTFLAG_DEFAULT
,
136 const wxString
& face
= wxEmptyString
,
137 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
139 // from the font components
141 const wxSize
& pixelSize
, // size of the font in pixels
142 int family
, // see wxFontFamily enum
143 int style
, // see wxFontStyle enum
144 int weight
, // see wxFontWeight enum
145 bool underlined
= false, // not underlined by default
146 const wxString
& face
= wxEmptyString
, // facename
147 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
); // ISO8859-X, ...
149 // from the font components but using the font flags instead of separate
150 // parameters for each flag
151 static wxFont
*New(const wxSize
& pixelSize
,
153 int flags
= wxFONTFLAG_DEFAULT
,
154 const wxString
& face
= wxEmptyString
,
155 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
157 // from the (opaque) native font description object
158 static wxFont
*New(const wxNativeFontInfo
& nativeFontDesc
);
160 // from the string representation of wxNativeFontInfo
161 static wxFont
*New(const wxString
& strNativeFontDesc
);
163 // was the font successfully created?
164 bool Ok() const { return m_refData
!= NULL
; }
167 bool operator == (const wxFont
& font
) const;
168 bool operator != (const wxFont
& font
) const;
170 // accessors: get the font characteristics
171 virtual int GetPointSize() const = 0;
172 virtual wxSize
GetPixelSize() const;
173 virtual bool IsUsingSizeInPixels() const;
174 virtual int GetFamily() const = 0;
175 virtual int GetStyle() const = 0;
176 virtual int GetWeight() const = 0;
177 virtual bool GetUnderlined() const = 0;
178 virtual wxString
GetFaceName() const = 0;
179 virtual wxFontEncoding
GetEncoding() const = 0;
180 virtual const wxNativeFontInfo
*GetNativeFontInfo() const = 0;
182 virtual bool IsFixedWidth() const;
184 wxString
GetNativeFontInfoDesc() const;
185 wxString
GetNativeFontInfoUserDesc() const;
187 // change the font characteristics
188 virtual void SetPointSize( int pointSize
) = 0;
189 virtual void SetPixelSize( const wxSize
& pixelSize
);
190 virtual void SetFamily( int family
) = 0;
191 virtual void SetStyle( int style
) = 0;
192 virtual void SetWeight( int weight
) = 0;
193 virtual void SetFaceName( const wxString
& faceName
) = 0;
194 virtual void SetUnderlined( bool underlined
) = 0;
195 virtual void SetEncoding(wxFontEncoding encoding
) = 0;
196 void SetNativeFontInfo(const wxNativeFontInfo
& info
)
197 { DoSetNativeFontInfo(info
); }
199 void SetNativeFontInfo(const wxString
& info
);
200 void SetNativeFontInfoUserDesc(const wxString
& info
);
202 // translate the fonts into human-readable string (i.e. GetStyleString()
203 // will return "wxITALIC" for an italic font, ...)
204 wxString
GetFamilyString() const;
205 wxString
GetStyleString() const;
206 wxString
GetWeightString() const;
208 // Unofficial API, don't use
209 virtual void SetNoAntiAliasing( bool WXUNUSED(no
) = true ) { }
210 virtual bool GetNoAntiAliasing() const { return false; }
212 // the default encoding is used for creating all fonts with default
213 // encoding parameter
214 static wxFontEncoding
GetDefaultEncoding() { return ms_encodingDefault
; }
215 static void SetDefaultEncoding(wxFontEncoding encoding
);
218 // get the internal data
219 wxFontRefData
*GetFontData() const
220 { return (wxFontRefData
*)m_refData
; }
222 // the function called by both overloads of SetNativeFontInfo()
223 virtual void DoSetNativeFontInfo(const wxNativeFontInfo
& info
);
226 // the currently default encoding: by default, it's the default system
227 // encoding, but may be changed by the application using
228 // SetDefaultEncoding() to make all subsequent fonts created without
229 // specifying encoding parameter using this encoding
230 static wxFontEncoding ms_encodingDefault
;
233 // include the real class declaration
234 #if defined(__WXPALMOS__)
235 #include "wx/palmos/font.h"
236 #elif defined(__WXMSW__)
237 #include "wx/msw/font.h"
238 #elif defined(__WXMOTIF__)
239 #include "wx/motif/font.h"
240 #elif defined(__WXGTK__)
241 #include "wx/gtk/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(__WXMAC__)
247 #include "wx/mac/font.h"
248 #elif defined(__WXCOCOA__)
249 #include "wx/cocoa/font.h"
250 #elif defined(__WXPM__)
251 #include "wx/os2/font.h"
254 // ----------------------------------------------------------------------------
256 // ----------------------------------------------------------------------------
258 #define M_FONTDATA GetFontData()