+2005-04-04 Kristian Høgsberg <krh@redhat.com>
+
+ 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 <marco@gnome.org>
* autogen.sh:
void
ev_document_find_begin (EvDocumentFind *document_find,
+ int page,
const char *search_string,
gboolean case_sensitive)
{
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
}
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
#include <glib.h>
#include <gdk/gdk.h>
+#include "ev-document.h" /* For EvRectangle */
+
G_BEGIN_DECLS
#define EV_TYPE_DOCUMENT_FIND (ev_document_find_get_type ())
/* 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 */
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);
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);
}
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;
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;
}
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;
LOG ("ev_document_render_pixbuf");
g_assert (iface->render_pixbuf);
- retval = iface->render_pixbuf (document);
+ retval = iface->render_pixbuf (document, page, scale);
return retval;
}
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,
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);
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
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);
typedef struct _EvPageCacheInfo
{
- gint width;
- gint height;
+ double width;
+ double height;
}
EvPageCacheInfo;
char **page_labels;
gboolean uniform;
- gint uniform_width;
- gint uniform_height;
+ double uniform_width;
+ double uniform_height;
EvPageCacheInfo *size_cache;
};
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);
GObject parent_instance;
PopplerDocument *document;
- PopplerPage *page;
- double scale;
gchar *password;
PdfDocumentSearch *search;
static void
pdf_document_init (PdfDocument *pdf_document)
{
- pdf_document->page = NULL;
- pdf_document->scale = 1.0;
pdf_document->password = NULL;
}
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,
}
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;
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);
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;
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);
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 */
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;
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;
}
static void
pdf_document_find_begin (EvDocumentFind *document,
+ int page,
const char *search_string,
gboolean case_sensitive)
{
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;
}
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;
}
GdkPixbuf *pixbuf;
GdkDrawable *target;
- gdouble scale;
gint x_offset, y_offset;
};
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);
}
}
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;
}
static void
pixbuf_document_init (PixbufDocument *pixbuf_document)
{
- pixbuf_document->scale = 1.0;
-
pixbuf_document->x_offset = 0;
pixbuf_document->y_offset = 0;
}
struct record_list *next;
};
+typedef struct {
+ int page;
+ double scale;
+ PSDocument *document;
+} PSRenderJob;
+
static gboolean broken_pipe = FALSE;
/* Forward declarations */
}
static void
-setup_page (PSDocument *gs)
+setup_page (PSDocument *gs, double scale)
{
char buf[1024];
#ifdef HAVE_LOCALE_H
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);
}
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);
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
*
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;
}
}
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;
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)
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;
}
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
+#include <math.h>
#include <gtk/gtkalignment.h>
#include <glib/gi18n.h>
#include <gtk/gtkbindings.h>
gboolean pressed_button;
gboolean has_selection;
GdkPoint selection_start;
- GdkRectangle selection;
+ EvRectangle selection;
EvViewCursor cursor;
GtkAdjustment *hadjustment;
}
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;
}
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;
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);
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);
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);
}
}
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),
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);
}
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
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);
}
}
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 ***/
}
}
+int
+ev_view_get_page (EvView *view)
+{
+ return view->current_page;
+}
+
static void
go_to_link (EvView *view, EvLink *link)
{
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);
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);
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);
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);