summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Aliste <[email protected]>2013-02-08 20:09:05 +0100
committerraveit65 <[email protected]>2017-09-06 18:25:34 +0200
commit12495d0accc29caba391cdeb2b5a5a9f13857217 (patch)
tree18db047c2bdb02511932d7a77f72d523690ee03a
parent16c02c8a3731665b06b1b8fdd3e882ede3f0ccfe (diff)
downloadatril-12495d0accc29caba391cdeb2b5a5a9f13857217.tar.bz2
atril-12495d0accc29caba391cdeb2b5a5a9f13857217.tar.xz
libview: Refactor code for drawing page and selection surfaces
The code necessary to draw a page surface or a selection surface is the same. We factor this out to a new static method called draw_surface origin commit: https://git.gnome.org/browse/evince/commit/?h=gnome-3-8&id=3ab6ac1 libview: Fix rendering of the first visible page while resizing While we are resizing the view widget and waiting for a new surface rendered at the right size, we use old surfaces scaled to match the target size. When the begining of a page is not visible, the scaled surfaces are not placed correctly. origin commit: https://git.gnome.org/browse/evince/commit/?h=gnome-3-8&id=72f2ae4
-rw-r--r--libview/ev-view.c87
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);
}
}