# HG changeset patch
# User Thomas Liebetraut <thomas@tommie-lie.de>
# Date 1396178635 -7200
#      Sun Mar 30 13:23:55 2014 +0200
# Node ID b8bcc5b4217c48ebe222ef43e53d93be1e617818
# Parent  6de33897d991bca633e43af6a01fcba927350762
Add bounding-rectangle property to EvAnnotation

This allows an EvAnnotation to know its location on the page.

diff -r 6de33897d991 -r b8bcc5b4217c backend/pdf/ev-poppler.cc
--- a/backend/pdf/ev-poppler.cc	Fri Mar 28 19:31:08 2014 +0000
+++ b/backend/pdf/ev-poppler.cc	Sun Mar 30 13:23:55 2014 +0200
@@ -2930,6 +2930,9 @@
 		gchar   *contents;
 		gchar   *name;
 		GdkColor color;
+		gdouble page_height;
+		EvRectangle ev_bound_rect;
+		PopplerRectangle poppler_rect;
 
 		contents = poppler_annot_get_contents (poppler_annot);
 		if (contents) {
@@ -2954,6 +2957,18 @@
 		poppler_annot_color_to_gdk_color (poppler_annot, &color);
 		ev_annotation_set_color (ev_annot, &color);
 
+		poppler_page_get_size (POPPLER_PAGE (page->backend_page),
+				       NULL, &page_height);
+		poppler_annot_get_rectangle(poppler_annot, &poppler_rect);
+		ev_bound_rect.x1 = poppler_rect.x1;
+		ev_bound_rect.x2 = poppler_rect.x2;
+		ev_bound_rect.y1 = page_height - poppler_rect.y2;
+		ev_bound_rect.y2 = page_height - poppler_rect.y1;
+		g_object_set(ev_annot,
+		             "bounding-rectangle", &ev_bound_rect,
+		             NULL);
+
+
 		if (POPPLER_IS_ANNOT_MARKUP (poppler_annot)) {
 			PopplerAnnotMarkup *markup;
 			gchar *label;
@@ -2965,14 +2980,11 @@
 			if (poppler_annot_markup_get_popup_rectangle (markup, &poppler_rect)) {
 				EvRectangle ev_rect;
 				gboolean is_open;
-				gdouble height;
-
-				poppler_page_get_size (POPPLER_PAGE (page->backend_page),
-						       NULL, &height);
+
 				ev_rect.x1 = poppler_rect.x1;
 				ev_rect.x2 = poppler_rect.x2;
-				ev_rect.y1 = height - poppler_rect.y2;
-				ev_rect.y2 = height - poppler_rect.y1;
+				ev_rect.y1 = page_height - poppler_rect.y2;
+				ev_rect.y2 = page_height - poppler_rect.y1;
 
 				is_open = poppler_annot_markup_get_popup_is_open (markup);
 
@@ -3050,10 +3062,8 @@
 		}
 
 		annot_mapping = g_new (EvMapping, 1);
-		annot_mapping->area.x1 = mapping->area.x1;
-		annot_mapping->area.x2 = mapping->area.x2;
-		annot_mapping->area.y1 = height - mapping->area.y2;
-		annot_mapping->area.y2 = height - mapping->area.y1;
+		ev_annotation_get_bounding_rectangle(ev_annot,
+		                                     &annot_mapping->area);
 		annot_mapping->data = ev_annot;
 
 		g_object_set_data_full (G_OBJECT (ev_annot),
diff -r 6de33897d991 -r b8bcc5b4217c libdocument/ev-annotation.c
--- a/libdocument/ev-annotation.c	Fri Mar 28 19:31:08 2014 +0000
+++ b/libdocument/ev-annotation.c	Sun Mar 30 13:23:55 2014 +0200
@@ -35,6 +35,7 @@
 	gchar           *name;
 	gchar           *modified;
 	GdkRGBA          rgba;
+	EvRectangle      rect;
 };
 
 struct _EvAnnotationClass {
@@ -78,7 +79,8 @@
 	PROP_ANNOT_NAME,
 	PROP_ANNOT_MODIFIED,
 	PROP_ANNOT_COLOR,
-        PROP_ANNOT_RGBA
+        PROP_ANNOT_RGBA,
+        PROP_ANNOT_BOUND_RECT
 };
 
 /* EvAnnotationMarkup */
@@ -177,6 +179,9 @@
         case PROP_ANNOT_RGBA:
                 ev_annotation_set_rgba (annot, g_value_get_boxed (value));
                 break;
+        case PROP_ANNOT_BOUND_RECT:
+        	ev_annotation_set_bounding_rectangle (annot, g_value_get_boxed (value));
+        	break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 	}
@@ -210,6 +215,9 @@
         case PROP_ANNOT_RGBA:
                 g_value_set_boxed (value, &annot->rgba);
                 break;
+        case PROP_ANNOT_BOUND_RECT:
+        	g_value_set_boxed (value, &annot->rect);
+        	break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 	}
@@ -284,6 +292,22 @@
                                                              GDK_TYPE_RGBA,
                                                              G_PARAM_READWRITE |
                                                              G_PARAM_STATIC_STRINGS));
+
+        /**
+         * EvAnnotation:bounding-rectangle:
+         *
+         * The bounding rectangle of the annotation within the page as a #EvRectangle.
+         *
+         * Since: 3.6
+         */
+        g_object_class_install_property (g_object_class,
+                                         PROP_ANNOT_BOUND_RECT,
+                                         g_param_spec_boxed ("bounding-rectangle",
+                                                             "Bounding rectangle",
+                                                             "The bounding rectangle of the annotation",
+                                                             EV_TYPE_RECTANGLE,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_STATIC_STRINGS));
 }
 
 EvAnnotationType
@@ -631,6 +655,35 @@
         return TRUE;
 }
 
+void
+ev_annotation_get_bounding_rectangle (EvAnnotation *annot,
+				      EvRectangle  *rect)
+{
+	g_return_if_fail (EV_IS_ANNOTATION (annot));
+	g_return_if_fail (rect != NULL);
+
+	*rect = annot->rect;
+}
+
+gboolean
+ev_annotation_set_bounding_rectangle (EvAnnotation      *annot,
+				      const EvRectangle *rect)
+{
+	g_return_val_if_fail (EV_IS_ANNOTATION (annot), FALSE);
+	g_return_val_if_fail (rect != NULL, FALSE);
+
+	if (annot->rect.x1 == rect->x1 &&
+	    annot->rect.y1 == rect->y1 &&
+	    annot->rect.x2 == rect->x2 &&
+	    annot->rect.y2 == rect->y2)
+		return FALSE;
+
+        annot->rect = *rect;
+        g_object_notify (G_OBJECT (annot), "bounding_rectangle");
+
+        return TRUE;
+}
+
 /* EvAnnotationMarkup */
 typedef struct {
 	gchar   *label;
diff -r 6de33897d991 -r b8bcc5b4217c libdocument/ev-annotation.h
--- a/libdocument/ev-annotation.h	Fri Mar 28 19:31:08 2014 +0000
+++ b/libdocument/ev-annotation.h	Sun Mar 30 13:23:55 2014 +0200
@@ -125,6 +125,10 @@
                                                               GdkRGBA                *rgba);
 gboolean             ev_annotation_set_rgba                  (EvAnnotation           *annot,
                                                               const GdkRGBA          *rgba);
+void                 ev_annotation_get_bounding_rectangle    (EvAnnotation           *annot,
+                                                              EvRectangle            *rect);
+gboolean             ev_annotation_set_bounding_rectangle    (EvAnnotation           *annot,
+                                                              const EvRectangle      *rect);
 
 /* EvAnnotationMarkup */
 GType                ev_annotation_markup_get_type           (void) G_GNUC_CONST;
diff -r 6de33897d991 -r b8bcc5b4217c libview/ev-view.c
--- a/libview/ev-view.c	Fri Mar 28 19:31:08 2014 +0000
+++ b/libview/ev-view.c	Sun Mar 30 13:23:55 2014 +0200
@@ -3119,6 +3119,7 @@
 	g_object_unref (page);
 
 	ev_annotation_set_color (annot, &color);
+	ev_annotation_set_bounding_rectangle(annot, &doc_rect);
 
 	if (EV_IS_ANNOTATION_MARKUP (annot)) {
 		popup_rect.x1 = doc_rect.x2;
