-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
SVG Images with viewbox in percent are not rendered #3
Comments
When outer svg element dimensions are given in percentages it is necessary to know the width and height of the enclosing area where SVG will be shown to get the actual dimensions of SVG by taking given percentages from that area. Currently, in case of percentages the SVG is not rendered at all which is kind of wrong. So, after fix, in order to get SVG rendered in case of percentage width or height then the requested width and height have to be specified (to be non-zero) to render() function. Will this solution work for you? |
I need to determine the dimensions and aspect ratio of a given SVG image. At first in the case of a viewbox I got nothing. |
Why do you need to render to find out resulting image dimensions? You can already now specify dimensions you want right a way, in this case the image will be stretched to requested dimensions. |
In some cases I just have the vertical or horizontal pixel dimension and want the aspect Ratio to be respected while drawing the image. |
Ok, in this case you need to set the width to your known value and height to 0 (or height to value and width to 0) then the resulting image will be of a correct size with correct aspect ratio, so you only need to draw the image once |
You can read the documentation here https://github.com/igagis/svgren/blob/master/src/svgren/render.hpp#L17 it is described there |
Ok, thats fine but wouldn't help with a viewbox right now!? |
The problem here is not in viewBox, but in percentages. Right now it won't work for percentages, but I'm working on that. |
I think I will implement my own method (copied from your source) to determine the initial size of the image respecting the viewbox. Than I will always pass svgren the width and height. |
Ok, I had another deeper thought about that. And it looks like nothing has to be done at all. For percentages problem one has to deal with it outside of the render() function, as you are currently doing. But it looks incorrect to me that you take the width and height from viewBox. Let's say you know the width of the area where you want to draw the SVG image, say it is 600 px.
|
I can avoid exporting a viewbox but it makes troubles if someone does by mistake. I can get the aspect ratio from the viewbox. I think this is what firefox does when it renderes the image. |
Ok, right, in https://www.w3.org/TR/SVGMobile12/coords.html#IntrinsicSizing I found rules for aspect ratio calculation, it should be taken from viewBox. I will implement that. But one of |
Thank you very much! I'm very happy with svgren! |
Fixed. New nuget package should be out in about 15 mins. |
libsvgren 0.4.1 is released |
I think you found a good solution for images with viewbos in percent. Thanks! |
if it works for you now, could you close the issue? |
Some SVG Images have a viewbox in percent and they don't get rendered at all. See attached example.
I have a simple solution for this:
In my opinion it would make sense to integrate this into the renderer method.
button-add-viewbox.zip
The text was updated successfully, but these errors were encountered: