+static gchar *
+djvu_text_copy (DjvuDocument *djvu_document,
+ gint page,
+ EvRectangle *rectangle)
+{
+ miniexp_t page_text;
+ gchar *text = NULL;
+
+ while ((page_text =
+ ddjvu_document_get_pagetext (djvu_document->d_document,
+ page, "char")) == miniexp_dummy)
+ djvu_handle_events (djvu_document, TRUE, NULL);
+
+ if (page_text != miniexp_nil) {
+ DjvuTextPage *page = djvu_text_page_new (page_text);
+
+ text = djvu_text_page_copy (page, rectangle);
+ djvu_text_page_free (page);
+ ddjvu_miniexp_release (djvu_document->d_document, page_text);
+ }
+
+ return text;
+}
+
+static gchar *
+djvu_selection_get_selected_text (EvSelection *selection,
+ EvRenderContext *rc,
+ EvSelectionStyle style,
+ EvRectangle *points)
+{
+ DjvuDocument *djvu_document = DJVU_DOCUMENT (selection);
+ double width, height;
+ EvRectangle rectangle;
+ gchar *text;
+
+ djvu_document_get_page_size (EV_DOCUMENT (djvu_document),
+ rc->page, &width, &height);
+ rectangle.x1 = points->x1 / SCALE_FACTOR;
+ rectangle.y1 = (height - points->y2) / SCALE_FACTOR;
+ rectangle.x2 = points->x2 / SCALE_FACTOR;
+ rectangle.y2 = (height - points->y1) / SCALE_FACTOR;
+
+ text = djvu_text_copy (djvu_document, rc->page->index, &rectangle);
+
+ if (text == NULL)
+ text = g_strdup ("");
+
+ return text;
+}
+
+static void
+djvu_selection_iface_init (EvSelectionIface *iface)
+{
+ iface->get_selected_text = djvu_selection_get_selected_text;
+}
+