[evince/wip/gpoo/204-annot-square-and-circle: 103/105] backends: Add circle/square annotation support in PDF




commit 7509f118eaa4600892ee577df4eeb53955e6c734
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 | 123 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 122 insertions(+), 1 deletion(-)
---
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index 551b37a0..72ecd2aa 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -3191,6 +3191,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)
@@ -3256,6 +3276,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:
@@ -3275,7 +3327,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
@@ -3538,6 +3589,58 @@ 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);
+                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,
@@ -3969,6 +4072,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]