]> git.saurik.com Git - wxWidgets.git/blob - include/wx/fontutil.h
Optionally allow showing tooltips for disabled ribbon buttons.
[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_FWD_BASE wxArrayString;
30 struct WXDLLIMPEXP_FWD_CORE 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
69 class WXDLLIMPEXP_CORE wxNativeFontInfo
70 {
71 public:
72 #if wxUSE_PANGO
73 PangoFontDescription *description;
74
75 // Pango font description doesn't have these attributes, so we store them
76 // separately and handle them ourselves in {To,From}String() methods.
77 bool m_underlined;
78 bool m_strikethrough;
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 wxNativeFontInfo(const LOGFONT& lf_) : lf(lf_) { }
115
116 LOGFONT lf;
117 #elif defined(__WXPM__)
118 // OS/2 native structures that define a font
119 FATTRS fa;
120 FONTMETRICS fm;
121 FACENAMEDESC fn;
122 #elif defined(__WXOSX__)
123 public:
124 wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
125 wxNativeFontInfo( int size,
126 wxFontFamily family,
127 wxFontStyle style,
128 wxFontWeight weight,
129 bool underlined,
130 const wxString& faceName,
131 wxFontEncoding encoding)
132 { Init(size,family,style,weight,underlined,faceName,encoding); }
133
134 ~wxNativeFontInfo() { Free(); }
135
136 wxNativeFontInfo& operator=(const wxNativeFontInfo& info)
137 {
138 if (this != &info)
139 {
140 Free();
141 Init(info);
142 }
143 return *this;
144 }
145
146 #if wxOSX_USE_CORE_TEXT
147 void Init(CTFontDescriptorRef descr);
148 #endif
149 void Init(const wxNativeFontInfo& info);
150 void Init(int size,
151 wxFontFamily family,
152 wxFontStyle style,
153 wxFontWeight weight,
154 bool underlined,
155 const wxString& faceName ,
156 wxFontEncoding encoding);
157
158 void Free();
159 void EnsureValid();
160
161 bool m_descriptorValid;
162
163 #if wxOSX_USE_ATSU_TEXT
164 bool m_atsuFontValid;
165 // the atsu font ID
166 wxUint32 m_atsuFontID;
167 // the qd styles that are not intrinsic to the font above
168 wxInt16 m_atsuAdditionalQDStyles;
169 #if wxOSX_USE_CARBON
170 wxInt16 m_qdFontFamily;
171 wxInt16 m_qdFontStyle;
172 #endif
173 #endif
174
175 int m_pointSize;
176 wxFontFamily m_family;
177 wxFontStyle m_style;
178 wxFontWeight m_weight;
179 bool m_underlined;
180 bool m_strikethrough;
181 wxString m_faceName;
182 wxFontEncoding m_encoding;
183 public :
184 #else // other platforms
185 //
186 // This is a generic implementation that should work on all ports
187 // without specific support by the port.
188 //
189 #define wxNO_NATIVE_FONTINFO
190
191 int pointSize;
192 wxFontFamily family;
193 wxFontStyle style;
194 wxFontWeight weight;
195 bool underlined;
196 bool strikethrough;
197 wxString faceName;
198 wxFontEncoding encoding;
199 #endif // platforms
200
201 // default ctor (default copy ctor is ok)
202 wxNativeFontInfo() { Init(); }
203
204 #if wxUSE_PANGO
205 private:
206 void Init(const wxNativeFontInfo& info);
207 void Free();
208
209 public:
210 wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
211 ~wxNativeFontInfo() { Free(); }
212
213 wxNativeFontInfo& operator=(const wxNativeFontInfo& info)
214 {
215 if (this != &info)
216 {
217 Free();
218 Init(info);
219 }
220 return *this;
221 }
222 #endif // wxUSE_PANGO
223
224 // reset to the default state
225 void Init();
226
227 // init with the parameters of the given font
228 void InitFromFont(const wxFont& font)
229 {
230 // translate all font parameters
231 SetStyle((wxFontStyle)font.GetStyle());
232 SetWeight((wxFontWeight)font.GetWeight());
233 SetUnderlined(font.GetUnderlined());
234 SetStrikethrough(font.GetStrikethrough());
235 #if defined(__WXMSW__)
236 if ( font.IsUsingSizeInPixels() )
237 SetPixelSize(font.GetPixelSize());
238 else
239 SetPointSize(font.GetPointSize());
240 #else
241 SetPointSize(font.GetPointSize());
242 #endif
243
244 // set the family/facename
245 SetFamily((wxFontFamily)font.GetFamily());
246 const wxString& facename = font.GetFaceName();
247 if ( !facename.empty() )
248 {
249 SetFaceName(facename);
250 }
251
252 // deal with encoding now (it may override the font family and facename
253 // so do it after setting them)
254 SetEncoding(font.GetEncoding());
255 }
256
257 // accessors and modifiers for the font elements
258 int GetPointSize() const;
259 wxSize GetPixelSize() const;
260 wxFontStyle GetStyle() const;
261 wxFontWeight GetWeight() const;
262 bool GetUnderlined() const;
263 bool GetStrikethrough() const;
264 wxString GetFaceName() const;
265 wxFontFamily GetFamily() const;
266 wxFontEncoding GetEncoding() const;
267
268 void SetPointSize(int pointsize);
269 void SetPixelSize(const wxSize& pixelSize);
270 void SetStyle(wxFontStyle style);
271 void SetWeight(wxFontWeight weight);
272 void SetUnderlined(bool underlined);
273 void SetStrikethrough(bool strikethrough);
274 bool SetFaceName(const wxString& facename);
275 void SetFamily(wxFontFamily family);
276 void SetEncoding(wxFontEncoding encoding);
277
278 // sets the first facename in the given array which is found
279 // to be valid. If no valid facename is given, sets the
280 // first valid facename returned by wxFontEnumerator::GetFacenames().
281 // Does not return a bool since it cannot fail.
282 void SetFaceName(const wxArrayString &facenames);
283
284
285 // it is important to be able to serialize wxNativeFontInfo objects to be
286 // able to store them (in config file, for example)
287 bool FromString(const wxString& s);
288 wxString ToString() const;
289
290 // we also want to present the native font descriptions to the user in some
291 // human-readable form (it is not platform independent neither, but can
292 // hopefully be understood by the user)
293 bool FromUserString(const wxString& s);
294 wxString ToUserString() const;
295 };
296
297 // ----------------------------------------------------------------------------
298 // font-related functions (common)
299 // ----------------------------------------------------------------------------
300
301 // translate a wxFontEncoding into native encoding parameter (defined above),
302 // returning true if an (exact) macth could be found, false otherwise (without
303 // attempting any substitutions)
304 WXDLLIMPEXP_CORE bool wxGetNativeFontEncoding(wxFontEncoding encoding,
305 wxNativeEncodingInfo *info);
306
307 // test for the existence of the font described by this facename/encoding,
308 // return true if such font(s) exist, false otherwise
309 WXDLLIMPEXP_CORE bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
310
311 // ----------------------------------------------------------------------------
312 // font-related functions (X and GTK)
313 // ----------------------------------------------------------------------------
314
315 #ifdef _WX_X_FONTLIKE
316 #include "wx/unix/fontutil.h"
317 #endif // X || GDK
318
319 #endif // _WX_FONTUTIL_H_