[devhelp/wip/webkit-font-size: 53/54] WebKit automatically updates font size on DPI change now



commit 0bac226665a8eeeed7a5e67dabda894f25a77ede
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date:   Tue Nov 21 23:13:39 2017 +0200

    WebKit automatically updates font size on DPI change now
    
    This was introduced in WebKitGTK+ 2.19.2.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790680

 src/dh-util.c   |   46 ++------------------------
 src/dh-window.c |   97 -------------------------------------------------------
 2 files changed, 4 insertions(+), 139 deletions(-)
---
diff --git a/src/dh-util.c b/src/dh-util.c
index da16361..81860db 100644
--- a/src/dh-util.c
+++ b/src/dh-util.c
@@ -111,44 +111,6 @@ dh_util_create_data_uri_for_filename (const gchar *filename,
         return uri;
 }
 
-static gdouble
-get_screen_dpi (GdkScreen *screen)
-{
-        GtkSettings *settings = NULL;
-        gdouble dpi = -1;
-        gdouble dp, di;
-        gint gtk_xft_dpi;
-
-        settings = gtk_settings_get_for_screen (screen);
-        if (settings != NULL) {
-                g_object_get (settings, "gtk-xft-dpi", &gtk_xft_dpi, NULL);
-                dpi = (gtk_xft_dpi != -1) ? gtk_xft_dpi / 1024.0 : -1;
-        }
-
-        if (dpi != -1)
-                return dpi;
-
-        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;
-
-        return dp / di;
-}
-
-static guint
-convert_font_size_to_pixels (GtkWidget *widget,
-                             gdouble    font_size)
-{
-        GdkScreen *screen;
-        gdouble    dpi;
-
-        /* WebKit2 uses font sizes in pixels */
-        screen = gtk_widget_has_screen (widget) ?
-                gtk_widget_get_screen (widget) : gdk_screen_get_default ();
-        dpi = screen ? get_screen_dpi (screen) : 96;
-
-        return font_size / 72.0 * dpi;
-}
-
 /* set the given fonts on the given view */
 void
 dh_util_view_set_font (WebKitWebView *view, const gchar *font_name_fixed, const gchar *font_name_variable)
@@ -156,10 +118,10 @@ dh_util_view_set_font (WebKitWebView *view, const gchar *font_name_fixed, const
         /* get the font size */
         PangoFontDescription *font_desc_fixed = pango_font_description_from_string (font_name_fixed);
         PangoFontDescription *font_desc_variable = pango_font_description_from_string (font_name_variable);
-        gdouble font_size_fixed = (double)pango_font_description_get_size (font_desc_fixed) / PANGO_SCALE;
-        gdouble font_size_variable = (double)pango_font_description_get_size (font_desc_variable) / 
PANGO_SCALE;
-        guint font_size_fixed_px = convert_font_size_to_pixels (GTK_WIDGET (view), font_size_fixed);
-        guint font_size_variable_px = convert_font_size_to_pixels (GTK_WIDGET (view), font_size_variable);
+        guint font_size_fixed = pango_font_description_get_size (font_desc_fixed) / PANGO_SCALE;
+        guint font_size_variable = pango_font_description_get_size (font_desc_variable) / PANGO_SCALE;
+        guint font_size_fixed_px = webkit_settings_font_size_to_pixels (font_size_fixed);
+        guint font_size_variable_px = webkit_settings_font_size_to_pixels (font_size_variable);
 
         pango_font_description_free (font_desc_fixed);
         pango_font_description_free (font_desc_variable);
diff --git a/src/dh-window.c b/src/dh-window.c
index 45987be..77d282d 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -48,9 +48,7 @@ typedef struct {
         GtkButton      *go_down_button;
 
         DhLink         *selected_search_link;
-        GtkSettings    *gtk_settings;
         guint           configure_id;
-        gulong          xft_dpi_changed_id;
 } DhWindowPrivate;
 
 enum {
@@ -574,86 +572,6 @@ settings_fonts_changed_cb (DhSettings  *settings,
         }
 }
 
-static void
-update_fonts_on_dpi_change (DhWindow *window)
-{
-        DhWindowPrivate *priv;
-        DhSettings *settings;
-        gchar *font_fixed = NULL;
-        gchar *font_variable = NULL;
-        WebKitWebView *view;
-        gint i;
-
-        priv = dh_window_get_instance_private (window);
-
-        settings = dh_settings_get_singleton ();
-        dh_settings_get_selected_fonts (settings, &font_fixed, &font_variable);
-
-        if (font_fixed != NULL && font_variable != NULL) {
-                /* change font for all pages */
-                for (i = 0; i < gtk_notebook_get_n_pages (priv->notebook); i++) {
-                        GtkWidget *page = gtk_notebook_get_nth_page (priv->notebook, i);
-                        view = WEBKIT_WEB_VIEW (g_object_get_data (G_OBJECT (page), "web_view"));
-                        dh_util_view_set_font (view, font_fixed, font_variable);
-                }
-        }
-
-        g_free (font_fixed);
-        g_free (font_variable);
-}
-
-static void
-gtk_xft_dpi_changed_cb (GtkSettings *gtk_settings,
-                        GParamSpec  *pspec,
-                        gpointer     user_data)
-{
-        DhWindow *window = DH_WINDOW (user_data);
-        update_fonts_on_dpi_change (window);
-}
-
-/* Monitor GdkScreen and GtkSettings for DPI changes. */
-static void
-dh_window_screen_changed (GtkWidget *window,
-                          GdkScreen *previous_screen)
-{
-        DhWindow *dh_window = DH_WINDOW(window);
-        DhWindowPrivate *priv = dh_window_get_instance_private (dh_window);
-        GtkSettings *previous_settings = gtk_settings_get_for_screen (previous_screen);
-        GtkSettings *current_settings = gtk_widget_get_settings (window);
-
-        /* If the screen has changed we need to re-retrieve the GtkSettings object,
-         * and disconnect the old signal handlers before re-connecting again.
-         */
-        if (current_settings != previous_settings) {
-                if (priv->xft_dpi_changed_id != 0) {
-                        if (priv->gtk_settings != NULL &&
-                            g_signal_handler_is_connected (priv->gtk_settings, priv->xft_dpi_changed_id))
-                                g_signal_handler_disconnect (priv->gtk_settings, priv->xft_dpi_changed_id);
-                        priv->xft_dpi_changed_id = 0;
-                }
-
-                priv->gtk_settings = NULL;
-        }
-
-        /* Now store the new GtkSettings and (re)connect the signals if needed. */
-        if (priv->gtk_settings == NULL) {
-                GdkScreen *screen = gtk_widget_get_screen (window);
-                priv->gtk_settings = gtk_settings_get_for_screen (screen);
-                priv->xft_dpi_changed_id =
-                        g_signal_connect (priv->gtk_settings,
-                                          "notify::gtk-xft-dpi",
-                                          G_CALLBACK (gtk_xft_dpi_changed_cb),
-                                          window);
-
-        }
-
-        update_fonts_on_dpi_change (dh_window);
-
-        if (GTK_WIDGET_CLASS (dh_window_parent_class)->screen_changed != NULL)
-                GTK_WIDGET_CLASS (dh_window_parent_class)->screen_changed (window,
-                                                                           previous_screen);
-}
-
 /* FIXME: this is a bit complicated just for saving the window state.
  * Implement something (hopefully) simpler, by saving the GSettings only when
  * needed:
@@ -759,13 +677,6 @@ dh_window_init (DhWindow *window)
                                  window,
                                  0);
 
-        /* we can't get the GdkScreen for the widget here, so get the
-         * GtkSettings associated to the default one instead for now */
-        priv->gtk_settings = gtk_settings_get_default ();
-        priv->xft_dpi_changed_id =
-                g_signal_connect (priv->gtk_settings, "notify::gtk-xft-dpi",
-                                  G_CALLBACK (gtk_xft_dpi_changed_cb), window);
-
         g_action_map_add_action_entries (G_ACTION_MAP (window),
                                          win_entries, G_N_ELEMENTS (win_entries),
                                          window);
@@ -797,13 +708,6 @@ dh_window_dispose (GObject *object)
                 priv->configure_id = 0;
         }
 
-        if (priv->xft_dpi_changed_id != 0) {
-                if (priv->gtk_settings != NULL &&
-                    g_signal_handler_is_connected (priv->gtk_settings, priv->xft_dpi_changed_id))
-                        g_signal_handler_disconnect (priv->gtk_settings, priv->xft_dpi_changed_id);
-                priv->xft_dpi_changed_id = 0;
-        }
-
         G_OBJECT_CLASS (dh_window_parent_class)->dispose (object);
 }
 
@@ -815,7 +719,6 @@ dh_window_class_init (DhWindowClass *klass)
 
         object_class->dispose = dh_window_dispose;
 
-        widget_class->screen_changed = dh_window_screen_changed;
         widget_class->configure_event = dh_window_configure_event;
         widget_class->delete_event = dh_window_delete_event;
 


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