X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7018409531500bd1850c1ab3f0107007802bbc5a..716cd4107bb8a5f37dea34507453be6870aaef3a:/src/common/fontmap.cpp?ds=sidebyside diff --git a/src/common/fontmap.cpp b/src/common/fontmap.cpp index d5b410beb1..c63b9af1c4 100644 --- a/src/common/fontmap.cpp +++ b/src/common/fontmap.cpp @@ -58,8 +58,11 @@ static const wxChar* FONTMAPPER_ROOT_PATH = wxT("/wxWindows/FontMapper"); static const wxChar* FONTMAPPER_CHARSET_PATH = wxT("Charsets"); static const wxChar* FONTMAPPER_CHARSET_ALIAS_PATH = wxT("Aliases"); + +// we only ask questions in GUI mode #if wxUSE_GUI static const wxChar* FONTMAPPER_FONT_FROM_ENCODING_PATH = wxT("Encodings"); + static const wxChar* FONTMAPPER_FONT_DONT_ASK = wxT("none"); #endif // wxUSE_GUI // encodings supported by GetEncodingDescription @@ -467,11 +470,14 @@ wxFontEncoding wxFontMapper::CharsetToEncoding(const wxString& charset, unsigned int value; if ( wxSscanf(p, wxT("8859-%u"), &value) == 1 ) { - if ( value < wxFONTENCODING_ISO8859_MAX - - wxFONTENCODING_ISO8859_1 ) + // make it 0 based and check that it is strictly positive in + // the process (no such thing as iso8859-0 encoding) + if ( (value-- > 0) && + (value < wxFONTENCODING_ISO8859_MAX - + wxFONTENCODING_ISO8859_1) ) { // it's a valid ISO8859 encoding - value += wxFONTENCODING_ISO8859_1 - 1; + value += wxFONTENCODING_ISO8859_1; encoding = (wxFontEncoding)value; } } @@ -689,29 +695,41 @@ bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding, RestorePath(pathOld); - if ( !!fontinfo && !!facename ) + // this special value means that we don't know of fonts for this + // encoding but, moreover, have already asked the user as well and he + // didn't specify any font neither + if ( fontinfo == FONTMAPPER_FONT_DONT_ASK ) { - // we tried to find a match with facename - now try without it - fontinfo = config->Read(encName); + interactive = FALSE; } - - if ( !!fontinfo ) + else // use the info entered the last time { - if ( info->FromString(fontinfo) ) + if ( !!fontinfo && !!facename ) { - if ( wxTestFontEncoding(*info) ) - { - // ok, got something - return TRUE; - } - //else: no such fonts, look for something else + // we tried to find a match with facename - now try without it + fontinfo = config->Read(encName); } - else + + if ( !!fontinfo ) { - wxLogDebug(wxT("corrupted config data: string '%s' is not a valid font encoding info"), fontinfo.c_str()); + if ( info->FromString(fontinfo) ) + { + if ( wxTestFontEncoding(*info) ) + { + // ok, got something + return TRUE; + } + //else: no such fonts, look for something else + // (should we erase the outdated value?) + } + else + { + wxLogDebug(wxT("corrupted config data: string '%s' is not a valid font encoding info"), + fontinfo.c_str()); + } } + //else: there is no information in config about this encoding } - //else: there is no information in config about this encoding } #endif // wxUSE_CONFIG @@ -724,7 +742,7 @@ bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding, // the message wxString msg; - 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)?"), + 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)?"), GetEncodingDescription(encoding).c_str()); wxWindow *parent = m_windowParent; @@ -747,7 +765,7 @@ bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding, info -> encoding = retData.GetEncoding(); #if wxUSE_CONFIG - // remember this in the config + // remember this in the config if ( ChangePath(FONTMAPPER_FONT_FROM_ENCODING_PATH, &pathOld) ) { GetConfig()->Write(configEntry, info->ToString()); @@ -760,7 +778,19 @@ bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding, } //else: the user canceled the font selection dialog } - //else: the user doesn't want to select a font + else + { + // the user doesn't want to select a font for this encoding, + // remember it to avoid asking the same question again later +#if wxUSE_CONFIG + if ( ChangePath(FONTMAPPER_FONT_FROM_ENCODING_PATH, &pathOld) ) + { + GetConfig()->Write(configEntry, FONTMAPPER_FONT_DONT_ASK); + + RestorePath(pathOld); + } +#endif // wxUSE_CONFIG + } } //else: we're in non-interactive mode