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
;
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // standard font families: these may be used only for the font creation, it
40 // doesn't make sense to query an existing font for its font family as,
41 // especially if the font had been created from a native font description, it
45 wxFONTFAMILY_DEFAULT
= wxDEFAULT
,
46 wxFONTFAMILY_DECORATIVE
= wxDECORATIVE
,
47 wxFONTFAMILY_ROMAN
= wxROMAN
,
48 wxFONTFAMILY_SCRIPT
= wxSCRIPT
,
49 wxFONTFAMILY_SWISS
= wxSWISS
,
50 wxFONTFAMILY_MODERN
= wxMODERN
,
51 wxFONTFAMILY_TELETYPE
= wxTELETYPE
,
53 wxFONTFAMILY_UNKNOWN
= wxFONTFAMILY_MAX
59 wxFONTSTYLE_NORMAL
= wxNORMAL
,
60 wxFONTSTYLE_ITALIC
= wxITALIC
,
61 wxFONTSTYLE_SLANT
= wxSLANT
,
68 wxFONTWEIGHT_NORMAL
= wxNORMAL
,
69 wxFONTWEIGHT_LIGHT
= wxLIGHT
,
70 wxFONTWEIGHT_BOLD
= wxBOLD
,
74 // the font flag bits for the new font ctor accepting one combined flags word
77 // no special flags: font with default weight/slant/anti-aliasing
78 wxFONTFLAG_DEFAULT
= 0,
80 // slant flags (default: no slant)
81 wxFONTFLAG_ITALIC
= 1 << 0,
82 wxFONTFLAG_SLANT
= 1 << 1,
84 // weight flags (default: medium)
85 wxFONTFLAG_LIGHT
= 1 << 2,
86 wxFONTFLAG_BOLD
= 1 << 3,
88 // anti-aliasing flag: force on or off (default: the current system default)
89 wxFONTFLAG_ANTIALIASED
= 1 << 4,
90 wxFONTFLAG_NOT_ANTIALIASED
= 1 << 5,
92 // underlined/strikethrough flags (default: no lines)
93 wxFONTFLAG_UNDERLINED
= 1 << 6,
94 wxFONTFLAG_STRIKETHROUGH
= 1 << 7,
96 // the mask of all currently used flags
97 wxFONTFLAG_MASK
= wxFONTFLAG_ITALIC
|
101 wxFONTFLAG_ANTIALIASED
|
102 wxFONTFLAG_NOT_ANTIALIASED
|
103 wxFONTFLAG_UNDERLINED
|
104 wxFONTFLAG_STRIKETHROUGH
107 // ----------------------------------------------------------------------------
108 // wxFontBase represents a font object
109 // ----------------------------------------------------------------------------
111 class WXDLLEXPORT wxFontRefData
;
112 struct WXDLLEXPORT wxNativeFontInfo
;
114 class WXDLLEXPORT wxFontBase
: public wxGDIObject
118 virtual ~wxFontBase();
120 // from the font components
122 int pointSize
, // size of the font in points
123 int family
, // see wxFontFamily enum
124 int style
, // see wxFontStyle enum
125 int weight
, // see wxFontWeight enum
126 bool underlined
= false, // not underlined by default
127 const wxString
& face
= wxEmptyString
, // facename
128 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
); // ISO8859-X, ...
130 // from the font components but using the font flags instead of separate
131 // parameters for each flag
132 static wxFont
*New(int pointSize
,
134 int flags
= wxFONTFLAG_DEFAULT
,
135 const wxString
& face
= wxEmptyString
,
136 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
138 // from the font components
140 const wxSize
& pixelSize
, // size of the font in pixels
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, ...
148 // from the font components but using the font flags instead of separate
149 // parameters for each flag
150 static wxFont
*New(const wxSize
& pixelSize
,
152 int flags
= wxFONTFLAG_DEFAULT
,
153 const wxString
& face
= wxEmptyString
,
154 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
156 // from the (opaque) native font description object
157 static wxFont
*New(const wxNativeFontInfo
& nativeFontDesc
);
159 // from the string representation of wxNativeFontInfo
160 static wxFont
*New(const wxString
& strNativeFontDesc
);
162 // was the font successfully created?
163 bool Ok() const { return m_refData
!= NULL
; }
166 bool operator == (const wxFont
& font
) const;
167 bool operator != (const wxFont
& font
) const;
169 // accessors: get the font characteristics
170 virtual int GetPointSize() const = 0;
171 virtual wxSize
GetPixelSize() const;
172 virtual bool IsUsingSizeInPixels() const;
173 virtual int GetFamily() const = 0;
174 virtual int GetStyle() const = 0;
175 virtual int GetWeight() const = 0;
176 virtual bool GetUnderlined() const = 0;
177 virtual wxString
GetFaceName() const = 0;
178 virtual wxFontEncoding
GetEncoding() const = 0;
179 virtual const wxNativeFontInfo
*GetNativeFontInfo() const = 0;
181 virtual bool IsFixedWidth() const;
183 wxString
GetNativeFontInfoDesc() const;
184 wxString
GetNativeFontInfoUserDesc() const;
186 // change the font characteristics
187 virtual void SetPointSize( int pointSize
) = 0;
188 virtual void SetPixelSize( const wxSize
& pixelSize
);
189 virtual void SetFamily( int family
) = 0;
190 virtual void SetStyle( int style
) = 0;
191 virtual void SetWeight( int weight
) = 0;
192 virtual void SetFaceName( const wxString
& faceName
) = 0;
193 virtual void SetUnderlined( bool underlined
) = 0;
194 virtual void SetEncoding(wxFontEncoding encoding
) = 0;
195 void SetNativeFontInfo(const wxNativeFontInfo
& info
)
196 { DoSetNativeFontInfo(info
); }
198 void SetNativeFontInfo(const wxString
& info
);
199 void SetNativeFontInfoUserDesc(const wxString
& info
);
201 // translate the fonts into human-readable string (i.e. GetStyleString()
202 // will return "wxITALIC" for an italic font, ...)
203 wxString
GetFamilyString() const;
204 wxString
GetStyleString() const;
205 wxString
GetWeightString() const;
207 // Unofficial API, don't use
208 virtual void SetNoAntiAliasing( bool WXUNUSED(no
) = true ) { }
209 virtual bool GetNoAntiAliasing() const { return false; }
211 // the default encoding is used for creating all fonts with default
212 // encoding parameter
213 static wxFontEncoding
GetDefaultEncoding() { return ms_encodingDefault
; }
214 static void SetDefaultEncoding(wxFontEncoding encoding
);
217 // get the internal data
218 wxFontRefData
*GetFontData() const
219 { return (wxFontRefData
*)m_refData
; }
221 // the function called by both overloads of SetNativeFontInfo()
222 virtual void DoSetNativeFontInfo(const wxNativeFontInfo
& info
);
225 // the currently default encoding: by default, it's the default system
226 // encoding, but may be changed by the application using
227 // SetDefaultEncoding() to make all subsequent fonts created without
228 // specifing encoding parameter using this encoding
229 static wxFontEncoding ms_encodingDefault
;
232 // include the real class declaration
233 #if defined(__WXMSW__)
234 #include "wx/msw/font.h"
235 #elif defined(__WXMOTIF__)
236 #include "wx/motif/font.h"
237 #elif defined(__WXGTK__)
238 #include "wx/gtk/font.h"
239 #elif defined(__WXX11__)
240 #include "wx/x11/font.h"
241 #elif defined(__WXMGL__)
242 #include "wx/mgl/font.h"
243 #elif defined(__WXMAC__)
244 #include "wx/mac/font.h"
245 #elif defined(__WXCOCOA__)
246 #include "wx/cocoa/font.h"
247 #elif defined(__WXPM__)
248 #include "wx/os2/font.h"
251 // ----------------------------------------------------------------------------
253 // ----------------------------------------------------------------------------
255 #define M_FONTDATA GetFontData()