[evince] [libview] Get text and text_layout and store it in EvPageCache



commit e285bb88a28a9b510dc88f656aa39bc0093a86ec
Author: Daniel Garcia <danigm yaco es>
Date:   Sat Jun 26 16:40:41 2010 +0200

    [libview] Get text and text_layout and store it in EvPageCache

 libview/ev-jobs.c       |   10 ++++-
 libview/ev-jobs.h       |   19 ++++++---
 libview/ev-page-cache.c |   96 +++++++++++++++++++++++++++++++++++++++++-----
 libview/ev-page-cache.h |    6 +++
 4 files changed, 112 insertions(+), 19 deletions(-)
---
diff --git a/libview/ev-jobs.c b/libview/ev-jobs.c
index e723a9f..7e522df 100644
--- a/libview/ev-jobs.c
+++ b/libview/ev-jobs.c
@@ -594,9 +594,17 @@ 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_DOCUMENT_TEXT (job->document))
+	if ((job_pd->flags & EV_PAGE_DATA_INCLUDE_TEXT_MAPPING) && EV_IS_DOCUMENT_TEXT (job->document))
 		job_pd->text_mapping =
 			ev_document_text_get_text_mapping (EV_DOCUMENT_TEXT (job->document), ev_page);
+	if ((job_pd->flags & EV_PAGE_DATA_INCLUDE_TEXT) && EV_IS_DOCUMENT_TEXT (job->document))
+		job_pd->text =
+			ev_document_text_get_text (EV_DOCUMENT_TEXT (job->document), ev_page);
+	if ((job_pd->flags & EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT) && EV_IS_DOCUMENT_TEXT (job->document))
+		ev_document_text_get_text_layout (EV_DOCUMENT_TEXT (job->document),
+						  ev_page,
+						  &(job_pd->text_layout),
+						  &(job_pd->text_layout_length));
 	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);
diff --git a/libview/ev-jobs.h b/libview/ev-jobs.h
index bb406ed..2e53ff1 100644
--- a/libview/ev-jobs.h
+++ b/libview/ev-jobs.h
@@ -225,13 +225,15 @@ struct _EvJobRenderClass
 };
 
 typedef enum {
-	EV_PAGE_DATA_INCLUDE_NONE   = 0,
-	EV_PAGE_DATA_INCLUDE_LINKS  = 1 << 0,
-	EV_PAGE_DATA_INCLUDE_TEXT   = 1 << 1,
-	EV_PAGE_DATA_INCLUDE_IMAGES = 1 << 2,
-	EV_PAGE_DATA_INCLUDE_FORMS  = 1 << 3,
-	EV_PAGE_DATA_INCLUDE_ANNOTS = 1 << 4,
-	EV_PAGE_DATA_INCLUDE_ALL    = (1 << 5) - 1
+	EV_PAGE_DATA_INCLUDE_NONE         = 0,
+	EV_PAGE_DATA_INCLUDE_LINKS        = 1 << 0,
+	EV_PAGE_DATA_INCLUDE_TEXT         = 1 << 1,
+	EV_PAGE_DATA_INCLUDE_TEXT_MAPPING = 1 << 2,
+	EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT  = 1 << 3,
+	EV_PAGE_DATA_INCLUDE_IMAGES       = 1 << 4,
+	EV_PAGE_DATA_INCLUDE_FORMS        = 1 << 5,
+	EV_PAGE_DATA_INCLUDE_ANNOTS       = 1 << 6,
+	EV_PAGE_DATA_INCLUDE_ALL          = (1 << 7) - 1
 } EvJobPageDataFlags;
 
 struct _EvJobPageData
@@ -246,6 +248,9 @@ struct _EvJobPageData
 	GList *form_field_mapping;
 	GList *annot_mapping;
 	GdkRegion *text_mapping;
+	gchar *text;
+	EvRectangle *text_layout;
+	guint text_layout_length;
 };
 
 struct _EvJobPageDataClass
diff --git a/libview/ev-page-cache.c b/libview/ev-page-cache.c
index d682080..e519217 100644
--- a/libview/ev-page-cache.c
+++ b/libview/ev-page-cache.c
@@ -19,6 +19,7 @@
 
 #include <config.h>
 
+#include <glib.h>
 #include "ev-jobs.h"
 #include "ev-job-scheduler.h"
 #include "ev-mapping.h"
@@ -27,17 +28,21 @@
 #include "ev-document-forms.h"
 #include "ev-document-images.h"
 #include "ev-document-annotations.h"
+#include "ev-document-text.h"
 #include "ev-page-cache.h"
 
 typedef struct _EvPageCacheData {
-	EvJob     *job;
-	gboolean   done : 1;
-
-	GList     *link_mapping;
-	GList     *image_mapping;
-	GList     *form_field_mapping;
-	GList     *annot_mapping;
-	GdkRegion *text_mapping;
+	EvJob       *job;
+	gboolean     done : 1;
+
+	GList       *link_mapping;
+	GList       *image_mapping;
+	GList       *form_field_mapping;
+	GList       *annot_mapping;
+	GdkRegion   *text_mapping;
+	EvRectangle *text_layout;
+	guint        text_layout_length;
+	gchar       *text;
 } EvPageCacheData;
 
 struct _EvPageCache {
@@ -90,6 +95,17 @@ ev_page_cache_data_free (EvPageCacheData *data)
 		gdk_region_destroy (data->text_mapping);
 		data->text_mapping = NULL;
 	}
+
+	if (data->text_layout) {
+		g_free (data->text_layout);
+		data->text_layout = NULL;
+		data->text_layout_length = 0;
+	}
+
+	if (data->text) {
+		g_free (data->text);
+		data->text = NULL;
+	}
 }
 
 static void
@@ -150,8 +166,10 @@ get_flags_for_document (EvDocument *document)
 		flags |= EV_PAGE_DATA_INCLUDE_FORMS;
 	if (EV_IS_DOCUMENT_ANNOTATIONS (document))
 		flags |= EV_PAGE_DATA_INCLUDE_ANNOTS;
-	if (EV_IS_SELECTION (document))
-		flags |= EV_PAGE_DATA_INCLUDE_TEXT;
+	if (EV_IS_SELECTION (document) && EV_IS_DOCUMENT_TEXT (document))
+		flags |= EV_PAGE_DATA_INCLUDE_TEXT_MAPPING;
+	if (EV_IS_DOCUMENT_TEXT (document))
+		flags |= EV_PAGE_DATA_INCLUDE_TEXT | EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT;
 
 	return flags;
 }
@@ -188,6 +206,9 @@ job_page_data_finished_cb (EvJob       *job,
 	data->form_field_mapping = job_data->form_field_mapping;
 	data->annot_mapping = job_data->annot_mapping;
 	data->text_mapping = job_data->text_mapping;
+	data->text_layout = job_data->text_layout;
+	data->text_layout_length = job_data->text_layout_length;
+	data->text = job_data->text;
 	data->done = TRUE;
 
 	g_object_unref (data->job);
@@ -328,7 +349,7 @@ ev_page_cache_get_text_mapping (EvPageCache *cache,
 	g_return_val_if_fail (EV_IS_PAGE_CACHE (cache), NULL);
 	g_return_val_if_fail (page >= 0 && page < cache->n_pages, NULL);
 
-	if (!(cache->flags & EV_PAGE_DATA_INCLUDE_TEXT))
+	if (!(cache->flags & EV_PAGE_DATA_INCLUDE_TEXT_MAPPING))
 		return NULL;
 
 	data = &cache->page_list[page];
@@ -341,3 +362,56 @@ ev_page_cache_get_text_mapping (EvPageCache *cache,
 	return data->text_mapping;
 }
 
+const gchar *
+ev_page_cache_get_text (EvPageCache *cache,
+			     gint         page)
+{
+	EvPageCacheData *data;
+
+	g_return_val_if_fail (EV_IS_PAGE_CACHE (cache), NULL);
+	g_return_val_if_fail (page >= 0 && page < cache->n_pages, NULL);
+
+	if (!(cache->flags & EV_PAGE_DATA_INCLUDE_TEXT))
+		return NULL;
+
+	data = &cache->page_list[page];
+	if (data->done)
+		return data->text;
+
+	if (data->job)
+		return EV_JOB_PAGE_DATA (data->job)->text;
+
+	return data->text;
+}
+
+gboolean
+ev_page_cache_get_text_layout (EvPageCache  *cache,
+			       gint          page,
+			       EvRectangle **areas,
+			       guint        *n_areas)
+{
+	EvPageCacheData *data;
+
+	g_return_val_if_fail (EV_IS_PAGE_CACHE (cache), FALSE);
+	g_return_val_if_fail (page >= 0 && page < cache->n_pages, FALSE);
+
+	if (!(cache->flags & EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT))
+		return FALSE;
+
+	data = &cache->page_list[page];
+	if (data->done)	{
+		*areas = data->text_layout;
+		*n_areas = data->text_layout_length;
+
+		return TRUE;
+	}
+
+	if (data->job) {
+		*areas = EV_JOB_PAGE_DATA (data->job)->text_layout;
+		*n_areas = EV_JOB_PAGE_DATA (data->job)->text_layout_length;
+
+		return TRUE;
+	}
+
+	return FALSE;
+}
diff --git a/libview/ev-page-cache.h b/libview/ev-page-cache.h
index 7f3345f..0abd7e5 100644
--- a/libview/ev-page-cache.h
+++ b/libview/ev-page-cache.h
@@ -57,6 +57,12 @@ GList             *ev_page_cache_get_annot_mapping      (EvPageCache       *cach
 							 gint               page);
 GdkRegion         *ev_page_cache_get_text_mapping       (EvPageCache       *cache,
 							 gint               page);
+const gchar       *ev_page_cache_get_text               (EvPageCache       *cache,
+							 gint               page);
+gboolean           ev_page_cache_get_text_layout        (EvPageCache       *cache,
+							 gint               page,
+							 EvRectangle      **areas,
+							 guint             *n_areas);
 
 G_END_DECLS
 



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