Skip to content

Commit

Permalink
EvView: render correctly on hi-dpi displays
Browse files Browse the repository at this point in the history
Make EvPixbufCache generate surfaces with extra resolution based on
gtk_widget_get_scale_factor(). Handle cairo surfaces with a device
scale in ev_view_draw(). Trigger an update of the pixbuf cache when
the scale factor changes.

https://bugzilla.gnome.org/show_bug.cgi?id=723431

origin commit:
https://git.gnome.org/browse/evince/commit/?id=a612f8
  • Loading branch information
owtaylor authored and raveit65 committed Mar 26, 2018
1 parent f4b94ea commit 58486bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions libview/ev-pixbuf-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ copy_job_to_job_info (EvJobRender *job_render,

job_info->selection_points = job_render->selection_points;
job_info->selection = cairo_surface_reference (job_render->selection);
job_info->selection_scale = job_render->scale;
if (job_info->selection)
set_device_scale_on_surface (job_info->selection, job_info->device_scale);
job_info->selection_scale = job_render->scale * job_info->device_scale;
g_assert (job_info->selection_points.x1 >= 0);

job_info->selection_region_points = job_render->selection_points;
Expand Down Expand Up @@ -1093,7 +1093,7 @@ ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache,
if (job_info->selection)
set_device_scale_on_surface (job_info->selection, job_info->device_scale);
job_info->selection_points = job_info->target_points;
job_info->selection_scale = scale;
job_info->selection_scale = scale * job_info->device_scale;
g_object_unref (rc);
ev_document_doc_mutex_unlock ();
}
Expand Down
23 changes: 18 additions & 5 deletions libview/ev-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -5690,10 +5690,14 @@ draw_surface (cairo_t *cr,
gint target_width,
gint target_height)
{
gint width, height;
gdouble width, height;
gdouble device_scale_x = 1, device_scale_y = 1;

width = cairo_image_surface_get_width (surface);
height = cairo_image_surface_get_height (surface);
#ifdef HAVE_HIDPI_SUPPORT
cairo_surface_get_device_scale (surface, &device_scale_x, &device_scale_y);
#endif
width = cairo_image_surface_get_width (surface) / device_scale_x;
height = cairo_image_surface_get_height (surface) / device_scale_y;

cairo_save (cr);
cairo_translate (cr, x, y);
Expand All @@ -5712,8 +5716,8 @@ draw_surface (cairo_t *cr,
}

cairo_surface_set_device_offset (surface,
offset_x,
offset_y);
offset_x * device_scale_x,
offset_y * device_scale_y);
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
cairo_restore (cr);
Expand Down Expand Up @@ -5848,9 +5852,18 @@ draw_one_page (EvView *view,
if (region) {
double scale_x, scale_y;
GdkRGBA color;
double device_scale_x = 1, device_scale_y = 1;

scale_x = (gdouble)width / cairo_image_surface_get_width (page_surface);
scale_y = (gdouble)height / cairo_image_surface_get_height (page_surface);

#ifdef HAVE_HIDPI_SUPPORT
cairo_surface_get_device_scale (page_surface, &device_scale_x, &device_scale_y);
#endif

scale_x *= device_scale_x;
scale_y *= device_scale_y;

_ev_view_get_selection_colors (view, &color, NULL);
draw_selection_region (cr, region, &color, real_page_area.x, real_page_area.y,
scale_x, scale_y);
Expand Down

0 comments on commit 58486bb

Please sign in to comment.