diff options
-rw-r--r-- | libempathy-gtk/empathy-webkit-utils.c | 73 | ||||
-rw-r--r-- | libempathy-gtk/empathy-webkit-utils.h | 4 |
2 files changed, 77 insertions, 0 deletions
diff --git a/libempathy-gtk/empathy-webkit-utils.c b/libempathy-gtk/empathy-webkit-utils.c index e5d163ae2..827d57e6b 100644 --- a/libempathy-gtk/empathy-webkit-utils.c +++ b/libempathy-gtk/empathy-webkit-utils.c @@ -21,6 +21,8 @@ #include "empathy-webkit-utils.h" #include "empathy-smiley-manager.h" +#define BORING_DPI_DEFAULT 96 + static void empathy_webkit_match_newline (const gchar *text, gssize len, @@ -89,3 +91,74 @@ empathy_webkit_get_string_parser (gboolean smileys) else return string_parsers; } + +static gboolean +webkit_get_font_family (GValue *value, + GVariant *variant, + gpointer user_data) +{ + PangoFontDescription *font = pango_font_description_from_string ( + g_variant_get_string (variant, NULL)); + + if (font == NULL) + return FALSE; + + g_value_set_string (value, pango_font_description_get_family (font)); + pango_font_description_free (font); + + return TRUE; +} + +static gboolean +webkit_get_font_size (GValue *value, + GVariant *variant, + gpointer user_data) +{ + PangoFontDescription *font = pango_font_description_from_string ( + g_variant_get_string (variant, NULL)); + int size; + + if (font == NULL) + return FALSE; + + size = pango_font_description_get_size (font) / PANGO_SCALE; + + if (pango_font_description_get_size_is_absolute (font)) + { + GdkScreen *screen = gdk_screen_get_default (); + double dpi; + + if (screen != NULL) + dpi = gdk_screen_get_resolution (screen); + else + dpi = BORING_DPI_DEFAULT; + + size = (gint) (size / (dpi / 72)); + } + + g_value_set_int (value, size); + pango_font_description_free (font); + + return TRUE; +} + +void +empathy_webkit_bind_font_setting (WebKitWebView *webview, + GSettings *gsettings, + const char *key) +{ + WebKitWebSettings *settings = webkit_web_view_get_settings (webview); + + g_settings_bind_with_mapping (gsettings, key, + settings, "default-font-family", + G_SETTINGS_BIND_GET, + webkit_get_font_family, + NULL, + NULL, NULL); + g_settings_bind_with_mapping (gsettings, key, + settings, "default-font-size", + G_SETTINGS_BIND_GET, + webkit_get_font_size, + NULL, + NULL, NULL); +} diff --git a/libempathy-gtk/empathy-webkit-utils.h b/libempathy-gtk/empathy-webkit-utils.h index 38cbfedcb..5ba0a840a 100644 --- a/libempathy-gtk/empathy-webkit-utils.h +++ b/libempathy-gtk/empathy-webkit-utils.h @@ -21,11 +21,15 @@ #ifndef _EMPATHY_WEBKIT_UTILS__H_ #define _EMPATHY_WEBKIT_UTILS__H_ +#include <webkit/webkit.h> + #include "empathy-string-parser.h" G_BEGIN_DECLS EmpathyStringParser *empathy_webkit_get_string_parser (gboolean smileys); +void empathy_webkit_bind_font_setting (WebKitWebView *webview, + GSettings *gsettings, const char *key); G_END_DECLS |