]> git.saurik.com Git - wxWidgets.git/blame - include/wx/fontutil.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[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
77ffb593 7// Copyright: (c) wxWidgets team
65571936 8// Licence: wxWindows licence
7beba2fc
VZ
9/////////////////////////////////////////////////////////////////////////////
10
77ffb593 11// General note: this header is private to wxWidgets and is not supposed to be
7beba2fc
VZ
12// included by user code. The functions declared here are implemented in
13// msw/fontutil.cpp for Windows, unix/fontutil.cpp for GTK/Motif &c.
14
15#ifndef _WX_FONTUTIL_H_
16#define _WX_FONTUTIL_H_
17
7beba2fc
VZ
18// ----------------------------------------------------------------------------
19// headers
20// ----------------------------------------------------------------------------
21
22#include "wx/font.h" // for wxFont and wxFontEncoding
23
82ef81ed 24#if defined(__WXMSW__)
7b162e54 25 #include "wx/msw/wrapwin.h"
09fcd889
VZ
26#endif
27
b5dbe15d
VS
28class WXDLLIMPEXP_FWD_BASE wxArrayString;
29struct WXDLLIMPEXP_FWD_CORE wxNativeEncodingInfo;
e4ffab29 30
53f6aab7
VZ
31#if defined(_WX_X_FONTLIKE)
32
33// the symbolic names for the XLFD fields (with examples for their value)
409d5a58
VZ
34//
35// NB: we suppose that the font always starts with the empty token (font name
36// registry field) as we never use nor generate it anyhow
53f6aab7
VZ
37enum wxXLFDField
38{
39 wxXLFD_FOUNDRY, // adobe
40 wxXLFD_FAMILY, // courier, times, ...
41 wxXLFD_WEIGHT, // black, bold, demibold, medium, regular, light
42 wxXLFD_SLANT, // r/i/o (roman/italique/oblique)
43 wxXLFD_SETWIDTH, // condensed, expanded, ...
44 wxXLFD_ADDSTYLE, // whatever - usually nothing
45 wxXLFD_PIXELSIZE, // size in pixels
46 wxXLFD_POINTSIZE, // size in points
47 wxXLFD_RESX, // 72, 75, 100, ...
48 wxXLFD_RESY,
49 wxXLFD_SPACING, // m/p/c (monospaced/proportional/character cell)
50 wxXLFD_AVGWIDTH, // average width in 1/10 pixels
51 wxXLFD_REGISTRY, // iso8859, rawin, koi8, ...
52 wxXLFD_ENCODING, // 1, r, r, ...
53 wxXLFD_MAX
54};
55
56#endif // _WX_X_FONTLIKE
57
7beba2fc
VZ
58// ----------------------------------------------------------------------------
59// types
60// ----------------------------------------------------------------------------
61
7826e2dd
VZ
62// wxNativeFontInfo is platform-specific font representation: this struct
63// should be considered as opaque font description only used by the native
64// functions, the user code can only get the objects of this type from
65// somewhere and pass it somewhere else (possibly save them somewhere using
66// ToString() and restore them using FromString())
f1c40652 67
53a2db12 68class WXDLLIMPEXP_CORE wxNativeFontInfo
7beba2fc 69{
85ab460e 70public:
2b5f62a0
VZ
71#if wxUSE_PANGO
72 PangoFontDescription *description;
a349dc10
VZ
73
74 // Pango font description doesn't have these attributes, so we store them
75 // separately and handle them ourselves in {To,From}String() methods.
76 bool m_underlined;
77 bool m_strikethrough;
2b5f62a0 78#elif defined(_WX_X_FONTLIKE)
409d5a58
VZ
79 // the members can't be accessed directly as we only parse the
80 // xFontName on demand
53f6aab7 81private:
ab5fe833 82 // the components of the XLFD
53f6aab7 83 wxString fontElements[wxXLFD_MAX];
ab5fe833
VZ
84
85 // the full XLFD
7826e2dd 86 wxString xFontName;
ab5fe833 87
409d5a58
VZ
88 // true until SetXFontName() is called
89 bool m_isDefault;
90
91 // return true if we have already initialized fontElements
92 inline bool HasElements() const;
93
94public:
a62848fd 95 // init the elements from an XLFD, return true if ok
ab5fe833
VZ
96 bool FromXFontName(const wxString& xFontName);
97
409d5a58
VZ
98 // return false if we were never initialized with a valid XLFD
99 bool IsDefault() const { return m_isDefault; }
100
101 // return the XLFD (using the fontElements if necessary)
ab5fe833 102 wxString GetXFontName() const;
53f6aab7
VZ
103
104 // get the given XFLD component
105 wxString GetXFontComponent(wxXLFDField field) const;
409d5a58
VZ
106
107 // change the font component
108 void SetXFontComponent(wxXLFDField field, const wxString& value);
109
110 // set the XFLD
111 void SetXFontName(const wxString& xFontName);
82ef81ed 112#elif defined(__WXMSW__)
5e0ebb71
VZ
113 wxNativeFontInfo(const LOGFONT& lf_) : lf(lf_) { }
114
09fcd889 115 LOGFONT lf;
cc95f4f9
DW
116#elif defined(__WXPM__)
117 // OS/2 native structures that define a font
118 FATTRS fa;
119 FONTMETRICS fm;
120 FACENAMEDESC fn;
f1c40652
SC
121#elif defined(__WXOSX__)
122public:
123 wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
124 wxNativeFontInfo( int size,
125 wxFontFamily family,
126 wxFontStyle style,
127 wxFontWeight weight,
128 bool underlined,
129 const wxString& faceName,
130 wxFontEncoding encoding)
131 { Init(size,family,style,weight,underlined,faceName,encoding); }
132
133 ~wxNativeFontInfo() { Free(); }
134
135 wxNativeFontInfo& operator=(const wxNativeFontInfo& info)
136 {
137 if (this != &info)
138 {
139 Free();
140 Init(info);
141 }
142 return *this;
143 }
144
145#if wxOSX_USE_CORE_TEXT
146 void Init(CTFontDescriptorRef descr);
147#endif
148 void Init(const wxNativeFontInfo& info);
149 void Init(int size,
150 wxFontFamily family,
151 wxFontStyle style,
152 wxFontWeight weight,
153 bool underlined,
154 const wxString& faceName ,
155 wxFontEncoding encoding);
156
157 void Free();
158 void EnsureValid();
03647350 159
f1c40652 160 bool m_descriptorValid;
f1c40652
SC
161
162#if wxOSX_USE_ATSU_TEXT
163 bool m_atsuFontValid;
164 // the atsu font ID
165 wxUint32 m_atsuFontID;
166 // the qd styles that are not intrinsic to the font above
167 wxInt16 m_atsuAdditionalQDStyles;
168#if wxOSX_USE_CARBON
169 wxInt16 m_qdFontFamily;
170 wxInt16 m_qdFontStyle;
171#endif
f1c40652
SC
172#endif
173
174 int m_pointSize;
175 wxFontFamily m_family;
176 wxFontStyle m_style;
177 wxFontWeight m_weight;
178 bool m_underlined;
c7a49742 179 bool m_strikethrough;
f1c40652
SC
180 wxString m_faceName;
181 wxFontEncoding m_encoding;
182public :
7826e2dd
VZ
183#else // other platforms
184 //
185 // This is a generic implementation that should work on all ports
186 // without specific support by the port.
187 //
ef243e70 188 #define wxNO_NATIVE_FONTINFO
ab5fe833 189
7826e2dd 190 int pointSize;
7936354d 191 wxFontFamily family;
ab5fe833
VZ
192 wxFontStyle style;
193 wxFontWeight weight;
7826e2dd 194 bool underlined;
c7a49742 195 bool strikethrough;
7826e2dd
VZ
196 wxString faceName;
197 wxFontEncoding encoding;
198#endif // platforms
199
ab5fe833
VZ
200 // default ctor (default copy ctor is ok)
201 wxNativeFontInfo() { Init(); }
202
fdf7514a 203#if wxUSE_PANGO
23afe648
VZ
204private:
205 void Init(const wxNativeFontInfo& info);
206 void Free();
207
208public:
209 wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
210 ~wxNativeFontInfo() { Free(); }
211
212 wxNativeFontInfo& operator=(const wxNativeFontInfo& info)
213 {
b0423774
PC
214 if (this != &info)
215 {
216 Free();
217 Init(info);
218 }
23afe648
VZ
219 return *this;
220 }
221#endif // wxUSE_PANGO
fdf7514a 222
ab5fe833
VZ
223 // reset to the default state
224 void Init();
225
3bf5a59b
VZ
226 // init with the parameters of the given font
227 void InitFromFont(const wxFont& font)
228 {
229 // translate all font parameters
230 SetStyle((wxFontStyle)font.GetStyle());
231 SetWeight((wxFontWeight)font.GetWeight());
232 SetUnderlined(font.GetUnderlined());
c7a49742 233 SetStrikethrough(font.GetStrikethrough());
544229d1
VZ
234#if defined(__WXMSW__)
235 if ( font.IsUsingSizeInPixels() )
236 SetPixelSize(font.GetPixelSize());
237 else
66e9a9f0 238 SetPointSize(font.GetPointSize());
544229d1 239#else
3bf5a59b 240 SetPointSize(font.GetPointSize());
544229d1 241#endif
3bf5a59b
VZ
242
243 // set the family/facename
244 SetFamily((wxFontFamily)font.GetFamily());
245 const wxString& facename = font.GetFaceName();
246 if ( !facename.empty() )
247 {
248 SetFaceName(facename);
249 }
250
251 // deal with encoding now (it may override the font family and facename
252 // so do it after setting them)
253 SetEncoding(font.GetEncoding());
254 }
255
7936354d 256 // accessors and modifiers for the font elements
ab5fe833 257 int GetPointSize() const;
544229d1 258 wxSize GetPixelSize() const;
ab5fe833
VZ
259 wxFontStyle GetStyle() const;
260 wxFontWeight GetWeight() const;
261 bool GetUnderlined() const;
c7a49742 262 bool GetStrikethrough() const;
ab5fe833 263 wxString GetFaceName() const;
7936354d 264 wxFontFamily GetFamily() const;
ab5fe833
VZ
265 wxFontEncoding GetEncoding() const;
266
267 void SetPointSize(int pointsize);
544229d1 268 void SetPixelSize(const wxSize& pixelSize);
ab5fe833
VZ
269 void SetStyle(wxFontStyle style);
270 void SetWeight(wxFontWeight weight);
271 void SetUnderlined(bool underlined);
c7a49742 272 void SetStrikethrough(bool strikethrough);
85ab460e 273 bool SetFaceName(const wxString& facename);
7936354d 274 void SetFamily(wxFontFamily family);
ab5fe833
VZ
275 void SetEncoding(wxFontEncoding encoding);
276
85ab460e
VZ
277 // sets the first facename in the given array which is found
278 // to be valid. If no valid facename is given, sets the
279 // first valid facename returned by wxFontEnumerator::GetFacenames().
280 // Does not return a bool since it cannot fail.
281 void SetFaceName(const wxArrayString &facenames);
282
283
7826e2dd
VZ
284 // it is important to be able to serialize wxNativeFontInfo objects to be
285 // able to store them (in config file, for example)
7beba2fc
VZ
286 bool FromString(const wxString& s);
287 wxString ToString() const;
ab5fe833
VZ
288
289 // we also want to present the native font descriptions to the user in some
290 // human-readable form (it is not platform independent neither, but can
291 // hopefully be understood by the user)
292 bool FromUserString(const wxString& s);
293 wxString ToUserString() const;
7beba2fc
VZ
294};
295
296// ----------------------------------------------------------------------------
297// font-related functions (common)
298// ----------------------------------------------------------------------------
299
300// translate a wxFontEncoding into native encoding parameter (defined above),
a62848fd 301// returning true if an (exact) macth could be found, false otherwise (without
7beba2fc 302// attempting any substitutions)
09da4ae5
RD
303WXDLLIMPEXP_CORE bool wxGetNativeFontEncoding(wxFontEncoding encoding,
304 wxNativeEncodingInfo *info);
7beba2fc
VZ
305
306// test for the existence of the font described by this facename/encoding,
a62848fd 307// return true if such font(s) exist, false otherwise
09da4ae5 308WXDLLIMPEXP_CORE bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
7beba2fc
VZ
309
310// ----------------------------------------------------------------------------
311// font-related functions (X and GTK)
312// ----------------------------------------------------------------------------
313
314#ifdef _WX_X_FONTLIKE
315 #include "wx/unix/fontutil.h"
316#endif // X || GDK
317
318#endif // _WX_FONTUTIL_H_