From 5e6728daa9b09a76f2537f7c848123639165cd70 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Tue, 5 Apr 2005 00:40:58 +0000 Subject: [PATCH] Make searching work again. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2005-04-04 Kristian Høgsberg Make searching work again. * backend/ev-document.c: * backend/ev-document.h: * backend/ev-document-find.c: * backend/ev-document-find.h: Change EvDocumentIface so we no longer store the current page or zoom level in the document. The consequence is that all calls that operate on the current page now instead take the page number as an extra argument, and all coordinates are now doubles in document coordinate system. * pdf/ev-poppler.cc: * pixbuf/pixbuf-document.c: * ps/ps-document.c: Update backends accordingly. --- ChangeLog | 17 ++++ backend/ev-document-find.c | 13 +-- backend/ev-document-find.h | 16 +++- backend/ev-document.c | 70 +++------------- backend/ev-document.h | 57 ++++++------- backend/ev-jobs.c | 8 +- backend/ev-page-cache.c | 13 ++- pdf/ev-poppler.cc | 158 ++++++++++++------------------------- pixbuf/pixbuf-document.c | 57 +++---------- ps/ps-document.c | 86 +++++++------------- shell/ev-view.c | 84 +++++++++++--------- shell/ev-view.h | 1 + shell/ev-window.c | 5 +- 13 files changed, 226 insertions(+), 359 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3571839e..ac173d37 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2005-04-04 Kristian Høgsberg + + Make searching work again. + + * backend/ev-document.c: + * backend/ev-document.h: + * backend/ev-document-find.c: + * backend/ev-document-find.h: Change EvDocumentIface so we no + longer store the current page or zoom level in the document. The + consequence is that all calls that operate on the current page now + instead take the page number as an extra argument, and all + coordinates are now doubles in document coordinate system. + + * pdf/ev-poppler.cc: + * pixbuf/pixbuf-document.c: + * ps/ps-document.c: Update backends accordingly. + 2005-04-04 Marco Pesenti Gritti * autogen.sh: diff --git a/backend/ev-document-find.c b/backend/ev-document-find.c index 5c1fbe44..1be43b98 100644 --- a/backend/ev-document-find.c +++ b/backend/ev-document-find.c @@ -68,6 +68,7 @@ ev_document_find_base_init (gpointer g_class) void ev_document_find_begin (EvDocumentFind *document_find, + int page, const char *search_string, gboolean case_sensitive) { @@ -75,7 +76,7 @@ ev_document_find_begin (EvDocumentFind *document_find, g_return_if_fail (search_string != NULL); - iface->begin (document_find, search_string, case_sensitive); + iface->begin (document_find, page, search_string, case_sensitive); } void @@ -94,19 +95,21 @@ ev_document_find_page_has_results (EvDocumentFind *document_find, } int -ev_document_find_get_n_results (EvDocumentFind *document_find) +ev_document_find_get_n_results (EvDocumentFind *document_find, + int page) { EvDocumentFindIface *iface = EV_DOCUMENT_FIND_GET_IFACE (document_find); - return iface->get_n_results (document_find); + return iface->get_n_results (document_find, page); } gboolean ev_document_find_get_result (EvDocumentFind *document_find, + int page, int n_result, - GdkRectangle *rectangle) + EvRectangle *rectangle) { EvDocumentFindIface *iface = EV_DOCUMENT_FIND_GET_IFACE (document_find); - return iface->get_result (document_find, n_result, rectangle); + return iface->get_result (document_find, page, n_result, rectangle); } double diff --git a/backend/ev-document-find.h b/backend/ev-document-find.h index 49c3672b..f365df13 100644 --- a/backend/ev-document-find.h +++ b/backend/ev-document-find.h @@ -26,6 +26,8 @@ #include #include +#include "ev-document.h" /* For EvRectangle */ + G_BEGIN_DECLS #define EV_TYPE_DOCUMENT_FIND (ev_document_find_get_type ()) @@ -45,15 +47,18 @@ struct _EvDocumentFindIface /* Methods */ void (* begin) (EvDocumentFind *document_find, + int page, const char *search_string, gboolean case_sensitive); void (* cancel) (EvDocumentFind *document_find); int (* page_has_results) (EvDocumentFind *document_find, int page); - int (* get_n_results) (EvDocumentFind *document_find); + int (* get_n_results) (EvDocumentFind *document_find, + int page); gboolean (* get_result) (EvDocumentFind *document_find, + int page, int n_result, - GdkRectangle *rectangle); + EvRectangle *rectangle); double (* get_progress) (EvDocumentFind *document_find); /* Signals */ @@ -64,15 +69,18 @@ struct _EvDocumentFindIface GType ev_document_find_get_type (void); void ev_document_find_begin (EvDocumentFind *document_find, + int page, const char *search_string, gboolean case_sensitive); void ev_document_find_cancel (EvDocumentFind *document_find); int ev_document_find_page_has_results (EvDocumentFind *document_find, int page); -int ev_document_find_get_n_results (EvDocumentFind *document_find); +int ev_document_find_get_n_results (EvDocumentFind *document_find, + int page); gboolean ev_document_find_get_result (EvDocumentFind *document_find, + int page, int n_result, - GdkRectangle *rectangle); + EvRectangle *rectangle); double ev_document_find_get_progress (EvDocumentFind *document_find); void ev_document_find_changed (EvDocumentFind *document_find, int page); diff --git a/backend/ev-document.c b/backend/ev-document.c index d4d6f200..aa61fc69 100644 --- a/backend/ev-document.c +++ b/backend/ev-document.c @@ -157,43 +157,11 @@ ev_document_get_n_pages (EvDocument *document) return retval; } -void -ev_document_set_page (EvDocument *document, - int page) -{ - EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - - LOG ("ev_document_set_page"); - iface->set_page (document, page); -} - -int -ev_document_get_page (EvDocument *document) -{ - EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - int retval; - - LOG ("ev_document_get_page"); - retval = iface->get_page (document); - - return retval; -} - -void -ev_document_set_scale (EvDocument *document, - double scale) -{ - EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - - LOG ("ev_document_set_scale"); - iface->set_scale (document, scale); -} - void ev_document_get_page_size (EvDocument *document, int page, - int *width, - int *height) + double *width, + double *height) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); @@ -215,36 +183,22 @@ ev_document_get_page_label(EvDocument *document, } char * -ev_document_get_text (EvDocument *document, - GdkRectangle *rect) +ev_document_get_text (EvDocument *document, + int page, + EvRectangle *rect) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); char *retval; LOG ("ev_document_get_text"); - retval = iface->get_text (document, rect); - - return retval; -} - -EvLink * -ev_document_get_link (EvDocument *document, - int x, - int y) -{ - EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - EvLink *retval; - - LOG ("ev_document_get_link"); - if (iface->get_link == NULL) - return NULL; - retval = iface->get_link (document, x, y); + retval = iface->get_text (document, page, rect); return retval; } GList * -ev_document_get_links (EvDocument *document) +ev_document_get_links (EvDocument *document, + int page) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); GList *retval; @@ -252,7 +206,7 @@ ev_document_get_links (EvDocument *document) LOG ("ev_document_get_link"); if (iface->get_links == NULL) return NULL; - retval = iface->get_links (document); + retval = iface->get_links (document, page); return retval; } @@ -260,7 +214,9 @@ ev_document_get_links (EvDocument *document) GdkPixbuf * -ev_document_render_pixbuf (EvDocument *document) +ev_document_render_pixbuf (EvDocument *document, + int page, + double scale) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); GdkPixbuf *retval; @@ -268,7 +224,7 @@ ev_document_render_pixbuf (EvDocument *document) LOG ("ev_document_render_pixbuf"); g_assert (iface->render_pixbuf); - retval = iface->render_pixbuf (document); + retval = iface->render_pixbuf (document, page, scale); return retval; } diff --git a/backend/ev-document.h b/backend/ev-document.h index e5c91b71..743b9478 100644 --- a/backend/ev-document.h +++ b/backend/ev-document.h @@ -54,14 +54,17 @@ typedef enum EV_DOCUMENT_ERROR_ENCRYPTED } EvDocumentError; +typedef struct { + double x1; + double y1; + double x2; + double y2; +} EvRectangle; + struct _EvDocumentIface { GTypeInterface base_iface; - /* Signals */ - void (* page_changed) (EvDocument *document); - void (* scale_changed) (EvDocument *document); - /* Methods */ gboolean (* load) (EvDocument *document, const char *uri, @@ -70,24 +73,20 @@ struct _EvDocumentIface const char *uri, GError **error); int (* get_n_pages) (EvDocument *document); - void (* set_page) (EvDocument *document, - int page); - int (* get_page) (EvDocument *document); - void (* set_scale) (EvDocument *document, - double scale); void (* get_page_size) (EvDocument *document, int page, - int *width, - int *height); + double *width, + double *height); char * (* get_page_label) (EvDocument *document, int page); char * (* get_text) (EvDocument *document, - GdkRectangle *rect); - EvLink * (* get_link) (EvDocument *document, - int x, - int y); - GList * (* get_links) (EvDocument *document); - GdkPixbuf * (* render_pixbuf) (EvDocument *document); + int page, + EvRectangle *rect); + GList * (* get_links) (EvDocument *document, + int page); + GdkPixbuf * (* render_pixbuf) (EvDocument *document, + int page, + double scale); }; GType ev_document_get_type (void); @@ -104,24 +103,20 @@ gboolean ev_document_save (EvDocument *document, GError **error); char *ev_document_get_title (EvDocument *document); int ev_document_get_n_pages (EvDocument *document); -void ev_document_set_page (EvDocument *document, - int page); -int ev_document_get_page (EvDocument *document); -void ev_document_set_scale (EvDocument *document, - double scale); void ev_document_get_page_size (EvDocument *document, int page, - int *width, - int *height); + double *width, + double *height); char *ev_document_get_page_label(EvDocument *document, - int page); + int page); char *ev_document_get_text (EvDocument *document, - GdkRectangle *rect); -EvLink *ev_document_get_link (EvDocument *document, - int x, - int y); -GList *ev_document_get_links (EvDocument *document); -GdkPixbuf *ev_document_render_pixbuf (EvDocument *document); + int page, + EvRectangle *rect); +GList *ev_document_get_links (EvDocument *document, + int page); +GdkPixbuf *ev_document_render_pixbuf (EvDocument *document, + int page, + double scale); G_END_DECLS diff --git a/backend/ev-jobs.c b/backend/ev-jobs.c index 8265aebd..0a5f69fe 100644 --- a/backend/ev-jobs.c +++ b/backend/ev-jobs.c @@ -206,11 +206,11 @@ ev_job_render_run (EvJobRender *job) g_mutex_lock (EV_DOC_MUTEX); - ev_document_set_page (EV_JOB (job)->document, job->page); - ev_document_set_scale (EV_JOB (job)->document, job->scale); - job->pixbuf = ev_document_render_pixbuf (EV_JOB (job)->document); + job->pixbuf = ev_document_render_pixbuf (EV_JOB (job)->document, + job->page, + job->scale); if (job->include_links) - job->link_mapping = ev_document_get_links (EV_JOB (job)->document); + job->link_mapping = ev_document_get_links (EV_JOB (job)->document, job->page); EV_JOB (job)->finished = TRUE; g_mutex_unlock (EV_DOC_MUTEX); diff --git a/backend/ev-page-cache.c b/backend/ev-page-cache.c index 08d1be45..7960cb43 100644 --- a/backend/ev-page-cache.c +++ b/backend/ev-page-cache.c @@ -5,8 +5,8 @@ typedef struct _EvPageCacheInfo { - gint width; - gint height; + double width; + double height; } EvPageCacheInfo; @@ -21,8 +21,8 @@ struct _EvPageCache char **page_labels; gboolean uniform; - gint uniform_width; - gint uniform_height; + double uniform_width; + double uniform_height; EvPageCacheInfo *size_cache; }; @@ -105,10 +105,9 @@ _ev_page_cache_new (EvDocument *document) page_cache->title = ev_document_get_title (document); page_cache->page_labels = g_new0 (char *, page_cache->n_pages); - ev_document_set_scale (document, 1.0); for (i = 0; i < page_cache->n_pages; i++) { - gint page_width = 0; - gint page_height = 0; + double page_width = 0; + double page_height = 0; ev_document_get_page_size (document, i, &page_width, &page_height); page_cache->page_labels[i] = ev_document_get_page_label (document, i); diff --git a/pdf/ev-poppler.cc b/pdf/ev-poppler.cc index e1ce95a4..7fcc9c0d 100644 --- a/pdf/ev-poppler.cc +++ b/pdf/ev-poppler.cc @@ -58,8 +58,6 @@ struct _PdfDocument GObject parent_instance; PopplerDocument *document; - PopplerPage *page; - double scale; gchar *password; PdfDocumentSearch *search; @@ -133,8 +131,6 @@ pdf_document_class_init (PdfDocumentClass *klass) static void pdf_document_init (PdfDocument *pdf_document) { - pdf_document->page = NULL; - pdf_document->scale = 1.0; pdf_document->password = NULL; } @@ -208,85 +204,29 @@ pdf_document_get_n_pages (EvDocument *document) return poppler_document_get_n_pages (PDF_DOCUMENT (document)->document); } -static void -pdf_document_set_page (EvDocument *document, - int page) -{ - page = CLAMP (page, 0, poppler_document_get_n_pages (PDF_DOCUMENT (document)->document) - 1); - - PDF_DOCUMENT (document)->page = poppler_document_get_page (PDF_DOCUMENT (document)->document, page); -} - -static int -pdf_document_get_page (EvDocument *document) -{ - PdfDocument *pdf_document; - - pdf_document = PDF_DOCUMENT (document); - - if (pdf_document->page) - return poppler_page_get_index (pdf_document->page); - - return 1; -} - -static void -pdf_document_set_scale (EvDocument *document, - double scale) -{ - PDF_DOCUMENT (document)->scale = scale; -} - - -static void -get_size_from_page (PopplerPage *poppler_page, - double scale, - int *width, - int *height) -{ - gdouble width_d, height_d; - poppler_page_get_size (poppler_page, &width_d, &height_d); - if (width) - *width = (int) (width_d * scale); - if (height) - *height = (int) (height_d * scale); - -} - static void pdf_document_get_page_size (EvDocument *document, int page, - int *width, - int *height) + double *width, + double *height) { - PopplerPage *poppler_page = NULL; - - if (page == -1) - poppler_page = PDF_DOCUMENT (document)->page; - else - poppler_page = poppler_document_get_page (PDF_DOCUMENT (document)->document, - page); + PopplerPage *poppler_page; - if (poppler_page == NULL) - poppler_document_get_page (PDF_DOCUMENT (document)->document, 0); + poppler_page = poppler_document_get_page (PDF_DOCUMENT (document)->document, + page); - get_size_from_page (poppler_page, - PDF_DOCUMENT (document)->scale, - width, height); + poppler_page_get_size (poppler_page, width, height); } static char * pdf_document_get_page_label (EvDocument *document, int page) { - PopplerPage *poppler_page = NULL; + PopplerPage *poppler_page; char *label = NULL; - if (page == -1) - poppler_page = PDF_DOCUMENT (document)->page; - else - poppler_page = poppler_document_get_page (PDF_DOCUMENT (document)->document, - page); + poppler_page = poppler_document_get_page (PDF_DOCUMENT (document)->document, + page); g_object_get (poppler_page, "label", &label, @@ -296,19 +236,21 @@ pdf_document_get_page_label (EvDocument *document, } static GList * -pdf_document_get_links (EvDocument *document) +pdf_document_get_links (EvDocument *document, + int page) { PdfDocument *pdf_document; + PopplerPage *poppler_page; GList *retval = NULL; GList *mapping_list; GList *list; - gint height; + double height; pdf_document = PDF_DOCUMENT (document); - g_return_val_if_fail (pdf_document->page != NULL, NULL); - - mapping_list = poppler_page_get_link_mapping (pdf_document->page); - get_size_from_page (pdf_document->page, 1.0, NULL, &height); + poppler_page = poppler_document_get_page (pdf_document->document, + page); + mapping_list = poppler_page_get_link_mapping (poppler_page); + poppler_page_get_size (poppler_page, NULL, &height); for (list = mapping_list; list; list = list->next) { PopplerLinkMapping *link_mapping; @@ -333,27 +275,32 @@ pdf_document_get_links (EvDocument *document) static GdkPixbuf * -pdf_document_render_pixbuf (EvDocument *document) +pdf_document_render_pixbuf (EvDocument *document, + int page, + double scale) { PdfDocument *pdf_document; + PopplerPage *poppler_page; GdkPixbuf *pixbuf; + double width_points, height_points; gint width, height; pdf_document = PDF_DOCUMENT (document); - g_return_val_if_fail (pdf_document->page != NULL, NULL); + poppler_page = poppler_document_get_page (pdf_document->document, + page); - get_size_from_page (pdf_document->page, - pdf_document->scale, - &width, &height); + poppler_page_get_size (poppler_page, &width_points, &height_points); + width = (int) ceil (width_points * scale); + height = (int) ceil (height_points * scale); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); - poppler_page_render_to_pixbuf (pdf_document->page, + poppler_page_render_to_pixbuf (poppler_page, 0, 0, width, height, - pdf_document->scale, + scale, pixbuf, 0, 0); @@ -389,9 +336,6 @@ pdf_document_document_iface_init (EvDocumentIface *iface) iface->save = pdf_document_save; iface->load = pdf_document_load; iface->get_n_pages = pdf_document_get_n_pages; - iface->set_page = pdf_document_set_page; - iface->get_page = pdf_document_get_page; - iface->set_scale = pdf_document_set_scale; iface->get_page_size = pdf_document_get_page_size; iface->get_page_label = pdf_document_get_page_label; iface->get_links = pdf_document_get_links; @@ -599,10 +543,9 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail has_thumb = poppler_page_get_thumbnail_size (poppler_page, width, height); if (!has_thumb) { - int page_width, page_height; - - get_size_from_page (poppler_page, 1.0, &page_width, &page_height); + double page_width, page_height; + poppler_page_get_size (poppler_page, &page_width, &page_height); if (page_width > page_height) { *width = size; *height = (int) (size * page_height / page_width); @@ -640,8 +583,7 @@ pdf_document_search_idle_callback (void *data) search->pages[search->search_page] = matches; n_pages = pdf_document_get_n_pages (EV_DOCUMENT (search->document)); - changed_page = search->start_page; - + changed_page = search->search_page; search->search_page += 1; if (search->search_page == n_pages) { /* wrap around */ @@ -661,7 +603,9 @@ pdf_document_search_idle_callback (void *data) static PdfDocumentSearch * -pdf_document_search_new (PdfDocument *pdf_document, const char *text) +pdf_document_search_new (PdfDocument *pdf_document, + int start_page, + const char *text) { PdfDocumentSearch *search; int n_pages; @@ -685,8 +629,8 @@ pdf_document_search_new (PdfDocument *pdf_document, const char *text) search, NULL); - search->start_page = pdf_document_get_page (EV_DOCUMENT (pdf_document)); - search->search_page = search->start_page; + search->start_page = start_page; + search->search_page = start_page; return search; } @@ -712,6 +656,7 @@ pdf_document_search_free (PdfDocumentSearch *search) static void pdf_document_find_begin (EvDocumentFind *document, + int page, const char *search_string, gboolean case_sensitive) { @@ -730,19 +675,18 @@ pdf_document_find_begin (EvDocumentFind *document, pdf_document_search_free (pdf_document->search); pdf_document->search = pdf_document_search_new (pdf_document, + page, search_string); } int -pdf_document_find_get_n_results (EvDocumentFind *document_find) +pdf_document_find_get_n_results (EvDocumentFind *document_find, int page) { PdfDocumentSearch *search = PDF_DOCUMENT (document_find)->search; int current_page; - current_page = pdf_document_get_page (EV_DOCUMENT (document_find)); - if (search) { - return g_list_length (search->pages[current_page]); + return g_list_length (search->pages[page]); } else { return 0; } @@ -750,29 +694,31 @@ pdf_document_find_get_n_results (EvDocumentFind *document_find) gboolean pdf_document_find_get_result (EvDocumentFind *document_find, + int page, int n_result, - GdkRectangle *rectangle) + EvRectangle *rectangle) { PdfDocument *pdf_document = PDF_DOCUMENT (document_find); PdfDocumentSearch *search = pdf_document->search; + PopplerPage *poppler_page; PopplerRectangle *r; int current_page; - double scale; + double scale, height; if (search == NULL) return FALSE; - current_page = pdf_document_get_page (EV_DOCUMENT (pdf_document)); - r = (PopplerRectangle *) g_list_nth_data (search->pages[current_page], + r = (PopplerRectangle *) g_list_nth_data (search->pages[page], n_result); if (r == NULL) return FALSE; - scale = pdf_document->scale; - rectangle->x = (gint) floor (r->x1 * scale); - rectangle->y = (gint) floor (r->y1 * scale); - rectangle->width = (gint) ceil (r->x2 * scale) - rectangle->x; - rectangle->height = (gint) ceil (r->y2 * scale) - rectangle->y; + poppler_page = poppler_document_get_page (pdf_document->document, page); + poppler_page_get_size (poppler_page, NULL, &height); + rectangle->x1 = r->x1; + rectangle->y1 = height - r->y2; + rectangle->x2 = r->x2; + rectangle->y2 = height - r->y1; return TRUE; } diff --git a/pixbuf/pixbuf-document.c b/pixbuf/pixbuf-document.c index c728ed08..b83da789 100644 --- a/pixbuf/pixbuf-document.c +++ b/pixbuf/pixbuf-document.c @@ -36,7 +36,6 @@ struct _PixbufDocument GdkPixbuf *pixbuf; GdkDrawable *target; - gdouble scale; gint x_offset, y_offset; }; @@ -93,49 +92,30 @@ pixbuf_document_get_n_pages (EvDocument *document) return 1; } -static void -pixbuf_document_set_page (EvDocument *document, - int page) -{ - /* Do nothing */ -} - -static int -pixbuf_document_get_page (EvDocument *document) -{ - return 1; -} - -static void -pixbuf_document_set_scale (EvDocument *document, - double scale) -{ - PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document); - - pixbuf_document->scale = scale; -} - static void pixbuf_document_get_page_size (EvDocument *document, int page, - int *width, - int *height) + double *width, + double *height) { PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document); if (width) - *width = gdk_pixbuf_get_width (pixbuf_document->pixbuf) * pixbuf_document->scale; + *width = gdk_pixbuf_get_width (pixbuf_document->pixbuf); if (height) - *height = gdk_pixbuf_get_height (pixbuf_document->pixbuf) * pixbuf_document->scale; + *height = gdk_pixbuf_get_height (pixbuf_document->pixbuf); + + printf ("get_page_size, page=%d, *width=%f, *height=%f\n", + page, *width, *height); } static GdkPixbuf* -pixbuf_document_render_pixbuf (EvDocument *document) +pixbuf_document_render_pixbuf (EvDocument *document, int page, double scale) { PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document); return gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, - gdk_pixbuf_get_width (pixbuf_document->pixbuf) * pixbuf_document->scale, - gdk_pixbuf_get_height (pixbuf_document->pixbuf) * pixbuf_document->scale, + gdk_pixbuf_get_width (pixbuf_document->pixbuf) * scale, + gdk_pixbuf_get_height (pixbuf_document->pixbuf) * scale, GDK_INTERP_BILINEAR); } @@ -190,33 +170,20 @@ pixbuf_document_class_init (PixbufDocumentClass *klass) } static char * -pixbuf_document_get_text (EvDocument *document, GdkRectangle *rect) +pixbuf_document_get_text (EvDocument *document, int page, EvRectangle *rect) { /* FIXME this method should not be in EvDocument */ g_warning ("pixbuf_document_get_text not implemented"); return NULL; } - -static EvLink * -pixbuf_document_get_link (EvDocument *document, - int x, - int y) -{ - return NULL; -} - static void pixbuf_document_document_iface_init (EvDocumentIface *iface) { iface->load = pixbuf_document_load; iface->save = pixbuf_document_save; iface->get_text = pixbuf_document_get_text; - iface->get_link = pixbuf_document_get_link; iface->get_n_pages = pixbuf_document_get_n_pages; - iface->set_page = pixbuf_document_set_page; - iface->get_page = pixbuf_document_get_page; - iface->set_scale = pixbuf_document_set_scale; iface->get_page_size = pixbuf_document_get_page_size; iface->render_pixbuf = pixbuf_document_render_pixbuf; } @@ -269,8 +236,6 @@ pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface static void pixbuf_document_init (PixbufDocument *pixbuf_document) { - pixbuf_document->scale = 1.0; - pixbuf_document->x_offset = 0; pixbuf_document->y_offset = 0; } diff --git a/ps/ps-document.c b/ps/ps-document.c index 4b2d4c43..20d55c44 100644 --- a/ps/ps-document.c +++ b/ps/ps-document.c @@ -82,6 +82,12 @@ struct record_list { struct record_list *next; }; +typedef struct { + int page; + double scale; + PSDocument *document; +} PSRenderJob; + static gboolean broken_pipe = FALSE; /* Forward declarations */ @@ -381,7 +387,7 @@ setup_pixmap (PSDocument *gs) } static void -setup_page (PSDocument *gs) +setup_page (PSDocument *gs, double scale) { char buf[1024]; #ifdef HAVE_LOCALE_H @@ -400,8 +406,8 @@ setup_page (PSDocument *gs) g_snprintf (buf, 1024, "%ld %d %d %d %d %d %f %f %d %d %d %d", 0L, gs->orientation * 90, gs->llx, gs->lly, gs->urx, gs->ury, - get_xdpi (gs) * gs->zoom_factor, - get_ydpi (gs) * gs->zoom_factor, + get_xdpi (gs) * scale, + get_ydpi (gs) * scale, 0, 0, 0, 0); LOG ("GS property %s", buf); @@ -1106,7 +1112,7 @@ ps_document_next_page (PSDocument *gs) } static gboolean -render_page (PSDocument *gs) +render_page (PSDocument *gs, int page) { g_return_val_if_fail(gs != NULL, FALSE); g_return_val_if_fail(PS_IS_DOCUMENT(gs), FALSE); @@ -1126,8 +1132,8 @@ render_page (PSDocument *gs) send_ps (gs, gs->doc->beginsetup, gs->doc->lensetup, FALSE); } - send_ps (gs, gs->doc->pages[gs->current_page].begin, - gs->doc->pages[gs->current_page].len, FALSE); + send_ps (gs, gs->doc->pages[page].begin, + gs->doc->pages[page].len, FALSE); } else { /* Unstructured document * @@ -1198,48 +1204,18 @@ ps_document_get_n_pages (EvDocument *document) return ps->structured_doc ? ps->doc->numpages : 1; } -static void -ps_document_set_page (EvDocument *document, - int page) -{ - PSDocument *gs = PS_DOCUMENT (document); - - LOG ("Set document page %d\n", page); - - gs->current_page = page; - compute_dimensions (gs, page); -} - -static int -ps_document_get_page (EvDocument *document) -{ - PSDocument *ps = PS_DOCUMENT (document); - - g_return_val_if_fail (ps != NULL, -1); - - return ps->current_page; -} - -static void -ps_document_set_scale (EvDocument *document, - double scale) -{ - PSDocument *gs = PS_DOCUMENT (document); - - gs->zoom_factor = scale; - compute_dimensions (gs, gs->current_page); -} - static void ps_document_get_page_size (EvDocument *document, int page, - int *width, - int *height) + double *width, + double *height) { /* Post script documents never vary in size */ PSDocument *gs = PS_DOCUMENT (document); + compute_dimensions (gs, page); + if (width) { *width = gs->width; } @@ -1250,24 +1226,16 @@ ps_document_get_page_size (EvDocument *document, } static char * -ps_document_get_text (EvDocument *document, GdkRectangle *rect) +ps_document_get_text (EvDocument *document, int page, EvRectangle *rect) { g_warning ("ps_document_get_text not implemented"); /* FIXME ? */ return NULL; } -static EvLink * -ps_document_get_link (EvDocument *document, - int x, - int y) -{ - return NULL; -} - static gboolean -render_pixbuf_idle (EvDocument *document) +render_pixbuf_idle (PSRenderJob *job) { - PSDocument *gs = PS_DOCUMENT (document); + PSDocument *gs = job->document; if (gs->pstarget == NULL) { GtkWidget *widget; @@ -1286,21 +1254,25 @@ render_pixbuf_idle (EvDocument *document) if (gs->changed) { stop_interpreter (gs); setup_pixmap (gs); - setup_page (gs); + setup_page (gs, job->scale); gs->changed = FALSE; } - render_page (PS_DOCUMENT (document)); + render_page (gs, job->page); return FALSE; } static GdkPixbuf * -ps_document_render_pixbuf (EvDocument *document) +ps_document_render_pixbuf (EvDocument *document, int page, double scale) { GdkPixbuf *pixbuf; + PSRenderJob job; - g_idle_add ((GSourceFunc)render_pixbuf_idle, document); + job.page = page; + job.scale = scale; + job.document = PS_DOCUMENT (document); + g_idle_add ((GSourceFunc)render_pixbuf_idle, &job); g_mutex_lock (pixbuf_mutex); while (!current_pixbuf) @@ -1320,11 +1292,7 @@ ps_document_document_iface_init (EvDocumentIface *iface) iface->load = ps_document_load; iface->save = ps_document_save; iface->get_text = ps_document_get_text; - iface->get_link = ps_document_get_link; iface->get_n_pages = ps_document_get_n_pages; - iface->set_page = ps_document_set_page; - iface->get_page = ps_document_get_page; - iface->set_scale = ps_document_set_scale; iface->get_page_size = ps_document_get_page_size; iface->render_pixbuf = ps_document_render_pixbuf; } diff --git a/shell/ev-view.c b/shell/ev-view.c index 29c85f46..2db13179 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -18,6 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ +#include #include #include #include @@ -94,7 +95,7 @@ struct _EvView { gboolean pressed_button; gboolean has_selection; GdkPoint selection_start; - GdkRectangle selection; + EvRectangle selection; EvViewCursor cursor; GtkAdjustment *hadjustment; @@ -257,27 +258,27 @@ ev_view_get_offsets (EvView *view, int *x_offset, int *y_offset) } static void -view_rect_to_doc_rect (EvView *view, GdkRectangle *view_rect, GdkRectangle *doc_rect) +view_rect_to_doc_rect (EvView *view, GdkRectangle *view_rect, EvRectangle *doc_rect) { int x_offset, y_offset; ev_view_get_offsets (view, &x_offset, &y_offset); - doc_rect->x = (view_rect->x - x_offset) / view->scale; - doc_rect->y = (view_rect->y - y_offset) / view->scale; - doc_rect->width = view_rect->width / view->scale; - doc_rect->height = view_rect->height / view->scale; + doc_rect->x1 = (double) (view_rect->x - x_offset) / view->scale; + doc_rect->y1 = (double) (view_rect->y - y_offset) / view->scale; + doc_rect->x2 = doc_rect->x1 + (double) view_rect->width / view->scale; + doc_rect->y2 = doc_rect->y1 + (double) view_rect->height / view->scale; } static void -doc_rect_to_view_rect (EvView *view, GdkRectangle *doc_rect, GdkRectangle *view_rect) +doc_rect_to_view_rect (EvView *view, EvRectangle *doc_rect, GdkRectangle *view_rect) { int x_offset, y_offset; ev_view_get_offsets (view, &x_offset, &y_offset); - view_rect->x = doc_rect->x * view->scale + x_offset; - view_rect->y = doc_rect->y * view->scale + y_offset; - view_rect->width = doc_rect->width * view->scale; - view_rect->height = doc_rect->height * view->scale; + view_rect->x = floor (doc_rect->x1 * view->scale) + x_offset; + view_rect->y = floor (doc_rect->y1 * view->scale) + y_offset; + view_rect->width = ceil (doc_rect->x2 * view->scale) + x_offset - view_rect->x; + view_rect->height = ceil (doc_rect->y2 * view->scale) + y_offset - view_rect->y; } @@ -436,9 +437,6 @@ draw_rubberband (GtkWidget *widget, GdkWindow *window, GdkPixbuf *pixbuf; GdkColor *fill_color_gdk; guint fill_color; - int x_offset, y_offset; - - ev_view_get_offsets (EV_VIEW (widget), &x_offset, &y_offset); fill_color_gdk = gdk_color_copy (>K_WIDGET (widget)->style->base[GTK_STATE_SELECTED]); fill_color = ev_gdk_color_to_rgb (fill_color_gdk) << 8 | alpha; @@ -449,7 +447,7 @@ draw_rubberband (GtkWidget *widget, GdkWindow *window, gdk_draw_pixbuf (window, NULL, pixbuf, 0, 0, - rect->x + x_offset, rect->y + y_offset, + rect->x, rect->y, rect->width, rect->height, GDK_RGB_DITHER_NONE, 0, 0); @@ -459,7 +457,7 @@ draw_rubberband (GtkWidget *widget, GdkWindow *window, gc = gdk_gc_new (window); gdk_gc_set_rgb_fg_color (gc, fill_color_gdk); gdk_draw_rectangle (window, gc, FALSE, - rect->x + x_offset, rect->y + y_offset, + rect->x, rect->y, rect->width - 1, rect->height - 1); g_object_unref (gc); @@ -478,19 +476,22 @@ highlight_find_results (EvView *view) find = EV_DOCUMENT_FIND (view->document); g_mutex_lock (EV_DOC_MUTEX); - results = ev_document_find_get_n_results (find); + results = ev_document_find_get_n_results (find, view->current_page); g_mutex_unlock (EV_DOC_MUTEX); for (i = 0; i < results; i++) { - GdkRectangle rectangle; + EvRectangle rectangle; + GdkRectangle view_rectangle; guchar alpha; alpha = (i == view->find_result) ? 0x90 : 0x20; g_mutex_lock (EV_DOC_MUTEX); - ev_document_find_get_result (find, i, &rectangle); + ev_document_find_get_result (find, view->current_page, + i, &rectangle); g_mutex_unlock (EV_DOC_MUTEX); + doc_rect_to_view_rect (view, &rectangle, &view_rectangle); draw_rubberband (GTK_WIDGET (view), view->bin_window, - &rectangle, alpha); + &view_rectangle, alpha); } } @@ -617,12 +618,12 @@ void ev_view_copy (EvView *ev_view) { GtkClipboard *clipboard; - GdkRectangle selection; char *text; - doc_rect_to_view_rect (ev_view, &ev_view->selection, &selection); g_mutex_lock (EV_DOC_MUTEX); - text = ev_document_get_text (ev_view->document, &selection); + text = ev_document_get_text (ev_view->document, + ev_view->current_page, + &ev_view->selection); g_mutex_unlock (EV_DOC_MUTEX); clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view), @@ -638,12 +639,12 @@ ev_view_primary_get_cb (GtkClipboard *clipboard, gpointer data) { EvView *ev_view = EV_VIEW (data); - GdkRectangle selection; char *text; - doc_rect_to_view_rect (ev_view, &ev_view->selection, &selection); g_mutex_lock (EV_DOC_MUTEX); - text = ev_document_get_text (ev_view->document, &selection); + text = ev_document_get_text (ev_view->document, + ev_view->current_page, + &ev_view->selection); g_mutex_unlock (EV_DOC_MUTEX); gtk_selection_data_set_text (selection_data, text, -1); } @@ -1207,12 +1208,13 @@ update_find_status_message (EvView *view) char *message; // g_mutex_lock (EV_DOC_MUTEX); - if (ev_document_get_page (view->document) == view->find_page) { + if (view->current_page == view->find_page) { int results; // g_mutex_lock (EV_DOC_MUTEX); results = ev_document_find_get_n_results - (EV_DOCUMENT_FIND (view->document)); + (EV_DOCUMENT_FIND (view->document), + view->current_page); // g_mutex_unlock (EV_DOC_MUTEX); /* TRANS: Sometimes this could be better translated as "%d hit(s) on this page". Therefore this string @@ -1280,20 +1282,22 @@ static void jump_to_find_result (EvView *view) { EvDocumentFind *find = EV_DOCUMENT_FIND (view->document); - GdkRectangle rect; + EvRectangle rect; + GdkRectangle view_rect; int n_results; g_mutex_lock (EV_DOC_MUTEX); - n_results = ev_document_find_get_n_results (find); + n_results = ev_document_find_get_n_results (find, view->current_page); g_mutex_unlock (EV_DOC_MUTEX); if (n_results > view->find_result) { g_mutex_lock (EV_DOC_MUTEX); ev_document_find_get_result - (find, view->find_result, &rect); + (find, view->current_page, view->find_result, &rect); g_mutex_unlock (EV_DOC_MUTEX); - ensure_rectangle_is_visible (view, &rect); + doc_rect_to_view_rect (view, &rect, &view_rect); + ensure_rectangle_is_visible (view, &view_rect); } } @@ -1334,12 +1338,8 @@ find_changed_cb (EvDocument *document, int page, EvView *view) jump_to_find_result (view); update_find_status_message (view); -#if 0 - /* FIXME: */ - if (ev_document_get_page (document) == page) { + if (view->current_page == page) gtk_widget_queue_draw (GTK_WIDGET (view)); - } -#endif } /*** Public API ***/ @@ -1443,6 +1443,12 @@ ev_view_set_document (EvView *view, } } +int +ev_view_get_page (EvView *view) +{ + return view->current_page; +} + static void go_to_link (EvView *view, EvLink *link) { @@ -1593,7 +1599,7 @@ ev_view_find_next (EvView *view) page_cache = ev_document_get_page_cache (view->document); g_mutex_lock (EV_DOC_MUTEX); - n_results = ev_document_find_get_n_results (find); + n_results = ev_document_find_get_n_results (find, view->current_page); g_mutex_unlock (EV_DOC_MUTEX); n_pages = ev_page_cache_get_n_pages (page_cache); @@ -1625,7 +1631,7 @@ ev_view_find_previous (EvView *view) page_cache = ev_document_get_page_cache (view->document); g_mutex_lock (EV_DOC_MUTEX); - n_results = ev_document_find_get_n_results (find); + n_results = ev_document_find_get_n_results (find, view->current_page); g_mutex_unlock (EV_DOC_MUTEX); n_pages = ev_page_cache_get_n_pages (page_cache); diff --git a/shell/ev-view.h b/shell/ev-view.h index 00b92ea8..8ba79f1e 100644 --- a/shell/ev-view.h +++ b/shell/ev-view.h @@ -38,6 +38,7 @@ GType ev_view_get_type (void) G_GNUC_CONST; GtkWidget* ev_view_new (void); void ev_view_set_document (EvView *view, EvDocument *document); +int ev_view_get_page (EvView *view); /* Clipboard */ void ev_view_copy (EvView *view); diff --git a/shell/ev-window.c b/shell/ev-window.c index e606aedf..64b072e1 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -1876,7 +1876,10 @@ find_bar_search_changed_cb (EggFindBar *find_bar, EV_IS_DOCUMENT_FIND (ev_window->priv->document)) { if (visible && search_string && search_string[0]) { g_mutex_lock (EV_DOC_MUTEX); - ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document), search_string, case_sensitive); + ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document), + ev_view_get_page (EV_VIEW (ev_window->priv->view)), + search_string, + case_sensitive); g_mutex_unlock (EV_DOC_MUTEX); } else { g_mutex_lock (EV_DOC_MUTEX); -- 2.43.5