]> git.saurik.com Git - wxWidgets.git/blob - include/wx/font.h
SetTextColour is gone
[wxWidgets.git] / include / wx / font.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/font.h
3 // Purpose: wxFontBase class: the interface of wxFont
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 20.09.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FONT_H_BASE_
13 #define _WX_FONT_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
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
23 // ----------------------------------------------------------------------------
24 // forward declarations
25 // ----------------------------------------------------------------------------
26
27 class WXDLLEXPORT wxFontData;
28 class WXDLLEXPORT wxFontBase;
29 class WXDLLEXPORT wxFont;
30 class WXDLLEXPORT wxSize;
31
32 // ----------------------------------------------------------------------------
33 // font constants
34 // ----------------------------------------------------------------------------
35
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
39 // may be unknown
40 enum wxFontFamily
41 {
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,
49 wxFONTFAMILY_MAX,
50 wxFONTFAMILY_UNKNOWN = wxFONTFAMILY_MAX
51 };
52
53 // font styles
54 enum wxFontStyle
55 {
56 wxFONTSTYLE_NORMAL = wxNORMAL,
57 wxFONTSTYLE_ITALIC = wxITALIC,
58 wxFONTSTYLE_SLANT = wxSLANT,
59 wxFONTSTYLE_MAX
60 };
61
62 // font weights
63 enum wxFontWeight
64 {
65 wxFONTWEIGHT_NORMAL = wxNORMAL,
66 wxFONTWEIGHT_LIGHT = wxLIGHT,
67 wxFONTWEIGHT_BOLD = wxBOLD,
68 wxFONTWEIGHT_MAX
69 };
70
71 // the font flag bits for the new font ctor accepting one combined flags word
72 enum
73 {
74 // no special flags: font with default weight/slant/anti-aliasing
75 wxFONTFLAG_DEFAULT = 0,
76
77 // slant flags (default: no slant)
78 wxFONTFLAG_ITALIC = 1 << 0,
79 wxFONTFLAG_SLANT = 1 << 1,
80
81 // weight flags (default: medium)
82 wxFONTFLAG_LIGHT = 1 << 2,
83 wxFONTFLAG_BOLD = 1 << 3,
84
85 // anti-aliasing flag: force on or off (default: the current system default)
86 wxFONTFLAG_ANTIALIASED = 1 << 4,
87 wxFONTFLAG_NOT_ANTIALIASED = 1 << 5,
88
89 // underlined/strikethrough flags (default: no lines)
90 wxFONTFLAG_UNDERLINED = 1 << 6,
91 wxFONTFLAG_STRIKETHROUGH = 1 << 7,
92
93 // the mask of all currently used flags
94 wxFONTFLAG_MASK = wxFONTFLAG_ITALIC |
95 wxFONTFLAG_SLANT |
96 wxFONTFLAG_LIGHT |
97 wxFONTFLAG_BOLD |
98 wxFONTFLAG_ANTIALIASED |
99 wxFONTFLAG_NOT_ANTIALIASED |
100 wxFONTFLAG_UNDERLINED |
101 wxFONTFLAG_STRIKETHROUGH
102 };
103
104 // ----------------------------------------------------------------------------
105 // wxFontBase represents a font object
106 // ----------------------------------------------------------------------------
107
108 class WXDLLEXPORT wxFontRefData;
109 class WXDLLEXPORT wxNativeFontInfo;
110
111 class WXDLLEXPORT wxFontBase : public wxGDIObject
112 {
113 public:
114 // creator function
115 virtual ~wxFontBase();
116
117 // from the font components
118 static wxFont *New(
119 int pointSize, // size of the font in points
120 int family, // see wxFontFamily enum
121 int style, // see wxFontStyle enum
122 int weight, // see wxFontWeight enum
123 bool underlined = false, // not underlined by default
124 const wxString& face = wxEmptyString, // facename
125 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ...
126
127 // from the font components but using the font flags instead of separate
128 // parameters for each flag
129 static wxFont *New(int pointSize,
130 wxFontFamily family,
131 int flags = wxFONTFLAG_DEFAULT,
132 const wxString& face = wxEmptyString,
133 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
134
135 // from the font components
136 static wxFont *New(
137 const wxSize& pixelSize, // size of the font in pixels
138 int family, // see wxFontFamily enum
139 int style, // see wxFontStyle enum
140 int weight, // see wxFontWeight enum
141 bool underlined = false, // not underlined by default
142 const wxString& face = wxEmptyString, // facename
143 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ...
144
145 // from the font components but using the font flags instead of separate
146 // parameters for each flag
147 static wxFont *New(const wxSize& pixelSize,
148 wxFontFamily family,
149 int flags = wxFONTFLAG_DEFAULT,
150 const wxString& face = wxEmptyString,
151 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
152
153 // from the (opaque) native font description object
154 static wxFont *New(const wxNativeFontInfo& nativeFontDesc);
155
156 // from the string representation of wxNativeFontInfo
157 static wxFont *New(const wxString& strNativeFontDesc);
158
159 // was the font successfully created?
160 bool Ok() const { return IsOk(); }
161 bool IsOk() const { return m_refData != NULL; }
162
163 // comparison
164 bool operator == (const wxFont& font) const;
165 bool operator != (const wxFont& font) const;
166
167 // accessors: get the font characteristics
168 virtual int GetPointSize() const = 0;
169 virtual wxSize GetPixelSize() const;
170 virtual bool IsUsingSizeInPixels() const;
171 virtual int GetFamily() const = 0;
172 virtual int GetStyle() const = 0;
173 virtual int GetWeight() const = 0;
174 virtual bool GetUnderlined() const = 0;
175 virtual wxString GetFaceName() const = 0;
176 virtual wxFontEncoding GetEncoding() const = 0;
177 virtual const wxNativeFontInfo *GetNativeFontInfo() const = 0;
178
179 virtual bool IsFixedWidth() const;
180
181 wxString GetNativeFontInfoDesc() const;
182 wxString GetNativeFontInfoUserDesc() const;
183
184 // change the font characteristics
185 virtual void SetPointSize( int pointSize ) = 0;
186 virtual void SetPixelSize( const wxSize& pixelSize );
187 virtual void SetFamily( int family ) = 0;
188 virtual void SetStyle( int style ) = 0;
189 virtual void SetWeight( int weight ) = 0;
190 virtual void SetUnderlined( bool underlined ) = 0;
191 virtual void SetEncoding(wxFontEncoding encoding) = 0;
192 virtual bool SetFaceName( const wxString& faceName );
193 void SetNativeFontInfo(const wxNativeFontInfo& info)
194 { DoSetNativeFontInfo(info); }
195
196 bool SetNativeFontInfo(const wxString& info);
197 bool SetNativeFontInfoUserDesc(const wxString& info);
198
199 // translate the fonts into human-readable string (i.e. GetStyleString()
200 // will return "wxITALIC" for an italic font, ...)
201 wxString GetFamilyString() const;
202 wxString GetStyleString() const;
203 wxString GetWeightString() const;
204
205 // Unofficial API, don't use
206 virtual void SetNoAntiAliasing( bool WXUNUSED(no) = true ) { }
207 virtual bool GetNoAntiAliasing() const { return false; }
208
209 // the default encoding is used for creating all fonts with default
210 // encoding parameter
211 static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
212 static void SetDefaultEncoding(wxFontEncoding encoding);
213
214 protected:
215 // get the internal data
216 wxFontRefData *GetFontData() const
217 { return (wxFontRefData *)m_refData; }
218
219 // the function called by both overloads of SetNativeFontInfo()
220 virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info);
221
222 private:
223 // the currently default encoding: by default, it's the default system
224 // encoding, but may be changed by the application using
225 // SetDefaultEncoding() to make all subsequent fonts created without
226 // specifying encoding parameter using this encoding
227 static wxFontEncoding ms_encodingDefault;
228 };
229
230 // include the real class declaration
231 #if defined(__WXPALMOS__)
232 #include "wx/palmos/font.h"
233 #elif defined(__WXMSW__)
234 #include "wx/msw/font.h"
235 #elif defined(__WXMOTIF__)
236 #include "wx/motif/font.h"
237 #elif defined(__WXGTK20__)
238 #include "wx/gtk/font.h"
239 #elif defined(__WXGTK__)
240 #include "wx/gtk1/font.h"
241 #elif defined(__WXX11__)
242 #include "wx/x11/font.h"
243 #elif defined(__WXMGL__)
244 #include "wx/mgl/font.h"
245 #elif defined(__WXDFB__)
246 #include "wx/dfb/font.h"
247 #elif defined(__WXMAC__)
248 #include "wx/mac/font.h"
249 #elif defined(__WXCOCOA__)
250 #include "wx/cocoa/font.h"
251 #elif defined(__WXPM__)
252 #include "wx/os2/font.h"
253 #endif
254
255 // ----------------------------------------------------------------------------
256 // macros
257 // ----------------------------------------------------------------------------
258
259 #define M_FONTDATA GetFontData()
260
261 #endif
262 // _WX_FONT_H_BASE_