]> git.saurik.com Git - wxWidgets.git/blob - include/wx/font.h
Compilation fix for VC++ 5 and 6
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "fontbase.h"
17 #endif
18
19 // ----------------------------------------------------------------------------
20 // headers
21 // ----------------------------------------------------------------------------
22
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
26
27 // ----------------------------------------------------------------------------
28 // forward declarations
29 // ----------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxFontData;
32 class WXDLLEXPORT wxFontBase;
33 class WXDLLEXPORT wxFont;
34 class WXDLLEXPORT wxSize;
35
36 // ----------------------------------------------------------------------------
37 // font constants
38 // ----------------------------------------------------------------------------
39
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
43 // may be unknown
44 enum wxFontFamily
45 {
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,
53 wxFONTFAMILY_MAX,
54 wxFONTFAMILY_UNKNOWN = wxFONTFAMILY_MAX
55 };
56
57 // font styles
58 enum wxFontStyle
59 {
60 wxFONTSTYLE_NORMAL = wxNORMAL,
61 wxFONTSTYLE_ITALIC = wxITALIC,
62 wxFONTSTYLE_SLANT = wxSLANT,
63 wxFONTSTYLE_MAX
64 };
65
66 // font weights
67 enum wxFontWeight
68 {
69 wxFONTWEIGHT_NORMAL = wxNORMAL,
70 wxFONTWEIGHT_LIGHT = wxLIGHT,
71 wxFONTWEIGHT_BOLD = wxBOLD,
72 wxFONTWEIGHT_MAX
73 };
74
75 // the font flag bits for the new font ctor accepting one combined flags word
76 enum
77 {
78 // no special flags: font with default weight/slant/anti-aliasing
79 wxFONTFLAG_DEFAULT = 0,
80
81 // slant flags (default: no slant)
82 wxFONTFLAG_ITALIC = 1 << 0,
83 wxFONTFLAG_SLANT = 1 << 1,
84
85 // weight flags (default: medium)
86 wxFONTFLAG_LIGHT = 1 << 2,
87 wxFONTFLAG_BOLD = 1 << 3,
88
89 // anti-aliasing flag: force on or off (default: the current system default)
90 wxFONTFLAG_ANTIALIASED = 1 << 4,
91 wxFONTFLAG_NOT_ANTIALIASED = 1 << 5,
92
93 // underlined/strikethrough flags (default: no lines)
94 wxFONTFLAG_UNDERLINED = 1 << 6,
95 wxFONTFLAG_STRIKETHROUGH = 1 << 7,
96
97 // the mask of all currently used flags
98 wxFONTFLAG_MASK = wxFONTFLAG_ITALIC |
99 wxFONTFLAG_SLANT |
100 wxFONTFLAG_LIGHT |
101 wxFONTFLAG_BOLD |
102 wxFONTFLAG_ANTIALIASED |
103 wxFONTFLAG_NOT_ANTIALIASED |
104 wxFONTFLAG_UNDERLINED |
105 wxFONTFLAG_STRIKETHROUGH
106 };
107
108 // ----------------------------------------------------------------------------
109 // wxFontBase represents a font object
110 // ----------------------------------------------------------------------------
111
112 class WXDLLEXPORT wxFontRefData;
113 struct WXDLLEXPORT wxNativeFontInfo;
114
115 class WXDLLEXPORT wxFontBase : public wxGDIObject
116 {
117 public:
118 // creator function
119 virtual ~wxFontBase();
120
121 // from the font components
122 static wxFont *New(
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, ...
130
131 // from the font components but using the font flags instead of separate
132 // parameters for each flag
133 static wxFont *New(int pointSize,
134 wxFontFamily family,
135 int flags = wxFONTFLAG_DEFAULT,
136 const wxString& face = wxEmptyString,
137 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
138
139 // from the font components
140 static wxFont *New(
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, ...
148
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,
152 wxFontFamily family,
153 int flags = wxFONTFLAG_DEFAULT,
154 const wxString& face = wxEmptyString,
155 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
156
157 // from the (opaque) native font description object
158 static wxFont *New(const wxNativeFontInfo& nativeFontDesc);
159
160 // from the string representation of wxNativeFontInfo
161 static wxFont *New(const wxString& strNativeFontDesc);
162
163 // was the font successfully created?
164 bool Ok() const { return m_refData != NULL; }
165
166 // comparison
167 bool operator == (const wxFont& font) const;
168 bool operator != (const wxFont& font) const;
169
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;
181
182 virtual bool IsFixedWidth() const;
183
184 wxString GetNativeFontInfoDesc() const;
185 wxString GetNativeFontInfoUserDesc() const;
186
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); }
198
199 void SetNativeFontInfo(const wxString& info);
200 void SetNativeFontInfoUserDesc(const wxString& info);
201
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;
207
208 // Unofficial API, don't use
209 virtual void SetNoAntiAliasing( bool WXUNUSED(no) = true ) { }
210 virtual bool GetNoAntiAliasing() const { return false; }
211
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);
216
217 protected:
218 // get the internal data
219 wxFontRefData *GetFontData() const
220 { return (wxFontRefData *)m_refData; }
221
222 // the function called by both overloads of SetNativeFontInfo()
223 virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info);
224
225 private:
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 // specifing encoding parameter using this encoding
230 static wxFontEncoding ms_encodingDefault;
231 };
232
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"
252 #endif
253
254 // ----------------------------------------------------------------------------
255 // macros
256 // ----------------------------------------------------------------------------
257
258 #define M_FONTDATA GetFontData()
259
260 #endif
261 // _WX_FONT_H_BASE_