Commit 027bfcc9 authored by Vadim's avatar Vadim Committed by mrbean-bremen
Browse files

Repair calculating a percentage value (#410)

* Repair calculate a percentage value
* Add percentage size tests
parent 4d4acd6e
...@@ -93,11 +93,12 @@ namespace Svg ...@@ -93,11 +93,12 @@ namespace Svg
} }
var center = SvgUnit.GetDevicePoint(this._centerX, this._centerY, renderer, this); var center = SvgUnit.GetDevicePoint(this._centerX, this._centerY, renderer, this);
var radius = SvgUnit.GetDevicePoint(this._radiusX + halfStrokeWidth, this._radiusY + halfStrokeWidth, renderer, this); var radiusX = this.RadiusX.ToDeviceValue(renderer, UnitRenderingType.Other, this) + halfStrokeWidth;
var radiusY = this.RadiusY.ToDeviceValue(renderer, UnitRenderingType.Other, this) + halfStrokeWidth;
this._path = new GraphicsPath(); this._path = new GraphicsPath();
_path.StartFigure(); _path.StartFigure();
_path.AddEllipse(center.X - radius.X, center.Y - radius.Y, 2 * radius.X, 2 * radius.Y); _path.AddEllipse(center.X - radiusX, center.Y - radiusY, 2 * radiusX, 2 * radiusY);
_path.CloseFigure(); _path.CloseFigure();
} }
return _path; return _path;
......
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Svg.UnitTests
{
[TestClass]
public class PercentageSizeTests
{
[TestMethod]
public void TestRectangle()
{
var svgRectangle = new SvgRectangle()
{
X = new SvgUnit(SvgUnitType.Percentage, 50),
Y = new SvgUnit(SvgUnitType.Percentage, 50),
Width = new SvgUnit(SvgUnitType.Percentage, 15),
Height = new SvgUnit(SvgUnitType.Percentage, 20)
};
CheckPercentageSize(svgRectangle);
}
[TestMethod]
public void TestCircle()
{
var svgCircle = new SvgCircle()
{
CenterX = new SvgUnit(SvgUnitType.Percentage, 50),
CenterY = new SvgUnit(SvgUnitType.Percentage, 50),
Radius = new SvgUnit(SvgUnitType.Percentage, 15),
};
CheckPercentageSize(svgCircle);
}
[TestMethod]
public void TestEllipse()
{
var svgEllipse = new SvgEllipse()
{
CenterX = new SvgUnit(SvgUnitType.Percentage, 50),
CenterY = new SvgUnit(SvgUnitType.Percentage, 50),
RadiusX = new SvgUnit(SvgUnitType.Percentage, 15),
RadiusY = new SvgUnit(SvgUnitType.Percentage, 5),
};
CheckPercentageSize(svgEllipse);
}
private void CheckPercentageSize(SvgVisualElement element)
{
var svgDoc = new SvgDocument()
{
Width = 200,
Height = 200
};
svgDoc.Children.Add(element);
var boudsPref = element.Bounds;
svgDoc.Width = 400;
svgDoc.Height = 400;
var boundsAfter = element.Bounds;
Assert.AreNotEqual(boudsPref.Size, boundsAfter.Size, "To device value convert error");
}
}
}
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
<Compile Include="SvgTextTests.cs" /> <Compile Include="SvgTextTests.cs" />
<Compile Include="SvgTextElementDeepCopyTest.cs" /> <Compile Include="SvgTextElementDeepCopyTest.cs" />
<Compile Include="ImageComparisonTest.cs" /> <Compile Include="ImageComparisonTest.cs" />
<Compile Include="PercentageSizeTests.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Source\Svg.csproj"> <ProjectReference Include="..\..\Source\Svg.csproj">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment