[evince] djvu: implement text interface



commit 602d7148ef176631f3ae213b3a9a87f0be2ca577
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Sat Jun 29 11:31:40 2013 +0200

    djvu: implement text interface
    
    https://bugzilla.gnome.org/show_bug.cgi?id=703108

 backend/djvu/djvu-document.c |   52 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/backend/djvu/djvu-document.c b/backend/djvu/djvu-document.c
index a187acb..22b3464 100644
--- a/backend/djvu/djvu-document.c
+++ b/backend/djvu/djvu-document.c
@@ -30,6 +30,7 @@
 #include "ev-document-links.h"
 #include "ev-selection.h"
 #include "ev-file-helpers.h"
+#include "ev-document-text.h"
 
 #include <glib.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
@@ -52,6 +53,7 @@ static void djvu_document_file_exporter_iface_init (EvFileExporterInterface *ifa
 static void djvu_document_find_iface_init (EvDocumentFindInterface *iface);
 static void djvu_document_document_links_iface_init  (EvDocumentLinksInterface *iface);
 static void djvu_selection_iface_init (EvSelectionInterface *iface);
+static void djvu_document_text_iface_init (EvDocumentTextInterface *iface);
 
 EV_BACKEND_REGISTER_WITH_CODE (DjvuDocument, djvu_document,
     {
@@ -59,6 +61,7 @@ EV_BACKEND_REGISTER_WITH_CODE (DjvuDocument, djvu_document,
       EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND, djvu_document_find_iface_init);
       EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS, djvu_document_document_links_iface_init);
       EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_SELECTION, djvu_selection_iface_init);
+      EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TEXT, djvu_document_text_iface_init);
      });
 
 
@@ -654,6 +657,55 @@ djvu_selection_iface_init (EvSelectionInterface *iface)
        iface->get_selection_region = djvu_selection_get_selection_region;
 }
 
+static cairo_region_t *
+djvu_document_text_get_text_mapping (EvDocumentText *document_text,
+                                    EvPage         *page)
+{
+       DjvuDocument *djvu_document = DJVU_DOCUMENT (document_text);
+       EvRectangle points;
+
+       points.x1 = 0;
+       points.y1 = 0;
+
+       document_get_page_size (djvu_document, page->index,
+                               &points.x2, &points.y2, NULL);
+
+       return djvu_get_selection_region (djvu_document, page->index,
+                                         1.0, &points);
+}
+
+static gchar *
+djvu_document_text_get_text (EvDocumentText  *selection,
+                             EvPage          *page)
+{
+       DjvuDocument *djvu_document = DJVU_DOCUMENT (selection);
+       miniexp_t     page_text;
+       gchar        *text = NULL;
+
+       while ((page_text = ddjvu_document_get_pagetext (djvu_document->d_document,
+                                                        page->index,
+                                                        "char")) == miniexp_dummy)
+               djvu_handle_events (djvu_document, TRUE, NULL);
+
+       if (page_text != miniexp_nil) {
+               DjvuTextPage *tpage = djvu_text_page_new (page_text);
+
+               djvu_text_page_index_text (tpage, TRUE);
+               text = tpage->text;
+               tpage->text = NULL;
+               djvu_text_page_free (tpage);
+               ddjvu_miniexp_release (djvu_document->d_document, page_text);
+       }
+       return text;
+}
+
+static void
+djvu_document_text_iface_init (EvDocumentTextInterface *iface)
+{
+       iface->get_text_mapping = djvu_document_text_get_text_mapping;
+       iface->get_text = djvu_document_text_get_text;
+}
+
 /* EvFileExporterIface */
 static void
 djvu_document_file_exporter_begin (EvFileExporter        *exporter,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]