summaryrefslogtreecommitdiff
path: root/libview
diff options
context:
space:
mode:
authorCarlos Garcia Campos <[email protected]>2013-06-11 14:22:41 +0200
committerraveit65 <[email protected]>2017-09-06 18:25:34 +0200
commit33889b3eddebef1251e70a882b72a1710ba20083 (patch)
tree195fe268f0bad17bff2e673845df603d0d97249e /libview
parentcd36f3b5e3cd9ee377d3431b51fa3814043f52ef (diff)
downloadatril-33889b3eddebef1251e70a882b72a1710ba20083.tar.bz2
atril-33889b3eddebef1251e70a882b72a1710ba20083.tar.xz
libview: Add a way to get the text logical attributes from the page cache
It returns an array of PangoLogAttr with the logical attributes of the text for the given page. taken from: https://git.gnome.org/browse/evince/commit/?h=gnome-3-10&id=6870279
Diffstat (limited to 'libview')
-rw-r--r--libview/ev-jobs.c7
-rw-r--r--libview/ev-jobs.h21
-rw-r--r--libview/ev-page-cache.c50
-rw-r--r--libview/ev-page-cache.h5
4 files changed, 73 insertions, 10 deletions
diff --git a/libview/ev-jobs.c b/libview/ev-jobs.c
index a2ba309a..c82ac6b5 100644
--- a/libview/ev-jobs.c
+++ b/libview/ev-jobs.c
@@ -760,6 +760,13 @@ ev_job_page_data_run (EvJob *job)
ev_page,
&(job_pd->text_layout),
&(job_pd->text_layout_length));
+ if ((job_pd->flags & EV_PAGE_DATA_INCLUDE_TEXT_LOG_ATTRS) && job_pd->text) {
+ job_pd->text_log_attrs_length = g_utf8_strlen (job_pd->text, -1);
+ job_pd->text_log_attrs = g_new0 (PangoLogAttr, job_pd->text_log_attrs_length + 1);
+
+ /* FIXME: We need API to get the language of the document */
+ pango_get_log_attrs (job_pd->text, -1, -1, NULL, job_pd->text_log_attrs, job_pd->text_log_attrs_length + 1);
+ }
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 fdc23bae..ddcbd486 100644
--- a/libview/ev-jobs.h
+++ b/libview/ev-jobs.h
@@ -253,15 +253,16 @@ 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_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
+ 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_TEXT_LOG_ATTRS = 1 << 4,
+ EV_PAGE_DATA_INCLUDE_IMAGES = 1 << 5,
+ EV_PAGE_DATA_INCLUDE_FORMS = 1 << 6,
+ EV_PAGE_DATA_INCLUDE_ANNOTS = 1 << 7,
+ EV_PAGE_DATA_INCLUDE_ALL = (1 << 8) - 1
} EvJobPageDataFlags;
struct _EvJobPageData
@@ -279,6 +280,8 @@ struct _EvJobPageData
gchar *text;
EvRectangle *text_layout;
guint text_layout_length;
+ PangoLogAttr *text_log_attrs;
+ gulong text_log_attrs_length;
};
struct _EvJobPageDataClass
diff --git a/libview/ev-page-cache.c b/libview/ev-page-cache.c
index b7c5e8aa..4deef21f 100644
--- a/libview/ev-page-cache.c
+++ b/libview/ev-page-cache.c
@@ -45,6 +45,8 @@ typedef struct _EvPageCacheData {
EvRectangle *text_layout;
guint text_layout_length;
gchar *text;
+ PangoLogAttr *text_log_attrs;
+ gulong text_log_attrs_length;
} EvPageCacheData;
struct _EvPageCache {
@@ -123,6 +125,12 @@ ev_page_cache_data_free (EvPageCacheData *data)
g_free (data->text);
data->text = NULL;
}
+
+ if (data->text_log_attrs) {
+ g_free (data->text_log_attrs);
+ data->text_log_attrs = NULL;
+ data->text_log_attrs_length = 0;
+ }
}
static void
@@ -226,6 +234,12 @@ ev_page_cache_get_flags_for_data (EvPageCache *cache,
flags | EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT;
}
+ if (cache->flags & EV_PAGE_DATA_INCLUDE_TEXT_LOG_ATTRS) {
+ flags = (data->text_log_attrs) ?
+ flags & ~EV_PAGE_DATA_INCLUDE_TEXT_LOG_ATTRS :
+ flags | EV_PAGE_DATA_INCLUDE_TEXT_LOG_ATTRS;
+ }
+
return flags;
}
@@ -270,6 +284,10 @@ job_page_data_finished_cb (EvJob *job,
}
if (job_data->flags & EV_PAGE_DATA_INCLUDE_TEXT)
data->text = job_data->text;
+ if (job_data->flags & EV_PAGE_DATA_INCLUDE_TEXT_LOG_ATTRS) {
+ data->text_log_attrs = job_data->text_log_attrs;
+ data->text_log_attrs_length = job_data->text_log_attrs_length;
+ }
data->done = TRUE;
data->dirty = FALSE;
@@ -541,3 +559,35 @@ ev_page_cache_get_text_layout (EvPageCache *cache,
return FALSE;
}
+
+gboolean
+ev_page_cache_get_text_log_attrs (EvPageCache *cache,
+ gint page,
+ PangoLogAttr **log_attrs,
+ gulong *n_attrs)
+{
+ 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_LOG_ATTRS))
+ return FALSE;
+
+ data = &cache->page_list[page];
+ if (data->done) {
+ *log_attrs = data->text_log_attrs;
+ *n_attrs = data->text_log_attrs_length;
+
+ return TRUE;
+ }
+
+ if (data->job) {
+ *log_attrs = EV_JOB_PAGE_DATA (data->job)->text_log_attrs;
+ *n_attrs = EV_JOB_PAGE_DATA (data->job)->text_log_attrs_length;
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
diff --git a/libview/ev-page-cache.h b/libview/ev-page-cache.h
index 1e6bf3f6..08d5ec7d 100644
--- a/libview/ev-page-cache.h
+++ b/libview/ev-page-cache.h
@@ -66,7 +66,10 @@ gboolean ev_page_cache_get_text_layout (EvPageCache *cach
gint page,
EvRectangle **areas,
guint *n_areas);
-
+gboolean ev_page_cache_get_text_log_attrs (EvPageCache *cache,
+ gint page,
+ PangoLogAttr **log_attrs,
+ gulong *n_attrs);
G_END_DECLS
#endif /* EV_PAGE_CACHE_H */