mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
[File Explorer Add-ons] Add viewBox attribute to svgs that don't have one (#18434)
This alows svg previewer to show full svg, not just a part of it
This commit is contained in:
@@ -84,6 +84,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg.Utilities
|
|||||||
string widthR = string.Empty;
|
string widthR = string.Empty;
|
||||||
string heightR = string.Empty;
|
string heightR = string.Empty;
|
||||||
string oldStyle = string.Empty;
|
string oldStyle = string.Empty;
|
||||||
|
bool hasViewBox = false;
|
||||||
|
|
||||||
// Get width and height of element and remove it afterwards because it will be added inside style attribute
|
// Get width and height of element and remove it afterwards because it will be added inside style attribute
|
||||||
for (int i = 0; i < attributes.Count(); i++)
|
for (int i = 0; i < attributes.Count(); i++)
|
||||||
@@ -106,6 +107,10 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg.Utilities
|
|||||||
attributes.ElementAt(i).Remove();
|
attributes.ElementAt(i).Remove();
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
|
else if (attributes.ElementAt(i).Name == "viewBox")
|
||||||
|
{
|
||||||
|
hasViewBox = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
svgData.ReplaceAttributes(attributes);
|
svgData.ReplaceAttributes(attributes);
|
||||||
@@ -122,6 +127,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg.Utilities
|
|||||||
scaling += $" _height:expression(this.scrollHeight > {heightR} ? \" {height}\" : \"auto\"); _width:expression(this.scrollWidth > {widthR} ? \"{width}\" : \"auto\");";
|
scaling += $" _height:expression(this.scrollHeight > {heightR} ? \" {height}\" : \"auto\"); _width:expression(this.scrollWidth > {widthR} ? \"{width}\" : \"auto\");";
|
||||||
|
|
||||||
svgData.Add(new XAttribute("style", scaling + centering + oldStyle));
|
svgData.Add(new XAttribute("style", scaling + centering + oldStyle));
|
||||||
|
|
||||||
|
if (!hasViewBox)
|
||||||
|
{
|
||||||
|
// Fixes https://github.com/microsoft/PowerToys/issues/18107
|
||||||
|
string viewBox = $"0 0 {widthR} {heightR}";
|
||||||
|
svgData.Add(new XAttribute("viewBox", viewBox));
|
||||||
|
}
|
||||||
|
|
||||||
return svgData.ToString();
|
return svgData.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user