[evince/wip/gpoo/204-annot-square-and-circle: 1/3] backends: Add circle/square annotation support in PDF
- From: Germán Poo-Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/gpoo/204-annot-square-and-circle: 1/3] backends: Add circle/square annotation support in PDF
- Date: Sun, 21 Jun 2020 02:11:32 +0000 (UTC)
commit cb86db927f4d5db4882a6843d627af733a98bc95
Author: Anuj Khare <khareanuj18 gmail com>
Date: Fri Jul 25 18:13:16 2014 +0200
backends: Add circle/square annotation support in PDF
This patch allows to create a circle/square annotation from the
corresponding poppler annotation, and to save the properties of the
annotations to the pdf file.
Fixes #204
backend/pdf/ev-poppler.cc | 124 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 123 insertions(+), 1 deletion(-)
---
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index 911894b9..86838706 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -3144,6 +3144,26 @@ poppler_annot_can_have_popup_window (PopplerAnnot *poppler_annot)
}
}
+static void
+gdk_rgba_from_poppler_color (PopplerColor *poppler_color,
+ GdkRGBA *rgba)
+{
+ g_return_if_fail (rgba != NULL);
+
+ if (poppler_color) {
+ rgba->red = poppler_color->red / 65535.;
+ rgba->green = poppler_color->green / 65535.;
+ rgba->blue = poppler_color->blue / 65535.;
+ g_free (poppler_color);
+ } else {
+ /* Default color set to yellow */
+ rgba->red = 1.;
+ rgba->green = 1.;
+ rgba->blue = 0.;
+ }
+ rgba->alpha = 1.;
+}
+
static EvAnnotation *
ev_annot_from_poppler_annot (PopplerAnnot *poppler_annot,
EvPage *page)
@@ -3209,6 +3229,38 @@ ev_annot_from_poppler_annot (PopplerAnnot *poppler_annot,
case POPPLER_ANNOT_SQUIGGLY:
ev_annot = ev_annotation_text_markup_squiggly_new (page);
break;
+ case POPPLER_ANNOT_CIRCLE: {
+ PopplerColor *poppler_color;
+ GdkRGBA interior_rgba;
+
+ ev_annot = ev_annotation_circle_new (page);
+
+ poppler_color = poppler_annot_circle_get_interior_color (POPPLER_ANNOT_CIRCLE
(poppler_annot));
+ if (poppler_color) {
+ gdk_rgba_from_poppler_color (poppler_color, &interior_rgba);
+ ev_annotation_circle_set_interior_rgba (EV_ANNOTATION_CIRCLE (ev_annot),
&interior_rgba);
+ ev_annotation_circle_set_has_interior_color (EV_ANNOTATION_CIRCLE
(ev_annot), TRUE);
+ } else {
+ ev_annotation_circle_set_has_interior_color (EV_ANNOTATION_CIRCLE
(ev_annot), FALSE);
+ }
+ }
+ break;
+ case POPPLER_ANNOT_SQUARE: {
+ PopplerColor *poppler_color;
+ GdkRGBA interior_rgba;
+
+ ev_annot = ev_annotation_square_new (page);
+
+ poppler_color = poppler_annot_square_get_interior_color (POPPLER_ANNOT_SQUARE
(poppler_annot));
+ if (poppler_color) {
+ gdk_rgba_from_poppler_color (poppler_color, &interior_rgba);
+ ev_annotation_square_set_interior_rgba (EV_ANNOTATION_SQUARE (ev_annot),
&interior_rgba);
+ ev_annotation_square_set_has_interior_color (EV_ANNOTATION_SQUARE
(ev_annot), TRUE);
+ } else {
+ ev_annotation_square_set_has_interior_color (EV_ANNOTATION_SQUARE
(ev_annot), FALSE);
+ }
+ }
+ break;
case POPPLER_ANNOT_LINK:
case POPPLER_ANNOT_WIDGET:
case POPPLER_ANNOT_MOVIE:
@@ -3228,7 +3280,6 @@ ev_annot_from_poppler_annot (PopplerAnnot *poppler_annot,
case POPPLER_ANNOT_FREE_TEXT:
case POPPLER_ANNOT_LINE:
case POPPLER_ANNOT_SOUND:
- case POPPLER_ANNOT_SQUARE:
case POPPLER_ANNOT_STAMP: {
/* FIXME: These annotations are unimplemented, but they were already
* reported in Evince Bugzilla with test case. We add a special
@@ -3491,6 +3542,59 @@ pdf_document_annotations_remove_annotation (EvDocumentAnnotations *document_anno
ev_document_set_modified (EV_DOCUMENT (document_annotations), TRUE);
}
+static void
+poppler_color_from_gdk_rgba (GdkRGBA *rgba,
+ PopplerColor *poppler_color)
+{
+ g_return_if_fail (poppler_color != NULL);
+ g_return_if_fail (rgba != NULL);
+
+ poppler_color->red = rgba->red * 65535.;
+ poppler_color->green = rgba->green * 65535.;
+ poppler_color->blue = rgba->blue * 65535.;
+}
+
+static void
+save_poppler_annot_circle_interior_color (EvAnnotationCircle *annot,
+ PopplerAnnotCircle *poppler_annot)
+{
+ PopplerColor *poppler_color;
+ GdkRGBA interior_color;
+
+ /* Transparent */
+ if (ev_annotation_circle_get_has_interior_color (annot) == FALSE) {
+ poppler_annot_circle_set_interior_color (poppler_annot, NULL);
+ printf ("set transparent to poppler \n");
+ return;
+ }
+
+ ev_annotation_circle_get_interior_rgba (annot, &interior_color);
+ poppler_color = poppler_color_new ();
+ poppler_color_from_gdk_rgba (&interior_color, poppler_color);
+ poppler_annot_circle_set_interior_color (poppler_annot, poppler_color);
+ poppler_color_free (poppler_color);
+}
+
+static void
+save_poppler_annot_square_interior_color (EvAnnotationSquare *annot,
+ PopplerAnnotSquare *poppler_annot)
+{
+ PopplerColor *poppler_color;
+ GdkRGBA interior_color;
+
+ /* Transparent */
+ if (!ev_annotation_square_get_has_interior_color (annot)) {
+ poppler_annot_square_set_interior_color (poppler_annot, NULL);
+ return;
+ }
+
+ ev_annotation_square_get_interior_rgba (annot, &interior_color);
+ poppler_color = poppler_color_new ();
+ poppler_color_from_gdk_rgba (&interior_color, poppler_color);
+ poppler_annot_square_set_interior_color (poppler_annot, poppler_color);
+ poppler_color_free (poppler_color);
+}
+
/* FIXME: this could be moved to poppler */
static GArray *
get_quads_for_area (PopplerPage *page,
@@ -3922,6 +4026,24 @@ pdf_document_annotations_save_annotation (EvDocumentAnnotations *document_annota
}
}
+ if (EV_IS_ANNOTATION_CIRCLE (annot)) {
+ EvAnnotationCircle *ev_circle = EV_ANNOTATION_CIRCLE (annot);
+ PopplerAnnotCircle *poppler_circle = POPPLER_ANNOT_CIRCLE (poppler_annot);
+
+ if (mask & EV_ANNOTATIONS_SAVE_INTERIOR_COLOR) {
+ save_poppler_annot_circle_interior_color (ev_circle, poppler_circle);
+ }
+ }
+
+ if (EV_IS_ANNOTATION_SQUARE (annot)) {
+ EvAnnotationSquare *ev_square = EV_ANNOTATION_SQUARE (annot);
+ PopplerAnnotSquare *poppler_square = POPPLER_ANNOT_SQUARE (poppler_annot);
+
+ if (mask & EV_ANNOTATIONS_SAVE_INTERIOR_COLOR) {
+ save_poppler_annot_square_interior_color (ev_square, poppler_square);
+ }
+ }
+
PDF_DOCUMENT (document_annotations)->annots_modified = TRUE;
ev_document_set_modified (EV_DOCUMENT (document_annotations), TRUE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]