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

How to scale SVGs without preserving the aspect ratio #44

Open
JoshuaNovak919 opened this issue Mar 18, 2016 · 4 comments
Open

How to scale SVGs without preserving the aspect ratio #44

JoshuaNovak919 opened this issue Mar 18, 2016 · 4 comments

Comments

@JoshuaNovak919
Copy link

Is there a way to get the SVGs to scale properly to the set Width and Height without preserving the aspect ratio? I tried setting preserveAspectRatio="none" and a few other settings and nothing worked. I'm testing it on Android btw.

@patridge
Copy link
Collaborator

That definitely needs to be available, but is a use-case I hadn't worked out in my initial code to get the 9-slice rendering working. Thank you for creating an issue about it. Let me see what I can do to get that working properly.

Just to confirm, you're asking if you can simply stretch an SVG to whatever container size it is in, right? If you have an SVG originally sized at 50x50 and you put it in a 150x200 container, without any 9-slice rendering, it just stretches the original SVG to 150x200.

@JoshuaNovak919
Copy link
Author

Awesome! Sounds great. Yep, that's exactly right, it would stretch the SVG to fill the container. I believe it has something to do with the section that says proportionalOutputScale since that seems to make sure it's proportional. If we either have the SVG read and respect the preserveAspectRatio option or even just add a property for stretching, it should work.

@JoshuaNovak919
Copy link
Author

@patridge I took a swing at this, but I couldn't figure out exactly where this would even be set since i'm not all that familiar with the code.

@patridge
Copy link
Collaborator

Sorry for my total lack of communication here. I started something up and kept hitting snags without sharing my progress. I know most of the code, so I'm not sure what my excuse is for my failing solution to the various aspect settings.

I went with using the Xamarin.Forms.Aspect enum:

  • AspectFit: proportionally scaled and smaller by "letterboxing" (default)
  • AspectFill: proportionally scaled and larger by "cropping"
  • Fill: just stretched to fit the available space

I have everything appearing to work successfully in a demo for the NControl.SvgImageView version, though that might just be because I don't have enough test cases. Unfortunately, with the original SvgImage version, a number of aspect options aren't rendering correctly (despite being mostly the same code these days).

Let me get together what I can for other eyes to look over, and maybe we can nail down a more bulletproof (or at least mildly bullet resistant) solution.

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

No branches or pull requests

2 participants