]> git.saurik.com Git - wxWidgets.git/blob - include/wx/fontutil.h
Rebake from clean wx tree.
[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 #elif defined(_WX_X_FONTLIKE)
75 // the members can't be accessed directly as we only parse the
76 // xFontName on demand
77 private:
78 // the components of the XLFD
79 wxString fontElements[wxXLFD_MAX];
80
81 // the full XLFD
82 wxString xFontName;
83
84 // true until SetXFontName() is called
85 bool m_isDefault;
86
87 // return true if we have already initialized fontElements
88 inline bool HasElements() const;
89
90 public:
91 // init the elements from an XLFD, return true if ok
92 bool FromXFontName(const wxString& xFontName);
93
94 // return false if we were never initialized with a valid XLFD
95 bool IsDefault() const { return m_isDefault; }
96
97 // return the XLFD (using the fontElements if necessary)
98 wxString GetXFontName() const;
99
100 // get the given XFLD component
101 wxString GetXFontComponent(wxXLFDField field) const;
102
103 // change the font component
104 void SetXFontComponent(wxXLFDField field, const wxString& value);
105
106 // set the XFLD
107 void SetXFontName(const wxString& xFontName);
108 #elif defined(__WXMSW__)
109 wxNativeFontInfo(const LOGFONT& lf_) : lf(lf_) { }
110
111 LOGFONT lf;
112 #elif defined(__WXPM__)
113 // OS/2 native structures that define a font
114 FATTRS fa;
115 FONTMETRICS fm;
116 FACENAMEDESC fn;
117 #elif defined(__WXOSX__)
118 public:
119 wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
120 wxNativeFontInfo( int size,
121 wxFontFamily family,
122 wxFontStyle style,
123 wxFontWeight weight,
124 bool underlined,
125 const wxString& faceName,
126 wxFontEncoding encoding)
127 { Init(size,family,style,weight,underlined,faceName,encoding); }
128
129 ~wxNativeFontInfo() { Free(); }
130
131 wxNativeFontInfo& operator=(const wxNativeFontInfo& info)
132 {
133 if (this != &info)
134 {
135 Free();
136 Init(info);
137 }
138 return *this;
139 }
140
141 #if wxOSX_USE_CORE_TEXT
142 void Init(CTFontDescriptorRef descr);
143 #endif
144 void Init(const wxNativeFontInfo& info);
145 void Init(int size,
146 wxFontFamily family,
147 wxFontStyle style,
148 wxFontWeight weight,
149 bool underlined,
150 const wxString& faceName ,
151 wxFontEncoding encoding);
152
153 void Free();
154 void EnsureValid();
155
156 bool m_descriptorValid;
157 #if wxOSX_USE_CORE_TEXT
158 CTFontDescriptorRef m_ctFontDescriptor;
159 #endif
160
161 #if wxOSX_USE_ATSU_TEXT
162 bool m_atsuFontValid;
163 // the atsu font ID
164 wxUint32 m_atsuFontID;
165 // the qd styles that are not intrinsic to the font above
166 wxInt16 m_atsuAdditionalQDStyles;
167 #if wxOSX_USE_CARBON
168 wxInt16 m_qdFontFamily;
169 wxInt16 m_qdFontStyle;
170 #endif
171 #endif
172
173 #if wxOSX_USE_COCOA
174 WX_NSFontDescriptor m_nsFontDescriptor;
175 void OSXValidateNSFontDescriptor();
176 #endif
177 #if wxOSX_USE_IPHONE
178 #endif
179
180 int m_pointSize;
181 wxFontFamily m_family;
182 wxFontStyle m_style;
183 wxFontWeight m_weight;
184 bool m_underlined;
185 wxString m_faceName;
186 wxFontEncoding m_encoding;
187 public :
188 #else // other platforms
189 //
190 // This is a generic implementation that should work on all ports
191 // without specific support by the port.
192 //
193 #define wxNO_NATIVE_FONTINFO
194
195 int pointSize;
196 wxFontFamily family;
197 wxFontStyle style;
198 wxFontWeight weight;
199 bool underlined;
200 wxString faceName;
201 wxFontEncoding encoding;
202 #endif // platforms
203
204 // default ctor (default copy ctor is ok)
205 wxNativeFontInfo() { Init(); }
206
207 #if wxUSE_PANGO
208 private:
209 void Init(const wxNativeFontInfo& info);
210 void Free();
211
212 public:
213 wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
214 ~wxNativeFontInfo() { Free(); }
215
216 wxNativeFontInfo& operator=(const wxNativeFontInfo& info)
217 {
218 if (this != &info)
219 {
220 Free();
221 Init(info);
222 }
223 return *this;
224 }
225 #endif // wxUSE_PANGO
226
227 // reset to the default state
228 void Init();
229
230 // init with the parameters of the given font
231 void InitFromFont(const wxFont& font)
232 {
233 // translate all font parameters
234 SetStyle((wxFontStyle)font.GetStyle());
235 SetWeight((wxFontWeight)font.GetWeight());
236 SetUnderlined(font.GetUnderlined());
237 #if defined(__WXMSW__)
238 if ( font.IsUsingSizeInPixels() )
239 SetPixelSize(font.GetPixelSize());
240 else
241 SetPointSize(font.GetPointSize());
242 #else
243 SetPointSize(font.GetPointSize());
244 #endif
245
246 // set the family/facename
247 SetFamily((wxFontFamily)font.GetFamily());
248 const wxString& facename = font.GetFaceName();
249 if ( !facename.empty() )
250 {
251 SetFaceName(facename);
252 }
253
254 // deal with encoding now (it may override the font family and facename
255 // so do it after setting them)
256 SetEncoding(font.GetEncoding());
257 }
258
259 // accessors and modifiers for the font elements
260 int GetPointSize() const;
261 wxSize GetPixelSize() const;
262 wxFontStyle GetStyle() const;
263 wxFontWeight GetWeight() const;
264 bool GetUnderlined() const;
265 wxString GetFaceName() const;
266 wxFontFamily GetFamily() const;
267 wxFontEncoding GetEncoding() const;
268
269 void SetPointSize(int pointsize);
270 void SetPixelSize(const wxSize& pixelSize);
271 void SetStyle(wxFontStyle style);
272 void SetWeight(wxFontWeight weight);
273 void SetUnderlined(bool underlined);
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_