#include "pdf-document.h"
#include "ev-ps-exporter.h"
#include "ev-document-find.h"
+#include "ev-document-misc.h"
#include "gpdf-g-switch.h"
#include "ev-document-links.h"
-#include "ev-document-misc.h"
#include "ev-document-security.h"
#include "ev-document-thumbnails.h"
/* full results are only possible for the rendered current page */
int current_page;
GArray *current_page_results;
- guchar *other_page_flags; /* length n_pages + 1, first element ignored */
+ int *other_page_flags; /* length n_pages + 1, first element ignored */
int start_page; /* skip this one as we iterate, since we did it first */
int search_page; /* the page we're searching now */
TextOutputDev *output_dev;
static void
pdf_document_get_page_size (EvDocument *document,
+ int page,
int *width,
int *height)
{
PdfDocument *pdf_document = PDF_DOCUMENT (document);
+ Page *the_page;
- if (document_validate_page (pdf_document)) {
+ /* set some default values */
+ if (width)
+ *width = 1;
+ if (height)
+ *height = 1;
+
+
+ if (page == -1 && document_validate_page (pdf_document)) {
if (width)
*width = pdf_document->out->getBitmapWidth();
if (height)
*height = pdf_document->out->getBitmapHeight();
- } else {
- if (width)
- *width = 1;
- if (height)
- *height = 1;
+ return;
+ }
+
+ the_page = pdf_document->doc->getCatalog ()->getPage (page);
+ if (the_page) {
+ *width = (int) the_page->getWidth ();
+ *height = (int) the_page->getHeight ();
}
}
draw.width, draw.height);
}
-static void
-pdf_document_search_emit_found (PdfDocumentSearch *search)
+double
+pdf_document_find_get_progress (EvDocumentFind *document_find)
{
- PdfDocument *pdf_document = search->document;
- int n_pages;
- int pages_done;
- GArray *tmp_results;
- int i;
+ PdfDocumentSearch *search;
+ int n_pages, pages_done;
- n_pages = ev_document_get_n_pages (EV_DOCUMENT (search->document));
- if (search->search_page > search->start_page) {
- pages_done = search->search_page - search->start_page;
- } else if (search->search_page == search->start_page) {
- pages_done = n_pages;
- } else {
- pages_done = n_pages - search->start_page + search->search_page;
- }
+ search = PDF_DOCUMENT (document_find)->search;
- tmp_results = g_array_new (FALSE, FALSE, sizeof (EvFindResult));
- g_array_append_vals (tmp_results,
- search->current_page_results->data,
- search->current_page_results->len);
+ if (search == NULL) {
+ return 0;
+ }
- /* Now append a bogus element for each page that has a result in it,
- * that is not the current page
- */
- i = 1;
- while (i <= n_pages) {
- if (i != pdf_document->page &&
- search->other_page_flags[i]) {
- EvFindResult result;
-
- result.page_num = i;
-
- /* Use bogus coordinates, again we can't get coordinates
- * until this is the current page because TextOutputDev
- * isn't good enough
- */
- result.highlight_area.x = -1;
- result.highlight_area.y = -1;
- result.highlight_area.width = 1;
- result.highlight_area.height = 1;
-
- g_array_append_val (tmp_results, result);
- }
+ n_pages = ev_document_get_n_pages (EV_DOCUMENT (document_find));
+ if (search->search_page > search->start_page) {
+ pages_done = search->search_page - search->start_page + 1;
+ } else if (search->search_page == search->start_page) {
+ pages_done = n_pages;
+ } else {
+ pages_done = n_pages - search->start_page + search->search_page;
+ }
- ++i;
- }
+ return pages_done / (double) n_pages;
+}
- ev_document_find_found (EV_DOCUMENT_FIND (pdf_document),
- (EvFindResult*) tmp_results->data,
- tmp_results->len,
- pages_done / (double) n_pages);
+int
+pdf_document_find_page_has_results (EvDocumentFind *document_find,
+ int page)
+{
+ PdfDocumentSearch *search = PDF_DOCUMENT (document_find)->search;
+
+ g_return_val_if_fail (search != NULL, FALSE);
- g_array_free (tmp_results, TRUE);
+ return search->other_page_flags[page];
+}
+
+int
+pdf_document_find_get_n_results (EvDocumentFind *document_find)
+{
+ PdfDocumentSearch *search = PDF_DOCUMENT (document_find)->search;
+
+ if (search) {
+ return search->current_page_results->len;
+ } else {
+ return 0;
+ }
+}
+
+gboolean
+pdf_document_find_get_result (EvDocumentFind *document_find,
+ int n_result,
+ GdkRectangle *rectangle)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (document_find);
+ PdfDocumentSearch *search = pdf_document->search;
+ GdkRectangle r;
+
+ if (search != NULL &&
+ n_result < search->current_page_results->len) {
+ r = g_array_index (search->current_page_results,
+ GdkRectangle, n_result);
+
+ rectangle->x = r.x + pdf_document->page_x_offset;
+ rectangle->y = r.y + pdf_document->page_y_offset;
+ rectangle->width = r.width;
+ rectangle->height = r.height;
+
+ return TRUE;
+ } else {
+ return FALSE;
+ }
}
static void
{
PdfDocument *pdf_document = search->document;
int current_page;
- EvFindResult result;
+ GdkRectangle result;
int xMin, yMin, xMax, yMax;
current_page = pdf_document->page;
gTrue, gTrue, // startAtTop, stopAtBottom
gFalse, gFalse, // startAtLast, stopAtLast
&xMin, &yMin, &xMax, &yMax)) {
- result.page_num = pdf_document->page;
-
- result.highlight_area.x = xMin + pdf_document->page_x_offset;
- result.highlight_area.y = yMin + pdf_document->page_y_offset;
- result.highlight_area.width = xMax - xMin;
- result.highlight_area.height = yMax - yMin;
+ result.x = xMin;
+ result.y = yMin;
+ result.width = xMax - xMin;
+ result.height = yMax - yMin;
g_array_append_val (search->current_page_results, result);
/* Now find further results */
gFalse, gTrue,
gTrue, gFalse,
&xMin, &yMin, &xMax, &yMax)) {
-
- result.page_num = pdf_document->page;
-
- result.highlight_area.x = xMin + pdf_document->page_x_offset;
- result.highlight_area.y = yMin + pdf_document->page_y_offset;
- result.highlight_area.width = xMax - xMin;
- result.highlight_area.height = yMax - yMin;
+ result.x = xMin;
+ result.y = yMin;
+ result.width = xMax - xMin;
+ result.height = yMax - yMin;
g_array_append_val (search->current_page_results, result);
}
}
-
- /* needed for the initial current page since we don't search
- * it in the idle
- */
- search->other_page_flags[current_page] =
- search->current_page_results->len > 0;
-
- pdf_document_search_emit_found (search);
}
static gboolean
{
PdfDocumentSearch *search = (PdfDocumentSearch*) data;
PdfDocument *pdf_document = search->document;
- int n_pages;
+ int n_pages, changed_page;
double xMin, yMin, xMax, yMax;
/* Note that PDF page count is 1 through n_pages INCLUSIVE
*/
n_pages = ev_document_get_n_pages (EV_DOCUMENT (search->document));
- if (search->search_page == search->start_page) {
- goto end_search;
- }
-
if (search->output_dev == 0) {
/* First time through here... */
search->output_dev = new TextOutputDev (NULL, gTrue, gFalse, gFalse);
gFalse, gFalse, // startAtLast, stopAtLast
&xMin, &yMin, &xMax, &yMax)) {
/* This page has results */
- search->other_page_flags[search->search_page] = TRUE;
- }
+ search->other_page_flags[search->search_page] = 1;
+ } else {
+ search->other_page_flags[search->search_page] = 0;
+ }
+
+ changed_page = search->start_page;
search->search_page += 1;
if (search->search_page > n_pages) {
search->search_page = 1;
}
- /* We do this even if nothing was found, to update the percent complete */
- pdf_document_search_emit_found (search);
-
- return TRUE;
+ if (search->search_page != search->start_page) {
+ ev_document_find_changed (EV_DOCUMENT_FIND (pdf_document),
+ changed_page);
+ return TRUE;
+ }
- end_search:
+end_search:
/* We're done. */
search->idle = 0; /* will return FALSE to remove */
return FALSE;
{
PdfDocument *pdf_document = PDF_DOCUMENT (document);
PdfDocumentSearch *search;
- int n_pages;
+ int n_pages, i;
gunichar *ucs4;
glong ucs4_len;
search->current_page_results = g_array_new (FALSE,
FALSE,
- sizeof (EvFindResult));
+ sizeof (GdkRectangle));
n_pages = ev_document_get_n_pages (EV_DOCUMENT (document));
- /* This is an array of bool; with the first value ignored
- * so we can index by the based-at-1 page numbers
- */
- search->other_page_flags = g_new0 (guchar, n_pages + 1);
+ search->other_page_flags = g_new0 (int, n_pages + 1);
+ for (i = 0; i <= n_pages; i++) {
+ search->other_page_flags[i] = -1;
+ }
search->document = pdf_document;
search->output_dev = 0;
search->start_page = pdf_document->page;
- search->search_page = search->start_page + 1;
- if (search->search_page > n_pages)
- search->search_page = 1;
+ search->search_page = search->start_page;
search->current_page = -1;
}
static void
-pdf_document_find_cancel (EvDocumentFind *document)
+pdf_document_find_cancel (EvDocumentFind *document)
{
PdfDocument *pdf_document = PDF_DOCUMENT (document);
if (link_action == NULL) {
link = ev_link_new_title (title);
+ } else if (link_action->getKind () == actionGoToR) {
+ g_warning ("actionGoToR links not implemented");
+ } else if (link_action->getKind () == actionLaunch) {
+ g_warning ("actionLaunch links not implemented");
+ } else if (link_action->getKind () == actionNamed) {
+ g_warning ("actionNamed links not implemented");
+ } else if (link_action->getKind () == actionMovie) {
+ g_warning ("actionMovie links not implemented");
} else if (link_action->getKind () == actionGoTo) {
LinkDest *link_dest;
LinkGoTo *link_goto;
link_uri = dynamic_cast <LinkURI *> (link_action);
link = ev_link_new_external
(title, link_uri->getURI()->getCString());
- } else if (link_action->getKind () == actionNamed) {
- /*Skip, for now */
+ } else if (link_action->getKind () == actionUnknown) {
+ LinkUnknown *link_unknown;
+
+ link_unknown = dynamic_cast <LinkUnknown *> (link_action);
+
+ g_warning ("Unknown link type %s",
+ link_unknown->getAction()->getCString());
}
return link;
char *title = NULL;
Object info;
+ if (pdf_document->doc == NULL)
+ return NULL;
pdf_document->doc->getDocInfo (&info);
if (info.isDict ()) {
return NULL;
}
- /* Zoom */
- link_x = x / pdf_document->scale;
- link_y = y / pdf_document->scale;
-
/* Offset */
- link_x -= pdf_document->page_x_offset;
- link_y -= pdf_document->page_y_offset;
+ link_x = x - pdf_document->page_x_offset;
+ link_y = y - pdf_document->page_y_offset;
/* Inverse y */
link_y = pdf_document->out->getBitmapHeight() - link_y;
+ /* Zoom */
+ link_x = link_x / pdf_document->scale;
+ link_y = link_y / pdf_document->scale;
+
action = pdf_document->links->find (link_x, link_y);
if (action) {
pdf_document_find_iface_init (EvDocumentFindIface *iface)
{
iface->begin = pdf_document_find_begin;
+ iface->get_n_results = pdf_document_find_get_n_results;
+ iface->get_result = pdf_document_find_get_result;
+ iface->page_has_results = pdf_document_find_page_has_results;
+ iface->get_progress = pdf_document_find_get_progress;
iface->cancel = pdf_document_find_cancel;
}
Thumb *thumb = NULL;
gdouble page_ratio;
- /* getPage seems to want page + 1 for some reason; */
- the_page = pdf_document->doc->getCatalog ()->getPage (page + 1);
+ the_page = pdf_document->doc->getCatalog ()->getPage (page);
the_page->getThumb (&the_thumb);
if (!(the_thumb.isNull () || the_thumb.isNone())) {