glib/demo/annots.c | 236 +++++++++++++++++++++++++++--- glib/poppler-annot.cc | 276 +++++++++++++++++++++++++++++++++++- glib/poppler-annot.h | 27 +++ glib/poppler-page.cc | 59 +++++++ glib/poppler-page.h | 33 ++++ glib/poppler-private.h | 1 glib/poppler.h | 2 glib/reference/poppler-sections.txt | 17 ++ poppler/Annot.cc | 1 9 files changed, 620 insertions(+), 32 deletions(-)
New commits: commit f99128e38bbff43623d5cd1c1bc27fd789d0bc0c Author: Carlos Garcia Campos <[email protected]> Date: Sun Jan 19 16:03:35 2014 +0100 glib: Make vertices a constructor parameter of line annotations It's a required field in the line annotation. diff --git a/glib/demo/annots.c b/glib/demo/annots.c index bb4a742..696297c 100644 --- a/glib/demo/annots.c +++ b/glib/demo/annots.c @@ -936,9 +936,7 @@ pgd_annots_add_annot (PgdAnnotsDemo *demo) end.x = rect.x2; end.y = rect.y2; - annot = poppler_annot_line_new (demo->doc, &rect); - poppler_annot_line_set_vertices (POPPLER_ANNOT_LINE (annot), - &start, &end); + annot = poppler_annot_line_new (demo->doc, &rect, &start, &end); } break; case POPPLER_ANNOT_SQUARE: diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc index a4c0087..3d6ce7e 100644 --- a/glib/poppler-annot.cc +++ b/glib/poppler-annot.cc @@ -594,6 +594,8 @@ poppler_annot_line_class_init (PopplerAnnotLineClass *klass) * poppler_annot_line_new: * @doc: a #PopplerDocument * @rect: a #PopplerRectangle + * @start: a #PopplerPoint of the starting vertice + * @end: a #PopplerPoint of the ending vertice * * Creates a new Line annotation that will be * located on @rect when added to a page. See @@ -605,15 +607,21 @@ poppler_annot_line_class_init (PopplerAnnotLineClass *klass) */ PopplerAnnot * poppler_annot_line_new (PopplerDocument *doc, - PopplerRectangle *rect) + PopplerRectangle *rect, + PopplerPoint *start, + PopplerPoint *end) { + PopplerAnnot *poppler_annot; Annot *annot; PDFRectangle pdf_rect(rect->x1, rect->y1, rect->x2, rect->y2); annot = new AnnotLine (doc->doc, &pdf_rect); - return _poppler_annot_line_new (annot); + poppler_annot = _poppler_annot_line_new (annot); + poppler_annot_line_set_vertices (POPPLER_ANNOT_LINE (poppler_annot), + start, end); + return poppler_annot; } PopplerAnnot * diff --git a/glib/poppler-annot.h b/glib/poppler-annot.h index 297df03..441563e 100644 --- a/glib/poppler-annot.h +++ b/glib/poppler-annot.h @@ -262,7 +262,9 @@ PopplerAction *poppler_annot_screen_get_action ( /* PopplerAnnotLine */ GType poppler_annot_line_get_type (void) G_GNUC_CONST; PopplerAnnot *poppler_annot_line_new (PopplerDocument *doc, - PopplerRectangle *rect); + PopplerRectangle *rect, + PopplerPoint *start, + PopplerPoint *end); void poppler_annot_line_set_vertices (PopplerAnnotLine *poppler_annot, PopplerPoint *start, PopplerPoint *end); commit 587a40f90e4ac5a1b6ab9044495a1ae403bc8c58 Author: Carlos Garcia Campos <[email protected]> Date: Sun Jan 19 15:58:43 2014 +0100 annots: Fix memory leak when setting AnnotTextMarkup quads twice diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 90a6e5d..ab48be6 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -3706,6 +3706,7 @@ void AnnotTextMarkup::setQuadrilaterals(AnnotQuadrilaterals *quadPoints) { obj1.arrayAdd (obj2.initReal (quadPoints->getY4(i))); } + delete quadrilaterals; quadrilaterals = new AnnotQuadrilaterals(obj1.getArray(), rect); annotObj.dictSet ("QuadPoints", &obj1); commit 69e73da1fbab9bf3365b40dced1008b0283ac931 Author: Germán Poo-Caamaño <[email protected]> Date: Wed Nov 20 11:53:30 2013 -0800 glib-demo: Add support for PopplerTextAnnotMarkup * The subtypes are: Highlihght, Squiggly, StrikeOut and Underline. * Use ScrolledWindow for annotation properties to make room to show the Quadrilaterals of TextMarkup annotations. https://bugs.freedesktop.org/show_bug.cgi?id=51487 diff --git a/glib/demo/annots.c b/glib/demo/annots.c index 6402501..bb4a742 100644 --- a/glib/demo/annots.c +++ b/glib/demo/annots.c @@ -38,6 +38,23 @@ enum { SELECTED_N_COLUMNS }; +typedef struct +{ + const guint type; + const gchar *label; +} Annotations; + +static Annotations supported_annots[] = { + { POPPLER_ANNOT_TEXT, "Text" }, + { POPPLER_ANNOT_LINE, "Line" }, + { POPPLER_ANNOT_SQUARE, "Square" }, + { POPPLER_ANNOT_CIRCLE, "Circle" }, + { POPPLER_ANNOT_HIGHLIGHT, "Highlight" }, + { POPPLER_ANNOT_UNDERLINE, "Underline" }, + { POPPLER_ANNOT_SQUIGGLY, "Squiggly" }, + { POPPLER_ANNOT_STRIKE_OUT, "Strike Out" }, +}; + typedef enum { MODE_NORMAL, /* Regular use as pointer in the page */ MODE_ADD, /* To add simple annotations */ @@ -449,6 +466,42 @@ pgd_annot_color_changed (GtkButton *button, } static void +pgd_annot_view_set_annot_text_markup (GtkWidget *table, + PopplerAnnotTextMarkup *annot, + gint *row) +{ + gint i; + gchar *text = NULL; + gchar *prev_text = NULL; + GArray *quads_array = NULL; + PopplerQuadrilateral quadrilateral; + + quads_array = poppler_annot_text_markup_get_quadrilaterals (annot); + + prev_text = g_strdup (""); + for (i = 0; i < quads_array->len; i++) { + quadrilateral = g_array_index (quads_array, PopplerQuadrilateral, i); + + text = g_strdup_printf ("%s%2d:(%.2f,%.2f) (%.2f,%.2f)\n" + " (%.2f,%.2f) (%.2f,%.2f)\n", + prev_text, i+1, + quadrilateral.p1.x, quadrilateral.p1.y, + quadrilateral.p2.x, quadrilateral.p2.y, + quadrilateral.p3.x, quadrilateral.p3.y, + quadrilateral.p4.x, quadrilateral.p4.y); + g_free (prev_text); + prev_text = text; + } + + text = g_strchomp (text); + pgd_table_add_property (GTK_GRID (table), "<b>Quadrilaterals:</b>", text, row); + + g_array_free (quads_array, TRUE); + g_free (text); +} + + +static void pgd_annot_view_set_annot_free_text (GtkWidget *table, PopplerAnnotFreeText *annot, gint *row) @@ -619,6 +672,12 @@ pgd_annot_view_set_annot (PgdAnnotsDemo *demo, case POPPLER_ANNOT_TEXT: pgd_annot_view_set_annot_text (table, POPPLER_ANNOT_TEXT (annot), &row); break; + case POPPLER_ANNOT_HIGHLIGHT: + case POPPLER_ANNOT_UNDERLINE: + case POPPLER_ANNOT_SQUIGGLY: + case POPPLER_ANNOT_STRIKE_OUT: + pgd_annot_view_set_annot_text_markup (table, POPPLER_ANNOT_TEXT_MARKUP (annot), &row); + break; case POPPLER_ANNOT_FREE_TEXT: pgd_annot_view_set_annot_free_text (table, POPPLER_ANNOT_FREE_TEXT (annot), &row); break; @@ -812,13 +871,44 @@ pgd_annots_invisible_flag_toggled (GtkCellRendererToggle *renderer, pgd_annots_flags_toggled (renderer, path_str, demo, ANNOTS_FLAG_INVISIBLE_COLUMN, POPPLER_ANNOT_FLAG_INVISIBLE); } +static inline void +pgd_annots_set_poppler_quad_from_rectangle (PopplerQuadrilateral *quad, + PopplerRectangle *rect) +{ + quad->p1.x = rect->x1; + quad->p1.y = rect->y1; + quad->p2.x = rect->x2; + quad->p2.y = rect->y1; + quad->p3.x = rect->x1; + quad->p3.y = rect->y2; + quad->p4.x = rect->x2; + quad->p4.y = rect->y2; +} + +static GArray * +pgd_annots_create_quads_array_for_rectangle (PopplerRectangle *rect) +{ + GArray *quads_array; + PopplerQuadrilateral *quad; + + quads_array = g_array_sized_new (FALSE, FALSE, + sizeof (PopplerQuadrilateral), + 1); + g_array_set_size (quads_array, 1); + + quad = &g_array_index (quads_array, PopplerQuadrilateral, 0); + pgd_annots_set_poppler_quad_from_rectangle (quad, rect); + + return quads_array; +} + static void pgd_annots_add_annot (PgdAnnotsDemo *demo) { - PopplerRectangle rect; - PopplerColor color; - PopplerAnnot *annot; - gdouble height; + PopplerRectangle rect; + PopplerColor color; + PopplerAnnot *annot; + gdouble height; g_assert (demo->mode == MODE_ADD); @@ -857,6 +947,38 @@ pgd_annots_add_annot (PgdAnnotsDemo *demo) case POPPLER_ANNOT_CIRCLE: annot = poppler_annot_circle_new (demo->doc, &rect); break; + case POPPLER_ANNOT_HIGHLIGHT: { + GArray *quads_array; + + quads_array = pgd_annots_create_quads_array_for_rectangle (&rect); + annot = poppler_annot_text_markup_new_highlight (demo->doc, &rect, quads_array); + g_array_free (quads_array, TRUE); + } + break; + case POPPLER_ANNOT_UNDERLINE: { + GArray *quads_array; + + quads_array = pgd_annots_create_quads_array_for_rectangle (&rect); + annot = poppler_annot_text_markup_new_underline (demo->doc, &rect, quads_array); + g_array_free (quads_array, TRUE); + } + break; + case POPPLER_ANNOT_SQUIGGLY: { + GArray *quads_array; + + quads_array = pgd_annots_create_quads_array_for_rectangle (&rect); + annot = poppler_annot_text_markup_new_squiggly (demo->doc, &rect, quads_array); + g_array_free (quads_array, TRUE); + } + break; + case POPPLER_ANNOT_STRIKE_OUT: { + GArray *quads_array; + + quads_array = pgd_annots_create_quads_array_for_rectangle (&rect); + annot = poppler_annot_text_markup_new_strikeout (demo->doc, &rect, quads_array); + g_array_free (quads_array, TRUE); + } + break; default: g_assert_not_reached (); } @@ -882,6 +1004,76 @@ pgd_annots_finish_add_annot (PgdAnnotsDemo *demo) gtk_label_set_text (GTK_LABEL (demo->timer_label), NULL); } +static void +pgd_annots_update_selected_text (PgdAnnotsDemo *demo) +{ + PopplerRectangle doc_area, *rects = NULL, *r = NULL; + gdouble width, height; + GArray *quads_array = NULL; + guint n_rects; + gint i, lines = 1; + GList *l_rects = NULL, *list; + + poppler_page_get_size (demo->page, &width, &height); + + doc_area.x1 = demo->start.x; + doc_area.y1 = demo->start.y; + doc_area.x2 = demo->stop.x; + doc_area.y2 = demo->stop.y; + + if (! poppler_page_get_text_layout_for_area (demo->page, &doc_area, + &rects, &n_rects)) + return; + + r = g_slice_new (PopplerRectangle); + r->x1 = G_MAXDOUBLE; r->y1 = G_MAXDOUBLE; + r->x2 = G_MINDOUBLE; r->y2 = G_MINDOUBLE; + + for (i = 0; i < n_rects; i++) { + /* Check if the rectangle belongs to the same line. + On a new line, start a new target rectangle. + On the same line, make an union of rectangles at + the same line */ + if (ABS(r->y2 - rects[i].y2) > 0.0001) { + if (i > 0) + l_rects = g_list_append (l_rects, r); + r = g_slice_new (PopplerRectangle); + r->x1 = rects[i].x1; + r->y1 = height - rects[i].y1; + r->x2 = rects[i].x2; + r->y2 = height - rects[i].y2; + lines++; + } else { + r->x1 = MIN(r->x1, rects[i].x1); + r->y1 = height - MIN(r->y1, rects[i].y1); + r->x2 = MAX(r->x2, rects[i].x2); + r->y2 = height - MAX(r->y2, rects[i].y2); + } + } + + l_rects = g_list_append (l_rects, r); + l_rects = g_list_reverse (l_rects); + + quads_array = g_array_sized_new (TRUE, TRUE, + sizeof (PopplerQuadrilateral), + lines); + g_array_set_size (quads_array, lines); + + for (list = l_rects, i = 0; list; list = list->next, i++) { + PopplerQuadrilateral *quad; + + quad = &g_array_index (quads_array, PopplerQuadrilateral, i); + r = (PopplerRectangle *)list->data; + pgd_annots_set_poppler_quad_from_rectangle (quad, r); + g_slice_free (PopplerRectangle, r); + } + + poppler_annot_text_markup_set_quadrilaterals (POPPLER_ANNOT_TEXT_MARKUP (demo->active_annot), quads_array); + g_array_free (quads_array, TRUE); + g_free (rects); + g_list_free (l_rects); +} + /* Render area */ static cairo_surface_t * pgd_annots_render_page (PgdAnnotsDemo *demo) @@ -1021,6 +1213,9 @@ pgd_annots_drawing_area_motion_notify (GtkWidget *area, poppler_annot_line_set_vertices (POPPLER_ANNOT_LINE (demo->active_annot), &start, &end); + if (POPPLER_IS_ANNOT_TEXT_MARKUP (demo->active_annot)) + pgd_annots_update_selected_text (demo); + pgd_annot_view_set_annot (demo, demo->active_annot); pgd_annots_viewer_queue_redraw (demo); @@ -1108,29 +1303,14 @@ pgd_annots_create_widget (PopplerDocument *document) model = gtk_list_store_new(SELECTED_N_COLUMNS, G_TYPE_INT, G_TYPE_STRING); - gtk_list_store_append (model, &iter); - gtk_list_store_set (model, &iter, - SELECTED_TYPE_COLUMN, POPPLER_ANNOT_TEXT, - SELECTED_LABEL_COLUMN, "Text", - -1); - - gtk_list_store_append (model, &iter); - gtk_list_store_set (model, &iter, - 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); + for (gint i = 0; i < G_N_ELEMENTS (supported_annots); i++) { + gtk_list_store_append (model, &iter); + gtk_list_store_set (model, &iter, + SELECTED_TYPE_COLUMN, supported_annots[i].type, + SELECTED_LABEL_COLUMN, supported_annots[i].label, + -1); + } demo->type_selector = gtk_combo_box_new_with_model (GTK_TREE_MODEL (model)); g_object_unref (model); commit 9a7699ebe3e644ba845ef75d9295c88d321cb934 Author: Germán Poo-Caamaño <[email protected]> Date: Mon Nov 18 16:42:08 2013 -0800 glib: Add PopplerAnnotTextMarkup class and subtypes The subtypes are: Highlihght, Squiggly, StrikeOut and Underline. It adds convenient methods to set/get/free quadrilaterals necessaries for TextMarkup annotations. https://bugs.freedesktop.org/show_bug.cgi?id=51487 diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc index 6a1c05e..a4c0087 100644 --- a/glib/poppler-annot.cc +++ b/glib/poppler-annot.cc @@ -33,6 +33,7 @@ typedef struct _PopplerAnnotClass PopplerAnnotClass; typedef struct _PopplerAnnotMarkupClass PopplerAnnotMarkupClass; typedef struct _PopplerAnnotFreeTextClass PopplerAnnotFreeTextClass; typedef struct _PopplerAnnotTextClass PopplerAnnotTextClass; +typedef struct _PopplerAnnotTextMarkupClass PopplerAnnotTextMarkupClass; typedef struct _PopplerAnnotFileAttachmentClass PopplerAnnotFileAttachmentClass; typedef struct _PopplerAnnotMovieClass PopplerAnnotMovieClass; typedef struct _PopplerAnnotScreenClass PopplerAnnotScreenClass; @@ -65,6 +66,16 @@ struct _PopplerAnnotTextClass PopplerAnnotMarkupClass parent_class; }; +struct _PopplerAnnotTextMarkup +{ + PopplerAnnotMarkup parent_instance; +}; + +struct _PopplerAnnotTextMarkupClass +{ + PopplerAnnotMarkupClass parent_class; +}; + struct _PopplerAnnotFreeText { PopplerAnnotMarkup parent_instance; @@ -141,6 +152,7 @@ struct _PopplerAnnotSquareClass 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) G_DEFINE_TYPE (PopplerAnnotText, poppler_annot_text, POPPLER_TYPE_ANNOT_MARKUP) G_DEFINE_TYPE (PopplerAnnotFreeText, poppler_annot_free_text, POPPLER_TYPE_ANNOT_MARKUP) G_DEFINE_TYPE (PopplerAnnotFileAttachment, poppler_annot_file_attachment, POPPLER_TYPE_ANNOT_MARKUP) @@ -246,6 +258,208 @@ poppler_annot_text_new (PopplerDocument *doc, return _poppler_annot_text_new (annot); } +PopplerAnnot * +_poppler_annot_text_markup_new (Annot *annot) +{ + return _poppler_create_annot (POPPLER_TYPE_ANNOT_TEXT_MARKUP, annot); +} + +static AnnotQuadrilaterals * +create_annot_quads_from_poppler_quads (GArray *quads) +{ + AnnotQuadrilaterals::AnnotQuadrilateral **quads_array; + + g_assert (quads->len > 0); + + quads_array = (AnnotQuadrilaterals::AnnotQuadrilateral **) g_malloc0_n ( + sizeof (AnnotQuadrilaterals::AnnotQuadrilateral *), + quads->len); + + for (guint i = 0; i < quads->len; i++) { + PopplerQuadrilateral *quadrilateral = &g_array_index (quads, PopplerQuadrilateral, i); + + quads_array[i] = new AnnotQuadrilaterals::AnnotQuadrilateral ( + quadrilateral->p1.x, quadrilateral->p1.y, + quadrilateral->p2.x, quadrilateral->p2.y, + quadrilateral->p3.x, quadrilateral->p3.y, + quadrilateral->p4.x, quadrilateral->p4.y); + } + + return new AnnotQuadrilaterals (quads_array, quads->len); +} + +static GArray * +create_poppler_quads_from_annot_quads (AnnotQuadrilaterals *quads_array) +{ + GArray *quads; + guint quads_len; + + quads_len = quads_array->getQuadrilateralsLength(); + quads = g_array_sized_new (FALSE, FALSE, + sizeof (PopplerQuadrilateral), + quads_len); + g_array_set_size (quads, quads_len); + + for (guint i = 0; i < quads_len; ++i) { + PopplerQuadrilateral *quadrilateral = &g_array_index (quads, PopplerQuadrilateral, i); + + quadrilateral->p1.x = quads_array->getX1(i); + quadrilateral->p1.y = quads_array->getX1(i); + quadrilateral->p2.x = quads_array->getX2(i); + quadrilateral->p2.y = quads_array->getY2(i); + quadrilateral->p3.x = quads_array->getX3(i); + quadrilateral->p3.y = quads_array->getY3(i); + quadrilateral->p4.x = quads_array->getX4(i); + quadrilateral->p4.y = quads_array->getY4(i); + } + + return quads; +} + +static void +poppler_annot_text_markup_init (PopplerAnnotTextMarkup *poppler_annot) +{ +} + +static void +poppler_annot_text_markup_class_init (PopplerAnnotTextMarkupClass *klass) +{ +} + +/** + * poppler_annot_text_markup_new_highlight: + * @doc: a #PopplerDocument + * @rect: a #PopplerRectangle + * @quadrilaterals: (element-type PopplerQuadrilateral): A #GArray of + * #PopplerQuadrilateral<!-- -->s + * + * Creates a new Highlight Text annotation that will be + * located on @rect when added to a page. See poppler_page_add_annot() + * + * Return value: (transfer full): A newly created #PopplerAnnotTextMarkup annotation + * + * Since: 0.26 + */ +PopplerAnnot * +poppler_annot_text_markup_new_highlight (PopplerDocument *doc, + PopplerRectangle *rect, + GArray *quadrilaterals) +{ + PopplerAnnot *poppler_annot; + AnnotTextMarkup *annot; + PDFRectangle pdf_rect(rect->x1, rect->y1, + rect->x2, rect->y2); + + annot = new AnnotTextMarkup (doc->doc, &pdf_rect, Annot::typeHighlight); + + poppler_annot = _poppler_annot_text_markup_new (annot); + poppler_annot_text_markup_set_quadrilaterals (POPPLER_ANNOT_TEXT_MARKUP (poppler_annot), + quadrilaterals); + return poppler_annot; +} + +/** + * poppler_annot_text_markup_new_squiggly: + * @doc: a #PopplerDocument + * @rect: a #PopplerRectangle + * @quadrilaterals: (element-type PopplerQuadrilateral): A #GArray of + * #PopplerQuadrilateral<!-- -->s + * + * Creates a new Squiggly Text annotation that will be + * located on @rect when added to a page. See poppler_page_add_annot() + * + * Return value: (transfer full): A newly created #PopplerAnnotTextMarkup annotation + * + * Since: 0.26 + */ +PopplerAnnot * +poppler_annot_text_markup_new_squiggly (PopplerDocument *doc, + PopplerRectangle *rect, + GArray *quadrilaterals) +{ + PopplerAnnot *poppler_annot; + AnnotTextMarkup *annot; + PDFRectangle pdf_rect(rect->x1, rect->y1, + rect->x2, rect->y2); + + g_return_val_if_fail (quadrilaterals != NULL && quadrilaterals->len > 0, NULL); + + annot = new AnnotTextMarkup (doc->doc, &pdf_rect, Annot::typeSquiggly); + + poppler_annot = _poppler_annot_text_markup_new (annot); + poppler_annot_text_markup_set_quadrilaterals (POPPLER_ANNOT_TEXT_MARKUP (poppler_annot), + quadrilaterals); + return poppler_annot; +} + +/** + * poppler_annot_text_markup_new_strikeout: + * @doc: a #PopplerDocument + * @rect: a #PopplerRectangle + * @quadrilaterals: (element-type PopplerQuadrilateral): A #GArray of + * #PopplerQuadrilateral<!-- -->s + * + * Creates a new Strike Out Text annotation that will be + * located on @rect when added to a page. See poppler_page_add_annot() + * + * Return value: (transfer full): A newly created #PopplerAnnotTextMarkup annotation + * + * Since: 0.26 + */ +PopplerAnnot * +poppler_annot_text_markup_new_strikeout (PopplerDocument *doc, + PopplerRectangle *rect, + GArray *quadrilaterals) +{ + PopplerAnnot *poppler_annot; + AnnotTextMarkup *annot; + PDFRectangle pdf_rect(rect->x1, rect->y1, + rect->x2, rect->y2); + + g_return_val_if_fail (quadrilaterals != NULL && quadrilaterals->len > 0, NULL); + + annot = new AnnotTextMarkup (doc->doc, &pdf_rect, Annot::typeStrikeOut); + + poppler_annot = _poppler_annot_text_markup_new (annot); + poppler_annot_text_markup_set_quadrilaterals (POPPLER_ANNOT_TEXT_MARKUP (poppler_annot), + quadrilaterals); + return poppler_annot; +} + +/** + * poppler_annot_text_markup_new_underline: + * @doc: a #PopplerDocument + * @rect: a #PopplerRectangle + * @quadrilaterals: (element-type PopplerQuadrilateral): A #GArray of + * #PopplerQuadrilateral<!-- -->s + * + * Creates a new Underline Text annotation that will be + * located on @rect when added to a page. See poppler_page_add_annot() + * + * Return value: (transfer full): A newly created #PopplerAnnotTextMarkup annotation + * + * Since: 0.26 + */ +PopplerAnnot * +poppler_annot_text_markup_new_underline (PopplerDocument *doc, + PopplerRectangle *rect, + GArray *quadrilaterals) +{ + PopplerAnnot *poppler_annot; + AnnotTextMarkup *annot; + PDFRectangle pdf_rect(rect->x1, rect->y1, + rect->x2, rect->y2); + + g_return_val_if_fail (quadrilaterals != NULL && quadrilaterals->len > 0, NULL); + + annot = new AnnotTextMarkup (doc->doc, &pdf_rect, Annot::typeUnderline); + + poppler_annot = _poppler_annot_text_markup_new (annot); + poppler_annot_text_markup_set_quadrilaterals (POPPLER_ANNOT_TEXT_MARKUP (poppler_annot), + quadrilaterals); + return poppler_annot; +} + static void poppler_annot_free_text_init (PopplerAnnotFreeText *poppler_annot) { @@ -1353,6 +1567,56 @@ poppler_annot_text_get_state (PopplerAnnotText *poppler_annot) return POPPLER_ANNOT_TEXT_STATE_UNKNOWN; } +/* PopplerAnnotTextMarkup */ +/** + * poppler_annot_text_markup_set_quadrilaterals: + * @poppler_annot: A #PopplerAnnotTextMarkup + * @quadrilaterals: (element-type PopplerQuadrilateral): A #GArray of + * #PopplerQuadrilateral<!-- -->s + * + * Set the regions (Quadrilaterals) to apply the text markup in @poppler_annot. + * + * Since: 0.26 + **/ +void +poppler_annot_text_markup_set_quadrilaterals (PopplerAnnotTextMarkup *poppler_annot, + GArray *quadrilaterals) +{ + AnnotTextMarkup *annot; + + g_return_if_fail (POPPLER_IS_ANNOT_TEXT_MARKUP (poppler_annot)); + g_return_if_fail (quadrilaterals != NULL && quadrilaterals->len > 0); + + annot = static_cast<AnnotTextMarkup *>(POPPLER_ANNOT (poppler_annot)->annot); + AnnotQuadrilaterals *quads = create_annot_quads_from_poppler_quads (quadrilaterals); + annot->setQuadrilaterals (quads); + delete quads; +} + +/** + * poppler_annot_text_markup_get_quadrilaterals: + * @poppler_annot: A #PopplerAnnotTextMarkup + * + * Returns a #GArray of #PopplerQuadrilateral items that map from a + * location on @page to a #PopplerAnnotTextMarkup. This array must be freed + * when done. + * + * Return value: (element-type PopplerQuadrilateral) (transfer full): A #GArray of #PopplerQuadrilateral + * + * Since: 0.26 + **/ +GArray * +poppler_annot_text_markup_get_quadrilaterals (PopplerAnnotTextMarkup *poppler_annot) +{ + AnnotTextMarkup *annot; + + g_return_val_if_fail (POPPLER_IS_ANNOT_TEXT_MARKUP (poppler_annot), NULL); + + annot = static_cast<AnnotTextMarkup *>(POPPLER_ANNOT (poppler_annot)->annot); + + return create_poppler_quads_from_annot_quads (annot->getQuadrilaterals()); +} + /* PopplerAnnotFreeText */ /** * poppler_annot_free_text_get_quadding: diff --git a/glib/poppler-annot.h b/glib/poppler-annot.h index 300e815..297df03 100644 --- a/glib/poppler-annot.h +++ b/glib/poppler-annot.h @@ -38,6 +38,11 @@ G_BEGIN_DECLS #define POPPLER_ANNOT_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_TEXT, PopplerAnnotText)) #define POPPLER_IS_ANNOT_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_TEXT)) +#define POPPLER_TYPE_ANNOT_TEXT_MARKUP (poppler_annot_text_markup_get_type ()) +#define POPPLER_ANNOT_TEXT_MARKUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_TEXT_MARKUP, PopplerAnnotTextMarkup)) +#define POPPLER_IS_ANNOT_TEXT_MARKUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_TEXT_MARKUP)) + + #define POPPLER_TYPE_ANNOT_FREE_TEXT (poppler_annot_free_text_get_type ()) #define POPPLER_ANNOT_FREE_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_FREE_TEXT, PopplerAnnotFreeText)) #define POPPLER_IS_ANNOT_FREE_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_FREE_TEXT)) @@ -217,6 +222,24 @@ void poppler_annot_text_set_icon ( const gchar *icon); PopplerAnnotTextState poppler_annot_text_get_state (PopplerAnnotText *poppler_annot); +/* PopplerAnnotTextMarkup */ +GType poppler_annot_text_markup_get_type (void) G_GNUC_CONST; +PopplerAnnot *poppler_annot_text_markup_new_highlight (PopplerDocument *doc, + PopplerRectangle *rect, + GArray *quadrilaterals); +PopplerAnnot *poppler_annot_text_markup_new_squiggly (PopplerDocument *doc, + PopplerRectangle *rect, + GArray *quadrilaterals); +PopplerAnnot *poppler_annot_text_markup_new_strikeout (PopplerDocument *doc, + PopplerRectangle *rect, + GArray *quadrilaterals); +PopplerAnnot *poppler_annot_text_markup_new_underline (PopplerDocument *doc, + PopplerRectangle *rect, + GArray *quadrilaterals); +void poppler_annot_text_markup_set_quadrilaterals (PopplerAnnotTextMarkup *poppler_annot, + GArray *quadrilaterals); +GArray *poppler_annot_text_markup_get_quadrilaterals (PopplerAnnotTextMarkup *poppler_annot); + /* PopplerAnnotFreeText */ GType poppler_annot_free_text_get_type (void) G_GNUC_CONST; PopplerAnnotFreeTextQuadding poppler_annot_free_text_get_quadding (PopplerAnnotFreeText *poppler_annot); diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index ef90eae..1916f95 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -1406,6 +1406,12 @@ poppler_page_get_annot_mapping (PopplerPage *page) case Annot::typeCircle: mapping->annot = _poppler_annot_circle_new (annot); break; + case Annot::typeHighlight: + case Annot::typeUnderline: + case Annot::typeSquiggly: + case Annot::typeStrikeOut: + mapping->annot = _poppler_annot_text_markup_new (annot); + break; default: mapping->annot = _poppler_annot_new (annot); break; diff --git a/glib/poppler-private.h b/glib/poppler-private.h index 1a1dab9..93d0f23 100644 --- a/glib/poppler-private.h +++ b/glib/poppler-private.h @@ -117,6 +117,7 @@ PopplerMedia *_poppler_media_new (MediaRendition *media); PopplerAnnot *_poppler_annot_new (Annot *annot); PopplerAnnot *_poppler_annot_text_new (Annot *annot); PopplerAnnot *_poppler_annot_free_text_new (Annot *annot); +PopplerAnnot *_poppler_annot_text_markup_new (Annot *annot); PopplerAnnot *_poppler_annot_file_attachment_new (Annot *annot); PopplerAnnot *_poppler_annot_movie_new (Annot *annot); PopplerAnnot *_poppler_annot_screen_new (Annot *annot); diff --git a/glib/poppler.h b/glib/poppler.h index 4313e5e..0db97d0 100644 --- a/glib/poppler.h +++ b/glib/poppler.h @@ -198,6 +198,7 @@ typedef struct _PopplerMedia PopplerMedia; typedef struct _PopplerAnnot PopplerAnnot; typedef struct _PopplerAnnotMarkup PopplerAnnotMarkup; typedef struct _PopplerAnnotText PopplerAnnotText; +typedef struct _PopplerAnnotTextMarkup PopplerAnnotTextMarkup; typedef struct _PopplerAnnotFreeText PopplerAnnotFreeText; typedef struct _PopplerAnnotFileAttachment PopplerAnnotFileAttachment; typedef struct _PopplerAnnotMovie PopplerAnnotMovie; diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt index 12218fe..a954f64 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -374,6 +374,7 @@ PopplerAnnot PopplerAnnotMarkup PopplerAnnotCircle PopplerAnnotText +PopplerAnnotTextMarkup PopplerAnnotFreeText PopplerAnnotFileAttachment PopplerAnnotLine @@ -428,6 +429,12 @@ poppler_annot_text_set_icon poppler_annot_text_get_is_open poppler_annot_text_set_is_open poppler_annot_text_get_state +poppler_annot_text_markup_new_highlight +poppler_annot_text_markup_new_squiggly +poppler_annot_text_markup_new_strikeout +poppler_annot_text_markup_new_underline +poppler_annot_text_markup_set_quadrilaterals +poppler_annot_text_markup_get_quadrilaterals poppler_annot_free_text_get_callout_line poppler_annot_free_text_get_quadding poppler_annot_file_attachment_get_attachment @@ -485,12 +492,15 @@ POPPLER_IS_ANNOT_SQUARE POPPLER_TYPE_ANNOT_SQUARE POPPLER_ANNOT_TEXT POPPLER_IS_ANNOT_TEXT +POPPLER_ANNOT_TEXT_MARKUP +POPPLER_IS_ANNOT_TEXT_MARKUP POPPLER_TYPE_ANNOT_TEXT POPPLER_TYPE_ANNOT_CALLOUT_LINE POPPLER_TYPE_ANNOT_EXTERNAL_DATA_TYPE POPPLER_TYPE_ANNOT_FLAG POPPLER_TYPE_ANNOT_MARKUP_REPLY_TYPE POPPLER_TYPE_ANNOT_TEXT_STATE +POPPLER_TYPE_ANNOT_TEXT_MARKUP POPPLER_TYPE_ANNOT_FREE_TEXT_QUADDING POPPLER_TYPE_ANNOT_TYPE POPPLER_TYPE_QUADRILATERAL @@ -500,6 +510,7 @@ poppler_annot_get_type poppler_annot_type_get_type poppler_annot_markup_get_type poppler_annot_text_get_type +poppler_annot_text_markup_get_type poppler_annot_free_text_get_type poppler_annot_file_attachment_get_type poppler_annot_screen_get_type commit 40040b41216a3dcc833fc224f1c6f15517a88aed Author: Germán Poo-Caamaño <[email protected]> Date: Mon Nov 18 16:26:27 2013 -0800 glib: Add PopplerQuadrilateral boxed type https://bugs.freedesktop.org/show_bug.cgi?id=51487 diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index a21be0f..ef90eae 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -1612,6 +1612,59 @@ poppler_point_free (PopplerPoint *point) g_slice_free (PopplerPoint, point); } +/* PopplerQuadrilateral type */ + +POPPLER_DEFINE_BOXED_TYPE (PopplerQuadrilateral, poppler_quadrilateral, + poppler_quadrilateral_copy, + poppler_quadrilateral_free) + +/** + * poppler_quadrilateral_new: + * + * Creates a new #PopplerQuadrilateral. It must be freed with poppler_quadrilateral_free() after use. + * + * Returns: a new #PopplerQuadrilateral. + * + * Since: 0.26 + **/ +PopplerQuadrilateral * +poppler_quadrilateral_new (void) +{ + return g_slice_new0 (PopplerQuadrilateral); +} + +/** + * poppler_quadrilateral_copy: + * @quad: a #PopplerQuadrilateral to copy + * + * Creates a copy of @quad. The copy must be freed with poppler_quadrilateral_free() after use. + * + * Returns: a new allocated copy of @quad + * + * Since: 0.26 + **/ +PopplerQuadrilateral * +poppler_quadrilateral_copy (PopplerQuadrilateral *quad) +{ + g_return_val_if_fail (quad != NULL, NULL); + + return g_slice_dup (PopplerQuadrilateral, quad); +} + +/** + * poppler_quadrilateral_free: + * @quad: a #PopplerQuadrilateral + * + * Frees the memory used by @quad + * + * Since: 0.26 + **/ +void +poppler_quadrilateral_free (PopplerQuadrilateral *quad) +{ + g_slice_free (PopplerQuadrilateral, quad); +} + /* PopplerTextAttributes type */ POPPLER_DEFINE_BOXED_TYPE (PopplerTextAttributes, poppler_text_attributes, diff --git a/glib/poppler-page.h b/glib/poppler-page.h index 68e2a1d..63fe362 100644 --- a/glib/poppler-page.h +++ b/glib/poppler-page.h @@ -155,6 +155,39 @@ PopplerPoint *poppler_point_new (void); PopplerPoint *poppler_point_copy (PopplerPoint *point); void poppler_point_free (PopplerPoint *point); +/* PopplerQuadrilateral */ + +/* A quadrilateral encompasses a word or group of contiguous words in the + * text underlying the annotation. The coordinates for each quadrilateral are + * given in the order x1 y1 x2 y2 x3 y3 x4 y4 specifying the quadrilateralâs four + * vertices in counterclockwise order */ + +#define POPPLER_TYPE_QUADRILATERAL (poppler_quadrilateral_get_type ()) +/** + * PopplerQuadrilateral: + * @p1: a #PopplerPoint with the first vertex coordinates + * @p2: a #PopplerPoint with the second vertex coordinates + * @p3: a #PopplerPoint with the third vertex coordinates + * @p4: a #PopplerPoint with the fourth vertex coordinates + * + * A #PopplerQuadrilateral is used to describe rectangle-like polygon + * with arbitrary inclination on a page. + * + * Since: 0.26 + **/ +struct _PopplerQuadrilateral +{ + PopplerPoint p1; + PopplerPoint p2; + PopplerPoint p3; + PopplerPoint p4; +}; + +GType poppler_quadrilateral_get_type (void) G_GNUC_CONST; +PopplerQuadrilateral *poppler_quadrilateral_new (void); +PopplerQuadrilateral *poppler_quadrilateral_copy (PopplerQuadrilateral *quad); +void poppler_quadrilateral_free (PopplerQuadrilateral *quad); + /* A color in RGB */ #define POPPLER_TYPE_COLOR (poppler_color_get_type ()) diff --git a/glib/poppler.h b/glib/poppler.h index 92121f6..4313e5e 100644 --- a/glib/poppler.h +++ b/glib/poppler.h @@ -206,6 +206,7 @@ typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine; typedef struct _PopplerAnnotLine PopplerAnnotLine; typedef struct _PopplerAnnotCircle PopplerAnnotCircle; typedef struct _PopplerAnnotSquare PopplerAnnotSquare; +typedef struct _PopplerQuadrilateral PopplerQuadrilateral; typedef enum { diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt index 9bf2a05..12218fe 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -388,6 +388,7 @@ PopplerAnnotCalloutLine PopplerAnnotFreeTextQuadding PopplerAnnotSquare PopplerPoint +PopplerQuadrilateral poppler_annot_get_annot_type poppler_annot_get_flags poppler_annot_get_name @@ -449,6 +450,10 @@ poppler_point_copy poppler_point_free poppler_point_get_type poppler_point_new +poppler_quadrilateral_copy +poppler_quadrilateral_free +poppler_quadrilateral_get_type +poppler_quadrilateral_new <SUBSECTION Standard> POPPLER_ANNOT @@ -488,6 +493,7 @@ POPPLER_TYPE_ANNOT_MARKUP_REPLY_TYPE POPPLER_TYPE_ANNOT_TEXT_STATE POPPLER_TYPE_ANNOT_FREE_TEXT_QUADDING POPPLER_TYPE_ANNOT_TYPE +POPPLER_TYPE_QUADRILATERAL <SUBSECTION Private> poppler_annot_get_type
_______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
