[evince] Add support for changing the type of a text markup annotation
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] Add support for changing the type of a text markup annotation
- Date: Sun, 16 Nov 2014 12:25:02 +0000 (UTC)
commit 46073c17781215f6ab8a4e4c2f20fb57f688aed5
Author: Carlos Garcia Campos <carlosgc gnome org>
Date: Sun Nov 16 13:23:07 2014 +0100
Add support for changing the type of a text markup annotation
backend/pdf/ev-poppler.cc | 87 +++++++++++++++++++++++++++++++
libdocument/ev-annotation.c | 15 +++++
libdocument/ev-annotation.h | 2 +
libdocument/ev-document-annotations.h | 25 +++++----
shell/ev-annotation-properties-dialog.c | 32 +++++++++++-
shell/ev-annotation-properties-dialog.h | 21 ++++----
shell/ev-window.c | 8 +++
7 files changed, 168 insertions(+), 22 deletions(-)
---
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index be05911..a9aaa13 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -3242,6 +3242,47 @@ pdf_document_annotations_add_annotation (EvDocumentAnnotations *document_annotat
pdf_document->annots_modified = TRUE;
}
+/* FIXME: We could probably add this to poppler */
+static void
+copy_poppler_annot (PopplerAnnot* src_annot,
+ PopplerAnnot* dst_annot)
+{
+ char *contents;
+ PopplerColor *color;
+
+ contents = poppler_annot_get_contents (src_annot);
+ poppler_annot_set_contents (dst_annot, contents);
+ g_free (contents);
+
+ poppler_annot_set_flags (dst_annot, poppler_annot_get_flags (src_annot));
+
+ color = poppler_annot_get_color (src_annot);
+ poppler_annot_set_color (dst_annot, color);
+ g_free (color);
+
+ if (EV_IS_ANNOTATION_MARKUP (src_annot)) {
+ PopplerAnnotMarkup *src_markup = POPPLER_ANNOT_MARKUP (src_annot);
+ PopplerAnnotMarkup *dst_markup = POPPLER_ANNOT_MARKUP (dst_annot);
+ char *label;
+
+ label = poppler_annot_markup_get_label (src_markup);
+ poppler_annot_markup_set_label (dst_markup, label);
+ g_free (label);
+
+ poppler_annot_markup_set_opacity (dst_markup, poppler_annot_markup_get_opacity (src_markup));
+
+ if (poppler_annot_markup_has_popup (src_markup)) {
+ PopplerRectangle popup_rect;
+
+ if (poppler_annot_markup_get_popup_rectangle (src_markup, &popup_rect)) {
+ poppler_annot_markup_set_popup (dst_markup, &popup_rect);
+ poppler_annot_markup_set_popup_is_open (dst_markup,
poppler_annot_markup_get_popup_is_open (src_markup));
+ }
+
+ }
+ }
+}
+
static void
pdf_document_annotations_save_annotation (EvDocumentAnnotations *document_annotations,
EvAnnotation *annot,
@@ -3296,6 +3337,52 @@ pdf_document_annotations_save_annotation (EvDocumentAnnotations *document_annota
}
}
+ if (EV_IS_ANNOTATION_TEXT_MARKUP (annot)) {
+ EvAnnotationTextMarkup *ev_text_markup = EV_ANNOTATION_TEXT_MARKUP (annot);
+ PopplerAnnotTextMarkup *text_markup = POPPLER_ANNOT_TEXT_MARKUP (poppler_annot);
+
+ if (mask & EV_ANNOTATIONS_SAVE_TEXT_MARKUP_TYPE) {
+ /* In poppler every text markup annotation type is a different class */
+ GArray *quads;
+ PopplerRectangle rect;
+ PopplerAnnot *new_annot = NULL;
+ PdfDocument *pdf_document;
+ EvPage *page;
+ PopplerPage *poppler_page;
+
+ pdf_document = PDF_DOCUMENT (document_annotations);
+
+ quads = poppler_annot_text_markup_get_quadrilaterals (text_markup);
+ poppler_annot_get_rectangle (POPPLER_ANNOT (text_markup), &rect);
+
+ switch (ev_annotation_text_markup_get_markup_type (ev_text_markup)) {
+ case EV_ANNOTATION_TEXT_MARKUP_HIGHLIGHT:
+ new_annot = poppler_annot_text_markup_new_highlight (pdf_document->document,
&rect, quads);
+ break;
+ case EV_ANNOTATION_TEXT_MARKUP_STRIKE_OUT:
+ new_annot = poppler_annot_text_markup_new_strikeout (pdf_document->document,
&rect, quads);
+ break;
+ case EV_ANNOTATION_TEXT_MARKUP_UNDERLINE:
+ new_annot = poppler_annot_text_markup_new_underline (pdf_document->document,
&rect, quads);
+ break;
+ }
+
+ g_array_unref (quads);
+
+ copy_poppler_annot (poppler_annot, new_annot);
+
+ page = ev_annotation_get_page (annot);
+ poppler_page = POPPLER_PAGE (page->backend_page);
+
+ poppler_page_remove_annot (poppler_page, poppler_annot);
+ poppler_page_add_annot (poppler_page, new_annot);
+ g_object_set_data_full (G_OBJECT (annot),
+ "poppler-annot",
+ new_annot,
+ (GDestroyNotify) g_object_unref);
+ }
+ }
+
PDF_DOCUMENT (document_annotations)->annots_modified = TRUE;
}
diff --git a/libdocument/ev-annotation.c b/libdocument/ev-annotation.c
index bb4fbd1..b77bef8 100644
--- a/libdocument/ev-annotation.c
+++ b/libdocument/ev-annotation.c
@@ -1367,3 +1367,18 @@ ev_annotation_text_markup_get_markup_type (EvAnnotationTextMarkup *annot)
return annot->type;
}
+
+gboolean
+ev_annotation_text_markup_set_markup_type (EvAnnotationTextMarkup *annot,
+ EvAnnotationTextMarkupType markup_type)
+{
+ g_return_val_if_fail (EV_IS_ANNOTATION_TEXT_MARKUP (annot), FALSE);
+
+ if (annot->type == markup_type)
+ return FALSE;
+
+ annot->type = markup_type;
+ g_object_notify (G_OBJECT (annot), "type");
+
+ return TRUE;
+}
diff --git a/libdocument/ev-annotation.h b/libdocument/ev-annotation.h
index b6c0d59..d9e0aaa 100644
--- a/libdocument/ev-annotation.h
+++ b/libdocument/ev-annotation.h
@@ -187,6 +187,8 @@ EvAnnotation *ev_annotation_text_markup_highlight_new (EvPage
EvAnnotation *ev_annotation_text_markup_strike_out_new (EvPage *page);
EvAnnotation *ev_annotation_text_markup_underline_new (EvPage *page);
EvAnnotationTextMarkupType ev_annotation_text_markup_get_markup_type (EvAnnotationTextMarkup *annot);
+gboolean ev_annotation_text_markup_set_markup_type (EvAnnotationTextMarkup *annot,
+ EvAnnotationTextMarkupType
markup_type);
G_END_DECLS
diff --git a/libdocument/ev-document-annotations.h b/libdocument/ev-document-annotations.h
index 5f2a98d..f0a9432 100644
--- a/libdocument/ev-document-annotations.h
+++ b/libdocument/ev-document-annotations.h
@@ -41,25 +41,28 @@ G_BEGIN_DECLS
#define EV_DOCUMENT_ANNOTATIONS_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst),
EV_TYPE_DOCUMENT_ANNOTATIONS, EvDocumentAnnotationsInterface))
typedef enum {
- EV_ANNOTATIONS_SAVE_NONE = 0,
- EV_ANNOTATIONS_SAVE_CONTENTS = 1 << 0,
- EV_ANNOTATIONS_SAVE_COLOR = 1 << 1,
+ EV_ANNOTATIONS_SAVE_NONE = 0,
+ EV_ANNOTATIONS_SAVE_CONTENTS = 1 << 0,
+ EV_ANNOTATIONS_SAVE_COLOR = 1 << 1,
/* Markup Annotations */
- EV_ANNOTATIONS_SAVE_LABEL = 1 << 2,
- EV_ANNOTATIONS_SAVE_OPACITY = 1 << 3,
- EV_ANNOTATIONS_SAVE_POPUP_RECT = 1 << 4,
- EV_ANNOTATIONS_SAVE_POPUP_IS_OPEN = 1 << 5,
+ EV_ANNOTATIONS_SAVE_LABEL = 1 << 2,
+ EV_ANNOTATIONS_SAVE_OPACITY = 1 << 3,
+ EV_ANNOTATIONS_SAVE_POPUP_RECT = 1 << 4,
+ EV_ANNOTATIONS_SAVE_POPUP_IS_OPEN = 1 << 5,
/* Text Annotations */
- EV_ANNOTATIONS_SAVE_TEXT_IS_OPEN = 1 << 6,
- EV_ANNOTATIONS_SAVE_TEXT_ICON = 1 << 7,
+ EV_ANNOTATIONS_SAVE_TEXT_IS_OPEN = 1 << 6,
+ EV_ANNOTATIONS_SAVE_TEXT_ICON = 1 << 7,
/* Attachment Annotations */
- EV_ANNOTATIONS_SAVE_ATTACHMENT = 1 << 8,
+ EV_ANNOTATIONS_SAVE_ATTACHMENT = 1 << 8,
+
+ /* Text Markup Annotations */
+ EV_ANNOTATIONS_SAVE_TEXT_MARKUP_TYPE = 1 << 9,
/* Save all */
- EV_ANNOTATIONS_SAVE_ALL = (1 << 9) - 1
+ EV_ANNOTATIONS_SAVE_ALL = (1 << 10) - 1
} EvAnnotationsSaveMask;
typedef struct _EvDocumentAnnotations EvDocumentAnnotations;
diff --git a/shell/ev-annotation-properties-dialog.c b/shell/ev-annotation-properties-dialog.c
index b850443..6cb25fd 100644
--- a/shell/ev-annotation-properties-dialog.c
+++ b/shell/ev-annotation-properties-dialog.c
@@ -44,6 +44,9 @@ struct _EvAnnotationPropertiesDialog {
/* Text Annotations */
GtkWidget *icon;
+
+ /* Text Markup Annotations */
+ GtkWidget *text_markup_type;
};
struct _EvAnnotationPropertiesDialogClass {
@@ -115,6 +118,22 @@ ev_annotation_properties_dialog_constructed (GObject *object)
break;
case EV_ANNOTATION_TYPE_ATTACHMENT:
/* TODO */
+ break;
+ case EV_ANNOTATION_TYPE_TEXT_MARKUP:
+ label = gtk_label_new (_("Markup type:"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
+ gtk_grid_attach (GTK_GRID (grid), label, 0, 5, 1, 1);
+ gtk_widget_show (label);
+
+ dialog->text_markup_type = gtk_combo_box_text_new ();
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->text_markup_type),
_("Highlight"));
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->text_markup_type), _("Strike
out"));
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->text_markup_type),
_("Underline"));
+ gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->text_markup_type), 0);
+ gtk_grid_attach (GTK_GRID (grid), dialog->text_markup_type, 1, 5, 1, 1);
+ gtk_widget_set_hexpand (dialog->text_markup_type, TRUE);
+ gtk_widget_show (dialog->text_markup_type);
+ break;
default:
break;
}
@@ -277,7 +296,12 @@ ev_annotation_properties_dialog_new_with_annotation (EvAnnotation *annot)
gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->icon),
ev_annotation_text_get_icon (annot_text));
- }
+ } else if (EV_IS_ANNOTATION_TEXT_MARKUP (annot)) {
+ EvAnnotationTextMarkup *annot_markup = EV_ANNOTATION_TEXT_MARKUP (annot);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->text_markup_type),
+ ev_annotation_text_markup_get_markup_type (annot_markup));
+ }
return GTK_WIDGET (dialog);
}
@@ -312,3 +336,9 @@ ev_annotation_properties_dialog_get_text_icon (EvAnnotationPropertiesDialog *dia
{
return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->icon));
}
+
+EvAnnotationTextMarkupType
+ev_annotation_properties_dialog_get_text_markup_type (EvAnnotationPropertiesDialog *dialog)
+{
+ return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->text_markup_type));
+}
diff --git a/shell/ev-annotation-properties-dialog.h b/shell/ev-annotation-properties-dialog.h
index c541e6a..acd55bd 100644
--- a/shell/ev-annotation-properties-dialog.h
+++ b/shell/ev-annotation-properties-dialog.h
@@ -38,16 +38,17 @@ G_BEGIN_DECLS
typedef struct _EvAnnotationPropertiesDialog EvAnnotationPropertiesDialog;
typedef struct _EvAnnotationPropertiesDialogClass EvAnnotationPropertiesDialogClass;
-GType ev_annotation_properties_dialog_get_type (void) G_GNUC_CONST;
-GtkWidget *ev_annotation_properties_dialog_new (EvAnnotationType
annot_type);
-GtkWidget *ev_annotation_properties_dialog_new_with_annotation (EvAnnotation
*annot);
-
-const gchar *ev_annotation_properties_dialog_get_author (EvAnnotationPropertiesDialog
*dialog);
-void ev_annotation_properties_dialog_get_rgba (EvAnnotationPropertiesDialog
*dialog,
- GdkRGBA *rgba);
-gdouble ev_annotation_properties_dialog_get_opacity (EvAnnotationPropertiesDialog
*dialog);
-gboolean ev_annotation_properties_dialog_get_popup_is_open (EvAnnotationPropertiesDialog
*dialog);
-EvAnnotationTextIcon ev_annotation_properties_dialog_get_text_icon (EvAnnotationPropertiesDialog
*dialog);
+GType ev_annotation_properties_dialog_get_type (void) G_GNUC_CONST;
+GtkWidget *ev_annotation_properties_dialog_new (EvAnnotationType
annot_type);
+GtkWidget *ev_annotation_properties_dialog_new_with_annotation (EvAnnotation
*annot);
+
+const gchar *ev_annotation_properties_dialog_get_author
(EvAnnotationPropertiesDialog *dialog);
+void ev_annotation_properties_dialog_get_rgba
(EvAnnotationPropertiesDialog *dialog,
+ GdkRGBA
*rgba);
+gdouble ev_annotation_properties_dialog_get_opacity
(EvAnnotationPropertiesDialog *dialog);
+gboolean ev_annotation_properties_dialog_get_popup_is_open
(EvAnnotationPropertiesDialog *dialog);
+EvAnnotationTextIcon ev_annotation_properties_dialog_get_text_icon
(EvAnnotationPropertiesDialog *dialog);
+EvAnnotationTextMarkupType ev_annotation_properties_dialog_get_text_markup_type
(EvAnnotationPropertiesDialog *dialog);
G_END_DECLS
diff --git a/shell/ev-window.c b/shell/ev-window.c
index e7f6a96..4d208f8 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -6486,6 +6486,14 @@ ev_window_popup_cmd_annot_properties (GSimpleAction *action,
mask |= EV_ANNOTATIONS_SAVE_TEXT_ICON;
}
+ if (EV_IS_ANNOTATION_TEXT_MARKUP (annot)) {
+ EvAnnotationTextMarkupType markup_type;
+
+ markup_type = ev_annotation_properties_dialog_get_text_markup_type (dialog);
+ if (ev_annotation_text_markup_set_markup_type (EV_ANNOTATION_TEXT_MARKUP (annot),
markup_type))
+ mask |= EV_ANNOTATIONS_SAVE_TEXT_MARKUP_TYPE;
+ }
+
if (mask != EV_ANNOTATIONS_SAVE_NONE) {
ev_document_doc_mutex_lock ();
ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (window->priv->document),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]