[evince/wip/highlight: 50/59] pdf: support for saving quadrilaterals
- From: Giselle Reis <gisellemnr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/highlight: 50/59] pdf: support for saving quadrilaterals
- Date: Sun, 2 Nov 2014 10:59:14 +0000 (UTC)
commit 1f7ac353d7fb300ad54f9e08b115275b5d35f4ef
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 | 54 +++++++++++++++++++++++++++++++++
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, 64 insertions(+), 4 deletions(-)
---
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index 44ade1c..d795b8e 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -3250,6 +3250,7 @@ pdf_document_annotations_add_annotation (EvDocumentAnnotations *document_annotat
static void
pdf_document_annotations_save_annotation (EvDocumentAnnotations *document_annotations,
EvAnnotation *annot,
+ EvRectangle *area,
EvAnnotationsSaveMask mask)
{
PopplerAnnot *poppler_annot;
@@ -3301,6 +3302,59 @@ pdf_document_annotations_save_annotation (EvDocumentAnnotations *document_annota
}
}
+ if (EV_IS_ANNOTATION_TEXT_MARKUP (annot)) {
+ EvAnnotationTextMarkup *ev_textmarkup = EV_ANNOTATION_TEXT_MARKUP (annot);
+ PopplerAnnotTextMarkup *textmarkup = POPPLER_ANNOT_TEXT_MARKUP (poppler_annot);
+
+ 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 (textmarkup, 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 5f2a98d..de41c4d 100644
--- a/libdocument/ev-document-annotations.h
+++ b/libdocument/ev-document-annotations.h
@@ -58,8 +58,11 @@ typedef enum {
/* Attachment Annotations */
EV_ANNOTATIONS_SAVE_ATTACHMENT = 1 << 8,
+ /* Text Markup Annotations */
+ EV_ANNOTATIONS_SAVE_QUADS = 1 << 9,
+
/* Save all */
- EV_ANNOTATIONS_SAVE_ALL = (1 << 9) - 1
+ EV_ANNOTATIONS_SAVE_ALL = (1 << 10) - 1
} EvAnnotationsSaveMask;
typedef struct _EvDocumentAnnotations EvDocumentAnnotations;
@@ -78,6 +81,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);
@@ -95,6 +99,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 7adb322..c4bbd44 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -2957,7 +2957,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 e7f6a96..ae9b3ec 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -6489,7 +6489,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]