bool wxFontEnumerator::EnumerateEncodings(const wxString& family) { #if wxUSE_NANOX return false; #else wxString pattern; pattern.Printf(wxT("-*-%s-*-*-*-*-*-*-*-*-*-*-*-*"), family.empty() ? wxT("*") : family.c_str()); // get the list of all fonts int nFonts; char **fonts = XListFonts((Display *)wxGetDisplay(), pattern.mb_str(), 32767, &nFonts); if ( !fonts ) { // unknown family? return false; } // extract the list of (unique) encodings wxSortedArrayString encodings; for ( int n = 0; n < nFonts; n++ ) { char *font = fonts[n]; if ( !wxString(font).Matches(wxT("-*-*-*-*-*-*-*-*-*-*-*-*-*-*")) ) { // it's not a full font name (probably an alias) continue; } // extract the family char *dash = strchr(font + 1, '-'); char *familyFont = dash + 1; dash = strchr(familyFont, '-'); *dash = '\0'; // !NULL because Matches() above succeeded if ( !family.empty() && (family != familyFont) ) { // family doesn't match continue; } // now extract the registry/encoding char *p = dash + 1; // just after the dash after family dash = strrchr(p, '-'); wxString registry(dash + 1); *dash = '\0'; dash = strrchr(p, '-'); wxString encoding(dash + 1); encoding << wxT('-') << registry; if ( encodings.Index(encoding) == wxNOT_FOUND ) { if ( !OnFontEncoding(familyFont, encoding) ) { break; } encodings.Add(encoding); } //else: already had this one } XFreeFontNames(fonts); return true; #endif // wxUSE_NANOX }
bool wxFontEnumerator::EnumerateEncodings(const wxString& family) { static wxFontEncoding encodings[] = { wxFONTENCODING_ISO8859_1, wxFONTENCODING_ISO8859_2, wxFONTENCODING_ISO8859_3, wxFONTENCODING_ISO8859_4, wxFONTENCODING_ISO8859_5, wxFONTENCODING_ISO8859_6, wxFONTENCODING_ISO8859_7, wxFONTENCODING_ISO8859_8, wxFONTENCODING_ISO8859_9, wxFONTENCODING_ISO8859_10, //wxFONTENCODING_ISO8859_11, //wxFONTENCODING_ISO8859_12, wxFONTENCODING_ISO8859_13, wxFONTENCODING_ISO8859_14, wxFONTENCODING_ISO8859_15, wxFONTENCODING_CP1250, wxFONTENCODING_CP1251, wxFONTENCODING_CP1252, wxFONTENCODING_CP1253, wxFONTENCODING_CP1254, wxFONTENCODING_CP1255, wxFONTENCODING_CP1256, wxFONTENCODING_CP1257, wxFONTENCODING_KOI8, wxFONTENCODING_SYSTEM }; static const char *encodingNames[] = { "iso88590-1", "iso88590-2", "iso88590-3", "iso88590-4", "iso88590-5", "iso88590-6", "iso88590-7", "iso88590-8", "iso88590-9", "iso88590-10", "iso88590-13", "iso88590-14", "iso88590-15", "windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "windows-1255", "windows-1256", "windows-1257", "koi-8", NULL }; wxNativeEncodingInfo info; info.facename = family; for (size_t i = 0; encodings[i] != wxFONTENCODING_SYSTEM; i++) { if ( !wxGetNativeFontEncoding(encodings[i], &info) || !wxTestFontEncoding(info) ) continue; if ( !OnFontEncoding(family, encodingNames[i]) ) break; } return true; }