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