Ensure SVGs are scaled correctly when viewbox is provided (#8872)

* Ensure SVGs with hard coded width and height as well as viewbox values are scaled correctly.

* Fix misspelling
This commit is contained in:
Chris Davis 2021-01-04 06:59:53 -08:00 committed by GitHub
parent 197af8853f
commit d82c083076
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -119,6 +119,21 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Svg
var svg = browser.Document.GetElementsByTagName("svg").Cast<HtmlElement>().FirstOrDefault();
if (svg != null)
{
var viewBox = svg.GetAttribute("viewbox");
if (viewBox != null)
{
// Update the svg style to override any width or height explicit settings
// Setting to 100% width and height will allow to scale to our intended size
// Otherwise, we would end up with a scaled up blurry image.
svg.Style = "width:100%;height:100%";
// Wait for the browser to render the content.
while (browser.IsBusy || browser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
}
// Update the size of the browser control to fit the SVG
// in the visible viewport.
browser.Width = svg.OffsetRectangle.Width;