From 589bf101dad00802ea80cdb00aa4b1dc32caa0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Poo-Caama=C3=B1o?= Date: Mon, 28 Oct 2013 22:48:39 -0700 Subject: [PATCH] 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 --- glib/poppler-annot.cc | 295 ++++++++++++++++++++++++++++++++--- glib/poppler-annot.h | 25 +++ glib/poppler-page.cc | 6 + glib/poppler-private.h | 2 + glib/poppler.h | 2 + glib/reference/poppler-sections.txt | 16 ++ 6 files changed, 321 insertions(+), 25 deletions(-) diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc index 9112f30..788c615 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,91 @@ 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() +* +* Creates a new empty #PopplerAnnotCircle circle. +* +* Return value: a newly #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 #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 +691,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 * +_poppler_new_poppler_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 +727,37 @@ poppler_annot_get_color (PopplerAnnot *poppler_annot) return poppler_color; } +static AnnotColor * +_poppler_new_annot_color (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); + } + + return color; +} + +/** + * 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 _poppler_new_poppler_color (poppler_annot->annot->getColor ()); +} + /** * poppler_annot_set_color: * @poppler_annot: a #PopplerAnnot @@ -646,16 +771,31 @@ void poppler_annot_set_color (PopplerAnnot *poppler_annot, PopplerColor *poppler_color) { - AnnotColor *color = NULL; + /* Annot takes ownership of the color */ + poppler_annot->annot->setColor (_poppler_new_annot_color (poppler_color)); +} - if (poppler_color) { - color = new AnnotColor ((double)poppler_color->red / 65535, - (double)poppler_color->green / 65535, - (double)poppler_color->blue / 65535); - } +/** + * poppler_annot_set_border_width: + * @poppler_annot: a #PopplerAnnot + * @line_width: the line width for the square or NULL for no line + * + * Set the border line width for the annotation @poppler_annot. + * + * Since: 0.26 + */ +void +poppler_annot_set_border_width (PopplerAnnot *poppler_annot, + gdouble line_width) +{ + AnnotBorderArray *border; - /* Annot takes ownership of the color */ - poppler_annot->annot->setColor (color); + g_return_if_fail (POPPLER_IS_ANNOT (poppler_annot)); + + border = new AnnotBorderArray (); + + border->setWidth (line_width); + poppler_annot->annot->setBorder (border); } /** @@ -1511,3 +1651,108 @@ poppler_annot_line_set_vertices (PopplerAnnotLine *poppler_annot, annot = static_cast(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; + + g_return_val_if_fail (POPPLER_IS_ANNOT_CIRCLE (poppler_annot) || + POPPLER_IS_ANNOT_SQUARE (poppler_annot), NULL); + + annot = static_cast(POPPLER_ANNOT (poppler_annot)->annot); + + return _poppler_new_poppler_color (annot->getInteriorColor ()); +} + +static void +_poppler_annot_geometry_set_interior_color (PopplerAnnot *poppler_annot, + PopplerColor *poppler_color) +{ + AnnotGeometry *annot; + + g_return_if_fail (POPPLER_IS_ANNOT_CIRCLE (poppler_annot) || + POPPLER_IS_ANNOT_SQUARE (poppler_annot)); + + annot = static_cast(POPPLER_ANNOT (poppler_annot)->annot); + + /* Annot takes ownership of the color */ + annot->setInteriorColor (_poppler_new_annot_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 #PopplerAnnot + * @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 #PopplerAnnot + * @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 6302be5..4657679 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 { @@ -171,6 +178,8 @@ void poppler_annot_set_flags ( PopplerColor *poppler_annot_get_color (PopplerAnnot *poppler_annot); void poppler_annot_set_color (PopplerAnnot *poppler_annot, PopplerColor *poppler_color); +void poppler_annot_set_border_width (PopplerAnnot *poppler_annot, + gdouble line_width); gint poppler_annot_get_page_index (PopplerAnnot *poppler_annot); void poppler_annot_get_rectangle (PopplerAnnot *poppler_annot, PopplerRectangle *poppler_rect); @@ -243,6 +252,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 fbab9b4..7619d90 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -1378,6 +1378,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 ce829e3..7293c8f 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -369,6 +369,7 @@ poppler_print_flags_get_type PopplerAnnot PopplerAnnot PopplerAnnotMarkup +PopplerAnnotCircle PopplerAnnotText PopplerAnnotFreeText PopplerAnnotFileAttachment @@ -382,6 +383,7 @@ PopplerAnnotMarkupReplyType PopplerAnnotTextState PopplerAnnotCalloutLine PopplerAnnotFreeTextQuadding +PopplerAnnotSquare PopplerPoint poppler_annot_get_annot_type poppler_annot_get_flags @@ -432,8 +434,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 @@ -443,6 +451,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 @@ -461,6 +472,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 @@ -488,6 +502,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
-- 1.7.9.5