]> www.fi.muni.cz Git - evince.git/commitdiff
[pdf] Implement EvDocumentText interface
authorDaniel Garcia <danigm@yaco.es>
Sat, 26 Jun 2010 14:12:57 +0000 (16:12 +0200)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Sat, 26 Jun 2010 14:24:32 +0000 (16:24 +0200)
backend/pdf/ev-poppler.cc
configure.ac
libdocument/ev-selection.c
libdocument/ev-selection.h
libview/ev-jobs.c

index 8659d082db5803e15de872accd155f470ae75c3c..4b262900427080c48589811524244f2a8dea3b98 100644 (file)
@@ -51,6 +51,7 @@
 #include "ev-document-print.h"
 #include "ev-document-annotations.h"
 #include "ev-document-attachments.h"
+#include "ev-document-text.h"
 #include "ev-selection.h"
 #include "ev-transition-effect.h"
 #include "ev-attachment.h"
@@ -126,6 +127,7 @@ static void pdf_document_find_iface_init                 (EvDocumentFindInterfac
 static void pdf_document_file_exporter_iface_init        (EvFileExporterInterface        *iface);
 static void pdf_selection_iface_init                     (EvSelectionInterface           *iface);
 static void pdf_document_page_transition_iface_init      (EvDocumentTransitionInterface  *iface);
+static void pdf_document_text_iface_init                 (EvDocumentTextInterface        *iface);
 static void pdf_document_thumbnails_get_dimensions       (EvDocumentThumbnails           *document_thumbnails,
                                                          EvRenderContext                *rc,
                                                          gint                           *width,
@@ -172,6 +174,8 @@ EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
                                                                 pdf_selection_iface_init);
                                 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TRANSITION,
                                                                 pdf_document_page_transition_iface_init);
+                                EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TEXT,
+                                                                pdf_document_text_iface_init);
                         });
 
 static void
@@ -1962,21 +1966,33 @@ pdf_selection_get_selection_region (EvSelection     *selection,
        return retval;
 }
 
+static void
+pdf_selection_iface_init (EvSelectionInterface *iface)
+{
+        iface->render_selection = pdf_selection_render_selection;
+       iface->get_selected_text = pdf_selection_get_selected_text;
+        iface->get_selection_region = pdf_selection_get_selection_region;
+}
+
+
+/* EvDocumentText */
 static GdkRegion *
-pdf_selection_get_selection_map (EvSelection *selection,
-                                EvPage      *page)
+pdf_document_text_get_text_mapping (EvDocumentText *document_text,
+                                   EvPage         *page)
 {
        PopplerPage *poppler_page;
        PopplerRectangle points;
        GList *region;
        GdkRegion *retval;
 
+       g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
+
        poppler_page = POPPLER_PAGE (page->backend_page);
 
        points.x1 = 0.0;
        points.y1 = 0.0;
        poppler_page_get_size (poppler_page, &(points.x2), &(points.y2));
-       
+
        region = poppler_page_get_selection_region (poppler_page, 1.0,
                                                    POPPLER_SELECTION_GLYPH,
                                                    &points);
@@ -1986,13 +2002,49 @@ pdf_selection_get_selection_map (EvSelection *selection,
        return retval;
 }
 
+static gchar *
+pdf_document_text_get_text (EvDocumentText  *selection,
+                           EvPage          *page)
+{
+       PopplerPage *poppler_page;
+       PopplerRectangle r;
+
+       g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
+
+       poppler_page = POPPLER_PAGE (page->backend_page);
+
+       r.x1 = 0;
+       r.y1 = 0;
+       poppler_page_get_size (poppler_page, &(r.x2), &(r.y2));
+
+       return poppler_page_get_text (poppler_page,
+                                     POPPLER_SELECTION_WORD,
+                                     &r);
+}
+
+static gboolean
+pdf_document_text_get_text_layout (EvDocumentText  *selection,
+                                  EvPage          *page,
+                                  EvRectangle    **areas,
+                                  guint           *n_areas)
+{
+       PopplerPage *poppler_page;
+
+       g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
+
+       poppler_page = POPPLER_PAGE (page->backend_page);
+
+       return poppler_page_get_text_layout (poppler_page, (PopplerRectangle **)areas, n_areas);
+}
+
 static void
-pdf_selection_iface_init (EvSelectionInterface *iface)
+pdf_document_text_iface_init (EvDocumentTextInterface *iface)
 {
-        iface->render_selection = pdf_selection_render_selection;
-       iface->get_selected_text = pdf_selection_get_selected_text;
-        iface->get_selection_region = pdf_selection_get_selection_region;
-        iface->get_selection_map = pdf_selection_get_selection_map;
+        iface->get_text_mapping = pdf_document_text_get_text_mapping;
+        iface->get_text = pdf_document_text_get_text;
+#ifdef HAVE_POPPLER_PAGE_GET_TEXT_LAYOUT
+        iface->get_text_layout = pdf_document_text_get_text_layout;
+#endif
 }
 
 /* Page Transitions */
index d193cee75ab8673c1f58e37c432d48c693af0e18..f9afa56e6053da4ad869c868cc05d0cef65dd47b 100644 (file)
@@ -477,6 +477,10 @@ if test "x$enable_pdf" = "xyes"; then
     PKG_CHECK_MODULES(POPPLER, poppler-glib >= $POPPLER_REQUIRED libxml-2.0 >= $LIBXML_REQUIRED,enable_pdf=yes,enable_pdf=no)
 
     if test "x$enable_pdf" = "xyes"; then
+           evince_save_LIBS=$LIBS
+           LIBS="$LIBS $POPPLER_LIBS"
+           AC_CHECK_FUNCS(poppler_page_get_text_layout)
+           LIBS=$evince_save_LIBS
            PKG_CHECK_MODULES(CAIRO_PDF, cairo-pdf, enable_cairo_pdf=yes, enable_cairo_pdf=no)
            if test x$enable_cairo_pdf = xyes; then
                    AC_DEFINE([HAVE_CAIRO_PDF], [1], [defined if cairo-pdf is available])
index 25879a9202ffc63e14054d04a807c9b8d7c46cc6..a34e863b2328aa870e10c2cb7bcdf1bb4e1d8c3c 100644 (file)
@@ -75,15 +75,3 @@ ev_selection_get_selection_region (EvSelection     *selection,
        
        return iface->get_selection_region (selection, rc, style, points);
 }
-
-GdkRegion *
-ev_selection_get_selection_map (EvSelection *selection,
-                               EvPage      *page)
-{
-       EvSelectionInterface *iface = EV_SELECTION_GET_IFACE (selection);
-
-       if (!iface->get_selection_map)
-               return NULL;
-
-       return iface->get_selection_map (selection, page);
-}
index 19b61bb5e1ed31c8ca0ec75692a21b23137373c7..5c9c7180ae6685e75b13b83ef0b1003fc800189a 100644 (file)
@@ -64,8 +64,6 @@ struct _EvSelectionInterface
                                              EvPage           *page,
                                              EvSelectionStyle  style,
                                              EvRectangle      *points);
-       GdkRegion * (* get_selection_map)    (EvSelection      *selection,
-                                             EvPage           *page);
        GdkRegion * (* get_selection_region) (EvSelection      *selection,
                                              EvRenderContext  *rc,
                                              EvSelectionStyle  style,
@@ -85,13 +83,11 @@ gchar     *ev_selection_get_selected_text    (EvSelection      *selection,
                                              EvPage           *page,
                                              EvSelectionStyle  style,
                                              EvRectangle      *points);
-GdkRegion *ev_selection_get_selection_map    (EvSelection      *selection,
-                                             EvPage           *page);
 GdkRegion *ev_selection_get_selection_region (EvSelection      *selection,
                                              EvRenderContext  *rc,
                                              EvSelectionStyle  style,
                                              EvRectangle      *points);
-                                 
+
 G_END_DECLS
 
 #endif
index 140c51ad9a9e67b936fbe31cb9941cf516f44bab..e723a9f46e3393d655204168b927985423e94ba7 100644 (file)
@@ -36,6 +36,7 @@
 #include "ev-document-print.h"
 #include "ev-document-annotations.h"
 #include "ev-document-attachments.h"
+#include "ev-document-text.h"
 #include "ev-debug.h"
 
 #include <errno.h>
@@ -593,9 +594,9 @@ ev_job_page_data_run (EvJob *job)
        ev_document_doc_mutex_lock ();
        ev_page = ev_document_get_page (job->document, job_pd->page);
 
-       if ((job_pd->flags & EV_PAGE_DATA_INCLUDE_TEXT) && EV_IS_SELECTION (job->document))
+       if ((job_pd->flags & EV_PAGE_DATA_INCLUDE_TEXT) && EV_IS_DOCUMENT_TEXT (job->document))
                job_pd->text_mapping =
-                       ev_selection_get_selection_map (EV_SELECTION (job->document), ev_page);
+                       ev_document_text_get_text_mapping (EV_DOCUMENT_TEXT (job->document), ev_page);
        if ((job_pd->flags & EV_PAGE_DATA_INCLUDE_LINKS) && EV_IS_DOCUMENT_LINKS (job->document))
                job_pd->link_mapping =
                        ev_document_links_get_links (EV_DOCUMENT_LINKS (job->document), ev_page);