From 7a9f2cc8fa9c783b4b00c7990bc01ec6b64018ab Mon Sep 17 00:00:00 2001 From: Antia Puentes Date: Wed, 10 Jul 2013 17:47:26 +0200 Subject: libview: Get text attributes from backend and save them in page cache origin commit: https://git.gnome.org/browse/evince/commit/?h=gnome-3-10&id=4592007 --- libview/ev-jobs.c | 4 ++++ libview/ev-jobs.h | 12 +++++++----- libview/ev-page-cache.c | 41 +++++++++++++++++++++++++++++++++++++++-- libview/ev-page-cache.h | 2 ++ libview/ev-view.c | 3 ++- 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/libview/ev-jobs.c b/libview/ev-jobs.c index c82ac6b5..e350376b 100644 --- a/libview/ev-jobs.c +++ b/libview/ev-jobs.c @@ -760,6 +760,10 @@ 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_ATTRS) && EV_IS_DOCUMENT_TEXT (job->document)) + job_pd ->text_attrs = + ev_document_text_get_text_attrs (EV_DOCUMENT_TEXT (job->document), + ev_page); 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); diff --git a/libview/ev-jobs.h b/libview/ev-jobs.h index ddcbd486..35a378c5 100644 --- a/libview/ev-jobs.h +++ b/libview/ev-jobs.h @@ -258,11 +258,12 @@ typedef enum { 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 + EV_PAGE_DATA_INCLUDE_TEXT_ATTRS = 1 << 4, + EV_PAGE_DATA_INCLUDE_TEXT_LOG_ATTRS = 1 << 5, + EV_PAGE_DATA_INCLUDE_IMAGES = 1 << 6, + EV_PAGE_DATA_INCLUDE_FORMS = 1 << 7, + EV_PAGE_DATA_INCLUDE_ANNOTS = 1 << 8, + EV_PAGE_DATA_INCLUDE_ALL = (1 << 9) - 1 } EvJobPageDataFlags; struct _EvJobPageData @@ -280,6 +281,7 @@ struct _EvJobPageData gchar *text; EvRectangle *text_layout; guint text_layout_length; + PangoAttrList *text_attrs; PangoLogAttr *text_log_attrs; gulong text_log_attrs_length; }; diff --git a/libview/ev-page-cache.c b/libview/ev-page-cache.c index d24382b1..827cbaf3 100644 --- a/libview/ev-page-cache.c +++ b/libview/ev-page-cache.c @@ -45,8 +45,9 @@ typedef struct _EvPageCacheData { EvRectangle *text_layout; guint text_layout_length; gchar *text; - PangoLogAttr *text_log_attrs; - gulong text_log_attrs_length; + PangoAttrList *text_attrs; + PangoLogAttr *text_log_attrs; + gulong text_log_attrs_length; } EvPageCacheData; struct _EvPageCache { @@ -127,6 +128,11 @@ ev_page_cache_data_free (EvPageCacheData *data) data->text = NULL; } + if (data->text_attrs) { + pango_attr_list_unref (data->text_attrs); + data->text_attrs = NULL; + } + if (data->text_log_attrs) { g_free (data->text_log_attrs); data->text_log_attrs = NULL; @@ -235,6 +241,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_ATTRS) { + flags = (data->text_attrs) ? + flags & ~EV_PAGE_DATA_INCLUDE_TEXT_ATTRS : + flags | EV_PAGE_DATA_INCLUDE_TEXT_ATTRS; + } + if (cache->flags & EV_PAGE_DATA_INCLUDE_TEXT_LOG_ATTRS) { flags = (data->text_log_attrs) ? flags & ~EV_PAGE_DATA_INCLUDE_TEXT_LOG_ATTRS : @@ -285,10 +297,13 @@ 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_ATTRS) + data->text_attrs = job_data->text_attrs; 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; @@ -586,6 +601,28 @@ ev_page_cache_get_text_layout (EvPageCache *cache, return FALSE; } +PangoAttrList * +ev_page_cache_get_text_attrs (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_ATTRS)) + return NULL; + + data = &cache->page_list[page]; + if (data->done) + return data->text_attrs; + + if (data->job) + return EV_JOB_PAGE_DATA(data->job)->text_attrs; + + return data->text_attrs; +} + gboolean ev_page_cache_get_text_log_attrs (EvPageCache *cache, gint page, diff --git a/libview/ev-page-cache.h b/libview/ev-page-cache.h index 08d5ec7d..a0e56af4 100644 --- a/libview/ev-page-cache.h +++ b/libview/ev-page-cache.h @@ -66,6 +66,8 @@ gboolean ev_page_cache_get_text_layout (EvPageCache *cach gint page, EvRectangle **areas, guint *n_areas); +PangoAttrList *ev_page_cache_get_text_attrs (EvPageCache *cache, + gint page); gboolean ev_page_cache_get_text_log_attrs (EvPageCache *cache, gint page, PangoLogAttr **log_attrs, diff --git a/libview/ev-view.c b/libview/ev-view.c index 155e8a64..e2ab37df 100644 --- a/libview/ev-view.c +++ b/libview/ev-view.c @@ -6576,7 +6576,8 @@ setup_caches (EvView *view) ev_page_cache_get_flags (view->page_cache) | EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT | EV_PAGE_DATA_INCLUDE_TEXT | - EV_PAGE_DATA_INCLUDE_TEXT_LOG_ATTRS); + EV_PAGE_DATA_INCLUDE_TEXT_ATTRS | + EV_PAGE_DATA_INCLUDE_TEXT_LOG_ATTRS); inverted_colors = ev_document_model_get_inverted_colors (view->model); ev_pixbuf_cache_set_inverted_colors (view->pixbuf_cache, inverted_colors); -- cgit v1.2.1