diff --git a/glib/demo/annots.c b/glib/demo/annots.c index c4607d1..a08a604 100644 --- a/glib/demo/annots.c +++ b/glib/demo/annots.c @@ -974,11 +974,12 @@ pgd_annots_finish_add_annot (PgdAnnotsDemo *demo) static void pgd_annots_update_selected_text (PgdAnnotsDemo *demo) { - PopplerRectangle doc_area, *rect; + PopplerRectangle doc_area, *rects = NULL; gdouble width, height; PopplerQuadrilateral quadrilateral; - GList *list, *region; GArray *quads_array = NULL; + guint n_rects; + gint i; poppler_page_get_size (demo->page, &width, &height); @@ -987,36 +988,30 @@ pgd_annots_update_selected_text (PgdAnnotsDemo *demo) doc_area.x2 = demo->stop.x; doc_area.y2 = demo->stop.y; - region = poppler_page_get_selection_region (demo->page, 1.0, - POPPLER_SELECTION_GLYPH, - &doc_area); - - if (region == NULL) + if (! poppler_page_get_text_layout_for_area (demo->page, &doc_area, + &rects, &n_rects)) return; quads_array = g_array_sized_new (FALSE, FALSE, sizeof (PopplerQuadrilateral), - g_list_length (region)); - - for (list = region; list; list = list->next) { - rect = (PopplerRectangle *) list->data; - - quadrilateral.p1.x = rect->x1; - quadrilateral.p1.y = height - rect->y1; - quadrilateral.p2.x = rect->x2; - quadrilateral.p2.y = height - rect->y1; - quadrilateral.p3.x = rect->x1; - quadrilateral.p3.y = height - rect->y2; - quadrilateral.p4.x = rect->x2; - quadrilateral.p4.y = height - rect->y2; + n_rects); + + for (i = 0; i < n_rects; i++) { + quadrilateral.p1.x = rects[i].x1; + quadrilateral.p1.y = height - rects[i].y1; + quadrilateral.p2.x = rects[i].x2; + quadrilateral.p2.y = height - rects[i].y1; + quadrilateral.p3.x = rects[i].x1; + quadrilateral.p3.y = height - rects[i].y2; + quadrilateral.p4.x = rects[i].x2; + quadrilateral.p4.y = height - rects[i].y2; g_array_append_val (quads_array, quadrilateral); } - poppler_page_selection_region_free (region); - poppler_annot_text_markup_set_quadrilaterals (POPPLER_ANNOT_TEXT_MARKUP (demo->active_annot), quads_array); g_array_free (quads_array, TRUE); + g_free (rects); } /* Render area */