static VALUE rg_image_mapping(VALUE self) { VALUE mappings; GList *image_mapping, *node; mappings = rb_ary_new(); image_mapping = poppler_page_get_image_mapping(SELF(self)); for (node = image_mapping; node; node = g_list_next(node)) { PopplerImageMapping *image_mapping; VALUE mapping; image_mapping = node->data; mapping = POPPLERIMAGEMAPPING2RVAL(image_mapping); #ifdef RB_POPPLER_CAIRO_AVAILABLE rb_iv_set(mapping, "@page", self); #endif rb_ary_push(mappings, mapping); } poppler_page_free_image_mapping(image_mapping); return mappings; }
static void pgd_images_get_images (GtkWidget *button, PgdImagesDemo *demo) { PopplerPage *page; GList *mapping, *l; gint n_images; GTimer *timer; gtk_list_store_clear (demo->model); pgd_image_view_set_image (demo->image_view, NULL); page = poppler_document_get_page (demo->doc, demo->page); if (!page) return; timer = g_timer_new (); mapping = poppler_page_get_image_mapping (page); g_timer_stop (timer); n_images = g_list_length (mapping); if (n_images > 0) { gchar *str; str = g_strdup_printf ("<i>%d images found in %.4f seconds</i>", n_images, g_timer_elapsed (timer, NULL)); gtk_label_set_markup (GTK_LABEL (demo->timer_label), str); g_free (str); } else { gtk_label_set_markup (GTK_LABEL (demo->timer_label), "<i>No images found</i>"); } g_timer_destroy (timer); for (l = mapping; l; l = g_list_next (l)) { PopplerImageMapping *imapping; GtkTreeIter iter; gchar *x1, *y1, *x2, *y2; imapping = (PopplerImageMapping *)l->data; x1 = g_strdup_printf ("%.2f", imapping->area.x1); y1 = g_strdup_printf ("%.2f", imapping->area.y1); x2 = g_strdup_printf ("%.2f", imapping->area.x2); y2 = g_strdup_printf ("%.2f", imapping->area.y2); gtk_list_store_append (demo->model, &iter); gtk_list_store_set (demo->model, &iter, IMAGES_ID_COLUMN, imapping->image_id, IMAGES_X1_COLUMN, x1, IMAGES_Y1_COLUMN, y1, IMAGES_X2_COLUMN, x2, IMAGES_Y2_COLUMN, y2, -1); g_free (x1); g_free (y1); g_free (x2); g_free (y2); } poppler_page_free_image_mapping (mapping); g_object_unref (page); }