X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=backend%2Fpdf%2Fev-poppler.cc;h=3c39e5960b866b2050eb5bc5f40c596bc38d971d;hb=dec10c13ca0e95a58e9d6eb537320505ca64d1f8;hp=746b945a888c4410b0c24f67ec5ad7df20c221ab;hpb=ef262303183a13c3d166dd4873e74a78b38cee28;p=evince.git diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index 746b945a..3c39e596 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -92,6 +92,7 @@ struct _PdfDocument PopplerDocument *document; gchar *password; + gboolean modified; PopplerFontInfo *font_info; PopplerFontsIter *fonts_iter; @@ -243,6 +244,8 @@ convert_error (GError *poppler_error, EV_DOCUMENT_ERROR, code, poppler_error->message); + + g_error_free (poppler_error); } else { g_propagate_error (error, poppler_error); } @@ -255,12 +258,18 @@ pdf_document_save (EvDocument *document, const char *uri, GError **error) { + PdfDocument *pdf_document = PDF_DOCUMENT (document); gboolean retval; GError *poppler_error = NULL; - retval = poppler_document_save (PDF_DOCUMENT (document)->document, - uri, - &poppler_error); + if (pdf_document->modified) { + retval = poppler_document_save (pdf_document->document, + uri, &poppler_error); + } else { + retval = poppler_document_save_a_copy (pdf_document->document, + uri, &poppler_error); + } + if (! retval) convert_error (poppler_error, error); @@ -1251,15 +1260,13 @@ pdf_document_document_images_iface_init (EvDocumentImagesIface *iface) } static GdkPixbuf * -make_thumbnail_for_page (PdfDocument *pdf_document, - PopplerPage *poppler_page, - EvRenderContext *rc) +make_thumbnail_for_page (PopplerPage *poppler_page, + EvRenderContext *rc, + gint width, + gint height) { GdkPixbuf *pixbuf; - int width, height; - pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document), - rc, &width, &height); #ifdef POPPLER_WITH_GDK pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); @@ -1293,9 +1300,13 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails PopplerPage *poppler_page; GdkPixbuf *pixbuf = NULL; GdkPixbuf *border_pixbuf; + gint width, height; poppler_page = POPPLER_PAGE (rc->page->backend_page); + pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document), + rc, &width, &height); + #ifdef POPPLER_WITH_GDK pixbuf = poppler_page_get_thumbnail_pixbuf (poppler_page); #else @@ -1308,17 +1319,26 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails } #endif /* POPPLER_WITH_GDK */ - if (pixbuf) { - /* Rotate provided thumbnail if needed */ - GdkPixbuf *rotated_pixbuf; + if (pixbuf != NULL) { + int thumb_width = (rc->rotation == 90 || rc->rotation == 270) ? + gdk_pixbuf_get_height (pixbuf) : + gdk_pixbuf_get_width (pixbuf); - rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, - (GdkPixbufRotation) (360 - rc->rotation)); - g_object_unref (pixbuf); - pixbuf = rotated_pixbuf; + if (thumb_width == width) { + GdkPixbuf *rotated_pixbuf; + + rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, + (GdkPixbufRotation) (360 - rc->rotation)); + g_object_unref (pixbuf); + pixbuf = rotated_pixbuf; + } else { + /* The provided thumbnail has a different size */ + g_object_unref (pixbuf); + pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height); + } } else { - /* There is no provided thumbnail. We need to make one. */ - pixbuf = make_thumbnail_for_page (pdf_document, poppler_page, rc); + /* There is no provided thumbnail. We need to make one. */ + pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height); } if (border) { @@ -1336,21 +1356,13 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail gint *width, gint *height) { - PopplerPage *poppler_page; - gint has_thumb; + double page_width, page_height; - poppler_page = POPPLER_PAGE (rc->page->backend_page); - - has_thumb = poppler_page_get_thumbnail_size (poppler_page, width, height); - - if (!has_thumb || *width <= 0 || *height <= 0) { - double page_width, page_height; - - poppler_page_get_size (poppler_page, &page_width, &page_height); - - *width = (gint) MAX (page_width * rc->scale, 1); - *height = (gint) MAX (page_height * rc->scale, 1); - } + poppler_page_get_size (POPPLER_PAGE (rc->page->backend_page), + &page_width, &page_height); + + *width = (gint) MAX (page_width * rc->scale, 1); + *height = (gint) MAX (page_height * rc->scale, 1); if (rc->rotation == 90 || rc->rotation == 270) { gint temp; @@ -2140,7 +2152,9 @@ pdf_document_forms_form_field_text_set_text (EvDocumentForms *document, poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field")); if (!poppler_field) return; + poppler_form_field_text_set_text (poppler_field, text); + PDF_DOCUMENT (document)->modified = TRUE; } static void @@ -2155,6 +2169,7 @@ pdf_document_forms_form_field_button_set_state (EvDocumentForms *document, return; poppler_form_field_button_set_state (poppler_field, state); + PDF_DOCUMENT (document)->modified = TRUE; } static gboolean @@ -2235,6 +2250,7 @@ pdf_document_forms_form_field_choice_select_item (EvDocumentForms *document, return; poppler_form_field_choice_select_item (poppler_field, index); + PDF_DOCUMENT (document)->modified = TRUE; } static void @@ -2249,6 +2265,7 @@ pdf_document_forms_form_field_choice_toggle_item (EvDocumentForms *document, return; poppler_form_field_choice_toggle_item (poppler_field, index); + PDF_DOCUMENT (document)->modified = TRUE; } static void @@ -2262,6 +2279,7 @@ pdf_document_forms_form_field_choice_unselect_all (EvDocumentForms *document, return; poppler_form_field_choice_unselect_all (poppler_field); + PDF_DOCUMENT (document)->modified = TRUE; } static void @@ -2276,6 +2294,7 @@ pdf_document_forms_form_field_choice_set_text (EvDocumentForms *document, return; poppler_form_field_choice_set_text (poppler_field, text); + PDF_DOCUMENT (document)->modified = TRUE; } static gchar *