applied wxNativeFontInfo patch from Derry Bryson (with minor changes)
[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) wxWindows team
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FONT_H_BASE_
13 #define _WX_FONT_H_BASE_
14
15 #ifdef __GNUG__
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
35 // ----------------------------------------------------------------------------
36 // font constants
37 // ----------------------------------------------------------------------------
38
39 // standard font families
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 };
51
52 // font styles
53 enum wxFontStyle
54 {
55 wxFONTSTYLE_NORMAL = wxNORMAL,
56 wxFONTSTYLE_ITALIC = wxITALIC,
57 wxFONTSTYLE_SLANT = wxSLANT,
58 wxFONTSTYLE_MAX
59 };
60
61 // font weights
62 enum wxFontWeight
63 {
64 wxFONTWEIGHT_NORMAL = wxNORMAL,
65 wxFONTWEIGHT_LIGHT = wxLIGHT,
66 wxFONTWEIGHT_BOLD = wxBOLD,
67 wxFONTWEIGHT_MAX
68 };
69
70 // ----------------------------------------------------------------------------
71 // wxNativeFontInfo is platform-specific font representation
72 // ----------------------------------------------------------------------------
73
74 // this struct should be considered as opaque font description only used by
75 // the native functions, the user code can only get the objects of this type
76 // from somewhere and pass it somewhere else (possibly save them somewhere
77 // using ToString() and restore them using FromString())
78 struct WXDLLEXPORT wxNativeFontInfo
79 {
80 #if defined(__WXGTK__)
81 wxString xFontName;
82 #else // other platforms
83 //
84 // This is a generic implementation that should work on all ports
85 // without specific support by the port.
86 //
87 int pointSize;
88 int family;
89 int style;
90 int weight;
91 bool underlined;
92 wxString faceName;
93 wxFontEncoding encoding;
94 #endif // platforms
95
96 // it is important to be able to serialize wxNativeFontInfo objects to be
97 // able to store them (in config file, for example)
98 bool FromString(const wxString& s);
99 wxString ToString() const;
100 };
101
102 WXDLLEXPORT_DATA(extern wxNativeFontInfo) wxNullNativeFontInfo;
103
104 // ----------------------------------------------------------------------------
105 // wxFontBase represents a font object
106 // ----------------------------------------------------------------------------
107
108 class WXDLLEXPORT wxFontRefData;
109
110 class WXDLLEXPORT wxFontBase : public wxGDIObject
111 {
112 public:
113 // creator function
114 static wxFont *New(
115 int pointSize, // size of the font in points
116 int family, // see wxFontFamily enum
117 int style, // see wxFontStyle enum
118 int weight, // see wxFontWeight enum
119 bool underlined = FALSE, // not underlined by default
120 const wxString& face = wxEmptyString, // facename
121 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ...
122 static wxFont *New(const wxNativeFontInfo& info);
123
124 // was the font successfully created?
125 bool Ok() const { return m_refData != NULL; }
126
127 // comparison
128 bool operator == (const wxFont& font) const;
129 bool operator != (const wxFont& font) const;
130
131 // accessors: get the font characteristics
132 virtual int GetPointSize() const = 0;
133 virtual int GetFamily() const = 0;
134 virtual int GetStyle() const = 0;
135 virtual int GetWeight() const = 0;
136 virtual bool GetUnderlined() const = 0;
137 virtual wxString GetFaceName() const = 0;
138 virtual wxFontEncoding GetEncoding() const = 0;
139 virtual wxNativeFontInfo GetNativeFontInfo() const;
140
141 // change the font characteristics
142 virtual void SetPointSize( int pointSize ) = 0;
143 virtual void SetFamily( int family ) = 0;
144 virtual void SetStyle( int style ) = 0;
145 virtual void SetWeight( int weight ) = 0;
146 virtual void SetFaceName( const wxString& faceName ) = 0;
147 virtual void SetUnderlined( bool underlined ) = 0;
148 virtual void SetEncoding(wxFontEncoding encoding) = 0;
149 virtual void SetNativeFontInfo(const wxNativeFontInfo& info);
150
151 // translate the fonts into human-readable string (i.e. GetStyleString()
152 // will return "wxITALIC" for an italic font, ...)
153 wxString GetFamilyString() const;
154 wxString GetStyleString() const;
155 wxString GetWeightString() const;
156
157 // the default encoding is used for creating all fonts with default
158 // encoding parameter
159 static wxFontEncoding GetDefaultEncoding()
160 { return ms_encodingDefault; }
161 static void SetDefaultEncoding(wxFontEncoding encoding)
162 { ms_encodingDefault = encoding; }
163
164 protected:
165 // get the internal data
166 wxFontRefData *GetFontData() const
167 { return (wxFontRefData *)m_refData; }
168
169 private:
170 // the currently default encoding: by default, it's the default system
171 // encoding, but may be changed by the application using
172 // SetDefaultEncoding() to make all subsequent fonts created without
173 // specifing encoding parameter using this encoding
174 static wxFontEncoding ms_encodingDefault;
175 };
176
177 // include the real class declaration
178 #if defined(__WXMSW__)
179 #include "wx/msw/font.h"
180 #elif defined(__WXMOTIF__)
181 #include "wx/motif/font.h"
182 #elif defined(__WXGTK__)
183 #include "wx/gtk/font.h"
184 #elif defined(__WXQT__)
185 #include "wx/qt/font.h"
186 #elif defined(__WXMAC__)
187 #include "wx/mac/font.h"
188 #elif defined(__WXPM__)
189 #include "wx/os2/font.h"
190 #elif defined(__WXSTUBS__)
191 #include "wx/stubs/font.h"
192 #endif
193
194 // ----------------------------------------------------------------------------
195 // macros
196 // ----------------------------------------------------------------------------
197
198 #define M_FONTDATA GetFontData()
199
200 #endif
201 // _WX_FONT_H_BASE_