From: Marco Pesenti Gritti Date: Mon, 7 Mar 2005 13:51:12 +0000 (+0000) Subject: Rework API a bit. Add a border flag and change sizing logic (now the size X-Git-Tag: EVINCE_0_1_7~4 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=b006971d2c876b5ae62e2ed917496d370e90333c;p=evince.git Rework API a bit. Add a border flag and change sizing logic (now the size 2005-03-07 Marco Pesenti Gritti * backend/ev-document-thumbnails.c: (ev_document_thumbnails_get_thumbnail): * backend/ev-document-thumbnails.h: Rework API a bit. Add a border flag and change sizing logic (now the size we specify applies to the bigger dimension). * pdf/pdf-document.cc: * pixbuf/pixbuf-document.c: (pixbuf_document_thumbnails_get_thumbnail): * shell/ev-sidebar-thumbnails.c: (do_one_iteration): * thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get): Adapt to the new API and do not draw a border for nautilus thumbnailer. --- diff --git a/ChangeLog b/ChangeLog index dc833ce8..1052cf2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2005-03-07 Marco Pesenti Gritti + + * backend/ev-document-thumbnails.c: + (ev_document_thumbnails_get_thumbnail): + * backend/ev-document-thumbnails.h: + + Rework API a bit. Add a border flag and + change sizing logic (now the size we specify + applies to the bigger dimension). + + * pdf/pdf-document.cc: + * pixbuf/pixbuf-document.c: + (pixbuf_document_thumbnails_get_thumbnail): + * shell/ev-sidebar-thumbnails.c: (do_one_iteration): + * thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get): + + Adapt to the new API and do not draw a border for nautilus + thumbnailer. + 2005-03-03 Fernando Herrera * thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get): diff --git a/backend/ev-document-thumbnails.c b/backend/ev-document-thumbnails.c index ce2f2187..260d6238 100644 --- a/backend/ev-document-thumbnails.c +++ b/backend/ev-document-thumbnails.c @@ -47,14 +47,15 @@ ev_document_thumbnails_get_type (void) GdkPixbuf * ev_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, gint page, - gint suggested_width) + gint size, + gboolean border) { EvDocumentThumbnailsIface *iface; g_return_val_if_fail (EV_IS_DOCUMENT_THUMBNAILS (document), NULL); iface = EV_DOCUMENT_THUMBNAILS_GET_IFACE (document); - return iface->get_thumbnail (document, page, suggested_width); + return iface->get_thumbnail (document, page, size, border); } void diff --git a/backend/ev-document-thumbnails.h b/backend/ev-document-thumbnails.h index 52ed6c57..76b0cc8c 100644 --- a/backend/ev-document-thumbnails.h +++ b/backend/ev-document-thumbnails.h @@ -42,7 +42,8 @@ struct _EvDocumentThumbnailsIface /* Methods */ GdkPixbuf * (* get_thumbnail) (EvDocumentThumbnails *document, gint page, - gint width); + gint size, + gboolean border); void (* get_dimensions) (EvDocumentThumbnails *document, gint page, gint suggested_width, @@ -53,10 +54,11 @@ struct _EvDocumentThumbnailsIface GType ev_document_thumbnails_get_type (void); GdkPixbuf *ev_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, gint page, - gint suggested_width); + gint size, + gboolean border); void ev_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, gint page, - gint suggested_width, + gint size, gint *width, gint *height); diff --git a/pdf/pdf-document.cc b/pdf/pdf-document.cc index a749d368..2ed1f171 100644 --- a/pdf/pdf-document.cc +++ b/pdf/pdf-document.cc @@ -1240,7 +1240,8 @@ pdf_document_thumbnails_get_page_pixbuf (PdfDocument *pdf_document, gdouble scale_factor, gint page_num, gint width, - gint height) + gint height, + gboolean border) { SplashOutputDev *output; GdkPixbuf *pixbuf; @@ -1256,9 +1257,17 @@ pdf_document_thumbnails_get_page_pixbuf (PdfDocument *pdf_document, 72*scale_factor, 0, gTrue, gFalse); - pixbuf = ev_document_misc_get_thumbnail_frame (output->getBitmap()->getWidth(), - output->getBitmap()->getHeight(), - NULL); + width = output->getBitmap()->getWidth(); + height = output->getBitmap()->getHeight(); + + if (border) { + pixbuf = ev_document_misc_get_thumbnail_frame (width, height, NULL); + } else { + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, + width + 4, height + 4); + gdk_pixbuf_fill (pixbuf, 0xffffffff); + } + bitmap_to_pixbuf (output->getBitmap(), pixbuf, 1, 1); delete output; @@ -1268,7 +1277,7 @@ pdf_document_thumbnails_get_page_pixbuf (PdfDocument *pdf_document, static void pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails, gint page, - gint suggested_width, + gint size, gint *width, gint *height) { @@ -1276,9 +1285,8 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail Page *the_page; Object the_thumb; Thumb *thumb = NULL; - gdouble page_ratio; - the_page = pdf_document->doc->getCatalog ()->getPage (page); + the_page = pdf_document->doc->getCatalog ()->getPage (page + 1); the_page->getThumb (&the_thumb); if (!(the_thumb.isNull () || the_thumb.isNone())) { @@ -1289,16 +1297,26 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail *width = thumb->getWidth (); *height = thumb->getHeight (); } else { - page_ratio = the_page->getHeight () / the_page->getWidth (); - *width = suggested_width; - *height = (gint) (suggested_width * page_ratio); + double page_width, page_height; + + page_width = the_page->getWidth (); + page_height = the_page->getHeight (); + + if (page_width > page_height) { + *width = size; + *height = (int) (size * page_height / page_width); + } else { + *width = (int) (size * page_width / page_height); + *height = size; + } } } static GdkPixbuf * pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails, gint page, - gint width) + gint size, + gboolean border) { PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails); GdkPixbuf *thumbnail; @@ -1306,17 +1324,11 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails Object the_thumb; Thumb *thumb = NULL; gboolean have_ethumbs = FALSE; - gdouble page_ratio; - gint dest_height; /* getPage seems to want page + 1 for some reason; */ the_page = pdf_document->doc->getCatalog ()->getPage (page + 1); the_page->getThumb(&the_thumb); - page_ratio = the_page->getHeight () / the_page->getWidth (); - dest_height = (gint) (width * page_ratio); - - if (!(the_thumb.isNull () || the_thumb.isNone())) { /* Build the thumbnail object */ thumb = new Thumb(pdf_document->doc->getXRef (), @@ -1342,15 +1354,18 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails thumbnail = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf); g_object_unref (tmp_pixbuf); } else { - gdouble scale_factor; - - scale_factor = (gdouble)width / the_page->getWidth (); - + int width, height; + double scale_factor; + + pdf_document_thumbnails_get_dimensions (document_thumbnails, page, size, + &width, &height); + scale_factor = width / the_page->getWidth (); thumbnail = pdf_document_thumbnails_get_page_pixbuf (pdf_document, scale_factor, page, width, - dest_height); + height, + border); } return thumbnail; diff --git a/pixbuf/pixbuf-document.c b/pixbuf/pixbuf-document.c index ab93f19b..4195675b 100644 --- a/pixbuf/pixbuf-document.c +++ b/pixbuf/pixbuf-document.c @@ -267,19 +267,20 @@ pixbuf_document_document_iface_init (EvDocumentIface *iface) static GdkPixbuf * pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - gint page, - gint width) + gint page, + gint size, + gboolean border) { PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document); GdkPixbuf *pixbuf; gdouble scale_factor; gint height; - scale_factor = (gdouble)width / gdk_pixbuf_get_width (pixbuf_document->pixbuf); + scale_factor = (gdouble)size / gdk_pixbuf_get_width (pixbuf_document->pixbuf); height = gdk_pixbuf_get_height (pixbuf_document->pixbuf) * scale_factor; - pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, width, height, + pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, size, height, GDK_INTERP_BILINEAR); return pixbuf; diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c index de31e478..b602bb26 100644 --- a/shell/ev-sidebar-thumbnails.c +++ b/shell/ev-sidebar-thumbnails.c @@ -35,7 +35,8 @@ #include "ev-window.h" #include "ev-utils.h" -#define THUMBNAIL_WIDTH 75 +#define THUMBNAIL_WIDTH 100 + /* Amount of time we devote to each iteration of the idle, in microseconds */ #define IDLE_WORK_LENGTH 5000 @@ -222,8 +223,9 @@ do_one_iteration (EvSidebarThumbnails *ev_sidebar_thumbnails) COLUMN_THUMBNAIL_SET, &thumbnail_set, -1); if (!thumbnail_set) { - pixbuf = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (priv->document), - priv->current_page, THUMBNAIL_WIDTH); + pixbuf = ev_document_thumbnails_get_thumbnail + (EV_DOCUMENT_THUMBNAILS (priv->document), + priv->current_page, THUMBNAIL_WIDTH, TRUE); gtk_list_store_set (priv->list_store, &(priv->current_page_iter), diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c index 06fdec14..d7db2654 100644 --- a/thumbnailer/evince-thumbnailer.c +++ b/thumbnailer/evince-thumbnailer.c @@ -28,7 +28,7 @@ #include -#define THUMBNAIL_SIZE 100 +#define THUMBNAIL_SIZE 128 static gboolean evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail) @@ -57,7 +57,7 @@ evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail) } pixbuf = ev_document_thumbnails_get_thumbnail - (EV_DOCUMENT_THUMBNAILS (document), 0, THUMBNAIL_SIZE); + (EV_DOCUMENT_THUMBNAILS (document), 0, THUMBNAIL_SIZE, FALSE); if (pixbuf != NULL) { GdkPixbuf *pdflogo;