]>
Commit | Line | Data |
---|---|---|
7beba2fc VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: unix/fontutil.cpp | |
3 | // Purpose: Font helper functions for X11 (GDK/X) | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 05.11.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Vadim Zeitlin | |
65571936 | 9 | // Licence: wxWindows licence |
7beba2fc VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
7beba2fc VZ |
21 | #pragma implementation "fontutil.h" |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
e4ffab29 | 32 | #include "wx/encinfo.h" |
7beba2fc VZ |
33 | #endif // PCH |
34 | ||
db16cab4 RR |
35 | #include "wx/fontutil.h" |
36 | #include "wx/fontmap.h" | |
37 | #include "wx/tokenzr.h" | |
38 | #include "wx/hash.h" | |
39 | #include "wx/module.h" | |
40 | ||
2b5f62a0 VZ |
41 | #if wxUSE_PANGO |
42 | ||
43 | #include "pango/pango.h" | |
db16cab4 | 44 | |
2b5f62a0 | 45 | #ifdef __WXGTK20__ |
db16cab4 | 46 | #include "wx/gtk/private.h" |
2b5f62a0 VZ |
47 | #else |
48 | #include "wx/x11/private.h" | |
49 | #endif | |
db16cab4 RR |
50 | |
51 | // ---------------------------------------------------------------------------- | |
52 | // wxNativeFontInfo | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
55 | void wxNativeFontInfo::Init() | |
56 | { | |
57 | description = NULL; | |
58 | } | |
59 | ||
23afe648 VZ |
60 | void |
61 | wxNativeFontInfo::Init(const wxNativeFontInfo& info) | |
fdf7514a VS |
62 | { |
63 | if (info.description) | |
64 | description = pango_font_description_copy(info.description); | |
65 | else | |
82680055 | 66 | description = NULL; |
fdf7514a VS |
67 | } |
68 | ||
82680055 | 69 | void wxNativeFontInfo::Free() |
fdf7514a VS |
70 | { |
71 | if (description) | |
72 | pango_font_description_free(description); | |
73 | } | |
74 | ||
db16cab4 RR |
75 | int wxNativeFontInfo::GetPointSize() const |
76 | { | |
77 | return pango_font_description_get_size( description ) / PANGO_SCALE; | |
78 | } | |
79 | ||
80 | wxFontStyle wxNativeFontInfo::GetStyle() const | |
81 | { | |
82 | wxFontStyle m_style = wxFONTSTYLE_NORMAL; | |
83 | ||
84 | switch (pango_font_description_get_style( description )) | |
85 | { | |
86 | case PANGO_STYLE_NORMAL: | |
87 | m_style = wxFONTSTYLE_NORMAL; | |
88 | break; | |
89 | case PANGO_STYLE_ITALIC: | |
90 | m_style = wxFONTSTYLE_ITALIC; | |
91 | break; | |
92 | case PANGO_STYLE_OBLIQUE: | |
93 | m_style = wxFONTSTYLE_SLANT; | |
94 | break; | |
95 | } | |
2b5f62a0 | 96 | |
db16cab4 RR |
97 | return m_style; |
98 | } | |
99 | ||
100 | wxFontWeight wxNativeFontInfo::GetWeight() const | |
101 | { | |
102 | wxFontWeight m_weight = wxFONTWEIGHT_NORMAL; | |
103 | ||
104 | switch (pango_font_description_get_weight( description )) | |
105 | { | |
106 | case PANGO_WEIGHT_ULTRALIGHT: | |
107 | m_weight = wxFONTWEIGHT_LIGHT; | |
108 | break; | |
109 | case PANGO_WEIGHT_LIGHT: | |
110 | m_weight = wxFONTWEIGHT_LIGHT; | |
111 | break; | |
112 | case PANGO_WEIGHT_NORMAL: | |
113 | m_weight = wxFONTWEIGHT_NORMAL; | |
114 | break; | |
115 | case PANGO_WEIGHT_BOLD: | |
116 | m_weight = wxFONTWEIGHT_BOLD; | |
117 | break; | |
118 | case PANGO_WEIGHT_ULTRABOLD: | |
119 | m_weight = wxFONTWEIGHT_BOLD; | |
120 | break; | |
121 | case PANGO_WEIGHT_HEAVY: | |
122 | m_weight = wxFONTWEIGHT_BOLD; | |
123 | break; | |
124 | } | |
2b5f62a0 | 125 | |
db16cab4 RR |
126 | return m_weight; |
127 | } | |
128 | ||
129 | bool wxNativeFontInfo::GetUnderlined() const | |
130 | { | |
131 | return FALSE; | |
132 | } | |
133 | ||
134 | wxString wxNativeFontInfo::GetFaceName() const | |
135 | { | |
136 | wxString tmp = wxGTK_CONV_BACK( pango_font_description_get_family( description ) ); | |
2b5f62a0 | 137 | |
db16cab4 RR |
138 | return tmp; |
139 | } | |
140 | ||
141 | wxFontFamily wxNativeFontInfo::GetFamily() const | |
142 | { | |
143 | return wxFONTFAMILY_SWISS; | |
144 | } | |
145 | ||
146 | wxFontEncoding wxNativeFontInfo::GetEncoding() const | |
147 | { | |
148 | return wxFONTENCODING_SYSTEM; | |
149 | } | |
150 | ||
3398cf2c VZ |
151 | |
152 | void wxNativeFontInfo::SetPointSize(int WXUNUSED(pointsize)) | |
153 | { | |
154 | wxFAIL_MSG( _T("not implemented") ); | |
155 | } | |
156 | ||
157 | void wxNativeFontInfo::SetStyle(wxFontStyle WXUNUSED(style)) | |
158 | { | |
159 | wxFAIL_MSG( _T("not implemented") ); | |
160 | } | |
161 | ||
162 | void wxNativeFontInfo::SetWeight(wxFontWeight WXUNUSED(weight)) | |
163 | { | |
164 | wxFAIL_MSG( _T("not implemented") ); | |
165 | } | |
166 | ||
167 | void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined)) | |
168 | { | |
169 | wxFAIL_MSG( _T("not implemented") ); | |
170 | } | |
171 | ||
172 | void wxNativeFontInfo::SetFaceName(wxString WXUNUSED(facename)) | |
173 | { | |
174 | wxFAIL_MSG( _T("not implemented") ); | |
175 | } | |
176 | ||
177 | void wxNativeFontInfo::SetFamily(wxFontFamily WXUNUSED(family)) | |
178 | { | |
179 | wxFAIL_MSG( _T("not implemented") ); | |
180 | } | |
181 | ||
182 | void wxNativeFontInfo::SetEncoding(wxFontEncoding WXUNUSED(encoding)) | |
183 | { | |
184 | wxFAIL_MSG( _T("not implemented") ); | |
185 | } | |
186 | ||
187 | ||
188 | ||
db16cab4 RR |
189 | bool wxNativeFontInfo::FromString(const wxString& s) |
190 | { | |
191 | if (description) | |
192 | pango_font_description_free( description ); | |
193 | ||
194 | description = pango_font_description_from_string( wxGTK_CONV( s ) ); | |
195 | ||
196 | return TRUE; | |
197 | } | |
198 | ||
199 | wxString wxNativeFontInfo::ToString() const | |
200 | { | |
61850501 RR |
201 | char *str = pango_font_description_to_string( description ); |
202 | wxString tmp = wxGTK_CONV_BACK( str ); | |
203 | g_free( str ); | |
db16cab4 RR |
204 | |
205 | return tmp; | |
206 | } | |
207 | ||
208 | bool wxNativeFontInfo::FromUserString(const wxString& s) | |
209 | { | |
210 | return FromString( s ); | |
211 | } | |
212 | ||
213 | wxString wxNativeFontInfo::ToUserString() const | |
214 | { | |
215 | return ToString(); | |
216 | } | |
217 | ||
218 | // ---------------------------------------------------------------------------- | |
219 | // wxNativeEncodingInfo | |
220 | // ---------------------------------------------------------------------------- | |
221 | ||
222 | bool wxNativeEncodingInfo::FromString(const wxString& s) | |
223 | { | |
224 | return FALSE; | |
225 | } | |
226 | ||
227 | wxString wxNativeEncodingInfo::ToString() const | |
228 | { | |
229 | return wxEmptyString; | |
230 | } | |
231 | ||
232 | bool wxTestFontEncoding(const wxNativeEncodingInfo& info) | |
233 | { | |
234 | return TRUE; | |
235 | } | |
236 | ||
237 | bool wxGetNativeFontEncoding(wxFontEncoding encoding, | |
238 | wxNativeEncodingInfo *info) | |
239 | { | |
240 | return FALSE; | |
241 | } | |
242 | ||
2b5f62a0 | 243 | #else // GTK+ 1.x |
db16cab4 | 244 | |
79e4b627 | 245 | #ifdef __X__ |
4ea45e6b VZ |
246 | #ifdef __VMS__ |
247 | #pragma message disable nosimpint | |
248 | #endif | |
249 | ||
250 | #include <X11/Xlib.h> | |
251 | ||
252 | #ifdef __VMS__ | |
253 | #pragma message enable nosimpint | |
254 | #endif | |
79e4b627 VZ |
255 | |
256 | #include "wx/utils.h" // for wxGetDisplay() | |
257 | #elif defined(__WXGTK__) | |
4ea45e6b VZ |
258 | // we have to declare struct tm to avoid problems with first forward |
259 | // declaring it in C code (glib.h included from gdk.h does it) and then | |
260 | // defining it when time.h is included from the headers below - this is | |
261 | // known not to work at least with Sun CC 6.01 | |
262 | #include <time.h> | |
263 | ||
264 | #include <gdk/gdk.h> | |
79e4b627 VZ |
265 | #endif |
266 | ||
2e0e025e RR |
267 | |
268 | // ---------------------------------------------------------------------------- | |
269 | // private data | |
270 | // ---------------------------------------------------------------------------- | |
271 | ||
272 | static wxHashTable *g_fontHash = (wxHashTable*) NULL; | |
7beba2fc VZ |
273 | |
274 | // ---------------------------------------------------------------------------- | |
275 | // private functions | |
276 | // ---------------------------------------------------------------------------- | |
277 | ||
278 | // define the functions to create and destroy native fonts for this toolkit | |
279 | #ifdef __X__ | |
3fe34ed0 | 280 | wxNativeFont wxLoadFont(const wxString& fontSpec) |
7beba2fc VZ |
281 | { |
282 | return XLoadQueryFont((Display *)wxGetDisplay(), fontSpec); | |
283 | } | |
284 | ||
409d5a58 | 285 | inline void wxFreeFont(wxNativeFont font) |
7beba2fc | 286 | { |
a5fc62a1 | 287 | XFreeFont((Display *)wxGetDisplay(), (XFontStruct *)font); |
7beba2fc VZ |
288 | } |
289 | #elif defined(__WXGTK__) | |
3fe34ed0 | 290 | wxNativeFont wxLoadFont(const wxString& fontSpec) |
7beba2fc | 291 | { |
8fa3a431 VZ |
292 | // VZ: we should use gdk_fontset_load() instead of gdk_font_load() |
293 | // here to be able to display Japanese fonts correctly (at least | |
294 | // this is what people report) but unfortunately doing it results | |
295 | // in tons of warnings when using GTK with "normal" European | |
296 | // languages and so we can't always do it and I don't know enough | |
297 | // to determine when should this be done... (FIXME) | |
298 | return gdk_font_load( wxConvertWX2MB(fontSpec) ); | |
7beba2fc VZ |
299 | } |
300 | ||
409d5a58 | 301 | inline void wxFreeFont(wxNativeFont font) |
7beba2fc VZ |
302 | { |
303 | gdk_font_unref(font); | |
304 | } | |
305 | #else | |
306 | #error "Unknown GUI toolkit" | |
307 | #endif | |
308 | ||
309 | static bool wxTestFontSpec(const wxString& fontspec); | |
310 | ||
311 | static wxNativeFont wxLoadQueryFont(int pointSize, | |
312 | int family, | |
313 | int style, | |
314 | int weight, | |
315 | bool underlined, | |
316 | const wxString& facename, | |
317 | const wxString& xregistry, | |
30764ab5 VZ |
318 | const wxString& xencoding, |
319 | wxString* xFontName); | |
7beba2fc VZ |
320 | |
321 | // ============================================================================ | |
322 | // implementation | |
323 | // ============================================================================ | |
324 | ||
325 | // ---------------------------------------------------------------------------- | |
326 | // wxNativeEncodingInfo | |
327 | // ---------------------------------------------------------------------------- | |
328 | ||
329 | // convert to/from the string representation: format is | |
1e1d0be1 | 330 | // encodingid;registry;encoding[;facename] |
7beba2fc VZ |
331 | bool wxNativeEncodingInfo::FromString(const wxString& s) |
332 | { | |
6c49baf2 | 333 | // use ";", not "-" because it may be part of encoding name |
1e1d0be1 | 334 | wxStringTokenizer tokenizer(s, _T(";")); |
1e1d0be1 VS |
335 | |
336 | wxString encid = tokenizer.GetNextToken(); | |
337 | long enc; | |
338 | if ( !encid.ToLong(&enc) ) | |
339 | return FALSE; | |
340 | encoding = (wxFontEncoding)enc; | |
7beba2fc VZ |
341 | |
342 | xregistry = tokenizer.GetNextToken(); | |
343 | if ( !xregistry ) | |
344 | return FALSE; | |
345 | ||
346 | xencoding = tokenizer.GetNextToken(); | |
347 | if ( !xencoding ) | |
348 | return FALSE; | |
349 | ||
350 | // ok even if empty | |
351 | facename = tokenizer.GetNextToken(); | |
352 | ||
353 | return TRUE; | |
354 | } | |
355 | ||
356 | wxString wxNativeEncodingInfo::ToString() const | |
357 | { | |
358 | wxString s; | |
1e1d0be1 | 359 | s << (long)encoding << _T(';') << xregistry << _T(';') << xencoding; |
7beba2fc VZ |
360 | if ( !!facename ) |
361 | { | |
1e1d0be1 | 362 | s << _T(';') << facename; |
7beba2fc VZ |
363 | } |
364 | ||
365 | return s; | |
366 | } | |
367 | ||
ab5fe833 VZ |
368 | // ---------------------------------------------------------------------------- |
369 | // wxNativeFontInfo | |
370 | // ---------------------------------------------------------------------------- | |
371 | ||
372 | void wxNativeFontInfo::Init() | |
373 | { | |
409d5a58 | 374 | m_isDefault = TRUE; |
ab5fe833 VZ |
375 | } |
376 | ||
377 | bool wxNativeFontInfo::FromString(const wxString& s) | |
378 | { | |
379 | wxStringTokenizer tokenizer(s, _T(";")); | |
380 | ||
381 | // check the version | |
382 | wxString token = tokenizer.GetNextToken(); | |
383 | if ( token != _T('0') ) | |
384 | return FALSE; | |
385 | ||
386 | xFontName = tokenizer.GetNextToken(); | |
387 | ||
388 | // this should be the end | |
389 | if ( tokenizer.HasMoreTokens() ) | |
390 | return FALSE; | |
391 | ||
392 | return FromXFontName(xFontName); | |
393 | } | |
394 | ||
395 | wxString wxNativeFontInfo::ToString() const | |
396 | { | |
397 | // 0 is the version | |
398 | return wxString::Format(_T("%d;%s"), 0, GetXFontName().c_str()); | |
399 | } | |
400 | ||
401 | bool wxNativeFontInfo::FromUserString(const wxString& s) | |
402 | { | |
403 | return FromXFontName(s); | |
404 | } | |
405 | ||
406 | wxString wxNativeFontInfo::ToUserString() const | |
407 | { | |
408 | return GetXFontName(); | |
409 | } | |
410 | ||
409d5a58 VZ |
411 | bool wxNativeFontInfo::HasElements() const |
412 | { | |
413 | // we suppose that the foundry is never empty, so if it is it means that we | |
414 | // had never parsed the XLFD | |
415 | return !fontElements[0].empty(); | |
416 | } | |
417 | ||
53f6aab7 VZ |
418 | wxString wxNativeFontInfo::GetXFontComponent(wxXLFDField field) const |
419 | { | |
420 | wxCHECK_MSG( field < wxXLFD_MAX, _T(""), _T("invalid XLFD field") ); | |
421 | ||
409d5a58 | 422 | if ( !HasElements() ) |
53f6aab7 VZ |
423 | { |
424 | // const_cast | |
425 | if ( !((wxNativeFontInfo *)this)->FromXFontName(xFontName) ) | |
426 | return _T(""); | |
427 | } | |
428 | ||
429 | return fontElements[field]; | |
430 | } | |
431 | ||
295272bd | 432 | bool wxNativeFontInfo::FromXFontName(const wxString& fontname) |
ab5fe833 VZ |
433 | { |
434 | // TODO: we should be able to handle the font aliases here, but how? | |
409d5a58 VZ |
435 | wxStringTokenizer tokenizer(fontname, _T("-")); |
436 | ||
437 | // skip the leading, usually empty field (font name registry) | |
438 | if ( !tokenizer.HasMoreTokens() ) | |
439 | return FALSE; | |
440 | ||
441 | (void)tokenizer.GetNextToken(); | |
ab5fe833 VZ |
442 | |
443 | for ( size_t n = 0; n < WXSIZEOF(fontElements); n++ ) | |
444 | { | |
445 | if ( !tokenizer.HasMoreTokens() ) | |
446 | { | |
447 | // not enough elements in the XLFD - or maybe an alias | |
448 | return FALSE; | |
449 | } | |
450 | ||
b4e4abb5 VZ |
451 | wxString field = tokenizer.GetNextToken(); |
452 | if ( !field.empty() && field != _T('*') ) | |
453 | { | |
454 | // we're really initialized now | |
455 | m_isDefault = FALSE; | |
456 | } | |
457 | ||
458 | fontElements[n] = field; | |
ab5fe833 VZ |
459 | } |
460 | ||
461 | // this should be all | |
011ba5ed VZ |
462 | if ( tokenizer.HasMoreTokens() ) |
463 | return FALSE; | |
464 | ||
011ba5ed | 465 | return TRUE; |
ab5fe833 VZ |
466 | } |
467 | ||
468 | wxString wxNativeFontInfo::GetXFontName() const | |
469 | { | |
470 | if ( xFontName.empty() ) | |
471 | { | |
472 | for ( size_t n = 0; n < WXSIZEOF(fontElements); n++ ) | |
473 | { | |
474 | // replace the non specified elements with '*' except for the | |
475 | // additional style which is usually just omitted | |
476 | wxString elt = fontElements[n]; | |
409d5a58 | 477 | if ( elt.empty() && n != wxXLFD_ADDSTYLE ) |
ab5fe833 VZ |
478 | { |
479 | elt = _T('*'); | |
480 | } | |
481 | ||
482 | // const_cast | |
483 | ((wxNativeFontInfo *)this)->xFontName << _T('-') << elt; | |
484 | } | |
485 | } | |
486 | ||
487 | return xFontName; | |
488 | } | |
489 | ||
409d5a58 VZ |
490 | void |
491 | wxNativeFontInfo::SetXFontComponent(wxXLFDField field, const wxString& value) | |
492 | { | |
493 | wxCHECK_RET( field < wxXLFD_MAX, _T("invalid XLFD field") ); | |
494 | ||
495 | // this class should be initialized with a valid font spec first and only | |
496 | // then the fields may be modified! | |
497 | wxASSERT_MSG( !IsDefault(), _T("can't modify an uninitialized XLFD") ); | |
498 | ||
499 | if ( !HasElements() ) | |
500 | { | |
501 | // const_cast | |
502 | if ( !((wxNativeFontInfo *)this)->FromXFontName(xFontName) ) | |
503 | { | |
504 | wxFAIL_MSG( _T("can't set font element for invalid XLFD") ); | |
505 | ||
506 | return; | |
507 | } | |
508 | } | |
509 | ||
510 | fontElements[field] = value; | |
511 | ||
512 | // invalidate the XFLD, it doesn't correspond to the font elements any more | |
513 | xFontName.clear(); | |
514 | } | |
515 | ||
516 | void wxNativeFontInfo::SetXFontName(const wxString& xFontName_) | |
517 | { | |
518 | // invalidate the font elements, GetXFontComponent() will reparse the XLFD | |
519 | fontElements[0].clear(); | |
520 | ||
521 | xFontName = xFontName_; | |
522 | ||
523 | m_isDefault = FALSE; | |
524 | } | |
525 | ||
2b5f62a0 VZ |
526 | int wxNativeFontInfo::GetPointSize() const |
527 | { | |
528 | const wxString s = GetXFontComponent(wxXLFD_POINTSIZE); | |
529 | ||
530 | // return -1 to indicate that the size is unknown | |
531 | long l; | |
532 | return s.ToLong(&l) ? l : -1; | |
533 | } | |
534 | ||
535 | wxFontStyle wxNativeFontInfo::GetStyle() const | |
536 | { | |
537 | const wxString s = GetXFontComponent(wxXLFD_SLANT); | |
538 | ||
539 | if ( s.length() != 1 ) | |
540 | { | |
541 | // it is really unknown but we don't have any way to return it from | |
542 | // here | |
543 | return wxFONTSTYLE_NORMAL; | |
544 | } | |
545 | ||
546 | switch ( s[0] ) | |
547 | { | |
548 | default: | |
549 | // again, unknown but consider normal by default | |
550 | ||
551 | case _T('r'): | |
552 | return wxFONTSTYLE_NORMAL; | |
553 | ||
554 | case _T('i'): | |
555 | return wxFONTSTYLE_ITALIC; | |
556 | ||
557 | case _T('o'): | |
558 | return wxFONTSTYLE_SLANT; | |
559 | } | |
560 | } | |
561 | ||
562 | wxFontWeight wxNativeFontInfo::GetWeight() const | |
563 | { | |
564 | const wxString s = GetXFontComponent(wxXLFD_WEIGHT).MakeLower(); | |
565 | if ( s.find(_T("bold")) != wxString::npos || s == _T("black") ) | |
566 | return wxFONTWEIGHT_BOLD; | |
567 | else if ( s == _T("light") ) | |
568 | return wxFONTWEIGHT_LIGHT; | |
569 | ||
570 | return wxFONTWEIGHT_NORMAL; | |
571 | } | |
572 | ||
573 | bool wxNativeFontInfo::GetUnderlined() const | |
574 | { | |
575 | // X fonts are never underlined | |
576 | return FALSE; | |
577 | } | |
578 | ||
579 | wxString wxNativeFontInfo::GetFaceName() const | |
580 | { | |
77ffb593 | 581 | // wxWidgets facename probably more accurately corresponds to X family |
2b5f62a0 VZ |
582 | return GetXFontComponent(wxXLFD_FAMILY); |
583 | } | |
584 | ||
585 | wxFontFamily wxNativeFontInfo::GetFamily() const | |
586 | { | |
77ffb593 | 587 | // and wxWidgets family -- to X foundry, but we have to translate it to |
2b5f62a0 VZ |
588 | // wxFontFamily somehow... |
589 | wxFAIL_MSG(_T("not implemented")); // GetXFontComponent(wxXLFD_FOUNDRY); | |
590 | ||
591 | return wxFONTFAMILY_DEFAULT; | |
592 | } | |
593 | ||
594 | wxFontEncoding wxNativeFontInfo::GetEncoding() const | |
595 | { | |
596 | // we already have the code for this but need to refactor it first | |
597 | wxFAIL_MSG( _T("not implemented") ); | |
598 | ||
599 | return wxFONTENCODING_MAX; | |
600 | } | |
601 | ||
602 | void wxNativeFontInfo::SetPointSize(int pointsize) | |
603 | { | |
604 | SetXFontComponent(wxXLFD_POINTSIZE, wxString::Format(_T("%d"), pointsize)); | |
605 | } | |
606 | ||
607 | void wxNativeFontInfo::SetStyle(wxFontStyle style) | |
608 | { | |
609 | wxString s; | |
610 | switch ( style ) | |
611 | { | |
612 | case wxFONTSTYLE_ITALIC: | |
613 | s = _T('i'); | |
614 | break; | |
615 | ||
616 | case wxFONTSTYLE_SLANT: | |
617 | s = _T('o'); | |
618 | break; | |
619 | ||
620 | case wxFONTSTYLE_NORMAL: | |
621 | s = _T('r'); | |
622 | ||
623 | default: | |
624 | wxFAIL_MSG( _T("unknown wxFontStyle in wxNativeFontInfo::SetStyle") ); | |
625 | return; | |
626 | } | |
627 | ||
628 | SetXFontComponent(wxXLFD_SLANT, s); | |
629 | } | |
630 | ||
631 | void wxNativeFontInfo::SetWeight(wxFontWeight weight) | |
632 | { | |
633 | wxString s; | |
634 | switch ( weight ) | |
635 | { | |
636 | case wxFONTWEIGHT_BOLD: | |
637 | s = _T("bold"); | |
638 | break; | |
639 | ||
640 | case wxFONTWEIGHT_LIGHT: | |
641 | s = _T("light"); | |
642 | break; | |
643 | ||
644 | case wxFONTWEIGHT_NORMAL: | |
645 | s = _T("medium"); | |
646 | break; | |
647 | ||
648 | default: | |
649 | wxFAIL_MSG( _T("unknown wxFontWeight in wxNativeFontInfo::SetWeight") ); | |
650 | return; | |
651 | } | |
652 | ||
653 | SetXFontComponent(wxXLFD_WEIGHT, s); | |
654 | } | |
655 | ||
656 | void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined)) | |
657 | { | |
658 | // can't do this under X | |
659 | } | |
660 | ||
661 | void wxNativeFontInfo::SetFaceName(wxString facename) | |
662 | { | |
663 | SetXFontComponent(wxXLFD_FAMILY, facename); | |
664 | } | |
665 | ||
666 | void wxNativeFontInfo::SetFamily(wxFontFamily family) | |
667 | { | |
668 | // wxFontFamily -> X foundry, anyone? | |
669 | wxFAIL_MSG( _T("not implemented") ); | |
670 | ||
671 | // SetXFontComponent(wxXLFD_FOUNDRY, ...); | |
672 | } | |
673 | ||
674 | void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding) | |
675 | { | |
676 | wxNativeEncodingInfo info; | |
677 | if ( wxGetNativeFontEncoding(encoding, &info) ) | |
678 | { | |
679 | SetXFontComponent(wxXLFD_ENCODING, info.xencoding); | |
680 | SetXFontComponent(wxXLFD_REGISTRY, info.xregistry); | |
681 | } | |
682 | } | |
683 | ||
7beba2fc VZ |
684 | // ---------------------------------------------------------------------------- |
685 | // common functions | |
686 | // ---------------------------------------------------------------------------- | |
687 | ||
688 | bool wxGetNativeFontEncoding(wxFontEncoding encoding, | |
689 | wxNativeEncodingInfo *info) | |
690 | { | |
691 | wxCHECK_MSG( info, FALSE, _T("bad pointer in wxGetNativeFontEncoding") ); | |
692 | ||
693 | if ( encoding == wxFONTENCODING_DEFAULT ) | |
694 | { | |
695 | encoding = wxFont::GetDefaultEncoding(); | |
696 | } | |
697 | ||
698 | switch ( encoding ) | |
699 | { | |
700 | case wxFONTENCODING_ISO8859_1: | |
701 | case wxFONTENCODING_ISO8859_2: | |
702 | case wxFONTENCODING_ISO8859_3: | |
703 | case wxFONTENCODING_ISO8859_4: | |
704 | case wxFONTENCODING_ISO8859_5: | |
705 | case wxFONTENCODING_ISO8859_6: | |
706 | case wxFONTENCODING_ISO8859_7: | |
707 | case wxFONTENCODING_ISO8859_8: | |
708 | case wxFONTENCODING_ISO8859_9: | |
709 | case wxFONTENCODING_ISO8859_10: | |
710 | case wxFONTENCODING_ISO8859_11: | |
80a24267 | 711 | case wxFONTENCODING_ISO8859_12: |
7beba2fc VZ |
712 | case wxFONTENCODING_ISO8859_13: |
713 | case wxFONTENCODING_ISO8859_14: | |
714 | case wxFONTENCODING_ISO8859_15: | |
715 | { | |
716 | int cp = encoding - wxFONTENCODING_ISO8859_1 + 1; | |
717 | info->xregistry = wxT("iso8859"); | |
718 | info->xencoding.Printf(wxT("%d"), cp); | |
719 | } | |
720 | break; | |
721 | ||
bb84929e | 722 | case wxFONTENCODING_UTF8: |
5707316c | 723 | info->xregistry = wxT("iso10646"); |
bb84929e VZ |
724 | info->xencoding = wxT("*"); |
725 | break; | |
726 | ||
2b5f62a0 | 727 | case wxFONTENCODING_GB2312: |
82680055 | 728 | info->xregistry = wxT("GB2312"); // or the otherway round? |
2b5f62a0 VZ |
729 | info->xencoding = wxT("*"); |
730 | break; | |
731 | ||
7beba2fc | 732 | case wxFONTENCODING_KOI8: |
15ad38c3 | 733 | case wxFONTENCODING_KOI8_U: |
7beba2fc VZ |
734 | info->xregistry = wxT("koi8"); |
735 | ||
5707316c | 736 | // we don't make distinction between koi8-r, koi8-u and koi8-ru (so far) |
7beba2fc VZ |
737 | info->xencoding = wxT("*"); |
738 | break; | |
739 | ||
740 | case wxFONTENCODING_CP1250: | |
741 | case wxFONTENCODING_CP1251: | |
742 | case wxFONTENCODING_CP1252: | |
743 | case wxFONTENCODING_CP1253: | |
744 | case wxFONTENCODING_CP1254: | |
745 | case wxFONTENCODING_CP1255: | |
746 | case wxFONTENCODING_CP1256: | |
747 | case wxFONTENCODING_CP1257: | |
748 | { | |
749 | int cp = encoding - wxFONTENCODING_CP1250 + 1250; | |
750 | info->xregistry = wxT("microsoft"); | |
751 | info->xencoding.Printf(wxT("cp%d"), cp); | |
752 | } | |
753 | break; | |
754 | ||
755 | case wxFONTENCODING_SYSTEM: | |
756 | info->xregistry = | |
81c67e27 | 757 | info->xencoding = wxT("*"); |
7beba2fc VZ |
758 | break; |
759 | ||
760 | default: | |
761 | // don't know how to translate this encoding into X fontspec | |
762 | return FALSE; | |
763 | } | |
764 | ||
ab5fe833 | 765 | info->encoding = encoding; |
6b0eebc5 | 766 | |
7beba2fc VZ |
767 | return TRUE; |
768 | } | |
769 | ||
770 | bool wxTestFontEncoding(const wxNativeEncodingInfo& info) | |
771 | { | |
772 | wxString fontspec; | |
773 | fontspec.Printf(_T("-*-%s-*-*-*-*-*-*-*-*-*-*-%s-%s"), | |
774 | !info.facename ? _T("*") : info.facename.c_str(), | |
775 | info.xregistry.c_str(), | |
776 | info.xencoding.c_str()); | |
777 | ||
778 | return wxTestFontSpec(fontspec); | |
779 | } | |
780 | ||
781 | // ---------------------------------------------------------------------------- | |
782 | // X-specific functions | |
783 | // ---------------------------------------------------------------------------- | |
784 | ||
785 | wxNativeFont wxLoadQueryNearestFont(int pointSize, | |
786 | int family, | |
787 | int style, | |
788 | int weight, | |
789 | bool underlined, | |
790 | const wxString &facename, | |
30764ab5 VZ |
791 | wxFontEncoding encoding, |
792 | wxString* xFontName) | |
7beba2fc | 793 | { |
97d3f0ee VZ |
794 | if ( encoding == wxFONTENCODING_DEFAULT ) |
795 | { | |
796 | encoding = wxFont::GetDefaultEncoding(); | |
797 | } | |
798 | ||
7beba2fc VZ |
799 | // first determine the encoding - if the font doesn't exist at all in this |
800 | // encoding, it's useless to do all other approximations (i.e. size, | |
801 | // family &c don't matter much) | |
802 | wxNativeEncodingInfo info; | |
97d3f0ee | 803 | if ( encoding == wxFONTENCODING_SYSTEM ) |
81c67e27 RR |
804 | { |
805 | // This will always work so we don't test to save time | |
806 | wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM, &info); | |
807 | } | |
808 | else | |
7beba2fc | 809 | { |
81c67e27 RR |
810 | if ( !wxGetNativeFontEncoding(encoding, &info) || |
811 | !wxTestFontEncoding(info) ) | |
7beba2fc | 812 | { |
1e6feb95 | 813 | #if wxUSE_FONTMAP |
142b3bc2 | 814 | if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &info) ) |
1e6feb95 | 815 | #endif // wxUSE_FONTMAP |
81c67e27 RR |
816 | { |
817 | // unspported encoding - replace it with the default | |
818 | // | |
819 | // NB: we can't just return 0 from here because wxGTK code doesn't | |
820 | // check for it (i.e. it supposes that we'll always succeed), | |
821 | // so it would provoke a crash | |
822 | wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM, &info); | |
823 | } | |
97d3f0ee | 824 | } |
7beba2fc | 825 | } |
6c49baf2 | 826 | |
81c67e27 | 827 | // OK, we have the correct xregistry/xencoding in info structure |
30764ab5 VZ |
828 | wxNativeFont font = 0; |
829 | ||
830 | // if we already have the X font name, try to use it | |
831 | if( xFontName && !xFontName->IsEmpty() ) | |
6c49baf2 VZ |
832 | { |
833 | // | |
834 | // Make sure point size is correct for scale factor. | |
835 | // | |
836 | wxStringTokenizer tokenizer(*xFontName, _T("-"), wxTOKEN_RET_DELIMS); | |
837 | wxString newFontName; | |
838 | ||
839 | for(int i = 0; i < 8; i++) | |
840 | newFontName += tokenizer.NextToken(); | |
841 | ||
842 | (void) tokenizer.NextToken(); | |
843 | ||
401eb3de | 844 | newFontName += wxString::Format(wxT("%d-"), pointSize); |
6c49baf2 VZ |
845 | |
846 | while(tokenizer.HasMoreTokens()) | |
847 | newFontName += tokenizer.GetNextToken(); | |
848 | ||
849 | font = wxLoadFont(newFontName); | |
850 | ||
851 | if(font) | |
852 | *xFontName = newFontName; | |
853 | } | |
30764ab5 | 854 | |
7beba2fc VZ |
855 | if ( !font ) |
856 | { | |
857 | // search up and down by stepsize 10 | |
858 | int max_size = pointSize + 20 * (1 + (pointSize/180)); | |
859 | int min_size = pointSize - 20 * (1 + (pointSize/180)); | |
860 | ||
34791896 | 861 | int i, round; // counters |
7beba2fc | 862 | |
34791896 RR |
863 | // first round: search for equal, then for smaller and for larger size with the given weight and style |
864 | int testweight = weight; | |
865 | int teststyle = style; | |
866 | ||
867 | for ( round = 0; round < 3; round++ ) | |
868 | { | |
869 | // second round: use normal weight | |
870 | if ( round == 1 ) | |
7beba2fc | 871 | { |
34791896 RR |
872 | if ( testweight != wxNORMAL ) |
873 | { | |
874 | testweight = wxNORMAL; | |
875 | } | |
876 | else | |
877 | { | |
878 | ++round; // fall through to third round | |
879 | } | |
880 | } | |
881 | ||
882 | // third round: ... and use normal style | |
883 | if ( round == 2 ) | |
884 | { | |
885 | if ( teststyle != wxNORMAL ) | |
886 | { | |
887 | teststyle = wxNORMAL; | |
888 | } | |
889 | else | |
890 | { | |
891 | break; | |
892 | } | |
893 | } | |
894 | // Search for equal or smaller size (approx.) | |
895 | for ( i = pointSize; !font && i >= 10 && i >= min_size; i -= 10 ) | |
896 | { | |
897 | font = wxLoadQueryFont(i, family, teststyle, testweight, underlined, | |
30764ab5 VZ |
898 | facename, info.xregistry, info.xencoding, |
899 | xFontName); | |
7beba2fc VZ |
900 | } |
901 | ||
902 | // Search for larger size (approx.) | |
903 | for ( i = pointSize + 10; !font && i <= max_size; i += 10 ) | |
904 | { | |
34791896 | 905 | font = wxLoadQueryFont(i, family, teststyle, testweight, underlined, |
30764ab5 VZ |
906 | facename, info.xregistry, info.xencoding, |
907 | xFontName); | |
34791896 | 908 | } |
7beba2fc VZ |
909 | } |
910 | ||
911 | // Try default family | |
912 | if ( !font && family != wxDEFAULT ) | |
913 | { | |
914 | font = wxLoadQueryFont(pointSize, wxDEFAULT, style, weight, | |
915 | underlined, facename, | |
30764ab5 VZ |
916 | info.xregistry, info.xencoding, |
917 | xFontName ); | |
7beba2fc VZ |
918 | } |
919 | ||
f139dfe8 VZ |
920 | // ignore size, family, style and weight but try to find font with the |
921 | // given facename and encoding | |
7beba2fc VZ |
922 | if ( !font ) |
923 | { | |
924 | font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL, | |
925 | underlined, facename, | |
30764ab5 VZ |
926 | info.xregistry, info.xencoding, |
927 | xFontName); | |
7beba2fc | 928 | |
f139dfe8 VZ |
929 | // ignore family as well |
930 | if ( !font ) | |
931 | { | |
932 | font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL, | |
933 | underlined, wxEmptyString, | |
934 | info.xregistry, info.xencoding, | |
935 | xFontName); | |
936 | ||
937 | // if it still failed, try to get the font of any size but | |
938 | // with the requested encoding: this can happen if the | |
939 | // encoding is only available in one size which happens to be | |
940 | // different from 120 | |
941 | if ( !font ) | |
942 | { | |
943 | font = wxLoadQueryFont(-1, wxDEFAULT, wxNORMAL, wxNORMAL, | |
944 | FALSE, wxEmptyString, | |
945 | info.xregistry, info.xencoding, | |
946 | xFontName); | |
947 | ||
948 | // this should never happen as we had tested for it in the | |
949 | // very beginning, but if it does, do return something non | |
950 | // NULL or we'd crash in wxFont code | |
951 | if ( !font ) | |
952 | { | |
953 | wxFAIL_MSG( _T("this encoding should be available!") ); | |
954 | ||
955 | font = wxLoadQueryFont(-1, | |
956 | wxDEFAULT, wxNORMAL, wxNORMAL, | |
957 | FALSE, wxEmptyString, | |
958 | _T("*"), _T("*"), | |
959 | xFontName); | |
960 | } | |
961 | } | |
962 | } | |
7beba2fc VZ |
963 | } |
964 | } | |
965 | ||
966 | return font; | |
967 | } | |
968 | ||
969 | // ---------------------------------------------------------------------------- | |
970 | // private functions | |
971 | // ---------------------------------------------------------------------------- | |
972 | ||
973 | // returns TRUE if there are any fonts matching this font spec | |
974 | static bool wxTestFontSpec(const wxString& fontspec) | |
975 | { | |
97d3f0ee VZ |
976 | // some X servers will fail to load this font because there are too many |
977 | // matches so we must test explicitly for this | |
978 | if ( fontspec == _T("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") ) | |
979 | { | |
980 | return TRUE; | |
981 | } | |
982 | ||
2e0e025e RR |
983 | wxNativeFont test = (wxNativeFont) g_fontHash->Get( fontspec ); |
984 | if (test) | |
985 | { | |
2e0e025e RR |
986 | return TRUE; |
987 | } | |
988 | ||
989 | test = wxLoadFont(fontspec); | |
990 | g_fontHash->Put( fontspec, (wxObject*) test ); | |
6c49baf2 | 991 | |
7beba2fc VZ |
992 | if ( test ) |
993 | { | |
994 | wxFreeFont(test); | |
995 | ||
996 | return TRUE; | |
997 | } | |
998 | else | |
999 | { | |
1000 | return FALSE; | |
1001 | } | |
1002 | } | |
1003 | ||
1004 | static wxNativeFont wxLoadQueryFont(int pointSize, | |
1005 | int family, | |
1006 | int style, | |
1007 | int weight, | |
1008 | bool WXUNUSED(underlined), | |
1009 | const wxString& facename, | |
1010 | const wxString& xregistry, | |
30764ab5 VZ |
1011 | const wxString& xencoding, |
1012 | wxString* xFontName) | |
7beba2fc VZ |
1013 | { |
1014 | wxString xfamily; | |
1015 | switch (family) | |
1016 | { | |
1017 | case wxDECORATIVE: xfamily = wxT("lucida"); break; | |
1018 | case wxROMAN: xfamily = wxT("times"); break; | |
1019 | case wxMODERN: xfamily = wxT("courier"); break; | |
1020 | case wxSWISS: xfamily = wxT("helvetica"); break; | |
1021 | case wxTELETYPE: xfamily = wxT("lucidatypewriter"); break; | |
1022 | case wxSCRIPT: xfamily = wxT("utopia"); break; | |
1023 | default: xfamily = wxT("*"); | |
1024 | } | |
16d865f7 | 1025 | #if wxUSE_NANOX |
c2ff68d3 JS |
1026 | int xweight; |
1027 | switch (weight) | |
1028 | { | |
1029 | case wxBOLD: | |
1030 | { | |
1031 | xweight = MWLF_WEIGHT_BOLD; | |
1032 | break; | |
1033 | } | |
1034 | case wxLIGHT: | |
1035 | { | |
1036 | xweight = MWLF_WEIGHT_LIGHT; | |
1037 | break; | |
1038 | } | |
1039 | case wxNORMAL: | |
1040 | { | |
1041 | xweight = MWLF_WEIGHT_NORMAL; | |
1042 | break; | |
1043 | } | |
1044 | ||
1045 | default: | |
1046 | { | |
1047 | xweight = MWLF_WEIGHT_DEFAULT; | |
1048 | break; | |
1049 | } | |
1050 | } | |
16d865f7 JS |
1051 | GR_SCREEN_INFO screenInfo; |
1052 | GrGetScreenInfo(& screenInfo); | |
1053 | ||
1054 | int yPixelsPerCM = screenInfo.ydpcm; | |
1055 | ||
0a68bc69 | 1056 | // A point is 1/72 of an inch. |
16d865f7 | 1057 | // An inch is 2.541 cm. |
0a68bc69 | 1058 | // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels) |
c2ff68d3 JS |
1059 | // In fact pointSize is 10 * the normal point size so |
1060 | // divide by 10. | |
1061 | ||
15d5a947 | 1062 | int pixelHeight = (int) ( (((float)pointSize) / 720.0) * 2.541 * (float) yPixelsPerCM) ; |
c2ff68d3 JS |
1063 | |
1064 | // An alternative: assume that the screen is 72 dpi. | |
0a68bc69 JS |
1065 | //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ; |
1066 | //int pixelHeight = (int) ((float)pointSize / 10.0) ; | |
2b5f62a0 | 1067 | |
16d865f7 JS |
1068 | GR_LOGFONT logFont; |
1069 | logFont.lfHeight = pixelHeight; | |
1070 | logFont.lfWidth = 0; | |
1071 | logFont.lfEscapement = 0; | |
1072 | logFont.lfOrientation = 0; | |
c2ff68d3 | 1073 | logFont.lfWeight = xweight; |
16d865f7 JS |
1074 | logFont.lfItalic = (style == wxNORMAL ? 0 : 1) ; |
1075 | logFont.lfUnderline = 0; | |
1076 | logFont.lfStrikeOut = 0; | |
1077 | logFont.lfCharSet = MWLF_CHARSET_DEFAULT; // TODO: select appropriate one | |
1078 | logFont.lfOutPrecision = MWLF_TYPE_DEFAULT; | |
1079 | logFont.lfClipPrecision = 0; // Not used | |
1080 | logFont.lfRoman = (family == wxROMAN ? 1 : 0) ; | |
1081 | logFont.lfSerif = (family == wxSWISS ? 0 : 1) ; | |
1082 | logFont.lfSansSerif = !logFont.lfSerif ; | |
1083 | logFont.lfModern = (family == wxMODERN ? 1 : 0) ; | |
1084 | logFont.lfProportional = (family == wxTELETYPE ? 0 : 1) ; | |
1085 | logFont.lfOblique = 0; | |
1086 | logFont.lfSmallCaps = 0; | |
1087 | logFont.lfPitch = 0; // 0 = default | |
1088 | strcpy(logFont.lfFaceName, facename.c_str()); | |
1089 | ||
1090 | XFontStruct* fontInfo = (XFontStruct*) malloc(sizeof(XFontStruct)); | |
1091 | fontInfo->fid = GrCreateFont((GR_CHAR*) facename.c_str(), pixelHeight, & logFont); | |
1092 | GrGetFontInfo(fontInfo->fid, & fontInfo->info); | |
1093 | return (wxNativeFont) fontInfo; | |
2b5f62a0 | 1094 | |
16d865f7 | 1095 | #else |
7beba2fc VZ |
1096 | wxString fontSpec; |
1097 | if (!facename.IsEmpty()) | |
1098 | { | |
1099 | fontSpec.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"), | |
1100 | facename.c_str()); | |
1101 | ||
1102 | if ( wxTestFontSpec(fontSpec) ) | |
1103 | { | |
1104 | xfamily = facename; | |
1105 | } | |
1106 | //else: no such family, use default one instead | |
1107 | } | |
1108 | ||
1109 | wxString xstyle; | |
1110 | switch (style) | |
1111 | { | |
f9dbf34f VZ |
1112 | case wxSLANT: |
1113 | fontSpec.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"), | |
1114 | xfamily.c_str()); | |
1115 | if ( wxTestFontSpec(fontSpec) ) | |
1116 | { | |
1117 | xstyle = wxT("o"); | |
1118 | break; | |
1119 | } | |
1120 | // fall through - try wxITALIC now | |
1121 | ||
1122 | case wxITALIC: | |
1123 | fontSpec.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"), | |
1124 | xfamily.c_str()); | |
1125 | if ( wxTestFontSpec(fontSpec) ) | |
1126 | { | |
1127 | xstyle = wxT("i"); | |
1128 | } | |
1129 | else if ( style == wxITALIC ) // and not wxSLANT | |
1130 | { | |
1131 | // try wxSLANT | |
1132 | fontSpec.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"), | |
1133 | xfamily.c_str()); | |
1134 | if ( wxTestFontSpec(fontSpec) ) | |
1135 | { | |
1136 | xstyle = wxT("o"); | |
1137 | } | |
1138 | else | |
1139 | { | |
1140 | // no italic, no slant - leave default | |
1141 | xstyle = wxT("*"); | |
1142 | } | |
1143 | } | |
1144 | break; | |
1145 | ||
1146 | default: | |
1147 | wxFAIL_MSG(_T("unknown font style")); | |
1148 | // fall back to normal | |
1149 | ||
1150 | case wxNORMAL: | |
1151 | xstyle = wxT("r"); | |
1152 | break; | |
7beba2fc VZ |
1153 | } |
1154 | ||
1155 | wxString xweight; | |
1156 | switch (weight) | |
1157 | { | |
1158 | case wxBOLD: | |
1159 | { | |
1160 | fontSpec.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"), | |
1161 | xfamily.c_str()); | |
1162 | if ( wxTestFontSpec(fontSpec) ) | |
1163 | { | |
1164 | xweight = wxT("bold"); | |
1165 | break; | |
1166 | } | |
1167 | fontSpec.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"), | |
1168 | xfamily.c_str()); | |
1169 | if ( wxTestFontSpec(fontSpec) ) | |
1170 | { | |
1171 | xweight = wxT("heavy"); | |
1172 | break; | |
1173 | } | |
1174 | fontSpec.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"), | |
1175 | xfamily.c_str()); | |
1176 | if ( wxTestFontSpec(fontSpec) ) | |
1177 | { | |
1178 | xweight = wxT("extrabold"); | |
1179 | break; | |
1180 | } | |
1181 | fontSpec.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"), | |
1182 | xfamily.c_str()); | |
1183 | if ( wxTestFontSpec(fontSpec) ) | |
1184 | { | |
1185 | xweight = wxT("demibold"); | |
1186 | break; | |
1187 | } | |
1188 | fontSpec.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"), | |
1189 | xfamily.c_str()); | |
1190 | if ( wxTestFontSpec(fontSpec) ) | |
1191 | { | |
1192 | xweight = wxT("black"); | |
1193 | break; | |
1194 | } | |
1195 | fontSpec.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"), | |
1196 | xfamily.c_str()); | |
1197 | if ( wxTestFontSpec(fontSpec) ) | |
1198 | { | |
1199 | xweight = wxT("ultrablack"); | |
1200 | break; | |
1201 | } | |
1202 | } | |
1203 | break; | |
1204 | case wxLIGHT: | |
1205 | { | |
1206 | fontSpec.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"), | |
1207 | xfamily.c_str()); | |
1208 | if ( wxTestFontSpec(fontSpec) ) | |
1209 | { | |
1210 | xweight = wxT("light"); | |
1211 | break; | |
1212 | } | |
1213 | fontSpec.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"), | |
1214 | xfamily.c_str()); | |
1215 | if ( wxTestFontSpec(fontSpec) ) | |
1216 | { | |
1217 | xweight = wxT("thin"); | |
1218 | break; | |
1219 | } | |
1220 | } | |
1221 | break; | |
1222 | case wxNORMAL: | |
1223 | { | |
1224 | fontSpec.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"), | |
1225 | xfamily.c_str()); | |
1226 | if ( wxTestFontSpec(fontSpec) ) | |
1227 | { | |
1228 | xweight = wxT("medium"); | |
1229 | break; | |
1230 | } | |
1231 | fontSpec.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"), | |
1232 | xfamily.c_str()); | |
1233 | if ( wxTestFontSpec(fontSpec) ) | |
1234 | { | |
1235 | xweight = wxT("normal"); | |
1236 | break; | |
1237 | } | |
1238 | fontSpec.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"), | |
1239 | xfamily.c_str()); | |
1240 | if ( wxTestFontSpec(fontSpec) ) | |
1241 | { | |
1242 | xweight = wxT("regular"); | |
1243 | break; | |
1244 | } | |
1245 | xweight = wxT("*"); | |
1246 | } | |
1247 | break; | |
1248 | default: xweight = wxT("*"); break; | |
1249 | } | |
1250 | ||
f139dfe8 VZ |
1251 | // if pointSize is -1, don't specify any |
1252 | wxString sizeSpec; | |
73b0423d | 1253 | if ( pointSize == -1 ) |
f139dfe8 VZ |
1254 | { |
1255 | sizeSpec = _T('*'); | |
1256 | } | |
1257 | else | |
1258 | { | |
1259 | sizeSpec.Printf(_T("%d"), pointSize); | |
1260 | } | |
1261 | ||
7beba2fc | 1262 | // construct the X font spec from our data |
f139dfe8 | 1263 | fontSpec.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"), |
7beba2fc | 1264 | xfamily.c_str(), xweight.c_str(), xstyle.c_str(), |
f139dfe8 | 1265 | sizeSpec.c_str(), xregistry.c_str(), xencoding.c_str()); |
7beba2fc | 1266 | |
30764ab5 VZ |
1267 | if( xFontName ) |
1268 | *xFontName = fontSpec; | |
1269 | ||
7beba2fc | 1270 | return wxLoadFont(fontSpec); |
16d865f7 JS |
1271 | #endif |
1272 | // wxUSE_NANOX | |
7beba2fc VZ |
1273 | } |
1274 | ||
2e0e025e RR |
1275 | // ---------------------------------------------------------------------------- |
1276 | // wxFontModule | |
1277 | // ---------------------------------------------------------------------------- | |
1278 | ||
1279 | class wxFontModule : public wxModule | |
1280 | { | |
1281 | public: | |
1282 | bool OnInit(); | |
1283 | void OnExit(); | |
1284 | ||
1285 | private: | |
1286 | DECLARE_DYNAMIC_CLASS(wxFontModule) | |
1287 | }; | |
1288 | ||
1289 | IMPLEMENT_DYNAMIC_CLASS(wxFontModule, wxModule) | |
1290 | ||
1291 | bool wxFontModule::OnInit() | |
1292 | { | |
1293 | g_fontHash = new wxHashTable( wxKEY_STRING ); | |
1294 | ||
1295 | return TRUE; | |
1296 | } | |
1297 | ||
1298 | void wxFontModule::OnExit() | |
1299 | { | |
1300 | delete g_fontHash; | |
1301 | ||
1302 | g_fontHash = (wxHashTable *)NULL; | |
1303 | } | |
db16cab4 | 1304 | |
2b5f62a0 VZ |
1305 | #endif // GTK 2.0/1.x |
1306 |