Commit b7a42280 authored by Enrico Lumetti's avatar Enrico Lumetti

Expose basic glib ink annotation interface and enable it in the demo

parent 5cdb78fd
......@@ -53,6 +53,7 @@ static const Annotations supported_annots[] = {
{ POPPLER_ANNOT_UNDERLINE, "Underline" },
{ POPPLER_ANNOT_SQUIGGLY, "Squiggly" },
{ POPPLER_ANNOT_STRIKE_OUT, "Strike Out" },
{ POPPLER_ANNOT_INK, "Ink"},
};
typedef enum {
......@@ -87,6 +88,8 @@ typedef struct {
GdkPoint stop;
GdkCursorType cursor;
guint annotations_idle;
GArray *ink_annot_points; // array of PopplerPoint
} PgdAnnotsDemo;
static void pgd_annots_viewer_queue_redraw (PgdAnnotsDemo *demo);
......@@ -369,7 +372,10 @@ pgd_annots_start_add_annot (GtkWidget *button,
-1);
demo->mode = MODE_ADD;
pgd_annots_update_cursor (demo, GDK_TCROSS);
if (demo->annot_type == POPPLER_ANNOT_INK)
pgd_annots_update_cursor (demo, GDK_PENCIL);
else
pgd_annots_update_cursor (demo, GDK_TCROSS);
}
static void
......@@ -976,6 +982,12 @@ pgd_annots_add_annot (PgdAnnotsDemo *demo)
g_array_free (quads_array, TRUE);
}
break;
case POPPLER_ANNOT_INK: {
annot = poppler_annot_ink_new (demo->doc, &rect);
demo->ink_annot_points = g_array_new(FALSE, TRUE, sizeof(PopplerPoint));
}
break;
default:
g_assert_not_reached ();
}
......@@ -993,6 +1005,10 @@ pgd_annots_finish_add_annot (PgdAnnotsDemo *demo)
{
g_assert (demo->mode == MODE_ADD || demo->mode == MODE_DRAWING);
if (demo->annot_type == POPPLER_ANNOT_INK) {
g_array_free(demo->ink_annot_points, TRUE);
}
demo->mode = MODE_NORMAL;
demo->start.x = -1;
pgd_annots_update_cursor (demo, GDK_LAST_CURSOR);
......@@ -1078,6 +1094,16 @@ pgd_annots_update_selected_text (PgdAnnotsDemo *demo)
g_list_free (l_rects);
}
static void
pgd_annot_update_ink_path (PgdAnnotsDemo *demo, gdouble x, gdouble y)
{
PopplerAnnotInk* annot = (PopplerAnnotInk*) demo->active_annot;
PopplerPoint p = { .x = (gdouble) x, .y = (gdouble) y };
g_array_append_val(demo->ink_annot_points, p);
poppler_annot_ink_set_single_path(annot, demo->ink_annot_points);
}
/* Render area */
static cairo_surface_t *
pgd_annots_render_page (PgdAnnotsDemo *demo)
......@@ -1220,6 +1246,9 @@ pgd_annots_drawing_area_motion_notify (GtkWidget *area,
if (POPPLER_IS_ANNOT_TEXT_MARKUP (demo->active_annot))
pgd_annots_update_selected_text (demo);
if (demo->annot_type == POPPLER_ANNOT_INK)
pgd_annot_update_ink_path (demo, rect.x2, rect.y2);
pgd_annot_view_set_annot (demo, demo->active_annot);
pgd_annots_viewer_queue_redraw (demo);
......
......@@ -23,6 +23,8 @@
#include "poppler.h"
#include "poppler-private.h"
#include <vector>
/**
* SECTION:poppler-annot
* @short_description: Annotations
......@@ -40,6 +42,7 @@ typedef struct _PopplerAnnotScreenClass PopplerAnnotScreenClass;
typedef struct _PopplerAnnotLineClass PopplerAnnotLineClass;
typedef struct _PopplerAnnotCircleClass PopplerAnnotCircleClass;
typedef struct _PopplerAnnotSquareClass PopplerAnnotSquareClass;
typedef struct _PopplerAnnotInkClass PopplerAnnotInkClass;
struct _PopplerAnnotClass
{
......@@ -150,6 +153,16 @@ struct _PopplerAnnotSquareClass
PopplerAnnotMarkupClass parent_class;
};
struct _PopplerAnnotInk
{
PopplerAnnotMarkup parent_instance;
};
struct _PopplerAnnotInkClass
{
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 (PopplerAnnotTextMarkup, poppler_annot_text_markup, POPPLER_TYPE_ANNOT_MARKUP)
......@@ -161,6 +174,7 @@ 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)
G_DEFINE_TYPE (PopplerAnnotInk, poppler_annot_ink, POPPLER_TYPE_ANNOT_INK)
static PopplerAnnot *
_poppler_create_annot (GType annot_type, Annot *annot)
......@@ -722,6 +736,50 @@ poppler_annot_square_new (PopplerDocument *doc,
return _poppler_annot_square_new (annot);
}
PopplerAnnot *
_poppler_annot_ink_new (Annot *annot)
{
return _poppler_create_annot (POPPLER_TYPE_ANNOT_INK, annot);
}
static void
poppler_annot_ink_init (PopplerAnnotInk *poppler_annot)
{
}
static void
poppler_annot_ink_class_init (PopplerAnnotInkClass *klass)
{
}
/**
* poppler_annot_ink_new:
* @doc: a #PopplerDocument
* @rect: a #PopplerRectangle
*
* Creates a new Ink annotation that will be
* located on @rect when added to a page. See
* poppler_page_add_annot()
*
* Return value: a newly created #PopplerAnnotInk annotation
*
* Since:
**/
PopplerAnnot *
poppler_annot_ink_new (PopplerDocument *doc,
PopplerRectangle *rect)
{
Annot *annot;
PDFRectangle pdf_rect(rect->x1, rect->y1,
rect->x2, rect->y2);
annot = new AnnotInk (doc->doc, &pdf_rect);
return _poppler_annot_ink_new (annot);
}
/* Public methods */
/**
* poppler_annot_get_annot_type:
......@@ -2081,3 +2139,21 @@ poppler_annot_square_set_interior_color (PopplerAnnotSquare *poppler_annot,
poppler_annot_geometry_set_interior_color (POPPLER_ANNOT (poppler_annot), poppler_color);
}
void
poppler_annot_ink_set_single_path(PopplerAnnotInk *poppler_annot, GArray* path_points)
{
g_return_if_fail (POPPLER_IS_ANNOT_INK (poppler_annot));
std::vector<AnnotCoord> coords;
coords.reserve(path_points->len);
for (guint i=0; i<path_points->len; i++) {
PopplerPoint* p = &g_array_index(path_points, PopplerPoint, i);
coords.emplace_back(AnnotCoord{p->x, p->y});
}
AnnotPath path{std::move(coords)};
AnnotPath* paths[] = { &path };
AnnotInk *annot = static_cast<AnnotInk*>(POPPLER_ANNOT (poppler_annot)->annot);
annot->setInkList(paths, 1);
}
......@@ -73,6 +73,10 @@ G_BEGIN_DECLS
#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))
#define POPPLER_TYPE_ANNOT_INK (poppler_annot_square_get_type ())
#define POPPLER_ANNOT_INK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_INK, PopplerAnnotInk))
#define POPPLER_IS_ANNOT_INK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_INK))
typedef enum
{
POPPLER_ANNOT_UNKNOWN,
......@@ -361,6 +365,15 @@ void poppler_annot_square_set_interior_color (
POPPLER_PUBLIC
PopplerColor *poppler_annot_square_get_interior_color (PopplerAnnotSquare *poppler_annot);
/* PopplerAnnotInk */
POPPLER_PUBLIC
GType poppler_annot_ink_get_type (void) G_GNUC_CONST;
POPPLER_PUBLIC
PopplerAnnot *poppler_annot_ink_new (PopplerDocument *doc,
PopplerRectangle *rect);
POPPLER_PUBLIC
void poppler_annot_ink_set_single_path (PopplerAnnotInk *poppler_annot,
GArray *path_points);
G_END_DECLS
#endif /* __POPPLER_ANNOT_H__ */
......@@ -139,6 +139,7 @@ PopplerAnnot *_poppler_annot_screen_new (PopplerDocument *doc, Annot *annot
PopplerAnnot *_poppler_annot_line_new (Annot *annot);
PopplerAnnot *_poppler_annot_circle_new (Annot *annot);
PopplerAnnot *_poppler_annot_square_new (Annot *annot);
PopplerAnnot *_poppler_annot_ink_new (Annot *annot);
const PDFRectangle *_poppler_annot_get_cropbox (PopplerAnnot *poppler_annot);
......
......@@ -207,6 +207,7 @@ typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine;
typedef struct _PopplerAnnotLine PopplerAnnotLine;
typedef struct _PopplerAnnotCircle PopplerAnnotCircle;
typedef struct _PopplerAnnotSquare PopplerAnnotSquare;
typedef struct _PopplerAnnotInk PopplerAnnotInk;
typedef struct _PopplerQuadrilateral PopplerQuadrilateral;
typedef struct _PopplerStructureElement PopplerStructureElement;
typedef struct _PopplerStructureElementIter PopplerStructureElementIter;
......
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