[evince/wip/highlight: 136/145] pdf: support for saving quadrilaterals
- From: Giselle Reis <gisellemnr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/highlight: 136/145] pdf: support for saving quadrilaterals
- Date: Tue, 14 Apr 2015 01:03:30 +0000 (UTC)
commit 4de869d42007d9ef77c2508e9fd29613ecad8c40
Author: Giselle Machado <gisellemnr src gnome org>
Date: Fri Jul 25 18:23:43 2014 +0200
pdf: support for saving quadrilaterals
Adding back-end support for updating the region
covered by text markup annotations in poppler.
NOTE:
This is implemented with the following in
mind: when adding a text markup annotation,
everytime the cursor moves, the annotation area is
updated and therefore the annotation
quadrilaterals should also be updated. This is
done when the function
'ev_document_annotation_save_annotation' is
called.
I could think of two ways to pass the new selected
rectangle to this function, either as a parameter
of the function or as a property of the text
markup annotation.
The first solution is implemented in this patch,
and it is in conformity with
'ev_document_annotation_add_annotation', which
also takes an EvRectangle as a parameter.
I don't like the fact that the other function
calls pass NULL for the rectangle, but oh well,
life is not perfect. Had I kept this rectangle as
a property of the annotation, it would only be
useful during the interaction when creating the
annotation. Actually, it would make sense if we
were able to edit the annotation (increase or
decrease it), but this does not seem to be the case.
backend/pdf/ev-poppler.cc | 49 +++++++++++++++++++++++++++++++++
libdocument/ev-document-annotations.c | 3 +-
libdocument/ev-document-annotations.h | 7 ++++-
libview/ev-view.c | 2 +-
shell/ev-window.c | 2 +-
5 files changed, 59 insertions(+), 4 deletions(-)
---
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index 0cb30ab..79c680f 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -3327,6 +3327,7 @@ copy_poppler_annot (PopplerAnnot* src_annot,
static void
pdf_document_annotations_save_annotation (EvDocumentAnnotations *document_annotations,
EvAnnotation *annot,
+ EvRectangle *area,
EvAnnotationsSaveMask mask)
{
PopplerAnnot *poppler_annot;
@@ -3422,6 +3423,54 @@ pdf_document_annotations_save_annotation (EvDocumentAnnotations *document_annota
new_annot,
(GDestroyNotify) g_object_unref);
}
+
+ if (mask & EV_ANNOTATIONS_SAVE_QUADS) {
+ GArray *quads;
+ PopplerRectangle *bbox;
+ EvPage *page;
+ PopplerPage *poppler_page;
+ EvMappingList *annot_mapping;
+ GList *annot_list;
+ gdouble height;
+
+ page = ev_annotation_get_page (annot);
+ poppler_page = POPPLER_PAGE (page->backend_page);
+ poppler_page_get_size (poppler_page, NULL, &height);
+
+ bbox = g_slice_new (PopplerRectangle);
+ quads = poppler_page_get_quadrilaterals_for_area (poppler_page, (PopplerRectangle *)
area, bbox);
+
+ if (quads->len > 0) {
+ poppler_annot_text_markup_set_quadrilaterals (text_markup, quads);
+ poppler_annot_set_rectangle (poppler_annot, bbox);
+
+ /* Update rectangle in annotation mapping */
+ annot_mapping = (EvMappingList *) g_hash_table_lookup (PDF_DOCUMENT
(document_annotations)->annots,
+ GINT_TO_POINTER
(page->index));
+ annot_list = ev_mapping_list_get_list (annot_mapping);
+
+ for (; annot_list; annot_list = g_list_next (annot_list)) {
+ EvMapping *map = (EvMapping *) annot_list->data;
+ EvAnnotation *map_annot = (EvAnnotation *) map->data;
+
+ if (ev_annotation_get_name (map_annot) == ev_annotation_get_name
(annot)) {
+ PopplerRectangle *poppler_rect = g_slice_new
(PopplerRectangle);
+
+ poppler_annot_get_rectangle (poppler_annot, poppler_rect);
+
+ map->area.x1 = poppler_rect->x1;
+ map->area.y1 = height - poppler_rect->y2;
+ map->area.x2 = poppler_rect->x2;
+ map->area.y2 = height - poppler_rect->y1;
+
+ g_slice_free (PopplerRectangle, poppler_rect);
+ break;
+ }
+ }
+ }
+ g_array_unref (quads);
+ g_slice_free (PopplerRectangle, bbox);
+ }
}
PDF_DOCUMENT (document_annotations)->annots_modified = TRUE;
diff --git a/libdocument/ev-document-annotations.c b/libdocument/ev-document-annotations.c
index 96ce4f6..cdf1ea8 100644
--- a/libdocument/ev-document-annotations.c
+++ b/libdocument/ev-document-annotations.c
@@ -48,11 +48,12 @@ ev_document_annotations_document_is_modified (EvDocumentAnnotations *document_an
void
ev_document_annotations_save_annotation (EvDocumentAnnotations *document_annots,
EvAnnotation *annot,
+ EvRectangle *rect,
EvAnnotationsSaveMask mask)
{
EvDocumentAnnotationsInterface *iface = EV_DOCUMENT_ANNOTATIONS_GET_IFACE (document_annots);
- iface->save_annotation (document_annots, annot, mask);
+ iface->save_annotation (document_annots, annot, rect, mask);
}
void
diff --git a/libdocument/ev-document-annotations.h b/libdocument/ev-document-annotations.h
index f0a9432..b62a8ab 100644
--- a/libdocument/ev-document-annotations.h
+++ b/libdocument/ev-document-annotations.h
@@ -61,8 +61,11 @@ typedef enum {
/* Text Markup Annotations */
EV_ANNOTATIONS_SAVE_TEXT_MARKUP_TYPE = 1 << 9,
+ /* Text Markup Annotations */
+ EV_ANNOTATIONS_SAVE_QUADS = 1 << 10,
+
/* Save all */
- EV_ANNOTATIONS_SAVE_ALL = (1 << 10) - 1
+ EV_ANNOTATIONS_SAVE_ALL = (1 << 11) - 1
} EvAnnotationsSaveMask;
typedef struct _EvDocumentAnnotations EvDocumentAnnotations;
@@ -81,6 +84,7 @@ struct _EvDocumentAnnotationsInterface
EvRectangle *rect);
void (* save_annotation) (EvDocumentAnnotations *document_annots,
EvAnnotation *annot,
+ EvRectangle *rect,
EvAnnotationsSaveMask mask);
void (* remove_annotation) (EvDocumentAnnotations *document_annots,
EvAnnotation *annot);
@@ -98,6 +102,7 @@ void ev_document_annotations_remove_annotation (EvDocumentAnnotatio
void ev_document_annotations_save_annotation (EvDocumentAnnotations *document_annots,
EvAnnotation *annot,
+ EvRectangle *rect,
EvAnnotationsSaveMask mask);
gboolean ev_document_annotations_can_add_annotation (EvDocumentAnnotations *document_annots);
gboolean ev_document_annotations_can_remove_annotation (EvDocumentAnnotations *document_annots);
diff --git a/libview/ev-view.c b/libview/ev-view.c
index f37b67a..f1dc8f0 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -2967,7 +2967,7 @@ ev_view_annotation_save_contents (EvView *view,
ev_document_doc_mutex_lock ();
ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (view->document),
- annot, EV_ANNOTATIONS_SAVE_CONTENTS);
+ annot, NULL, EV_ANNOTATIONS_SAVE_CONTENTS);
ev_document_doc_mutex_unlock ();
}
diff --git a/shell/ev-window.c b/shell/ev-window.c
index f9802ae..0ab649f 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -6344,7 +6344,7 @@ ev_window_popup_cmd_annot_properties (GSimpleAction *action,
if (mask != EV_ANNOTATIONS_SAVE_NONE) {
ev_document_doc_mutex_lock ();
ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (window->priv->document),
- window->priv->annot,
+ window->priv->annot, NULL,
mask);
ev_document_doc_mutex_unlock ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]