1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/fontmap.cpp
3 // Purpose: wxFontMapper class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "fontmap.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
39 #include "wx/module.h"
40 #include "wx/fontmap.h"
43 #include "wx/config.h"
44 #include "wx/memconf.h"
48 #include "wx/fontutil.h"
49 #include "wx/msgdlg.h"
50 #include "wx/fontdlg.h"
51 #include "wx/choicdlg.h"
54 #include "wx/encconv.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // the config paths we use
62 static const wxChar
* FONTMAPPER_ROOT_PATH
= wxT("/wxWindows/FontMapper");
63 static const wxChar
* FONTMAPPER_CHARSET_PATH
= wxT("Charsets");
64 static const wxChar
* FONTMAPPER_CHARSET_ALIAS_PATH
= wxT("Aliases");
66 // we only ask questions in GUI mode
68 static const wxChar
* FONTMAPPER_FONT_FROM_ENCODING_PATH
= wxT("Encodings");
69 static const wxChar
* FONTMAPPER_FONT_DONT_ASK
= wxT("none");
71 #endif // wxUSE_CONFIG
73 // encodings supported by GetEncodingDescription
74 static wxFontEncoding gs_encodings
[] =
76 wxFONTENCODING_ISO8859_1
,
77 wxFONTENCODING_ISO8859_2
,
78 wxFONTENCODING_ISO8859_3
,
79 wxFONTENCODING_ISO8859_4
,
80 wxFONTENCODING_ISO8859_5
,
81 wxFONTENCODING_ISO8859_6
,
82 wxFONTENCODING_ISO8859_7
,
83 wxFONTENCODING_ISO8859_8
,
84 wxFONTENCODING_ISO8859_9
,
85 wxFONTENCODING_ISO8859_10
,
86 wxFONTENCODING_ISO8859_11
,
87 wxFONTENCODING_ISO8859_12
,
88 wxFONTENCODING_ISO8859_13
,
89 wxFONTENCODING_ISO8859_14
,
90 wxFONTENCODING_ISO8859_15
,
96 wxFONTENCODING_CP1250
,
97 wxFONTENCODING_CP1251
,
98 wxFONTENCODING_CP1252
,
99 wxFONTENCODING_CP1253
,
100 wxFONTENCODING_CP1254
,
101 wxFONTENCODING_CP1255
,
102 wxFONTENCODING_CP1256
,
103 wxFONTENCODING_CP1257
,
104 wxFONTENCODING_CP437
,
107 wxFONTENCODING_EUC_JP
,
110 // the descriptions for them
111 static const wxChar
* gs_encodingDescs
[] =
113 wxTRANSLATE( "Western European (ISO-8859-1)" ),
114 wxTRANSLATE( "Central European (ISO-8859-2)" ),
115 wxTRANSLATE( "Esperanto (ISO-8859-3)" ),
116 wxTRANSLATE( "Baltic (old) (ISO-8859-4)" ),
117 wxTRANSLATE( "Cyrillic (ISO-8859-5)" ),
118 wxTRANSLATE( "Arabic (ISO-8859-6)" ),
119 wxTRANSLATE( "Greek (ISO-8859-7)" ),
120 wxTRANSLATE( "Hebrew (ISO-8859-8)" ),
121 wxTRANSLATE( "Turkish (ISO-8859-9)" ),
122 wxTRANSLATE( "Nordic (ISO-8859-10)" ),
123 wxTRANSLATE( "Thai (ISO-8859-11)" ),
124 wxTRANSLATE( "Indian (ISO-8859-12)" ),
125 wxTRANSLATE( "Baltic (ISO-8859-13)" ),
126 wxTRANSLATE( "Celtic (ISO-8859-14)" ),
127 wxTRANSLATE( "Western European with Euro (ISO-8859-15)" ),
128 wxTRANSLATE( "KOI8-R" ),
129 wxTRANSLATE( "Windows Japanese (CP 932)" ),
130 wxTRANSLATE( "Windows Chinese Simplified (CP 936)" ),
131 wxTRANSLATE( "Windows Korean (CP 949)" ),
132 wxTRANSLATE( "Windows Chinese Traditional (CP 950)" ),
133 wxTRANSLATE( "Windows Central European (CP 1250)" ),
134 wxTRANSLATE( "Windows Cyrillic (CP 1251)" ),
135 wxTRANSLATE( "Windows Western European (CP 1252)" ),
136 wxTRANSLATE( "Windows Greek (CP 1253)" ),
137 wxTRANSLATE( "Windows Turkish (CP 1254)" ),
138 wxTRANSLATE( "Windows Hebrew (CP 1255)" ),
139 wxTRANSLATE( "Windows Arabic (CP 1256)" ),
140 wxTRANSLATE( "Windows Baltic (CP 1257)" ),
141 wxTRANSLATE( "Windows/DOS OEM (CP 437)" ),
142 wxTRANSLATE( "Unicode 7 bit (UTF-7)" ),
143 wxTRANSLATE( "Unicode 8 bit (UTF-8)" ),
144 wxTRANSLATE( "Extended Unix Codepage for Japanese (EUC-JP)" ),
147 // and the internal names (these are not translated on purpose!)
148 static const wxChar
* gs_encodingNames
[] =
159 wxT( "iso-8859-10" ),
160 wxT( "iso-8859-11" ),
161 wxT( "iso-8859-12" ),
162 wxT( "iso-8859-13" ),
163 wxT( "iso-8859-14" ),
164 wxT( "iso-8859-15" ),
166 wxT( "windows-932" ),
167 wxT( "windows-936" ),
168 wxT( "windows-949" ),
169 wxT( "windows-950" ),
170 wxT( "windows-1250" ),
171 wxT( "windows-1251" ),
172 wxT( "windows-1252" ),
173 wxT( "windows-1253" ),
174 wxT( "windows-1254" ),
175 wxT( "windows-1255" ),
176 wxT( "windows-1256" ),
177 wxT( "windows-1257" ),
178 wxT( "windows-437" ),
184 wxCOMPILE_TIME_ASSERT( WXSIZEOF(gs_encodingDescs
) == WXSIZEOF(gs_encodings
) &&
185 WXSIZEOF(gs_encodingNames
) == WXSIZEOF(gs_encodings
),
186 EncodingsArraysNotInSync
);
188 // ----------------------------------------------------------------------------
190 // ----------------------------------------------------------------------------
192 // change the config path during the lifetime of this object
193 class wxFontMapperPathChanger
196 wxFontMapperPathChanger(wxFontMapper
*fontMapper
, const wxString
& path
)
198 m_fontMapper
= fontMapper
;
199 m_ok
= m_fontMapper
->ChangePath(path
, &m_pathOld
);
202 bool IsOk() const { return m_ok
; }
204 ~wxFontMapperPathChanger()
207 m_fontMapper
->RestorePath(m_pathOld
);
211 wxFontMapper
*m_fontMapper
;
215 DECLARE_NO_COPY_CLASS(wxFontMapperPathChanger
)
218 // ============================================================================
220 // ============================================================================
222 // ----------------------------------------------------------------------------
224 // ----------------------------------------------------------------------------
226 wxFontMapper::wxFontMapper()
230 m_configIsDummy
= FALSE
;
231 #endif // wxUSE_CONFIG
234 m_windowParent
= NULL
;
238 wxFontMapper::~wxFontMapper()
241 if ( m_configIsDummy
)
243 #endif // wxUSE_CONFIG
246 wxFontMapper
*wxFontMapper::sm_instance
= NULL
;
248 /*static*/ wxFontMapper
*wxFontMapper::Get()
251 sm_instance
= new wxFontMapper
;
255 /*static*/ wxFontMapper
*wxFontMapper::Set(wxFontMapper
*mapper
)
257 wxFontMapper
*old
= sm_instance
;
258 sm_instance
= mapper
;
262 class wxFontMapperModule
: public wxModule
265 wxFontMapperModule() : wxModule() {}
266 virtual bool OnInit() { return TRUE
; }
267 virtual void OnExit() { delete wxFontMapper::Set(NULL
); }
269 DECLARE_DYNAMIC_CLASS(wxFontMapperModule
)
272 IMPLEMENT_DYNAMIC_CLASS(wxFontMapperModule
, wxModule
)
274 // ----------------------------------------------------------------------------
276 // ----------------------------------------------------------------------------
280 /* static */ const wxChar
*wxFontMapper::GetDefaultConfigPath()
282 return FONTMAPPER_ROOT_PATH
;
285 void wxFontMapper::SetConfigPath(const wxString
& prefix
)
287 wxCHECK_RET( !prefix
.IsEmpty() && prefix
[0] == wxCONFIG_PATH_SEPARATOR
,
288 wxT("an absolute path should be given to wxFontMapper::SetConfigPath()") );
290 m_configRootPath
= prefix
;
293 // ----------------------------------------------------------------------------
294 // get config object and path for it
295 // ----------------------------------------------------------------------------
297 wxConfigBase
*wxFontMapper::GetConfig()
302 m_config
= wxConfig::Get(FALSE
/*don't create on demand*/ );
306 // we still want to have a config object because otherwise we would
307 // keep asking the user the same questions in the interactive mode,
308 // so create a dummy config which won't write to any files/registry
309 // but will allow us to remember the results of the questions at
310 // least during this run
311 m_config
= new wxMemoryConfig
;
312 m_configIsDummy
= TRUE
;
313 // VS: we can't call wxConfig::Set(m_config) here because that would
314 // disable automatic wxConfig instance creation if this code was
315 // called before wxApp::OnInit (this happens in wxGTK -- it sets
316 // default wxFont encoding in wxApp::Initialize())
320 if ( m_configIsDummy
&& wxConfig::Get(FALSE
) != NULL
)
322 // VS: in case we created dummy m_config (see above), we want to switch back
323 // to the real one as soon as one becomes available.
325 m_config
= wxConfig::Get(FALSE
);
326 m_configIsDummy
= FALSE
;
327 // FIXME: ideally, we should add keys from dummy config to the real one now,
328 // but it is a low-priority task because typical wxWin application
329 // either doesn't use wxConfig at all or creates wxConfig object in
330 // wxApp::OnInit(), before any real interaction with the user takes
337 const wxString
& wxFontMapper::GetConfigPath()
339 if ( !m_configRootPath
)
342 m_configRootPath
= GetDefaultConfigPath();
345 return m_configRootPath
;
349 bool wxFontMapper::ChangePath(const wxString
& pathNew
, wxString
*pathOld
)
352 wxConfigBase
*config
= GetConfig();
356 *pathOld
= config
->GetPath();
358 wxString path
= GetConfigPath();
359 if ( path
.IsEmpty() || path
.Last() != wxCONFIG_PATH_SEPARATOR
)
361 path
+= wxCONFIG_PATH_SEPARATOR
;
364 wxASSERT_MSG( !pathNew
|| (pathNew
[0] != wxCONFIG_PATH_SEPARATOR
),
365 wxT("should be a relative path") );
369 config
->SetPath(path
);
377 void wxFontMapper::RestorePath(const wxString
& pathOld
)
380 GetConfig()->SetPath(pathOld
);
385 // ----------------------------------------------------------------------------
386 // charset/encoding correspondence
387 // ----------------------------------------------------------------------------
390 wxString
wxFontMapper::GetEncodingDescription(wxFontEncoding encoding
)
392 if ( encoding
== wxFONTENCODING_DEFAULT
)
394 return _("Default encoding");
397 const size_t count
= WXSIZEOF(gs_encodingDescs
);
399 for ( size_t i
= 0; i
< count
; i
++ )
401 if ( gs_encodings
[i
] == encoding
)
403 return wxGetTranslation(gs_encodingDescs
[i
]);
408 str
.Printf(_("Unknown encoding (%d)"), encoding
);
414 wxString
wxFontMapper::GetEncodingName(wxFontEncoding encoding
)
416 if ( encoding
== wxFONTENCODING_DEFAULT
)
421 const size_t count
= WXSIZEOF(gs_encodingNames
);
423 for ( size_t i
= 0; i
< count
; i
++ )
425 if ( gs_encodings
[i
] == encoding
)
427 return gs_encodingNames
[i
];
432 str
.Printf(_("unknown-%d"), encoding
);
437 wxFontEncoding
wxFontMapper::CharsetToEncoding(const wxString
& charset
,
440 // a special pseudo encoding which means "don't ask me about this charset
441 // any more" - we need it to avoid driving the user crazy with asking him
442 // time after time about the same charset which he [presumably] doesn't
443 // have the fonts fot
444 static const int wxFONTENCODING_UNKNOWN
= -2;
446 wxFontEncoding encoding
= wxFONTENCODING_SYSTEM
;
448 // we're going to modify it, make a copy
449 wxString cs
= charset
;
452 // first try the user-defined settings
454 if ( ChangePath(FONTMAPPER_CHARSET_PATH
, &pathOld
) )
456 wxConfigBase
*config
= GetConfig();
458 // do we have an encoding for this charset?
459 long value
= config
->Read(charset
, -1l);
462 if ( value
== wxFONTENCODING_UNKNOWN
)
464 // don't try to find it, in particular don't ask the user
465 return wxFONTENCODING_SYSTEM
;
468 if ( value
>= 0 && value
<= wxFONTENCODING_MAX
)
470 encoding
= (wxFontEncoding
)value
;
474 wxLogDebug(wxT("corrupted config data: invalid encoding %ld for charset '%s' ignored"),
475 value
, charset
.c_str());
479 if ( encoding
== wxFONTENCODING_SYSTEM
)
481 // may be we have an alias?
482 config
->SetPath(FONTMAPPER_CHARSET_ALIAS_PATH
);
484 wxString alias
= config
->Read(charset
);
487 // yes, we do - use it instead
492 RestorePath(pathOld
);
494 #endif // wxUSE_CONFIG
496 // if didn't find it there, try to recognize it ourselves
497 if ( encoding
== wxFONTENCODING_SYSTEM
)
503 // discard the optional quotes
506 if ( cs
[0u] == _T('"') && cs
.Last() == _T('"') )
508 cs
= wxString(cs
.c_str(), cs
.length() - 1);
514 if ( cs
.empty() || cs
== _T("US-ASCII") )
516 encoding
= wxFONTENCODING_DEFAULT
;
518 else if ( cs
== wxT("UTF-7") )
520 encoding
= wxFONTENCODING_UTF7
;
522 else if ( cs
== wxT("UTF-8") )
524 encoding
= wxFONTENCODING_UTF8
;
526 else if ( cs
== wxT("GB2312") )
528 encoding
= wxFONTENCODING_GB2312
;
530 else if ( cs
== wxT("BIG5") )
532 encoding
= wxFONTENCODING_BIG5
;
534 else if ( cs
== wxT("SJIS") ||
535 cs
== wxT("SHIFT_JIS") ||
536 cs
== wxT("SHIFT-JIS") )
538 encoding
= wxFONTENCODING_SHIFT_JIS
;
540 else if ( cs
== wxT("EUC-JP") ||
541 cs
== wxT("EUC_JP") )
543 encoding
= wxFONTENCODING_EUC_JP
;
545 else if ( cs
== wxT("KOI8-R") ||
546 cs
== wxT("KOI8-U") ||
547 cs
== wxT("KOI8-RU") )
549 // although koi8-ru is not strictly speaking the same as koi8-r,
550 // they are similar enough to make mapping it to koi8 better than
551 // not reckognizing it at all
552 encoding
= wxFONTENCODING_KOI8
;
554 else if ( cs
.Left(3) == wxT("ISO") )
556 // the dash is optional (or, to be exact, it is not, but
557 // several brokenmails "forget" it)
558 const wxChar
*p
= cs
.c_str() + 3;
559 if ( *p
== wxT('-') )
562 // printf( "iso %s\n", (const char*) cs.ToAscii() );
565 if ( wxSscanf(p
, wxT("8859-%u"), &value
) == 1 )
567 // printf( "value %d\n", (int)value );
569 // make it 0 based and check that it is strictly positive in
570 // the process (no such thing as iso8859-0 encoding)
571 if ( (value
-- > 0) &&
572 (value
< wxFONTENCODING_ISO8859_MAX
-
573 wxFONTENCODING_ISO8859_1
) )
575 // it's a valid ISO8859 encoding
576 value
+= wxFONTENCODING_ISO8859_1
;
577 encoding
= (wxFontEncoding
)value
;
581 else if ( cs
.Left(4) == wxT("8859") )
583 const wxChar
*p
= cs
.c_str();
586 if ( wxSscanf(p
, wxT("8859-%u"), &value
) == 1 )
588 // printf( "value %d\n", (int)value );
590 // make it 0 based and check that it is strictly positive in
591 // the process (no such thing as iso8859-0 encoding)
592 if ( (value
-- > 0) &&
593 (value
< wxFONTENCODING_ISO8859_MAX
-
594 wxFONTENCODING_ISO8859_1
) )
596 // it's a valid ISO8859 encoding
597 value
+= wxFONTENCODING_ISO8859_1
;
598 encoding
= (wxFontEncoding
)value
;
602 else // check for Windows charsets
605 if ( cs
.Left(7) == wxT("WINDOWS") )
609 else if ( cs
.Left(2) == wxT("CP") )
613 else // not a Windows encoding
620 const wxChar
*p
= cs
.c_str() + len
;
621 if ( *p
== wxT('-') )
625 if ( wxSscanf(p
, wxT("%u"), &value
) == 1 )
630 if ( value
< wxFONTENCODING_CP12_MAX
-
631 wxFONTENCODING_CP1250
)
633 // a valid Windows code page
634 value
+= wxFONTENCODING_CP1250
;
635 encoding
= (wxFontEncoding
)value
;
642 encoding
= wxFONTENCODING_CP932
;
646 encoding
= wxFONTENCODING_CP936
;
650 encoding
= wxFONTENCODING_CP949
;
654 encoding
= wxFONTENCODING_CP950
;
664 // if still no luck, ask the user - unless disabled
665 if ( (encoding
== wxFONTENCODING_SYSTEM
) && interactive
)
667 // prepare the dialog data
670 wxString
title(m_titleDialog
);
672 title
<< wxTheApp
->GetAppName() << _(": unknown charset");
676 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());
678 // the list of choices
679 const size_t count
= WXSIZEOF(gs_encodingDescs
);
681 wxString
*encodingNamesTranslated
= new wxString
[count
];
683 for ( size_t i
= 0; i
< count
; i
++ )
685 encodingNamesTranslated
[i
] = wxGetTranslation(gs_encodingDescs
[i
]);
689 wxWindow
*parent
= m_windowParent
;
691 parent
= wxTheApp
->GetTopWindow();
693 // do ask the user and get back the index in encodings table
694 int n
= wxGetSingleChoiceIndex(msg
, title
,
696 encodingNamesTranslated
,
699 delete [] encodingNamesTranslated
;
703 encoding
= gs_encodings
[n
];
707 // save the result in the config now
708 if ( ChangePath(FONTMAPPER_CHARSET_PATH
, &pathOld
) )
710 wxConfigBase
*config
= GetConfig();
712 // remember the alt encoding for this charset - or remember that
714 long value
= n
== -1 ? wxFONTENCODING_UNKNOWN
: (long)encoding
;
715 if ( !config
->Write(charset
, value
) )
717 wxLogError(_("Failed to remember the encoding for the charset '%s'."), charset
.c_str());
720 RestorePath(pathOld
);
722 #endif // wxUSE_CONFIG
729 // ----------------------------------------------------------------------------
730 // support for unknown encodings: we maintain a map between the
731 // (platform-specific) strings identifying them and our wxFontEncodings they
732 // correspond to which is used by GetFontForEncoding() function
733 // ----------------------------------------------------------------------------
737 bool wxFontMapper::TestAltEncoding(const wxString
& configEntry
,
738 wxFontEncoding encReplacement
,
739 wxNativeEncodingInfo
*info
)
741 if ( wxGetNativeFontEncoding(encReplacement
, info
) &&
742 wxTestFontEncoding(*info
) )
745 // remember the mapping in the config
746 wxFontMapperPathChanger
path(this, FONTMAPPER_FONT_FROM_ENCODING_PATH
);
750 GetConfig()->Write(configEntry
, info
->ToString());
752 #endif // wxUSE_CONFIG
760 class ReentrancyBlocker
763 ReentrancyBlocker(bool& b
) : m_b(b
) { m_b
= TRUE
; }
764 ~ReentrancyBlocker() { m_b
= FALSE
; }
771 bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding
,
772 wxNativeEncodingInfo
*info
,
773 const wxString
& facename
,
777 // we need a flag to prevent infinite recursion which happens, for
778 // example, when GetAltForEncoding() is called from an OnPaint() handler:
779 // in this case, wxYield() which is called from wxMessageBox() we use here
780 // will lead to another call of OnPaint() and hence to another call of
781 // GetAltForEncoding() - and it is impossible to catch this from the user
782 // code because we are called from wxFont ctor implicitly.
784 // assume we're always called from the main thread, so that it is safe to
786 static bool s_inGetAltForEncoding
= FALSE
;
788 if ( interactive
&& s_inGetAltForEncoding
)
791 ReentrancyBlocker
blocker(s_inGetAltForEncoding
);
794 wxCHECK_MSG( info
, FALSE
, wxT("bad pointer in GetAltForEncoding") );
796 info
->facename
= facename
;
798 if ( encoding
== wxFONTENCODING_DEFAULT
)
800 encoding
= wxFont::GetDefaultEncoding();
803 // if we failed to load the system default encoding, something is really
804 // wrong and we'd better stop now - otherwise we will go into endless
805 // recursion trying to create the font in the msg box with the error
807 if ( encoding
== wxFONTENCODING_SYSTEM
)
809 wxLogFatalError(_("can't load any font, aborting"));
811 // wxLogFatalError doesn't return
814 wxString configEntry
,
815 encName
= GetEncodingName(encoding
);
818 configEntry
= facename
+ _T("_");
820 configEntry
+= encName
;
823 // do we have a font spec for this encoding?
825 if ( ChangePath(FONTMAPPER_FONT_FROM_ENCODING_PATH
, &pathOld
) )
827 wxConfigBase
*config
= GetConfig();
829 wxString fontinfo
= config
->Read(configEntry
);
831 RestorePath(pathOld
);
833 // this special value means that we don't know of fonts for this
834 // encoding but, moreover, have already asked the user as well and he
835 // didn't specify any font neither
836 if ( fontinfo
== FONTMAPPER_FONT_DONT_ASK
)
840 else // use the info entered the last time
842 if ( !!fontinfo
&& !!facename
)
844 // we tried to find a match with facename - now try without it
845 fontinfo
= config
->Read(encName
);
850 if ( info
->FromString(fontinfo
) )
852 if ( wxTestFontEncoding(*info
) )
857 //else: no such fonts, look for something else
858 // (should we erase the outdated value?)
862 wxLogDebug(wxT("corrupted config data: string '%s' is not a valid font encoding info"),
866 //else: there is no information in config about this encoding
869 #endif // wxUSE_CONFIG
871 // now try to map this encoding to a compatible one which we have on this
873 wxFontEncodingArray equiv
= wxEncodingConverter::GetAllEquivalents(encoding
);
874 size_t count
= equiv
.GetCount();
875 bool foundEquivEncoding
= FALSE
;
876 wxFontEncoding equivEncoding
= wxFONTENCODING_SYSTEM
;
879 for ( size_t i
= 0; i
< count
&& !foundEquivEncoding
; i
++ )
881 // don't test for encoding itself, we already know we don't have it
882 if ( equiv
[i
] == encoding
)
885 if ( TestAltEncoding(configEntry
, equiv
[i
], info
) )
887 equivEncoding
= equiv
[i
];
889 foundEquivEncoding
= TRUE
;
898 wxString
title(m_titleDialog
);
900 title
<< wxTheApp
->GetAppName() << _(": unknown encoding");
903 wxString encDesc
= GetEncodingDescription(encoding
),
905 if ( foundEquivEncoding
)
907 // ask the user if he wants to override found alternative encoding
908 msg
.Printf(_("No font for displaying text in encoding '%s' found,\nbut an alternative encoding '%s' is available.\nDo you want to use this encoding (otherwise you will have to choose another one)?"),
909 encDesc
.c_str(), GetEncodingDescription(equivEncoding
).c_str());
913 msg
.Printf(_("No font for displaying text in encoding '%s' found.\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)?"),
917 // the question is different in 2 cases so the answer has to be
918 // interpreted differently as well
919 int answer
= foundEquivEncoding
? wxNO
: wxYES
;
921 if ( wxMessageBox(msg
, title
,
922 wxICON_QUESTION
| wxYES_NO
,
923 m_windowParent
) == answer
)
926 data
.SetEncoding(encoding
);
927 data
.EncodingInfo() = *info
;
928 wxFontDialog
dialog(m_windowParent
, data
);
929 if ( dialog
.ShowModal() == wxID_OK
)
931 wxFontData retData
= dialog
.GetFontData();
932 wxFont font
= retData
.GetChosenFont();
934 *info
= retData
.EncodingInfo();
935 info
->encoding
= retData
.GetEncoding();
938 // remember this in the config
939 if ( ChangePath(FONTMAPPER_FONT_FROM_ENCODING_PATH
, &pathOld
) )
941 GetConfig()->Write(configEntry
, info
->ToString());
943 RestorePath(pathOld
);
945 #endif // wxUSE_CONFIG
949 //else: the user canceled the font selection dialog
953 // the user doesn't want to select a font for this encoding
954 // or selected to use equivalent encoding
956 // remember it to avoid asking the same question again later
958 if ( ChangePath(FONTMAPPER_FONT_FROM_ENCODING_PATH
, &pathOld
) )
963 foundEquivEncoding
? info
->ToString().c_str()
964 : FONTMAPPER_FONT_DONT_ASK
967 RestorePath(pathOld
);
969 #endif // wxUSE_CONFIG
972 //else: we're in non-interactive mode
973 #endif // wxUSE_FONTDLG
975 return foundEquivEncoding
;
978 bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding
,
979 wxFontEncoding
*alt_encoding
,
980 const wxString
& facename
,
983 wxNativeEncodingInfo info
;
984 bool r
= GetAltForEncoding(encoding
, &info
, facename
, interactive
);
985 *alt_encoding
= info
.encoding
;
989 bool wxFontMapper::IsEncodingAvailable(wxFontEncoding encoding
,
990 const wxString
& facename
)
992 wxNativeEncodingInfo info
;
994 if (wxGetNativeFontEncoding(encoding
, &info
))
996 info
.facename
= facename
;
997 return wxTestFontEncoding(info
);
1005 #endif // wxUSE_FONTMAP