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