~ubuntu-branches/ubuntu/hardy/evince/hardy-proposed

« back to all changes in this revision

Viewing changes to shell/ev-pixbuf-cache.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2007-07-10 23:50:59 UTC
  • mfrom: (1.1.16 upstream)
  • Revision ID: james.westby@ubuntu.com-20070710235059-qwycayuufgbi0nhd
Tags: 0.9.2-0ubuntu1
* New Features and UI Improvements:
  * Forms support
  * Toolbar editor icons on dragging
* Bug fixes:
  * Program description translation issue fixed
  * Do not change page after presentation
  * Fix LP: #49340 bug : Forgets "Fit Page Width" option on each click on
    the index
* debian/rules: add DEB_DESTDIR_evince-gtk to clean target.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#include "ev-page-cache.h"
4
4
#include "ev-selection.h"
5
5
#include "ev-document-images.h"
 
6
#include "ev-document-forms.h"
6
7
#include "ev-image.h"
 
8
#include "ev-form-field.h"
7
9
 
8
10
typedef struct _CacheJobInfo
9
11
{
10
12
        EvJob *job;
11
13
        EvRenderContext *rc;
12
14
 
 
15
        /* Region of the page that needs to be drawn */
 
16
        GdkRegion *region; 
 
17
 
13
18
        /* Data we get from rendering */
14
19
        cairo_surface_t *surface;
15
20
        GList *link_mapping;
16
21
        GList *image_mapping;
 
22
        GList *form_field_mapping;
17
23
        GdkRegion *text_mapping;
18
24
        
19
25
        /* Selection data. 
112
118
        object_class->finalize = ev_pixbuf_cache_finalize;
113
119
        object_class->dispose = ev_pixbuf_cache_dispose;
114
120
 
115
 
        signals[JOB_FINISHED] = g_signal_new ("job-finished",
116
 
                                            G_OBJECT_CLASS_TYPE (object_class),
117
 
                                            G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
118
 
                                            G_STRUCT_OFFSET (EvPixbufCacheClass, job_finished),
119
 
                                            NULL, NULL,
120
 
                                            g_cclosure_marshal_VOID__VOID,
121
 
                                            G_TYPE_NONE, 0);
 
121
        signals[JOB_FINISHED] =
 
122
                g_signal_new ("job-finished",
 
123
                              G_OBJECT_CLASS_TYPE (object_class),
 
124
                              G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
 
125
                              G_STRUCT_OFFSET (EvPixbufCacheClass, job_finished),
 
126
                              NULL, NULL,
 
127
                              g_cclosure_marshal_VOID__POINTER,
 
128
                              G_TYPE_NONE, 1,
 
129
                              G_TYPE_POINTER);
122
130
}
123
131
 
124
132
static void
153
161
                cairo_surface_destroy (job_info->surface);
154
162
                job_info->surface = NULL;
155
163
        }
 
164
        if (job_info->region) {
 
165
                gdk_region_destroy (job_info->region);
 
166
                job_info->region = NULL;
 
167
        }
156
168
        if (job_info->link_mapping) {
157
169
                ev_link_mapping_free (job_info->link_mapping);
158
170
                job_info->link_mapping = NULL;
161
173
                ev_image_mapping_free (job_info->image_mapping);
162
174
                job_info->image_mapping = NULL;
163
175
        }
 
176
        if (job_info->form_field_mapping) {
 
177
                ev_form_field_mapping_free (job_info->form_field_mapping);
 
178
                job_info->form_field_mapping = NULL;
 
179
        }
164
180
        if (job_info->text_mapping) {
165
181
                gdk_region_destroy (job_info->text_mapping);
166
182
                job_info->text_mapping = NULL;
233
249
        job_info = find_job_cache (pixbuf_cache, job_render->rc->page);
234
250
 
235
251
        copy_job_to_job_info (job_render, job_info, pixbuf_cache);
236
 
        g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0);
 
252
        g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
237
253
}
238
254
 
239
255
/* This checks a job to see if the job would generate the right sized pixbuf
320
336
 
321
337
        *target_page = *job_info;
322
338
        job_info->job = NULL;
 
339
        job_info->region = NULL;
323
340
        job_info->surface = NULL;
324
341
        job_info->link_mapping = NULL;
325
342
        job_info->image_mapping = NULL;
 
343
        job_info->form_field_mapping = NULL;
326
344
 
327
345
        if (new_priority != priority && target_page->job) {
328
346
                ev_job_queue_update_job (target_page->job, new_priority);
329
347
        }
330
348
}
331
349
 
332
 
 
333
 
 
334
350
static void
335
351
ev_pixbuf_cache_update_range (EvPixbufCache *pixbuf_cache,
336
352
                              gint           start_page,
432
448
                job_info->image_mapping = job_render->image_mapping;
433
449
        }
434
450
 
 
451
        if (job_render->include_forms) {
 
452
                if (job_info->form_field_mapping)
 
453
                        ev_form_field_mapping_free (job_info->form_field_mapping);
 
454
                job_info->form_field_mapping = job_render->form_field_mapping;
 
455
        }
 
456
 
435
457
        if (job_render->include_text) {
436
458
                if (job_info->text_mapping)
437
459
                        gdk_region_destroy (job_info->text_mapping);
532
554
}
533
555
 
534
556
static void
535
 
add_job_if_needed (EvPixbufCache *pixbuf_cache,
536
 
                   CacheJobInfo  *job_info,
537
 
                   EvPageCache   *page_cache,
538
 
                   gint           page,
539
 
                   gint           rotation,
540
 
                   gfloat         scale,
541
 
                   EvJobPriority  priority)
 
557
add_job (EvPixbufCache *pixbuf_cache,
 
558
         CacheJobInfo  *job_info,
 
559
         EvPageCache   *page_cache,
 
560
         GdkRegion     *region,
 
561
         gint           width,
 
562
         gint           height,
 
563
         gint           page,
 
564
         gint           rotation,
 
565
         gfloat         scale,
 
566
         EvJobPriority  priority)
542
567
{
543
568
        gboolean include_links = FALSE;
544
569
        gboolean include_text = FALSE;
545
570
        gboolean include_selection = FALSE;
546
 
        gboolean include_images = FALSE;
547
 
        int width, height;
 
571
        gboolean include_images = TRUE;
 
572
        gboolean include_forms = FALSE;
548
573
        GdkColor *text, *base;
549
 
 
550
 
        if (job_info->job)
551
 
                return;
552
 
 
553
 
        ev_page_cache_get_size (page_cache, page, rotation,
554
 
                                scale, &width, &height);
555
 
 
556
 
        if (job_info->surface &&
557
 
            cairo_image_surface_get_width (job_info->surface) == width &&
558
 
            cairo_image_surface_get_height (job_info->surface) == height)
559
 
                return;
560
 
 
561
 
        /* make a new job now */
 
574
        
562
575
        if (job_info->rc == NULL) {
563
576
                job_info->rc = ev_render_context_new (rotation, page, scale);
564
577
        } else {
567
580
                ev_render_context_set_scale (job_info->rc, scale);
568
581
        }
569
582
 
 
583
        if (job_info->region)
 
584
                gdk_region_destroy (job_info->region);
 
585
        job_info->region = region ? gdk_region_copy (region) : NULL;
 
586
 
570
587
        /* Figure out what else we need for this job */
571
588
        if (job_info->link_mapping == NULL)
572
589
                include_links = TRUE;
573
590
        if (job_info->image_mapping == NULL)
574
591
                include_images = TRUE;
 
592
        if (job_info->form_field_mapping == NULL)
 
593
                include_forms = TRUE;
575
594
        if (job_info->text_mapping == NULL)
576
595
                include_text = TRUE;
577
596
        if (new_selection_surface_needed (pixbuf_cache, job_info, page, scale)) {
587
606
                                           width, height,
588
607
                                           &(job_info->target_points),
589
608
                                           text, base,
 
609
                                           include_forms,
590
610
                                           include_links,
591
611
                                           include_images,
592
612
                                           include_text,
593
613
                                           include_selection);
594
614
        ev_job_queue_add_job (job_info->job, priority);
595
 
        g_signal_connect (job_info->job, "finished", G_CALLBACK (job_finished_cb), pixbuf_cache);
596
 
}
597
 
 
 
615
        g_signal_connect (job_info->job, "finished",
 
616
                          G_CALLBACK (job_finished_cb),
 
617
                          pixbuf_cache);
 
618
}
 
619
 
 
620
static void
 
621
add_job_if_needed (EvPixbufCache *pixbuf_cache,
 
622
                   CacheJobInfo  *job_info,
 
623
                   EvPageCache   *page_cache,
 
624
                   gint           page,
 
625
                   gint           rotation,
 
626
                   gfloat         scale,
 
627
                   EvJobPriority  priority)
 
628
{
 
629
        gint width, height;
 
630
 
 
631
        if (job_info->job)
 
632
                return;
 
633
 
 
634
        ev_page_cache_get_size (page_cache, page, rotation,
 
635
                                scale, &width, &height);
 
636
 
 
637
        if (job_info->surface &&
 
638
            cairo_image_surface_get_width (job_info->surface) == width &&
 
639
            cairo_image_surface_get_height (job_info->surface) == height)
 
640
                return;
 
641
 
 
642
        add_job (pixbuf_cache, job_info, page_cache, NULL,
 
643
                 width, height, page, rotation, scale,
 
644
                 priority);
 
645
}
598
646
 
599
647
static void
600
648
ev_pixbuf_cache_add_jobs_if_needed (EvPixbufCache *pixbuf_cache,
685
733
        if (job_info->job &&
686
734
            EV_JOB (job_info->job)->finished) {
687
735
                copy_job_to_job_info (EV_JOB_RENDER (job_info->job), job_info, pixbuf_cache);
688
 
                g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0);
 
736
                g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
689
737
        }
690
738
 
691
739
        return job_info->surface;
705
753
        if (job_info->job &&
706
754
            EV_JOB (job_info->job)->finished) {
707
755
                copy_job_to_job_info (EV_JOB_RENDER (job_info->job), job_info, pixbuf_cache);
708
 
                g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0);
 
756
                g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
709
757
        }
710
758
 
711
759
        return job_info->link_mapping;
728
776
        if (job_info->job &&
729
777
            EV_JOB (job_info->job)->finished) {
730
778
                copy_job_to_job_info (EV_JOB_RENDER (job_info->job), job_info, pixbuf_cache);
731
 
                g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0);
 
779
                g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
732
780
        }
733
781
 
734
782
        return job_info->image_mapping;
735
783
}
736
784
 
 
785
GList *
 
786
ev_pixbuf_cache_get_form_field_mapping (EvPixbufCache *pixbuf_cache,
 
787
                                        gint           page)
 
788
{
 
789
        CacheJobInfo *job_info;
 
790
 
 
791
        if (!EV_IS_DOCUMENT_FORMS (pixbuf_cache->document))
 
792
                return NULL;
 
793
        
 
794
        job_info = find_job_cache (pixbuf_cache, page);
 
795
        if (job_info == NULL)
 
796
                return NULL;
 
797
 
 
798
        /* We don't need to wait for the idle to handle the callback */
 
799
        if (job_info->job &&
 
800
           EV_JOB (job_info->job)->finished) {
 
801
                copy_job_to_job_info (EV_JOB_RENDER(job_info->job), job_info, pixbuf_cache);
 
802
                g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
 
803
        }
 
804
        
 
805
        return job_info->form_field_mapping;
 
806
}
 
807
 
737
808
static gboolean
738
809
new_selection_surface_needed (EvPixbufCache *pixbuf_cache,
739
810
                             CacheJobInfo  *job_info,
792
863
        if (job_info->job &&
793
864
            EV_JOB (job_info->job)->finished) {
794
865
                copy_job_to_job_info (EV_JOB_RENDER (job_info->job), job_info, pixbuf_cache);
795
 
                g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0);
 
866
                g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
796
867
        }
797
868
        
798
869
        return job_info->text_mapping;
1102
1173
        return retval;
1103
1174
}
1104
1175
 
 
1176
void           
 
1177
ev_pixbuf_cache_reload_page (EvPixbufCache *pixbuf_cache,
 
1178
                             GdkRegion     *region,
 
1179
                             gint           page,
 
1180
                             gint           rotation,
 
1181
                             gdouble        scale)
 
1182
{
 
1183
        CacheJobInfo *job_info;
 
1184
        EvPageCache *page_cache;
 
1185
        gint width, height;
 
1186
 
 
1187
        job_info = find_job_cache (pixbuf_cache, page);
 
1188
        if (job_info == NULL)
 
1189
                return;
 
1190
        
 
1191
        page_cache = ev_page_cache_get (pixbuf_cache->document);
 
1192
        ev_page_cache_get_size (page_cache, page, rotation, scale,
 
1193
                                &width, &height);
 
1194
 
 
1195
        add_job (pixbuf_cache, job_info, page_cache, region,
 
1196
                 width, height, page, rotation, scale,
 
1197
                 EV_JOB_PRIORITY_HIGH);
 
1198
}
 
1199
 
 
1200