Commit 2ec45056 authored by Germán Poo-Caamaño's avatar Germán Poo-Caamaño Committed by Carlos Garcia Campos

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
parent e109cf24
...@@ -37,6 +37,8 @@ typedef struct _PopplerAnnotFileAttachmentClass PopplerAnnotFileAttachmentClass; ...@@ -37,6 +37,8 @@ typedef struct _PopplerAnnotFileAttachmentClass PopplerAnnotFileAttachmentClass;
typedef struct _PopplerAnnotMovieClass PopplerAnnotMovieClass; typedef struct _PopplerAnnotMovieClass PopplerAnnotMovieClass;
typedef struct _PopplerAnnotScreenClass PopplerAnnotScreenClass; typedef struct _PopplerAnnotScreenClass PopplerAnnotScreenClass;
typedef struct _PopplerAnnotLineClass PopplerAnnotLineClass; typedef struct _PopplerAnnotLineClass PopplerAnnotLineClass;
typedef struct _PopplerAnnotCircleClass PopplerAnnotCircleClass;
typedef struct _PopplerAnnotSquareClass PopplerAnnotSquareClass;
struct _PopplerAnnotClass struct _PopplerAnnotClass
{ {
...@@ -117,6 +119,26 @@ struct _PopplerAnnotLineClass ...@@ -117,6 +119,26 @@ struct _PopplerAnnotLineClass
PopplerAnnotMarkupClass parent_class; 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 (PopplerAnnot, poppler_annot, G_TYPE_OBJECT)
G_DEFINE_TYPE (PopplerAnnotMarkup, poppler_annot_markup, POPPLER_TYPE_ANNOT) G_DEFINE_TYPE (PopplerAnnotMarkup, poppler_annot_markup, POPPLER_TYPE_ANNOT)
G_DEFINE_TYPE (PopplerAnnotText, poppler_annot_text, POPPLER_TYPE_ANNOT_MARKUP) G_DEFINE_TYPE (PopplerAnnotText, poppler_annot_text, POPPLER_TYPE_ANNOT_MARKUP)
...@@ -125,6 +147,8 @@ G_DEFINE_TYPE (PopplerAnnotFileAttachment, poppler_annot_file_attachment, POPPLE ...@@ -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 (PopplerAnnotMovie, poppler_annot_movie, POPPLER_TYPE_ANNOT)
G_DEFINE_TYPE (PopplerAnnotScreen, poppler_annot_screen, 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 (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 * static PopplerAnnot *
_poppler_create_annot (GType annot_type, Annot *annot) _poppler_create_annot (GType annot_type, Annot *annot)
...@@ -378,6 +402,89 @@ poppler_annot_line_new (PopplerDocument *doc, ...@@ -378,6 +402,89 @@ poppler_annot_line_new (PopplerDocument *doc,
return _poppler_annot_line_new (annot); 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 */ /* Public methods */
/** /**
...@@ -582,26 +689,11 @@ poppler_annot_set_flags (PopplerAnnot *poppler_annot, PopplerAnnotFlag flags) ...@@ -582,26 +689,11 @@ poppler_annot_set_flags (PopplerAnnot *poppler_annot, PopplerAnnotFlag flags)
poppler_annot->annot->setFlags ((guint) flags); poppler_annot->annot->setFlags ((guint) flags);
} }
static PopplerColor *
/** create_poppler_color_from_annot_color (AnnotColor *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)
{ {
AnnotColor *color;
PopplerColor *poppler_color = NULL; PopplerColor *poppler_color = NULL;
g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), NULL);
color = poppler_annot->annot->getColor ();
if (color) { if (color) {
const double *values = color->getValues (); const double *values = color->getValues ();
...@@ -633,6 +725,34 @@ poppler_annot_get_color (PopplerAnnot *poppler_annot) ...@@ -633,6 +725,34 @@ poppler_annot_get_color (PopplerAnnot *poppler_annot)
return poppler_color; 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_set_color:
* @poppler_annot: a #PopplerAnnot * @poppler_annot: a #PopplerAnnot
...@@ -646,16 +766,8 @@ void ...@@ -646,16 +766,8 @@ void
poppler_annot_set_color (PopplerAnnot *poppler_annot, poppler_annot_set_color (PopplerAnnot *poppler_annot,
PopplerColor *poppler_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);
}
/* Annot takes ownership of the color */ /* 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, ...@@ -1511,3 +1623,102 @@ poppler_annot_line_set_vertices (PopplerAnnotLine *poppler_annot,
annot = static_cast<AnnotLine *>(POPPLER_ANNOT (poppler_annot)->annot); annot = static_cast<AnnotLine *>(POPPLER_ANNOT (poppler_annot)->annot);
annot->setVertices (start->x, start->y, end->x, end->y); 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);
}
...@@ -60,6 +60,13 @@ G_BEGIN_DECLS ...@@ -60,6 +60,13 @@ G_BEGIN_DECLS
#define POPPLER_TYPE_ANNOT_CALLOUT_LINE (poppler_annot_callout_line_get_type ()) #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 typedef enum
{ {
...@@ -243,6 +250,22 @@ PopplerAnnotCalloutLine *poppler_annot_callout_line_new ( ...@@ -243,6 +250,22 @@ PopplerAnnotCalloutLine *poppler_annot_callout_line_new (
PopplerAnnotCalloutLine *poppler_annot_callout_line_copy (PopplerAnnotCalloutLine *callout); PopplerAnnotCalloutLine *poppler_annot_callout_line_copy (PopplerAnnotCalloutLine *callout);
void poppler_annot_callout_line_free (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 G_END_DECLS
#endif /* __POPPLER_ANNOT_H__ */ #endif /* __POPPLER_ANNOT_H__ */
...@@ -1400,6 +1400,12 @@ poppler_page_get_annot_mapping (PopplerPage *page) ...@@ -1400,6 +1400,12 @@ poppler_page_get_annot_mapping (PopplerPage *page)
case Annot::typeLine: case Annot::typeLine:
mapping->annot = _poppler_annot_line_new (annot); mapping->annot = _poppler_annot_line_new (annot);
break; break;
case Annot::typeSquare:
mapping->annot = _poppler_annot_square_new (annot);
break;
case Annot::typeCircle:
mapping->annot = _poppler_annot_circle_new (annot);
break;
default: default:
mapping->annot = _poppler_annot_new (annot); mapping->annot = _poppler_annot_new (annot);
break; break;
......
...@@ -121,6 +121,8 @@ PopplerAnnot *_poppler_annot_file_attachment_new (Annot *annot); ...@@ -121,6 +121,8 @@ PopplerAnnot *_poppler_annot_file_attachment_new (Annot *annot);
PopplerAnnot *_poppler_annot_movie_new (Annot *annot); PopplerAnnot *_poppler_annot_movie_new (Annot *annot);
PopplerAnnot *_poppler_annot_screen_new (Annot *annot); PopplerAnnot *_poppler_annot_screen_new (Annot *annot);
PopplerAnnot *_poppler_annot_line_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); char *_poppler_goo_string_to_utf8(GooString *s);
gboolean _poppler_convert_pdf_date_to_gtime (GooString *date, gboolean _poppler_convert_pdf_date_to_gtime (GooString *date,
......
...@@ -204,6 +204,8 @@ typedef struct _PopplerAnnotMovie PopplerAnnotMovie; ...@@ -204,6 +204,8 @@ typedef struct _PopplerAnnotMovie PopplerAnnotMovie;
typedef struct _PopplerAnnotScreen PopplerAnnotScreen; typedef struct _PopplerAnnotScreen PopplerAnnotScreen;
typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine; typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine;
typedef struct _PopplerAnnotLine PopplerAnnotLine; typedef struct _PopplerAnnotLine PopplerAnnotLine;
typedef struct _PopplerAnnotCircle PopplerAnnotCircle;
typedef struct _PopplerAnnotSquare PopplerAnnotSquare;
typedef enum typedef enum
{ {
......
...@@ -372,6 +372,7 @@ poppler_print_flags_get_type ...@@ -372,6 +372,7 @@ poppler_print_flags_get_type
<TITLE>PopplerAnnot</TITLE> <TITLE>PopplerAnnot</TITLE>
PopplerAnnot PopplerAnnot
PopplerAnnotMarkup PopplerAnnotMarkup
PopplerAnnotCircle
PopplerAnnotText PopplerAnnotText
PopplerAnnotFreeText PopplerAnnotFreeText
PopplerAnnotFileAttachment PopplerAnnotFileAttachment
...@@ -385,6 +386,7 @@ PopplerAnnotMarkupReplyType ...@@ -385,6 +386,7 @@ PopplerAnnotMarkupReplyType
PopplerAnnotTextState PopplerAnnotTextState
PopplerAnnotCalloutLine PopplerAnnotCalloutLine
PopplerAnnotFreeTextQuadding PopplerAnnotFreeTextQuadding
PopplerAnnotSquare
PopplerPoint PopplerPoint
poppler_annot_get_annot_type poppler_annot_get_annot_type
poppler_annot_get_flags poppler_annot_get_flags
...@@ -435,8 +437,14 @@ poppler_annot_movie_get_title ...@@ -435,8 +437,14 @@ poppler_annot_movie_get_title
poppler_annot_callout_line_new poppler_annot_callout_line_new
poppler_annot_callout_line_copy poppler_annot_callout_line_copy
poppler_annot_callout_line_free 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_new
poppler_annot_line_set_vertices 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_copy
poppler_point_free poppler_point_free
poppler_point_get_type poppler_point_get_type
...@@ -446,6 +454,9 @@ poppler_point_new ...@@ -446,6 +454,9 @@ poppler_point_new
POPPLER_ANNOT POPPLER_ANNOT
POPPLER_IS_ANNOT POPPLER_IS_ANNOT
POPPLER_TYPE_ANNOT POPPLER_TYPE_ANNOT
POPPLER_ANNOT_CIRCLE
POPPLER_IS_ANNOT_CIRCLE
POPPLER_TYPE_ANNOT_CIRCLE
POPPLER_ANNOT_FILE_ATTACHMENT POPPLER_ANNOT_FILE_ATTACHMENT
POPPLER_IS_ANNOT_FILE_ATTACHMENT POPPLER_IS_ANNOT_FILE_ATTACHMENT
POPPLER_TYPE_ANNOT_FILE_ATTACHMENT POPPLER_TYPE_ANNOT_FILE_ATTACHMENT
...@@ -464,6 +475,9 @@ POPPLER_TYPE_ANNOT_MOVIE ...@@ -464,6 +475,9 @@ POPPLER_TYPE_ANNOT_MOVIE
POPPLER_ANNOT_SCREEN POPPLER_ANNOT_SCREEN
POPPLER_IS_ANNOT_SCREEN POPPLER_IS_ANNOT_SCREEN
POPPLER_TYPE_ANNOT_SCREEN POPPLER_TYPE_ANNOT_SCREEN
POPPLER_ANNOT_SQUARE
POPPLER_IS_ANNOT_SQUARE
POPPLER_TYPE_ANNOT_SQUARE
POPPLER_ANNOT_TEXT POPPLER_ANNOT_TEXT
POPPLER_IS_ANNOT_TEXT POPPLER_IS_ANNOT_TEXT
POPPLER_TYPE_ANNOT_TEXT POPPLER_TYPE_ANNOT_TEXT
...@@ -491,6 +505,8 @@ poppler_annot_callout_line_get_type ...@@ -491,6 +505,8 @@ poppler_annot_callout_line_get_type
poppler_annot_text_state_get_type poppler_annot_text_state_get_type
poppler_annot_free_text_quadding_get_type poppler_annot_free_text_quadding_get_type
poppler_annot_line_get_type poppler_annot_line_get_type
poppler_annot_circle_get_type
poppler_annot_square_get_type
</SECTION> </SECTION>
<SECTION> <SECTION>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment