[empathy: 12/28] Utility to set the webkit default font/size from GSettings
- From: Danielle Madeley <daniellem src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy: 12/28] Utility to set the webkit default font/size from GSettings
- Date: Thu, 18 Aug 2011 00:35:48 +0000 (UTC)
commit 3b97f8064e775fd770188b4f186da95706e205f8
Author: Danielle Madeley <danielle madeley collabora co uk>
Date: Tue Aug 9 11:40:53 2011 +1000
Utility to set the webkit default font/size from GSettings
libempathy-gtk/empathy-webkit-utils.c | 73 +++++++++++++++++++++++++++++++++
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 e5d163a..827d57e 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 38cbfed..5ba0a84 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]