]>
Commit | Line | Data |
---|---|---|
0c5d3e1c VZ |
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$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
0c5d3e1c VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_FONT_H_BASE_ |
13 | #define _WX_FONT_H_BASE_ | |
c801d85f | 14 | |
0c5d3e1c VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
19 | #include "wx/defs.h" // for wxDEFAULT &c | |
f6bcfd97 | 20 | #include "wx/fontenc.h" // the font encoding constants |
0c5d3e1c | 21 | #include "wx/gdiobj.h" // the base class |
9d7a8e4a | 22 | #include "wx/gdicmn.h" // for wxGDIObjListBase |
0c5d3e1c VZ |
23 | |
24 | // ---------------------------------------------------------------------------- | |
25 | // forward declarations | |
26 | // ---------------------------------------------------------------------------- | |
27 | ||
b5dbe15d VS |
28 | class WXDLLIMPEXP_FWD_CORE wxFontData; |
29 | class WXDLLIMPEXP_FWD_CORE wxFontBase; | |
30 | class WXDLLIMPEXP_FWD_CORE wxFont; | |
31 | class WXDLLIMPEXP_FWD_CORE wxSize; | |
0c5d3e1c VZ |
32 | |
33 | // ---------------------------------------------------------------------------- | |
34 | // font constants | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
409d5a58 VZ |
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 | |
40 | // may be unknown | |
0c5d3e1c VZ |
41 | enum wxFontFamily |
42 | { | |
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, | |
409d5a58 VZ |
50 | wxFONTFAMILY_MAX, |
51 | wxFONTFAMILY_UNKNOWN = wxFONTFAMILY_MAX | |
0c5d3e1c VZ |
52 | }; |
53 | ||
54 | // font styles | |
55 | enum wxFontStyle | |
56 | { | |
57 | wxFONTSTYLE_NORMAL = wxNORMAL, | |
58 | wxFONTSTYLE_ITALIC = wxITALIC, | |
59 | wxFONTSTYLE_SLANT = wxSLANT, | |
60 | wxFONTSTYLE_MAX | |
61 | }; | |
62 | ||
63 | // font weights | |
64 | enum wxFontWeight | |
65 | { | |
66 | wxFONTWEIGHT_NORMAL = wxNORMAL, | |
67 | wxFONTWEIGHT_LIGHT = wxLIGHT, | |
68 | wxFONTWEIGHT_BOLD = wxBOLD, | |
69 | wxFONTWEIGHT_MAX | |
70 | }; | |
71 | ||
01cb1c26 | 72 | // the font flag bits for the new font ctor accepting one combined flags word |
0b70c946 | 73 | enum wxFontFlag |
01cb1c26 VZ |
74 | { |
75 | // no special flags: font with default weight/slant/anti-aliasing | |
76 | wxFONTFLAG_DEFAULT = 0, | |
77 | ||
78 | // slant flags (default: no slant) | |
79 | wxFONTFLAG_ITALIC = 1 << 0, | |
80 | wxFONTFLAG_SLANT = 1 << 1, | |
81 | ||
82 | // weight flags (default: medium) | |
83 | wxFONTFLAG_LIGHT = 1 << 2, | |
84 | wxFONTFLAG_BOLD = 1 << 3, | |
85 | ||
86 | // anti-aliasing flag: force on or off (default: the current system default) | |
87 | wxFONTFLAG_ANTIALIASED = 1 << 4, | |
88 | wxFONTFLAG_NOT_ANTIALIASED = 1 << 5, | |
89 | ||
90 | // underlined/strikethrough flags (default: no lines) | |
91 | wxFONTFLAG_UNDERLINED = 1 << 6, | |
92 | wxFONTFLAG_STRIKETHROUGH = 1 << 7, | |
93 | ||
94 | // the mask of all currently used flags | |
95 | wxFONTFLAG_MASK = wxFONTFLAG_ITALIC | | |
96 | wxFONTFLAG_SLANT | | |
97 | wxFONTFLAG_LIGHT | | |
98 | wxFONTFLAG_BOLD | | |
99 | wxFONTFLAG_ANTIALIASED | | |
100 | wxFONTFLAG_NOT_ANTIALIASED | | |
101 | wxFONTFLAG_UNDERLINED | | |
102 | wxFONTFLAG_STRIKETHROUGH | |
103 | }; | |
104 | ||
0c5d3e1c VZ |
105 | // ---------------------------------------------------------------------------- |
106 | // wxFontBase represents a font object | |
107 | // ---------------------------------------------------------------------------- | |
108 | ||
b5dbe15d | 109 | class WXDLLIMPEXP_FWD_CORE wxNativeFontInfo; |
4d85bcd1 | 110 | |
53a2db12 | 111 | class WXDLLIMPEXP_CORE wxFontBase : public wxGDIObject |
0c5d3e1c VZ |
112 | { |
113 | public: | |
b5791cc7 FM |
114 | /* |
115 | derived classes should provide the following ctors: | |
03647350 | 116 | |
b5791cc7 FM |
117 | wxFont(); |
118 | wxFont(const wxString& nativeFontInfoString); | |
119 | wxFont(const wxNativeFontInfo& info); | |
120 | wxFont(int size, | |
121 | wxFontFamily family, | |
122 | wxFontStyle style, | |
123 | wxFontWeight weight, | |
124 | bool underlined = false, | |
125 | const wxString& face = wxEmptyString, | |
126 | wxFontEncoding encoding = wxFONTENCODING_DEFAULT); | |
127 | wxFont(const wxSize& pixelSize, | |
128 | wxFontFamily family, | |
129 | wxFontStyle style, | |
130 | wxFontWeight weight, | |
131 | bool underlined = false, | |
132 | const wxString& face = wxEmptyString, | |
133 | wxFontEncoding encoding = wxFONTENCODING_DEFAULT); | |
134 | */ | |
03647350 | 135 | |
0c5d3e1c | 136 | // creator function |
799ea011 | 137 | virtual ~wxFontBase(); |
7826e2dd | 138 | |
0c14b6c3 FM |
139 | |
140 | #if FUTURE_WXWIN_COMPATIBILITY_3_0 | |
7826e2dd | 141 | // from the font components |
0c5d3e1c VZ |
142 | static wxFont *New( |
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 | |
a62848fd | 147 | bool underlined = false, // not underlined by default |
0c5d3e1c | 148 | const wxString& face = wxEmptyString, // facename |
0c14b6c3 FM |
149 | wxFontEncoding encoding = wxFONTENCODING_DEFAULT) // ISO8859-X, ... |
150 | { return New(pointSize, (wxFontFamily)family, (wxFontStyle)style, | |
151 | (wxFontWeight)weight, underlined, face, encoding); } | |
01cb1c26 | 152 | |
544229d1 VZ |
153 | // from the font components |
154 | static wxFont *New( | |
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 | |
4055ed82 | 159 | bool underlined = false, // not underlined by default |
544229d1 | 160 | const wxString& face = wxEmptyString, // facename |
0c14b6c3 FM |
161 | wxFontEncoding encoding = wxFONTENCODING_DEFAULT) // ISO8859-X, ... |
162 | { return New(pixelSize, (wxFontFamily)family, (wxFontStyle)style, | |
163 | (wxFontWeight)weight, underlined, face, encoding); } | |
164 | #endif | |
165 | ||
166 | // from the font components | |
167 | static wxFont *New( | |
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 | |
544229d1 VZ |
174 | wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ... |
175 | ||
0c14b6c3 FM |
176 | // from the font components |
177 | static wxFont *New( | |
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, ... | |
185 | ||
186 | // from the font components but using the font flags instead of separate | |
187 | // parameters for each flag | |
188 | static wxFont *New(int pointSize, | |
189 | wxFontFamily family, | |
190 | int flags = wxFONTFLAG_DEFAULT, | |
191 | const wxString& face = wxEmptyString, | |
192 | wxFontEncoding encoding = wxFONTENCODING_DEFAULT); | |
193 | ||
194 | ||
544229d1 VZ |
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, | |
198 | wxFontFamily family, | |
199 | int flags = wxFONTFLAG_DEFAULT, | |
200 | const wxString& face = wxEmptyString, | |
201 | wxFontEncoding encoding = wxFONTENCODING_DEFAULT); | |
202 | ||
7826e2dd VZ |
203 | // from the (opaque) native font description object |
204 | static wxFont *New(const wxNativeFontInfo& nativeFontDesc); | |
205 | ||
206 | // from the string representation of wxNativeFontInfo | |
207 | static wxFont *New(const wxString& strNativeFontDesc); | |
0c5d3e1c | 208 | |
0c5d3e1c | 209 | // comparison |
8f884a0d VZ |
210 | bool operator==(const wxFont& font) const; |
211 | bool operator!=(const wxFont& font) const { return !(*this == font); } | |
0c5d3e1c VZ |
212 | |
213 | // accessors: get the font characteristics | |
214 | virtual int GetPointSize() const = 0; | |
544229d1 VZ |
215 | virtual wxSize GetPixelSize() const; |
216 | virtual bool IsUsingSizeInPixels() const; | |
59b7da02 | 217 | wxFontFamily GetFamily() const; |
0c14b6c3 FM |
218 | virtual wxFontStyle GetStyle() const = 0; |
219 | virtual wxFontWeight GetWeight() const = 0; | |
0c5d3e1c VZ |
220 | virtual bool GetUnderlined() const = 0; |
221 | virtual wxString GetFaceName() const = 0; | |
222 | virtual wxFontEncoding GetEncoding() const = 0; | |
3bf5a59b | 223 | virtual const wxNativeFontInfo *GetNativeFontInfo() const = 0; |
ab5fe833 | 224 | |
53f6aab7 VZ |
225 | virtual bool IsFixedWidth() const; |
226 | ||
7826e2dd | 227 | wxString GetNativeFontInfoDesc() const; |
ab5fe833 | 228 | wxString GetNativeFontInfoUserDesc() const; |
0c5d3e1c VZ |
229 | |
230 | // change the font characteristics | |
231 | virtual void SetPointSize( int pointSize ) = 0; | |
544229d1 | 232 | virtual void SetPixelSize( const wxSize& pixelSize ); |
0c14b6c3 FM |
233 | virtual void SetFamily( wxFontFamily family ) = 0; |
234 | virtual void SetStyle( wxFontStyle style ) = 0; | |
235 | virtual void SetWeight( wxFontWeight weight ) = 0; | |
236 | ||
0c5d3e1c VZ |
237 | virtual void SetUnderlined( bool underlined ) = 0; |
238 | virtual void SetEncoding(wxFontEncoding encoding) = 0; | |
85ab460e | 239 | virtual bool SetFaceName( const wxString& faceName ); |
9045ad9d VZ |
240 | void SetNativeFontInfo(const wxNativeFontInfo& info) |
241 | { DoSetNativeFontInfo(info); } | |
ab5fe833 | 242 | |
85ab460e VZ |
243 | bool SetNativeFontInfo(const wxString& info); |
244 | bool SetNativeFontInfoUserDesc(const wxString& info); | |
7826e2dd | 245 | |
0c5d3e1c VZ |
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; | |
251 | ||
252 | // the default encoding is used for creating all fonts with default | |
253 | // encoding parameter | |
cafbf6fb VZ |
254 | static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; } |
255 | static void SetDefaultEncoding(wxFontEncoding encoding); | |
0c5d3e1c | 256 | |
8462a84b VZ |
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 | |
262 | ||
0c5d3e1c | 263 | protected: |
9045ad9d VZ |
264 | // the function called by both overloads of SetNativeFontInfo() |
265 | virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info); | |
266 | ||
59b7da02 VZ |
267 | // The function called by public GetFamily(): it can return |
268 | // wxFONTFAMILY_UNKNOWN unlike the public method (see comment there). | |
269 | virtual wxFontFamily DoGetFamily() const = 0; | |
270 | ||
0c5d3e1c VZ |
271 | private: |
272 | // the currently default encoding: by default, it's the default system | |
273 | // encoding, but may be changed by the application using | |
274 | // SetDefaultEncoding() to make all subsequent fonts created without | |
3103e8a9 | 275 | // specifying encoding parameter using this encoding |
0c5d3e1c VZ |
276 | static wxFontEncoding ms_encodingDefault; |
277 | }; | |
278 | ||
fc9361e3 VZ |
279 | // wxFontBase <-> wxString utilities, used by wxConfig |
280 | WXDLLIMPEXP_CORE wxString wxToString(const wxFontBase& font); | |
281 | WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxFontBase* font); | |
282 | ||
283 | ||
0c14b6c3 | 284 | #if FUTURE_WXWIN_COMPATIBILITY_3_0 |
f76c0758 | 285 | #define wxDECLARE_FONT_COMPAT_SETTER \ |
0c14b6c3 FM |
286 | wxDEPRECATED_FUTURE( void SetFamily(int family) ) \ |
287 | { SetFamily((wxFontFamily)family); } \ | |
288 | wxDEPRECATED_FUTURE( void SetStyle(int style) ) \ | |
289 | { SetStyle((wxFontStyle)style); } \ | |
290 | wxDEPRECATED_FUTURE( void SetWeight(int weight) ) \ | |
291 | { SetWeight((wxFontWeight)weight); } \ | |
292 | wxDEPRECATED_FUTURE( void SetFamily(wxDeprecatedGUIConstants family) ) \ | |
293 | { SetFamily((wxFontFamily)family); } \ | |
294 | wxDEPRECATED_FUTURE( void SetStyle(wxDeprecatedGUIConstants style) ) \ | |
295 | { SetStyle((wxFontStyle)style); } \ | |
296 | wxDEPRECATED_FUTURE( void SetWeight(wxDeprecatedGUIConstants weight) ) \ | |
297 | { SetWeight((wxFontWeight)weight); } | |
298 | #else | |
f76c0758 | 299 | #define wxDECLARE_FONT_COMPAT_SETTER /*empty*/ |
0c14b6c3 | 300 | #endif |
fc9361e3 | 301 | |
f76c0758 VZ |
302 | // this macro must be used in all derived wxFont classes declarations |
303 | #define wxDECLARE_COMMON_FONT_METHODS() \ | |
304 | wxDECLARE_FONT_COMPAT_SETTER \ | |
305 | \ | |
6e7d2550 VZ |
306 | /* functions for modifying font in place */ \ |
307 | wxFont& MakeBold(); \ | |
308 | wxFont& MakeItalic(); \ | |
309 | wxFont& MakeLarger() { return Scale(1.2f); } \ | |
310 | wxFont& MakeSmaller() { return Scale(1/1.2f); } \ | |
311 | wxFont& Scale(float x); \ | |
f76c0758 | 312 | /* functions for creating fonts based on this one */ \ |
6e7d2550 VZ |
313 | wxFont Bold() const; \ |
314 | wxFont Italic() const; \ | |
315 | wxFont Larger() const { return Scaled(1.2f); } \ | |
316 | wxFont Smaller() const { return Scaled(1/1.2f); } \ | |
317 | wxFont Scaled(float x) const | |
f76c0758 | 318 | |
0c5d3e1c | 319 | // include the real class declaration |
4055ed82 | 320 | #if defined(__WXPALMOS__) |
ffecfa5a JS |
321 | #include "wx/palmos/font.h" |
322 | #elif defined(__WXMSW__) | |
0c5d3e1c | 323 | #include "wx/msw/font.h" |
2049ba38 | 324 | #elif defined(__WXMOTIF__) |
0c5d3e1c | 325 | #include "wx/motif/font.h" |
1be7a35c | 326 | #elif defined(__WXGTK20__) |
0c5d3e1c | 327 | #include "wx/gtk/font.h" |
1be7a35c MR |
328 | #elif defined(__WXGTK__) |
329 | #include "wx/gtk1/font.h" | |
83df96d6 JS |
330 | #elif defined(__WXX11__) |
331 | #include "wx/x11/font.h" | |
1e6feb95 VZ |
332 | #elif defined(__WXMGL__) |
333 | #include "wx/mgl/font.h" | |
b3c86150 VS |
334 | #elif defined(__WXDFB__) |
335 | #include "wx/dfb/font.h" | |
34138703 | 336 | #elif defined(__WXMAC__) |
ef0e9220 | 337 | #include "wx/osx/font.h" |
e64df9bc DE |
338 | #elif defined(__WXCOCOA__) |
339 | #include "wx/cocoa/font.h" | |
1777b9bb | 340 | #elif defined(__WXPM__) |
0c5d3e1c | 341 | #include "wx/os2/font.h" |
c801d85f KB |
342 | #endif |
343 | ||
82cddbd9 FM |
344 | class WXDLLIMPEXP_CORE wxFontList: public wxGDIObjListBase |
345 | { | |
346 | public: | |
347 | wxFont *FindOrCreateFont(int pointSize, | |
348 | wxFontFamily family, | |
349 | wxFontStyle style, | |
350 | wxFontWeight weight, | |
351 | bool underline = false, | |
352 | const wxString& face = wxEmptyString, | |
353 | wxFontEncoding encoding = wxFONTENCODING_DEFAULT); | |
020eeaa8 FM |
354 | |
355 | #if FUTURE_WXWIN_COMPATIBILITY_3_0 | |
356 | wxFont *FindOrCreateFont(int pointSize, int family, int style, int weight, | |
357 | bool underline = false, | |
358 | const wxString& face = wxEmptyString, | |
359 | wxFontEncoding encoding = wxFONTENCODING_DEFAULT) | |
360 | { return FindOrCreateFont(pointSize, (wxFontFamily)family, (wxFontStyle)style, | |
361 | (wxFontWeight)weight, underline, face, encoding); } | |
362 | #endif | |
363 | ||
82cddbd9 FM |
364 | #if WXWIN_COMPATIBILITY_2_6 |
365 | wxDEPRECATED( void AddFont(wxFont*) ); | |
366 | wxDEPRECATED( void RemoveFont(wxFont*) ); | |
367 | #endif | |
368 | }; | |
369 | ||
53a2db12 | 370 | extern WXDLLIMPEXP_DATA_CORE(wxFontList*) wxTheFontList; |
82cddbd9 | 371 | |
0c14b6c3 FM |
372 | |
373 | // provide comparison operators to allow code such as | |
374 | // | |
375 | // if ( font.GetStyle() == wxFONTSTYLE_SLANT ) | |
376 | // | |
377 | // to compile without warnings which it would otherwise provoke from some | |
378 | // compilers as it compares elements of different enums | |
379 | #if FUTURE_WXWIN_COMPATIBILITY_3_0 | |
380 | ||
381 | inline bool operator==(wxFontFamily s, wxDeprecatedGUIConstants t) | |
382 | { return static_cast<int>(s) == static_cast<int>(t); } | |
383 | inline bool operator!=(wxFontFamily s, wxDeprecatedGUIConstants t) | |
384 | { return !(s == t); } | |
385 | inline bool operator==(wxFontStyle s, wxDeprecatedGUIConstants t) | |
386 | { return static_cast<int>(s) == static_cast<int>(t); } | |
387 | inline bool operator!=(wxFontStyle s, wxDeprecatedGUIConstants t) | |
388 | { return !(s == t); } | |
389 | inline bool operator==(wxFontWeight s, wxDeprecatedGUIConstants t) | |
390 | { return static_cast<int>(s) == static_cast<int>(t); } | |
391 | inline bool operator!=(wxFontWeight s, wxDeprecatedGUIConstants t) | |
392 | { return !(s == t); } | |
393 | ||
394 | #endif // FUTURE_WXWIN_COMPATIBILITY_3_0 | |
395 | ||
c801d85f | 396 | #endif |
34138703 | 397 | // _WX_FONT_H_BASE_ |