reckognize cp125x charsets
[wxWidgets.git] / src / common / fontmap.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/fontmap.cpp
3 // Purpose: wxFontMapper class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 04.11.99
7 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "fontmap.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
32 #include "wx/app.h"
33 #include "wx/log.h"
34 #include "wx/intl.h"
35 #endif // PCH
36
37 #include "wx/fontmap.h"
38
39 #if wxUSE_CONFIG
40 #include "wx/config.h"
41 #include "wx/memconf.h"
42 #endif
43
44 #if wxUSE_GUI
45 #include "wx/msgdlg.h"
46 #include "wx/fontdlg.h"
47 #include "wx/choicdlg.h"
48 #endif // wxUSE_GUI
49
50 #include "wx/encconv.h"
51
52 // ----------------------------------------------------------------------------
53 // constants
54 // ----------------------------------------------------------------------------
55
56 // the config paths we use
57 static const wxChar* FONTMAPPER_ROOT_PATH = wxT("/wxWindows/FontMapper");
58 static const wxChar* FONTMAPPER_CHARSET_PATH = wxT("Charsets");
59 static const wxChar* FONTMAPPER_CHARSET_ALIAS_PATH = wxT("Aliases");
60 #if wxUSE_GUI
61 static const wxChar* FONTMAPPER_FONT_FROM_ENCODING_PATH = wxT("Encodings");
62 #endif // wxUSE_GUI
63
64 // encodings supported by GetEncodingDescription
65 static wxFontEncoding gs_encodings[] =
66 {
67 wxFONTENCODING_ISO8859_1,
68 wxFONTENCODING_ISO8859_2,
69 wxFONTENCODING_ISO8859_3,
70 wxFONTENCODING_ISO8859_4,
71 wxFONTENCODING_ISO8859_5,
72 wxFONTENCODING_ISO8859_6,
73 wxFONTENCODING_ISO8859_7,
74 wxFONTENCODING_ISO8859_8,
75 wxFONTENCODING_ISO8859_9,
76 wxFONTENCODING_ISO8859_10,
77 wxFONTENCODING_ISO8859_11,
78 wxFONTENCODING_ISO8859_12,
79 wxFONTENCODING_ISO8859_13,
80 wxFONTENCODING_ISO8859_14,
81 wxFONTENCODING_ISO8859_15,
82 wxFONTENCODING_KOI8,
83 wxFONTENCODING_CP1250,
84 wxFONTENCODING_CP1251,
85 wxFONTENCODING_CP1252,
86 wxFONTENCODING_CP1253,
87 wxFONTENCODING_CP1254,
88 wxFONTENCODING_CP1255,
89 wxFONTENCODING_CP1256,
90 wxFONTENCODING_CP1257,
91 wxFONTENCODING_CP437,
92 wxFONTENCODING_UTF7,
93 wxFONTENCODING_UTF8,
94 };
95
96 // the descriptions for them
97 static const wxChar* gs_encodingDescs[] =
98 {
99 wxTRANSLATE( "Western European (ISO-8859-1)" ),
100 wxTRANSLATE( "Central European (ISO-8859-2)" ),
101 wxTRANSLATE( "Esperanto (ISO-8859-3)" ),
102 wxTRANSLATE( "Baltic (old) (ISO-8859-4)" ),
103 wxTRANSLATE( "Cyrillic (ISO-8859-5)" ),
104 wxTRANSLATE( "Arabic (ISO-8859-6)" ),
105 wxTRANSLATE( "Greek (ISO-8859-7)" ),
106 wxTRANSLATE( "Hebrew (ISO-8859-8)" ),
107 wxTRANSLATE( "Turkish (ISO-8859-9)" ),
108 wxTRANSLATE( "Nordic (ISO-8859-10)" ),
109 wxTRANSLATE( "Thai (ISO-8859-11)" ),
110 wxTRANSLATE( "Indian (ISO-8859-12)" ),
111 wxTRANSLATE( "Baltic (ISO-8859-13)" ),
112 wxTRANSLATE( "Celtic (ISO-8859-14)" ),
113 wxTRANSLATE( "Western European with Euro (ISO-8859-15)" ),
114 wxTRANSLATE( "KOI8-R" ),
115 wxTRANSLATE( "Windows Central European (CP 1250)" ),
116 wxTRANSLATE( "Windows Cyrillic (CP 1251)" ),
117 wxTRANSLATE( "Windows Western European (CP 1252)" ),
118 wxTRANSLATE( "Windows Greek (CP 1253)" ),
119 wxTRANSLATE( "Windows Turkish (CP 1254)" ),
120 wxTRANSLATE( "Windows Hebrew (CP 1255)" ),
121 wxTRANSLATE( "Windows Arabic (CP 1256)" ),
122 wxTRANSLATE( "Windows Baltic (CP 1257)" ),
123 wxTRANSLATE( "Windows/DOS OEM (CP 437)" ),
124 wxTRANSLATE( "Unicode 7 bit (UTF-7)" ),
125 wxTRANSLATE( "Unicode 8 bit (UTF-8)" ),
126 };
127
128 // and the internal names
129 static const wxChar* gs_encodingNames[] =
130 {
131 wxT( "iso8859-1" ),
132 wxT( "iso8859-2" ),
133 wxT( "iso8859-3" ),
134 wxT( "iso8859-4" ),
135 wxT( "iso8859-5" ),
136 wxT( "iso8859-6" ),
137 wxT( "iso8859-7" ),
138 wxT( "iso8859-8" ),
139 wxT( "iso8859-9" ),
140 wxT( "iso8859-10" ),
141 wxT( "iso8859-11" ),
142 wxT( "iso8859-12" ),
143 wxT( "iso8859-13" ),
144 wxT( "iso8859-14" ),
145 wxT( "iso8859-15" ),
146 wxT( "koi8-r" ),
147 wxT( "windows-1250" ),
148 wxT( "windows-1251" ),
149 wxT( "windows-1252" ),
150 wxT( "windows-1253" ),
151 wxT( "windows-1254" ),
152 wxT( "windows-1255" ),
153 wxT( "windows-1256" ),
154 wxT( "windows-1257" ),
155 wxT( "windows-437" ),
156 wxT( "utf7" ),
157 wxT( "utf8" ),
158 };
159
160 // ----------------------------------------------------------------------------
161 // global data
162 // ----------------------------------------------------------------------------
163
164 // private object
165 static wxFontMapper gs_fontMapper;
166
167 // and public pointer
168 wxFontMapper * wxTheFontMapper = &gs_fontMapper;
169
170 // ----------------------------------------------------------------------------
171 // private classes
172 // ----------------------------------------------------------------------------
173
174 // change the config path during the lifetime of this object
175 class wxFontMapperPathChanger
176 {
177 public:
178 wxFontMapperPathChanger(wxFontMapper *fontMapper, const wxString& path)
179 {
180 m_fontMapper = fontMapper;
181 m_ok = m_fontMapper->ChangePath(path, &m_pathOld);
182 }
183
184 bool IsOk() const { return m_ok; }
185
186 ~wxFontMapperPathChanger()
187 {
188 if ( IsOk() )
189 m_fontMapper->RestorePath(m_pathOld);
190 }
191
192 private:
193 wxFontMapper *m_fontMapper;
194 bool m_ok;
195 wxString m_pathOld;
196 };
197
198 // ============================================================================
199 // implementation
200 // ============================================================================
201
202 // ----------------------------------------------------------------------------
203 // ctor and dtor
204 // ----------------------------------------------------------------------------
205
206 wxFontMapper::wxFontMapper()
207 {
208 #if wxUSE_CONFIG
209 m_config = NULL;
210 #endif // wxUSE_CONFIG
211
212 #if wxUSE_GUI
213 m_windowParent = NULL;
214 #endif // wxUSE_GUI
215 }
216
217 wxFontMapper::~wxFontMapper()
218 {
219 }
220
221 // ----------------------------------------------------------------------------
222 // customisation
223 // ----------------------------------------------------------------------------
224
225 #if wxUSE_CONFIG
226
227 /* static */ const wxChar *wxFontMapper::GetDefaultConfigPath()
228 {
229 return FONTMAPPER_ROOT_PATH;
230 }
231
232 void wxFontMapper::SetConfigPath(const wxString& prefix)
233 {
234 wxCHECK_RET( !prefix.IsEmpty() && prefix[0] == wxCONFIG_PATH_SEPARATOR,
235 wxT("an absolute path should be given to wxFontMapper::SetConfigPath()") );
236
237 m_configRootPath = prefix;
238 }
239
240 // ----------------------------------------------------------------------------
241 // get config object and path for it
242 // ----------------------------------------------------------------------------
243
244 wxConfigBase *wxFontMapper::GetConfig()
245 {
246 if ( !m_config )
247 {
248 // try the default
249 m_config = wxConfig::Get(FALSE /*don't create on demand*/ );
250
251 if ( !m_config )
252 {
253 // we still want to have a config object because otherwise we would
254 // keep asking the user the same questions in the interactive mode,
255 // so create a dummy config which won't write to any files/registry
256 // but will allow us to remember the results of the questions at
257 // least during this run
258 m_config = new wxMemoryConfig;
259 wxConfig::Set(m_config);
260 }
261 }
262
263 return m_config;
264 }
265
266 const wxString& wxFontMapper::GetConfigPath()
267 {
268 if ( !m_configRootPath )
269 {
270 // use the default
271 m_configRootPath = GetDefaultConfigPath();
272 }
273
274 return m_configRootPath;
275 }
276 #endif
277
278 bool wxFontMapper::ChangePath(const wxString& pathNew, wxString *pathOld)
279 {
280 #if wxUSE_CONFIG
281 wxConfigBase *config = GetConfig();
282 if ( !config )
283 return FALSE;
284
285 *pathOld = config->GetPath();
286
287 wxString path = GetConfigPath();
288 if ( path.IsEmpty() || path.Last() != wxCONFIG_PATH_SEPARATOR )
289 {
290 path += wxCONFIG_PATH_SEPARATOR;
291 }
292
293 wxASSERT_MSG( !pathNew || (pathNew[0] != wxCONFIG_PATH_SEPARATOR),
294 wxT("should be a relative path") );
295
296 path += pathNew;
297
298 config->SetPath(path);
299
300 return TRUE;
301 #else
302 return FALSE;
303 #endif
304 }
305
306 void wxFontMapper::RestorePath(const wxString& pathOld)
307 {
308 #if wxUSE_CONFIG
309 GetConfig()->SetPath(pathOld);
310 #else
311 #endif
312 }
313
314 // ----------------------------------------------------------------------------
315 // charset/encoding correspondence
316 // ----------------------------------------------------------------------------
317
318 /* static */
319 wxString wxFontMapper::GetEncodingDescription(wxFontEncoding encoding)
320 {
321 if ( encoding == wxFONTENCODING_DEFAULT )
322 {
323 return _("Default encoding");
324 }
325
326 size_t count = WXSIZEOF(gs_encodingDescs);
327
328 wxASSERT_MSG( count == WXSIZEOF(gs_encodings),
329 wxT("inconsitency detected - forgot to update one of the arrays?") );
330
331 for ( size_t i = 0; i < count; i++ )
332 {
333 if ( gs_encodings[i] == encoding )
334 {
335 return wxGetTranslation(gs_encodingDescs[i]);
336 }
337 }
338
339 wxString str;
340 str.Printf(_("Unknown encoding (%d)"), encoding);
341
342 return str;
343 }
344
345 /* static */
346 wxString wxFontMapper::GetEncodingName(wxFontEncoding encoding)
347 {
348 if ( encoding == wxFONTENCODING_DEFAULT )
349 {
350 return _("default");
351 }
352
353 size_t count = WXSIZEOF(gs_encodingNames);
354
355 wxASSERT_MSG( count == WXSIZEOF(gs_encodings),
356 wxT("inconsistency detected - forgot to update one of the arrays?") );
357
358 for ( size_t i = 0; i < count; i++ )
359 {
360 if ( gs_encodings[i] == encoding )
361 {
362 return wxGetTranslation(gs_encodingNames[i]);
363 }
364 }
365
366 wxString str;
367 str.Printf(_("unknown-%d"), encoding);
368
369 return str;
370 }
371
372 wxFontEncoding wxFontMapper::CharsetToEncoding(const wxString& charset,
373 bool interactive)
374 {
375 wxFontEncoding encoding = wxFONTENCODING_SYSTEM;
376
377 // we're going to modify it, make a copy
378 wxString cs = charset;
379
380 #if wxUSE_CONFIG
381 // first try the user-defined settings
382 wxString pathOld;
383 if ( ChangePath(FONTMAPPER_CHARSET_PATH, &pathOld) )
384 {
385 wxConfigBase *config = GetConfig();
386
387 // do we have an encoding for this charset?
388 long value = config->Read(charset, -1l);
389 if ( value != -1 )
390 {
391 if ( value >= 0 && value <= wxFONTENCODING_MAX )
392 {
393 encoding = (wxFontEncoding)value;
394 }
395 else
396 {
397 wxLogDebug(wxT("corrupted config data: invalid encoding %ld for charset '%s' ignored"),
398 value, charset.c_str());
399 }
400 }
401
402 if ( encoding == wxFONTENCODING_SYSTEM )
403 {
404 // may be we have an alias?
405 config->SetPath(FONTMAPPER_CHARSET_ALIAS_PATH);
406
407 wxString alias = config->Read(charset);
408 if ( !!alias )
409 {
410 // yes, we do - use it instead
411 cs = alias;
412 }
413 }
414
415 RestorePath(pathOld);
416 }
417 #endif
418
419 // if didn't find it there, try to recognize it ourselves
420 if ( encoding == wxFONTENCODING_SYSTEM )
421 {
422 // trim any spaces
423 cs.Trim(TRUE);
424 cs.Trim(FALSE);
425
426 // discard the optional quotes
427 if ( !!cs )
428 {
429 if ( cs[0u] == _T('"') && cs.Last() == _T('"') )
430 {
431 cs = wxString(cs.c_str(), cs.length() - 1);
432 }
433 }
434
435 cs.MakeUpper();
436
437 if ( !cs || cs == wxT("US-ASCII") )
438 {
439 encoding = wxFONTENCODING_DEFAULT;
440 }
441 else if ( cs == wxT("UTF-7") )
442 {
443 encoding = wxFONTENCODING_UTF7;
444 }
445 else if ( cs == wxT("UTF-8") )
446 {
447 encoding = wxFONTENCODING_UTF8;
448 }
449 else if ( cs == wxT("KOI8-R") ||
450 cs == wxT("KOI8-U") ||
451 cs == wxT("KOI8-RU") )
452 {
453 // although koi8-ru is not strictly speaking the same as koi8-r,
454 // they are similar enough to make mapping it to koi8 better than
455 // not reckognizing it at all
456 encoding = wxFONTENCODING_KOI8;
457 }
458 else if ( cs.Left(3) == wxT("ISO") )
459 {
460 // the dash is optional (or, to be exact, it is not, but
461 // several brokenmails "forget" it)
462 const wxChar *p = cs.c_str() + 3;
463 if ( *p == wxT('-') )
464 p++;
465
466 unsigned int value;
467 if ( wxSscanf(p, wxT("8859-%u"), &value) == 1 )
468 {
469 if ( value < wxFONTENCODING_ISO8859_MAX -
470 wxFONTENCODING_ISO8859_1 )
471 {
472 // it's a valid ISO8859 encoding
473 value += wxFONTENCODING_ISO8859_1 - 1;
474 encoding = (wxFontEncoding)value;
475 }
476 }
477 }
478 else // check for Windows charsets
479 {
480 size_t len;
481 if ( cs.Left(7) == wxT("WINDOWS") )
482 {
483 len = 7;
484 }
485 else if ( cs.Left(2) == wxT("CP") )
486 {
487 len = 2;
488 }
489 else // not a Windows encoding
490 {
491 len = 0;
492 }
493
494 if ( len )
495 {
496 const wxChar *p = cs.c_str() + len;
497 if ( *p == wxT('-') )
498 p++;
499
500 int value;
501 if ( wxSscanf(p, wxT("%u"), &value) == 1 )
502 {
503 if ( value >= 1250 )
504 {
505 value -= 1250;
506 if ( value < wxFONTENCODING_CP12_MAX -
507 wxFONTENCODING_CP1250 )
508 {
509 // a valid Windows code page
510 value += wxFONTENCODING_CP1250;
511 encoding = (wxFontEncoding)value;
512 }
513 }
514 }
515 }
516 }
517 //else: unknown
518 }
519
520 #if wxUSE_GUI
521 // if still no luck, ask the user - unless disabled
522 if ( (encoding == wxFONTENCODING_SYSTEM) && interactive )
523 {
524 // prepare the dialog data
525
526 // the dialog title
527 wxString title(m_titleDialog);
528 if ( !title )
529 title << wxTheApp->GetAppName() << _(": unknown charset");
530
531 // the message
532 wxString msg;
533 msg.Printf(_("The charset '%s' is unknown. You may select\nanother charset to replace it with or choose\n[Cancel] if it cannot be replaced"), charset.c_str());
534
535 // the list of choices
536 size_t count = WXSIZEOF(gs_encodingDescs);
537
538 wxASSERT_MSG( count == WXSIZEOF(gs_encodings),
539 wxT("inconsitency detected - forgot to update one of the arrays?") );
540
541 wxString *encodingNamesTranslated = new wxString[count];
542
543 for ( size_t i = 0; i < count; i++ )
544 {
545 encodingNamesTranslated[i] = wxGetTranslation(gs_encodingDescs[i]);
546 }
547
548 // the parent window
549 wxWindow *parent = m_windowParent;
550 if ( !parent )
551 parent = wxTheApp->GetTopWindow();
552
553 // do ask the user and get back the index in encodings table
554 int n = wxGetSingleChoiceIndex(msg, title,
555 count,
556 encodingNamesTranslated,
557 parent);
558
559 delete [] encodingNamesTranslated;
560
561 if ( n != -1 )
562 {
563 encoding = gs_encodings[n];
564
565 #if wxUSE_CONFIG
566 // save the result in the config now
567 if ( ChangePath(FONTMAPPER_CHARSET_PATH, &pathOld) )
568 {
569 wxConfigBase *config = GetConfig();
570
571 // remember the alt encoding for this charset
572 if ( !config->Write(charset, (long)encoding) )
573 {
574 wxLogError(_("Failed to remember the encoding for the charset '%s'."), charset.c_str());
575 }
576
577 RestorePath(pathOld);
578 }
579 #endif // wxUSE_CONFIG
580 }
581 //else: cancelled
582 }
583 #endif // wxUSE_GUI
584
585 return encoding;
586 }
587
588 // ----------------------------------------------------------------------------
589 // support for unknown encodings: we maintain a map between the
590 // (platform-specific) strings identifying them and our wxFontEncodings they
591 // correspond to which is used by GetFontForEncoding() function
592 // ----------------------------------------------------------------------------
593
594 #if wxUSE_GUI
595
596 bool wxFontMapper::TestAltEncoding(const wxString& configEntry,
597 wxFontEncoding encReplacement,
598 wxNativeEncodingInfo *info)
599 {
600 if ( wxGetNativeFontEncoding(encReplacement, info) &&
601 wxTestFontEncoding(*info) )
602 {
603 #if wxUSE_CONFIG
604 // remember the mapping in the config
605 wxFontMapperPathChanger path(this, FONTMAPPER_FONT_FROM_ENCODING_PATH);
606
607 if ( path.IsOk() )
608 {
609 GetConfig()->Write(configEntry, info->ToString());
610 }
611 #endif // wxUSE_CONFIG
612 return TRUE;
613 }
614
615 return FALSE;
616 }
617
618 #if wxUSE_GUI
619 class ReentrancyBlocker
620 {
621 public:
622 ReentrancyBlocker(bool& b) : m_b(b) { m_b = TRUE; }
623 ~ReentrancyBlocker() { m_b = FALSE; }
624
625 private:
626 bool& m_b;
627 };
628 #endif
629
630 bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding,
631 wxNativeEncodingInfo *info,
632 const wxString& facename,
633 bool interactive)
634 {
635 #if wxUSE_GUI
636 // we need a flag to prevent infinite recursion which happens, for
637 // example, when GetAltForEncoding() is called from an OnPaint() handler:
638 // in this case, wxYield() which is called from wxMessageBox() we use here
639 // will lead to another call of OnPaint() and hence to another call of
640 // GetAltForEncoding() - and it is impossible to catch this from the user
641 // code because we are called from wxFont ctor implicitly.
642
643 // assume we're always called from the main thread, so that it is safe to
644 // use a static var
645 static bool s_inGetAltForEncoding = FALSE;
646
647 if ( interactive && s_inGetAltForEncoding )
648 return FALSE;
649
650 ReentrancyBlocker blocker(s_inGetAltForEncoding);
651 #endif // wxUSE_GUI
652
653 wxCHECK_MSG( info, FALSE, wxT("bad pointer in GetAltForEncoding") );
654
655 info->facename = facename;
656
657 if ( encoding == wxFONTENCODING_DEFAULT )
658 {
659 encoding = wxFont::GetDefaultEncoding();
660 }
661
662 // if we failed to load the system default encoding, something is really
663 // wrong and we'd better stop now - otherwise we will go into endless
664 // recursion trying to create the font in the msg box with the error
665 // message
666 if ( encoding == wxFONTENCODING_SYSTEM )
667 {
668 wxFatalError(_("can't load any font, aborting"));
669
670 // wxFatalError doesn't return
671 }
672
673 wxString configEntry, encName = GetEncodingName(encoding);
674 if ( !!facename )
675 {
676 configEntry = facename + _T("_");
677 }
678 configEntry += encName;
679
680 #if wxUSE_CONFIG
681 // do we have a font spec for this encoding?
682 wxString pathOld;
683 if ( ChangePath(FONTMAPPER_FONT_FROM_ENCODING_PATH, &pathOld) )
684 {
685 wxConfigBase *config = GetConfig();
686
687 wxString fontinfo = config->Read(configEntry);
688
689 RestorePath(pathOld);
690
691 if ( !!fontinfo && !!facename )
692 {
693 // we tried to find a match with facename - now try without it
694 fontinfo = config->Read(encName);
695 }
696
697 if ( !!fontinfo )
698 {
699 if ( info->FromString(fontinfo) )
700 {
701 if ( wxTestFontEncoding(*info) )
702 {
703 // ok, got something
704 return TRUE;
705 }
706 //else: no such fonts, look for something else
707 }
708 else
709 {
710 wxLogDebug(wxT("corrupted config data: string '%s' is not a valid font encoding info"), fontinfo.c_str());
711 }
712 }
713 //else: there is no information in config about this encoding
714 }
715 #endif // wxUSE_CONFIG
716
717 // ask the user
718 if ( interactive )
719 {
720 wxString title(m_titleDialog);
721 if ( !title )
722 title << wxTheApp->GetAppName() << _(": unknown encoding");
723
724 // the message
725 wxString msg;
726 msg.Printf(_("The encoding '%s' is unknown.\nWould you like to select a font to be used for this encoding\n(otherwise the text in this encoding will not be shown correctly)?"),
727 GetEncodingDescription(encoding).c_str());
728
729 wxWindow *parent = m_windowParent;
730 if ( !parent )
731 parent = wxTheApp->GetTopWindow();
732
733 if ( wxMessageBox(msg, title,
734 wxICON_QUESTION | wxYES_NO, parent) == wxYES )
735 {
736 wxFontData data;
737 data.SetEncoding(encoding);
738 data.EncodingInfo() = *info;
739 wxFontDialog dialog(parent, &data);
740 if ( dialog.ShowModal() == wxID_OK )
741 {
742 wxFontData retData = dialog.GetFontData();
743 wxFont font = retData.GetChosenFont();
744
745 *info = retData.EncodingInfo();
746 info -> encoding = retData.GetEncoding();
747
748 #if wxUSE_CONFIG
749 // remember this in the config
750 if ( ChangePath(FONTMAPPER_FONT_FROM_ENCODING_PATH, &pathOld) )
751 {
752 GetConfig()->Write(configEntry, info->ToString());
753
754 RestorePath(pathOld);
755 }
756 #endif // wxUSE_CONFIG
757
758 return TRUE;
759 }
760 //else: the user canceled the font selection dialog
761 }
762 //else: the user doesn't want to select a font
763 }
764 //else: we're in non-interactive mode
765
766 // now try the default mappings:
767 wxFontEncodingArray equiv = wxEncodingConverter::GetAllEquivalents(encoding);
768 size_t count = equiv.GetCount();
769 if ( count )
770 {
771 for ( size_t i = (equiv[0] == encoding) ? 1 : 0; i < count; i++ )
772 {
773 if ( TestAltEncoding(configEntry, equiv[i], info) )
774 return TRUE;
775 }
776 }
777
778 return FALSE;
779 }
780
781 bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding,
782 wxFontEncoding *alt_encoding,
783 const wxString& facename,
784 bool interactive)
785 {
786 wxNativeEncodingInfo info;
787 bool r = GetAltForEncoding(encoding, &info, facename, interactive);
788 *alt_encoding = info.encoding;
789 return r;
790 }
791
792 bool wxFontMapper::IsEncodingAvailable(wxFontEncoding encoding,
793 const wxString& facename)
794 {
795 wxNativeEncodingInfo info;
796
797 if (wxGetNativeFontEncoding(encoding, &info))
798 {
799 info.facename = facename;
800 return wxTestFontEncoding(info);
801 }
802
803 return FALSE;
804 }
805
806 #endif // wxUSE_GUI