From 5789c828f9a9a59cbf925662fd45b7b68ea8ec69 Mon Sep 17 00:00:00 2001 From: H1Gdev Date: Sat, 30 Oct 2021 19:35:52 +0900 Subject: [PATCH] Fix: #917 'SVG to PNG renders inline images incorrectly' issue. --- Source/Document Structure/SvgFragment.cs | 15 ++++++++++----- Source/Document Structure/SvgImage.cs | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Source/Document Structure/SvgFragment.cs b/Source/Document Structure/SvgFragment.cs index 7f59cf8f3..b8a9185fd 100644 --- a/Source/Document Structure/SvgFragment.cs +++ b/Source/Document Structure/SvgFragment.cs @@ -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); @@ -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; @@ -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); diff --git a/Source/Document Structure/SvgImage.cs b/Source/Document Structure/SvgImage.cs index 2f56471db..1eb0929af 100644 --- a/Source/Document Structure/SvgImage.cs +++ b/Source/Document Structure/SvgImage.cs @@ -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),