X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/23afe648cebb471ce620528fbeb8bfd2f25849fc..77f4f0a700031e1c1fa4ece26df44f3af49b7545:/src/unix/fontutil.cpp diff --git a/src/unix/fontutil.cpp b/src/unix/fontutil.cpp index ddbf06d0cf..082ce17f8b 100644 --- a/src/unix/fontutil.cpp +++ b/src/unix/fontutil.cpp @@ -29,6 +29,7 @@ #endif #ifndef WX_PRECOMP + #include "wx/font.h" // wxFont enums #include "wx/encinfo.h" #endif // PCH @@ -63,10 +64,10 @@ wxNativeFontInfo::Init(const wxNativeFontInfo& info) if (info.description) description = pango_font_description_copy(info.description); else - description = NULL; + description = NULL; } -wxNativeFontInfo::Free() +void wxNativeFontInfo::Free() { if (description) pango_font_description_free(description); @@ -99,31 +100,27 @@ wxFontStyle wxNativeFontInfo::GetStyle() const wxFontWeight wxNativeFontInfo::GetWeight() const { - wxFontWeight m_weight = wxFONTWEIGHT_NORMAL; +#if 0 + // We seem to currently initialize only by string. + // In that case PANGO_FONT_MASK_WEIGHT is always set. + if (!(pango_font_description_get_set_fields(description) & PANGO_FONT_MASK_WEIGHT)) + return wxFONTWEIGHT_NORMAL; +#endif - switch (pango_font_description_get_weight( description )) - { - case PANGO_WEIGHT_ULTRALIGHT: - m_weight = wxFONTWEIGHT_LIGHT; - break; - case PANGO_WEIGHT_LIGHT: - m_weight = wxFONTWEIGHT_LIGHT; - break; - case PANGO_WEIGHT_NORMAL: - m_weight = wxFONTWEIGHT_NORMAL; - break; - case PANGO_WEIGHT_BOLD: - m_weight = wxFONTWEIGHT_BOLD; - break; - case PANGO_WEIGHT_ULTRABOLD: - m_weight = wxFONTWEIGHT_BOLD; - break; - case PANGO_WEIGHT_HEAVY: - m_weight = wxFONTWEIGHT_BOLD; - break; - } + PangoWeight pango_weight = pango_font_description_get_weight( description ); + + // Until the API can be changed the following ranges of weight values are used: + // wxFONTWEIGHT_LIGHT: 100 .. 349 - range of 250 + // wxFONTWEIGHT_NORMAL: 350 .. 599 - range of 250 + // wxFONTWEIGHT_BOLD: 600 .. 900 - range of 301 (600 is "semibold" already) - return m_weight; + if (pango_weight >= 600) + return wxFONTWEIGHT_BOLD; + + if (pango_weight < 350) + return wxFONTWEIGHT_LIGHT; + + return wxFONTWEIGHT_NORMAL; } bool wxNativeFontInfo::GetUnderlined() const @@ -237,7 +234,17 @@ bool wxTestFontEncoding(const wxNativeEncodingInfo& info) bool wxGetNativeFontEncoding(wxFontEncoding encoding, wxNativeEncodingInfo *info) { - return FALSE; + // we *must* return true for default encoding as otherwise wxFontMapper + // considers that we can't load any font and aborts with wxLogFatalError! + if ( encoding == wxFONTENCODING_SYSTEM ) + { + info->facename.clear(); + info->encoding = wxFONTENCODING_SYSTEM; + } + + // pretend that we support everything, it's better than to always return + // false as the old code did + return true; } #else // GTK+ 1.x @@ -725,7 +732,7 @@ bool wxGetNativeFontEncoding(wxFontEncoding encoding, break; case wxFONTENCODING_GB2312: - info->xregistry = wxT("GB2312"); // or the otherway round? + info->xregistry = wxT("GB2312"); // or the otherway round? info->xencoding = wxT("*"); break;