]> git.saurik.com Git - wxWidgets.git/blame - include/wx/fontutil.h
correct the signature of the overriden Reparent()
[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())
53a2db12 68class WXDLLIMPEXP_CORE wxNativeFontInfo
7beba2fc 69{
85ab460e 70public:
2b5f62a0
VZ
71#if wxUSE_PANGO
72 PangoFontDescription *description;
73#elif defined(_WX_X_FONTLIKE)
409d5a58
VZ
74 // the members can't be accessed directly as we only parse the
75 // xFontName on demand
53f6aab7 76private:
ab5fe833 77 // the components of the XLFD
53f6aab7 78 wxString fontElements[wxXLFD_MAX];
ab5fe833
VZ
79
80 // the full XLFD
7826e2dd 81 wxString xFontName;
ab5fe833 82
409d5a58
VZ
83 // true until SetXFontName() is called
84 bool m_isDefault;
85
86 // return true if we have already initialized fontElements
87 inline bool HasElements() const;
88
89public:
a62848fd 90 // init the elements from an XLFD, return true if ok
ab5fe833
VZ
91 bool FromXFontName(const wxString& xFontName);
92
409d5a58
VZ
93 // return false if we were never initialized with a valid XLFD
94 bool IsDefault() const { return m_isDefault; }
95
96 // return the XLFD (using the fontElements if necessary)
ab5fe833 97 wxString GetXFontName() const;
53f6aab7
VZ
98
99 // get the given XFLD component
100 wxString GetXFontComponent(wxXLFDField field) const;
409d5a58
VZ
101
102 // change the font component
103 void SetXFontComponent(wxXLFDField field, const wxString& value);
104
105 // set the XFLD
106 void SetXFontName(const wxString& xFontName);
82ef81ed 107#elif defined(__WXMSW__)
5e0ebb71
VZ
108 wxNativeFontInfo(const LOGFONT& lf_) : lf(lf_) { }
109
09fcd889 110 LOGFONT lf;
cc95f4f9
DW
111#elif defined(__WXPM__)
112 // OS/2 native structures that define a font
113 FATTRS fa;
114 FONTMETRICS fm;
115 FACENAMEDESC fn;
7826e2dd
VZ
116#else // other platforms
117 //
118 // This is a generic implementation that should work on all ports
119 // without specific support by the port.
120 //
ef243e70 121 #define wxNO_NATIVE_FONTINFO
ab5fe833 122
7826e2dd 123 int pointSize;
7936354d 124 wxFontFamily family;
ab5fe833
VZ
125 wxFontStyle style;
126 wxFontWeight weight;
7826e2dd
VZ
127 bool underlined;
128 wxString faceName;
129 wxFontEncoding encoding;
130#endif // platforms
131
ab5fe833
VZ
132 // default ctor (default copy ctor is ok)
133 wxNativeFontInfo() { Init(); }
134
fdf7514a 135#if wxUSE_PANGO
23afe648
VZ
136private:
137 void Init(const wxNativeFontInfo& info);
138 void Free();
139
140public:
141 wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
142 ~wxNativeFontInfo() { Free(); }
143
144 wxNativeFontInfo& operator=(const wxNativeFontInfo& info)
145 {
146 Free();
147 Init(info);
148 return *this;
149 }
150#endif // wxUSE_PANGO
fdf7514a 151
ab5fe833
VZ
152 // reset to the default state
153 void Init();
154
3bf5a59b
VZ
155 // init with the parameters of the given font
156 void InitFromFont(const wxFont& font)
157 {
158 // translate all font parameters
159 SetStyle((wxFontStyle)font.GetStyle());
160 SetWeight((wxFontWeight)font.GetWeight());
161 SetUnderlined(font.GetUnderlined());
544229d1
VZ
162#if defined(__WXMSW__)
163 if ( font.IsUsingSizeInPixels() )
164 SetPixelSize(font.GetPixelSize());
165 else
66e9a9f0 166 SetPointSize(font.GetPointSize());
544229d1 167#else
3bf5a59b 168 SetPointSize(font.GetPointSize());
544229d1 169#endif
3bf5a59b
VZ
170
171 // set the family/facename
172 SetFamily((wxFontFamily)font.GetFamily());
173 const wxString& facename = font.GetFaceName();
174 if ( !facename.empty() )
175 {
176 SetFaceName(facename);
177 }
178
179 // deal with encoding now (it may override the font family and facename
180 // so do it after setting them)
181 SetEncoding(font.GetEncoding());
182 }
183
7936354d 184 // accessors and modifiers for the font elements
ab5fe833 185 int GetPointSize() const;
544229d1 186 wxSize GetPixelSize() const;
ab5fe833
VZ
187 wxFontStyle GetStyle() const;
188 wxFontWeight GetWeight() const;
189 bool GetUnderlined() const;
190 wxString GetFaceName() const;
7936354d 191 wxFontFamily GetFamily() const;
ab5fe833
VZ
192 wxFontEncoding GetEncoding() const;
193
194 void SetPointSize(int pointsize);
544229d1 195 void SetPixelSize(const wxSize& pixelSize);
ab5fe833
VZ
196 void SetStyle(wxFontStyle style);
197 void SetWeight(wxFontWeight weight);
198 void SetUnderlined(bool underlined);
85ab460e 199 bool SetFaceName(const wxString& facename);
7936354d 200 void SetFamily(wxFontFamily family);
ab5fe833
VZ
201 void SetEncoding(wxFontEncoding encoding);
202
85ab460e
VZ
203 // sets the first facename in the given array which is found
204 // to be valid. If no valid facename is given, sets the
205 // first valid facename returned by wxFontEnumerator::GetFacenames().
206 // Does not return a bool since it cannot fail.
207 void SetFaceName(const wxArrayString &facenames);
208
209
7826e2dd
VZ
210 // it is important to be able to serialize wxNativeFontInfo objects to be
211 // able to store them (in config file, for example)
7beba2fc
VZ
212 bool FromString(const wxString& s);
213 wxString ToString() const;
ab5fe833
VZ
214
215 // we also want to present the native font descriptions to the user in some
216 // human-readable form (it is not platform independent neither, but can
217 // hopefully be understood by the user)
218 bool FromUserString(const wxString& s);
219 wxString ToUserString() const;
7beba2fc
VZ
220};
221
222// ----------------------------------------------------------------------------
223// font-related functions (common)
224// ----------------------------------------------------------------------------
225
226// translate a wxFontEncoding into native encoding parameter (defined above),
a62848fd 227// returning true if an (exact) macth could be found, false otherwise (without
7beba2fc 228// attempting any substitutions)
09da4ae5
RD
229WXDLLIMPEXP_CORE bool wxGetNativeFontEncoding(wxFontEncoding encoding,
230 wxNativeEncodingInfo *info);
7beba2fc
VZ
231
232// test for the existence of the font described by this facename/encoding,
a62848fd 233// return true if such font(s) exist, false otherwise
09da4ae5 234WXDLLIMPEXP_CORE bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
7beba2fc
VZ
235
236// ----------------------------------------------------------------------------
237// font-related functions (X and GTK)
238// ----------------------------------------------------------------------------
239
240#ifdef _WX_X_FONTLIKE
241 #include "wx/unix/fontutil.h"
242#endif // X || GDK
243
244#endif // _WX_FONTUTIL_H_