From 6ac3eb8adb9f4bb8c59c832e7d83334243d90cd5 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Thu, 19 Aug 2010 15:41:25 +0200 Subject: [PATCH] Remove EvDocumentThumbnails interface The only method get_thumbnail() has been moved to EvDocument. Thumbnails are always implemented by backends since it's usually just rendering the page at a lower scale factor. EvDocument provides a default implementation so that most of the backends don't even need to implement it. --- backend/comics/comics-document.c | 34 +---- backend/djvu/djvu-document.c | 94 +++++------- backend/dvi/dvi-document.c | 74 +--------- backend/pdf/ev-poppler.cc | 211 ++++++++++++--------------- backend/pixbuf/pixbuf-document.c | 60 +++----- backend/ps/ev-spectre.c | 40 ----- backend/tiff/tiff-document.c | 32 +--- evince-document.h | 1 - libdocument/Makefile.am | 2 - libdocument/ev-document-thumbnails.c | 46 ------ libdocument/ev-document-thumbnails.h | 61 -------- libdocument/ev-document.c | 27 ++++ libdocument/ev-document.h | 4 + libview/ev-jobs.c | 8 +- shell/ev-sidebar-thumbnails.c | 6 +- shell/ev-window.c | 4 +- thumbnailer/evince-thumbnailer.c | 9 +- 17 files changed, 206 insertions(+), 507 deletions(-) delete mode 100644 libdocument/ev-document-thumbnails.c delete mode 100644 libdocument/ev-document-thumbnails.h diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c index 9205b974..0481de86 100644 --- a/backend/comics/comics-document.c +++ b/backend/comics/comics-document.c @@ -39,7 +39,6 @@ #include "comics-document.h" #include "ev-document-misc.h" -#include "ev-document-thumbnails.h" #include "ev-file-helpers.h" #ifdef G_OS_WIN32 @@ -123,8 +122,6 @@ static const ComicBookDecompressCommand command_usage_def[] = { {"%s -xOf" , "%s -tf %s" , NULL , FALSE, NO_OFFSET} }; -static void comics_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface); - static GSList* get_supported_image_extensions (void); static void get_page_size_area_prepared_cb (GdkPixbufLoader *loader, gpointer data); @@ -136,11 +133,7 @@ static char** extract_argv (EvDocument *document, gint page); -EV_BACKEND_REGISTER_WITH_CODE (ComicsDocument, comics_document, - { - EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, - comics_document_document_thumbnails_iface_init); - } ); +EV_BACKEND_REGISTER (ComicsDocument, comics_document) /** * comics_regex_quote: @@ -851,31 +844,6 @@ get_supported_image_extensions() return extensions; } -static GdkPixbuf * -comics_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - EvRenderContext *rc, - gboolean border) -{ - GdkPixbuf *thumbnail; - - thumbnail = comics_document_render_pixbuf (EV_DOCUMENT (document), rc); - - if (border) { - GdkPixbuf *tmp_pixbuf = thumbnail; - - thumbnail = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf); - g_object_unref (tmp_pixbuf); - } - - return thumbnail; -} - -static void -comics_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface) -{ - iface->get_thumbnail = comics_document_thumbnails_get_thumbnail; -} - static char** extract_argv (EvDocument *document, gint page) { diff --git a/backend/djvu/djvu-document.c b/backend/djvu/djvu-document.c index ae4fb01a..3349f403 100644 --- a/backend/djvu/djvu-document.c +++ b/backend/djvu/djvu-document.c @@ -24,7 +24,6 @@ #include "djvu-text-page.h" #include "djvu-links.h" #include "djvu-document-private.h" -#include "ev-document-thumbnails.h" #include "ev-file-exporter.h" #include "ev-document-misc.h" #include "ev-document-find.h" @@ -51,7 +50,6 @@ struct _DjvuDocumentClass typedef struct _DjvuDocumentClass DjvuDocumentClass; -static void djvu_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface); static void djvu_document_file_exporter_iface_init (EvFileExporterInterface *iface); static void djvu_document_find_iface_init (EvDocumentFindInterface *iface); static void djvu_document_document_links_iface_init (EvDocumentLinksInterface *iface); @@ -59,7 +57,6 @@ static void djvu_selection_iface_init (EvSelectionInterface *iface); EV_BACKEND_REGISTER_WITH_CODE (DjvuDocument, djvu_document, { - EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, djvu_document_document_thumbnails_iface_init); EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, djvu_document_file_exporter_iface_init); EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND, djvu_document_find_iface_init); EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS, djvu_document_document_links_iface_init); @@ -380,6 +377,44 @@ djvu_document_render (EvDocument *document, return surface; } +static GdkPixbuf * +djvu_document_get_thumbnail (EvDocument *document, + EvRenderContext *rc) +{ + DjvuDocument *djvu_document = DJVU_DOCUMENT (document); + GdkPixbuf *pixbuf, *rotated_pixbuf; + gdouble page_width, page_height; + gint thumb_width, thumb_height; + guchar *pixels; + + g_return_val_if_fail (djvu_document->d_document, NULL); + + djvu_document_get_page_size (EV_DOCUMENT(djvu_document), rc->page, + &page_width, &page_height); + + thumb_width = (gint) (page_width * rc->scale); + thumb_height = (gint) (page_height * rc->scale); + + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, + thumb_width, thumb_height); + gdk_pixbuf_fill (pixbuf, 0xffffffff); + pixels = gdk_pixbuf_get_pixels (pixbuf); + + while (ddjvu_thumbnail_status (djvu_document->d_document, rc->page->index, 1) < DDJVU_JOB_OK) + djvu_handle_events(djvu_document, TRUE, NULL); + + ddjvu_thumbnail_render (djvu_document->d_document, rc->page->index, + &thumb_width, &thumb_height, + djvu_document->thumbs_format, + gdk_pixbuf_get_rowstride (pixbuf), + (gchar *)pixels); + + rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation); + g_object_unref (pixbuf); + + return rotated_pixbuf; +} + static void djvu_document_finalize (GObject *object) { @@ -415,6 +450,7 @@ djvu_document_class_init (DjvuDocumentClass *klass) ev_document_class->get_n_pages = djvu_document_get_n_pages; ev_document_class->get_page_size = djvu_document_get_page_size; ev_document_class->render = djvu_document_render; + ev_document_class->get_thumbnail = djvu_document_get_thumbnail; } static gchar * @@ -473,58 +509,6 @@ djvu_selection_iface_init (EvSelectionInterface *iface) iface->get_selected_text = djvu_selection_get_selected_text; } -static GdkPixbuf * -djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - EvRenderContext *rc, - gboolean border) -{ - DjvuDocument *djvu_document = DJVU_DOCUMENT (document); - GdkPixbuf *pixbuf, *rotated_pixbuf; - gdouble page_width, page_height; - gint thumb_width, thumb_height; - guchar *pixels; - - g_return_val_if_fail (djvu_document->d_document, NULL); - - djvu_document_get_page_size (EV_DOCUMENT(djvu_document), rc->page, - &page_width, &page_height); - - thumb_width = (gint) (page_width * rc->scale); - thumb_height = (gint) (page_height * rc->scale); - - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, - thumb_width, thumb_height); - gdk_pixbuf_fill (pixbuf, 0xffffffff); - pixels = gdk_pixbuf_get_pixels (pixbuf); - - while (ddjvu_thumbnail_status (djvu_document->d_document, rc->page->index, 1) < DDJVU_JOB_OK) - djvu_handle_events(djvu_document, TRUE, NULL); - - ddjvu_thumbnail_render (djvu_document->d_document, rc->page->index, - &thumb_width, &thumb_height, - djvu_document->thumbs_format, - gdk_pixbuf_get_rowstride (pixbuf), - (gchar *)pixels); - - rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation); - g_object_unref (pixbuf); - - if (border) { - GdkPixbuf *tmp_pixbuf = rotated_pixbuf; - - rotated_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf); - g_object_unref (tmp_pixbuf); - } - - return rotated_pixbuf; -} - -static void -djvu_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface) -{ - iface->get_thumbnail = djvu_document_thumbnails_get_thumbnail; -} - /* EvFileExporterIface */ static void djvu_document_file_exporter_begin (EvFileExporter *exporter, diff --git a/backend/dvi/dvi-document.c b/backend/dvi/dvi-document.c index 84870365..89d3189d 100644 --- a/backend/dvi/dvi-document.c +++ b/backend/dvi/dvi-document.c @@ -21,7 +21,6 @@ #include "dvi-document.h" #include "texmfcnf.h" -#include "ev-document-thumbnails.h" #include "ev-document-misc.h" #include "ev-file-exporter.h" #include "ev-file-helpers.h" @@ -74,15 +73,13 @@ struct _DviDocument typedef struct _DviDocumentClass DviDocumentClass; -static void dvi_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface); -static void dvi_document_file_exporter_iface_init (EvFileExporterInterface *iface); -static void dvi_document_do_color_special (DviContext *dvi, - const char *prefix, - const char *arg); +static void dvi_document_file_exporter_iface_init (EvFileExporterInterface *iface); +static void dvi_document_do_color_special (DviContext *dvi, + const char *prefix, + const char *arg); EV_BACKEND_REGISTER_WITH_CODE (DviDocument, dvi_document, { - EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, dvi_document_document_thumbnails_iface_init); EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, dvi_document_file_exporter_iface_init); }); @@ -267,69 +264,6 @@ dvi_document_class_init (DviDocumentClass *klass) ev_document_class->support_synctex = dvi_document_support_synctex; } -static GdkPixbuf * -dvi_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - EvRenderContext *rc, - gboolean border) -{ - DviDocument *dvi_document = DVI_DOCUMENT (document); - GdkPixbuf *pixbuf; - GdkPixbuf *rotated_pixbuf; - cairo_surface_t *surface; - gint thumb_width, thumb_height; - gint proposed_width, proposed_height; - - thumb_width = (gint) (dvi_document->base_width * rc->scale); - thumb_height = (gint) (dvi_document->base_height * rc->scale); - - g_mutex_lock (dvi_context_mutex); - - 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, - (int)dvi_document->base_height * dvi_document->params->vshrink / thumb_height); - - proposed_width = dvi_document->context->dvi_page_w * dvi_document->context->params.conv; - proposed_height = dvi_document->context->dvi_page_h * dvi_document->context->params.vconv; - - if (border) { - mdvi_cairo_device_set_margins (&dvi_document->context->device, - MAX (thumb_width - proposed_width, 0) / 2, - MAX (thumb_height - proposed_height, 0) / 2); - } else { - mdvi_cairo_device_set_margins (&dvi_document->context->device, - MAX (thumb_width - proposed_width - 2, 0) / 2, - MAX (thumb_height - proposed_height - 2, 0) / 2); - } - - mdvi_cairo_device_set_scale (&dvi_document->context->device, rc->scale); - mdvi_cairo_device_render (dvi_document->context); - surface = mdvi_cairo_device_get_surface (&dvi_document->context->device); - g_mutex_unlock (dvi_context_mutex); - - pixbuf = ev_document_misc_pixbuf_from_surface (surface); - cairo_surface_destroy (surface); - - rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation); - g_object_unref (pixbuf); - - if (border) { - GdkPixbuf *tmp_pixbuf = rotated_pixbuf; - - rotated_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf); - g_object_unref (tmp_pixbuf); - } - - return rotated_pixbuf; -} - -static void -dvi_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface) -{ - iface->get_thumbnail = dvi_document_thumbnails_get_thumbnail; -} - /* EvFileExporterIface */ static void dvi_document_file_exporter_begin (EvFileExporter *exporter, diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index dc253c70..bf1fed5a 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -43,7 +43,6 @@ #include "ev-document-images.h" #include "ev-document-fonts.h" #include "ev-document-security.h" -#include "ev-document-thumbnails.h" #include "ev-document-transition.h" #include "ev-document-forms.h" #include "ev-document-layers.h" @@ -115,7 +114,6 @@ struct _PdfDocument }; static void pdf_document_security_iface_init (EvDocumentSecurityInterface *iface); -static void pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface); static void pdf_document_document_links_iface_init (EvDocumentLinksInterface *iface); static void pdf_document_document_images_iface_init (EvDocumentImagesInterface *iface); static void pdf_document_document_forms_iface_init (EvDocumentFormsInterface *iface); @@ -145,8 +143,6 @@ EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document, { EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_SECURITY, pdf_document_security_iface_init); - EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, - pdf_document_document_thumbnails_iface_init); EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS, pdf_document_document_links_iface_init); EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_IMAGES, @@ -403,6 +399,102 @@ pdf_document_render (EvDocument *document, width, height, rc); } +static GdkPixbuf * +make_thumbnail_for_page (PopplerPage *poppler_page, + EvRenderContext *rc, + gint width, + gint height) +{ + GdkPixbuf *pixbuf; + +#ifdef POPPLER_WITH_GDK + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, + width, height); + gdk_pixbuf_fill (pixbuf, 0xffffffff); + + ev_document_fc_mutex_lock (); + poppler_page_render_to_pixbuf (poppler_page, 0, 0, + width, height, + rc->scale, rc->rotation, pixbuf); + ev_document_fc_mutex_unlock (); +#else + cairo_surface_t *surface; + + ev_document_fc_mutex_lock (); + surface = pdf_page_render (poppler_page, width, height, rc); + ev_document_fc_mutex_unlock (); + + pixbuf = ev_document_misc_pixbuf_from_surface (surface); + cairo_surface_destroy (surface); +#endif /* POPPLER_WITH_GDK */ + + return pixbuf; +} + +static GdkPixbuf * +pdf_document_get_thumbnail (EvDocument *document, + EvRenderContext *rc) +{ + PdfDocument *pdf_document = PDF_DOCUMENT (document); + PopplerPage *poppler_page; + GdkPixbuf *pixbuf = NULL; + GdkPixbuf *border_pixbuf; + double page_width, page_height; + gint width, height; + + poppler_page = POPPLER_PAGE (rc->page->backend_page); + + poppler_page_get_size (poppler_page, + &page_width, &page_height); + + width = MAX ((gint)(page_width * rc->scale + 0.5), 1); + height = MAX ((gint)(page_height * rc->scale + 0.5), 1); + + if (rc->rotation == 90 || rc->rotation == 270) { + gint temp; + + temp = width; + width = height; + height = temp; + } + +#ifdef POPPLER_WITH_GDK + pixbuf = poppler_page_get_thumbnail_pixbuf (poppler_page); +#else + cairo_surface_t *surface; + + surface = poppler_page_get_thumbnail (poppler_page); + if (surface) { + pixbuf = ev_document_misc_pixbuf_from_surface (surface); + cairo_surface_destroy (surface); + } +#endif /* POPPLER_WITH_GDK */ + + if (pixbuf != NULL) { + int thumb_width = (rc->rotation == 90 || rc->rotation == 270) ? + gdk_pixbuf_get_height (pixbuf) : + gdk_pixbuf_get_width (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 (poppler_page, rc, width, height); + } + + return pixbuf; +} + /* reference: http://www.pdfa.org/lib/exe/fetch.php?id=pdfa%3Aen%3Atechdoc&cache=cache&media=pdfa:techdoc:tn0001_pdfa-1_and_namespaces_2008-03-18.pdf */ static char * @@ -825,6 +917,7 @@ pdf_document_class_init (PdfDocumentClass *klass) ev_document_class->get_page_size = pdf_document_get_page_size; ev_document_class->get_page_label = pdf_document_get_page_label; ev_document_class->render = pdf_document_render; + ev_document_class->get_thumbnail = pdf_document_get_thumbnail; ev_document_class->get_info = pdf_document_get_info; ev_document_class->get_backend_info = pdf_document_get_backend_info; ev_document_class->support_synctex = pdf_document_support_synctex; @@ -1381,116 +1474,6 @@ pdf_document_document_images_iface_init (EvDocumentImagesInterface *iface) iface->get_image = pdf_document_images_get_image; } -static GdkPixbuf * -make_thumbnail_for_page (PopplerPage *poppler_page, - EvRenderContext *rc, - gint width, - gint height) -{ - GdkPixbuf *pixbuf; - -#ifdef POPPLER_WITH_GDK - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, - width, height); - gdk_pixbuf_fill (pixbuf, 0xffffffff); - - ev_document_fc_mutex_lock (); - poppler_page_render_to_pixbuf (poppler_page, 0, 0, - width, height, - rc->scale, rc->rotation, pixbuf); - ev_document_fc_mutex_unlock (); -#else - cairo_surface_t *surface; - - ev_document_fc_mutex_lock (); - surface = pdf_page_render (poppler_page, width, height, rc); - ev_document_fc_mutex_unlock (); - - pixbuf = ev_document_misc_pixbuf_from_surface (surface); - cairo_surface_destroy (surface); -#endif /* POPPLER_WITH_GDK */ - - return pixbuf; -} - -static GdkPixbuf * -pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails, - EvRenderContext *rc, - gboolean border) -{ - PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails); - PopplerPage *poppler_page; - GdkPixbuf *pixbuf = NULL; - GdkPixbuf *border_pixbuf; - double page_width, page_height; - gint width, height; - - poppler_page = POPPLER_PAGE (rc->page->backend_page); - - poppler_page_get_size (poppler_page, - &page_width, &page_height); - - width = MAX ((gint)(page_width * rc->scale + 0.5), 1); - height = MAX ((gint)(page_height * rc->scale + 0.5), 1); - - if (rc->rotation == 90 || rc->rotation == 270) { - gint temp; - - temp = width; - width = height; - height = temp; - } - -#ifdef POPPLER_WITH_GDK - pixbuf = poppler_page_get_thumbnail_pixbuf (poppler_page); -#else - cairo_surface_t *surface; - - surface = poppler_page_get_thumbnail (poppler_page); - if (surface) { - pixbuf = ev_document_misc_pixbuf_from_surface (surface); - cairo_surface_destroy (surface); - } -#endif /* POPPLER_WITH_GDK */ - - if (pixbuf != NULL) { - int thumb_width = (rc->rotation == 90 || rc->rotation == 270) ? - gdk_pixbuf_get_height (pixbuf) : - gdk_pixbuf_get_width (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 (poppler_page, rc, width, height); - } - - if (border && pixbuf) { - border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf); - g_object_unref (pixbuf); - pixbuf = border_pixbuf; - } - - return pixbuf; -} - -static void -pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface) -{ - iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail; -} - - static GList * pdf_document_find_find_text (EvDocumentFind *document_find, EvPage *page, diff --git a/backend/pixbuf/pixbuf-document.c b/backend/pixbuf/pixbuf-document.c index 978970dd..ae7b4376 100644 --- a/backend/pixbuf/pixbuf-document.c +++ b/backend/pixbuf/pixbuf-document.c @@ -21,7 +21,6 @@ #include #include "pixbuf-document.h" -#include "ev-document-thumbnails.h" #include "ev-document-misc.h" #include "ev-file-helpers.h" @@ -41,13 +40,7 @@ struct _PixbufDocument typedef struct _PixbufDocumentClass PixbufDocumentClass; -static void pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface); - -EV_BACKEND_REGISTER_WITH_CODE (PixbufDocument, pixbuf_document, - { - EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, - pixbuf_document_document_thumbnails_iface_init) - }); +EV_BACKEND_REGISTER (PixbufDocument, pixbuf_document) static gboolean pixbuf_document_load (EvDocument *document, @@ -127,6 +120,27 @@ pixbuf_document_render (EvDocument *document, return surface; } +static GdkPixbuf * +pixbuf_document_get_thumbnail (EvDocument *document, + EvRenderContext *rc) +{ + PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document); + GdkPixbuf *pixbuf, *rotated_pixbuf; + gint width, height; + + width = (gint) (gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale); + height = (gint) (gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale); + + pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, + width, height, + GDK_INTERP_BILINEAR); + + rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation); + g_object_unref (pixbuf); + + return rotated_pixbuf; +} + static void pixbuf_document_finalize (GObject *object) { @@ -151,37 +165,9 @@ pixbuf_document_class_init (PixbufDocumentClass *klass) ev_document_class->get_n_pages = pixbuf_document_get_n_pages; ev_document_class->get_page_size = pixbuf_document_get_page_size; ev_document_class->render = pixbuf_document_render; + ev_document_class->get_thumbnail = pixbuf_document_get_thumbnail; } -static GdkPixbuf * -pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - EvRenderContext *rc, - gboolean border) -{ - PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document); - GdkPixbuf *pixbuf, *rotated_pixbuf; - gint width, height; - - width = (gint) (gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale); - height = (gint) (gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale); - - pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, - width, height, - GDK_INTERP_BILINEAR); - - rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation); - g_object_unref (pixbuf); - - return rotated_pixbuf; -} - -static void -pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface) -{ - iface->get_thumbnail = pixbuf_document_thumbnails_get_thumbnail; -} - - static void pixbuf_document_init (PixbufDocument *pixbuf_document) { diff --git a/backend/ps/ev-spectre.c b/backend/ps/ev-spectre.c index 256d9bef..23957cd6 100644 --- a/backend/ps/ev-spectre.c +++ b/backend/ps/ev-spectre.c @@ -27,7 +27,6 @@ #include "ev-spectre.h" #include "ev-file-exporter.h" -#include "ev-document-thumbnails.h" #include "ev-document-misc.h" struct _PSDocument { @@ -42,12 +41,9 @@ struct _PSDocumentClass { }; static void ps_document_file_exporter_iface_init (EvFileExporterInterface *iface); -static void ps_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface); EV_BACKEND_REGISTER_WITH_CODE (PSDocument, ps_document, { - EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, - ps_document_document_thumbnails_iface_init); EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, ps_document_file_exporter_iface_init); }); @@ -348,42 +344,6 @@ ps_document_class_init (PSDocumentClass *klass) ev_document_class->render = ps_document_render; } -/* EvDocumentThumbnailsIface */ -static GdkPixbuf * -ps_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails, - EvRenderContext *rc, - gboolean border) -{ - PSDocument *ps = PS_DOCUMENT (document_thumbnails); - cairo_surface_t *surface; - GdkPixbuf *pixbuf = NULL; - - surface = ps_document_render (EV_DOCUMENT (ps), rc); - if (!surface) { - g_warning ("Error rendering thumbnail"); - return NULL; - } - - pixbuf = ev_document_misc_pixbuf_from_surface (surface); - cairo_surface_destroy (surface); - - if (border) { - GdkPixbuf *border_pixbuf; - - border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf); - g_object_unref (pixbuf); - pixbuf = border_pixbuf; - } - - return pixbuf; -} - -static void -ps_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface) -{ - iface->get_thumbnail = ps_document_thumbnails_get_thumbnail; -} - /* EvFileExporterIface */ static void ps_document_file_exporter_begin (EvFileExporter *exporter, diff --git a/backend/tiff/tiff-document.c b/backend/tiff/tiff-document.c index 80aec9b2..1be2aece 100644 --- a/backend/tiff/tiff-document.c +++ b/backend/tiff/tiff-document.c @@ -31,7 +31,6 @@ #include "tiff2ps.h" #include "tiff-document.h" #include "ev-document-misc.h" -#include "ev-document-thumbnails.h" #include "ev-file-exporter.h" #include "ev-file-helpers.h" @@ -53,13 +52,10 @@ struct _TiffDocument typedef struct _TiffDocumentClass TiffDocumentClass; -static void tiff_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface); static void tiff_document_document_file_exporter_iface_init (EvFileExporterInterface *iface); EV_BACKEND_REGISTER_WITH_CODE (TiffDocument, tiff_document, { - EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, - tiff_document_document_thumbnails_iface_init); EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, tiff_document_document_file_exporter_iface_init); }); @@ -312,7 +308,7 @@ tiff_document_render (EvDocument *document, } static GdkPixbuf * -tiff_document_render_pixbuf (EvDocument *document, +tiff_document_get_thumbnail (EvDocument *document, EvRenderContext *rc) { TiffDocument *tiff_document = TIFF_DOCUMENT (document); @@ -424,34 +420,10 @@ tiff_document_class_init (TiffDocumentClass *klass) ev_document_class->get_n_pages = tiff_document_get_n_pages; ev_document_class->get_page_size = tiff_document_get_page_size; ev_document_class->render = tiff_document_render; + ev_document_class->get_thumbnail = tiff_document_get_thumbnail; ev_document_class->get_page_label = tiff_document_get_page_label; } -static GdkPixbuf * -tiff_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - EvRenderContext *rc, - gboolean border) -{ - GdkPixbuf *pixbuf; - - pixbuf = tiff_document_render_pixbuf (EV_DOCUMENT (document), rc); - - if (border) { - GdkPixbuf *tmp_pixbuf = pixbuf; - - pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf); - g_object_unref (tmp_pixbuf); - } - - return pixbuf; -} - -static void -tiff_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface) -{ - iface->get_thumbnail = tiff_document_thumbnails_get_thumbnail; -} - /* postscript exporter implementation */ static void tiff_document_file_exporter_begin (EvFileExporter *exporter, diff --git a/evince-document.h b/evince-document.h index 3e38c25b..1db675b9 100644 --- a/evince-document.h +++ b/evince-document.h @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include diff --git a/libdocument/Makefile.am b/libdocument/Makefile.am index e8bad83b..7ca7fc8c 100644 --- a/libdocument/Makefile.am +++ b/libdocument/Makefile.am @@ -23,7 +23,6 @@ INST_H_SRC_FILES = \ ev-document-misc.h \ ev-document-print.h \ ev-document-security.h \ - ev-document-thumbnails.h \ ev-document-transition.h \ ev-document-text.h \ ev-file-exporter.h \ @@ -64,7 +63,6 @@ libevdocument3_la_SOURCES= \ ev-document-annotations.c \ ev-document-attachments.c \ ev-document-factory.c \ - ev-document-thumbnails.c \ ev-document-fonts.c \ ev-document-layers.c \ ev-document-links.c \ diff --git a/libdocument/ev-document-thumbnails.c b/libdocument/ev-document-thumbnails.c deleted file mode 100644 index 9ff10f8f..00000000 --- a/libdocument/ev-document-thumbnails.c +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */ -/* - * Copyright (C) 2004 Anders Carlsson - * - * This program 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, or (at your option) - * any later version. - * - * This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include -#include "ev-document-thumbnails.h" -#include "ev-document.h" - -G_DEFINE_INTERFACE (EvDocumentThumbnails, ev_document_thumbnails, 0) - -static void -ev_document_thumbnails_default_init (EvDocumentThumbnailsInterface *klass) -{ -} - -GdkPixbuf * -ev_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - EvRenderContext *rc, - gboolean border) -{ - EvDocumentThumbnailsInterface *iface; - - g_return_val_if_fail (EV_IS_DOCUMENT_THUMBNAILS (document), NULL); - g_return_val_if_fail (EV_IS_RENDER_CONTEXT (rc), NULL); - - iface = EV_DOCUMENT_THUMBNAILS_GET_IFACE (document); - - return iface->get_thumbnail (document, rc, border); -} - diff --git a/libdocument/ev-document-thumbnails.h b/libdocument/ev-document-thumbnails.h deleted file mode 100644 index b2779fc3..00000000 --- a/libdocument/ev-document-thumbnails.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */ -/* - * Copyright (C) 2004 Anders Carlsson - * - * This program 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, or (at your option) - * any later version. - * - * This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#if !defined (__EV_EVINCE_DOCUMENT_H_INSIDE__) && !defined (EVINCE_COMPILATION) -#error "Only can be included directly." -#endif - -#ifndef EV_DOCUMENT_THUMBNAILS_H -#define EV_DOCUMENT_THUMBNAILS_H - -#include - -#include "ev-render-context.h" - -G_BEGIN_DECLS - -#define EV_TYPE_DOCUMENT_THUMBNAILS (ev_document_thumbnails_get_type ()) -#define EV_DOCUMENT_THUMBNAILS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnails)) -#define EV_DOCUMENT_THUMBNAILS_IFACE(k) (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnailsInterface)) -#define EV_IS_DOCUMENT_THUMBNAILS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_DOCUMENT_THUMBNAILS)) -#define EV_IS_DOCUMENT_THUMBNAILS_IFACE(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_DOCUMENT_THUMBNAILS)) -#define EV_DOCUMENT_THUMBNAILS_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnailsInterface)) - -typedef struct _EvDocumentThumbnails EvDocumentThumbnails; -typedef struct _EvDocumentThumbnailsInterface EvDocumentThumbnailsInterface; - -struct _EvDocumentThumbnailsInterface { - GTypeInterface base_iface; - - /* Methods */ - GdkPixbuf * (* get_thumbnail) (EvDocumentThumbnails *document, - EvRenderContext *rc, - gboolean border); -}; - -GType ev_document_thumbnails_get_type (void) G_GNUC_CONST; - -GdkPixbuf *ev_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - EvRenderContext *rc, - gboolean border); - -G_END_DECLS - -#endif /* EV_DOCUMENT_THUMBNAILS_H */ diff --git a/libdocument/ev-document.c b/libdocument/ev-document.c index 70349dcb..d7ee2c1d 100644 --- a/libdocument/ev-document.c +++ b/libdocument/ev-document.c @@ -25,6 +25,7 @@ #include #include "ev-document.h" +#include "ev-document-misc.h" #include "synctex_parser.h" #define EV_DOCUMENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EV_TYPE_DOCUMENT, EvDocumentPrivate)) @@ -581,6 +582,32 @@ ev_document_render (EvDocument *document, return klass->render (document, rc); } +static GdkPixbuf * +_ev_document_get_thumbnail (EvDocument *document, + EvRenderContext *rc) +{ + cairo_surface_t *surface; + GdkPixbuf *pixbuf; + + surface = ev_document_render (document, rc); + pixbuf = ev_document_misc_pixbuf_from_surface (surface); + cairo_surface_destroy (surface); + + return pixbuf; +} + +GdkPixbuf * +ev_document_get_thumbnail (EvDocument *document, + EvRenderContext *rc) +{ + EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document); + + if (klass->get_thumbnail) + return klass->get_thumbnail (document, rc); + + return _ev_document_get_thumbnail (document, rc); +} + const gchar * ev_document_get_uri (EvDocument *document) { diff --git a/libdocument/ev-document.h b/libdocument/ev-document.h index 63d2a8ec..d2828925 100644 --- a/libdocument/ev-document.h +++ b/libdocument/ev-document.h @@ -109,6 +109,8 @@ struct _EvDocumentClass EvPage *page); cairo_surface_t * (* render) (EvDocument *document, EvRenderContext *rc); + GdkPixbuf * (* get_thumbnail) (EvDocument *document, + EvRenderContext *rc); EvDocumentInfo * (* get_info) (EvDocument *document); gboolean (* get_backend_info)(EvDocument *document, EvDocumentBackendInfo *info); @@ -150,6 +152,8 @@ gchar *ev_document_get_page_label (EvDocument *document, gint page_index); cairo_surface_t *ev_document_render (EvDocument *document, EvRenderContext *rc); +GdkPixbuf *ev_document_get_thumbnail (EvDocument *document, + EvRenderContext *rc); const gchar *ev_document_get_uri (EvDocument *document); const gchar *ev_document_get_title (EvDocument *document); gboolean ev_document_is_page_size_uniform (EvDocument *document); diff --git a/libview/ev-jobs.c b/libview/ev-jobs.c index e1522757..3e33886f 100644 --- a/libview/ev-jobs.c +++ b/libview/ev-jobs.c @@ -21,7 +21,6 @@ #include #include "ev-jobs.h" -#include "ev-document-thumbnails.h" #include "ev-document-links.h" #include "ev-document-images.h" #include "ev-document-forms.h" @@ -765,6 +764,7 @@ ev_job_thumbnail_run (EvJob *job) { EvJobThumbnail *job_thumb = EV_JOB_THUMBNAIL (job); EvRenderContext *rc; + GdkPixbuf *pixbuf; EvPage *page; ev_debug_message (DEBUG_JOBS, "%d (%p)", job_thumb->page, job); @@ -776,11 +776,13 @@ ev_job_thumbnail_run (EvJob *job) rc = ev_render_context_new (page, job_thumb->rotation, job_thumb->scale); g_object_unref (page); - job_thumb->thumbnail = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (job->document), - rc, TRUE); + pixbuf = ev_document_get_thumbnail (job->document, rc); g_object_unref (rc); ev_document_doc_mutex_unlock (); + job_thumb->thumbnail = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf); + g_object_unref (pixbuf); + ev_job_succeeded (job); return FALSE; diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c index ef0e3a91..4854e930 100644 --- a/shell/ev-sidebar-thumbnails.c +++ b/shell/ev-sidebar-thumbnails.c @@ -32,7 +32,6 @@ #include #include "ev-document-misc.h" -#include "ev-document-thumbnails.h" #include "ev-job-scheduler.h" #include "ev-sidebar-page.h" #include "ev-sidebar-thumbnails.h" @@ -822,8 +821,7 @@ ev_sidebar_thumbnails_document_changed_cb (EvDocumentModel *model, EvDocument *document = ev_document_model_get_document (model); EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv; - if (!EV_IS_DOCUMENT_THUMBNAILS (document) || - ev_document_get_n_pages (document) <= 0 || + if (ev_document_get_n_pages (document) <= 0 || !ev_document_check_dimensions (document)) { return; } @@ -931,7 +929,7 @@ static gboolean ev_sidebar_thumbnails_support_document (EvSidebarPage *sidebar_page, EvDocument *document) { - return (EV_IS_DOCUMENT_THUMBNAILS (document)); + return TRUE; } static const gchar* diff --git a/shell/ev-window.c b/shell/ev-window.c index f1d3bd90..89d18d99 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -56,7 +56,6 @@ #include "ev-document-fonts.h" #include "ev-document-images.h" #include "ev-document-links.h" -#include "ev-document-thumbnails.h" #include "ev-document-annotations.h" #include "ev-document-type-builtins.h" #include "ev-document-misc.h" @@ -1310,8 +1309,7 @@ ev_window_refresh_window_thumbnail (EvWindow *ev_window) gint rotation; EvDocument *document = ev_window->priv->document; - if (!EV_IS_DOCUMENT_THUMBNAILS (document) || - ev_document_get_n_pages (document) <= 0 || + if (ev_document_get_n_pages (document) <= 0 || !ev_document_check_dimensions (document)) { return; } diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c index 31da3d3c..94d6b77e 100644 --- a/thumbnailer/evince-thumbnailer.c +++ b/thumbnailer/evince-thumbnailer.c @@ -137,8 +137,7 @@ evince_thumbnail_pngenc_get (EvDocument *document, const char *thumbnail, int si ev_document_get_page_size (document, 0, &width, &height); rc = ev_render_context_new (page, 0, size / width); - pixbuf = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (document), - rc, FALSE); + pixbuf = ev_document_get_thumbnail (document, rc); g_object_unref (rc); g_object_unref (page); @@ -270,12 +269,6 @@ main (int argc, char *argv[]) return -2; } - if (!EV_IS_DOCUMENT_THUMBNAILS (document)) { - g_object_unref (document); - ev_shutdown (); - return -2; - } - if (EV_IS_ASYNC_RENDERER (document)) { struct AsyncData data; -- 2.43.0