ropensci / rsvg

SVG renderer for R based on librsvg2
Other
95 stars 1 forks source link

Use autoscaling? #29

Open jeroen opened 2 years ago

jeroen commented 2 years ago

Currently we manually calculate the size and scale parameters, based on the w and h given by the user and fitting that into the size given by rsvg_handle_get_intrinsic_dimensions.

However as of librsvg 2.52 we have to use the new rsvg_handle_render_document API which allows us to pass a viewport size to do auto-scaling. Perhaps this also makes the output work better with css.

However the thing I can't figure out is how to make this work if we don't know the viewport size beforehand, i.e. if we just want to render to the size defined in the svg itself, rather than provides by the user. The API seems to assume that the application uses a fixed size viewport, but that is not always the case.

In our application, we first create a cairo canvas using cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height), and then load the svg handle. So we need to give a width/height before loading the svg, but if the user has not specified a width/height, we want to use the width/height as specified in the svg file (which we haven't loaded yet at that point).

So for now we don't use auto-scaling yet, and keep manual scaling (with the new apis): https://github.com/jeroen/rsvg/pull/28

federicomenaquintero commented 2 years ago

I've just filed https://gitlab.gnome.org/GNOME/librsvg/-/issues/852 to remind myself to document how to deal exactly with this case :)

Short summary, which I'll expand in the docs: