Skip to content

Commit

Permalink
Fix: svg-net#917 'SVG to PNG renders inline images incorrectly' issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
H1Gdev committed Oct 30, 2021
1 parent 467d710 commit 5789c82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions Source/Document Structure/SvgFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected override void Render(ISvgRenderer renderer)
var prevClip = renderer.GetClip();
try
{
var size = Parent == null ? renderer.GetBoundable().Bounds.Size : GetDimensions();
var size = this is SvgDocument ? renderer.GetBoundable().Bounds.Size : GetDimensions(renderer);
var clip = new RectangleF(X.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this),
Y.ToDeviceValue(renderer, UnitRenderingType.Vertical, this),
size.Width, size.Height);
Expand Down Expand Up @@ -250,6 +250,11 @@ public RectangleF Bounds
}

public SizeF GetDimensions()
{
return GetDimensions(null);
}

public SizeF GetDimensions(ISvgRenderer renderer)
{
float w, h;
var isWidthperc = Width.Type == SvgUnitType.Percentage;
Expand All @@ -268,21 +273,21 @@ public SizeF GetDimensions()
}
}

if (isWidthperc)
if (isWidthperc && this is SvgDocument)
{
w = (bounds.Width + bounds.X) * (Width.Value * 0.01f);
}
else
{
w = Width.ToDeviceValue(null, UnitRenderingType.Horizontal, this);
w = Width.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this);
}
if (isHeightperc)
if (isHeightperc && this is SvgDocument)
{
h = (bounds.Height + bounds.Y) * (Height.Value * 0.01f);
}
else
{
h = Height.ToDeviceValue(null, UnitRenderingType.Vertical, this);
h = Height.ToDeviceValue(renderer, UnitRenderingType.Vertical, this);
}

return new SizeF(w, h);
Expand Down
2 changes: 1 addition & 1 deletion Source/Document Structure/SvgImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected override void Render(ISvgRenderer renderer)
if (bmp != null)
srcRect = new RectangleF(0f, 0f, bmp.Width, bmp.Height);
else
srcRect = new RectangleF(new PointF(0f, 0f), svg.GetDimensions());
srcRect = new RectangleF(new PointF(0f, 0f), svg.GetDimensions(renderer));

var destClip = new RectangleF(Location.ToDeviceValue(renderer, this),
new SizeF(Width.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this),
Expand Down

0 comments on commit 5789c82

Please sign in to comment.