Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use autoscaling? #29

Open
jeroen opened this issue Feb 6, 2022 · 1 comment
Open

Use autoscaling? #29

jeroen opened this issue Feb 6, 2022 · 1 comment

Comments

@jeroen
Copy link
Member

jeroen commented Feb 6, 2022

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): #28

@federicomenaquintero
Copy link

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:

  • First, use rsvg_handle_get_intrinsic_size_in_pixels(). If that returns true, you have a size you can use. If it doesn't, it means the SVG has something like <svg width="50%" height="100%">, which must be resolved against a viewport..
  • ... and in that case, I think you are in the "just figure out a sensible size so I can create my surface" case. You can rsvg_handle_get_geometry_for_element(handle, NULL, &out_ink_rect, NULL, &error) to ask librsvg to actually measure the geometries of all elements. This is the implicit behavior from the old rsvg_handle_get_dimensions().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants