// 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;
encoding = (wxFontEncoding)value;
}
}
}
else if ( cs.Left(4) == wxT("8859") )
{
const wxChar *p = cs.c_str();
unsigned int value;
if ( wxSscanf(p, wxT("8859-%u"), &value) == 1 )
{
// printf( "value %d\n", (int)value );
// 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;
encoding = (wxFontEncoding)value;
}
}
}
else // check for Windows charsets
{
size_t len;
if ( cs.Left(7) == wxT("WINDOWS") )
{
len = 7;
}
else if ( cs.Left(2) == wxT("CP") )
{
len = 2;
}
else // not a Windows encoding
{
len = 0;
}
if ( len )
{
const wxChar *p = cs.c_str() + len;
if ( *p == wxT('-') )
p++;
int value;
if ( wxSscanf(p, 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;
}
}
switch ( value )
{
case 932:
encoding = wxFONTENCODING_CP932;
break;
case 936:
encoding = wxFONTENCODING_CP936;
break;
case 949:
encoding = wxFONTENCODING_CP949;
break;
case 950:
encoding = wxFONTENCODING_CP950;
break;
}
}
}
}
//else: unknown
}
#if wxUSE_GUI
// if still no luck, ask the user - unless disabled
if ( (encoding == wxFONTENCODING_SYSTEM) && interactive )
{
// prepare the dialog data
// the dialog title
wxString title(m_titleDialog);
if ( !title )
title << wxTheApp->GetAppName() << _(": unknown charset");
// the message
wxString msg;
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());
// the list of choices
const size_t count = WXSIZEOF(gs_encodingDescs);
wxString *encodingNamesTranslated = new wxString[count];
// ask the user if he wants to override found alternative encoding
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)?"),
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)?"),
encDesc.c_str());
}
// the question is different in 2 cases so the answer has to be
// interpreted differently as well
int answer = foundEquivEncoding ? wxNO : wxYES;
if ( wxMessageBox(msg, title,
wxICON_QUESTION | wxYES_NO,
m_windowParent) == answer )
{
wxFontData data;
data.SetEncoding(encoding);
data.EncodingInfo() = *info;
wxFontDialog dialog(m_windowParent, data);
if ( dialog.ShowModal() == wxID_OK )
{
wxFontData retData = dialog.GetFontData();
wxFont font = retData.GetChosenFont();
*info = retData.EncodingInfo();
info->encoding = retData.GetEncoding();
#if wxUSE_CONFIG
// remember this in the config
if ( ChangePath(FONTMAPPER_FONT_FROM_ENCODING_PATH, &pathOld) )