[evince/wip/hidpi: 4/4] EvSidebarThumbnails: render thumbnails correctly for hi-dpi displays



commit c2d93e623f91619b6cc79c863fa11a5a073ab09c
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Thu Apr 10 10:18:07 2014 -0700

    EvSidebarThumbnails: render thumbnails correctly for hi-dpi displays
    
    Render thumbnails with resolution from gtk_widget_get_scale_factor() and
    recreate them when the scale change. Make the thumbnail-rendering helper
    functions create a hi-resolution surface when the widget has a scale
    factor.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723431

 libdocument/ev-document-misc.c |   12 +++++++++++-
 shell/ev-sidebar-thumbnails.c  |   15 +++++++++++++++
 2 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/libdocument/ev-document-misc.c b/libdocument/ev-document-misc.c
index 4c3b54f..d04ce89 100644
--- a/libdocument/ev-document-misc.c
+++ b/libdocument/ev-document-misc.c
@@ -140,6 +140,7 @@ ev_document_misc_render_thumbnail_frame (GtkWidget       *widget,
         int              width_f, height_f;
         cairo_surface_t *surface;
         cairo_t         *cr;
+       int              device_scale;
         GtkBorder        border = {0, };
 
         if (source_surface) {
@@ -165,8 +166,17 @@ ev_document_misc_render_thumbnail_frame (GtkWidget       *widget,
         width_f = width_r + border.left + border.right;
         height_f = height_r + border.top + border.bottom;
 
+#ifdef HAVE_HIDPI_SUPPORT
+        device_scale = gtk_widget_get_scale_factor (widget);
+#else
+        device_scale = 1;
+#endif
         surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
-                                              width_f, height_f);
+                                              device_scale * width_f, device_scale * height_f);
+
+#ifdef HAVE_HIDPI_SUPPORT
+        cairo_surface_set_device_scale (surface, device_scale, device_scale);
+#endif
 
         cr = cairo_create (surface);
         if (source_surface) {
diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c
index 65703e0..dc30a4e 100644
--- a/shell/ev-sidebar-thumbnails.c
+++ b/shell/ev-sidebar-thumbnails.c
@@ -102,6 +102,7 @@ static void         ev_sidebar_thumbnails_set_current_page (EvSidebarThumbnails
                                                            gint     page);
 static void         thumbnail_job_completed_callback       (EvJobThumbnail          *job,
                                                            EvSidebarThumbnails     *sidebar_thumbnails);
+static void         ev_sidebar_thumbnails_reload           (EvSidebarThumbnails     *sidebar_thumbnails);
 static void         adjustment_changed_cb                  (EvSidebarThumbnails     *sidebar_thumbnails);
 
 G_DEFINE_TYPE_EXTENDED (EvSidebarThumbnails, 
@@ -616,6 +617,17 @@ adjustment_changed_cb (EvSidebarThumbnails *sidebar_thumbnails)
 }
 
 static void
+notify_scale_factor_cb (GtkWidget  *widget,
+                        GParamSpec *pspec)
+{
+       EvSidebarThumbnails *sidebar_thumbnails = EV_SIDEBAR_THUMBNAILS (widget);
+       EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
+
+       g_hash_table_remove_all (priv->loading_icons);
+       ev_sidebar_thumbnails_reload (sidebar_thumbnails);
+}
+
+static void
 ev_sidebar_thumbnails_fill_model (EvSidebarThumbnails *sidebar_thumbnails)
 {
        EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
@@ -802,6 +814,9 @@ ev_sidebar_thumbnails_init (EvSidebarThumbnails *ev_sidebar_thumbnails)
                                  ev_sidebar_thumbnails);
        gtk_box_pack_start (GTK_BOX (ev_sidebar_thumbnails), priv->swindow, TRUE, TRUE, 0);
 
+       g_signal_connect (ev_sidebar_thumbnails, "notify::scale-factor",
+                         G_CALLBACK (notify_scale_factor_cb), NULL);
+
        /* Put it all together */
        gtk_widget_show_all (priv->swindow);
 }


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