# HG changeset patch
# User Thomas Liebetraut <thomas@tommie-lie.de>
# Date 1396196080 -7200
#      Sun Mar 30 18:14:40 2014 +0200
# Node ID 15b1715682fd6d48ea723619431834214e67701d
# Parent  48de07d940ed928d89b67b4d47bc53b8adb65622
Add support for POPPLER_ANNOT_HIGHLIGHT

https://bugzilla.gnome.org/show_bug.cgi?id=583377

diff -r 48de07d940ed -r 15b1715682fd backend/pdf/ev-poppler.cc
--- a/backend/pdf/ev-poppler.cc	Sun Mar 30 18:09:27 2014 +0200
+++ b/backend/pdf/ev-poppler.cc	Sun Mar 30 18:14:40 2014 +0200
@@ -2872,6 +2872,10 @@
 				g_object_unref (poppler_attachment);
 		}
 			break;
+		case POPPLER_ANNOT_HIGHLIGHT: {
+			ev_annot = ev_annotation_text_markup_highlight_new (page);
+		}
+			break;
 	        case POPPLER_ANNOT_LINK:
 	        case POPPLER_ANNOT_WIDGET:
 			/* Ignore link and widgets annots since they are already handled */
@@ -2879,7 +2883,6 @@
 		case POPPLER_ANNOT_3D:
 		case POPPLER_ANNOT_CARET:
 		case POPPLER_ANNOT_FREE_TEXT:
-		case POPPLER_ANNOT_HIGHLIGHT:
 		case POPPLER_ANNOT_LINE:
 		case POPPLER_ANNOT_SCREEN:
 		case POPPLER_ANNOT_SOUND:
@@ -2968,6 +2971,58 @@
 		             "bounding-rectangle", &ev_bound_rect,
 		             NULL);
 
+		if (POPPLER_IS_ANNOT_TEXT_MARKUP (poppler_annot)) {
+			PopplerAnnotTextMarkup *poppler_text_markup;
+			EvAnnotationTextMarkup *ev_annot_text_markup;
+			GArray *poppler_quads = NULL;
+			GArray *ev_quads = NULL;
+			gdouble page_height;
+
+			poppler_text_markup = POPPLER_ANNOT_TEXT_MARKUP (poppler_annot);
+
+			poppler_quads = poppler_annot_text_markup_get_quadrilaterals(poppler_text_markup);
+			if (poppler_quads && poppler_quads->len) {
+				ev_quads = g_array_sized_new (FALSE, FALSE,
+				                              sizeof(EvQuadrilateral),
+				                              poppler_quads->len);
+
+				poppler_page_get_size (POPPLER_PAGE (page->backend_page),
+						       NULL, &page_height);
+
+				guint i;
+				for (i = 0; i < poppler_quads->len; ++i) {
+					EvQuadrilateral ev_quad;
+					PopplerQuadrilateral quad = g_array_index(poppler_quads,
+					                                            PopplerQuadrilateral,
+					                                            i);
+					/*
+					 * Reorder poppler quads to be
+					 * counter-clockwise and starting
+					 * at the bottom left corner.
+					 */
+					ev_quad.p1.x =               quad.p3.x;
+					ev_quad.p1.y = page_height - quad.p3.y;
+
+					ev_quad.p2.x =               quad.p4.x;
+					ev_quad.p2.y = page_height - quad.p4.y;
+
+					ev_quad.p3.x =               quad.p2.x;
+					ev_quad.p3.y = page_height - quad.p2.y;
+
+					ev_quad.p4.x =               quad.p1.x;
+					ev_quad.p4.y = page_height - quad.p1.y;
+
+					g_array_append_val(ev_quads,
+							   ev_quad);
+				}
+			}
+
+			ev_annot_text_markup = EV_ANNOTATION_TEXT_MARKUP (ev_annot);
+
+			g_object_set(ev_annot_text_markup, "quadrilaterals", ev_quads, NULL);
+			g_array_unref(poppler_quads);
+			g_array_unref(ev_quads);
+		}
 
 		if (POPPLER_IS_ANNOT_MARKUP (poppler_annot)) {
 			PopplerAnnotMarkup *markup;
diff -r 48de07d940ed -r 15b1715682fd libdocument/ev-annotation.c
--- a/libdocument/ev-annotation.c	Sun Mar 30 18:09:27 2014 +0200
+++ b/libdocument/ev-annotation.c	Sun Mar 30 18:14:40 2014 +0200
@@ -1551,3 +1551,15 @@
 	return TRUE;
 }
 
+EvAnnotation *
+ev_annotation_text_markup_highlight_new (EvPage  *page)
+{
+	EvAnnotation *annot = EV_ANNOTATION(g_object_new (EV_TYPE_ANNOTATION_TEXT_MARKUP,
+	                                                  "page", page,
+	                                                  NULL));
+	if (annot) {
+		annot->type = EV_ANNOTATION_TYPE_HIGHLIGHT;
+	}
+	return annot;
+}
+
diff -r 48de07d940ed -r 15b1715682fd libdocument/ev-annotation.h
--- a/libdocument/ev-annotation.h	Sun Mar 30 18:09:27 2014 +0200
+++ b/libdocument/ev-annotation.h	Sun Mar 30 18:14:40 2014 +0200
@@ -112,7 +112,8 @@
 typedef enum {
 	EV_ANNOTATION_TYPE_UNKNOWN,
 	EV_ANNOTATION_TYPE_TEXT,
-	EV_ANNOTATION_TYPE_ATTACHMENT
+	EV_ANNOTATION_TYPE_ATTACHMENT,
+	EV_ANNOTATION_TYPE_HIGHLIGHT
 } EvAnnotationType;
 
 typedef enum {
@@ -205,6 +206,7 @@
 GArray              *ev_annotation_text_markup_get_quadrilaterals (EvAnnotationTextMarkup *annot);
 gboolean             ev_annotation_text_markup_set_quadrilaterals (EvAnnotationTextMarkup *annot,
                                                                    GArray *arr);
+EvAnnotation        *ev_annotation_text_markup_highlight_new      (EvPage                 *page);
 
 
 G_END_DECLS
