diff options
Diffstat (limited to 'libview/ev-view.c')
-rw-r--r-- | libview/ev-view.c | 87 |
1 files changed, 44 insertions, 43 deletions
diff --git a/libview/ev-view.c b/libview/ev-view.c index a445ef2e..650730c0 100644 --- a/libview/ev-view.c +++ b/libview/ev-view.c @@ -4773,6 +4773,45 @@ hide_loading_window (EvView *view) } static void +draw_surface (cairo_t *cr, + cairo_surface_t *surface, + gint x, + gint y, + gint offset_x, + gint offset_y, + gint target_width, + gint target_height) +{ + gint width, height; + + width = cairo_image_surface_get_width (surface); + height = cairo_image_surface_get_height (surface); + + cairo_save (cr); + cairo_translate (cr, x, y); + + if (width != target_width || height != target_height) { + gdouble scale_x, scale_y; + + scale_x = (gdouble)target_width / width; + scale_y = (gdouble)target_height / height; + cairo_pattern_set_filter (cairo_get_source (cr), + CAIRO_FILTER_FAST); + cairo_scale (cr, scale_x, scale_y); + + offset_x /= scale_x; + offset_y /= scale_y; + } + + cairo_surface_set_device_offset (surface, + offset_x, + offset_y); + cairo_set_source_surface (cr, surface, 0, 0); + cairo_paint (cr); + cairo_restore (cr); +} + +static void draw_one_page (EvView *view, gint page, cairo_t *cr, @@ -4810,10 +4849,9 @@ draw_one_page (EvView *view, if (gdk_rectangle_intersect (&real_page_area, expose_area, &overlap)) { gint width, height; - gint page_width, page_height; cairo_surface_t *page_surface = NULL; - gint selection_width, selection_height; cairo_surface_t *selection_surface = NULL; + gint offset_x, offset_y; double device_scale_x = 1, device_scale_y = 1; page_surface = ev_pixbuf_cache_get_surface (view->pixbuf_cache, page); @@ -4835,27 +4873,10 @@ draw_one_page (EvView *view, hide_loading_window (view); ev_view_get_page_size (view, page, &width, &height); + offset_x = overlap.x - real_page_area.x; + offset_y = overlap.y - real_page_area.y; - page_width = cairo_image_surface_get_width (page_surface); - page_height = cairo_image_surface_get_height (page_surface); - - cairo_save (cr); - cairo_translate (cr, overlap.x, overlap.y); - - if (width != page_width || height != page_height) { - cairo_pattern_set_filter (cairo_get_source (cr), - CAIRO_FILTER_FAST); - cairo_scale (cr, - (gdouble)width / page_width * device_scale_x, - (gdouble)height / page_height * device_scale_y); - } - - cairo_surface_set_device_offset (page_surface, - (overlap.x - real_page_area.x) * device_scale_x, - (overlap.y - real_page_area.y) * device_scale_y); - cairo_set_source_surface (cr, page_surface, 0, 0); - cairo_paint (cr); - cairo_restore (cr); + draw_surface (cr, page_surface, overlap.x, overlap.y, offset_x, offset_y, width, height); /* Get the selection pixbuf iff we have something to draw */ if (find_selection_for_page (view, page) && @@ -4870,28 +4891,8 @@ draw_one_page (EvView *view, if (!selection_surface) { return; } + draw_surface (cr, selection_surface, overlap.x, overlap.y, offset_x, offset_y, width, height); - selection_width = cairo_image_surface_get_width (selection_surface); - selection_height = cairo_image_surface_get_height (selection_surface); - - cairo_save (cr); - cairo_translate (cr, overlap.x, overlap.y); - - if (width != selection_width || height != selection_height) { - cairo_pattern_set_filter (cairo_get_source (cr), - CAIRO_FILTER_FAST); - cairo_scale (cr, - (gdouble)width / selection_width * device_scale_x, - (gdouble)height / selection_height * device_scale_y); - } - - cairo_surface_set_device_offset (selection_surface, - (overlap.x - real_page_area.x) * device_scale_x, - (overlap.y - real_page_area.y) * device_scale_y); - - cairo_set_source_surface (cr, selection_surface, 0, 0); - cairo_paint (cr); - cairo_restore (cr); } } |