summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiselle Machado <[email protected]>2014-06-27 19:41:57 +0200
committerraveit65 <[email protected]>2017-08-28 16:04:00 +0200
commit7e53c5708bd38b99adf1a4b363ed2c21304dccdd (patch)
tree3bc5e8a8498fb0805ebbe9240ffb053fcc6d3aeb
parentd933e02e8bf0594627c975d5c73a46fb8b593020 (diff)
downloadatril-7e53c5708bd38b99adf1a4b363ed2c21304dccdd.tar.bz2
atril-7e53c5708bd38b99adf1a4b363ed2c21304dccdd.tar.xz
pdf: Make annotation names unique
Naming the annotations sequentially by number is problematic when they can be removed (see https://bugzilla.gnome.org/show_bug.cgi?id=649044#c33). This patch changes the annotation names to timestamps, guaranteeing that they are indeed unique. https://bugzilla.gnome.org/show_bug.cgi?id=649044 origin commit: https://git.gnome.org/browse/evince/commit/?id=0f38a27 fix build warning: https://git.gnome.org/browse/evince/commit/?id=6197eba
-rw-r--r--backend/pdf/ev-poppler.cc27
1 files changed, 14 insertions, 13 deletions
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index bc8b99ad..24c452dd 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -2730,6 +2730,16 @@ ev_annot_from_poppler_annot (PopplerAnnot *poppler_annot,
return ev_annot;
}
+static void
+annot_set_unique_name (EvAnnotation *annot)
+{
+ gchar *name;
+
+ name = g_strdup_printf ("annot-%" G_GUINT64_FORMAT, g_get_real_time ());
+ ev_annotation_set_name (annot, name);
+ g_free (name);
+}
+
static EvMappingList *
pdf_document_annotations_get_annotations (EvDocumentAnnotations *document_annotations,
EvPage *page)
@@ -2770,12 +2780,8 @@ pdf_document_annotations_get_annotations (EvDocumentAnnotations *document_annota
i++;
/* Make sure annot has a unique name */
- if (!ev_annotation_get_name (ev_annot)) {
- gchar *name = g_strdup_printf ("annot-%d-%d", page->index, i);
-
- ev_annotation_set_name (ev_annot, name);
- g_free (name);
- }
+ if (!ev_annotation_get_name (ev_annot))
+ annot_set_unique_name (ev_annot);
annot_mapping = g_new (EvMapping, 1);
annot_mapping->area.x1 = mapping->area.x1;
@@ -2834,7 +2840,6 @@ pdf_document_annotations_add_annotation (EvDocumentAnnotations *document_annotat
gdouble height;
PopplerColor poppler_color;
GdkColor color;
- gchar *name;
pdf_document = PDF_DOCUMENT (document_annotations);
page = ev_annotation_get_page (annot);
@@ -2911,16 +2916,12 @@ pdf_document_annotations_add_annotation (EvDocumentAnnotations *document_annotat
mapping_list = NULL;
}
+ annot_set_unique_name (annot);
+
if (mapping_list) {
list = ev_mapping_list_get_list (mapping_list);
- name = g_strdup_printf ("annot-%d-%d", page->index, g_list_length (list) + 1);
- ev_annotation_set_name (annot, name);
- g_free (name);
list = g_list_append (list, annot_mapping);
} else {
- name = g_strdup_printf ("annot-%d-0", page->index);
- ev_annotation_set_name (annot, name);
- g_free (name);
list = g_list_append (list, annot_mapping);
mapping_list = ev_mapping_list_new (page->index, list, (GDestroyNotify)g_object_unref);
g_hash_table_insert (pdf_document->annots,