]> www.fi.muni.cz Git - evince.git/commitdiff
[libview] Invert colors of pages after rendering when inverted colors option is enabled
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 29 Nov 2009 14:57:08 +0000 (15:57 +0100)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 29 Nov 2009 14:57:08 +0000 (15:57 +0100)
See bgo#321823.

libview/ev-pixbuf-cache.c
libview/ev-pixbuf-cache.h
libview/ev-view.c

index df06705c51b2360e709e2373f53e14dc9498ee0a..d0f8644e57dd2757622bc2c0ed554f6c26479c35 100644 (file)
@@ -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)
index 4ab0fce062326fa7f295989fc0dd0f0de89e0420..94673c2e083de8d943abb3861d45063ca8211c3d 100644 (file)
@@ -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,
index 28c8f822dbd8292e14e9122a779a45668966aad8..f0502b44369295c6916226cf4103813ae644c4ba 100644 (file)
@@ -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);