From bef2ba638f56bb3cb85ca0b9152f7ccfec68dc1d 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 5/9] 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. --- glib/poppler-annot.cc | 178 +++++++++++++++++++++++++++++++++++ glib/poppler-annot.h | 13 +++ glib/poppler-page.cc | 4 + glib/poppler-private.h | 1 + glib/poppler.h | 1 + glib/reference/poppler-sections.txt | 10 ++ 6 files changed, 207 insertions(+) diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc index 521b4e9..5f61b59 100644 --- a/glib/poppler-annot.cc +++ b/glib/poppler-annot.cc @@ -37,6 +37,7 @@ typedef struct _PopplerAnnotFileAttachmentClass PopplerAnnotFileAttachmentClass; typedef struct _PopplerAnnotMovieClass PopplerAnnotMovieClass; typedef struct _PopplerAnnotScreenClass PopplerAnnotScreenClass; typedef struct _PopplerAnnotLineClass PopplerAnnotLineClass; +typedef struct _PopplerAnnotGeometryClass PopplerAnnotGeometryClass; struct _PopplerAnnotClass { @@ -117,6 +118,16 @@ struct _PopplerAnnotLineClass PopplerAnnotMarkupClass parent_class; }; +struct _PopplerAnnotGeometry +{ + PopplerAnnotMarkup parent_instance; +}; + +struct _PopplerAnnotGeometryClass +{ + 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 +136,7 @@ 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 (PopplerAnnotGeometry, poppler_annot_geometry, POPPLER_TYPE_ANNOT_MARKUP) static PopplerAnnot * _poppler_create_annot (GType annot_type, Annot *annot) @@ -378,6 +390,85 @@ poppler_annot_line_new (PopplerDocument *doc, return _poppler_annot_line_new (annot); } +PopplerAnnot * +_poppler_annot_geometry_new (Annot *annot) +{ + return _poppler_create_annot (POPPLER_TYPE_ANNOT_GEOMETRY, annot); +} + +static void +poppler_annot_geometry_init (PopplerAnnotGeometry *poppler_annot) +{ +} + +static void +poppler_annot_geometry_class_init (PopplerAnnotGeometryClass *klass) +{ +} + +/** +* poppler_annot_geometry_new_circle: + * @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 #PopplerAnnotGeometry circle. +* +* Return value: a newly #PopplerAnnotGeometry annotation +* +* Since: 0.25 +**/ +PopplerAnnot * +poppler_annot_geometry_new_circle (PopplerDocument *doc, + PopplerRectangle *rect) +{ + Annot *annot; + AnnotBorderArray *border; + PDFRectangle pdf_rect(rect->x1, rect->y1, + rect->x2, rect->y2); + + border = new AnnotBorderArray (); + border->setWidth (1.5); + + annot = new AnnotGeometry (doc->doc, &pdf_rect, Annot::typeCircle); + annot->setBorder (border); + + return _poppler_annot_geometry_new (annot); +} + +/** + * poppler_annot_geometry_new_square: + * @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 #PopplerAnnotGeometry annotation + * + * Since: 0.25 +**/ +PopplerAnnot * +poppler_annot_geometry_new_square (PopplerDocument *doc, + PopplerRectangle *rect) +{ + Annot *annot; + AnnotBorderArray *border; + PDFRectangle pdf_rect(rect->x1, rect->y1, + rect->x2, rect->y2); + + border = new AnnotBorderArray (); + border->setWidth (1.5); + + annot = new AnnotGeometry (doc->doc, &pdf_rect, Annot::typeSquare); + annot->setBorder (border); + + return _poppler_annot_geometry_new (annot); +} /* Public methods */ /** @@ -1617,3 +1708,90 @@ poppler_annot_line_set_ending_style (PopplerAnnotLine *poppler_annot, annot->setStartEndStyle ((AnnotLineEndingStyle)start_style, (AnnotLineEndingStyle)end_style); } + +/* PopplerAnnotGeometry */ +/** + * poppler_annot_geometry_get_interior_color: + * @poppler_annot: a #PopplerAnnotGeometry + * + * 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.25 + */ +PopplerColor * +poppler_annot_geometry_get_interior_color (PopplerAnnotLine *poppler_annot) +{ + AnnotGeometry *annot; + AnnotColor *color; + PopplerColor *poppler_color = NULL; + + g_return_val_if_fail (POPPLER_IS_ANNOT_GEOMETRY (poppler_annot), NULL); + + annot = static_cast(POPPLER_ANNOT (poppler_annot)->annot); + color = annot->getInteriorColor (); + + if (color) { + const double *values = color->getValues (); + + switch (color->getSpace ()) + { + case AnnotColor::colorGray: + poppler_color = g_new (PopplerColor, 1); + + poppler_color->red = (guint16) (values[0] * 65535); + poppler_color->green = poppler_color->red; + poppler_color->blue = poppler_color->red; + + break; + case AnnotColor::colorRGB: + poppler_color = g_new (PopplerColor, 1); + + poppler_color->red = (guint16) (values[0] * 65535); + poppler_color->green = (guint16) (values[1] * 65535); + poppler_color->blue = (guint16) (values[2] * 65535); + + break; + case AnnotColor::colorCMYK: + g_warning ("Unsupported Annot Color: colorCMYK"); + case AnnotColor::colorTransparent: + break; + } + } + + return poppler_color; +} + +/** + * poppler_annot_geometry_set_interior_color: + * @poppler_annot: a #PopplerAnnot + * @poppler_color: (allow-none): a #PopplerColor, or %NULL + * + * Sets the interior color of @poppler_annot. + * + * Since: 0.25 + */ +void +poppler_annot_geometry_set_interior_color (PopplerAnnotGeometry *poppler_annot, + PopplerColor *poppler_color) +{ + AnnotGeometry *annot; + AnnotColor *color = NULL; + + g_return_if_fail (POPPLER_IS_ANNOT_GEOMETRY (poppler_annot)); + + annot = static_cast(POPPLER_ANNOT (poppler_annot)->annot); + + + 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 */ + annot->setInteriorColor (color); +} + diff --git a/glib/poppler-annot.h b/glib/poppler-annot.h index 825ffcf..0b547f9 100644 --- a/glib/poppler-annot.h +++ b/glib/poppler-annot.h @@ -60,6 +60,9 @@ G_BEGIN_DECLS #define POPPLER_TYPE_ANNOT_CALLOUT_LINE (poppler_annot_callout_line_get_type ()) +#define POPPLER_TYPE_ANNOT_GEOMETRY (poppler_annot_geometry_get_type ()) +#define POPPLER_ANNOT_GEOMETRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_GEOMETRY, PopplerAnnotGeometry)) +#define POPPLER_IS_ANNOT_GEOMETRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_GEOMETRY)) typedef enum { @@ -262,6 +265,16 @@ PopplerAnnotCalloutLine *poppler_annot_callout_line_new ( PopplerAnnotCalloutLine *poppler_annot_callout_line_copy (PopplerAnnotCalloutLine *callout); void poppler_annot_callout_line_free (PopplerAnnotCalloutLine *callout); +/* PopplerAnnotGeometry */ +GType poppler_annot_geometry_get_type (void) G_GNUC_CONST; +PopplerAnnot *poppler_annot_geometry_new_circle (PopplerDocument *doc, + PopplerRectangle *rect); +PopplerAnnot *poppler_annot_geometry_new_square (PopplerDocument *doc, + PopplerRectangle *rect); +void poppler_annot_geometry_set_interior_color (PopplerAnnotGeometry *poppler_annot, + PopplerColor *poppler_color); +PopplerColor *poppler_annot_geometry_get_interior_color (PopplerAnnotGeometry *poppler_annot); + G_END_DECLS #endif /* __POPPLER_ANNOT_H__ */ diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index 20fccb6..57a3f07 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -1378,6 +1378,10 @@ poppler_page_get_annot_mapping (PopplerPage *page) case Annot::typeLine: mapping->annot = _poppler_annot_line_new (annot); break; + case Annot::typeSquare: + case Annot::typeCircle: + mapping->annot = _poppler_annot_geometry_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..3cd5a4a 100644 --- a/glib/poppler-private.h +++ b/glib/poppler-private.h @@ -121,6 +121,7 @@ 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_geometry_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 a023515..db92752 100644 --- a/glib/poppler.h +++ b/glib/poppler.h @@ -203,6 +203,7 @@ typedef struct _PopplerAnnotMovie PopplerAnnotMovie; typedef struct _PopplerAnnotScreen PopplerAnnotScreen; typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine; typedef struct _PopplerAnnotLine PopplerAnnotLine; +typedef struct _PopplerAnnotGeometry PopplerAnnotGeometry; typedef enum { diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt index a2fb25f..566748c 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -372,6 +372,7 @@ PopplerAnnotMarkup PopplerAnnotText PopplerAnnotFreeText PopplerAnnotFileAttachment +PopplerAnnotGeometry PopplerAnnotLine PopplerAnnotLineEndingStyle PopplerAnnotMovie @@ -432,6 +433,10 @@ poppler_annot_movie_get_title poppler_annot_callout_line_new poppler_annot_callout_line_copy poppler_annot_callout_line_free +poppler_annot_geometry_new_circle +poppler_annot_geometry_new_square +poppler_annot_geometry_get_interior_color +poppler_annot_geometry_set_interior_color poppler_annot_line_new poppler_annot_line_set_vertices poppler_annot_line_set_width @@ -440,6 +445,7 @@ poppler_annot_line_get_end_style poppler_annot_line_get_start_style poppler_annot_line_set_ending_style + POPPLER_ANNOT POPPLER_IS_ANNOT @@ -450,6 +456,9 @@ POPPLER_TYPE_ANNOT_FILE_ATTACHMENT POPPLER_ANNOT_FREE_TEXT POPPLER_IS_ANNOT_FREE_TEXT POPPLER_TYPE_ANNOT_FREE_TEXT +POPPLER_ANNOT_GEOMETRY +POPPLER_IS_ANNOT_GEOMETRY +POPPLER_TYPE_ANNOT_GEOMETRY POPPLER_ANNOT_LINE POPPLER_IS_ANNOT_LINE POPPLER_TYPE_ANNOT_LINE @@ -490,6 +499,7 @@ 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_geometry_get_type
-- 1.7.9.5