diff options
author | Gabriel Ivascu <gabrielivascu@gnome.org> | 2017-11-01 16:32:03 +0200 |
---|---|---|
committer | Gabriel Ivascu <gabrielivascu@gnome.org> | 2017-11-01 16:47:53 +0200 |
commit | d76120a64a2566f86e2bfe47b5a52106c18754ef (patch) | |
tree | 3d4a1679c8f762c5ac1e27dbcf22e03aaa7b3e1b | |
parent | 55c9ec60b44b2c5232a383ed5fdc2f9db127ac00 (diff) | |
download | epiphany-wip/auto-font-size.tar.gz |
embed-prefs: Start using WebKit's new font size propertieswip/auto-font-size
Replace the old font size properties in pixels with the new properties
in points that automatically scale the text when the screen DPI changes.
-rw-r--r-- | embed/ephy-embed-prefs.c | 83 | ||||
-rw-r--r-- | meson.build | 2 |
2 files changed, 11 insertions, 74 deletions
diff --git a/embed/ephy-embed-prefs.c b/embed/ephy-embed-prefs.c index 951756d2d..b4f4ce25e 100644 --- a/embed/ephy-embed-prefs.c +++ b/embed/ephy-embed-prefs.c @@ -29,8 +29,6 @@ #include "ephy-settings.h" #include "ephy-user-agent.h" -#include <math.h> - typedef struct { const char *schema; const char *key; @@ -128,41 +126,6 @@ webkit_pref_callback_user_agent (GSettings *settings, g_free (user_agent); } -static gdouble -get_screen_dpi (GdkScreen *screen) -{ - gdouble dpi; - gdouble dp, di; - - dpi = gdk_screen_get_resolution (screen); - if (dpi != -1) - return dpi; - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - dp = hypot (gdk_screen_get_width (screen), gdk_screen_get_height (screen)); - di = hypot (gdk_screen_get_width_mm (screen), gdk_screen_get_height_mm (screen)) / 25.4; -#pragma GCC diagnostic pop - - return dp / di; -} - -static guint -normalize_font_size (gdouble font_size) -{ - /* WebKit2 uses font sizes in pixels. */ - GdkScreen *screen; - gdouble dpi; - - /* FIXME: We should use the view screen instead of the detault one - * but we don't have access to the view here. - */ - screen = gdk_screen_get_default (); - dpi = screen ? get_screen_dpi (screen) : 96; - - return font_size / 72.0 * dpi; -} - static void webkit_pref_callback_font_size (GSettings *settings, const char *key, @@ -196,7 +159,7 @@ webkit_pref_callback_font_size (GSettings *settings, pango_font_description_free (desc); } - g_object_set (webkit_settings, webkit_pref, normalize_font_size (size), NULL); + g_object_set (webkit_settings, webkit_pref, size, NULL); g_free (value); } @@ -348,22 +311,24 @@ webkit_pref_callback_cookie_accept_policy (GSettings *settings, } static void -ephy_embed_prefs_update_font_settings (GSettings *ephy_settings, const char *key) +webkit_pref_callback_gnome_fonts (GSettings *ephy_settings, + const char *key, + gpointer data) { if (g_settings_get_boolean (ephy_settings, key)) { g_object_set (webkit_settings, "default-font-family", "serif", "sans-serif-font-family", "sans-serif", "monospace-font-family", "monospace", - "default-font-size", normalize_font_size (12), - "default-monospace-font-size", normalize_font_size (10), + "default-font-size-pts", 12, + "default-monospace-font-size-pts", 10, NULL); } else { /* Sync with Epiphany values */ webkit_pref_callback_font_size (ephy_settings, EPHY_PREFS_WEB_SERIF_FONT, - (gpointer)"default-font-size"); + (gpointer)"default-font-size-pts"); webkit_pref_callback_font_size (ephy_settings, EPHY_PREFS_WEB_MONOSPACE_FONT, - (gpointer)"default-monospace-font-size"); + (gpointer)"default-monospace-font-size-pts"); webkit_pref_callback_font_family (ephy_settings, EPHY_PREFS_WEB_SERIF_FONT, (gpointer)"default-font-family"); @@ -377,14 +342,6 @@ ephy_embed_prefs_update_font_settings (GSettings *ephy_settings, const char *key } static void -webkit_pref_callback_gnome_fonts (GSettings *ephy_settings, - const char *key, - gpointer data) -{ - ephy_embed_prefs_update_font_settings (ephy_settings, key); -} - -static void webkit_pref_callback_enable_spell_checking (GSettings *settings, const char *key, gpointer data) @@ -409,25 +366,16 @@ webkit_pref_callback_enable_spell_checking (GSettings *settings, } } -static void -gtk_settings_xft_dpi_changed_cb (GtkSettings *gtk_settings, - GParamSpec *pspec, - gpointer data) -{ - GSettings *gsettings = ephy_settings_get (EPHY_PREFS_WEB_SCHEMA); - ephy_embed_prefs_update_font_settings (gsettings, EPHY_PREFS_WEB_USE_GNOME_FONTS); -} - static const PrefData webkit_pref_entries[] = { /* Epiphany font settings */ { EPHY_PREFS_WEB_SCHEMA, EPHY_PREFS_WEB_SERIF_FONT, - "default-font-size", + "default-font-size-pts", webkit_pref_callback_font_size }, { EPHY_PREFS_WEB_SCHEMA, EPHY_PREFS_WEB_MONOSPACE_FONT, - "default-monospace-font-size", + "default-monospace-font-size-pts", webkit_pref_callback_font_size }, { EPHY_PREFS_WEB_SCHEMA, EPHY_PREFS_WEB_SERIF_FONT, @@ -477,7 +425,6 @@ static const PrefData webkit_pref_entries[] = static gpointer ephy_embed_prefs_init (gpointer user_data) { - GtkSettings *gtk_settings; guint i; webkit_settings = webkit_settings_new_with_settings ("enable-developer-extras", TRUE, @@ -504,16 +451,6 @@ ephy_embed_prefs_init (gpointer user_data) g_free (key); } - /* Connect to the "notify::gtk-xft-dpi" signal for GtkSettings, so that - * we can update the font size in real time if the screen's resolution - * for font handling changes (e.g. enabled "Large Text" a11y mode). - */ - gtk_settings = gtk_settings_get_default (); - if (gtk_settings) { - g_signal_connect (gtk_settings, "notify::gtk-xft-dpi", - G_CALLBACK (gtk_settings_xft_dpi_changed_cb), NULL); - } - g_settings_bind (EPHY_SETTINGS_MAIN, EPHY_PREFS_ENABLE_CARET_BROWSING, webkit_settings, "enable-caret-browsing", diff --git a/meson.build b/meson.build index e836e2854..f04132fe7 100644 --- a/meson.build +++ b/meson.build @@ -44,7 +44,7 @@ configure_file( glib_requirement = '>= 2.52.0' gtk_requirement = '>= 3.22.13' nettle_requirement = '>= 3.2' -webkitgtk_requirement = '>= 2.19.1' +webkitgtk_requirement = '>= 2.19.2' cairo_dep = dependency('cairo', version: '>= 1.2') gcr_dep = dependency('gcr-3', version: '>= 3.5.5') |