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