-
- return m_config;
-}
-
-const wxString& wxFontMapper::GetConfigPath()
-{
- if ( !m_configRootPath )
- {
- // use the default
- m_configRootPath = GetDefaultConfigPath();
- }
-
- return m_configRootPath;
-}
-#endif
-
-bool wxFontMapper::ChangePath(const wxString& pathNew, wxString *pathOld)
-{
-#if wxUSE_CONFIG
- wxConfigBase *config = GetConfig();
- if ( !config )
- return FALSE;
-
- *pathOld = config->GetPath();
-
- wxString path = GetConfigPath();
- if ( path.IsEmpty() || path.Last() != wxCONFIG_PATH_SEPARATOR )
- {
- path += wxCONFIG_PATH_SEPARATOR;
- }
-
- wxASSERT_MSG( !pathNew || (pathNew[0] != wxCONFIG_PATH_SEPARATOR),
- wxT("should be a relative path") );
-
- path += pathNew;
-
- config->SetPath(path);
-
- return TRUE;
-#else
- return FALSE;
-#endif
-}
-
-void wxFontMapper::RestorePath(const wxString& pathOld)
-{
-#if wxUSE_CONFIG
- GetConfig()->SetPath(pathOld);
-#else
-#endif
-}
-
-// ----------------------------------------------------------------------------
-// charset/encoding correspondence
-// ----------------------------------------------------------------------------
-
-/* static */
-wxString wxFontMapper::GetEncodingDescription(wxFontEncoding encoding)
-{
- size_t count = WXSIZEOF(gs_encodingDescs);
-
- wxASSERT_MSG( count == WXSIZEOF(gs_encodings),
- wxT("inconsitency detected - forgot to update one of the arrays?") );
-
- for ( size_t i = 0; i < count; i++ )
- {
- if ( gs_encodings[i] == encoding )
- {
- return wxGetTranslation(gs_encodingDescs[i]);
- }
- }
-
- wxString str;
- str.Printf(_("Unknown encoding (%d)"), encoding);
-
- return str;
-}
-
-/* static */
-wxString wxFontMapper::GetEncodingName(wxFontEncoding encoding)
-{
- size_t count = WXSIZEOF(gs_encodingNames);
-
- wxASSERT_MSG( count == WXSIZEOF(gs_encodings),
- wxT("inconsistency detected - forgot to update one of the arrays?") );
-
- for ( size_t i = 0; i < count; i++ )
- {
- if ( gs_encodings[i] == encoding )
- {
- return wxGetTranslation(gs_encodingNames[i]);
- }
- }
-
- wxString str;
- str.Printf(_("unknown-%d"), encoding);
-
- return str;
-}
-
-wxFontEncoding wxFontMapper::CharsetToEncoding(const wxString& charset,
- bool interactive)
-{
- wxFontEncoding encoding = wxFONTENCODING_SYSTEM;
-
- // we're going to modify it, make a copy
- wxString cs = charset;
-
-#if wxUSE_CONFIG
- // first try the user-defined settings
- wxString pathOld;
- if ( ChangePath(FONTMAPPER_CHARSET_PATH, &pathOld) )
- {
- wxConfigBase *config = GetConfig();
-
- // do we have an encoding for this charset?
- long value = config->Read(charset, -1l);
- if ( value != -1 )
- {
- if ( value >= 0 && value <= wxFONTENCODING_MAX )
- {
- encoding = (wxFontEncoding)value;
- }
- else
- {
- wxLogDebug(wxT("corrupted config data: invalid encoding %ld for charset '%s' ignored"),
- value, charset.c_str());
- }
- }
-
- if ( encoding == wxFONTENCODING_SYSTEM )
- {
- // may be we have an alias?
- config->SetPath(FONTMAPPER_CHARSET_ALIAS_PATH);
-
- wxString alias = config->Read(charset);
- if ( !!alias )
- {
- // yes, we do - use it instead
- cs = alias;
- }
- }
-
- RestorePath(pathOld);
- }
-#endif
-
- // if didn't find it there, try to reckognise it ourselves
- if ( encoding == wxFONTENCODING_SYSTEM )
- {
- // discard the optional quotes
- if ( !!cs )
- {
- if ( cs[0u] == _T('"') && cs.Last() == _T('"') )
- {
- cs = wxString(cs.c_str(), cs.length() - 1);
- }
- }
-
- cs.MakeUpper();
-
- if ( !cs || cs == wxT("US-ASCII") )
- encoding = wxFONTENCODING_DEFAULT;
- else if ( cs == wxT("KOI8-R") || cs == wxT("KOI8-U") )
- encoding = wxFONTENCODING_KOI8;
- else if ( cs.Left(3) == wxT("ISO") )
- {
- // the dash is optional (or, to be exact, it is not, but
- // several brokenmails "forget" it)
- const wxChar *p = cs.c_str() + 3;
- if ( *p == wxT('-') )
- p++;
-
- unsigned int value;
- if ( wxSscanf(p, wxT("8859-%u"), &value) == 1 )
- {
- if ( value < wxFONTENCODING_ISO8859_MAX -
- wxFONTENCODING_ISO8859_1 )
- {
- // it's a valid ISO8859 encoding
- value += wxFONTENCODING_ISO8859_1 - 1;
- encoding = (wxFontEncoding)value;
- }
- }
- }
- else if ( cs.Left(8) == wxT("WINDOWS-") )
- {
- int value;
- if ( wxSscanf(cs.c_str() + 8, wxT("%u"), &value) == 1 )
- {
- if ( value >= 1250 )
- {
- value -= 1250;
- if ( value < wxFONTENCODING_CP12_MAX -
- wxFONTENCODING_CP1250 )
- {
- // a valid Windows code page
- value += wxFONTENCODING_CP1250;
- encoding = (wxFontEncoding)value;
- }
- }
- }
- }
- //else: unknown
- }
-
-#if wxUSE_GUI
- // if still no luck, ask the user - unless disabled
- if ( (encoding == wxFONTENCODING_SYSTEM) && interactive )