From: Carlos Garcia Campos Date: Sun, 29 Nov 2009 14:57:08 +0000 (+0100) Subject: [libview] Invert colors of pages after rendering when inverted colors option is enabled X-Git-Tag: EVINCE_2_29_3~14 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=139f0ec4a2f5fe022b9a7d5848b5998615f81834;p=evince.git [libview] Invert colors of pages after rendering when inverted colors option is enabled See bgo#321823. --- diff --git a/libview/ev-pixbuf-cache.c b/libview/ev-pixbuf-cache.c index df06705c..d0f8644e 100644 --- a/libview/ev-pixbuf-cache.c +++ b/libview/ev-pixbuf-cache.c @@ -45,6 +45,7 @@ struct _EvPixbufCache EvDocument *document; int start_page; int end_page; + gboolean inverted_colors; /* preload_cache_size is the number of pages prior to the current * visible area that we cache. It's normally 1, but could be 2 in the @@ -468,6 +469,9 @@ copy_job_page_and_selection_to_job_info (EvJobRender *job_render, cairo_surface_destroy (job_info->surface); } job_info->surface = cairo_surface_reference (job_render->surface); + if (pixbuf_cache->inverted_colors) { + ev_document_misc_invert_surface (job_info->surface); + } job_info->points_set = FALSE; if (job_render->flags & EV_RENDER_INCLUDE_SELECTION) { @@ -759,6 +763,38 @@ ev_pixbuf_cache_set_page_range (EvPixbufCache *pixbuf_cache, ev_pixbuf_cache_add_jobs_if_needed (pixbuf_cache, rotation, scale); } +void +ev_pixbuf_cache_set_inverted_colors (EvPixbufCache *pixbuf_cache, + gboolean inverted_colors) +{ + gint i; + + if (pixbuf_cache->inverted_colors == inverted_colors) + return; + + pixbuf_cache->inverted_colors = inverted_colors; + + for (i = 0; i < pixbuf_cache->preload_cache_size; i++) { + CacheJobInfo *job_info; + + job_info = pixbuf_cache->prev_job + i; + if (job_info->surface) + ev_document_misc_invert_surface (job_info->surface); + + job_info = pixbuf_cache->next_job + i; + if (job_info->surface) + ev_document_misc_invert_surface (job_info->surface); + } + + for (i = 0; i < PAGE_CACHE_LEN (pixbuf_cache); i++) { + CacheJobInfo *job_info; + + job_info = pixbuf_cache->job_list + i; + if (job_info->surface) + ev_document_misc_invert_surface (job_info->surface); + } +} + cairo_surface_t * ev_pixbuf_cache_get_surface (EvPixbufCache *pixbuf_cache, gint page) diff --git a/libview/ev-pixbuf-cache.h b/libview/ev-pixbuf-cache.h index 4ab0fce0..94673c2e 100644 --- a/libview/ev-pixbuf-cache.h +++ b/libview/ev-pixbuf-cache.h @@ -80,7 +80,9 @@ void ev_pixbuf_cache_reload_page (EvPixbufCache *pixbuf_cache, GdkRegion *region, gint page, gint rotation, - gdouble scale); + gdouble scale); +void ev_pixbuf_cache_set_inverted_colors (EvPixbufCache *pixbuf_cache, + gboolean inverted_colors); /* Selection */ cairo_surface_t *ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache, gint page, diff --git a/libview/ev-view.c b/libview/ev-view.c index 28c8f822..f0502b44 100644 --- a/libview/ev-view.c +++ b/libview/ev-view.c @@ -5066,8 +5066,12 @@ ev_view_new (void) static void setup_caches (EvView *view) { + gboolean inverted_colors; + view->height_to_page_cache = ev_view_get_height_to_page_cache (view); view->pixbuf_cache = ev_pixbuf_cache_new (GTK_WIDGET (view), view->document); + inverted_colors = ev_document_model_get_inverted_colors (view->model); + ev_pixbuf_cache_set_inverted_colors (view->pixbuf_cache, inverted_colors); g_signal_connect (view->pixbuf_cache, "job-finished", G_CALLBACK (job_finished_cb), view); } @@ -5219,6 +5223,20 @@ ev_view_rotation_changed_cb (EvDocumentModel *model, clear_selection (view); } +static void +ev_view_inverted_colors_changed_cb (EvDocumentModel *model, + GParamSpec *pspec, + EvView *view) +{ + if (view->pixbuf_cache) { + gboolean inverted_colors; + + inverted_colors = ev_document_model_get_inverted_colors (model); + ev_pixbuf_cache_set_inverted_colors (view->pixbuf_cache, inverted_colors); + gtk_widget_queue_resize (GTK_WIDGET (view)); + } +} + static void ev_view_sizing_mode_changed_cb (EvDocumentModel *model, GParamSpec *pspec, @@ -5318,6 +5336,9 @@ ev_view_set_model (EvView *view, g_signal_connect (view->model, "notify::rotation", G_CALLBACK (ev_view_rotation_changed_cb), view); + g_signal_connect (view->model, "notify::inverted-colors", + G_CALLBACK (ev_view_inverted_colors_changed_cb), + view); g_signal_connect (view->model, "notify::sizing-mode", G_CALLBACK (ev_view_sizing_mode_changed_cb), view);