]> www.fi.muni.cz Git - evince.git/commitdiff
Take screen DPI into account when zooming. Fixes bug #318285.
authorCarlos Garcia Campos <carlosgc@gnome.org>
Thu, 14 Dec 2006 11:45:40 +0000 (11:45 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Thu, 14 Dec 2006 11:45:40 +0000 (11:45 +0000)
2006-12-14  Carlos Garcia Campos  <carlosgc@gnome.org>
* ps/ps-document.c: (setup_page), (ps_document_get_page_size):
* shell/ev-window.c: (ev_window_get_screen_dpi),
(ev_window_update_actions), (setup_view_from_metadata),
(ev_window_zoom_changed_cb), (zoom_control_changed_cb):
Take screen DPI into account when zooming. Fixes bug #318285.

ChangeLog
ps/ps-document.c
shell/ev-window.c

index d00a79760e9dd38433e234094901581d7182cdc6..31adf50325e4ca18bdc06d7f482cd71e8961ee12 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-12-14  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * ps/ps-document.c: (setup_page), (ps_document_get_page_size):
+       * shell/ev-window.c: (ev_window_get_screen_dpi),
+       (ev_window_update_actions), (setup_view_from_metadata),
+       (ev_window_zoom_changed_cb), (zoom_control_changed_cb):
+
+       Take screen DPI into account when zooming. Fixes bug #318285.
+
 2006-12-14  Wouter Bolsterlee  <wbolster@cvs.gnome.org>
 
        * data/Makefile.am:
index 19800109a1834b860e0cc164f6646d365f9b014c..cd120aaa3e52afa5f56ea5745a63725ff6bbd640 100644 (file)
@@ -294,18 +294,6 @@ send_ps (PSDocument *gs, long begin, unsigned int len, gboolean close)
        }
 }
 
-static float
-get_xdpi (PSDocument *gs)
-{
-       return 25.4 * gdk_screen_width() / gdk_screen_width_mm();
-}
-
-static float
-get_ydpi (PSDocument *gs)
-{
-       return 25.4 * gdk_screen_height() / gdk_screen_height_mm();
-}
-
 static void
 setup_pixmap (PSDocument *gs, int page, double scale, int rotation)
 {
@@ -447,19 +435,17 @@ static void
 setup_page (PSDocument *gs, int page, double scale, int rotation)
 {
        gchar *buf;
-       char scaled_xdpi[G_ASCII_DTOSTR_BUF_SIZE];      
-       char scaled_ydpi[G_ASCII_DTOSTR_BUF_SIZE];
+       char scaled_dpi[G_ASCII_DTOSTR_BUF_SIZE];       
        int urx, ury, llx, lly;
 
        LOG ("Setup the page");
 
        get_page_box (gs, page, &urx, &ury, &llx, &lly);
-       g_ascii_dtostr (scaled_xdpi, G_ASCII_DTOSTR_BUF_SIZE, get_xdpi (gs) * scale);
-       g_ascii_dtostr (scaled_ydpi, G_ASCII_DTOSTR_BUF_SIZE, get_ydpi (gs) * scale);
+       g_ascii_dtostr (scaled_dpi, G_ASCII_DTOSTR_BUF_SIZE, 72.0 * scale);
 
        buf = g_strdup_printf ("%ld %d %d %d %d %d %s %s %d %d %d %d",
                               0L, rotation, llx, lly, urx, ury,
-                              scaled_xdpi, scaled_ydpi,
+                              scaled_dpi, scaled_dpi,
                               0, 0, 0, 0);
        LOG ("GS property %s", buf);
 
@@ -1212,14 +1198,14 @@ ps_document_get_page_size (EvDocument   *document,
        PSDocument *gs = PS_DOCUMENT (document);
        int urx, ury, llx, lly;
 
-       get_page_box (PS_DOCUMENT (document), page, &urx, &ury, &llx, &lly);
+       get_page_box (gs, page, &urx, &ury, &llx, &lly);
 
        if (width) {
-               *width = (urx - llx) / 72.0 * get_xdpi (gs) + 0.5;
+               *width = (urx - llx) + 0.5;
        }
 
        if (height) {
-               *height = (ury - lly) / 72.0 * get_ydpi (gs) + 0.5;
+               *height = (ury - lly) + 0.5;
        }
 }
 
index b3ad4ee7dbd01d7dc2939ed1bab1b38594a31640..6d9f778ac4333d0a5faec9471aa9aaaf3bf70007 100644 (file)
@@ -265,6 +265,20 @@ static gboolean fullscreen_leave_notify_cb                 (GtkWidget *widget,
 
 G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
 
+static gdouble
+ev_window_get_screen_dpi (EvWindow *ev_window)
+{
+       GdkScreen *screen;
+       gdouble    xdpi, ydpi;
+
+       screen = gtk_window_get_screen (GTK_WINDOW (ev_window));
+
+       xdpi = 25.4 * gdk_screen_get_width (screen) / gdk_screen_get_width_mm (screen);
+       ydpi = 25.4 * gdk_screen_get_height (screen) / gdk_screen_get_height_mm (screen);
+       
+       return (xdpi + ydpi) / 2.0;
+}
+
 static void
 ev_window_set_action_sensitive (EvWindow   *ev_window,
                                const char *name,
@@ -425,6 +439,7 @@ ev_window_update_actions (EvWindow *ev_window)
                                                      ZOOM_CONTROL_ACTION);
 
                real_zoom = ev_view_get_zoom (EV_VIEW (ev_window->priv->view));
+               real_zoom *= 72.0 / ev_window_get_screen_dpi (ev_window);
                zoom = ephy_zoom_get_nearest_zoom_level (real_zoom);
 
                ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action), zoom);
@@ -810,7 +825,11 @@ setup_view_from_metadata (EvWindow *window)
        /* Zoom */
        if (ev_metadata_manager_get (uri, "zoom", &zoom, FALSE) &&
            ev_view_get_sizing_mode (view) == EV_SIZING_FREE) {
-               ev_view_set_zoom (view, g_value_get_double (&zoom), FALSE);
+               gdouble zoom_value;
+
+               zoom_value = g_value_get_double (&zoom);
+               zoom_value *= ev_window_get_screen_dpi (window) / 72.0;
+               ev_view_set_zoom (view, zoom_value, FALSE);
                g_value_unset (&zoom);
        }
 
@@ -3025,8 +3044,11 @@ ev_window_zoom_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *ev_window)
         ev_window_update_actions (ev_window);
 
        if (ev_view_get_sizing_mode (view) == EV_SIZING_FREE && !ev_window_is_empty (ev_window)) {
-               ev_metadata_manager_set_double (ev_window->priv->uri, "zoom",
-                                               ev_view_get_zoom (view));
+               gdouble zoom;
+
+               zoom = ev_view_get_zoom (view);
+               zoom *= 72.0 / ev_window_get_screen_dpi (ev_window);
+               ev_metadata_manager_set_double (ev_window->priv->uri, "zoom", zoom);
        }
 }
 
@@ -3459,7 +3481,9 @@ zoom_control_changed_cb (EphyZoomAction *action,
        ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), mode);
        
        if (mode == EV_SIZING_FREE) {
-               ev_view_set_zoom (EV_VIEW (ev_window->priv->view), zoom, FALSE);
+               ev_view_set_zoom (EV_VIEW (ev_window->priv->view),
+                                 zoom * ev_window_get_screen_dpi (ev_window) / 72.0,
+                                 FALSE);
        }
 }