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

Fix SVG symbol sizing when width and height are with physical units #7054

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mapcentia
Copy link
Contributor

SVG symbols having width and height attributes with physical units (px, in, cm, mm, pt, pc) will get sized from the viewBox if present. so a symbol like this:

<svg xmlns="http://www.w3.org/2000/svg" width="5.5mm" height="5.5mm" viewBox="0 0 15 15">..</svg>

will get sized according to the viewBox. But 5.5mm is 20px, so the symbol will end up cropped on the map.

This patch will test if the symbol has intrinsic size and use rsvg_handle_get_intrinsic_size_in_pixels to get the pixel size and size the symbol from that.

…x, in, cm, mm, pt, pc) will get size from the viewBox if present. so a symbol like this:

```svg
<svg xmlns="http://www.w3.org/2000/svg" width="5.5mm" height="5.5mm" viewBox="0 0 15 15">..</svg>
```

will get sized according to the viewBox. But 5.5mm is 20px, so the symbol will end up cropped on the map.

This patch will test if the symbol has intrinsic size and use rsvg_handle_get_intrinsic_size_in_pixels to get the pixel size.
@mapcentia
Copy link
Contributor Author

The build test fails because it uses Ubuntu 20.04 with rsvg 2.48. get_intrinsic_size_in_pixels is added in 2.52.

It's worth reading the docs for get_intrinsic_dimensions: https://gnome.pages.gitlab.gnome.org/librsvg/Rsvg-2.0/method.Handle.get_intrinsic_dimensions.html

It's not necessary to test the symbol for having a width and height any longer, because it will always have them (it a geometry property of the svg symbol)

@geographika
Copy link
Member

@mapcentia - thanks for the pull request.
Could it be updated to check for the RSVG version number so the code works with multiple versions, with a check similar to:

https://github.com/MapServer/MapServer/blob/ba0d946f31fccc503da2e7c821043253b0e8dbad/src/mapcairo.c#L1009C1-L1009C36

#if LIBRSVG_CHECK_VERSION(2, 46, 0)

@mapcentia
Copy link
Contributor Author

mapcentia commented Mar 24, 2024

@geographika Yes. I'll try to setup a build environment based on 20.04.

The matrix of conditionals around SVG size extraction has been refactored in mapcairo.c. With this change, the symbols' height and width are better handled depending on the presence of width and height attributes, their units, and the viewBox. The conditions now account for newest LIBRSVG versions and fallback for older ones.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants