]> www.fi.muni.cz Git - evince.git/commitdiff
[pdf] Cache annotations in the backend
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 11 Jul 2010 17:34:47 +0000 (19:34 +0200)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Mon, 12 Jul 2010 17:12:01 +0000 (19:12 +0200)
backend/pdf/ev-poppler.cc

index df5573bdd0892f4d3ff685acc2b79e293ca3612f..f457d64e2822a229371dde15119b02806a2609dc 100644 (file)
@@ -110,6 +110,7 @@ struct _PdfDocument
        PdfPrintContext *print_ctx;
 
        GList *layers;
+       GHashTable *annots;
 };
 
 static void pdf_document_security_iface_init             (EvDocumentSecurityInterface    *iface);
@@ -187,6 +188,11 @@ pdf_document_dispose (GObject *object)
                pdf_document->print_ctx = NULL;
        }
 
+       if (pdf_document->annots) {
+               g_hash_table_destroy (pdf_document->annots);
+               pdf_document->annots = NULL;
+       }
+
        if (pdf_document->document) {
                g_object_unref (pdf_document->document);
        }
@@ -2681,6 +2687,7 @@ pdf_document_annotations_get_annotations (EvDocumentAnnotations *document_annota
        GList *retval = NULL;
        PdfDocument *pdf_document;
        PopplerPage *poppler_page;
+       EvMappingList *mapping_list;
        GList *annots;
        GList *list;
        gdouble height;
@@ -2688,6 +2695,14 @@ pdf_document_annotations_get_annotations (EvDocumentAnnotations *document_annota
 
        pdf_document = PDF_DOCUMENT (document_annotations);
        poppler_page = POPPLER_PAGE (page->backend_page);
+
+       if (pdf_document->annots) {
+               mapping_list = (EvMappingList *)g_hash_table_lookup (pdf_document->annots,
+                                                                    GINT_TO_POINTER (page->index));
+               if (mapping_list)
+                       return ev_mapping_list_ref (mapping_list);
+       }
+
        annots = poppler_page_get_annot_mapping (poppler_page);
        poppler_page_get_size (poppler_page, NULL, &height);
 
@@ -2725,7 +2740,22 @@ pdf_document_annotations_get_annotations (EvDocumentAnnotations *document_annota
 
        poppler_page_free_annot_mapping (annots);
 
-       return ev_mapping_list_new (page->index, g_list_reverse (retval), (GDestroyNotify)g_object_unref);
+       if (!retval)
+               return NULL;
+
+       if (!pdf_document->annots) {
+               pdf_document->annots = g_hash_table_new_full (g_direct_hash,
+                                                             g_direct_equal,
+                                                             (GDestroyNotify)NULL,
+                                                             (GDestroyNotify)ev_mapping_list_unref);
+       }
+
+       mapping_list = ev_mapping_list_new (page->index, g_list_reverse (retval), (GDestroyNotify)g_object_unref);
+       g_hash_table_insert (pdf_document->annots,
+                            GINT_TO_POINTER (page->index),
+                            ev_mapping_list_ref (mapping_list));
+
+       return mapping_list;
 }
 
 static void