]> git.saurik.com Git - wxWidgets.git/blame - include/wx/fontutil.h
Increase version to 2.9.5.
[wxWidgets.git] / include / wx / fontutil.h
CommitLineData
7beba2fc
VZ
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$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
7beba2fc
VZ
10/////////////////////////////////////////////////////////////////////////////
11
77ffb593 12// General note: this header is private to wxWidgets and is not supposed to be
7beba2fc
VZ
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
7beba2fc
VZ
19// ----------------------------------------------------------------------------
20// headers
21// ----------------------------------------------------------------------------
22
23#include "wx/font.h" // for wxFont and wxFontEncoding
24
82ef81ed 25#if defined(__WXMSW__)
7b162e54 26 #include "wx/msw/wrapwin.h"
09fcd889
VZ
27#endif
28
b5dbe15d
VS
29class WXDLLIMPEXP_FWD_BASE wxArrayString;
30struct WXDLLIMPEXP_FWD_CORE wxNativeEncodingInfo;
e4ffab29 31
53f6aab7
VZ
32#if defined(_WX_X_FONTLIKE)
33
34// the symbolic names for the XLFD fields (with examples for their value)
409d5a58
VZ
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
53f6aab7
VZ
38enum 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
7beba2fc
VZ
59// ----------------------------------------------------------------------------
60// types
61// ----------------------------------------------------------------------------
62
7826e2dd
VZ
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())
f1c40652 68
53a2db12 69class WXDLLIMPEXP_CORE wxNativeFontInfo
7beba2fc 70{
85ab460e 71public:
2b5f62a0
VZ
72#if wxUSE_PANGO
73 PangoFontDescription *description;
74#elif defined(_WX_X_FONTLIKE)
409d5a58
VZ
75 // the members can't be accessed directly as we only parse the
76 // xFontName on demand
53f6aab7 77private:
ab5fe833 78 // the components of the XLFD
53f6aab7 79 wxString fontElements[wxXLFD_MAX];
ab5fe833
VZ
80
81 // the full XLFD
7826e2dd 82 wxString xFontName;
ab5fe833 83
409d5a58
VZ
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
90public:
a62848fd 91 // init the elements from an XLFD, return true if ok
ab5fe833
VZ
92 bool FromXFontName(const wxString& xFontName);
93
409d5a58
VZ
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)
ab5fe833 98 wxString GetXFontName() const;
53f6aab7
VZ
99
100 // get the given XFLD component
101 wxString GetXFontComponent(wxXLFDField field) const;
409d5a58
VZ
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);
82ef81ed 108#elif defined(__WXMSW__)
5e0ebb71
VZ
109 wxNativeFontInfo(const LOGFONT& lf_) : lf(lf_) { }
110
09fcd889 111 LOGFONT lf;
cc95f4f9
DW
112#elif defined(__WXPM__)
113 // OS/2 native structures that define a font
114 FATTRS fa;
115 FONTMETRICS fm;
116 FACENAMEDESC fn;
f1c40652
SC
117#elif defined(__WXOSX__)
118public:
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();
03647350 155
f1c40652 156 bool m_descriptorValid;
f1c40652
SC
157
158#if wxOSX_USE_ATSU_TEXT
159 bool m_atsuFontValid;
160 // the atsu font ID
161 wxUint32 m_atsuFontID;
162 // the qd styles that are not intrinsic to the font above
163 wxInt16 m_atsuAdditionalQDStyles;
164#if wxOSX_USE_CARBON
165 wxInt16 m_qdFontFamily;
166 wxInt16 m_qdFontStyle;
167#endif
f1c40652
SC
168#endif
169
170 int m_pointSize;
171 wxFontFamily m_family;
172 wxFontStyle m_style;
173 wxFontWeight m_weight;
174 bool m_underlined;
c7a49742 175 bool m_strikethrough;
f1c40652
SC
176 wxString m_faceName;
177 wxFontEncoding m_encoding;
178public :
7826e2dd
VZ
179#else // other platforms
180 //
181 // This is a generic implementation that should work on all ports
182 // without specific support by the port.
183 //
ef243e70 184 #define wxNO_NATIVE_FONTINFO
ab5fe833 185
7826e2dd 186 int pointSize;
7936354d 187 wxFontFamily family;
ab5fe833
VZ
188 wxFontStyle style;
189 wxFontWeight weight;
7826e2dd 190 bool underlined;
c7a49742 191 bool strikethrough;
7826e2dd
VZ
192 wxString faceName;
193 wxFontEncoding encoding;
194#endif // platforms
195
ab5fe833
VZ
196 // default ctor (default copy ctor is ok)
197 wxNativeFontInfo() { Init(); }
198
fdf7514a 199#if wxUSE_PANGO
23afe648
VZ
200private:
201 void Init(const wxNativeFontInfo& info);
202 void Free();
203
204public:
205 wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
206 ~wxNativeFontInfo() { Free(); }
207
208 wxNativeFontInfo& operator=(const wxNativeFontInfo& info)
209 {
b0423774
PC
210 if (this != &info)
211 {
212 Free();
213 Init(info);
214 }
23afe648
VZ
215 return *this;
216 }
217#endif // wxUSE_PANGO
fdf7514a 218
ab5fe833
VZ
219 // reset to the default state
220 void Init();
221
3bf5a59b
VZ
222 // init with the parameters of the given font
223 void InitFromFont(const wxFont& font)
224 {
225 // translate all font parameters
226 SetStyle((wxFontStyle)font.GetStyle());
227 SetWeight((wxFontWeight)font.GetWeight());
228 SetUnderlined(font.GetUnderlined());
c7a49742 229 SetStrikethrough(font.GetStrikethrough());
544229d1
VZ
230#if defined(__WXMSW__)
231 if ( font.IsUsingSizeInPixels() )
232 SetPixelSize(font.GetPixelSize());
233 else
66e9a9f0 234 SetPointSize(font.GetPointSize());
544229d1 235#else
3bf5a59b 236 SetPointSize(font.GetPointSize());
544229d1 237#endif
3bf5a59b
VZ
238
239 // set the family/facename
240 SetFamily((wxFontFamily)font.GetFamily());
241 const wxString& facename = font.GetFaceName();
242 if ( !facename.empty() )
243 {
244 SetFaceName(facename);
245 }
246
247 // deal with encoding now (it may override the font family and facename
248 // so do it after setting them)
249 SetEncoding(font.GetEncoding());
250 }
251
7936354d 252 // accessors and modifiers for the font elements
ab5fe833 253 int GetPointSize() const;
544229d1 254 wxSize GetPixelSize() const;
ab5fe833
VZ
255 wxFontStyle GetStyle() const;
256 wxFontWeight GetWeight() const;
257 bool GetUnderlined() const;
c7a49742 258 bool GetStrikethrough() const;
ab5fe833 259 wxString GetFaceName() const;
7936354d 260 wxFontFamily GetFamily() const;
ab5fe833
VZ
261 wxFontEncoding GetEncoding() const;
262
263 void SetPointSize(int pointsize);
544229d1 264 void SetPixelSize(const wxSize& pixelSize);
ab5fe833
VZ
265 void SetStyle(wxFontStyle style);
266 void SetWeight(wxFontWeight weight);
267 void SetUnderlined(bool underlined);
c7a49742 268 void SetStrikethrough(bool strikethrough);
85ab460e 269 bool SetFaceName(const wxString& facename);
7936354d 270 void SetFamily(wxFontFamily family);
ab5fe833
VZ
271 void SetEncoding(wxFontEncoding encoding);
272
85ab460e
VZ
273 // sets the first facename in the given array which is found
274 // to be valid. If no valid facename is given, sets the
275 // first valid facename returned by wxFontEnumerator::GetFacenames().
276 // Does not return a bool since it cannot fail.
277 void SetFaceName(const wxArrayString &facenames);
278
279
7826e2dd
VZ
280 // it is important to be able to serialize wxNativeFontInfo objects to be
281 // able to store them (in config file, for example)
7beba2fc
VZ
282 bool FromString(const wxString& s);
283 wxString ToString() const;
ab5fe833
VZ
284
285 // we also want to present the native font descriptions to the user in some
286 // human-readable form (it is not platform independent neither, but can
287 // hopefully be understood by the user)
288 bool FromUserString(const wxString& s);
289 wxString ToUserString() const;
7beba2fc
VZ
290};
291
292// ----------------------------------------------------------------------------
293// font-related functions (common)
294// ----------------------------------------------------------------------------
295
296// translate a wxFontEncoding into native encoding parameter (defined above),
a62848fd 297// returning true if an (exact) macth could be found, false otherwise (without
7beba2fc 298// attempting any substitutions)
09da4ae5
RD
299WXDLLIMPEXP_CORE bool wxGetNativeFontEncoding(wxFontEncoding encoding,
300 wxNativeEncodingInfo *info);
7beba2fc
VZ
301
302// test for the existence of the font described by this facename/encoding,
a62848fd 303// return true if such font(s) exist, false otherwise
09da4ae5 304WXDLLIMPEXP_CORE bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
7beba2fc
VZ
305
306// ----------------------------------------------------------------------------
307// font-related functions (X and GTK)
308// ----------------------------------------------------------------------------
309
310#ifdef _WX_X_FONTLIKE
311 #include "wx/unix/fontutil.h"
312#endif // X || GDK
313
314#endif // _WX_FONTUTIL_H_