]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/fontutil.cpp
Updated info about missing parts in OW headers (now reported and fixed for incoming...
[wxWidgets.git] / src / unix / fontutil.cpp
index 09c673e0c225ac4bf17f4544698c6cfc4fef3d4b..082ce17f8b63ef5751db96e750f99a87a7606b0b 100644 (file)
@@ -29,6 +29,7 @@
 #endif
 
 #ifndef WX_PRECOMP
+    #include "wx/font.h" // wxFont enums
     #include "wx/encinfo.h"
 #endif // PCH
 
@@ -57,6 +58,21 @@ void wxNativeFontInfo::Init()
     description = NULL;
 }
 
+void
+wxNativeFontInfo::Init(const wxNativeFontInfo& info)
+{
+    if (info.description)
+        description = pango_font_description_copy(info.description);
+    else
+        description = NULL;
+}
+
+void wxNativeFontInfo::Free()
+{
+    if (description)
+        pango_font_description_free(description);
+}
+
 int wxNativeFontInfo::GetPointSize() const
 {
     return pango_font_description_get_size( description ) / PANGO_SCALE;
@@ -84,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)
+
+    if (pango_weight >= 600)
+        return wxFONTWEIGHT_BOLD;
+
+    if (pango_weight < 350)
+        return wxFONTWEIGHT_LIGHT;
 
-    return m_weight;
+    return wxFONTWEIGHT_NORMAL;
 }
 
 bool wxNativeFontInfo::GetUnderlined() const
@@ -222,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
@@ -710,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;