]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-pixbuf-cache.c
Really make use of the orientation bit of the render context. Use the
[evince.git] / shell / ev-pixbuf-cache.c
index 58ba3bff51be64306214b0576282e115caf3d8b4..00d71d434e6b2c326c0c5471dc38f0e34f0d9545 100644 (file)
@@ -9,6 +9,7 @@ typedef struct _CacheJobInfo
        GdkPixbuf *pixbuf;
        EvRenderContext *rc;
        GList *link_mapping;
+       GdkRegion *text_mapping;
 
        /* Selection info.  If the *_points structs are unset, we put -1 in x1.
         * selection_points are the coordinates encapsulated in selection.
@@ -144,6 +145,10 @@ dispose_cache_job_info (CacheJobInfo *job_info,
                ev_link_mapping_free (job_info->link_mapping);
                job_info->link_mapping = NULL;
        }
+       if (job_info->text_mapping) {
+               gdk_region_destroy (job_info->text_mapping);
+               job_info->text_mapping = NULL;
+       }
        if (job_info->selection) {
                g_object_unref (G_OBJECT (job_info->selection));
                job_info->selection = NULL;
@@ -210,6 +215,13 @@ job_finished_cb (EvJob         *job,
                        ev_link_mapping_free (job_info->link_mapping);
                job_info->link_mapping = job_render->link_mapping;
        }
+
+       if (job_render->text_mapping) {
+               if (job_info->text_mapping)
+                       gdk_region_destroy (job_info->text_mapping);
+               job_info->text_mapping = job_render->text_mapping;
+       }
+
        if (job_render->include_selection) {
                if (job_info->selection)
                        g_object_unref (job_info->selection);
@@ -243,6 +255,7 @@ check_job_size_and_unref (CacheJobInfo *job_info,
 
        ev_page_cache_get_size (page_cache,
                                EV_JOB_RENDER (job_info->job)->rc->page,
+                               EV_JOB_RENDER (job_info->job)->rc->orientation,
                                scale,
                                &width, &height);
                                
@@ -403,6 +416,8 @@ copy_job_to_job_info (EvJobRender   *job_render,
        job_info->pixbuf = pixbuf;
        if (job_render->link_mapping)
                job_info->link_mapping = job_render->link_mapping;
+       if (job_render->text_mapping)
+               job_info->text_mapping = job_render->text_mapping;      
 }
 
 static CacheJobInfo *
@@ -464,19 +479,20 @@ add_job_if_needed (EvPixbufCache *pixbuf_cache,
                   CacheJobInfo  *job_info,
                   EvPageCache   *page_cache,
                   gint           page,
+                  EvOrientation  orientation,
                   gfloat         scale,
                   EvJobPriority  priority)
 {
        gboolean include_links = FALSE;
+       gboolean include_text = FALSE;
        gboolean include_selection = FALSE;
        int width, height;
 
        if (job_info->job)
                return;
 
-       ev_page_cache_get_size (page_cache,
-                               page, scale,
-                               &width, &height);
+       ev_page_cache_get_size (page_cache, page, orientation,
+                               scale, &width, &height);
 
        if (job_info->pixbuf &&
            gdk_pixbuf_get_width (job_info->pixbuf) == width &&
@@ -485,16 +501,18 @@ add_job_if_needed (EvPixbufCache *pixbuf_cache,
 
        /* make a new job now */
        if (job_info->rc == NULL) {
-               job_info->rc = ev_render_context_new (EV_ORIENTATION_PORTRAIT,
-                                                     page, scale);
+               job_info->rc = ev_render_context_new (orientation, page, scale);
        } else {
                ev_render_context_set_page (job_info->rc, page);
                ev_render_context_set_scale (job_info->rc, scale);
+               ev_render_context_set_orientation (job_info->rc, orientation);
        }
 
        /* Figure out what else we need for this job */
        if (job_info->link_mapping == NULL)
                include_links = TRUE;
+       if (job_info->text_mapping == NULL)
+               include_text = TRUE;
        if (new_selection_pixbuf_needed (pixbuf_cache, job_info, page, scale)) {
                include_selection = TRUE;
        }
@@ -504,6 +522,7 @@ add_job_if_needed (EvPixbufCache *pixbuf_cache,
                                           width, height,
                                           &(job_info->new_points),
                                           include_links,
+                                          include_text,
                                           include_selection);
        ev_job_queue_add_job (job_info->job, priority);
        g_signal_connect (job_info->job, "finished", G_CALLBACK (job_finished_cb), pixbuf_cache);
@@ -512,6 +531,7 @@ add_job_if_needed (EvPixbufCache *pixbuf_cache,
 
 static void
 ev_pixbuf_cache_add_jobs_if_needed (EvPixbufCache *pixbuf_cache,
+                                   EvOrientation  orientation,
                                    gfloat         scale)
 {
        EvPageCache *page_cache;
@@ -526,7 +546,7 @@ ev_pixbuf_cache_add_jobs_if_needed (EvPixbufCache *pixbuf_cache,
                page = pixbuf_cache->start_page + i;
 
                add_job_if_needed (pixbuf_cache, job_info,
-                                  page_cache, page, scale,
+                                  page_cache, page, orientation, scale,
                                   EV_JOB_PRIORITY_HIGH);
        }
 
@@ -535,7 +555,7 @@ ev_pixbuf_cache_add_jobs_if_needed (EvPixbufCache *pixbuf_cache,
                page = pixbuf_cache->start_page - pixbuf_cache->preload_cache_size + i;
 
                add_job_if_needed (pixbuf_cache, job_info,
-                                  page_cache, page, scale,
+                                  page_cache, page, orientation, scale,
                                   EV_JOB_PRIORITY_LOW);
        }
 
@@ -544,7 +564,7 @@ ev_pixbuf_cache_add_jobs_if_needed (EvPixbufCache *pixbuf_cache,
                page = pixbuf_cache->end_page + 1 + i;
 
                add_job_if_needed (pixbuf_cache, job_info,
-                                  page_cache, page, scale,
+                                  page_cache, page, orientation, scale,
                                   EV_JOB_PRIORITY_LOW);
        }
 
@@ -554,6 +574,7 @@ void
 ev_pixbuf_cache_set_page_range (EvPixbufCache *pixbuf_cache,
                                gint           start_page,
                                gint           end_page,
+                               EvOrientation  orientation,
                                gfloat         scale,
                                GList          *selection_list)
 {
@@ -580,7 +601,7 @@ ev_pixbuf_cache_set_page_range (EvPixbufCache *pixbuf_cache,
 
        /* Finally, we add the new jobs for all the sizes that don't have a
         * pixbuf */
-       ev_pixbuf_cache_add_jobs_if_needed (pixbuf_cache, scale);
+       ev_pixbuf_cache_add_jobs_if_needed (pixbuf_cache, orientation, scale);
 }
 
 GdkPixbuf *
@@ -633,8 +654,8 @@ new_selection_pixbuf_needed (EvPixbufCache *pixbuf_cache,
 
        if (job_info->selection) {
                page_cache = ev_page_cache_get (pixbuf_cache->document);
-               ev_page_cache_get_size (page_cache, page, scale,
-                                       &width, &height);
+               ev_page_cache_get_size (page_cache, page, job_info->rc->orientation,
+                                       scale, &width, &height);
                
                if (width != gdk_pixbuf_get_width (job_info->selection) ||
                    height != gdk_pixbuf_get_height (job_info->selection))
@@ -660,11 +681,23 @@ clear_selection_if_needed (EvPixbufCache *pixbuf_cache,
        }
 }
 
-GList *
-ev_pixbuf_cach_get_text_mapping      (EvPixbufCache *pixbuf_cache,
+GdkRegion *
+ev_pixbuf_cache_get_text_mapping      (EvPixbufCache *pixbuf_cache,
                                      gint           page)
 {
-       return NULL;
+       CacheJobInfo *job_info;
+
+       job_info = find_job_cache (pixbuf_cache, page);
+       if (job_info == NULL)
+               return NULL;
+
+       /* We don't need to wait for the idle to handle the callback */
+       if (job_info->job &&
+           EV_JOB (job_info->job)->finished) {
+               copy_job_to_job_info (EV_JOB_RENDER (job_info->job), job_info, pixbuf_cache);
+       }
+       
+       return job_info->text_mapping;
 }
 
 GdkPixbuf *
@@ -674,6 +707,10 @@ ev_pixbuf_cache_get_selection_pixbuf (EvPixbufCache *pixbuf_cache,
 {
        CacheJobInfo *job_info;
 
+       /* the document does not implement the selection interface */
+       if (!EV_IS_SELECTION (pixbuf_cache->document))
+               return NULL;
+
        job_info = find_job_cache (pixbuf_cache, page);
        if (job_info == NULL)
                return NULL;