]> www.fi.muni.cz Git - evince.git/blobdiff - backend/pdf/ev-poppler.cc
Bump requirements to poppler 0.5.9 and drop all ifdefs used.
[evince.git] / backend / pdf / ev-poppler.cc
index 5c7f495d3301f17e8fcdeb9296d588e99562fb06..a3549b248b55d949ce44909763c049bda84c2cd6 100644 (file)
@@ -92,8 +92,7 @@ static void pdf_document_file_exporter_iface_init       (EvFileExporterIface
 static void pdf_selection_iface_init                    (EvSelectionIface          *iface);
 static void pdf_document_page_transition_iface_init     (EvDocumentTransitionIface *iface);
 static void pdf_document_thumbnails_get_dimensions      (EvDocumentThumbnails      *document_thumbnails,
 static void pdf_selection_iface_init                    (EvSelectionIface          *iface);
 static void pdf_document_page_transition_iface_init     (EvDocumentTransitionIface *iface);
 static void pdf_document_thumbnails_get_dimensions      (EvDocumentThumbnails      *document_thumbnails,
-                                                        gint                       page,
-                                                        gint                       size,
+                                                        EvRenderContext           *rc,
                                                         gint                      *width,
                                                         gint                      *height);
 static int  pdf_document_get_n_pages                   (EvDocument                *document);
                                                         gint                      *width,
                                                         gint                      *height);
 static int  pdf_document_get_n_pages                   (EvDocument                *document);
@@ -191,6 +190,8 @@ pdf_document_dispose (GObject *object)
        if (pdf_document->fonts_iter) {
                poppler_fonts_iter_free (pdf_document->fonts_iter);
        }
        if (pdf_document->fonts_iter) {
                poppler_fonts_iter_free (pdf_document->fonts_iter);
        }
+
+       G_OBJECT_CLASS (pdf_document_parent_class)->dispose (object);
 }
 
 static void
 }
 
 static void
@@ -1134,7 +1135,6 @@ pdf_document_images_get_images (EvDocumentImages *document_images,
                                gint              page)
 {
        GList *retval = NULL;
                                gint              page)
 {
        GList *retval = NULL;
-#ifdef HAVE_POPPLER_PAGE_GET_IMAGE_MAPPING
        PdfDocument *pdf_document;
        PopplerPage *poppler_page;
        GList *mapping_list;
        PdfDocument *pdf_document;
        PopplerPage *poppler_page;
        GList *mapping_list;
@@ -1163,7 +1163,7 @@ pdf_document_images_get_images (EvDocumentImages *document_images,
 
        poppler_page_free_image_mapping (mapping_list);
        g_object_unref (poppler_page);
 
        poppler_page_free_image_mapping (mapping_list);
        g_object_unref (poppler_page);
-#endif /* HAVE_POPPLER_PAGE_GET_IMAGE_MAPPING */
+
        return retval;
 }
 
        return retval;
 }
 
@@ -1174,32 +1174,15 @@ pdf_document_document_images_iface_init (EvDocumentImagesIface *iface)
 }
 
 static GdkPixbuf *
 }
 
 static GdkPixbuf *
-make_thumbnail_for_size (PdfDocument   *pdf_document,
-                        gint           page,
-                        int            rotation,
-                        gint           size)
+make_thumbnail_for_page (PdfDocument     *pdf_document,
+                        PopplerPage     *poppler_page, 
+                        EvRenderContext *rc)
 {
 {
-       PopplerPage *poppler_page;
        GdkPixbuf *pixbuf;
        int width, height;
        GdkPixbuf *pixbuf;
        int width, height;
-       double scale;
-       gdouble unscaled_width, unscaled_height;
 
 
-       poppler_page = poppler_document_get_page (pdf_document->document, page);
-       g_return_val_if_fail (poppler_page != NULL, NULL);
-
-       pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document), page,
-                                               size, &width, &height);
-       poppler_page_get_size (poppler_page, &unscaled_width, &unscaled_height);
-       scale = width / unscaled_width;
-
-       /* rotate */
-       if (rotation == 90 || rotation == 270) {
-               int temp;
-               temp = width;
-               width = height;
-               height = temp;
-       }
+       pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document),
+                                               rc, &width, &height);
 
        pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
                                 width, height);
 
        pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
                                 width, height);
@@ -1208,20 +1191,15 @@ make_thumbnail_for_size (PdfDocument   *pdf_document,
        ev_document_fc_mutex_lock ();
        poppler_page_render_to_pixbuf (poppler_page, 0, 0,
                                       width, height,
        ev_document_fc_mutex_lock ();
        poppler_page_render_to_pixbuf (poppler_page, 0, 0,
                                       width, height,
-                                      scale, rotation, pixbuf);
+                                      rc->scale, rc->rotation, pixbuf);
        ev_document_fc_mutex_unlock ();
        ev_document_fc_mutex_unlock ();
-       
-
-       g_object_unref (poppler_page);
 
        return pixbuf;
 }
 
 static GdkPixbuf *
 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
 
        return pixbuf;
 }
 
 static GdkPixbuf *
 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
-                                      gint                  page,
-                                      gint                  rotation,
-                                      gint                  size,
+                                      EvRenderContext      *rc, 
                                       gboolean              border)
 {
        PdfDocument *pdf_document;
                                       gboolean              border)
 {
        PdfDocument *pdf_document;
@@ -1231,18 +1209,17 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails
 
        pdf_document = PDF_DOCUMENT (document_thumbnails);
 
 
        pdf_document = PDF_DOCUMENT (document_thumbnails);
 
-       poppler_page = poppler_document_get_page (pdf_document->document, page);
+       poppler_page = poppler_document_get_page (pdf_document->document, rc->page);
        g_return_val_if_fail (poppler_page != NULL, NULL);
 
        pixbuf = poppler_page_get_thumbnail (poppler_page);
        g_return_val_if_fail (poppler_page != NULL, NULL);
 
        pixbuf = poppler_page_get_thumbnail (poppler_page);
-       
-       if (pixbuf == NULL) {
+       if (!pixbuf) {
                /* There is no provided thumbnail.  We need to make one. */
                /* There is no provided thumbnail.  We need to make one. */
-               pixbuf = make_thumbnail_for_size (pdf_document, page, rotation, size);
+               pixbuf = make_thumbnail_for_page (pdf_document, poppler_page, rc);
        }
 
         if (border) {          
        }
 
         if (border) {          
-               border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, rotation, pixbuf);
+               border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf);
                g_object_unref (pixbuf);
                pixbuf = border_pixbuf;
        }               
                g_object_unref (pixbuf);
                pixbuf = border_pixbuf;
        }               
@@ -1254,8 +1231,7 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails
 
 static void
 pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
 
 static void
 pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
-                                       gint                  page,
-                                       gint                  size,
+                                       EvRenderContext      *rc,
                                        gint                 *width,
                                        gint                 *height)
 {
                                        gint                 *width,
                                        gint                 *height)
 {
@@ -1264,10 +1240,8 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail
        gint has_thumb;
        
        pdf_document = PDF_DOCUMENT (document_thumbnails);
        gint has_thumb;
        
        pdf_document = PDF_DOCUMENT (document_thumbnails);
-       poppler_page = poppler_document_get_page (pdf_document->document, page);
+       poppler_page = poppler_document_get_page (pdf_document->document, rc->page);
 
 
-       g_return_if_fail (width != NULL);
-       g_return_if_fail (height != NULL);
        g_return_if_fail (poppler_page != NULL);
 
        has_thumb = poppler_page_get_thumbnail_size (poppler_page, width, height);
        g_return_if_fail (poppler_page != NULL);
 
        has_thumb = poppler_page_get_thumbnail_size (poppler_page, width, height);
@@ -1276,9 +1250,19 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail
                double page_width, page_height;
 
                poppler_page_get_size (poppler_page, &page_width, &page_height);
                double page_width, page_height;
 
                poppler_page_get_size (poppler_page, &page_width, &page_height);
-               *width = size;
-               *height = (int) (size * page_height / page_width);
+
+               *width = (gint) (page_width * rc->scale);
+               *height = (gint) (page_height * rc->scale);
+       }
+
+       if (rc->rotation == 90 || rc->rotation == 270) {
+               gint  temp;
+
+               temp = *width;
+               *width = *height;
+               *height = temp;
        }
        }
+       
        g_object_unref (poppler_page);
 }
 
        g_object_unref (poppler_page);
 }
 
@@ -1577,11 +1561,15 @@ pdf_document_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *r
                        poppler_page_render_to_ps (poppler_page, ctx->ps_file);
                        break;
                case EV_FILE_FORMAT_PDF:
                        poppler_page_render_to_ps (poppler_page, ctx->ps_file);
                        break;
                case EV_FILE_FORMAT_PDF:
+#ifdef HAVE_CAIRO_PDF
+                       cairo_save (ctx->pdf_cairo);
+#endif
 #ifdef HAVE_POPPLER_PAGE_RENDER
                        poppler_page_render (poppler_page, ctx->pdf_cairo);
 #endif
 #ifdef HAVE_CAIRO_PDF
                        cairo_show_page (ctx->pdf_cairo);
 #ifdef HAVE_POPPLER_PAGE_RENDER
                        poppler_page_render (poppler_page, ctx->pdf_cairo);
 #endif
 #ifdef HAVE_CAIRO_PDF
                        cairo_show_page (ctx->pdf_cairo);
+                       cairo_restore (ctx->pdf_cairo);
 #endif
                        break;
                default:
 #endif
                        break;
                default:
@@ -1634,13 +1622,14 @@ pdf_selection_render_selection (EvSelection      *selection,
                                           TRUE, 8,
                                           width, height);
        }
                                           TRUE, 8,
                                           width, height);
        }
-       
-       poppler_page_render_selection (POPPLER_PAGE (rc->data),
-                                      rc->scale, rc->rotation, *pixbuf,
-                                      (PopplerRectangle *)points,
-                                      (PopplerRectangle *)old_points,
-                                      text,
-                                      base);
+
+       poppler_page_render_selection_to_pixbuf (POPPLER_PAGE (rc->data),
+                                                rc->scale, rc->rotation, *pixbuf,
+                                                (PopplerRectangle *)points,
+                                                (PopplerRectangle *)old_points,
+                                                POPPLER_SELECTION_NORMAL, /* SelectionStyle */
+                                                text,
+                                                base);
 }
 
 
 }
 
 
@@ -1696,7 +1685,6 @@ static gdouble
 pdf_document_get_page_duration (EvDocumentTransition *trans,
                                gint                  page)
 {
 pdf_document_get_page_duration (EvDocumentTransition *trans,
                                gint                  page)
 {
-#ifdef HAVE_POPPLER_PAGE_GET_DURATION  
        PdfDocument *pdf_document;
        PopplerPage *poppler_page;
        gdouble      duration = -1;
        PdfDocument *pdf_document;
        PopplerPage *poppler_page;
        gdouble      duration = -1;
@@ -1710,9 +1698,6 @@ pdf_document_get_page_duration (EvDocumentTransition *trans,
        g_object_unref (poppler_page);
 
        return duration;
        g_object_unref (poppler_page);
 
        return duration;
-#else
-       return -1;
-#endif /* HAVE_POPPLER_PAGE_GET_DURATION */
 }
 
 static void
 }
 
 static void