[poppler] 2 commits - glib/demo glib/poppler-annot.cc glib/poppler-annot.h glib/poppler.h glib/poppler-page.cc glib/poppler-private.h glib/reference
Carlos Garcia Campos
carlosgc at kemper.freedesktop.org
Thu Dec 5 09:27:38 PST 2013
glib/demo/annots.c | 19 ++
glib/poppler-annot.cc | 263 ++++++++++++++++++++++++++++++++----
glib/poppler-annot.h | 23 +++
glib/poppler-page.cc | 6
glib/poppler-private.h | 2
glib/poppler.h | 2
glib/reference/poppler-sections.txt | 16 ++
7 files changed, 305 insertions(+), 26 deletions(-)
New commits:
commit ab7da0bf62bb5032c4683d9cd841075d26045aae
Author: Germán Poo-Caamaño <gpoo at gnome.org>
Date: Mon Oct 28 22:52:22 2013 -0700
glib-demo: Add Square and Circle annotations demo
https://bugs.freedesktop.org/show_bug.cgi?id=70983
diff --git a/glib/demo/annots.c b/glib/demo/annots.c
index c71b923..6402501 100644
--- a/glib/demo/annots.c
+++ b/glib/demo/annots.c
@@ -851,6 +851,12 @@ pgd_annots_add_annot (PgdAnnotsDemo *demo)
&start, &end);
}
break;
+ case POPPLER_ANNOT_SQUARE:
+ annot = poppler_annot_square_new (demo->doc, &rect);
+ break;
+ case POPPLER_ANNOT_CIRCLE:
+ annot = poppler_annot_circle_new (demo->doc, &rect);
+ break;
default:
g_assert_not_reached ();
}
@@ -1113,6 +1119,19 @@ pgd_annots_create_widget (PopplerDocument *document)
SELECTED_TYPE_COLUMN, POPPLER_ANNOT_LINE,
SELECTED_LABEL_COLUMN, "Line",
-1);
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ SELECTED_TYPE_COLUMN, POPPLER_ANNOT_SQUARE,
+ SELECTED_LABEL_COLUMN, "Square",
+ -1);
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ SELECTED_TYPE_COLUMN, POPPLER_ANNOT_CIRCLE,
+ SELECTED_LABEL_COLUMN, "Circle",
+ -1);
+
demo->type_selector = gtk_combo_box_new_with_model (GTK_TREE_MODEL (model));
g_object_unref (model);
commit 2ec450567f27bba3ee4a08b5e69b7c9605bea4bb
Author: Germán Poo-Caamaño <gpoo at gnome.org>
Date: Mon Oct 28 22:48:39 2013 -0700
glib: Add implementation of Square and Circle annotations
Square and Circle only differ in the constructor which defines
the subtype. Therefore, it uses the same name than Poppler's
Geometry class.
https://bugs.freedesktop.org/show_bug.cgi?id=70983
diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index 9d073f6..6a1c05e 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -37,6 +37,8 @@ typedef struct _PopplerAnnotFileAttachmentClass PopplerAnnotFileAttachmentClass;
typedef struct _PopplerAnnotMovieClass PopplerAnnotMovieClass;
typedef struct _PopplerAnnotScreenClass PopplerAnnotScreenClass;
typedef struct _PopplerAnnotLineClass PopplerAnnotLineClass;
+typedef struct _PopplerAnnotCircleClass PopplerAnnotCircleClass;
+typedef struct _PopplerAnnotSquareClass PopplerAnnotSquareClass;
struct _PopplerAnnotClass
{
@@ -117,6 +119,26 @@ struct _PopplerAnnotLineClass
PopplerAnnotMarkupClass parent_class;
};
+struct _PopplerAnnotCircle
+{
+ PopplerAnnotMarkup parent_instance;
+};
+
+struct _PopplerAnnotCircleClass
+{
+ PopplerAnnotMarkupClass parent_class;
+};
+
+struct _PopplerAnnotSquare
+{
+ PopplerAnnotMarkup parent_instance;
+};
+
+struct _PopplerAnnotSquareClass
+{
+ PopplerAnnotMarkupClass parent_class;
+};
+
G_DEFINE_TYPE (PopplerAnnot, poppler_annot, G_TYPE_OBJECT)
G_DEFINE_TYPE (PopplerAnnotMarkup, poppler_annot_markup, POPPLER_TYPE_ANNOT)
G_DEFINE_TYPE (PopplerAnnotText, poppler_annot_text, POPPLER_TYPE_ANNOT_MARKUP)
@@ -125,6 +147,8 @@ G_DEFINE_TYPE (PopplerAnnotFileAttachment, poppler_annot_file_attachment, POPPLE
G_DEFINE_TYPE (PopplerAnnotMovie, poppler_annot_movie, POPPLER_TYPE_ANNOT)
G_DEFINE_TYPE (PopplerAnnotScreen, poppler_annot_screen, POPPLER_TYPE_ANNOT)
G_DEFINE_TYPE (PopplerAnnotLine, poppler_annot_line, POPPLER_TYPE_ANNOT_MARKUP)
+G_DEFINE_TYPE (PopplerAnnotCircle, poppler_annot_circle, POPPLER_TYPE_ANNOT_MARKUP)
+G_DEFINE_TYPE (PopplerAnnotSquare, poppler_annot_square, POPPLER_TYPE_ANNOT_MARKUP)
static PopplerAnnot *
_poppler_create_annot (GType annot_type, Annot *annot)
@@ -378,6 +402,89 @@ poppler_annot_line_new (PopplerDocument *doc,
return _poppler_annot_line_new (annot);
}
+PopplerAnnot *
+_poppler_annot_circle_new (Annot *annot)
+{
+ return _poppler_create_annot (POPPLER_TYPE_ANNOT_CIRCLE, annot);
+}
+
+static void
+poppler_annot_circle_init (PopplerAnnotCircle *poppler_annot)
+{
+}
+
+static void
+poppler_annot_circle_class_init (PopplerAnnotCircleClass *klass)
+{
+}
+
+/**
+ * poppler_annot_circle_new:
+ * @doc: a #PopplerDocument
+ * @rect: a #PopplerRectangle
+ *
+ * Creates a new Circle annotation that will be
+ * located on @rect when added to a page. See
+ * poppler_page_add_annot()
+ *
+ * Return value: a newly created #PopplerAnnotCircle annotation
+ *
+ * Since: 0.26
+ **/
+PopplerAnnot *
+poppler_annot_circle_new (PopplerDocument *doc,
+ PopplerRectangle *rect)
+{
+ Annot *annot;
+ PDFRectangle pdf_rect(rect->x1, rect->y1,
+ rect->x2, rect->y2);
+
+ annot = new AnnotGeometry (doc->doc, &pdf_rect, Annot::typeCircle);
+
+ return _poppler_annot_circle_new (annot);
+}
+
+PopplerAnnot *
+_poppler_annot_square_new (Annot *annot)
+{
+ return _poppler_create_annot (POPPLER_TYPE_ANNOT_SQUARE, annot);
+}
+
+static void
+poppler_annot_square_init (PopplerAnnotSquare *poppler_annot)
+{
+}
+
+static void
+poppler_annot_square_class_init (PopplerAnnotSquareClass *klass)
+{
+}
+
+/**
+ * poppler_annot_square_new:
+ * @doc: a #PopplerDocument
+ * @rect: a #PopplerRectangle
+ *
+ * Creates a new Square annotation that will be
+ * located on @rect when added to a page. See
+ * poppler_page_add_annot()
+ *
+ * Return value: a newly created #PopplerAnnotSquare annotation
+ *
+ * Since: 0.26
+**/
+PopplerAnnot *
+poppler_annot_square_new (PopplerDocument *doc,
+ PopplerRectangle *rect)
+{
+ Annot *annot;
+ PDFRectangle pdf_rect(rect->x1, rect->y1,
+ rect->x2, rect->y2);
+
+ annot = new AnnotGeometry (doc->doc, &pdf_rect, Annot::typeSquare);
+
+ return _poppler_annot_square_new (annot);
+}
/* Public methods */
/**
@@ -582,26 +689,11 @@ poppler_annot_set_flags (PopplerAnnot *poppler_annot, PopplerAnnotFlag flags)
poppler_annot->annot->setFlags ((guint) flags);
}
-
-/**
- * poppler_annot_get_color:
- * @poppler_annot: a #PopplerAnnot
- *
- * Retrieves the color of @poppler_annot.
- *
- * Return value: a new allocated #PopplerColor with the color values of
- * @poppler_annot, or %NULL. It must be freed with g_free() when done.
- **/
-PopplerColor *
-poppler_annot_get_color (PopplerAnnot *poppler_annot)
+static PopplerColor *
+create_poppler_color_from_annot_color (AnnotColor *color)
{
- AnnotColor *color;
PopplerColor *poppler_color = NULL;
- g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), NULL);
-
- color = poppler_annot->annot->getColor ();
-
if (color) {
const double *values = color->getValues ();
@@ -633,6 +725,34 @@ poppler_annot_get_color (PopplerAnnot *poppler_annot)
return poppler_color;
}
+static AnnotColor *
+create_annot_color_from_poppler_color (PopplerColor *poppler_color)
+{
+ if (!poppler_color)
+ return NULL;
+
+ return new AnnotColor ((double)poppler_color->red / 65535,
+ (double)poppler_color->green / 65535,
+ (double)poppler_color->blue / 65535);
+}
+
+/**
+ * poppler_annot_get_color:
+ * @poppler_annot: a #PopplerAnnot
+ *
+ * Retrieves the color of @poppler_annot.
+ *
+ * Return value: a new allocated #PopplerColor with the color values of
+ * @poppler_annot, or %NULL. It must be freed with g_free() when done.
+ **/
+PopplerColor *
+poppler_annot_get_color (PopplerAnnot *poppler_annot)
+{
+ g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), NULL);
+
+ return create_poppler_color_from_annot_color (poppler_annot->annot->getColor ());
+}
+
/**
* poppler_annot_set_color:
* @poppler_annot: a #PopplerAnnot
@@ -646,16 +766,8 @@ void
poppler_annot_set_color (PopplerAnnot *poppler_annot,
PopplerColor *poppler_color)
{
- AnnotColor *color = NULL;
-
- if (poppler_color) {
- color = new AnnotColor ((double)poppler_color->red / 65535,
- (double)poppler_color->green / 65535,
- (double)poppler_color->blue / 65535);
- }
-
/* Annot takes ownership of the color */
- poppler_annot->annot->setColor (color);
+ poppler_annot->annot->setColor (create_annot_color_from_poppler_color (poppler_color));
}
/**
@@ -1511,3 +1623,102 @@ poppler_annot_line_set_vertices (PopplerAnnotLine *poppler_annot,
annot = static_cast<AnnotLine *>(POPPLER_ANNOT (poppler_annot)->annot);
annot->setVertices (start->x, start->y, end->x, end->y);
}
+
+/* PopplerAnnotCircle and PopplerAnnotSquare helpers */
+static PopplerColor *
+poppler_annot_geometry_get_interior_color (PopplerAnnot *poppler_annot)
+{
+ AnnotGeometry *annot;
+
+ annot = static_cast<AnnotGeometry *>(POPPLER_ANNOT (poppler_annot)->annot);
+
+ return create_poppler_color_from_annot_color (annot->getInteriorColor ());
+}
+
+static void
+poppler_annot_geometry_set_interior_color (PopplerAnnot *poppler_annot,
+ PopplerColor *poppler_color)
+{
+ AnnotGeometry *annot;
+
+ annot = static_cast<AnnotGeometry *>(POPPLER_ANNOT (poppler_annot)->annot);
+
+ /* Annot takes ownership of the color */
+ annot->setInteriorColor (create_annot_color_from_poppler_color (poppler_color));
+}
+
+/* PopplerAnnotCircle */
+/**
+ * poppler_annot_circle_get_interior_color:
+ * @poppler_annot: a #PopplerAnnotCircle
+ *
+ * Retrieves the interior color of @poppler_annot.
+ *
+ * Return value: a new allocated #PopplerColor with the color values of
+ * @poppler_annot, or %NULL. It must be freed with g_free() when done.
+ *
+ * Since: 0.26
+ */
+PopplerColor *
+poppler_annot_circle_get_interior_color (PopplerAnnotCircle *poppler_annot)
+{
+ g_return_val_if_fail (POPPLER_IS_ANNOT_CIRCLE (poppler_annot), NULL);
+
+ return poppler_annot_geometry_get_interior_color (POPPLER_ANNOT (poppler_annot));
+}
+
+/**
+ * poppler_annot_circle_set_interior_color:
+ * @poppler_annot: a #PopplerAnnotCircle
+ * @poppler_color: (allow-none): a #PopplerColor, or %NULL
+ *
+ * Sets the interior color of @poppler_annot.
+ *
+ * Since: 0.26
+ */
+void
+poppler_annot_circle_set_interior_color (PopplerAnnotCircle *poppler_annot,
+ PopplerColor *poppler_color)
+{
+ g_return_if_fail (POPPLER_IS_ANNOT_CIRCLE (poppler_annot));
+
+ poppler_annot_geometry_set_interior_color (POPPLER_ANNOT (poppler_annot), poppler_color);
+}
+
+/* PopplerAnnotSquare */
+/**
+ * poppler_annot_square_get_interior_color:
+ * @poppler_annot: a #PopplerAnnotSquare
+ *
+ * Retrieves the interior color of @poppler_annot.
+ *
+ * Return value: a new allocated #PopplerColor with the color values of
+ * @poppler_annot, or %NULL. It must be freed with g_free() when done.
+ *
+ * Since: 0.26
+ */
+PopplerColor *
+poppler_annot_square_get_interior_color (PopplerAnnotSquare *poppler_annot)
+{
+ g_return_val_if_fail (POPPLER_IS_ANNOT_SQUARE (poppler_annot), NULL);
+
+ return poppler_annot_geometry_get_interior_color (POPPLER_ANNOT (poppler_annot));
+}
+
+/**
+ * poppler_annot_square_set_interior_color:
+ * @poppler_annot: a #PopplerAnnotSquare
+ * @poppler_color: (allow-none): a #PopplerColor, or %NULL
+ *
+ * Sets the interior color of @poppler_annot.
+ *
+ * Since: 0.26
+ */
+void
+poppler_annot_square_set_interior_color (PopplerAnnotSquare *poppler_annot,
+ PopplerColor *poppler_color)
+{
+ g_return_if_fail (POPPLER_IS_ANNOT_SQUARE (poppler_annot));
+
+ poppler_annot_geometry_set_interior_color (POPPLER_ANNOT (poppler_annot), poppler_color);
+}
diff --git a/glib/poppler-annot.h b/glib/poppler-annot.h
index 18091f8..300e815 100644
--- a/glib/poppler-annot.h
+++ b/glib/poppler-annot.h
@@ -60,6 +60,13 @@ G_BEGIN_DECLS
#define POPPLER_TYPE_ANNOT_CALLOUT_LINE (poppler_annot_callout_line_get_type ())
+#define POPPLER_TYPE_ANNOT_CIRCLE (poppler_annot_circle_get_type ())
+#define POPPLER_ANNOT_CIRCLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_CIRCLE, PopplerAnnotCircle))
+#define POPPLER_IS_ANNOT_CIRCLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_CIRCLE))
+
+#define POPPLER_TYPE_ANNOT_SQUARE (poppler_annot_square_get_type ())
+#define POPPLER_ANNOT_SQUARE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_SQUARE, PopplerAnnotSquare))
+#define POPPLER_IS_ANNOT_SQUARE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_SQUARE))
typedef enum
{
@@ -243,6 +250,22 @@ PopplerAnnotCalloutLine *poppler_annot_callout_line_new (
PopplerAnnotCalloutLine *poppler_annot_callout_line_copy (PopplerAnnotCalloutLine *callout);
void poppler_annot_callout_line_free (PopplerAnnotCalloutLine *callout);
+/* PopplerAnnotCircle */
+GType poppler_annot_circle_get_type (void) G_GNUC_CONST;
+PopplerAnnot *poppler_annot_circle_new (PopplerDocument *doc,
+ PopplerRectangle *rect);
+void poppler_annot_circle_set_interior_color (PopplerAnnotCircle *poppler_annot,
+ PopplerColor *poppler_color);
+PopplerColor *poppler_annot_circle_get_interior_color (PopplerAnnotCircle *poppler_annot);
+
+/* PopplerAnnotGeometry */
+GType poppler_annot_square_get_type (void) G_GNUC_CONST;
+PopplerAnnot *poppler_annot_square_new (PopplerDocument *doc,
+ PopplerRectangle *rect);
+void poppler_annot_square_set_interior_color (PopplerAnnotSquare *poppler_annot,
+ PopplerColor *poppler_color);
+PopplerColor *poppler_annot_square_get_interior_color (PopplerAnnotSquare *poppler_annot);
+
G_END_DECLS
#endif /* __POPPLER_ANNOT_H__ */
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index bb32473..a21be0f 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -1400,6 +1400,12 @@ poppler_page_get_annot_mapping (PopplerPage *page)
case Annot::typeLine:
mapping->annot = _poppler_annot_line_new (annot);
break;
+ case Annot::typeSquare:
+ mapping->annot = _poppler_annot_square_new (annot);
+ break;
+ case Annot::typeCircle:
+ mapping->annot = _poppler_annot_circle_new (annot);
+ break;
default:
mapping->annot = _poppler_annot_new (annot);
break;
diff --git a/glib/poppler-private.h b/glib/poppler-private.h
index bebe0c8..1a1dab9 100644
--- a/glib/poppler-private.h
+++ b/glib/poppler-private.h
@@ -121,6 +121,8 @@ PopplerAnnot *_poppler_annot_file_attachment_new (Annot *annot);
PopplerAnnot *_poppler_annot_movie_new (Annot *annot);
PopplerAnnot *_poppler_annot_screen_new (Annot *annot);
PopplerAnnot *_poppler_annot_line_new (Annot *annot);
+PopplerAnnot *_poppler_annot_circle_new (Annot *annot);
+PopplerAnnot *_poppler_annot_square_new (Annot *annot);
char *_poppler_goo_string_to_utf8(GooString *s);
gboolean _poppler_convert_pdf_date_to_gtime (GooString *date,
diff --git a/glib/poppler.h b/glib/poppler.h
index dd0df09..92121f6 100644
--- a/glib/poppler.h
+++ b/glib/poppler.h
@@ -204,6 +204,8 @@ typedef struct _PopplerAnnotMovie PopplerAnnotMovie;
typedef struct _PopplerAnnotScreen PopplerAnnotScreen;
typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine;
typedef struct _PopplerAnnotLine PopplerAnnotLine;
+typedef struct _PopplerAnnotCircle PopplerAnnotCircle;
+typedef struct _PopplerAnnotSquare PopplerAnnotSquare;
typedef enum
{
diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt
index 62e0f77..9bf2a05 100644
--- a/glib/reference/poppler-sections.txt
+++ b/glib/reference/poppler-sections.txt
@@ -372,6 +372,7 @@ poppler_print_flags_get_type
<TITLE>PopplerAnnot</TITLE>
PopplerAnnot
PopplerAnnotMarkup
+PopplerAnnotCircle
PopplerAnnotText
PopplerAnnotFreeText
PopplerAnnotFileAttachment
@@ -385,6 +386,7 @@ PopplerAnnotMarkupReplyType
PopplerAnnotTextState
PopplerAnnotCalloutLine
PopplerAnnotFreeTextQuadding
+PopplerAnnotSquare
PopplerPoint
poppler_annot_get_annot_type
poppler_annot_get_flags
@@ -435,8 +437,14 @@ poppler_annot_movie_get_title
poppler_annot_callout_line_new
poppler_annot_callout_line_copy
poppler_annot_callout_line_free
+poppler_annot_circle_new
+poppler_annot_circle_get_interior_color
+poppler_annot_circle_set_interior_color
poppler_annot_line_new
poppler_annot_line_set_vertices
+poppler_annot_square_new
+poppler_annot_square_get_interior_color
+poppler_annot_square_set_interior_color
poppler_point_copy
poppler_point_free
poppler_point_get_type
@@ -446,6 +454,9 @@ poppler_point_new
POPPLER_ANNOT
POPPLER_IS_ANNOT
POPPLER_TYPE_ANNOT
+POPPLER_ANNOT_CIRCLE
+POPPLER_IS_ANNOT_CIRCLE
+POPPLER_TYPE_ANNOT_CIRCLE
POPPLER_ANNOT_FILE_ATTACHMENT
POPPLER_IS_ANNOT_FILE_ATTACHMENT
POPPLER_TYPE_ANNOT_FILE_ATTACHMENT
@@ -464,6 +475,9 @@ POPPLER_TYPE_ANNOT_MOVIE
POPPLER_ANNOT_SCREEN
POPPLER_IS_ANNOT_SCREEN
POPPLER_TYPE_ANNOT_SCREEN
+POPPLER_ANNOT_SQUARE
+POPPLER_IS_ANNOT_SQUARE
+POPPLER_TYPE_ANNOT_SQUARE
POPPLER_ANNOT_TEXT
POPPLER_IS_ANNOT_TEXT
POPPLER_TYPE_ANNOT_TEXT
@@ -491,6 +505,8 @@ poppler_annot_callout_line_get_type
poppler_annot_text_state_get_type
poppler_annot_free_text_quadding_get_type
poppler_annot_line_get_type
+poppler_annot_circle_get_type
+poppler_annot_square_get_type
</SECTION>
<SECTION>
More information about the poppler
mailing list