Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2007-02-16 17:27:12 (GMT)
committer Carlos Garcia Campos <carlosgc@src.gnome.org>2007-02-16 17:27:12 (GMT)
commit1d6150237848b4c1fede94ce23baa4fd8870fd93 (patch)
tree7a607e0263e6b40591b31885b561f2192b7b6695 /backend
parent76f055907e4eab82025f28cd0e813eb39713bf5b (diff)
Use an EvRenderContext for rendering thumbnails instead of a suggested
2007-02-16 Carlos Garcia Campos <carlosgc@gnome.org> * backend/dvi/dvi-document.c: (dvi_document_thumbnails_get_dimensions), (dvi_document_thumbnails_get_thumbnail): * backend/impress/impress-document.c: (impress_document_thumbnails_get_thumbnail), (impress_document_thumbnails_get_dimensions): * backend/ps/ps-document.c: (ps_document_thumbnails_get_thumbnail), (ps_document_thumbnails_get_dimensions): * backend/djvu/djvu-document.c: (djvu_document_thumbnails_get_dimensions), (djvu_document_thumbnails_get_thumbnail): * backend/tiff/tiff-document.c: (tiff_document_thumbnails_get_thumbnail), (tiff_document_thumbnails_get_dimensions): * backend/pdf/ev-poppler.cc: (make_thumbnail_for_page), (pdf_document_thumbnails_get_thumbnail), (pdf_document_thumbnails_get_dimensions): * backend/comics/comics-document.c: (comics_document_thumbnails_get_thumbnail), (comics_document_thumbnails_get_dimensions): * backend/pixbuf/pixbuf-document.c: (pixbuf_document_thumbnails_get_thumbnail), (pixbuf_document_thumbnails_get_dimensions): * libdocument/ev-document-thumbnails.[ch]: (ev_document_thumbnails_get_thumbnail), (ev_document_thumbnails_get_dimensions): * libdocument/ev-document-misc.[ch]: (ev_document_misc_get_thumbnail_frame): * shell/ev-jobs.[ch]: (ev_job_thumbnail_dispose), (ev_job_thumbnail_new), (ev_job_thumbnail_run): * shell/ev-sidebar-thumbnails.c: (get_scale_for_page), (add_range), (ev_sidebar_thumbnails_set_loading_icon), (refresh), (ev_sidebar_thumbnails_refresh): * shell/ev-window.c: (ev_window_setup_document): * thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get): Use an EvRenderContext for rendering thumbnails instead of a suggested width, so that different sized pages get sized proportionally. svn path=/trunk/; revision=2332
Diffstat (limited to 'backend')
-rw-r--r--backend/comics/comics-document.c67
-rw-r--r--backend/djvu/djvu-document.c52
-rw-r--r--backend/dvi/dvi-document.c42
-rw-r--r--backend/impress/impress-document.c45
-rw-r--r--backend/pdf/ev-poppler.cc69
-rw-r--r--backend/pixbuf/pixbuf-document.c44
-rw-r--r--backend/ps/ps-document.c39
-rw-r--r--backend/tiff/tiff-document.c369
8 files changed, 331 insertions, 396 deletions
diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c
index 7f53f85..e0fdd31 100644
--- a/backend/comics/comics-document.c
+++ b/backend/comics/comics-document.c
@@ -409,52 +409,19 @@ get_supported_image_extensions()
return extensions;
}
-static void
-comics_document_thumbnails_get_geometry (EvDocumentThumbnails *document,
- gint page,
- gint suggested_width,
- gint *width,
- gint *height,
- gdouble *scale_factor)
-{
- gdouble orig_width, orig_height, scale;
-
- comics_document_get_page_size (EV_DOCUMENT (document), page,
- &orig_width, &orig_height);
- scale = suggested_width / orig_width;
-
- if (width)
- *width = suggested_width;
- if (height)
- *height = orig_height * scale;
- if (scale_factor)
- *scale_factor = scale;
-}
-
static GdkPixbuf *
comics_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
- gint page,
- gint rotation,
- gint size,
- gboolean border)
+ EvRenderContext *rc,
+ gboolean border)
{
- GdkPixbuf *thumbnail, *framed;
- gint thumb_width, thumb_height;
- gdouble scale;
- EvRenderContext *rc;
+ GdkPixbuf *thumbnail;
- comics_document_thumbnails_get_geometry (document, page, size,
- &thumb_width, &thumb_height,
- &scale);
-
- rc = ev_render_context_new (rotation, page, scale);
- thumbnail = comics_document_render_pixbuf (EV_DOCUMENT (document),
- rc);
- g_object_unref (G_OBJECT (rc));
+ thumbnail = comics_document_render_pixbuf (EV_DOCUMENT (document), rc);
if (border) {
GdkPixbuf *tmp_pixbuf = thumbnail;
- thumbnail = ev_document_misc_get_thumbnail_frame (-1, -1, 0, tmp_pixbuf);
+
+ thumbnail = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf);
g_object_unref (tmp_pixbuf);
}
@@ -463,14 +430,22 @@ comics_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
static void
comics_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
- gint page,
- gint suggested_width,
- gint *width,
- gint *height)
+ EvRenderContext *rc,
+ gint *width,
+ gint *height)
{
- comics_document_thumbnails_get_geometry (document, page,
- suggested_width,
- width, height, NULL);
+ gdouble page_width, page_height;
+
+ comics_document_get_page_size (EV_DOCUMENT (document), rc->page,
+ &page_width, &page_height);
+
+ if (rc->rotation == 90 || rc->rotation == 270) {
+ *width = (gint) (page_height * rc->scale);
+ *height = (gint) (page_width * rc->scale);
+ } else {
+ *width = (gint) (page_width * rc->scale);
+ *height = (gint) (page_height * rc->scale);
+ }
}
static void
diff --git a/backend/djvu/djvu-document.c b/backend/djvu/djvu-document.c
index bf74c9a..8b45514 100644
--- a/backend/djvu/djvu-document.c
+++ b/backend/djvu/djvu-document.c
@@ -326,61 +326,65 @@ djvu_document_document_iface_init (EvDocumentIface *iface)
static void
djvu_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
- gint page,
- gint suggested_width,
- gint *width,
- gint *height)
+ EvRenderContext *rc,
+ gint *width,
+ gint *height)
{
DjvuDocument *djvu_document = DJVU_DOCUMENT (document);
- gdouble p_width, p_height;
- gdouble page_ratio;
+ gdouble page_width, page_height;
- djvu_document_get_page_size (EV_DOCUMENT(djvu_document), page, &p_width, &p_height);
+ djvu_document_get_page_size (EV_DOCUMENT(djvu_document), rc->page,
+ &page_width, &page_height);
- page_ratio = p_height / p_width;
- *width = suggested_width;
- *height = (gint) (suggested_width * page_ratio);
-
- return;
+ if (rc->rotation == 90 || rc->rotation == 270) {
+ *width = (gint) (page_height * rc->scale);
+ *height = (gint) (page_width * rc->scale);
+ } else {
+ *width = (gint) (page_width * rc->scale);
+ *height = (gint) (page_height * rc->scale);
+ }
}
static GdkPixbuf *
-djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
- gint page,
- gint rotation,
- gint width,
- gboolean border)
+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);
- djvu_document_thumbnails_get_dimensions (document, page, width, &thumb_width, &thumb_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, page, 1) < DDJVU_JOB_OK)
+ while (ddjvu_thumbnail_status (djvu_document->d_document, rc->page, 1) < DDJVU_JOB_OK)
djvu_handle_events(djvu_document, TRUE);
- ddjvu_thumbnail_render (djvu_document->d_document, page,
+ ddjvu_thumbnail_render (djvu_document->d_document, rc->page,
&thumb_width, &thumb_height,
djvu_document->d_format,
gdk_pixbuf_get_rowstride (pixbuf),
(gchar *)pixels);
- rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rotation);
+ 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, 0, tmp_pixbuf);
+
+ rotated_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf);
g_object_unref (tmp_pixbuf);
}
diff --git a/backend/dvi/dvi-document.c b/backend/dvi/dvi-document.c
index 4de5e64..bd69970 100644
--- a/backend/dvi/dvi-document.c
+++ b/backend/dvi/dvi-document.c
@@ -17,8 +17,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include <config.h>
-
#include "dvi-document.h"
#include "ev-document-thumbnails.h"
#include "ev-document-misc.h"
@@ -267,27 +265,27 @@ dvi_document_document_iface_init (EvDocumentIface *iface)
static void
dvi_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
- gint page,
- gint suggested_width,
+ EvRenderContext *rc,
gint *width,
gint *height)
{
- DviDocument *dvi_document = DVI_DOCUMENT (document);
- gdouble page_ratio;
-
- page_ratio = dvi_document->base_height / dvi_document->base_width;
- *width = suggested_width;
- *height = (gint) (suggested_width * page_ratio);
+ DviDocument *dvi_document = DVI_DOCUMENT (document);
+ gdouble page_width = dvi_document->base_width;
+ gdouble page_height = dvi_document->base_height;
- return;
+ if (rc->rotation == 90 || rc->rotation == 270) {
+ *width = (gint) (page_height * rc->scale);
+ *height = (gint) (page_width * rc->scale);
+ } else {
+ *width = (gint) (page_width * rc->scale);
+ *height = (gint) (page_height * rc->scale);
+ }
}
static GdkPixbuf *
-dvi_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
- gint page,
- gint rotation,
- gint width,
- gboolean border)
+dvi_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
+ EvRenderContext *rc,
+ gboolean border)
{
DviDocument *dvi_document = DVI_DOCUMENT (document);
GdkPixbuf *pixbuf;
@@ -296,11 +294,12 @@ dvi_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
gint thumb_width, thumb_height;
gint proposed_width, proposed_height;
- dvi_document_thumbnails_get_dimensions (document, page, width, &thumb_width, &thumb_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, page);
+ mdvi_setpage (dvi_document->context, rc->page);
mdvi_set_shrink (dvi_document->context,
(int)dvi_document->base_width * dvi_document->params->hshrink / thumb_width,
@@ -325,12 +324,13 @@ dvi_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
g_mutex_unlock (dvi_context_mutex);
- rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rotation);
+ 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, 0, tmp_pixbuf);
+
+ rotated_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf);
g_object_unref (tmp_pixbuf);
}
diff --git a/backend/impress/impress-document.c b/backend/impress/impress-document.c
index 9756a84..5f5982e 100644
--- a/backend/impress/impress-document.c
+++ b/backend/impress/impress-document.c
@@ -467,27 +467,19 @@ impress_document_document_iface_init (EvDocumentIface *iface)
static GdkPixbuf *
impress_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
- gint page,
- gint rotation,
- gint size,
- gboolean border)
+ EvRenderContext *rc,
+ gboolean border)
{
GdkPixbuf *pixbuf = NULL;
gdouble w, h;
- EvRenderContext *rc;
- impress_document_get_page_size (EV_DOCUMENT (document),
- page,
- &w, &h);
-
- rc = ev_render_context_new (rotation, page, size/w);
pixbuf = impress_document_render_pixbuf (EV_DOCUMENT (document), rc);
- g_object_unref (G_OBJECT (rc));
if (border)
{
GdkPixbuf *tmp_pixbuf = pixbuf;
- pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, 0, tmp_pixbuf);
+
+ pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf);
g_object_unref (tmp_pixbuf);
}
@@ -496,21 +488,26 @@ impress_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
static void
impress_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
- gint page,
- gint suggested_width,
- gint *width,
- gint *height)
+ EvRenderContext *rc,
+ gint *width,
+ gint *height)
{
- gdouble page_ratio;
- gdouble w, h;
+ gdouble page_width, page_height;
impress_document_get_page_size (EV_DOCUMENT (document),
- page,
- &w, &h);
- g_return_if_fail (w > 0);
- page_ratio = h/w;
- *width = suggested_width;
- *height = (gint) (suggested_width * page_ratio);
+ rc->page,
+ &page_width, &page_height);
+
+ if (rc->rotation == 90 || rc->rotation == 270)
+ {
+ *width = (gint) (page_height * rc->scale);
+ *height = (gint) (page_width * rc->scale);
+ }
+ else
+ {
+ *width = (gint) (page_width * rc->scale);
+ *height = (gint) (page_height * rc->scale);
+ }
}
static void
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index 7c2c528..715226a 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -92,8 +92,7 @@ static void pdf_document_file_exporter_iface_init (EvFileExporterIface
static void pdf_selection_iface_init (EvSelectionIface *iface);
static void pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface);
static void pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
- gint page,
- gint size,
+ EvRenderContext *rc,
gint *width,
gint *height);
static int pdf_document_get_n_pages (EvDocument *document);
@@ -1174,32 +1173,15 @@ pdf_document_document_images_iface_init (EvDocumentImagesIface *iface)
}
static GdkPixbuf *
-make_thumbnail_for_size (PdfDocument *pdf_document,
- gint page,
- int rotation,
- gint size)
+make_thumbnail_for_page (PdfDocument *pdf_document,
+ PopplerPage *poppler_page,
+ EvRenderContext *rc)
{
- PopplerPage *poppler_page;
GdkPixbuf *pixbuf;
int width, height;
- double scale;
- gdouble unscaled_width, unscaled_height;
- poppler_page = poppler_document_get_page (pdf_document->document, page);
- g_return_val_if_fail (poppler_page != NULL, NULL);
-
- pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document), page,
- size, &width, &height);
- poppler_page_get_size (poppler_page, &unscaled_width, &unscaled_height);
- scale = width / unscaled_width;
-
- /* rotate */
- if (rotation == 90 || rotation == 270) {
- int temp;
- temp = width;
- width = height;
- height = temp;
- }
+ pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document),
+ rc, &width, &height);
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
width, height);
@@ -1208,20 +1190,15 @@ make_thumbnail_for_size (PdfDocument *pdf_document,
ev_document_fc_mutex_lock ();
poppler_page_render_to_pixbuf (poppler_page, 0, 0,
width, height,
- scale, rotation, pixbuf);
+ rc->scale, rc->rotation, pixbuf);
ev_document_fc_mutex_unlock ();
-
-
- g_object_unref (poppler_page);
return pixbuf;
}
static GdkPixbuf *
pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
- gint page,
- gint rotation,
- gint size,
+ EvRenderContext *rc,
gboolean border)
{
PdfDocument *pdf_document;
@@ -1231,18 +1208,17 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails
pdf_document = PDF_DOCUMENT (document_thumbnails);
- poppler_page = poppler_document_get_page (pdf_document->document, page);
+ poppler_page = poppler_document_get_page (pdf_document->document, rc->page);
g_return_val_if_fail (poppler_page != NULL, NULL);
pixbuf = poppler_page_get_thumbnail (poppler_page);
-
- if (pixbuf == NULL) {
+ if (!pixbuf) {
/* There is no provided thumbnail. We need to make one. */
- pixbuf = make_thumbnail_for_size (pdf_document, page, rotation, size);
+ pixbuf = make_thumbnail_for_page (pdf_document, poppler_page, rc);
}
if (border) {
- border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, rotation, pixbuf);
+ border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf);
g_object_unref (pixbuf);
pixbuf = border_pixbuf;
}
@@ -1254,8 +1230,7 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails
static void
pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
- gint page,
- gint size,
+ EvRenderContext *rc,
gint *width,
gint *height)
{
@@ -1264,10 +1239,8 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail
gint has_thumb;
pdf_document = PDF_DOCUMENT (document_thumbnails);
- poppler_page = poppler_document_get_page (pdf_document->document, page);
+ poppler_page = poppler_document_get_page (pdf_document->document, rc->page);
- g_return_if_fail (width != NULL);
- g_return_if_fail (height != NULL);
g_return_if_fail (poppler_page != NULL);
has_thumb = poppler_page_get_thumbnail_size (poppler_page, width, height);
@@ -1276,9 +1249,19 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail
double page_width, page_height;
poppler_page_get_size (poppler_page, &page_width, &page_height);
- *width = size;
- *height = (int) (size * page_height / page_width);
+
+ *width = (gint) (page_width * rc->scale);
+ *height = (gint) (page_height * rc->scale);
}
+
+ if (rc->rotation == 90 || rc->rotation == 270) {
+ gint temp;
+
+ temp = *width;
+ *width = *height;
+ *height = temp;
+ }
+
g_object_unref (poppler_page);
}
diff --git a/backend/pixbuf/pixbuf-document.c b/backend/pixbuf/pixbuf-document.c
index e3d064d..c1cace0 100644
--- a/backend/pixbuf/pixbuf-document.c
+++ b/backend/pixbuf/pixbuf-document.c
@@ -168,25 +168,22 @@ pixbuf_document_document_iface_init (EvDocumentIface *iface)
}
static GdkPixbuf *
-pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
- gint page,
- gint rotation,
- gint size,
- gboolean border)
+pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
+ EvRenderContext *rc,
+ gboolean border)
{
PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
GdkPixbuf *pixbuf, *rotated_pixbuf;
- gdouble scale_factor;
- gint height;
+ gint width, height;
- scale_factor = (gdouble)size / gdk_pixbuf_get_width (pixbuf_document->pixbuf);
-
- height = gdk_pixbuf_get_height (pixbuf_document->pixbuf) * scale_factor;
+ 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, size, height,
+ pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf,
+ width, height,
GDK_INTERP_BILINEAR);
- rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rotation);
+ rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation);
g_object_unref (pixbuf);
return rotated_pixbuf;
@@ -194,18 +191,21 @@ pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
static void
pixbuf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
- gint page,
- gint suggested_width,
- gint *width,
- gint *height)
+ EvRenderContext *rc,
+ gint *width,
+ gint *height)
{
PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
- gdouble page_ratio;
-
- page_ratio = ((double)gdk_pixbuf_get_height (pixbuf_document->pixbuf)) /
- gdk_pixbuf_get_width (pixbuf_document->pixbuf);
- *width = suggested_width;
- *height = (gint) (suggested_width * page_ratio);
+ gint p_width = gdk_pixbuf_get_width (pixbuf_document->pixbuf);
+ gint p_height = gdk_pixbuf_get_height (pixbuf_document->pixbuf);
+
+ if (rc->rotation == 90 || rc->rotation == 270) {
+ *width = (gint) (p_height * rc->scale);
+ *height = (gint) (p_width * rc->scale);
+ } else {
+ *width = (gint) (p_width * rc->scale);
+ *height = (gint) (p_height * rc->scale);
+ }
}
static void
diff --git a/backend/ps/ps-document.c b/backend/ps/ps-document.c
index d1b456d..0e79ec5 100644
--- a/backend/ps/ps-document.c
+++ b/backend/ps/ps-document.c
@@ -516,15 +516,11 @@ ps_document_render_thumbnail (PSDocument *ps_document)
static GdkPixbuf *
ps_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
- gint page,
- gint rotation,
- gint size,
+ EvRenderContext *rc,
gboolean border)
{
PSDocument *ps_document;
GdkPixbuf *pixbuf = NULL;
- gdouble page_width, page_height;
- gdouble scale;
ps_document = PS_DOCUMENT (document_thumbnails);
@@ -543,19 +539,9 @@ ps_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
ps_document->thumbs_mutex = g_mutex_new ();
ps_document->thumbs_cond = g_cond_new ();
- ps_document_get_page_size (EV_DOCUMENT (ps_document), page,
- &page_width, &page_height);
- scale = size / page_width;
-
- rotation = (rotation + ps_document_get_page_rotation (ps_document, page)) % 360;
-
- if (!ps_document->thumbs_rc) {
- ps_document->thumbs_rc = ev_render_context_new (rotation, page, scale);
- } else {
- ev_render_context_set_page (ps_document->thumbs_rc, page);
- ev_render_context_set_scale (ps_document->thumbs_rc, scale);
- ev_render_context_set_rotation (ps_document->thumbs_rc, rotation);
- }
+ if (ps_document->thumbs_rc)
+ g_object_unref (ps_document->thumbs_rc);
+ ps_document->thumbs_rc = g_object_ref (rc);
ev_document_doc_mutex_unlock ();
g_mutex_lock (ps_document->thumbs_mutex);
@@ -572,7 +558,7 @@ ps_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
if (border) {
GdkPixbuf *border_pixbuf;
- border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, rotation, pixbuf);
+ border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf);
g_object_unref (pixbuf);
pixbuf = border_pixbuf;
}
@@ -582,8 +568,7 @@ ps_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
static void
ps_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
- gint page,
- gint size,
+ EvRenderContext *rc,
gint *width,
gint *height)
{
@@ -593,10 +578,16 @@ ps_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails
ps_document = PS_DOCUMENT (document_thumbnails);
ps_document_get_page_size (EV_DOCUMENT (ps_document),
- page,
+ rc->page,
&page_width, &page_height);
- *width = size;
- *height = (int) (size * page_height / page_width);
+
+ if (rc->rotation == 90 || rc->rotation == 270) {
+ *width = (gint) (page_height * rc->scale);
+ *height = (gint) (page_width * rc->scale);
+ } else {
+ *width = (gint) (page_width * rc->scale);
+ *height = (gint) (page_height * rc->scale);
+ }
}
static void
diff --git a/backend/tiff/tiff-document.c b/backend/tiff/tiff-document.c
index 24af05f..9348ed4 100644
--- a/backend/tiff/tiff-document.c
+++ b/backend/tiff/tiff-document.c
@@ -67,15 +67,15 @@ static TIFFErrorHandler orig_warning_handler = NULL;
static void
push_handlers (void)
{
- orig_error_handler = TIFFSetErrorHandler (NULL);
- orig_warning_handler = TIFFSetWarningHandler (NULL);
+ orig_error_handler = TIFFSetErrorHandler (NULL);
+ orig_warning_handler = TIFFSetWarningHandler (NULL);
}
static void
pop_handlers (void)
{
- TIFFSetErrorHandler (orig_error_handler);
- TIFFSetWarningHandler (orig_warning_handler);
+ TIFFSetErrorHandler (orig_error_handler);
+ TIFFSetWarningHandler (orig_warning_handler);
}
static gboolean
@@ -83,44 +83,44 @@ tiff_document_load (EvDocument *document,
const char *uri,
GError **error)
{
- TiffDocument *tiff_document = TIFF_DOCUMENT (document);
- gchar *filename;
- TIFF *tiff;
-
- push_handlers ();
- filename = g_filename_from_uri (uri, NULL, error);
- if (!filename)
- {
- pop_handlers ();
- return FALSE;
- }
-
- tiff = TIFFOpen (filename, "r");
- if (tiff)
- {
- guint32 w, h;
- /* FIXME: unused data? why bother here */
- TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &w);
- TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &h);
- }
- if (!tiff)
- {
- pop_handlers ();
- return FALSE;
- }
- tiff_document->tiff = tiff;
- g_free (tiff_document->uri);
- g_free (filename);
- tiff_document->uri = g_strdup (uri);
-
- pop_handlers ();
- return TRUE;
+ TiffDocument *tiff_document = TIFF_DOCUMENT (document);
+ gchar *filename;
+ TIFF *tiff;
+
+ push_handlers ();
+ filename = g_filename_from_uri (uri, NULL, error);
+ if (!filename) {
+ pop_handlers ();
+ return FALSE;
+ }
+
+ tiff = TIFFOpen (filename, "r");
+ if (tiff) {
+ guint32 w, h;
+
+ /* FIXME: unused data? why bother here */
+ TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &w);
+ TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &h);
+ }
+
+ if (!tiff) {
+ pop_handlers ();
+ return FALSE;
+ }
+
+ tiff_document->tiff = tiff;
+ g_free (tiff_document->uri);
+ g_free (filename);
+ tiff_document->uri = g_strdup (uri);
+
+ pop_handlers ();
+ return TRUE;
}
static gboolean
tiff_document_save (EvDocument *document,
- const char *uri,
- GError **error)
+ const char *uri,
+ GError **error)
{
TiffDocument *tiff_document = TIFF_DOCUMENT (document);
@@ -130,24 +130,23 @@ tiff_document_save (EvDocument *document,
static int
tiff_document_get_n_pages (EvDocument *document)
{
- TiffDocument *tiff_document = TIFF_DOCUMENT (document);
-
- g_return_val_if_fail (TIFF_IS_DOCUMENT (document), 0);
- g_return_val_if_fail (tiff_document->tiff != NULL, 0);
-
- if (tiff_document->n_pages == -1)
- {
- push_handlers ();
- tiff_document->n_pages = 0;
- do
- {
- tiff_document->n_pages ++;
+ TiffDocument *tiff_document = TIFF_DOCUMENT (document);
+
+ g_return_val_if_fail (TIFF_IS_DOCUMENT (document), 0);
+ g_return_val_if_fail (tiff_document->tiff != NULL, 0);
+
+ if (tiff_document->n_pages == -1) {
+ push_handlers ();
+ tiff_document->n_pages = 0;
+
+ do {
+ tiff_document->n_pages ++;
+ }
+ while (TIFFReadDirectory (tiff_document->tiff));
+ pop_handlers ();
}
- while (TIFFReadDirectory (tiff_document->tiff));
- pop_handlers ();
- }
- return tiff_document->n_pages;
+ return tiff_document->n_pages;
}
static void
@@ -156,117 +155,111 @@ tiff_document_get_page_size (EvDocument *document,
double *width,
double *height)
{
- guint32 w, h;
- gfloat x_res, y_res;
- TiffDocument *tiff_document = TIFF_DOCUMENT (document);
-
- g_return_if_fail (TIFF_IS_DOCUMENT (document));
- g_return_if_fail (tiff_document->tiff != NULL);
-
- push_handlers ();
- if (TIFFSetDirectory (tiff_document->tiff, page) != 1)
- {
- pop_handlers ();
- return;
- }
-
- TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &w);
- TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &h);
- TIFFGetField (tiff_document->tiff, TIFFTAG_XRESOLUTION, &x_res);
- TIFFGetField (tiff_document->tiff, TIFFTAG_YRESOLUTION, &y_res);
- h = h * (x_res / y_res);
-
- *width = w;
- *height = h;
-
- pop_handlers ();
+ guint32 w, h;
+ gfloat x_res, y_res;
+ TiffDocument *tiff_document = TIFF_DOCUMENT (document);
+
+ g_return_if_fail (TIFF_IS_DOCUMENT (document));
+ g_return_if_fail (tiff_document->tiff != NULL);
+
+ push_handlers ();
+ if (TIFFSetDirectory (tiff_document->tiff, page) != 1) {
+ pop_handlers ();
+ return;
+ }
+
+ TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &w);
+ TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &h);
+ TIFFGetField (tiff_document->tiff, TIFFTAG_XRESOLUTION, &x_res);
+ TIFFGetField (tiff_document->tiff, TIFFTAG_YRESOLUTION, &y_res);
+ h = h * (x_res / y_res);
+
+ *width = w;
+ *height = h;
+
+ pop_handlers ();
}
static GdkPixbuf *
tiff_document_render_pixbuf (EvDocument *document,
EvRenderContext *rc)
{
- TiffDocument *tiff_document = TIFF_DOCUMENT (document);
- int width, height;
- float x_res, y_res;
- gint rowstride, bytes;
- guchar *pixels = NULL;
- GdkPixbuf *pixbuf;
- GdkPixbuf *scaled_pixbuf;
- GdkPixbuf *rotated_pixbuf;
-
- g_return_val_if_fail (TIFF_IS_DOCUMENT (document), 0);
- g_return_val_if_fail (tiff_document->tiff != NULL, 0);
-
- push_handlers ();
- if (TIFFSetDirectory (tiff_document->tiff, rc->page) != 1)
- {
- pop_handlers ();
- return NULL;
- }
-
- if (!TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &width))
- {
- pop_handlers ();
- return NULL;
- }
-
- if (! TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &height))
- {
- pop_handlers ();
- return NULL;
- }
-
- if (!TIFFGetField (tiff_document->tiff, TIFFTAG_XRESOLUTION, &x_res))
- {
- pop_handlers ();
- return NULL;
- }
-
- if (! TIFFGetField (tiff_document->tiff, TIFFTAG_YRESOLUTION, &y_res))
- {
- pop_handlers ();
- return NULL;
- }
-
- pop_handlers ();
-
- /* Sanity check the doc */
- if (width <= 0 || height <= 0)
- return NULL;
-
- rowstride = width * 4;
- if (rowstride / 4 != width)
- /* overflow */
- return NULL;
-
- bytes = height * rowstride;
- if (bytes / rowstride != height)
- /* overflow */
- return NULL;
-
- pixels = g_try_malloc (bytes);
- if (!pixels)
- return NULL;
+ TiffDocument *tiff_document = TIFF_DOCUMENT (document);
+ int width, height;
+ float x_res, y_res;
+ gint rowstride, bytes;
+ guchar *pixels = NULL;
+ GdkPixbuf *pixbuf;
+ GdkPixbuf *scaled_pixbuf;
+ GdkPixbuf *rotated_pixbuf;
+
+ g_return_val_if_fail (TIFF_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (tiff_document->tiff != NULL, NULL);
+
+ push_handlers ();
+ if (TIFFSetDirectory (tiff_document->tiff, rc->page) != 1) {
+ pop_handlers ();
+ return NULL;
+ }
- pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8,
- width, height, rowstride,
- (GdkPixbufDestroyNotify) g_free, NULL);
+ if (!TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &width)) {
+ pop_handlers ();
+ return NULL;
+ }
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
- TIFFReadRGBAImageOriented (tiff_document->tiff, width, height, (uint32 *)gdk_pixbuf_get_pixels (pixbuf), ORIENTATION_TOPLEFT, 1);
- pop_handlers ();
+ if (! TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &height)) {
+ pop_handlers ();
+ return NULL;
+ }
- scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
- width * rc->scale,
- height * rc->scale * (x_res/y_res),
- GDK_INTERP_BILINEAR);
- g_object_unref (pixbuf);
+ if (!TIFFGetField (tiff_document->tiff, TIFFTAG_XRESOLUTION, &x_res)) {
+ pop_handlers ();
+ return NULL;
+ }
- rotated_pixbuf = gdk_pixbuf_rotate_simple (scaled_pixbuf, 360 - rc->rotation);
- g_object_unref (scaled_pixbuf);
+ if (! TIFFGetField (tiff_document->tiff, TIFFTAG_YRESOLUTION, &y_res)) {
+ pop_handlers ();
+ return NULL;
+ }
- return rotated_pixbuf;
+ pop_handlers ();
+
+ /* Sanity check the doc */
+ if (width <= 0 || height <= 0)
+ return NULL;
+
+ rowstride = width * 4;
+ if (rowstride / 4 != width)
+ /* overflow */
+ return NULL;
+
+ bytes = height * rowstride;
+ if (bytes / rowstride != height)
+ /* overflow */
+ return NULL;
+
+ pixels = g_try_malloc (bytes);
+ if (!pixels)
+ return NULL;
+
+ pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8,
+ width, height, rowstride,
+ (GdkPixbufDestroyNotify) g_free, NULL);
+
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+ TIFFReadRGBAImageOriented (tiff_document->tiff, width, height, (uint32 *)gdk_pixbuf_get_pixels (pixbuf), ORIENTATION_TOPLEFT, 1);
+ pop_handlers ();
+
+ scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+ width * rc->scale,
+ height * rc->scale * (x_res/y_res),
+ GDK_INTERP_BILINEAR);
+ g_object_unref (pixbuf);
+
+ rotated_pixbuf = gdk_pixbuf_rotate_simple (scaled_pixbuf, 360 - rc->rotation);
+ g_object_unref (scaled_pixbuf);
+
+ return rotated_pixbuf;
}
static void
@@ -321,57 +314,49 @@ tiff_document_document_iface_init (EvDocumentIface *iface)
static GdkPixbuf *
tiff_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
- gint page,
- gint rotation,
- gint size,
+ EvRenderContext *rc,
gboolean border)
{
- EvRenderContext *rc;
- GdkPixbuf *pixbuf;
- gdouble w, h;
-
- tiff_document_get_page_size (EV_DOCUMENT (document),
- page,
- &w, &h);
-
- rc = ev_render_context_new (rotation, page, size/w);
- pixbuf = tiff_document_render_pixbuf (EV_DOCUMENT (document), rc);
- g_object_unref (G_OBJECT (rc));
-
- if (border)
- {
- GdkPixbuf *tmp_pixbuf = pixbuf;
- pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, 0, tmp_pixbuf);
- g_object_unref (tmp_pixbuf);
- }
-
- return pixbuf;
+ 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_thumbnails_get_dimensions (EvDocumentThumbnails *document,
- gint page,
- gint suggested_width,
+ EvRenderContext *rc,
gint *width,
gint *height)
{
- gdouble page_ratio;
- gdouble w, h;
-
- tiff_document_get_page_size (EV_DOCUMENT (document),
- page,
- &w, &h);
- g_return_if_fail (w > 0);
- page_ratio = h/w;
- *width = suggested_width;
- *height = (gint) (suggested_width * page_ratio);
+ gdouble page_width, page_height;
+
+ tiff_document_get_page_size (EV_DOCUMENT (document),
+ rc->page,
+ &page_width, &page_height);
+
+ if (rc->rotation == 90 || rc->rotation == 270) {
+ *width = (gint) (page_height * rc->scale);
+ *height = (gint) (page_width * rc->scale);
+ } else {
+ *width = (gint) (page_width * rc->scale);
+ *height = (gint) (page_height * rc->scale);
+ }
}
static void
tiff_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
{
- iface->get_thumbnail = tiff_document_thumbnails_get_thumbnail;
- iface->get_dimensions = tiff_document_thumbnails_get_dimensions;
+ iface->get_thumbnail = tiff_document_thumbnails_get_thumbnail;
+ iface->get_dimensions = tiff_document_thumbnails_get_dimensions;
}
/* postscript exporter implementation */
@@ -433,5 +418,5 @@ tiff_document_document_file_exporter_iface_init (EvFileExporterIface *iface)
static void
tiff_document_init (TiffDocument *tiff_document)
{
- tiff_document->n_pages = -1;
+ tiff_document->n_pages = -1;
}