From: Carlos Garcia Campos Date: Sun, 8 Apr 2007 16:49:49 +0000 (+0000) Subject: Use default resolution when it's not provided by document. Fixes bug X-Git-Tag: EVINCE_0_8_1~2 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=5ac7231bd357b88678418b4eec896e90c63b4384;p=evince.git Use default resolution when it's not provided by document. Fixes bug 2007-03-08 Carlos Garcia Campos * backend/tiff/tiff-document.c: (tiff_document_get_resolution), (tiff_document_get_page_size), (tiff_document_render_pixbuf): Use default resolution when it's not provided by document. Fixes bug #408762. svn path=/trunk/; revision=2399 --- diff --git a/ChangeLog b/ChangeLog index 65fa1779..64187725 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-03-08 Carlos Garcia Campos + + * backend/tiff/tiff-document.c: (tiff_document_get_resolution), + (tiff_document_get_page_size), (tiff_document_render_pixbuf): + + Use default resolution when it's not provided by document. Fixes bug + #408762. + 2007-03-08 Carlos Garcia Campos * configure.ac: diff --git a/backend/tiff/tiff-document.c b/backend/tiff/tiff-document.c index 9348ed4e..74259472 100644 --- a/backend/tiff/tiff-document.c +++ b/backend/tiff/tiff-document.c @@ -149,6 +149,28 @@ tiff_document_get_n_pages (EvDocument *document) return tiff_document->n_pages; } +static void +tiff_document_get_resolution (TiffDocument *tiff_document, + gfloat *x_res, + gfloat *y_res) +{ + gfloat x = 72.0, y = 72.0; + gushort unit; + + if (TIFFGetField (tiff_document->tiff, TIFFTAG_XRESOLUTION, &x) && + TIFFGetField (tiff_document->tiff, TIFFTAG_YRESOLUTION, &y)) { + if (TIFFGetFieldDefaulted (tiff_document->tiff, TIFFTAG_RESOLUTIONUNIT, &unit)) { + if (unit == RESUNIT_CENTIMETER) { + x *= 2.54; + y *= 2.54; + } + } + } + + *x_res = x; + *y_res = y; +} + static void tiff_document_get_page_size (EvDocument *document, int page, @@ -170,8 +192,7 @@ tiff_document_get_page_size (EvDocument *document, 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); + tiff_document_get_resolution (tiff_document, &x_res, &y_res); h = h * (x_res / y_res); *width = w; @@ -212,22 +233,14 @@ tiff_document_render_pixbuf (EvDocument *document, 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; - } - + tiff_document_get_resolution (tiff_document, &x_res, &y_res); + pop_handlers (); /* Sanity check the doc */ if (width <= 0 || height <= 0) return NULL; - + rowstride = width * 4; if (rowstride / 4 != width) /* overflow */ @@ -247,12 +260,14 @@ tiff_document_render_pixbuf (EvDocument *document, (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); + 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), + height * rc->scale * (x_res / y_res), GDK_INTERP_BILINEAR); g_object_unref (pixbuf);