]>
Commit | Line | Data |
---|---|---|
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 | // Copyright: (c) wxWidgets team | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // General note: this header is private to wxWidgets and is not supposed to be | |
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 | ||
18 | // ---------------------------------------------------------------------------- | |
19 | // headers | |
20 | // ---------------------------------------------------------------------------- | |
21 | ||
22 | #include "wx/font.h" // for wxFont and wxFontEncoding | |
23 | ||
24 | #if defined(__WXMSW__) | |
25 | #include "wx/msw/wrapwin.h" | |
26 | #endif | |
27 | ||
28 | class WXDLLIMPEXP_FWD_BASE wxArrayString; | |
29 | struct WXDLLIMPEXP_FWD_CORE wxNativeEncodingInfo; | |
30 | ||
31 | #if defined(_WX_X_FONTLIKE) | |
32 | ||
33 | // the symbolic names for the XLFD fields (with examples for their value) | |
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 | |
37 | enum 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 | ||
58 | // ---------------------------------------------------------------------------- | |
59 | // types | |
60 | // ---------------------------------------------------------------------------- | |
61 | ||
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()) | |
67 | ||
68 | class WXDLLIMPEXP_CORE wxNativeFontInfo | |
69 | { | |
70 | public: | |
71 | #if wxUSE_PANGO | |
72 | PangoFontDescription *description; | |
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; | |
78 | #elif defined(_WX_X_FONTLIKE) | |
79 | // the members can't be accessed directly as we only parse the | |
80 | // xFontName on demand | |
81 | private: | |
82 | // the components of the XLFD | |
83 | wxString fontElements[wxXLFD_MAX]; | |
84 | ||
85 | // the full XLFD | |
86 | wxString xFontName; | |
87 | ||
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 | ||
94 | public: | |
95 | // init the elements from an XLFD, return true if ok | |
96 | bool FromXFontName(const wxString& xFontName); | |
97 | ||
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) | |
102 | wxString GetXFontName() const; | |
103 | ||
104 | // get the given XFLD component | |
105 | wxString GetXFontComponent(wxXLFDField field) const; | |
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); | |
112 | #elif defined(__WXMSW__) | |
113 | wxNativeFontInfo(const LOGFONT& lf_) : lf(lf_) { } | |
114 | ||
115 | LOGFONT lf; | |
116 | #elif defined(__WXPM__) | |
117 | // OS/2 native structures that define a font | |
118 | FATTRS fa; | |
119 | FONTMETRICS fm; | |
120 | FACENAMEDESC fn; | |
121 | #elif defined(__WXOSX__) | |
122 | public: | |
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(); | |
159 | ||
160 | bool m_descriptorValid; | |
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 | |
172 | #endif | |
173 | ||
174 | int m_pointSize; | |
175 | wxFontFamily m_family; | |
176 | wxFontStyle m_style; | |
177 | wxFontWeight m_weight; | |
178 | bool m_underlined; | |
179 | bool m_strikethrough; | |
180 | wxString m_faceName; | |
181 | wxFontEncoding m_encoding; | |
182 | public : | |
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 | // | |
188 | #define wxNO_NATIVE_FONTINFO | |
189 | ||
190 | int pointSize; | |
191 | wxFontFamily family; | |
192 | wxFontStyle style; | |
193 | wxFontWeight weight; | |
194 | bool underlined; | |
195 | bool strikethrough; | |
196 | wxString faceName; | |
197 | wxFontEncoding encoding; | |
198 | #endif // platforms | |
199 | ||
200 | // default ctor (default copy ctor is ok) | |
201 | wxNativeFontInfo() { Init(); } | |
202 | ||
203 | #if wxUSE_PANGO | |
204 | private: | |
205 | void Init(const wxNativeFontInfo& info); | |
206 | void Free(); | |
207 | ||
208 | public: | |
209 | wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); } | |
210 | ~wxNativeFontInfo() { Free(); } | |
211 | ||
212 | wxNativeFontInfo& operator=(const wxNativeFontInfo& info) | |
213 | { | |
214 | if (this != &info) | |
215 | { | |
216 | Free(); | |
217 | Init(info); | |
218 | } | |
219 | return *this; | |
220 | } | |
221 | #endif // wxUSE_PANGO | |
222 | ||
223 | // reset to the default state | |
224 | void Init(); | |
225 | ||
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()); | |
233 | SetStrikethrough(font.GetStrikethrough()); | |
234 | #if defined(__WXMSW__) | |
235 | if ( font.IsUsingSizeInPixels() ) | |
236 | SetPixelSize(font.GetPixelSize()); | |
237 | else | |
238 | SetPointSize(font.GetPointSize()); | |
239 | #else | |
240 | SetPointSize(font.GetPointSize()); | |
241 | #endif | |
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 | ||
256 | // accessors and modifiers for the font elements | |
257 | int GetPointSize() const; | |
258 | wxSize GetPixelSize() const; | |
259 | wxFontStyle GetStyle() const; | |
260 | wxFontWeight GetWeight() const; | |
261 | bool GetUnderlined() const; | |
262 | bool GetStrikethrough() const; | |
263 | wxString GetFaceName() const; | |
264 | wxFontFamily GetFamily() const; | |
265 | wxFontEncoding GetEncoding() const; | |
266 | ||
267 | void SetPointSize(int pointsize); | |
268 | void SetPixelSize(const wxSize& pixelSize); | |
269 | void SetStyle(wxFontStyle style); | |
270 | void SetWeight(wxFontWeight weight); | |
271 | void SetUnderlined(bool underlined); | |
272 | void SetStrikethrough(bool strikethrough); | |
273 | bool SetFaceName(const wxString& facename); | |
274 | void SetFamily(wxFontFamily family); | |
275 | void SetEncoding(wxFontEncoding encoding); | |
276 | ||
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 | ||
284 | // it is important to be able to serialize wxNativeFontInfo objects to be | |
285 | // able to store them (in config file, for example) | |
286 | bool FromString(const wxString& s); | |
287 | wxString ToString() const; | |
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; | |
294 | }; | |
295 | ||
296 | // ---------------------------------------------------------------------------- | |
297 | // font-related functions (common) | |
298 | // ---------------------------------------------------------------------------- | |
299 | ||
300 | // translate a wxFontEncoding into native encoding parameter (defined above), | |
301 | // returning true if an (exact) macth could be found, false otherwise (without | |
302 | // attempting any substitutions) | |
303 | WXDLLIMPEXP_CORE bool wxGetNativeFontEncoding(wxFontEncoding encoding, | |
304 | wxNativeEncodingInfo *info); | |
305 | ||
306 | // test for the existence of the font described by this facename/encoding, | |
307 | // return true if such font(s) exist, false otherwise | |
308 | WXDLLIMPEXP_CORE bool wxTestFontEncoding(const wxNativeEncodingInfo& info); | |
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_ |