[evince/wip/gpoo/204-annot-square-and-circle: 2/3] libdocument: Add square and circle annotations
- 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: 2/3] libdocument: Add square and circle annotations
- Date: Sun, 21 Jun 2020 02:11:37 +0000 (UTC)
commit 98afe5ac98302d5f19598116da3f3ca1045aa4d7
Author: Anuj Khare <khareanuj18 gmail com>
Date: Fri Jul 25 16:04:40 2014 +0200
libdocument: Add square and circle annotations
Adds the EV_ANNOTATION_CIRCLE and EV_ANNOTATION_SQUARE annotation types
along with their properties.
Extends fixes for #204
libdocument/ev-annotation.c | 402 ++++++++++++++++++++++++++++++++++
libdocument/ev-annotation.h | 45 ++++
libdocument/ev-document-annotations.h | 5 +-
3 files changed, 451 insertions(+), 1 deletion(-)
---
diff --git a/libdocument/ev-annotation.c b/libdocument/ev-annotation.c
index 1b466cb5..d78f1cdc 100644
--- a/libdocument/ev-annotation.c
+++ b/libdocument/ev-annotation.c
@@ -57,6 +57,28 @@ struct _EvAnnotationTextClass {
EvAnnotationClass parent_class;
};
+struct _EvAnnotationCircle {
+ EvAnnotation parent;
+
+ GdkRGBA interior_rgba;
+ gboolean has_interior_color;
+};
+
+struct _EvAnnotationCircleClass {
+ EvAnnotationClass parent_class;
+};
+
+struct _EvAnnotationSquare {
+ EvAnnotation parent;
+
+ GdkRGBA interior_rgba;
+ gboolean has_interior_color;
+};
+
+struct _EvAnnotationSquareClass {
+ EvAnnotationClass parent_class;
+};
+
struct _EvAnnotationAttachment {
EvAnnotation parent;
@@ -79,6 +101,8 @@ struct _EvAnnotationTextMarkupClass {
static void ev_annotation_markup_default_init (EvAnnotationMarkupInterface *iface);
static void ev_annotation_text_markup_iface_init (EvAnnotationMarkupInterface *iface);
+static void ev_annotation_circle_markup_iface_init (EvAnnotationMarkupInterface *iface);
+static void ev_annotation_square_markup_iface_init (EvAnnotationMarkupInterface *iface);
static void ev_annotation_attachment_markup_iface_init (EvAnnotationMarkupInterface *iface);
static void ev_annotation_text_markup_markup_iface_init (EvAnnotationMarkupInterface *iface);
@@ -111,6 +135,18 @@ enum {
PROP_TEXT_IS_OPEN
};
+/* EvAnnotationCircle */
+enum {
+ PROP_CIRCLE_INTERIOR_RGBA = PROP_MARKUP_POPUP_IS_OPEN + 1,
+ PROP_CIRCLE_HAS_INTERIOR_COLOR
+};
+
+/* EvAnnotationSquare */
+enum {
+ PROP_SQUARE_INTERIOR_RGBA = PROP_MARKUP_POPUP_IS_OPEN + 1,
+ PROP_SQUARE_HAS_INTERIOR_COLOR
+};
+
/* EvAnnotationAttachment */
enum {
PROP_ATTACHMENT_ATTACHMENT = PROP_MARKUP_POPUP_IS_OPEN + 1
@@ -128,6 +164,16 @@ G_DEFINE_TYPE_WITH_CODE (EvAnnotationText, ev_annotation_text, EV_TYPE_ANNOTATIO
G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
ev_annotation_text_markup_iface_init);
});
+G_DEFINE_TYPE_WITH_CODE (EvAnnotationCircle, ev_annotation_circle, EV_TYPE_ANNOTATION,
+ {
+ G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
+ ev_annotation_circle_markup_iface_init);
+ });
+G_DEFINE_TYPE_WITH_CODE (EvAnnotationSquare, ev_annotation_square, EV_TYPE_ANNOTATION,
+ {
+ G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
+ ev_annotation_square_markup_iface_init);
+ });
G_DEFINE_TYPE_WITH_CODE (EvAnnotationAttachment, ev_annotation_attachment, EV_TYPE_ANNOTATION,
{
G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
@@ -1231,6 +1277,362 @@ ev_annotation_text_set_is_open (EvAnnotationText *text,
return TRUE;
}
+/* EvAnnotationCircle */
+static void
+ev_annotation_circle_init (EvAnnotationCircle *annot)
+{
+ EV_ANNOTATION (annot)->type = EV_ANNOTATION_TYPE_CIRCLE;
+}
+
+static void
+ev_annotation_circle_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EvAnnotationCircle *annot = EV_ANNOTATION_CIRCLE (object);
+
+ if (prop_id < PROP_CIRCLE_INTERIOR_RGBA) {
+ ev_annotation_markup_set_property (object, prop_id, value, pspec);
+ return;
+ }
+
+ switch (prop_id) {
+ case PROP_CIRCLE_INTERIOR_RGBA:
+ ev_annotation_circle_set_interior_rgba (annot, g_value_get_boxed (value));
+ break;
+ case PROP_CIRCLE_HAS_INTERIOR_COLOR:
+ ev_annotation_circle_set_has_interior_color (annot, g_value_get_boolean (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ev_annotation_circle_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EvAnnotationCircle *annot = EV_ANNOTATION_CIRCLE (object);
+
+ if (prop_id < PROP_CIRCLE_INTERIOR_RGBA) {
+ ev_annotation_markup_get_property (object, prop_id, value, pspec);
+ return;
+ }
+
+ switch (prop_id) {
+ case PROP_CIRCLE_INTERIOR_RGBA:
+ g_value_set_boxed (value, &annot->interior_rgba);
+ break;
+ case PROP_CIRCLE_HAS_INTERIOR_COLOR:
+ g_value_set_boolean (value, ev_annotation_circle_get_has_interior_color (annot));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ev_annotation_circle_class_init (EvAnnotationCircleClass *klass)
+{
+ GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
+
+ ev_annotation_markup_class_install_properties (g_object_class);
+
+ g_object_class->set_property = ev_annotation_circle_set_property;
+ g_object_class->get_property = ev_annotation_circle_get_property;
+
+ g_object_class_install_property (g_object_class,
+ PROP_CIRCLE_INTERIOR_RGBA,
+ g_param_spec_boxed ("interior-rgba", NULL, NULL,
+ GDK_TYPE_RGBA,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (g_object_class,
+ PROP_CIRCLE_HAS_INTERIOR_COLOR,
+ g_param_spec_boolean ("has-interior-color",
+ "Has interior color",
+ "Whether the geometry annotation has "
+ "interior color set",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+ev_annotation_circle_markup_iface_init (EvAnnotationMarkupInterface *iface)
+{
+}
+
+EvAnnotation *
+ev_annotation_circle_new (EvPage *page)
+{
+ return EV_ANNOTATION (g_object_new (EV_TYPE_ANNOTATION_CIRCLE,
+ "page", page,
+ NULL));
+}
+
+/**
+ * ev_annotation_circle_get_interior_rgba:
+ * @annot: an #EvAnnotationCircle
+ * @rgba: (out): a #GdkRGBA to be filled with the annotation color
+ *
+ * Gets the interior color of @annot.
+ */
+void
+ev_annotation_circle_get_interior_rgba (EvAnnotationCircle *annot,
+ GdkRGBA *rgba)
+{
+ g_return_if_fail (EV_IS_ANNOTATION_CIRCLE (annot));
+ g_return_if_fail (rgba != NULL);
+
+ *rgba = annot->interior_rgba;
+}
+
+/**
+ * ev_annotation_circle_set_interior_rgba:
+ * @annot: an #EvAnnotationCircle
+ * @rgba: a #GdkRGBA
+ *
+ * Set the interior color of the annotation to @rgba.
+ *
+ * Returns: %TRUE if the color has been changed, %FALSE otherwise
+ */
+gboolean
+ev_annotation_circle_set_interior_rgba (EvAnnotationCircle *annot,
+ const GdkRGBA *rgba)
+{
+ g_return_val_if_fail (EV_IS_ANNOTATION_CIRCLE (annot), FALSE);
+ g_return_val_if_fail (rgba != NULL, FALSE);
+
+ if (gdk_rgba_equal (rgba, &annot->interior_rgba))
+ return FALSE;
+
+ annot->interior_rgba = *rgba;
+ g_object_notify (G_OBJECT (annot), "interior-rgba");
+
+ return TRUE;
+}
+
+/**
+ * ev_annotation_circle_get_has_interior_rgba:
+ * @annot: an #EvAnnotationCircle
+ *
+ * Gets whether @annot has interior color.
+ * Returns: %TRUE if the annotation has interior color, %FALSE otherwise
+ */
+gboolean
+ev_annotation_circle_get_has_interior_color (EvAnnotationCircle *annot)
+{
+ g_return_val_if_fail (EV_IS_ANNOTATION_CIRCLE (annot), FALSE);
+
+ return annot->has_interior_color;
+}
+
+/**
+ * ev_annotation_circle_set_has_interior_rgba:
+ * @annot: an #EvAnnotationCircle
+ *
+ * Sets whether @annot has interior color.
+ * Returns: %TRUE if the has interior color property has changed,
+ * %FALSE otherwise
+ */
+gboolean
+ev_annotation_circle_set_has_interior_color (EvAnnotationCircle *annot,
+ const gboolean has_interior_color)
+{
+ g_return_val_if_fail (EV_IS_ANNOTATION_CIRCLE (annot), FALSE);
+
+ if (has_interior_color == annot->has_interior_color)
+ return FALSE;
+
+ annot->has_interior_color = has_interior_color ;
+ g_object_notify (G_OBJECT (annot), "has-interior-color");
+
+ return TRUE;
+}
+
+/* EvAnnotationSquare */
+static void
+ev_annotation_square_init (EvAnnotationSquare *annot)
+{
+ EV_ANNOTATION (annot)->type = EV_ANNOTATION_TYPE_SQUARE;
+}
+
+static void
+ev_annotation_square_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EvAnnotationSquare *annot = EV_ANNOTATION_SQUARE (object);
+
+ if (prop_id < PROP_SQUARE_INTERIOR_RGBA) {
+ ev_annotation_markup_set_property (object, prop_id, value, pspec);
+ return;
+ }
+
+ switch (prop_id) {
+ case PROP_SQUARE_INTERIOR_RGBA:
+ ev_annotation_square_set_interior_rgba (annot, g_value_get_boxed (value));
+ break;
+ case PROP_SQUARE_HAS_INTERIOR_COLOR:
+ ev_annotation_square_set_has_interior_color (annot, g_value_get_boolean (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ev_annotation_square_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EvAnnotationSquare *annot = EV_ANNOTATION_SQUARE (object);
+
+ if (prop_id < PROP_SQUARE_INTERIOR_RGBA) {
+ ev_annotation_markup_get_property (object, prop_id, value, pspec);
+ return;
+ }
+
+ switch (prop_id) {
+ case PROP_SQUARE_INTERIOR_RGBA:
+ g_value_set_boxed (value, &annot->interior_rgba);
+ break;
+ case PROP_SQUARE_HAS_INTERIOR_COLOR:
+ g_value_set_boolean (value, annot->has_interior_color);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ev_annotation_square_class_init (EvAnnotationSquareClass *klass)
+{
+ GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
+
+ ev_annotation_markup_class_install_properties (g_object_class);
+
+ g_object_class->set_property = ev_annotation_square_set_property;
+ g_object_class->get_property = ev_annotation_square_get_property;
+
+ g_object_class_install_property (g_object_class,
+ PROP_SQUARE_INTERIOR_RGBA,
+ g_param_spec_boxed ("interior-rgba", NULL, NULL,
+ GDK_TYPE_RGBA,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (g_object_class,
+ PROP_SQUARE_HAS_INTERIOR_COLOR,
+ g_param_spec_boolean ("has-interior-color",
+ "Has interior color",
+ "Whether the geometry annotation has "
+ "interior color set",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+ev_annotation_square_markup_iface_init (EvAnnotationMarkupInterface *iface)
+{
+}
+
+EvAnnotation *
+ev_annotation_square_new (EvPage *page)
+{
+ return EV_ANNOTATION (g_object_new (EV_TYPE_ANNOTATION_SQUARE,
+ "page", page,
+ NULL));
+}
+
+/**
+ * ev_annotation_square_get_interior_rgba:
+ * @annot: an #EvAnnotationSquare
+ * @rgba: (out): a #GdkRGBA to be filled with the annotation color
+ *
+ * Gets the interior color of @annot.
+ */
+void
+ev_annotation_square_get_interior_rgba (EvAnnotationSquare *annot,
+ GdkRGBA *rgba)
+{
+ g_return_if_fail (EV_IS_ANNOTATION_SQUARE (annot));
+ g_return_if_fail (rgba != NULL);
+
+ *rgba = annot->interior_rgba;
+}
+
+/**
+ * ev_annotation_square_set_interior_rgba:
+ * @annot: an #EvAnnotationSquare
+ * @rgba: a #GdkRGBA
+ *
+ * Set the interior color of the annotation to @rgba.
+ *
+ * Returns: %TRUE if the color has been changed, %FALSE otherwise
+ */
+gboolean
+ev_annotation_square_set_interior_rgba (EvAnnotationSquare *annot,
+ const GdkRGBA *rgba)
+{
+ g_return_val_if_fail (EV_IS_ANNOTATION_SQUARE (annot), FALSE);
+ g_return_val_if_fail (rgba != NULL, FALSE);
+
+ if (gdk_rgba_equal (rgba, &annot->interior_rgba))
+ return FALSE;
+
+ annot->interior_rgba = *rgba;
+ g_object_notify (G_OBJECT (annot), "interior-rgba");
+
+ return TRUE;
+}
+
+/**
+ * ev_annotation_square_get_has_interior_rgba:
+ * @annot: an #EvAnnotationSquare
+ *
+ * Gets whether @annot has interior color.
+ * Returns: %TRUE if the annotation has interior color, %FALSE otherwise
+ */
+gboolean
+ev_annotation_square_get_has_interior_color (EvAnnotationSquare *annot)
+{
+ g_return_val_if_fail (EV_IS_ANNOTATION_SQUARE (annot), FALSE);
+
+ return annot->has_interior_color;
+}
+
+/**
+ * ev_annotation_square_set_has_interior_rgba:
+ * @annot: an #EvAnnotationSquare
+ *
+ * Sets whether @annot has interior color.
+ * Returns: %TRUE if the has interior color property has changed,
+ * %FALSE otherwise
+ */
+gboolean
+ev_annotation_square_set_has_interior_color (EvAnnotationSquare *annot,
+ const gboolean has_interior_color)
+{
+ g_return_val_if_fail (EV_IS_ANNOTATION_SQUARE (annot), FALSE);
+
+ if (has_interior_color == annot->has_interior_color)
+ return FALSE;
+
+ annot->has_interior_color = has_interior_color ;
+ g_object_notify (G_OBJECT (annot), "has-interior-color");
+
+ return TRUE;
+}
+
/* EvAnnotationAttachment */
static void
ev_annotation_attachment_finalize (GObject *object)
diff --git a/libdocument/ev-annotation.h b/libdocument/ev-annotation.h
index 69c6686f..baccf5d0 100644
--- a/libdocument/ev-annotation.h
+++ b/libdocument/ev-annotation.h
@@ -74,6 +74,22 @@ G_BEGIN_DECLS
#define EV_IS_ANNOTATION_TEXT_MARKUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
EV_TYPE_ANNOTATION_TEXT_MARKUP))
#define EV_ANNOTATION_TEXT_MARKUP_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object),
EV_TYPE_ANNOTATION_TEXT_MARKUP, EvAnnotationTextMarkupClass))
+/* EvAnnotationCircle */
+#define EV_TYPE_ANNOTATION_CIRCLE (ev_annotation_circle_get_type())
+#define EV_ANNOTATION_CIRCLE(object) (G_TYPE_CHECK_INSTANCE_CAST((object),
EV_TYPE_ANNOTATION_CIRCLE, EvAnnotationCircle))
+#define EV_ANNOTATION_CIRCLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),
EV_TYPE_ANNOTATION_CIRCLE, EvAnnotationCircleClass))
+#define EV_IS_ANNOTATION_CIRCLE(object) (G_TYPE_CHECK_INSTANCE_TYPE((object),
EV_TYPE_ANNOTATION_CIRCLE))
+#define EV_IS_ANNOTATION_CIRCLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),
EV_TYPE_ANNOTATION_CIRCLE))
+#define EV_ANNOTATION_CIRCLE_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object),
EV_TYPE_ANNOTATION_CIRCLE, EvAnnotationCircleClass))
+
+/* EvAnnotationSquare */
+#define EV_TYPE_ANNOTATION_SQUARE (ev_annotation_square_get_type())
+#define EV_ANNOTATION_SQUARE(object) (G_TYPE_CHECK_INSTANCE_CAST((object),
EV_TYPE_ANNOTATION_SQUARE, EvAnnotationSquare))
+#define EV_ANNOTATION_SQUARE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),
EV_TYPE_ANNOTATION_SQUARE, EvAnnotationSquareClass))
+#define EV_IS_ANNOTATION_SQUARE(object) (G_TYPE_CHECK_INSTANCE_TYPE((object),
EV_TYPE_ANNOTATION_SQUARE))
+#define EV_IS_ANNOTATION_SQUARE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),
EV_TYPE_ANNOTATION_SQUARE))
+#define EV_ANNOTATION_SQUARE_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object),
EV_TYPE_ANNOTATION_SQUARE, EvAnnotationSquareClass))
+
typedef struct _EvAnnotation EvAnnotation;
typedef struct _EvAnnotationClass EvAnnotationClass;
@@ -83,6 +99,12 @@ typedef struct _EvAnnotationMarkupInterface EvAnnotationMarkupInterface;
typedef struct _EvAnnotationText EvAnnotationText;
typedef struct _EvAnnotationTextClass EvAnnotationTextClass;
+typedef struct _EvAnnotationCircle EvAnnotationCircle;
+typedef struct _EvAnnotationCircleClass EvAnnotationCircleClass;
+
+typedef struct _EvAnnotationSquare EvAnnotationSquare;
+typedef struct _EvAnnotationSquareClass EvAnnotationSquareClass;
+
typedef struct _EvAnnotationAttachment EvAnnotationAttachment;
typedef struct _EvAnnotationAttachmentClass EvAnnotationAttachmentClass;
@@ -92,6 +114,8 @@ typedef struct _EvAnnotationTextMarkupClass EvAnnotationTextMarkupClass;
typedef enum {
EV_ANNOTATION_TYPE_UNKNOWN,
EV_ANNOTATION_TYPE_TEXT,
+ EV_ANNOTATION_TYPE_CIRCLE,
+ EV_ANNOTATION_TYPE_SQUARE,
EV_ANNOTATION_TYPE_ATTACHMENT,
EV_ANNOTATION_TYPE_TEXT_MARKUP
} EvAnnotationType;
@@ -181,6 +205,27 @@ gboolean ev_annotation_text_get_is_open (EvAnnotationText
gboolean ev_annotation_text_set_is_open (EvAnnotationText *text,
gboolean is_open);
+/* EvAnnotationCircle */
+GType ev_annotation_circle_get_type (void) G_GNUC_CONST;
+EvAnnotation *ev_annotation_circle_new (EvPage *page);
+void ev_annotation_circle_get_interior_rgba (EvAnnotationCircle *annot,
+ GdkRGBA *rgba);
+gboolean ev_annotation_circle_set_interior_rgba (EvAnnotationCircle *annot,
+ const GdkRGBA *rgba);
+gboolean ev_annotation_circle_get_has_interior_color (EvAnnotationCircle *annot);
+gboolean ev_annotation_circle_set_has_interior_color (EvAnnotationCircle *annot,
+ const gboolean
has_interior_color);
+/* EvAnnotationSquare */
+GType ev_annotation_square_get_type (void) G_GNUC_CONST;
+EvAnnotation *ev_annotation_square_new (EvPage *page);
+void ev_annotation_square_get_interior_rgba (EvAnnotationSquare *annot,
+ GdkRGBA *rgba);
+gboolean ev_annotation_square_set_interior_rgba (EvAnnotationSquare *annot,
+ const GdkRGBA *rgba);
+gboolean ev_annotation_square_get_has_interior_color (EvAnnotationSquare *annot);
+gboolean ev_annotation_square_set_has_interior_color (EvAnnotationSquare *annot,
+ const gboolean
has_interior_color);
+
/* EvAnnotationAttachment */
GType ev_annotation_attachment_get_type (void) G_GNUC_CONST;
EvAnnotation *ev_annotation_attachment_new (EvPage *page,
diff --git a/libdocument/ev-document-annotations.h b/libdocument/ev-document-annotations.h
index f0137c2b..e3c23a7a 100644
--- a/libdocument/ev-document-annotations.h
+++ b/libdocument/ev-document-annotations.h
@@ -62,8 +62,11 @@ typedef enum {
/* Text Markup Annotations */
EV_ANNOTATIONS_SAVE_TEXT_MARKUP_TYPE = 1 << 10,
+ /* Square/Circle Annotations */
+ EV_ANNOTATIONS_SAVE_INTERIOR_COLOR = 1 << 11,
+
/* Save all */
- EV_ANNOTATIONS_SAVE_ALL = (1 << 11) - 1
+ EV_ANNOTATIONS_SAVE_ALL = (1 << 12) - 1
} EvAnnotationsSaveMask;
typedef enum {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]