diff --git a/ChangeLog b/ChangeLog index ea978edb..2d1b2528 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,8 @@ 12/6/17 started 8.5.7 - transform cmyk->rgb automatically on write if there's an embedded profile and the saver does not support cmyk +- fix DPI mixup in svgload ... we were writing images about 20% too large, + thanks Fosk 19/5/17 started 8.5.6 - tiff read with start page > 0 could break edge tiles or strips diff --git a/libvips/foreign/svgload.c b/libvips/foreign/svgload.c index d3afcc16..9c425506 100644 --- a/libvips/foreign/svgload.c +++ b/libvips/foreign/svgload.c @@ -6,6 +6,8 @@ * - add svgz support * 18/1/17 * - invalidate operation on read error + * 8/7/17 + * - fix DPI mixup, thanks Fosk */ /* @@ -107,21 +109,6 @@ vips_foreign_load_svg_dispose( GObject *gobject ) dispose( gobject ); } -static int -vips_foreign_load_svg_build( VipsObject *object ) -{ - VipsForeignLoadSvg *svg = (VipsForeignLoadSvg *) object; - - if( !vips_object_argument_isset( object, "scale" ) ) - svg->scale = svg->dpi / 72.0; - - if( VIPS_OBJECT_CLASS( vips_foreign_load_svg_parent_class )-> - build( object ) ) - return( -1 ); - - return( 0 ); -} - static VipsForeignFlags vips_foreign_load_svg_get_flags_filename( const char *filename ) { @@ -143,6 +130,7 @@ vips_foreign_load_svg_parse( VipsForeignLoadSvg *svg, RsvgDimensionData dimensions; double res; + rsvg_handle_set_dpi( svg->page, svg->dpi * svg->scale ); rsvg_handle_get_dimensions( svg->page, &dimensions ); /* We need pixels/mm for vips. @@ -150,7 +138,7 @@ vips_foreign_load_svg_parse( VipsForeignLoadSvg *svg, res = svg->dpi / 25.4; vips_image_init_fields( out, - dimensions.width * svg->scale, dimensions.height * svg->scale, + dimensions.width, dimensions.height, 4, VIPS_FORMAT_UCHAR, VIPS_CODING_NONE, VIPS_INTERPRETATION_sRGB, res, res ); @@ -194,9 +182,7 @@ vips_foreign_load_svg_generate( VipsRegion *or, cr = cairo_create( surface ); cairo_surface_destroy( surface ); - cairo_scale( cr, svg->scale, svg->scale ); - cairo_translate( cr, - -r->left / svg->scale, -r->top / svg->scale ); + cairo_translate( cr, -r->left, -r->top ); /* rsvg is single-threaded, but we don't need to lock since we're * running inside a non-threaded tilecache. @@ -272,7 +258,6 @@ vips_foreign_load_svg_class_init( VipsForeignLoadSvgClass *class ) object_class->nickname = "svgload"; object_class->description = _( "load SVG with rsvg" ); - object_class->build = vips_foreign_load_svg_build; load_class->get_flags_filename = vips_foreign_load_svg_get_flags_filename; @@ -557,8 +542,8 @@ vips_foreign_load_svg_buffer_init( VipsForeignLoadSvgBuffer *buffer ) * Render a SVG file into a VIPS image. Rendering uses the librsvg library * and should be fast. * - * Use @dpi to set the rendering resolution. The default is 72. Alternatively, - * you can scale the rendering from the default 1 point == 1 pixel by @scale. + * Use @dpi to set the rendering resolution. The default is 72. You can also + * scale the rendering by @scale. * * This function only reads the image header and does not render any pixel * data. Rendering occurs when pixels are accessed. diff --git a/test/images/blankpage.png b/test/images/blankpage.pdf.png similarity index 100% rename from test/images/blankpage.png rename to test/images/blankpage.pdf.png diff --git a/test/images/blankpage.svg b/test/images/blankpage.svg index b0365ff7..bdff12be 100644 --- a/test/images/blankpage.svg +++ b/test/images/blankpage.svg @@ -1,3 +1,58 @@ - - + + + + + + image/svg+xml + + + + + + + + diff --git a/test/images/blankpage.svg.png b/test/images/blankpage.svg.png new file mode 100644 index 00000000..01e4e739 Binary files /dev/null and b/test/images/blankpage.svg.png differ diff --git a/test/test_foreign.py b/test/test_foreign.py index cb787312..d1caa7c4 100755 --- a/test/test_foreign.py +++ b/test/test_foreign.py @@ -595,9 +595,9 @@ class TestForeign(unittest.TestCase): def svg_valid(self, im): a = im(10, 10) - self.assertAlmostEqualObjects(a, [0, 0, 77, 255]) - self.assertEqual(im.width, 360) - self.assertEqual(im.height, 588) + self.assertAlmostEqualObjects(a, [79, 79, 132, 255]) + self.assertEqual(im.width, 288) + self.assertEqual(im.height, 470) self.assertEqual(im.bands, 4) self.file_loader("svgload", self.svg_file, svg_valid) diff --git a/test/test_formats.sh b/test/test_formats.sh index 0341c0a0..52b075f7 100755 --- a/test/test_formats.sh +++ b/test/test_formats.sh @@ -10,11 +10,11 @@ set -e # poppler / pdfload reference image poppler=$test_images/blankpage.pdf -poppler_ref=$test_images/blankpage.png +poppler_ref=$test_images/blankpage.pdf.png # rsvg / svgload reference image rsvg=$test_images/blankpage.svg -rsvg_ref=$test_images/blankpage.png +rsvg_ref=$test_images/blankpage.svg.png # giflib / gifload reference image giflib=$test_images/trans-x.gif @@ -139,13 +139,14 @@ test_loader() { ref=$1 in=$2 format=$3 + thresh=$4 printf "testing $(basename $in) $format ... " $vips copy $ref $tmp/before.v $vips copy $in $tmp/after.v - test_difference $tmp/before.v $tmp/after.v 0 + test_difference $tmp/before.v $tmp/after.v $thresh echo "ok" } @@ -230,19 +231,20 @@ test_raw $mono test_raw $image if test_supported pdfload; then - test_loader $poppler_ref $poppler pdfload + test_loader $poppler_ref $poppler pdfload 0 fi if test_supported svgload; then - test_loader $rsvg_ref $rsvg svgload + # librsvg can give small differences on some platforms + test_loader $rsvg_ref $rsvg svgload 10 fi if test_supported gifload; then - test_loader $giflib_ref $giflib gifload + test_loader $giflib_ref $giflib gifload 0 fi if test_supported matload; then - test_loader $matlab_ref $matlab matlab + test_loader $matlab_ref $matlab matlab 0 fi if test_supported dzsave; then