]> git.saurik.com Git - wxWidgets.git/blob - include/wx/fontutil.h
Applied patch [ 882493 ] Added XRC support for wxStatusBar
[wxWidgets.git] / include / wx / fontutil.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/fontutil.h
3 // Purpose: font-related helper functions
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 05.11.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // General note: this header is private to wxWindows and is not supposed to be
13 // included by user code. The functions declared here are implemented in
14 // msw/fontutil.cpp for Windows, unix/fontutil.cpp for GTK/Motif &c.
15
16 #ifndef _WX_FONTUTIL_H_
17 #define _WX_FONTUTIL_H_
18
19 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma interface "fontutil.h"
21 #endif
22
23 // ----------------------------------------------------------------------------
24 // headers
25 // ----------------------------------------------------------------------------
26
27 #include "wx/font.h" // for wxFont and wxFontEncoding
28
29 #if defined(__WXMSW__)
30 #include <windows.h>
31 #include "wx/msw/winundef.h"
32 #endif
33
34 struct WXDLLEXPORT wxNativeEncodingInfo;
35
36 #if defined(_WX_X_FONTLIKE)
37
38 // the symbolic names for the XLFD fields (with examples for their value)
39 //
40 // NB: we suppose that the font always starts with the empty token (font name
41 // registry field) as we never use nor generate it anyhow
42 enum wxXLFDField
43 {
44 wxXLFD_FOUNDRY, // adobe
45 wxXLFD_FAMILY, // courier, times, ...
46 wxXLFD_WEIGHT, // black, bold, demibold, medium, regular, light
47 wxXLFD_SLANT, // r/i/o (roman/italique/oblique)
48 wxXLFD_SETWIDTH, // condensed, expanded, ...
49 wxXLFD_ADDSTYLE, // whatever - usually nothing
50 wxXLFD_PIXELSIZE, // size in pixels
51 wxXLFD_POINTSIZE, // size in points
52 wxXLFD_RESX, // 72, 75, 100, ...
53 wxXLFD_RESY,
54 wxXLFD_SPACING, // m/p/c (monospaced/proportional/character cell)
55 wxXLFD_AVGWIDTH, // average width in 1/10 pixels
56 wxXLFD_REGISTRY, // iso8859, rawin, koi8, ...
57 wxXLFD_ENCODING, // 1, r, r, ...
58 wxXLFD_MAX
59 };
60
61 #endif // _WX_X_FONTLIKE
62
63 // ----------------------------------------------------------------------------
64 // types
65 // ----------------------------------------------------------------------------
66
67 // wxNativeFontInfo is platform-specific font representation: this struct
68 // should be considered as opaque font description only used by the native
69 // functions, the user code can only get the objects of this type from
70 // somewhere and pass it somewhere else (possibly save them somewhere using
71 // ToString() and restore them using FromString())
72 //
73 // NB: it is a POD currently for max efficiency but if it continues to grow
74 // further it might make sense to make it a real class with virtual methods
75 struct WXDLLEXPORT wxNativeFontInfo
76 {
77 #if wxUSE_PANGO
78 PangoFontDescription *description;
79 #elif defined(_WX_X_FONTLIKE)
80 // the members can't be accessed directly as we only parse the
81 // xFontName on demand
82 private:
83 // the components of the XLFD
84 wxString fontElements[wxXLFD_MAX];
85
86 // the full XLFD
87 wxString xFontName;
88
89 // true until SetXFontName() is called
90 bool m_isDefault;
91
92 // return true if we have already initialized fontElements
93 inline bool HasElements() const;
94
95 public:
96 // init the elements from an XLFD, return TRUE if ok
97 bool FromXFontName(const wxString& xFontName);
98
99 // return false if we were never initialized with a valid XLFD
100 bool IsDefault() const { return m_isDefault; }
101
102 // return the XLFD (using the fontElements if necessary)
103 wxString GetXFontName() const;
104
105 // get the given XFLD component
106 wxString GetXFontComponent(wxXLFDField field) const;
107
108 // change the font component
109 void SetXFontComponent(wxXLFDField field, const wxString& value);
110
111 // set the XFLD
112 void SetXFontName(const wxString& xFontName);
113 #elif defined(__WXMSW__)
114 LOGFONT lf;
115 #elif defined(__WXPM__)
116 // OS/2 native structures that define a font
117 FATTRS fa;
118 FONTMETRICS fm;
119 FACENAMEDESC fn;
120 #else // other platforms
121 //
122 // This is a generic implementation that should work on all ports
123 // without specific support by the port.
124 //
125 #define wxNO_NATIVE_FONTINFO
126
127 int pointSize;
128 wxFontFamily family;
129 wxFontStyle style;
130 wxFontWeight weight;
131 bool underlined;
132 wxString faceName;
133 wxFontEncoding encoding;
134 #endif // platforms
135
136 // default ctor (default copy ctor is ok)
137 wxNativeFontInfo() { Init(); }
138
139 // reset to the default state
140 void Init();
141
142 // init with the parameters of the given font
143 void InitFromFont(const wxFont& font)
144 {
145 // translate all font parameters
146 SetStyle((wxFontStyle)font.GetStyle());
147 SetWeight((wxFontWeight)font.GetWeight());
148 SetUnderlined(font.GetUnderlined());
149 SetPointSize(font.GetPointSize());
150
151 // set the family/facename
152 SetFamily((wxFontFamily)font.GetFamily());
153 const wxString& facename = font.GetFaceName();
154 if ( !facename.empty() )
155 {
156 SetFaceName(facename);
157 }
158
159 // deal with encoding now (it may override the font family and facename
160 // so do it after setting them)
161 SetEncoding(font.GetEncoding());
162 }
163
164 // accessors and modifiers for the font elements
165 int GetPointSize() const;
166 wxFontStyle GetStyle() const;
167 wxFontWeight GetWeight() const;
168 bool GetUnderlined() const;
169 wxString GetFaceName() const;
170 wxFontFamily GetFamily() const;
171 wxFontEncoding GetEncoding() const;
172
173 void SetPointSize(int pointsize);
174 void SetStyle(wxFontStyle style);
175 void SetWeight(wxFontWeight weight);
176 void SetUnderlined(bool underlined);
177 void SetFaceName(wxString facename);
178 void SetFamily(wxFontFamily family);
179 void SetEncoding(wxFontEncoding encoding);
180
181 // it is important to be able to serialize wxNativeFontInfo objects to be
182 // able to store them (in config file, for example)
183 bool FromString(const wxString& s);
184 wxString ToString() const;
185
186 // we also want to present the native font descriptions to the user in some
187 // human-readable form (it is not platform independent neither, but can
188 // hopefully be understood by the user)
189 bool FromUserString(const wxString& s);
190 wxString ToUserString() const;
191 };
192
193 // ----------------------------------------------------------------------------
194 // font-related functions (common)
195 // ----------------------------------------------------------------------------
196
197 // translate a wxFontEncoding into native encoding parameter (defined above),
198 // returning TRUE if an (exact) macth could be found, FALSE otherwise (without
199 // attempting any substitutions)
200 extern bool wxGetNativeFontEncoding(wxFontEncoding encoding,
201 wxNativeEncodingInfo *info);
202
203 // test for the existence of the font described by this facename/encoding,
204 // return TRUE if such font(s) exist, FALSE otherwise
205 extern bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
206
207 // ----------------------------------------------------------------------------
208 // font-related functions (X and GTK)
209 // ----------------------------------------------------------------------------
210
211 #ifdef _WX_X_FONTLIKE
212 #include "wx/unix/fontutil.h"
213 #endif // X || GDK
214
215 // ----------------------------------------------------------------------------
216 // font-related functions (MGL)
217 // ----------------------------------------------------------------------------
218
219 #ifdef __WXMGL__
220 #include "wx/mgl/fontutil.h"
221 #endif // __WXMGL__
222
223 #endif // _WX_FONTUTIL_H_