[epiphany/wip/auto-font-size] embed-prefs: Start using WebKit's new font size properties



commit 4eb800893962a87d66bf6e340418814275649d50
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date:   Wed Nov 1 16:32:03 2017 +0200

    embed-prefs: Start using WebKit's new font size properties
    
    Replace the old font size properties in pixels with the new properties
    in points that automatically scale the text when the screen DPI changes.

 embed/ephy-embed-prefs.c |   83 +++++----------------------------------------
 1 files changed, 10 insertions(+), 73 deletions(-)
---
diff --git a/embed/ephy-embed-prefs.c b/embed/ephy-embed-prefs.c
index 951756d..b4f4ce2 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",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]