Skip to content

Commit 060bdd2

Browse files
committed
fix svgload resolution again
use rsvg_handle_set_dpi() rather than cairo_scale() to avoid int truncation on dimensions see https://github.com/jcupitt/libvips/issues/688
1 parent f3393fb commit 060bdd2

File tree

2 files changed

+5
-27
lines changed

2 files changed

+5
-27
lines changed

libvips/foreign/svgload.c

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,6 @@ vips_foreign_load_svg_dispose( GObject *gobject )
109109
dispose( gobject );
110110
}
111111

112-
static int
113-
vips_foreign_load_svg_build( VipsObject *object )
114-
{
115-
VipsForeignLoadSvg *svg = (VipsForeignLoadSvg *) object;
116-
117-
if( !vips_object_argument_isset( object, "scale" ) )
118-
svg->scale = svg->dpi / 72.0;
119-
120-
/* librsvg defaults to 90 DPI, but vips defaults to 72. We need to
121-
* adjust the scale down.
122-
*/
123-
svg->scale *= 72.0 / 90.0;
124-
125-
if( VIPS_OBJECT_CLASS( vips_foreign_load_svg_parent_class )->
126-
build( object ) )
127-
return( -1 );
128-
129-
return( 0 );
130-
}
131-
132112
static VipsForeignFlags
133113
vips_foreign_load_svg_get_flags_filename( const char *filename )
134114
{
@@ -150,14 +130,15 @@ vips_foreign_load_svg_parse( VipsForeignLoadSvg *svg,
150130
RsvgDimensionData dimensions;
151131
double res;
152132

133+
rsvg_handle_set_dpi( svg->page, svg->dpi * svg->scale );
153134
rsvg_handle_get_dimensions( svg->page, &dimensions );
154135

155136
/* We need pixels/mm for vips.
156137
*/
157138
res = svg->dpi / 25.4;
158139

159140
vips_image_init_fields( out,
160-
dimensions.width * svg->scale, dimensions.height * svg->scale,
141+
dimensions.width, dimensions.height,
161142
4, VIPS_FORMAT_UCHAR,
162143
VIPS_CODING_NONE, VIPS_INTERPRETATION_sRGB, res, res );
163144

@@ -201,9 +182,7 @@ vips_foreign_load_svg_generate( VipsRegion *or,
201182
cr = cairo_create( surface );
202183
cairo_surface_destroy( surface );
203184

204-
cairo_scale( cr, svg->scale, svg->scale );
205-
cairo_translate( cr,
206-
-r->left / svg->scale, -r->top / svg->scale );
185+
cairo_translate( cr, -r->left, -r->top );
207186

208187
/* rsvg is single-threaded, but we don't need to lock since we're
209188
* running inside a non-threaded tilecache.
@@ -279,7 +258,6 @@ vips_foreign_load_svg_class_init( VipsForeignLoadSvgClass *class )
279258

280259
object_class->nickname = "svgload";
281260
object_class->description = _( "load SVG with rsvg" );
282-
object_class->build = vips_foreign_load_svg_build;
283261

284262
load_class->get_flags_filename =
285263
vips_foreign_load_svg_get_flags_filename;
@@ -564,8 +542,8 @@ vips_foreign_load_svg_buffer_init( VipsForeignLoadSvgBuffer *buffer )
564542
* Render a SVG file into a VIPS image. Rendering uses the librsvg library
565543
* and should be fast.
566544
*
567-
* Use @dpi to set the rendering resolution. The default is 72. Alternatively,
568-
* you can scale the rendering from the default 1 point == 1 pixel by @scale.
545+
* Use @dpi to set the rendering resolution. The default is 72. You can also
546+
* scale the rendering by @scale.
569547
*
570548
* This function only reads the image header and does not render any pixel
571549
* data. Rendering occurs when pixels are accessed.

test/images/blankpage.svg.png

20 Bytes
Loading

0 commit comments

Comments
 (0)