2018-11-17 07:32:18 +08:00
|
|
|
|
namespace UglyToad.PdfPig.Tests.Fonts
|
2018-11-15 06:22:51 +08:00
|
|
|
|
{
|
|
|
|
|
using System.Text;
|
2018-11-17 07:32:18 +08:00
|
|
|
|
using PdfPig.Fonts;
|
2018-11-15 06:22:51 +08:00
|
|
|
|
using PdfPig.Geometry;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
public class CharacterPathTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void BezierCurveGeneratesCorrectBoundingBox()
|
|
|
|
|
{
|
2018-12-12 08:09:15 +08:00
|
|
|
|
var curve = new PdfPath.BezierCurve(new PdfPoint(60, 105),
|
2018-11-15 06:22:51 +08:00
|
|
|
|
new PdfPoint(75, 30),
|
|
|
|
|
new PdfPoint(215, 115),
|
|
|
|
|
new PdfPoint(140, 160));
|
|
|
|
|
|
|
|
|
|
var result = curve.GetBoundingRectangle();
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
Assert.Equal(160, result.Value.Top);
|
|
|
|
|
// Extends beyond start but not as far as 1st control point.
|
|
|
|
|
Assert.True(result.Value.Bottom < 105 && result.Value.Bottom > 30);
|
|
|
|
|
// Extends beyond end but not as far as 2nd control point.
|
|
|
|
|
Assert.True(result.Value.Right > 140 && result.Value.Right < 215);
|
|
|
|
|
Assert.Equal(60, result.Value.Left);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void LoopBezierCurveGeneratesCorrectBoundingBox()
|
|
|
|
|
{
|
2018-12-12 08:09:15 +08:00
|
|
|
|
var curve = new PdfPath.BezierCurve(new PdfPoint(166, 142),
|
2018-11-15 06:22:51 +08:00
|
|
|
|
new PdfPoint(75, 30),
|
|
|
|
|
new PdfPoint(215, 115),
|
|
|
|
|
new PdfPoint(140, 160));
|
|
|
|
|
|
|
|
|
|
var result = curve.GetBoundingRectangle();
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
Assert.Equal(160, result.Value.Top);
|
|
|
|
|
// Extends beyond start but not as far as 1st control point.
|
|
|
|
|
Assert.True(result.Value.Bottom < 142 && result.Value.Bottom > 30);
|
|
|
|
|
Assert.Equal(166, result.Value.Right);
|
|
|
|
|
// Extends beyond end.
|
|
|
|
|
Assert.True(result.Value.Left < 140);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void BezierCurveAddsCorrectSvgCommand()
|
|
|
|
|
{
|
2018-12-12 08:09:15 +08:00
|
|
|
|
var curve = new PdfPath.BezierCurve(new PdfPoint(60, 105),
|
2018-11-15 06:22:51 +08:00
|
|
|
|
new PdfPoint(75, 30),
|
|
|
|
|
new PdfPoint(215, 115),
|
|
|
|
|
new PdfPoint(140, 160));
|
|
|
|
|
|
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
curve.WriteSvg(builder);
|
|
|
|
|
|
|
|
|
|
Assert.Equal("C 75 30, 215 115, 140 160 ", builder.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|