From 18d2af9bce80392407fae997c8dfa029f5a54123 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Date: Sat, 26 Jun 2010 14:12:57 +0000 Subject: [pdf] Implement EvDocumentText interface --- diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index 8659d08..4b26290 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -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 */ diff --git a/configure.ac b/configure.ac index d193cee..f9afa56 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/libdocument/ev-selection.c b/libdocument/ev-selection.c index 25879a9..a34e863 100644 --- a/libdocument/ev-selection.c +++ b/libdocument/ev-selection.c @@ -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); -} diff --git a/libdocument/ev-selection.h b/libdocument/ev-selection.h index 19b61bb..5c9c718 100644 --- a/libdocument/ev-selection.h +++ b/libdocument/ev-selection.h @@ -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 diff --git a/libview/ev-jobs.c b/libview/ev-jobs.c index 140c51a..e723a9f 100644 --- a/libview/ev-jobs.c +++ b/libview/ev-jobs.c @@ -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 @@ -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); -- cgit v0.9.1