Skip to content

Commit

Permalink
Correct width/height calculation when viewBox is present
Browse files Browse the repository at this point in the history
May be connected to the third point in openfl#18
  • Loading branch information
Gulvan0 authored Mar 26, 2022
1 parent 5842f1c commit a228cf3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions format/svg/SVGData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,30 @@ class SVGData extends Group {
width = getFloatStyle ("width", svg, null, 0.0);
height = getFloatStyle ("height", svg, null, 0.0);

if (width == 0 && height == 0)
width = height = 400;
else if (width == 0)
if (width == 0)
width = height;
else if (height == 0)
height = width;

var viewBox = new Rectangle(0, 0, width, height);

if (svg.exists("viewBox")) {
var viewBox:Rectangle;

if (svg.exists("viewBox"))
{
var vbox = svg.get("viewBox");
var params = vbox.indexOf(",") != -1 ? vbox.split(",") : vbox.split(" ");
viewBox = new Rectangle( trimToFloat(params[0]), trimToFloat(params[1]), trimToFloat(params[2]), trimToFloat(params[3]) );


if (width == 0 && height == 0)
{
width = viewBox.width;
height = viewBox.height;
}
}
else
{
if (width == 0 && height == 0)
width = height = 400;
viewBox = new Rectangle(0, 0, width, height);
}

loadGroup(this, svg, new Matrix (1, 0, 0, 1, -viewBox.x, -viewBox.y), null);
Expand Down

0 comments on commit a228cf3

Please sign in to comment.