]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/pdf-document.cc
Add «nb» to ALL_LINGUAS too.
[evince.git] / pdf / xpdf / pdf-document.cc
index df380ad37e79b8d84c393026fe8c830529721c4f..1855222562df660d3f88a4fe77f4f9bdf4482865 100644 (file)
@@ -56,7 +56,7 @@ typedef struct
         /* 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;
@@ -350,21 +350,32 @@ pdf_document_set_page_offset (EvDocument  *document,
 
 static void
 pdf_document_get_page_size (EvDocument   *document,
+                           int           page,
                            int          *width,
                            int          *height)
 {
        PdfDocument *pdf_document = PDF_DOCUMENT (document);
+       Page *the_page;
+
+       /* set some default values */
+       if (width)
+               *width = 1;
+       if (height)
+               *height = 1;
 
-       if (document_validate_page (pdf_document)) {
+               
+       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 ();
        }
 }
 
@@ -399,6 +410,24 @@ pdf_document_render (EvDocument  *document,
                                           draw.width, draw.height);
 }
 
+double
+pdf_document_find_get_progress (EvDocumentFind *document_find)
+{
+       PdfDocumentSearch *search = PDF_DOCUMENT (document_find)->search;
+       int n_pages, pages_done;
+       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;
+       } else if (search->search_page == search->start_page) {
+               pages_done = n_pages;
+       } else {
+               pages_done = n_pages - search->start_page + search->search_page;
+       }
+
+       return pages_done / (double) n_pages;
+}
+
 int
 pdf_document_find_page_has_results (EvDocumentFind *document_find,
                                    int             page)
@@ -427,15 +456,16 @@ pdf_document_find_get_result (EvDocumentFind *document_find,
                              int             n_result,
                              GdkRectangle   *rectangle)
 {
-       PdfDocumentSearch *search = PDF_DOCUMENT (document_find)->search;
+       PdfDocument *pdf_document = PDF_DOCUMENT (document_find);
+       PdfDocumentSearch *search = pdf_document->search;
        GdkRectangle r;
 
        if (search != NULL) {
                r = g_array_index (search->current_page_results,
                                   GdkRectangle, n_result);
 
-               rectangle->x = r.x;
-               rectangle->y = r.y;
+               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;
 
@@ -498,7 +528,7 @@ pdf_document_search_idle_callback (void *data)
 {
         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
@@ -510,10 +540,6 @@ pdf_document_search_idle_callback (void *data)
          */
         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);
@@ -532,8 +558,12 @@ pdf_document_search_idle_callback (void *data)
                                           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) {
@@ -541,12 +571,13 @@ pdf_document_search_idle_callback (void *data)
                 search->search_page = 1;
         }
 
-        /* We do this even if nothing was found, to update the percent complete */
-        ev_document_find_changed (EV_DOCUMENT_FIND (pdf_document));
-
-        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;
@@ -559,7 +590,7 @@ pdf_document_find_begin (EvDocumentFind   *document,
 {
         PdfDocument *pdf_document = PDF_DOCUMENT (document);
         PdfDocumentSearch *search;
-        int n_pages;
+        int n_pages, i;
         gunichar *ucs4;
         glong ucs4_len;
 
@@ -597,10 +628,10 @@ pdf_document_find_begin (EvDocumentFind   *document,
                                                     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;
 
@@ -613,9 +644,7 @@ pdf_document_find_begin (EvDocumentFind   *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;
 
@@ -1226,8 +1255,7 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail
        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())) {