]> git.saurik.com Git - wxWidgets.git/blame - include/wx/fontutil.h
HAVE_XIM is disabled in GTK2 build, don't include useless member variables
[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
12028905 19#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
7beba2fc
VZ
20 #pragma interface "fontutil.h"
21#endif
22
23// ----------------------------------------------------------------------------
24// headers
25// ----------------------------------------------------------------------------
26
27#include "wx/font.h" // for wxFont and wxFontEncoding
28
09fcd889 29#if defined(__WXMSW__)
7b162e54 30 #include "wx/msw/wrapwin.h"
09fcd889
VZ
31#endif
32
e4ffab29
MB
33struct WXDLLEXPORT wxNativeEncodingInfo;
34
53f6aab7
VZ
35#if defined(_WX_X_FONTLIKE)
36
37// the symbolic names for the XLFD fields (with examples for their value)
409d5a58
VZ
38//
39// NB: we suppose that the font always starts with the empty token (font name
40// registry field) as we never use nor generate it anyhow
53f6aab7
VZ
41enum wxXLFDField
42{
43 wxXLFD_FOUNDRY, // adobe
44 wxXLFD_FAMILY, // courier, times, ...
45 wxXLFD_WEIGHT, // black, bold, demibold, medium, regular, light
46 wxXLFD_SLANT, // r/i/o (roman/italique/oblique)
47 wxXLFD_SETWIDTH, // condensed, expanded, ...
48 wxXLFD_ADDSTYLE, // whatever - usually nothing
49 wxXLFD_PIXELSIZE, // size in pixels
50 wxXLFD_POINTSIZE, // size in points
51 wxXLFD_RESX, // 72, 75, 100, ...
52 wxXLFD_RESY,
53 wxXLFD_SPACING, // m/p/c (monospaced/proportional/character cell)
54 wxXLFD_AVGWIDTH, // average width in 1/10 pixels
55 wxXLFD_REGISTRY, // iso8859, rawin, koi8, ...
56 wxXLFD_ENCODING, // 1, r, r, ...
57 wxXLFD_MAX
58};
59
60#endif // _WX_X_FONTLIKE
61
7beba2fc
VZ
62// ----------------------------------------------------------------------------
63// types
64// ----------------------------------------------------------------------------
65
7826e2dd
VZ
66// wxNativeFontInfo is platform-specific font representation: this struct
67// should be considered as opaque font description only used by the native
68// functions, the user code can only get the objects of this type from
69// somewhere and pass it somewhere else (possibly save them somewhere using
70// ToString() and restore them using FromString())
ab5fe833
VZ
71//
72// NB: it is a POD currently for max efficiency but if it continues to grow
73// further it might make sense to make it a real class with virtual methods
7826e2dd 74struct WXDLLEXPORT wxNativeFontInfo
7beba2fc 75{
2b5f62a0
VZ
76#if wxUSE_PANGO
77 PangoFontDescription *description;
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:
ab5fe833
VZ
95 // init the elements from an XLFD, return TRUE if ok
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);
09fcd889
VZ
112#elif defined(__WXMSW__)
113 LOGFONT lf;
cc95f4f9
DW
114#elif defined(__WXPM__)
115 // OS/2 native structures that define a font
116 FATTRS fa;
117 FONTMETRICS fm;
118 FACENAMEDESC fn;
7826e2dd
VZ
119#else // other platforms
120 //
121 // This is a generic implementation that should work on all ports
122 // without specific support by the port.
123 //
ef243e70 124 #define wxNO_NATIVE_FONTINFO
ab5fe833 125
7826e2dd 126 int pointSize;
7936354d 127 wxFontFamily family;
ab5fe833
VZ
128 wxFontStyle style;
129 wxFontWeight weight;
7826e2dd
VZ
130 bool underlined;
131 wxString faceName;
132 wxFontEncoding encoding;
133#endif // platforms
134
ab5fe833
VZ
135 // default ctor (default copy ctor is ok)
136 wxNativeFontInfo() { Init(); }
137
fdf7514a
VS
138#if wxUSE_PANGO
139 wxNativeFontInfo(const wxNativeFontInfo& info);
140 ~wxNativeFontInfo();
141#endif
142
ab5fe833
VZ
143 // reset to the default state
144 void Init();
145
3bf5a59b
VZ
146 // init with the parameters of the given font
147 void InitFromFont(const wxFont& font)
148 {
149 // translate all font parameters
150 SetStyle((wxFontStyle)font.GetStyle());
151 SetWeight((wxFontWeight)font.GetWeight());
152 SetUnderlined(font.GetUnderlined());
153 SetPointSize(font.GetPointSize());
154
155 // set the family/facename
156 SetFamily((wxFontFamily)font.GetFamily());
157 const wxString& facename = font.GetFaceName();
158 if ( !facename.empty() )
159 {
160 SetFaceName(facename);
161 }
162
163 // deal with encoding now (it may override the font family and facename
164 // so do it after setting them)
165 SetEncoding(font.GetEncoding());
166 }
167
7936354d 168 // accessors and modifiers for the font elements
ab5fe833
VZ
169 int GetPointSize() const;
170 wxFontStyle GetStyle() const;
171 wxFontWeight GetWeight() const;
172 bool GetUnderlined() const;
173 wxString GetFaceName() const;
7936354d 174 wxFontFamily GetFamily() const;
ab5fe833
VZ
175 wxFontEncoding GetEncoding() const;
176
177 void SetPointSize(int pointsize);
178 void SetStyle(wxFontStyle style);
179 void SetWeight(wxFontWeight weight);
180 void SetUnderlined(bool underlined);
181 void SetFaceName(wxString facename);
7936354d 182 void SetFamily(wxFontFamily family);
ab5fe833
VZ
183 void SetEncoding(wxFontEncoding encoding);
184
7826e2dd
VZ
185 // it is important to be able to serialize wxNativeFontInfo objects to be
186 // able to store them (in config file, for example)
7beba2fc
VZ
187 bool FromString(const wxString& s);
188 wxString ToString() const;
ab5fe833
VZ
189
190 // we also want to present the native font descriptions to the user in some
191 // human-readable form (it is not platform independent neither, but can
192 // hopefully be understood by the user)
193 bool FromUserString(const wxString& s);
194 wxString ToUserString() const;
7beba2fc
VZ
195};
196
197// ----------------------------------------------------------------------------
198// font-related functions (common)
199// ----------------------------------------------------------------------------
200
201// translate a wxFontEncoding into native encoding parameter (defined above),
202// returning TRUE if an (exact) macth could be found, FALSE otherwise (without
203// attempting any substitutions)
204extern bool wxGetNativeFontEncoding(wxFontEncoding encoding,
205 wxNativeEncodingInfo *info);
206
207// test for the existence of the font described by this facename/encoding,
208// return TRUE if such font(s) exist, FALSE otherwise
209extern bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
210
211// ----------------------------------------------------------------------------
212// font-related functions (X and GTK)
213// ----------------------------------------------------------------------------
214
215#ifdef _WX_X_FONTLIKE
216 #include "wx/unix/fontutil.h"
217#endif // X || GDK
218
1e6feb95
VZ
219// ----------------------------------------------------------------------------
220// font-related functions (MGL)
221// ----------------------------------------------------------------------------
222
223#ifdef __WXMGL__
224 #include "wx/mgl/fontutil.h"
225#endif // __WXMGL__
226
7beba2fc 227#endif // _WX_FONTUTIL_H_