]> git.saurik.com Git - wxWidgets.git/blame - include/wx/fontutil.h
Only link with libwxscintilla if using Scintilla is enabled.
[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;
a349dc10
VZ
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;
2b5f62a0 79#elif defined(_WX_X_FONTLIKE)
409d5a58
VZ
80 // the members can't be accessed directly as we only parse the
81 // xFontName on demand
53f6aab7 82private:
ab5fe833 83 // the components of the XLFD
53f6aab7 84 wxString fontElements[wxXLFD_MAX];
ab5fe833
VZ
85
86 // the full XLFD
7826e2dd 87 wxString xFontName;
ab5fe833 88
409d5a58
VZ
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
95public:
a62848fd 96 // init the elements from an XLFD, return true if ok
ab5fe833
VZ
97 bool FromXFontName(const wxString& xFontName);
98
409d5a58
VZ
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)
ab5fe833 103 wxString GetXFontName() const;
53f6aab7
VZ
104
105 // get the given XFLD component
106 wxString GetXFontComponent(wxXLFDField field) const;
409d5a58
VZ
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);
82ef81ed 113#elif defined(__WXMSW__)
5e0ebb71
VZ
114 wxNativeFontInfo(const LOGFONT& lf_) : lf(lf_) { }
115
09fcd889 116 LOGFONT lf;
cc95f4f9
DW
117#elif defined(__WXPM__)
118 // OS/2 native structures that define a font
119 FATTRS fa;
120 FONTMETRICS fm;
121 FACENAMEDESC fn;
f1c40652
SC
122#elif defined(__WXOSX__)
123public:
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();
03647350 160
f1c40652 161 bool m_descriptorValid;
f1c40652
SC
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
f1c40652
SC
173#endif
174
175 int m_pointSize;
176 wxFontFamily m_family;
177 wxFontStyle m_style;
178 wxFontWeight m_weight;
179 bool m_underlined;
c7a49742 180 bool m_strikethrough;
f1c40652
SC
181 wxString m_faceName;
182 wxFontEncoding m_encoding;
183public :
7826e2dd
VZ
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 //
ef243e70 189 #define wxNO_NATIVE_FONTINFO
ab5fe833 190
7826e2dd 191 int pointSize;
7936354d 192 wxFontFamily family;
ab5fe833
VZ
193 wxFontStyle style;
194 wxFontWeight weight;
7826e2dd 195 bool underlined;
c7a49742 196 bool strikethrough;
7826e2dd
VZ
197 wxString faceName;
198 wxFontEncoding encoding;
199#endif // platforms
200
ab5fe833
VZ
201 // default ctor (default copy ctor is ok)
202 wxNativeFontInfo() { Init(); }
203
fdf7514a 204#if wxUSE_PANGO
23afe648
VZ
205private:
206 void Init(const wxNativeFontInfo& info);
207 void Free();
208
209public:
210 wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
211 ~wxNativeFontInfo() { Free(); }
212
213 wxNativeFontInfo& operator=(const wxNativeFontInfo& info)
214 {
b0423774
PC
215 if (this != &info)
216 {
217 Free();
218 Init(info);
219 }
23afe648
VZ
220 return *this;
221 }
222#endif // wxUSE_PANGO
fdf7514a 223
ab5fe833
VZ
224 // reset to the default state
225 void Init();
226
3bf5a59b
VZ
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());
c7a49742 234 SetStrikethrough(font.GetStrikethrough());
544229d1
VZ
235#if defined(__WXMSW__)
236 if ( font.IsUsingSizeInPixels() )
237 SetPixelSize(font.GetPixelSize());
238 else
66e9a9f0 239 SetPointSize(font.GetPointSize());
544229d1 240#else
3bf5a59b 241 SetPointSize(font.GetPointSize());
544229d1 242#endif
3bf5a59b
VZ
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
7936354d 257 // accessors and modifiers for the font elements
ab5fe833 258 int GetPointSize() const;
544229d1 259 wxSize GetPixelSize() const;
ab5fe833
VZ
260 wxFontStyle GetStyle() const;
261 wxFontWeight GetWeight() const;
262 bool GetUnderlined() const;
c7a49742 263 bool GetStrikethrough() const;
ab5fe833 264 wxString GetFaceName() const;
7936354d 265 wxFontFamily GetFamily() const;
ab5fe833
VZ
266 wxFontEncoding GetEncoding() const;
267
268 void SetPointSize(int pointsize);
544229d1 269 void SetPixelSize(const wxSize& pixelSize);
ab5fe833
VZ
270 void SetStyle(wxFontStyle style);
271 void SetWeight(wxFontWeight weight);
272 void SetUnderlined(bool underlined);
c7a49742 273 void SetStrikethrough(bool strikethrough);
85ab460e 274 bool SetFaceName(const wxString& facename);
7936354d 275 void SetFamily(wxFontFamily family);
ab5fe833
VZ
276 void SetEncoding(wxFontEncoding encoding);
277
85ab460e
VZ
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
7826e2dd
VZ
285 // it is important to be able to serialize wxNativeFontInfo objects to be
286 // able to store them (in config file, for example)
7beba2fc
VZ
287 bool FromString(const wxString& s);
288 wxString ToString() const;
ab5fe833
VZ
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;
7beba2fc
VZ
295};
296
297// ----------------------------------------------------------------------------
298// font-related functions (common)
299// ----------------------------------------------------------------------------
300
301// translate a wxFontEncoding into native encoding parameter (defined above),
a62848fd 302// returning true if an (exact) macth could be found, false otherwise (without
7beba2fc 303// attempting any substitutions)
09da4ae5
RD
304WXDLLIMPEXP_CORE bool wxGetNativeFontEncoding(wxFontEncoding encoding,
305 wxNativeEncodingInfo *info);
7beba2fc
VZ
306
307// test for the existence of the font described by this facename/encoding,
a62848fd 308// return true if such font(s) exist, false otherwise
09da4ae5 309WXDLLIMPEXP_CORE bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
7beba2fc
VZ
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_