[gedit/wip/printing-enhancements: 1/2] print-preview: simplify set_zoom_fit_to_size()



commit 08241e2f93c62782c4f21dca0dd8ea18e5a01468
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Jun 28 05:52:06 2015 +0200

    print-preview: simplify set_zoom_fit_to_size()
    
    Call set_zoom_factor() instead of computing ourself the tile size.
    set_zoom_factor() calls update_tile_size(), which is equivalent to the
    code that updated manually the tile size, except when
    
    width - 2 * PAGE_PAD
    or
    height - 2 * PAGE_PAD
    
    is negative (in the case of a very small gedit window). In that case,
    the new code is slightly better since it takes 1 pixel to draw the page.
    But the new code is better in the sense that update_tile_size() can be
    modified later to get_tile_size() instead of storing the values.

 gedit/gedit-print-preview.c |   31 +++++++++----------------------
 1 files changed, 9 insertions(+), 22 deletions(-)
---
diff --git a/gedit/gedit-print-preview.c b/gedit/gedit-print-preview.c
index fe75210..dd4393c 100644
--- a/gedit/gedit-print-preview.c
+++ b/gedit/gedit-print-preview.c
@@ -172,36 +172,23 @@ set_zoom_fit_to_size (GeditPrintPreview *preview)
 {
        GtkAdjustment *hadj, *vadj;
        gdouble width, height;
-       gdouble p_width, p_height;
+       gdouble paper_width, paper_height;
        gdouble zoomx, zoomy;
 
        get_adjustments (preview, &hadj, &vadj);
 
-       g_object_get (hadj, "page-size", &width, NULL);
-       g_object_get (vadj, "page-size", &height, NULL);
+       width = gtk_adjustment_get_page_size (hadj);
+       height = gtk_adjustment_get_page_size (vadj);
 
        width /= preview->n_columns;
 
-       p_width = get_paper_width (preview);
-       p_height = get_paper_height (preview);
+       paper_width = get_paper_width (preview);
+       paper_height = get_paper_height (preview);
 
-       zoomx = MAX (1, width - 2 * PAGE_PAD) / p_width;
-       zoomy = MAX (1, height - 2 * PAGE_PAD) / p_height;
+       zoomx = MAX (1, width - 2 * PAGE_PAD) / paper_width;
+       zoomy = MAX (1, height - 2 * PAGE_PAD) / paper_height;
 
-       if (zoomx <= zoomy)
-       {
-               preview->tile_width = width;
-               preview->tile_height = round (width * (p_height / p_width));
-               preview->scale = zoomx;
-       }
-       else
-       {
-               preview->tile_width = round (height * (p_width / p_height));
-               preview->tile_height = height;
-               preview->scale = zoomy;
-       }
-
-       update_layout_size (preview);
+       set_zoom_factor (preview, zoomx <= zoomy ? zoomx : zoomy);
 }
 
 static void


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