From: Carlos Garcia Campos Date: Mon, 14 Apr 2008 17:07:39 +0000 (+0000) Subject: Add EvPage so that we can hold a reference to the backend page. Form X-Git-Tag: EVINCE_2_23_4~44 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=b8aebf2e1ba5b4f9ff1e1256b28acb3e23947c51;p=evince.git Add EvPage so that we can hold a reference to the backend page. Form 2008-04-14 Carlos Garcia Campos * libdocument/Makefile.am: * libdocument/ev-page.[ch]: * libdocument/ev-render-context.[ch]: (ev_render_context_dispose), (ev_render_context_new), (ev_render_context_set_page): * libdocument/ev-form-field.[ch]: (ev_form_field_init), (ev_form_field_finalize), (ev_form_field_class_init): * libdocument/ev-document-forms.[ch]: (ev_document_forms_get_form_fields): * libdocument/ev-document.[ch]: (ev_document_get_page), (ev_document_get_page_size), (ev_document_get_page_label): * shell/ev-jobs.[ch]: (ev_job_thumbnail_dispose), (ev_job_render_run), (ev_job_thumbnail_new), (ev_job_thumbnail_run), (ev_job_print_run): * shell/ev-page-cache.c: (ev_page_cache_new): * shell/ev-pixbuf-cache.c: (job_page_ready_cb), (job_finished_cb), (check_job_size_and_unref), (add_job): * shell/ev-sidebar-thumbnails.c: (add_range): * shell/ev-view.c: (ev_view_form_field_get_region), (ev_view_form_field_button_create_widget), (ev_view_form_field_text_save), (ev_view_form_field_choice_save), (ev_view_handle_form_field), (ev_view_size_allocate), (get_selected_text): * shell/ev-window.c: (ev_window_refresh_window_thumbnail): * backend/pdf/ev-poppler.cc: (pdf_document_get_page_size), (pdf_document_get_page), (pdf_document_get_page_label), (pdf_document_render), (pdf_document_get_info), (pdf_document_document_iface_init), (pdf_document_thumbnails_get_thumbnail), (pdf_document_thumbnails_get_dimensions), (pdf_document_file_exporter_do_page), (pdf_selection_render_selection), (pdf_selection_get_selected_text), (pdf_selection_get_selection_region), (pdf_selection_get_selection_map), (pdf_document_forms_get_form_fields), (pdf_document_forms_form_field_text_get_text), (pdf_document_forms_form_field_text_set_text), (pdf_document_forms_form_field_button_set_state), (pdf_document_forms_form_field_button_get_state), (pdf_document_forms_form_field_choice_get_item), (pdf_document_forms_form_field_choice_get_n_items), (pdf_document_forms_form_field_choice_is_item_selected), (pdf_document_forms_form_field_choice_select_item), (pdf_document_forms_form_field_choice_toggle_item), (pdf_document_forms_form_field_choice_unselect_all), (pdf_document_forms_form_field_choice_set_text), (pdf_document_forms_form_field_choice_get_text): * backend/ps/ev-spectre.c: (ps_document_get_page), (ps_document_get_page_size), (ps_document_get_page_label), (ps_document_render), (ps_document_document_iface_init), (ps_document_file_exporter_do_page): * backend/tiff/tiff-document.c: (tiff_document_get_page_size), (tiff_document_render), (tiff_document_render_pixbuf), (tiff_document_file_exporter_do_page): * backend/pixbuf/pixbuf-document.c: (pixbuf_document_get_page_size): * backend/comics/comics-document.c: (comics_document_get_page_size), (comics_document_render_pixbuf): * backend/djvu/djvu-document.c: (djvu_document_get_page_size), (djvu_document_render), (djvu_selection_get_selected_text), (djvu_document_thumbnails_get_thumbnail), (djvu_document_file_exporter_do_page), (djvu_document_find_get_result): * backend/dvi/dvi-document.c: (dvi_document_get_page_size), (dvi_document_render), (dvi_document_thumbnails_get_dimensions), (dvi_document_thumbnails_get_thumbnail), (dvi_document_file_exporter_do_page): * backend/impress/impress-document.c: (impress_document_get_page_size), (impress_document_render_pixbuf): * thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get): Add EvPage so that we can hold a reference to the backend page. Form fields keep now a reference to the poppler page improving performance since we don't have to create/destroy the poppler field for every form operation. This will be needed for annotations too. svn path=/trunk/; revision=3004 --- diff --git a/ChangeLog b/ChangeLog index 4345e53c..79c0003d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,83 @@ +2008-04-14 Carlos Garcia Campos + + * libdocument/Makefile.am: + * libdocument/ev-page.[ch]: + * libdocument/ev-render-context.[ch]: (ev_render_context_dispose), + (ev_render_context_new), (ev_render_context_set_page): + * libdocument/ev-form-field.[ch]: (ev_form_field_init), + (ev_form_field_finalize), (ev_form_field_class_init): + * libdocument/ev-document-forms.[ch]: + (ev_document_forms_get_form_fields): + * libdocument/ev-document.[ch]: (ev_document_get_page), + (ev_document_get_page_size), (ev_document_get_page_label): + * shell/ev-jobs.[ch]: (ev_job_thumbnail_dispose), + (ev_job_render_run), (ev_job_thumbnail_new), + (ev_job_thumbnail_run), (ev_job_print_run): + * shell/ev-page-cache.c: (ev_page_cache_new): + * shell/ev-pixbuf-cache.c: (job_page_ready_cb), (job_finished_cb), + (check_job_size_and_unref), (add_job): + * shell/ev-sidebar-thumbnails.c: (add_range): + * shell/ev-view.c: (ev_view_form_field_get_region), + (ev_view_form_field_button_create_widget), + (ev_view_form_field_text_save), (ev_view_form_field_choice_save), + (ev_view_handle_form_field), (ev_view_size_allocate), + (get_selected_text): + * shell/ev-window.c: (ev_window_refresh_window_thumbnail): + * backend/pdf/ev-poppler.cc: (pdf_document_get_page_size), + (pdf_document_get_page), (pdf_document_get_page_label), + (pdf_document_render), (pdf_document_get_info), + (pdf_document_document_iface_init), + (pdf_document_thumbnails_get_thumbnail), + (pdf_document_thumbnails_get_dimensions), + (pdf_document_file_exporter_do_page), + (pdf_selection_render_selection), + (pdf_selection_get_selected_text), + (pdf_selection_get_selection_region), + (pdf_selection_get_selection_map), + (pdf_document_forms_get_form_fields), + (pdf_document_forms_form_field_text_get_text), + (pdf_document_forms_form_field_text_set_text), + (pdf_document_forms_form_field_button_set_state), + (pdf_document_forms_form_field_button_get_state), + (pdf_document_forms_form_field_choice_get_item), + (pdf_document_forms_form_field_choice_get_n_items), + (pdf_document_forms_form_field_choice_is_item_selected), + (pdf_document_forms_form_field_choice_select_item), + (pdf_document_forms_form_field_choice_toggle_item), + (pdf_document_forms_form_field_choice_unselect_all), + (pdf_document_forms_form_field_choice_set_text), + (pdf_document_forms_form_field_choice_get_text): + * backend/ps/ev-spectre.c: (ps_document_get_page), + (ps_document_get_page_size), (ps_document_get_page_label), + (ps_document_render), (ps_document_document_iface_init), + (ps_document_file_exporter_do_page): + * backend/tiff/tiff-document.c: (tiff_document_get_page_size), + (tiff_document_render), (tiff_document_render_pixbuf), + (tiff_document_file_exporter_do_page): + * backend/pixbuf/pixbuf-document.c: + (pixbuf_document_get_page_size): + * backend/comics/comics-document.c: + (comics_document_get_page_size), (comics_document_render_pixbuf): + * backend/djvu/djvu-document.c: (djvu_document_get_page_size), + (djvu_document_render), (djvu_selection_get_selected_text), + (djvu_document_thumbnails_get_thumbnail), + (djvu_document_file_exporter_do_page), + (djvu_document_find_get_result): + * backend/dvi/dvi-document.c: (dvi_document_get_page_size), + (dvi_document_render), (dvi_document_thumbnails_get_dimensions), + (dvi_document_thumbnails_get_thumbnail), + (dvi_document_file_exporter_do_page): + * backend/impress/impress-document.c: + (impress_document_get_page_size), + (impress_document_render_pixbuf): + * thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get): + + Add EvPage so that we can hold a reference to the backend + page. Form fields keep now a reference to the poppler page + improving performance since we don't have to create/destroy the + poppler field for every form operation. This will be needed for + annotations too. + 2008-04-12 Carlos Garcia Campos * data/evince-ui.xml: diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c index 127943d1..2d8404e0 100644 --- a/backend/comics/comics-document.c +++ b/backend/comics/comics-document.c @@ -221,7 +221,7 @@ comics_document_get_n_pages (EvDocument *document) static void comics_document_get_page_size (EvDocument *document, - int page, + EvPage *page, double *width, double *height) { @@ -232,7 +232,7 @@ comics_document_get_page_size (EvDocument *document, gint outpipe = -1; GPid child_pid = -1; - argv = extract_argv (document, page); + argv = extract_argv (document, page->index); success = g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, @@ -290,7 +290,7 @@ comics_document_render_pixbuf (EvDocument *document, gint outpipe = -1; GPid child_pid = -1; - argv = extract_argv (document, rc->page); + argv = extract_argv (document, rc->page->index); success = g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, diff --git a/backend/djvu/djvu-document.c b/backend/djvu/djvu-document.c index f4caa7f0..392a7dc2 100644 --- a/backend/djvu/djvu-document.c +++ b/backend/djvu/djvu-document.c @@ -195,17 +195,14 @@ djvu_document_get_n_pages (EvDocument *document) } static void -djvu_document_get_page_size (EvDocument *document, - int page, - double *width, - double *height) +document_get_page_size (DjvuDocument *djvu_document, + gint page, + double *width, + double *height) { - DjvuDocument *djvu_document = DJVU_DOCUMENT (document); - ddjvu_pageinfo_t info; + ddjvu_pageinfo_t info; ddjvu_status_t r; - g_return_if_fail (djvu_document->d_document); - while ((r = ddjvu_document_get_pageinfo(djvu_document->d_document, page, &info)) < DDJVU_JOB_OK) djvu_handle_events(djvu_document, TRUE); @@ -216,6 +213,20 @@ djvu_document_get_page_size (EvDocument *document, *height = info.height * SCALE_FACTOR; } +static void +djvu_document_get_page_size (EvDocument *document, + EvPage *page, + double *width, + double *height) +{ + DjvuDocument *djvu_document = DJVU_DOCUMENT (document); + + g_return_if_fail (djvu_document->d_document); + + document_get_page_size (djvu_document, page->index, + width, height); +} + static cairo_surface_t * djvu_document_render (EvDocument *document, EvRenderContext *rc) @@ -231,7 +242,7 @@ djvu_document_render (EvDocument *document, double page_width, page_height, tmp; static const cairo_user_data_key_t key; - d_page = ddjvu_page_create_by_pageno (djvu_document->d_document, rc->page); + d_page = ddjvu_page_create_by_pageno (djvu_document->d_document, rc->page->index); while (!ddjvu_page_decoding_done (d_page)) djvu_handle_events(djvu_document, TRUE); @@ -364,7 +375,7 @@ djvu_selection_get_selected_text (EvSelection *selection, rectangle.x2 = points->x2 / SCALE_FACTOR; rectangle.y2 = (height - points->y1) / SCALE_FACTOR; - text = djvu_text_copy (djvu_document, rc->page, &rectangle); + text = djvu_text_copy (djvu_document, rc->page->index, &rectangle); if (text == NULL) text = g_strdup (""); @@ -423,10 +434,10 @@ djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, gdk_pixbuf_fill (pixbuf, 0xffffffff); pixels = gdk_pixbuf_get_pixels (pixbuf); - while (ddjvu_thumbnail_status (djvu_document->d_document, rc->page, 1) < DDJVU_JOB_OK) + while (ddjvu_thumbnail_status (djvu_document->d_document, rc->page->index, 1) < DDJVU_JOB_OK) djvu_handle_events(djvu_document, TRUE); - ddjvu_thumbnail_render (djvu_document->d_document, rc->page, + ddjvu_thumbnail_render (djvu_document->d_document, rc->page->index, &thumb_width, &thumb_height, djvu_document->thumbs_format, gdk_pixbuf_get_rowstride (pixbuf), @@ -472,7 +483,7 @@ djvu_document_file_exporter_do_page (EvFileExporter *exporter, { DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter); - g_string_append_printf (djvu_document->opts, "%d,", (rc->page) + 1); + g_string_append_printf (djvu_document->opts, "%d,", (rc->page->index) + 1); } static void @@ -587,8 +598,7 @@ djvu_document_find_get_result (EvDocumentFind *document_find, if (r == NULL) return FALSE; - djvu_document_get_page_size (EV_DOCUMENT (djvu_document), - page, &width, &height); + document_get_page_size (djvu_document, page, &width, &height); rectangle->x1 = r->x1 * SCALE_FACTOR; rectangle->y1 = height - r->y2 * SCALE_FACTOR; rectangle->x2 = r->x2 * SCALE_FACTOR; diff --git a/backend/dvi/dvi-document.c b/backend/dvi/dvi-document.c index c8295232..876d5770 100644 --- a/backend/dvi/dvi-document.c +++ b/backend/dvi/dvi-document.c @@ -67,10 +67,6 @@ typedef struct _DviDocumentClass DviDocumentClass; static void dvi_document_document_iface_init (EvDocumentIface *iface); static void dvi_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface); static void dvi_document_file_exporter_iface_init (EvFileExporterIface *iface); -static void dvi_document_get_page_size (EvDocument *document, - int page, - double *width, - double *height); static void dvi_document_do_color_special (DviContext *dvi, const char *prefix, const char *arg); @@ -150,7 +146,7 @@ dvi_document_get_n_pages (EvDocument *document) static void dvi_document_get_page_size (EvDocument *document, - int page, + EvPage *page, double *width, double *height) { @@ -177,7 +173,7 @@ dvi_document_render (EvDocument *document, */ g_mutex_lock (dvi_context_mutex); - mdvi_setpage (dvi_document->context, rc->page); + mdvi_setpage (dvi_document->context, rc->page->index); mdvi_set_shrink (dvi_document->context, (int)((dvi_document->params->hshrink - 1) / rc->scale) + 1, @@ -274,8 +270,8 @@ dvi_document_document_iface_init (EvDocumentIface *iface) static void dvi_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, EvRenderContext *rc, - gint *width, - gint *height) + gint *width, + gint *height) { DviDocument *dvi_document = DVI_DOCUMENT (document); gdouble page_width = dvi_document->base_width; @@ -307,7 +303,7 @@ dvi_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, g_mutex_lock (dvi_context_mutex); - mdvi_setpage (dvi_document->context, rc->page); + mdvi_setpage (dvi_document->context, rc->page->index); mdvi_set_shrink (dvi_document->context, (int)dvi_document->base_width * dvi_document->params->hshrink / thumb_width, @@ -377,7 +373,7 @@ dvi_document_file_exporter_do_page (EvFileExporter *exporter, { DviDocument *dvi_document = DVI_DOCUMENT(exporter); - g_string_append_printf (dvi_document->exporter_opts, "%d,", (rc->page) + 1); + g_string_append_printf (dvi_document->exporter_opts, "%d,", (rc->page->index) + 1); } static void diff --git a/backend/impress/impress-document.c b/backend/impress/impress-document.c index 8ceabd43..2e3c39be 100644 --- a/backend/impress/impress-document.c +++ b/backend/impress/impress-document.c @@ -334,9 +334,9 @@ impress_document_get_n_pages (EvDocument *document) static void impress_document_get_page_size (EvDocument *document, - int page, - double *width, - double *height) + EvPage *page, + double *width, + double *height) { ImpressDocument *impress_document = IMPRESS_DOCUMENT (document); @@ -383,7 +383,7 @@ impress_document_render_pixbuf (EvDocument *document, g_return_val_if_fail (IMPRESS_IS_DOCUMENT (document), NULL); g_return_val_if_fail (impress_document->imp != NULL, NULL); - impress_document->pagenum = rc->page; + impress_document->pagenum = rc->page->index; g_mutex_lock (impress_document->mutex); impress_document->cond = g_cond_new (); diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index 01c9a698..2b6d4159 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -148,19 +148,6 @@ EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document, pdf_document_page_transition_iface_init); }); -static void -set_rc_data (PdfDocument *pdf_document, - EvRenderContext *rc) -{ - if (rc->data == NULL) { - rc->data = poppler_document_get_page (pdf_document->document, - rc->page); - rc->destroy = g_object_unref; - } else { - g_assert (rc->page == poppler_page_get_index (POPPLER_PAGE (rc->data))); - } -} - static void pdf_document_search_free (PdfDocumentSearch *search) { @@ -296,35 +283,45 @@ pdf_document_get_n_pages (EvDocument *document) return poppler_document_get_n_pages (PDF_DOCUMENT (document)->document); } -static void -pdf_document_get_page_size (EvDocument *document, - int page, - double *width, - double *height) +static EvPage * +pdf_document_get_page (EvDocument *document, + gint index) { PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerPage *poppler_page; + EvPage *page; - poppler_page = poppler_document_get_page (pdf_document->document, page); - poppler_page_get_size (poppler_page, width, height); + poppler_page = poppler_document_get_page (pdf_document->document, index); + page = ev_page_new (index); + page->backend_page = (EvBackendPage)g_object_ref (poppler_page); + page->backend_destroy_func = (EvBackendPageDestroyFunc)g_object_unref; g_object_unref (poppler_page); + + return page; +} + +static void +pdf_document_get_page_size (EvDocument *document, + EvPage *page, + double *width, + double *height) +{ + g_return_if_fail (POPPLER_IS_PAGE (page->backend_page)); + + poppler_page_get_size (POPPLER_PAGE (page->backend_page), width, height); } static char * pdf_document_get_page_label (EvDocument *document, - int page) + EvPage *page) { - PopplerPage *poppler_page; char *label = NULL; - poppler_page = poppler_document_get_page (PDF_DOCUMENT (document)->document, - page); + g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL); - g_object_get (G_OBJECT (poppler_page), + g_object_get (G_OBJECT (page->backend_page), "label", &label, NULL); - g_object_unref (poppler_page); - return label; } @@ -504,14 +501,13 @@ pdf_document_render (EvDocument *document, EvRenderContext *rc) { PdfDocument *pdf_document; + PopplerPage *poppler_page; double width_points, height_points; gint width, height; - pdf_document = PDF_DOCUMENT (document); - - set_rc_data (pdf_document, rc); + poppler_page = POPPLER_PAGE (rc->page->backend_page); - poppler_page_get_size (POPPLER_PAGE (rc->data), + poppler_page_get_size (poppler_page, &width_points, &height_points); if (rc->rotation == 90 || rc->rotation == 270) { @@ -522,7 +518,7 @@ pdf_document_render (EvDocument *document, height = (int) ((height_points * rc->scale) + 0.5); } - return pdf_page_render (POPPLER_PAGE (rc->data), + return pdf_page_render (poppler_page, width, height, rc); } @@ -555,6 +551,7 @@ pdf_document_get_info (EvDocument *document) PopplerPageMode mode; PopplerViewerPreferences view_prefs; PopplerPermissions permissions; + EvPage *page; info = g_new0 (EvDocumentInfo, 1); @@ -593,9 +590,11 @@ pdf_document_get_info (EvDocument *document) "linearized", &(info->linearized), NULL); - pdf_document_get_page_size(document, 0, + page = ev_document_get_page (document, 0); + ev_document_get_page_size (document, page, &(info->paper_width), &(info->paper_height)); + g_object_unref (page); // Convert to mm. info->paper_width = info->paper_width / 72.0f * 25.4f; @@ -698,6 +697,7 @@ pdf_document_document_iface_init (EvDocumentIface *iface) iface->save = pdf_document_save; iface->load = pdf_document_load; iface->get_n_pages = pdf_document_get_n_pages; + iface->get_page = pdf_document_get_page; iface->get_page_size = pdf_document_get_page_size; iface->get_page_label = pdf_document_get_page_label; iface->has_attachments = pdf_document_has_attachments; @@ -1281,15 +1281,12 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails EvRenderContext *rc, gboolean border) { - PdfDocument *pdf_document; + PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails); PopplerPage *poppler_page; GdkPixbuf *pixbuf = NULL; GdkPixbuf *border_pixbuf; - pdf_document = PDF_DOCUMENT (document_thumbnails); - - poppler_page = poppler_document_get_page (pdf_document->document, rc->page); - g_return_val_if_fail (poppler_page != NULL, NULL); + poppler_page = POPPLER_PAGE (rc->page->backend_page); #ifdef POPPLER_WITH_GDK pixbuf = poppler_page_get_thumbnail_pixbuf (poppler_page); @@ -1303,7 +1300,6 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails } #endif /* POPPLER_WITH_GDK */ - if (pixbuf) { /* Rotate provided thumbnail if needed */ GdkPixbuf *rotated_pixbuf; @@ -1323,8 +1319,6 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails pixbuf = border_pixbuf; } - g_object_unref (poppler_page); - return pixbuf; } @@ -1334,14 +1328,10 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail gint *width, gint *height) { - PdfDocument *pdf_document; PopplerPage *poppler_page; gint has_thumb; - pdf_document = PDF_DOCUMENT (document_thumbnails); - poppler_page = poppler_document_get_page (pdf_document->document, rc->page); - - g_return_if_fail (poppler_page != NULL); + poppler_page = POPPLER_PAGE (rc->page->backend_page); has_thumb = poppler_page_get_thumbnail_size (poppler_page, width, height); @@ -1361,8 +1351,6 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail *width = *height; *height = temp; } - - g_object_unref (poppler_page); } static void @@ -1709,7 +1697,7 @@ pdf_document_file_exporter_do_page (EvFileExporter *exporter, g_return_if_fail (pdf_document->print_ctx != NULL); - poppler_page = poppler_document_get_page (pdf_document->document, rc->page); + poppler_page = POPPLER_PAGE (rc->page->backend_page); #ifdef HAVE_CAIRO_PRINT x = (ctx->pages_printed % ctx->pages_per_sheet) % ctx->pages_x; @@ -1795,8 +1783,6 @@ pdf_document_file_exporter_do_page (EvFileExporter *exporter, if (ctx->format == EV_FILE_FORMAT_PS) poppler_page_render_to_ps (poppler_page, ctx->ps_file); #endif /* HAVE_CAIRO_PRINT */ - - g_object_unref (poppler_page); } static void @@ -1867,14 +1853,13 @@ pdf_selection_render_selection (EvSelection *selection, GdkColor *text, GdkColor *base) { - PdfDocument *pdf_document; + PopplerPage *poppler_page; double width_points, height_points; gint width, height; - pdf_document = PDF_DOCUMENT (selection); - set_rc_data (pdf_document, rc); + poppler_page = POPPLER_PAGE (rc->page->backend_page); - poppler_page_get_size (POPPLER_PAGE (rc->data), + poppler_page_get_size (poppler_page, &width_points, &height_points); width = (int) ((width_points * rc->scale) + 0.5); height = (int) ((height_points * rc->scale) + 0.5); @@ -1903,7 +1888,7 @@ pdf_selection_render_selection (EvSelection *selection, memset (cairo_image_surface_get_data (*surface), 0x00, cairo_image_surface_get_height (*surface) * cairo_image_surface_get_stride (*surface)); - poppler_page_render_selection (POPPLER_PAGE (rc->data), + poppler_page_render_selection (poppler_page, cr, (PopplerRectangle *)points, (PopplerRectangle *)old_points, @@ -1918,7 +1903,7 @@ pdf_selection_render_selection (EvSelection *selection, TRUE, 8, width, height); - poppler_page_render_selection_to_pixbuf (POPPLER_PAGE (rc->data), + poppler_page_render_selection_to_pixbuf (poppler_page, rc->scale, rc->rotation, pixbuf, (PopplerRectangle *)points, (PopplerRectangle *)old_points, @@ -1938,14 +1923,12 @@ pdf_selection_get_selected_text (EvSelection *selection, EvSelectionStyle style, EvRectangle *points) { - PdfDocument *pdf_document = PDF_DOCUMENT (selection); PopplerPage *poppler_page; PopplerRectangle r; double height; char *retval; - poppler_page = poppler_document_get_page (pdf_document->document, rc->page); - g_return_val_if_fail (poppler_page != NULL, NULL); + poppler_page = POPPLER_PAGE (rc->page->backend_page); poppler_page_get_size (poppler_page, NULL, &height); r.x1 = points->x1; @@ -1957,8 +1940,6 @@ pdf_selection_get_selected_text (EvSelection *selection, (PopplerSelectionStyle)style, &r); - g_object_unref (poppler_page); - return retval; } @@ -1994,15 +1975,13 @@ pdf_selection_get_selection_region (EvSelection *selection, EvSelectionStyle style, EvRectangle *points) { - PdfDocument *pdf_document; + PopplerPage *poppler_page; GdkRegion *retval; - GList *region; + GList *region; - pdf_document = PDF_DOCUMENT (selection); - - set_rc_data (pdf_document, rc); + poppler_page = POPPLER_PAGE (rc->page->backend_page); - region = poppler_page_get_selection_region (POPPLER_PAGE (rc->data), + region = poppler_page_get_selection_region (poppler_page, rc->scale, (PopplerSelectionStyle)style, (PopplerRectangle *) points); @@ -2016,15 +1995,12 @@ static GdkRegion * pdf_selection_get_selection_map (EvSelection *selection, EvRenderContext *rc) { - PdfDocument *pdf_document; PopplerPage *poppler_page; PopplerRectangle points; GList *region; GdkRegion *retval; - pdf_document = PDF_DOCUMENT (selection); - poppler_page = poppler_document_get_page (pdf_document->document, - rc->page); + poppler_page = POPPLER_PAGE (rc->page->backend_page); points.x1 = 0.0; points.y1 = 0.0; @@ -2035,7 +2011,6 @@ pdf_selection_get_selection_map (EvSelection *selection, &points); retval = create_gdk_region_from_poppler_region (region); g_list_free (region); - g_object_unref (poppler_page); return retval; } @@ -2239,17 +2214,17 @@ ev_form_field_from_poppler_field (PopplerFormField *poppler_field) static GList * pdf_document_forms_get_form_fields (EvDocumentForms *document, - gint page) + EvPage *page) { - PdfDocument *pdf_document; PopplerPage *poppler_page; GList *retval = NULL; GList *fields; GList *list; double height; - pdf_document = PDF_DOCUMENT (document); - poppler_page = poppler_document_get_page (pdf_document->document, page); + g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL); + + poppler_page = POPPLER_PAGE (page->backend_page); fields = poppler_page_get_form_field_mapping (poppler_page); poppler_page_get_size (poppler_page, NULL, &height); @@ -2270,13 +2245,17 @@ pdf_document_forms_get_form_fields (EvDocumentForms *document, field_mapping->y1 = height - mapping->area.y2; field_mapping->y2 = height - mapping->area.y1; field_mapping->field = ev_field; - field_mapping->field->page = page; + field_mapping->field->page = EV_PAGE (g_object_ref (page)); + + g_object_set_data_full (G_OBJECT (ev_field), + "poppler-field", + g_object_ref (mapping->field), + (GDestroyNotify) g_object_unref); retval = g_list_prepend (retval, field_mapping); } poppler_page_free_form_field_mapping (fields); - g_object_unref (poppler_page); return g_list_reverse (retval); } @@ -2286,16 +2265,14 @@ pdf_document_forms_form_field_text_get_text (EvDocumentForms *document, EvFormField *field) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerFormField *poppler_field; gchar *text; - poppler_field = poppler_document_get_form_field (pdf_document->document, field->id); + poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field")); if (!poppler_field) return NULL; text = poppler_form_field_text_get_text (poppler_field); - g_object_unref (poppler_field); return text; } @@ -2305,14 +2282,12 @@ pdf_document_forms_form_field_text_set_text (EvDocumentForms *document, EvFormField *field, const gchar *text) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerFormField *poppler_field; - poppler_field = poppler_document_get_form_field (pdf_document->document, field->id); + 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); - g_object_unref (poppler_field); } static void @@ -2320,31 +2295,27 @@ pdf_document_forms_form_field_button_set_state (EvDocumentForms *document, EvFormField *field, gboolean state) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerFormField *poppler_field; - poppler_field = poppler_document_get_form_field (pdf_document->document, field->id); + poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field")); if (!poppler_field) return; poppler_form_field_button_set_state (poppler_field, state); - g_object_unref (poppler_field); } static gboolean pdf_document_forms_form_field_button_get_state (EvDocumentForms *document, EvFormField *field) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerFormField *poppler_field; gboolean state; - poppler_field = poppler_document_get_form_field (pdf_document->document, field->id); + poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field")); if (!poppler_field) return FALSE; state = poppler_form_field_button_get_state (poppler_field); - g_object_unref (poppler_field); return state; } @@ -2354,16 +2325,14 @@ pdf_document_forms_form_field_choice_get_item (EvDocumentForms *document, EvFormField *field, gint index) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerFormField *poppler_field; gchar *text; - poppler_field = poppler_document_get_form_field (pdf_document->document, field->id); + poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field")); if (!poppler_field) return NULL; text = poppler_form_field_choice_get_item (poppler_field, index); - g_object_unref (poppler_field); return text; } @@ -2372,16 +2341,14 @@ static int pdf_document_forms_form_field_choice_get_n_items (EvDocumentForms *document, EvFormField *field) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerFormField *poppler_field; gint n_items; - poppler_field = poppler_document_get_form_field (pdf_document->document, field->id); + poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field")); if (!poppler_field) return -1; n_items = poppler_form_field_choice_get_n_items (poppler_field); - g_object_unref (poppler_field); return n_items; } @@ -2391,16 +2358,14 @@ pdf_document_forms_form_field_choice_is_item_selected (EvDocumentForms *document EvFormField *field, gint index) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerFormField *poppler_field; gboolean selected; - poppler_field = poppler_document_get_form_field (pdf_document->document, field->id); + poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field")); if (!poppler_field) return FALSE; selected = poppler_form_field_choice_is_item_selected (poppler_field, index); - g_object_unref (poppler_field); return selected; } @@ -2410,15 +2375,13 @@ pdf_document_forms_form_field_choice_select_item (EvDocumentForms *document, EvFormField *field, gint index) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerFormField *poppler_field; - poppler_field = poppler_document_get_form_field (pdf_document->document, field->id); + poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field")); if (!poppler_field) return; poppler_form_field_choice_select_item (poppler_field, index); - g_object_unref (poppler_field); } static void @@ -2426,30 +2389,26 @@ pdf_document_forms_form_field_choice_toggle_item (EvDocumentForms *document, EvFormField *field, gint index) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerFormField *poppler_field; - poppler_field = poppler_document_get_form_field (pdf_document->document, field->id); + poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field")); if (!poppler_field) return; poppler_form_field_choice_toggle_item (poppler_field, index); - g_object_unref (poppler_field); } static void pdf_document_forms_form_field_choice_unselect_all (EvDocumentForms *document, EvFormField *field) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerFormField *poppler_field; - poppler_field = poppler_document_get_form_field (pdf_document->document, field->id); + poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field")); if (!poppler_field) return; poppler_form_field_choice_unselect_all (poppler_field); - g_object_unref (poppler_field); } static void @@ -2457,31 +2416,27 @@ pdf_document_forms_form_field_choice_set_text (EvDocumentForms *document, EvFormField *field, const gchar *text) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerFormField *poppler_field; - poppler_field = poppler_document_get_form_field (pdf_document->document, field->id); + poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field")); if (!poppler_field) return; poppler_form_field_choice_set_text (poppler_field, text); - g_object_unref (poppler_field); } static gchar * pdf_document_forms_form_field_choice_get_text (EvDocumentForms *document, EvFormField *field) { - PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerFormField *poppler_field; gchar *text; - poppler_field = poppler_document_get_form_field (pdf_document->document, field->id); + poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field")); if (!poppler_field) return NULL; text = poppler_form_field_choice_get_text (poppler_field); - g_object_unref (poppler_field); return text; } diff --git a/backend/pixbuf/pixbuf-document.c b/backend/pixbuf/pixbuf-document.c index ed7034be..bebc25b6 100644 --- a/backend/pixbuf/pixbuf-document.c +++ b/backend/pixbuf/pixbuf-document.c @@ -95,7 +95,7 @@ pixbuf_document_get_n_pages (EvDocument *document) static void pixbuf_document_get_page_size (EvDocument *document, - int page, + EvPage *page, double *width, double *height) { diff --git a/backend/ps/ev-spectre.c b/backend/ps/ev-spectre.c index 6fe58692..54b59570 100644 --- a/backend/ps/ev-spectre.c +++ b/backend/ps/ev-spectre.c @@ -164,6 +164,22 @@ ps_document_get_n_pages (EvDocument *document) return spectre_document_get_n_pages (ps->doc); } +static EvPage * +ps_document_get_page (EvDocument *document, + gint index) +{ + PSDocument *ps = PS_DOCUMENT (document); + SpectrePage *ps_page; + EvPage *page; + + ps_page = spectre_document_get_page (ps->doc, index); + page = ev_page_new (index); + page->backend_page = (EvBackendPage)ps_page; + page->backend_destroy_func = (EvBackendPageDestroyFunc)spectre_page_free; + + return page; +} + static gint get_page_rotation (SpectrePage *page) { @@ -184,17 +200,17 @@ get_page_rotation (SpectrePage *page) static void ps_document_get_page_size (EvDocument *document, - int page, + EvPage *page, double *width, double *height) { - PSDocument *ps = PS_DOCUMENT (document); SpectrePage *ps_page; gdouble page_width, page_height; gint pwidth, pheight; gint rotate; - ps_page = spectre_document_get_page (ps->doc, page); + ps_page = (SpectrePage *)page->backend_page; + spectre_page_get_size (ps_page, &pwidth, &pheight); rotate = get_page_rotation (ps_page); @@ -206,8 +222,6 @@ ps_document_get_page_size (EvDocument *document, page_height = pheight; } - spectre_page_free (ps_page); - if (width) { *width = page_width; } @@ -219,17 +233,9 @@ ps_document_get_page_size (EvDocument *document, static char * ps_document_get_page_label (EvDocument *document, - int page) + EvPage *page) { - PSDocument *ps = PS_DOCUMENT (document); - SpectrePage *ps_page; - gchar *label; - - ps_page = spectre_document_get_page (ps->doc, page); - label = g_strdup (spectre_page_get_label (ps_page)); - spectre_page_free (ps_page); - - return label; + return g_strdup (spectre_page_get_label ((SpectrePage *)page->backend_page)); } static EvDocumentInfo * @@ -268,7 +274,6 @@ static cairo_surface_t * ps_document_render (EvDocument *document, EvRenderContext *rc) { - PSDocument *ps = PS_DOCUMENT (document); SpectrePage *ps_page; SpectreRenderContext *src; gint width_points; @@ -281,7 +286,8 @@ ps_document_render (EvDocument *document, cairo_surface_t *surface; static const cairo_user_data_key_t key; - ps_page = spectre_document_get_page (ps->doc, rc->page); + ps_page = (SpectrePage *)rc->page->backend_page; + spectre_page_get_size (ps_page, &width_points, &height_points); width = (gint) ((width_points * rc->scale) + 0.5); @@ -297,20 +303,16 @@ ps_document_render (EvDocument *document, spectre_render_context_free (src); if (!data) { - spectre_page_free (ps_page); return NULL; } if (spectre_page_status (ps_page)) { g_warning (spectre_status_to_string (spectre_page_status (ps_page))); g_free (data); - spectre_page_free (ps_page); return NULL; } - spectre_page_free (ps_page); - if (rotation == 90 || rotation == 270) { swidth = height; sheight = width; @@ -334,6 +336,7 @@ ps_document_document_iface_init (EvDocumentIface *iface) iface->load = ps_document_load; iface->save = ps_document_save; iface->get_n_pages = ps_document_get_n_pages; + iface->get_page = ps_document_get_page; iface->get_page_size = ps_document_get_page_size; iface->get_page_label = ps_document_get_page_label; iface->get_info = ps_document_get_info; @@ -433,7 +436,7 @@ ps_document_file_exporter_do_page (EvFileExporter *exporter, { PSDocument *ps = PS_DOCUMENT (exporter); - spectre_exporter_do_page (ps->exporter, rc->page); + spectre_exporter_do_page (ps->exporter, rc->page->index); } static void diff --git a/backend/tiff/tiff-document.c b/backend/tiff/tiff-document.c index 146e4553..fc8f4aaa 100644 --- a/backend/tiff/tiff-document.c +++ b/backend/tiff/tiff-document.c @@ -176,10 +176,10 @@ tiff_document_get_resolution (TiffDocument *tiff_document, } static void -tiff_document_get_page_size (EvDocument *document, - int page, - double *width, - double *height) +tiff_document_get_page_size (EvDocument *document, + EvPage *page, + double *width, + double *height) { guint32 w, h; gfloat x_res, y_res; @@ -189,7 +189,7 @@ tiff_document_get_page_size (EvDocument *document, g_return_if_fail (tiff_document->tiff != NULL); push_handlers (); - if (TIFFSetDirectory (tiff_document->tiff, page) != 1) { + if (TIFFSetDirectory (tiff_document->tiff, page->index) != 1) { pop_handlers (); return; } @@ -223,7 +223,7 @@ tiff_document_render (EvDocument *document, g_return_val_if_fail (tiff_document->tiff != NULL, NULL); push_handlers (); - if (TIFFSetDirectory (tiff_document->tiff, rc->page) != 1) { + if (TIFFSetDirectory (tiff_document->tiff, rc->page->index) != 1) { pop_handlers (); return NULL; } @@ -317,7 +317,7 @@ tiff_document_render_pixbuf (EvDocument *document, GdkPixbuf *rotated_pixbuf; push_handlers (); - if (TIFFSetDirectory (tiff_document->tiff, rc->page) != 1) { + if (TIFFSetDirectory (tiff_document->tiff, rc->page->index) != 1) { pop_handlers (); return NULL; } @@ -482,7 +482,7 @@ tiff_document_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext * if (document->ps_export_ctx == NULL) return; - if (TIFFSetDirectory (document->tiff, rc->page) != 1) + if (TIFFSetDirectory (document->tiff, rc->page->index) != 1) return; tiff2ps_process_page (document->ps_export_ctx, document->tiff, 0, 0, 0, 0, 0); diff --git a/libdocument/Makefile.am b/libdocument/Makefile.am index a00eeaec..577c1c52 100644 --- a/libdocument/Makefile.am +++ b/libdocument/Makefile.am @@ -38,6 +38,7 @@ INST_H_FILES = \ ev-link-action.h \ ev-link-dest.h \ ev-link.h \ + ev-page.h \ ev-render-context.h \ ev-selection.h \ ev-transition-effect.h @@ -68,6 +69,7 @@ libevbackend_la_SOURCES= \ ev-file-exporter.c \ ev-file-helpers.c \ ev-module.c \ + ev-page.c \ ev-render-context.c \ ev-selection.c \ ev-transition-effect.c \ diff --git a/libdocument/ev-document-forms.c b/libdocument/ev-document-forms.c index db90bb88..d5d9c709 100644 --- a/libdocument/ev-document-forms.c +++ b/libdocument/ev-document-forms.c @@ -43,7 +43,7 @@ ev_document_forms_get_type (void) GList * ev_document_forms_get_form_fields (EvDocumentForms *document_forms, - gint page) + EvPage *page) { EvDocumentFormsIface *iface = EV_DOCUMENT_FORMS_GET_IFACE (document_forms); diff --git a/libdocument/ev-document-forms.h b/libdocument/ev-document-forms.h index a1b192da..1337a5ed 100644 --- a/libdocument/ev-document-forms.h +++ b/libdocument/ev-document-forms.h @@ -44,7 +44,7 @@ struct _EvDocumentFormsIface /* Methods */ GList *(* get_form_fields) (EvDocumentForms *document_forms, - gint page); + EvPage *page); gchar *(* form_field_text_get_text) (EvDocumentForms *document_forms, EvFormField *field); void (* form_field_text_set_text) (EvDocumentForms *document_forms, @@ -80,7 +80,7 @@ struct _EvDocumentFormsIface GType ev_document_forms_get_type (void) G_GNUC_CONST; GList *ev_document_forms_get_form_fields (EvDocumentForms *document_forms, - gint page); + EvPage *page); gchar *ev_document_forms_form_field_text_get_text (EvDocumentForms *document_forms, EvFormField *field); diff --git a/libdocument/ev-document.c b/libdocument/ev-document.c index 2c6db95a..5e582d0a 100644 --- a/libdocument/ev-document.c +++ b/libdocument/ev-document.c @@ -150,11 +150,26 @@ ev_document_get_n_pages (EvDocument *document) return retval; } +EvPage * +ev_document_get_page (EvDocument *document, + gint index) +{ + EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); + EvPage *retval; + + if (iface->get_page) + retval = iface->get_page (document, index); + else + retval = ev_page_new (index); + + return retval; +} + void -ev_document_get_page_size (EvDocument *document, - int page, - double *width, - double *height) +ev_document_get_page_size (EvDocument *document, + EvPage *page, + double *width, + double *height) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); @@ -163,8 +178,8 @@ ev_document_get_page_size (EvDocument *document, } char * -ev_document_get_page_label(EvDocument *document, - int page) +ev_document_get_page_label (EvDocument *document, + EvPage *page) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); @@ -239,7 +254,6 @@ ev_document_info_free (EvDocumentInfo *info) g_free (info->linearized); g_free (info->security); - g_free (info); } diff --git a/libdocument/ev-document.h b/libdocument/ev-document.h index bc040d14..cfcccdbe 100644 --- a/libdocument/ev-document.h +++ b/libdocument/ev-document.h @@ -28,6 +28,7 @@ #include #include "ev-document-info.h" +#include "ev-page.h" #include "ev-render-context.h" G_BEGIN_DECLS @@ -78,12 +79,14 @@ struct _EvDocumentIface const char *uri, GError **error); int (* get_n_pages) (EvDocument *document); + EvPage * (* get_page) (EvDocument *document, + gint index); void (* get_page_size) (EvDocument *document, - int page, + EvPage *page, double *width, double *height); char * (* get_page_label) (EvDocument *document, - int page); + EvPage *page); gboolean (* has_attachments) (EvDocument *document); GList * (* get_attachments) (EvDocument *document); cairo_surface_t * (* render) (EvDocument *document, @@ -112,12 +115,14 @@ gboolean ev_document_save (EvDocument *document, const char *uri, GError **error); int ev_document_get_n_pages (EvDocument *document); +EvPage *ev_document_get_page (EvDocument *document, + gint index); void ev_document_get_page_size (EvDocument *document, - int page, + EvPage *page, double *width, double *height); char *ev_document_get_page_label (EvDocument *document, - int page); + EvPage *page); gboolean ev_document_has_attachments (EvDocument *document); GList *ev_document_get_attachments (EvDocument *document); cairo_surface_t *ev_document_render (EvDocument *document, diff --git a/libdocument/ev-form-field.c b/libdocument/ev-form-field.c index cfa25f82..130b6c08 100644 --- a/libdocument/ev-form-field.c +++ b/libdocument/ev-form-field.c @@ -42,14 +42,28 @@ G_DEFINE_TYPE (EvFormFieldSignature, ev_form_field_signature, EV_TYPE_FORM_FIELD static void ev_form_field_init (EvFormField *field) { - field->page = -1; + field->page = NULL; field->changed = FALSE; field->is_read_only = FALSE; } +static void +ev_form_field_finalize (GObject *object) +{ + EvFormField *field = EV_FORM_FIELD (object); + + g_object_unref (field->page); + field->page = NULL; + + (* G_OBJECT_CLASS (ev_form_field_parent_class)->finalize) (object); +} + static void ev_form_field_class_init (EvFormFieldClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = ev_form_field_finalize; } static void diff --git a/libdocument/ev-form-field.h b/libdocument/ev-form-field.h index 0b09af94..027bee60 100644 --- a/libdocument/ev-form-field.h +++ b/libdocument/ev-form-field.h @@ -105,7 +105,7 @@ struct _EvFormField gboolean is_read_only; gdouble font_size; - gint page; + EvPage *page; gboolean changed; }; diff --git a/libdocument/ev-page.c b/libdocument/ev-page.c new file mode 100644 index 00000000..c37e38f3 --- /dev/null +++ b/libdocument/ev-page.c @@ -0,0 +1,62 @@ +/* this file is part of evince, a gnome document viewer + * + * Copyright (C) 2008 Carlos Garcia Campos + * + * Evince is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Evince is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +#include "ev-page.h" + +G_DEFINE_TYPE (EvPage, ev_page, G_TYPE_OBJECT) + +static void +ev_page_init (EvPage *page) +{ +} + +static void +ev_page_finalize (GObject *object) +{ + EvPage *page = EV_PAGE (object); + + if (page->backend_destroy_func) { + page->backend_destroy_func (page->backend_page); + page->backend_destroy_func = NULL; + } + page->backend_page = NULL; + + (* G_OBJECT_CLASS (ev_page_parent_class)->finalize) (object); +} + +static void +ev_page_class_init (EvPageClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = ev_page_finalize; +} + +EvPage * +ev_page_new (gint index) +{ + EvPage *page; + + page = EV_PAGE (g_object_new (EV_TYPE_PAGE, NULL)); + page->index = index; + + return page; +} diff --git a/libdocument/ev-page.h b/libdocument/ev-page.h new file mode 100644 index 00000000..801b3e19 --- /dev/null +++ b/libdocument/ev-page.h @@ -0,0 +1,59 @@ +/* this file is part of evince, a gnome document viewer + * + * Copyright (C) 2008 Carlos Garcia Campos + * + * Evince is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Evince is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef EV_PAGE_H +#define EV_PAGE_H + +#include + +G_BEGIN_DECLS + +#define EV_TYPE_PAGE (ev_page_get_type()) +#define EV_PAGE(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_PAGE, EvPage)) +#define EV_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_PAGE, EvPageClass)) +#define EV_IS_PAGE(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_PAGE)) +#define EV_IS_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_PAGE)) +#define EV_PAGE_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_PAGE, EvPageClass)) + +typedef struct _EvPage EvPage; +typedef struct _EvPageClass EvPageClass; + +typedef gpointer EvBackendPage; +typedef GDestroyNotify EvBackendPageDestroyFunc; + +struct _EvPage { + GObject base_instance; + + gint index; + + EvBackendPage backend_page; + EvBackendPageDestroyFunc backend_destroy_func; +}; + +struct _EvPageClass { + GObjectClass base_class; +}; + +GType ev_page_get_type (void) G_GNUC_CONST; + +EvPage *ev_page_new (gint index); + +G_END_DECLS + +#endif /* EV_PAGE_H */ diff --git a/libdocument/ev-render-context.c b/libdocument/ev-render-context.c index 55956510..45740661 100644 --- a/libdocument/ev-render-context.c +++ b/libdocument/ev-render-context.c @@ -35,9 +35,9 @@ ev_render_context_dispose (GObject *object) rc = (EvRenderContext *) object; - if (rc->destroy) { - (*rc->destroy) (rc->data); - rc->destroy = NULL; + if (rc->page) { + g_object_unref (rc->page); + rc->page = NULL; } (* G_OBJECT_CLASS (ev_render_context_parent_class)->dispose) (object); @@ -53,18 +53,17 @@ ev_render_context_class_init (EvRenderContextClass *class) oclass->dispose = ev_render_context_dispose; } - EvRenderContext * -ev_render_context_new (int rotation, - gint page, - gdouble scale) +ev_render_context_new (EvPage *page, + gint rotation, + gdouble scale) { EvRenderContext *rc; rc = (EvRenderContext *) g_object_new (EV_TYPE_RENDER_CONTEXT, NULL); + rc->page = page ? g_object_ref (page) : NULL; rc->rotation = rotation; - rc->page = page; rc->scale = scale; return rc; @@ -72,11 +71,14 @@ ev_render_context_new (int rotation, void ev_render_context_set_page (EvRenderContext *rc, - gint page) + EvPage *page) { g_return_if_fail (rc != NULL); + g_return_if_fail (EV_IS_PAGE (page)); - rc->page = page; + if (rc->page) + g_object_unref (rc->page); + rc->page = g_object_ref (page); } void diff --git a/libdocument/ev-render-context.h b/libdocument/ev-render-context.h index 636f02fd..eb324e88 100644 --- a/libdocument/ev-render-context.h +++ b/libdocument/ev-render-context.h @@ -22,14 +22,16 @@ #include +#include "ev-page.h" + G_BEGIN_DECLS typedef struct _EvRenderContext EvRenderContext; typedef struct _EvRenderContextClass EvRenderContextClass; #define EV_TYPE_RENDER_CONTEXT (ev_render_context_get_type()) -#define EV_RENDER_CONTEXT(context) ((EvRenderContext *) (context)) -#define EV_RENDER_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_RENDER_CONTEXT, EvRenderContext)) +#define EV_RENDER_CONTEXT(context) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_RENDER_CONTEXT, EvRenderContext) +#define EV_RENDER_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_RENDER_CONTEXT, EvRenderContextClass)) #define EV_IS_RENDER_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_RENDER_CONTEXT)) struct _EvRenderContextClass @@ -40,23 +42,21 @@ struct _EvRenderContextClass struct _EvRenderContext { GObject parent; - int rotation; - gint page; + + EvPage *page; + gint rotation; gdouble scale; - - gpointer data; - GDestroyNotify destroy; }; GType ev_render_context_get_type (void) G_GNUC_CONST; -EvRenderContext *ev_render_context_new (int rotation, - gint page, +EvRenderContext *ev_render_context_new (EvPage *page, + gint rotation, gdouble scale); void ev_render_context_set_page (EvRenderContext *rc, - gint page); + EvPage *page); void ev_render_context_set_rotation (EvRenderContext *rc, - int rotation); + gint rotation); void ev_render_context_set_scale (EvRenderContext *rc, gdouble scale); diff --git a/shell/ev-jobs.c b/shell/ev-jobs.c index f6328af6..7a642a2d 100644 --- a/shell/ev-jobs.c +++ b/shell/ev-jobs.c @@ -184,11 +184,6 @@ ev_job_thumbnail_dispose (GObject *object) job->thumbnail = NULL; } - if (job->rc) { - g_object_unref (job->rc); - job->rc = NULL; - } - (* G_OBJECT_CLASS (ev_job_thumbnail_parent_class)->dispose) (object); } @@ -362,7 +357,7 @@ ev_job_render_run (EvJobRender *job) if (EV_JOB (job)->async) { EvAsyncRenderer *renderer = EV_ASYNC_RENDERER (EV_JOB (job)->document); - ev_async_renderer_render_pixbuf (renderer, job->rc->page, job->rc->scale, + ev_async_renderer_render_pixbuf (renderer, job->rc->page->index, job->rc->scale, job->rc->rotation); g_signal_connect (EV_JOB (job)->document, "render_finished", G_CALLBACK (render_finished_cb), job); @@ -396,15 +391,15 @@ ev_job_render_run (EvJobRender *job) if (job->include_links && EV_IS_DOCUMENT_LINKS (EV_JOB (job)->document)) job->link_mapping = ev_document_links_get_links (EV_DOCUMENT_LINKS (EV_JOB (job)->document), - job->rc->page); + job->rc->page->index); if (job->include_forms && EV_IS_DOCUMENT_FORMS (EV_JOB (job)->document)) job->form_field_mapping = - ev_document_forms_get_form_fields (EV_DOCUMENT_FORMS (EV_JOB(job)->document), + ev_document_forms_get_form_fields (EV_DOCUMENT_FORMS (EV_JOB (job)->document), job->rc->page); if (job->include_images && EV_IS_DOCUMENT_IMAGES (EV_JOB (job)->document)) job->image_mapping = ev_document_images_get_image_mapping (EV_DOCUMENT_IMAGES (EV_JOB (job)->document), - job->rc->page); + job->rc->page->index); EV_JOB (job)->finished = TRUE; } @@ -412,15 +407,19 @@ ev_job_render_run (EvJobRender *job) } EvJob * -ev_job_thumbnail_new (EvDocument *document, - EvRenderContext *rc) +ev_job_thumbnail_new (EvDocument *document, + gint page, + gint rotation, + gdouble scale) { EvJobThumbnail *job; job = g_object_new (EV_TYPE_JOB_THUMBNAIL, NULL); EV_JOB (job)->document = g_object_ref (document); - job->rc = g_object_ref (rc); + job->page = page; + job->rotation = rotation; + job->scale = scale; return EV_JOB (job); } @@ -428,16 +427,24 @@ ev_job_thumbnail_new (EvDocument *document, void ev_job_thumbnail_run (EvJobThumbnail *job) { + EvRenderContext *rc; + EvPage *page; + g_return_if_fail (EV_IS_JOB_THUMBNAIL (job)); ev_document_doc_mutex_lock (); + page = ev_document_get_page (EV_JOB (job)->document, job->page); + rc = ev_render_context_new (page, job->rotation, job->scale); + g_object_unref (page); + job->thumbnail = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (EV_JOB (job)->document), - job->rc, TRUE); - EV_JOB (job)->finished = TRUE; - + rc, TRUE); + g_object_unref (rc); ev_document_doc_mutex_unlock (); + + EV_JOB (job)->finished = TRUE; } static void ev_job_fonts_init (EvJobFonts *job) { /* Do Nothing */ } @@ -917,7 +924,7 @@ ev_job_print_run (EvJobPrint *job) fc.duplex = FALSE; fc.pages_per_sheet = MAX (1, job->pages_per_sheet); - rc = ev_render_context_new (0, 0, 1.0); + rc = ev_render_context_new (NULL, 0, 1.0); ev_document_doc_mutex_lock (); ev_file_exporter_begin (EV_FILE_EXPORTER (document), &fc); @@ -937,12 +944,17 @@ ev_job_print_run (EvJobPrint *job) ev_file_exporter_begin_page (EV_FILE_EXPORTER (document)); for (j = 0; j < job->pages_per_sheet; j++) { + EvPage *ev_page; + gint p = page + j; if (p < 0 || p >= n_pages) break; + + ev_page = ev_document_get_page (document, page_list[p]); + ev_render_context_set_page (rc, ev_page); + g_object_unref (ev_page); - ev_render_context_set_page (rc, page_list[p]); ev_file_exporter_do_page (EV_FILE_EXPORTER (document), rc); } diff --git a/shell/ev-jobs.h b/shell/ev-jobs.h index c6d73a1a..16471544 100644 --- a/shell/ev-jobs.h +++ b/shell/ev-jobs.h @@ -163,7 +163,10 @@ struct _EvJobThumbnail { EvJob parent; - EvRenderContext *rc; + gint page; + gint rotation; + gdouble scale; + GdkPixbuf *thumbnail; }; @@ -265,7 +268,9 @@ void ev_job_render_run (EvJobRender *thumbnail); /* EvJobThumbnail */ GType ev_job_thumbnail_get_type (void) G_GNUC_CONST; EvJob *ev_job_thumbnail_new (EvDocument *document, - EvRenderContext *rc); + gint page, + gint rotation, + gdouble scale); void ev_job_thumbnail_run (EvJobThumbnail *thumbnail); /* EvJobFonts */ diff --git a/shell/ev-page-cache.c b/shell/ev-page-cache.c index a1b4d609..8b8bedc9 100644 --- a/shell/ev-page-cache.c +++ b/shell/ev-page-cache.c @@ -2,6 +2,7 @@ #include "ev-page-cache.h" #include "ev-job-queue.h" #include "ev-document-thumbnails.h" +#include "ev-page.h" #include #include @@ -289,19 +290,22 @@ ev_page_cache_new (EvDocument *document) has_thumbs = EV_IS_DOCUMENT_THUMBNAILS (document); for (i = 0; i < page_cache->n_pages; i++) { - double page_width = 0; - double page_height = 0; - gint thumb_width = 0; - gint thumb_height = 0; + EvPage *page; + double page_width = 0; + double page_height = 0; + gint thumb_width = 0; + gint thumb_height = 0; - ev_document_get_page_size (document, i, &page_width, &page_height); + page = ev_document_get_page (document, i); + + ev_document_get_page_size (document, page, &page_width, &page_height); - page_cache->page_labels[i] = ev_document_get_page_label (document, i); + page_cache->page_labels[i] = ev_document_get_page_label (document, page); if (page_cache->page_labels[i] != NULL) { - page_cache->max_label_chars = MAX(page_cache->max_label_chars, - g_utf8_strlen (page_cache->page_labels[i], 256)); + page_cache->max_label_chars = MAX (page_cache->max_label_chars, + g_utf8_strlen (page_cache->page_labels[i], 256)); if (!page_cache->has_labels) { gchar *expected_label; @@ -347,13 +351,15 @@ ev_page_cache_new (EvDocument *document) info->height = page_height; } - if (!has_thumbs) + if (!has_thumbs) { + g_object_unref (page); continue; + } if (!rc) { - rc = ev_render_context_new (0, i, (gdouble)THUMBNAIL_WIDTH / page_width); + rc = ev_render_context_new (page, 0, (gdouble)THUMBNAIL_WIDTH / page_width); } else { - ev_render_context_set_page (rc, i); + ev_render_context_set_page (rc, page); ev_render_context_set_scale (rc, (gdouble)THUMBNAIL_WIDTH / page_width); } @@ -393,6 +399,8 @@ ev_page_cache_new (EvDocument *document) thumb_info->width = thumb_width; thumb_info->height = thumb_height; } + + g_object_unref (page); } if (rc) { diff --git a/shell/ev-pixbuf-cache.c b/shell/ev-pixbuf-cache.c index 3403873c..4710dfee 100644 --- a/shell/ev-pixbuf-cache.c +++ b/shell/ev-pixbuf-cache.c @@ -250,13 +250,13 @@ job_page_ready_cb (EvJob *job, EvJobRender *job_render = EV_JOB_RENDER (job); /* If the job is outside of our interest, we silently discard it */ - if ((job_render->rc->page < (pixbuf_cache->start_page - pixbuf_cache->preload_cache_size)) || - (job_render->rc->page > (pixbuf_cache->end_page + pixbuf_cache->preload_cache_size))) { + if ((job_render->rc->page->index < (pixbuf_cache->start_page - pixbuf_cache->preload_cache_size)) || + (job_render->rc->page->index > (pixbuf_cache->end_page + pixbuf_cache->preload_cache_size))) { g_object_unref (job); return; } - job_info = find_job_cache (pixbuf_cache, job_render->rc->page); + job_info = find_job_cache (pixbuf_cache, job_render->rc->page->index); copy_job_page_and_selection_to_job_info (job_render, job_info, pixbuf_cache); g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region); @@ -270,13 +270,13 @@ job_finished_cb (EvJob *job, EvJobRender *job_render = EV_JOB_RENDER (job); /* If the job is outside of our interest, we silently discard it */ - if ((job_render->rc->page < (pixbuf_cache->start_page - pixbuf_cache->preload_cache_size)) || - (job_render->rc->page > (pixbuf_cache->end_page + pixbuf_cache->preload_cache_size))) { + if ((job_render->rc->page->index < (pixbuf_cache->start_page - pixbuf_cache->preload_cache_size)) || + (job_render->rc->page->index > (pixbuf_cache->end_page + pixbuf_cache->preload_cache_size))) { g_object_unref (job); return; } - job_info = find_job_cache (pixbuf_cache, job_render->rc->page); + job_info = find_job_cache (pixbuf_cache, job_render->rc->page->index); copy_job_to_job_info (job_render, job_info, pixbuf_cache); } @@ -298,7 +298,7 @@ check_job_size_and_unref (EvPixbufCache *pixbuf_cache, return; ev_page_cache_get_size (page_cache, - EV_JOB_RENDER (job_info->job)->rc->page, + EV_JOB_RENDER (job_info->job)->rc->page->index, EV_JOB_RENDER (job_info->job)->rc->rotation, scale, &width, &height); @@ -608,6 +608,7 @@ add_job (EvPixbufCache *pixbuf_cache, gfloat scale, EvJobPriority priority) { + EvPage *ev_page; gboolean include_links = FALSE; gboolean include_text = FALSE; gboolean include_selection = FALSE; @@ -617,14 +618,21 @@ add_job (EvPixbufCache *pixbuf_cache, job_info->page_ready = FALSE; + /* FIXME: we shouldn't lock here */ + ev_document_doc_mutex_lock (); + ev_page = ev_document_get_page (pixbuf_cache->document, page); + ev_document_doc_mutex_unlock (); + if (job_info->rc == NULL) { - job_info->rc = ev_render_context_new (rotation, page, scale); + job_info->rc = ev_render_context_new (ev_page, rotation, scale); } else { + ev_render_context_set_page (job_info->rc, ev_page); ev_render_context_set_rotation (job_info->rc, rotation); - ev_render_context_set_page (job_info->rc, page); ev_render_context_set_scale (job_info->rc, scale); } + g_object_unref (ev_page); + if (job_info->region) gdk_region_destroy (job_info->region); job_info->region = region ? gdk_region_copy (region) : NULL; diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c index 0d4ed311..25b1b838 100644 --- a/shell/ev-sidebar-thumbnails.c +++ b/shell/ev-sidebar-thumbnails.c @@ -260,13 +260,10 @@ add_range (EvSidebarThumbnails *sidebar_thumbnails, -1); if (job == NULL && !thumbnail_set) { - EvRenderContext *rc; - - rc = ev_render_context_new (priv->rotation, page, + job = ev_job_thumbnail_new (priv->document, + page, priv->rotation, get_scale_for_page (sidebar_thumbnails, page)); - job = ev_job_thumbnail_new (priv->document, rc); ev_job_queue_add_job (EV_JOB (job), EV_JOB_PRIORITY_HIGH); - g_object_unref (rc); g_object_set_data_full (G_OBJECT (job), "tree_iter", gtk_tree_iter_copy (&iter), diff --git a/shell/ev-view.c b/shell/ev-view.c index 1a76442a..f984396c 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -1658,9 +1658,9 @@ ev_view_form_field_get_region (EvView *view, GList *forms_mapping; forms_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache, - field->page); + field->page->index); ev_form_field_mapping_get_area (forms_mapping, field, &field_area); - doc_rect_to_view_rect (view, field->page, &field_area, &view_area); + doc_rect_to_view_rect (view, field->page->index, &field_area, &view_area); view_area.x -= view->scroll_x; view_area.y -= view->scroll_y; @@ -1711,7 +1711,7 @@ ev_view_form_field_button_create_widget (EvView *view, * we need to update also the region for the current selected item */ forms_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache, - field->page); + field->page->index); for (l = forms_mapping; l; l = g_list_next (l)) { EvFormField *button = ((EvFormFieldMapping *)(l->data))->field; GdkRegion *button_region; @@ -1739,7 +1739,7 @@ ev_view_form_field_button_create_widget (EvView *view, ev_pixbuf_cache_reload_page (view->pixbuf_cache, field_region, - field->page, + field->page->index, view->rotation, view->scale); gdk_region_destroy (field_region); @@ -1769,7 +1769,7 @@ ev_view_form_field_text_save (EvView *view, field->changed = FALSE; ev_pixbuf_cache_reload_page (view->pixbuf_cache, field_region, - field->page, + field->page->index, view->rotation, view->scale); gdk_region_destroy (field_region); @@ -1890,7 +1890,7 @@ ev_view_form_field_choice_save (EvView *view, field->changed = FALSE; ev_pixbuf_cache_reload_page (view->pixbuf_cache, field_region, - field->page, + field->page->index, view->rotation, view->scale); gdk_region_destroy (field_region); @@ -2107,10 +2107,10 @@ ev_view_handle_form_field (EvView *view, g_object_ref (field), (GDestroyNotify)g_object_unref); - form_field_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache, field->page); + form_field_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache, field->page->index); ev_form_field_mapping_get_area (form_field_mapping, field, &field_area); - doc_rect_to_view_rect (view, field->page, &field_area, &view_area); + doc_rect_to_view_rect (view, field->page->index, &field_area, &view_area); view_area.x -= view->scroll_x; view_area.y -= view->scroll_y; @@ -2310,10 +2310,10 @@ ev_view_size_allocate (GtkWidget *widget, continue; form_field_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache, - field->page); + field->page->index); ev_form_field_mapping_get_area (form_field_mapping, field, &field_area); - doc_rect_to_view_rect (view, field->page, &field_area, &view_area); + doc_rect_to_view_rect (view, field->page->index, &field_area, &view_area); view_area.x -= view->scroll_x; view_area.y -= view->scroll_y; @@ -5716,15 +5716,19 @@ get_selected_text (EvView *view) EvRenderContext *rc; text = g_string_new (NULL); - rc = ev_render_context_new (view->rotation, 1, view->scale); + rc = ev_render_context_new (NULL, view->rotation, view->scale); ev_document_doc_mutex_lock (); for (l = view->selection_info.selections; l != NULL; l = l->next) { EvViewSelection *selection = (EvViewSelection *)l->data; + EvPage *page; gchar *tmp; - ev_render_context_set_page (rc, selection->page); + page = ev_document_get_page (view->document, selection->page); + ev_render_context_set_page (rc, page); + g_object_unref (page); + tmp = ev_selection_get_selected_text (EV_SELECTION (view->document), rc, selection->style, &(selection->rect)); @@ -5733,10 +5737,10 @@ get_selected_text (EvView *view) g_free (tmp); } - ev_document_doc_mutex_unlock (); - g_object_unref (rc); + ev_document_doc_mutex_unlock (); + normalized_text = g_utf8_normalize (text->str, text->len, G_NORMALIZE_NFKC); g_string_free (text, TRUE); return normalized_text; diff --git a/shell/ev-window.c b/shell/ev-window.c index ffac5d73..81c5b9ee 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -1072,8 +1072,6 @@ ev_window_set_icon_from_thumbnail (EvJobThumbnail *job, static void ev_window_refresh_window_thumbnail (EvWindow *ev_window, int rotation) { - - EvRenderContext *rc; gint page_width, page_height; gdouble scale; EvDocument *document = ev_window->priv->document; @@ -1089,14 +1087,11 @@ ev_window_refresh_window_thumbnail (EvWindow *ev_window, int rotation) &page_width, &page_height); scale = (gdouble)128 / (gdouble)page_width; - rc = ev_render_context_new (rotation, 0, scale); - - ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, rc); + ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, 0, rotation, scale); g_signal_connect (ev_window->priv->thumbnail_job, "finished", G_CALLBACK (ev_window_set_icon_from_thumbnail), ev_window); ev_job_queue_add_job (EV_JOB (ev_window->priv->thumbnail_job), EV_JOB_PRIORITY_LOW); - g_object_unref (rc); } static gboolean diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c index 8960f180..b3c8285e 100644 --- a/thumbnailer/evince-thumbnailer.c +++ b/thumbnailer/evince-thumbnailer.c @@ -65,13 +65,17 @@ evince_thumbnail_pngenc_get (EvDocument *document, const char *thumbnail, int si EvRenderContext *rc; double width, height; GdkPixbuf *pixbuf; + EvPage *page; - ev_document_get_page_size (document, 0, &width, &height); + page = ev_document_get_page (document, 0); + + ev_document_get_page_size (document, page, &width, &height); - rc = ev_render_context_new (0, 0, size / width); + rc = ev_render_context_new (page, 0, size / width); pixbuf = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (document), rc, FALSE); g_object_unref (rc); + g_object_unref (page); if (pixbuf != NULL) { const char *overlaid_icon_name = NULL;