use doubles where calculations are being run

This commit is contained in:
Eliot Jones
2019-12-21 18:09:49 +00:00
parent e984180b3d
commit 935d182888
101 changed files with 825 additions and 802 deletions

View File

@@ -3,21 +3,21 @@ using System.Collections.Generic;
namespace UglyToad.PdfPig.Tests
{
internal class DecimalComparer : IEqualityComparer<decimal>
internal class DoubleComparer : IEqualityComparer<double>
{
private readonly decimal precision;
private readonly double precision;
public DecimalComparer(decimal precision)
public DoubleComparer(double precision)
{
this.precision = precision;
}
public bool Equals(decimal x, decimal y)
public bool Equals(double x, double y)
{
return Math.Abs(x - y) < precision;
}
public int GetHashCode(decimal obj)
public int GetHashCode(double obj)
{
return obj.GetHashCode();
}

View File

@@ -30,16 +30,16 @@
var data = new VerticalWritingMetrics(defaults, null, null);
var position = data.GetPositionVector(9, 120);
Assert.Equal(120 / 2m, position.X);
Assert.Equal(120 / 2d, position.X);
var displacement = data.GetDisplacementVector(10);
Assert.Equal(0m, displacement.X);
Assert.Equal(0d, displacement.X);
}
[Fact]
public void UsesVectorOverridesWhenPresent()
{
var data = new VerticalWritingMetrics(defaults, new Dictionary<int, decimal> {{7, 120}},
var data = new VerticalWritingMetrics(defaults, new Dictionary<int, double> {{7, 120}},
new Dictionary<int, PdfVector> {{7, new PdfVector(25, 250)}});
var position = data.GetPositionVector(7, 360);

View File

@@ -202,8 +202,8 @@
{
var match = regex.Match(lines[i]);
var width = decimal.Parse(match.Groups["width"].Value, CultureInfo.InvariantCulture);
var height = decimal.Parse(match.Groups["height"].Value, CultureInfo.InvariantCulture);
var width = double.Parse(match.Groups["width"].Value, CultureInfo.InvariantCulture);
var height = double.Parse(match.Groups["height"].Value, CultureInfo.InvariantCulture);
var points = int.Parse(match.Groups["points"].Value, CultureInfo.InvariantCulture);
var glyph = font.TableRegister.GlyphTable.Glyphs[i];

View File

@@ -21,50 +21,50 @@ namespace UglyToad.PdfPig.Tests.Geometry
public void Length()
{
var line = new PdfLine(2, 1, 6, 4);
Assert.Equal(5m, line.Length);
Assert.Equal(5d, line.Length);
var line2 = new PdfLine(-2, 8, -7, -5);
Assert.Equal(13.93m, Math.Round(line2.Length, 2));
Assert.Equal(13.93d, Math.Round(line2.Length, 2));
}
[Fact]
public void Contains()
{
var line = new PdfLine(10, 7.5m, 26.3m, 12);
var line = new PdfLine(10, 7.5d, 26.3d, 12);
Assert.False(line.Contains(new PdfPoint(5, 2)));
Assert.False(line.Contains(new PdfPoint(5, 6.11963190184049m)));
Assert.False(line.Contains(new PdfPoint(27, 12.1932515337423m)));
Assert.False(line.Contains(new PdfPoint(5, 6.11963190184049d)));
Assert.False(line.Contains(new PdfPoint(27, 12.1932515337423d)));
Assert.False(line.Contains(new PdfPoint(12, 15)));
Assert.False(line.Contains(new PdfPoint(10, 12)));
Assert.True(line.Contains(new PdfPoint(20, 10.260736196319m)));
Assert.True(line.Contains(new PdfPoint(10, 7.5m)));
Assert.True(line.Contains(new PdfPoint(20, 10.260736196319d)));
Assert.True(line.Contains(new PdfPoint(10, 7.5d)));
var verticalLine = new PdfLine(10, 7.5m, 10, 15);
var verticalLine = new PdfLine(10, 7.5d, 10, 15);
Assert.False(verticalLine.Contains(new PdfPoint(5, 2)));
Assert.False(verticalLine.Contains(new PdfPoint(12, 15)));
Assert.False(verticalLine.Contains(new PdfPoint(10, 16)));
Assert.False(verticalLine.Contains(new PdfPoint(10, 7)));
Assert.True(verticalLine.Contains(new PdfPoint(10, 12)));
Assert.True(verticalLine.Contains(new PdfPoint(10, 7.5m)));
Assert.True(verticalLine.Contains(new PdfPoint(10, 7.5d)));
var horizontalLine = new PdfLine(10, 7.5m, 26.3m, 7.5m);
var horizontalLine = new PdfLine(10, 7.5d, 26.3d, 7.5d);
Assert.False(horizontalLine.Contains(new PdfPoint(5, 2)));
Assert.False(horizontalLine.Contains(new PdfPoint(5, 7.5)));
Assert.False(horizontalLine.Contains(new PdfPoint(27, 7.5)));
Assert.False(horizontalLine.Contains(new PdfPoint(10, 12)));
Assert.True(horizontalLine.Contains(new PdfPoint(20, 7.5)));
Assert.True(horizontalLine.Contains(new PdfPoint(26.3m, 7.5m)));
Assert.True(horizontalLine.Contains(new PdfPoint(26.3d, 7.5d)));
}
[Fact]
public void ParallelTo()
{
var verticalLine1 = new PdfLine(10, 7.5m, 10, 15);
var verticalLine2 = new PdfLine(200, 0, 200, 551.5467m);
var horizontalLine1 = new PdfLine(10, 7.5m, 26.3m, 7.5m);
var horizontalLine2 = new PdfLine(27, 57, 200.9999872m, 57);
var obliqueLine1 = new PdfLine(10, 7.5m, 26.3m, 12);
var obliqueLine2 = new PdfLine(60, 28.8036809815951m, 40, 23.2822085889571m);
var verticalLine1 = new PdfLine(10, 7.5d, 10, 15);
var verticalLine2 = new PdfLine(200, 0, 200, 551.5467d);
var horizontalLine1 = new PdfLine(10, 7.5d, 26.3d, 7.5d);
var horizontalLine2 = new PdfLine(27, 57, 200.9999872d, 57);
var obliqueLine1 = new PdfLine(10, 7.5d, 26.3d, 12);
var obliqueLine2 = new PdfLine(60, 28.8036809815951d, 40, 23.2822085889571d);
Assert.True(verticalLine1.ParallelTo(verticalLine2));
Assert.True(verticalLine2.ParallelTo(verticalLine1));
@@ -93,81 +93,5 @@ namespace UglyToad.PdfPig.Tests.Geometry
Assert.True(obliqueLine1.ParallelTo(obliqueLine2));
Assert.True(obliqueLine2.ParallelTo(obliqueLine1));
}
[Fact]
public void IntersectsWithLine()
{
var verticalLine1 = new PdfLine(10, 7.5m, 10, 15);
var verticalLine2 = new PdfLine(200, 0, 200, 551.5467m);
var horizontalLine1 = new PdfLine(10, 7.5m, 26.3m, 7.5m);
var horizontalLine2 = new PdfLine(27, 57, 200.9999872m, 57);
var horizontalLine3 = new PdfLine(27, 57, 250, 57);
var obliqueLine1 = new PdfLine(10, 7.5m, 26.3m, 12);
var obliqueLine2 = new PdfLine(60, 28.8036809815951m, 40, 23.2822085889571m);
var obliqueLine3 = new PdfLine(20, 7.5m, 10, 15);
Assert.False(verticalLine1.IntersectsWith(verticalLine2));
Assert.False(verticalLine2.IntersectsWith(verticalLine1));
Assert.False(horizontalLine1.IntersectsWith(horizontalLine2));
Assert.False(horizontalLine2.IntersectsWith(horizontalLine1));
Assert.False(obliqueLine1.IntersectsWith(obliqueLine2));
Assert.False(obliqueLine2.IntersectsWith(obliqueLine1));
Assert.False(obliqueLine1.IntersectsWith(obliqueLine1));
Assert.False(obliqueLine1.IntersectsWith(verticalLine2));
Assert.False(verticalLine2.IntersectsWith(obliqueLine1));
Assert.False(obliqueLine1.IntersectsWith(horizontalLine2));
Assert.False(horizontalLine2.IntersectsWith(obliqueLine1));
Assert.False(verticalLine1.IntersectsWith(horizontalLine2));
Assert.False(horizontalLine2.IntersectsWith(verticalLine1));
Assert.True(obliqueLine1.IntersectsWith(horizontalLine1));
Assert.True(horizontalLine1.IntersectsWith(obliqueLine1));
Assert.True(obliqueLine1.IntersectsWith(verticalLine1));
Assert.True(verticalLine1.IntersectsWith(obliqueLine1));
Assert.True(verticalLine2.IntersectsWith(horizontalLine2));
Assert.True(horizontalLine2.IntersectsWith(verticalLine2));
Assert.True(verticalLine2.IntersectsWith(horizontalLine3));
Assert.True(horizontalLine3.IntersectsWith(verticalLine2));
Assert.True(obliqueLine1.IntersectsWith(obliqueLine3));
Assert.True(obliqueLine3.IntersectsWith(obliqueLine1));
}
[Fact]
public void IntersectLine()
{
var verticalLine1 = new PdfLine(10, 7.5m, 10, 15);
var verticalLine2 = new PdfLine(200, 0, 200, 551.5467m);
var horizontalLine1 = new PdfLine(10, 7.5m, 26.3m, 7.5m);
var horizontalLine2 = new PdfLine(27, 57, 200.9999872m, 57);
var horizontalLine3 = new PdfLine(27, 57, 250, 57);
var obliqueLine1 = new PdfLine(10, 7.5m, 26.3m, 12);
var obliqueLine2 = new PdfLine(60, 28.8036809815951m, 40, 23.2822085889571m);
var obliqueLine3 = new PdfLine(20, 7.5m, 10, 15);
Assert.Null(verticalLine1.Intersect(verticalLine2));
Assert.Null(verticalLine2.Intersect(verticalLine1));
Assert.Null(horizontalLine1.Intersect(horizontalLine2));
Assert.Null(horizontalLine2.Intersect(horizontalLine1));
Assert.Null(obliqueLine1.Intersect(obliqueLine2));
Assert.Null(obliqueLine2.Intersect(obliqueLine1));
Assert.Null(obliqueLine1.Intersect(obliqueLine1));
Assert.Null(obliqueLine1.Intersect(verticalLine2));
Assert.Null(verticalLine2.Intersect(obliqueLine1));
Assert.Null(obliqueLine1.Intersect(horizontalLine2));
Assert.Null(horizontalLine2.Intersect(obliqueLine1));
Assert.Null(verticalLine1.Intersect(horizontalLine2));
Assert.Null(horizontalLine2.Intersect(verticalLine1));
Assert.Equal(new PdfPoint(10, 7.5m), obliqueLine1.Intersect(horizontalLine1));
Assert.Equal(new PdfPoint(10, 7.5m), horizontalLine1.Intersect(obliqueLine1));
Assert.Equal(new PdfPoint(10, 7.5m), obliqueLine1.Intersect(verticalLine1));
Assert.Equal(new PdfPoint(10, 7.5m), verticalLine1.Intersect(obliqueLine1));
Assert.Equal(new PdfPoint(200, 57), verticalLine2.Intersect(horizontalLine2));
Assert.Equal(new PdfPoint(200, 57), horizontalLine2.Intersect(verticalLine2));
Assert.Equal(new PdfPoint(200, 57), verticalLine2.Intersect(horizontalLine3));
Assert.Equal(new PdfPoint(200, 57), horizontalLine3.Intersect(verticalLine2));
Assert.Equal(new PdfPoint(17.3094170403587m, 9.51793721973094m), obliqueLine1.Intersect(obliqueLine3));
Assert.Equal(new PdfPoint(17.3094170403587m, 9.51793721973094m), obliqueLine3.Intersect(obliqueLine1));
}
}
}

View File

@@ -28,8 +28,8 @@
{
var origin = new PdfPoint(0.534436, 0.32552);
Assert.Equal(0.534436m, origin.X);
Assert.Equal(0.32552m, origin.Y);
Assert.Equal(0.534436, origin.X);
Assert.Equal(0.32552, origin.Y);
}
}
}

View File

@@ -8,10 +8,10 @@ namespace UglyToad.PdfPig.Tests.Geometry
public void Area()
{
PdfRectangle rectangle = new PdfRectangle(10, 10, 20, 20);
Assert.Equal(100m, rectangle.Area);
Assert.Equal(100d, rectangle.Area);
PdfRectangle rectangle1 = new PdfRectangle(149.95376m, 687.13456m, 451.73539m, 1478.4997m);
Assert.Equal(238819.4618743782m, rectangle1.Area);
PdfRectangle rectangle1 = new PdfRectangle(149.95376d, 687.13456d, 451.73539d, 1478.4997d);
Assert.Equal(238819.4618743782d, rectangle1.Area);
}
public void Centroid()
@@ -19,19 +19,19 @@ namespace UglyToad.PdfPig.Tests.Geometry
PdfRectangle rectangle = new PdfRectangle(10, 10, 20, 20);
Assert.Equal(new PdfPoint(15, 15), rectangle.Centroid);
PdfRectangle rectangle1 = new PdfRectangle(149.95376m, 687.13456m, 451.73539m, 1478.4997m);
Assert.Equal(new PdfPoint(300.844575m, 1082.81713m), rectangle1.Centroid);
PdfRectangle rectangle1 = new PdfRectangle(149.95376d, 687.13456d, 451.73539d, 1478.4997d);
Assert.Equal(new PdfPoint(300.844575d, 1082.81713d), rectangle1.Centroid);
}
public void Intersect()
{
PdfRectangle rectangle = new PdfRectangle(10, 10, 20, 20);
PdfRectangle rectangle1 = new PdfRectangle(149.95376m, 687.13456m, 451.73539m, 1478.4997m);
PdfRectangle rectangle1 = new PdfRectangle(149.95376d, 687.13456d, 451.73539d, 1478.4997d);
Assert.Null(rectangle.Intersect(rectangle1));
Assert.Equal(rectangle1, rectangle1.Intersect(rectangle1));
PdfRectangle rectangle2 = new PdfRectangle(50, 687.13456m, 350, 1478.4997m);
Assert.Equal(new PdfRectangle(149.95376m, 687.13456m, 350, 1478.4997m), rectangle1.Intersect(rectangle2));
PdfRectangle rectangle2 = new PdfRectangle(50, 687.13456d, 350, 1478.4997d);
Assert.Equal(new PdfRectangle(149.95376d, 687.13456d, 350, 1478.4997d), rectangle1.Intersect(rectangle2));
PdfRectangle rectangle3 = new PdfRectangle(200, 800, 350, 1200);
Assert.Equal(rectangle3, rectangle1.Intersect(rectangle3));
@@ -40,11 +40,11 @@ namespace UglyToad.PdfPig.Tests.Geometry
public void IntersectsWith()
{
PdfRectangle rectangle = new PdfRectangle(10, 10, 20, 20);
PdfRectangle rectangle1 = new PdfRectangle(149.95376m, 687.13456m, 451.73539m, 1478.4997m);
PdfRectangle rectangle1 = new PdfRectangle(149.95376d, 687.13456d, 451.73539d, 1478.4997d);
Assert.False(rectangle.IntersectsWith(rectangle1));
Assert.True(rectangle1.IntersectsWith(rectangle1));
PdfRectangle rectangle2 = new PdfRectangle(50, 687.13456m, 350, 1478.4997m);
PdfRectangle rectangle2 = new PdfRectangle(50, 687.13456d, 350, 1478.4997d);
Assert.True(rectangle1.IntersectsWith(rectangle2));
PdfRectangle rectangle3 = new PdfRectangle(200, 800, 350, 1200);

View File

@@ -8,24 +8,24 @@
[Fact]
public void ConstructorSetsValues()
{
var vector = new PdfVector(5.2m, 6.9m);
var vector = new PdfVector(5.2d, 6.9d);
Assert.Equal(5.2m, vector.X);
Assert.Equal(6.9m, vector.Y);
Assert.Equal(5.2d, vector.X);
Assert.Equal(6.9d, vector.Y);
}
[Fact]
public void ScaleMultipliesLeavesOriginalUnchanged()
{
var vector = new PdfVector(5.2m, 6.9m);
var vector = new PdfVector(5.2d, 6.9d);
var scaled = vector.Scale(0.7m);
var scaled = vector.Scale(0.7d);
Assert.Equal(5.2m, vector.X);
Assert.Equal(5.2m * 0.7m, scaled.X);
Assert.Equal(5.2d, vector.X);
Assert.Equal(5.2d * 0.7d, scaled.X);
Assert.Equal(6.9m, vector.Y);
Assert.Equal(6.9m * 0.7m, scaled.Y);
Assert.Equal(6.9d, vector.Y);
Assert.Equal(6.9d * 0.7d, scaled.Y);
}
}
}

View File

@@ -62,7 +62,7 @@
var state = context.GetCurrentState();
Assert.Equal(69.42m, state.FontState.FontSize);
Assert.Equal(69.42, state.FontState.FontSize);
Assert.Equal(Font1Name, state.FontState.FontName);
}
}

View File

@@ -7,19 +7,19 @@
public class AssertablePositionData
{
public decimal X { get; set; }
public double X { get; set; }
public decimal Y { get; set; }
public double Y { get; set; }
public decimal Width { get; set; }
public double Width { get; set; }
public string Text { get; set; }
public decimal FontSize { get; set; }
public double FontSize { get; set; }
public string FontName { get; set; }
public decimal Height { get; set; }
public double Height { get; set; }
public static AssertablePositionData Parse(string line)
{
@@ -30,15 +30,15 @@
throw new ArgumentException($"Expected 6 parts to the line, instead got {parts.Length}");
}
var height = parts.Length < 7 ? 0 : decimal.Parse(parts[6], CultureInfo.InvariantCulture);
var height = parts.Length < 7 ? 0 : double.Parse(parts[6], CultureInfo.InvariantCulture);
return new AssertablePositionData
{
X = decimal.Parse(parts[0], CultureInfo.InvariantCulture),
Y = decimal.Parse(parts[1], CultureInfo.InvariantCulture),
Width = decimal.Parse(parts[2], CultureInfo.InvariantCulture),
X = double.Parse(parts[0], CultureInfo.InvariantCulture),
Y = double.Parse(parts[1], CultureInfo.InvariantCulture),
Width = double.Parse(parts[2], CultureInfo.InvariantCulture),
Text = parts[3],
FontSize = decimal.Parse(parts[4], CultureInfo.InvariantCulture),
FontSize = double.Parse(parts[4], CultureInfo.InvariantCulture),
FontName = parts[5],
Height = height
};

View File

@@ -63,7 +63,7 @@
{
var stripped = x.Trim();
var parts = stripped.Split('|');
return (index: int.Parse(parts[0]), letter: parts[1], x: decimal.Parse(parts[2]), y: decimal.Parse(parts[3]));
return (index: int.Parse(parts[0]), letter: parts[1], x: double.Parse(parts[2]), y: double.Parse(parts[3]));
}).ToArray();
using (var document = PdfDocument.Open(GetFilename()))
@@ -75,8 +75,8 @@
var letter = page.Letters[expected.index];
Assert.Equal(expected.letter, letter.Value);
Assert.Equal(expected.x, decimal.Round(letter.Location.X, 2));
Assert.Equal(expected.y, decimal.Round(letter.Location.Y, 2));
Assert.Equal(expected.x, Math.Round(letter.Location.X, 2));
Assert.Equal(expected.y, Math.Round(letter.Location.Y, 2));
}
}
}

View File

@@ -24,6 +24,8 @@
[Fact]
public void ImagesHaveCorrectDimensionsAndLocations()
{
var doubleComparer = new DoubleComparer(1);
using (var document = PdfDocument.Open(GetFilePath(), ParsingOptions.LenientParsingOff))
{
var page = document.GetPage(1);
@@ -32,24 +34,25 @@
var pdfPigSquare = images[0];
Assert.Equal(148.3m, pdfPigSquare.Bounds.Width);
Assert.Equal(148.3m, pdfPigSquare.Bounds.Height);
Assert.Equal(60.1m, pdfPigSquare.Bounds.Left);
Assert.Equal(765.8m, pdfPigSquare.Bounds.Top);
Assert.Equal(148.3d, pdfPigSquare.Bounds.Width, doubleComparer);
Assert.Equal(148.3d, pdfPigSquare.Bounds.Height, doubleComparer);
Assert.Equal(60.1d, pdfPigSquare.Bounds.Left, doubleComparer);
Assert.Equal(765.8d, pdfPigSquare.Bounds.Top, doubleComparer);
var pdfPigSquished = images[1];
Assert.Equal(206.8m, pdfPigSquished.Bounds.Width);
Assert.Equal(83.2m, pdfPigSquished.Bounds.Height);
Assert.Equal(309.8m, pdfPigSquished.Bounds.Left);
Assert.Equal(552.1m, pdfPigSquished.Bounds.Top);
Assert.Equal(206.8d, pdfPigSquished.Bounds.Width, doubleComparer);
Assert.Equal(83.2d, pdfPigSquished.Bounds.Height, doubleComparer);
Assert.Equal(309.8d, pdfPigSquished.Bounds.Left, doubleComparer);
Assert.Equal(552.1d, pdfPigSquished.Bounds.Top, doubleComparer);
var birthdayPigs = images[2];
Assert.Equal(391m, birthdayPigs.Bounds.Width);
Assert.Equal(267.1m, birthdayPigs.Bounds.Height);
Assert.Equal(102.2m, birthdayPigs.Bounds.Left);
Assert.Equal(426.3m, birthdayPigs.Bounds.Top);
Assert.Equal(391d, birthdayPigs.Bounds.Width, doubleComparer);
Assert.Equal(267.1d, birthdayPigs.Bounds.Height, doubleComparer);
Assert.Equal(102.2d, birthdayPigs.Bounds.Left, doubleComparer);
Assert.Equal(426.3d, birthdayPigs.Bounds.Top, doubleComparer);
}
}

View File

@@ -79,7 +79,7 @@
continue;
}
var comparer = new DecimalComparer(3m);
var comparer = new DoubleComparer(3);
Assert.Equal(theirLetter, myLetter);
@@ -95,7 +95,7 @@
[Fact]
public void LetterPositionsAreCorrectXfinium()
{
var comparer = new DecimalComparer(1);
var comparer = new DoubleComparer(1);
using (var document = PdfDocument.Open(GetFilename()))
{

View File

@@ -183,7 +183,7 @@ namespace UglyToad.PdfPig.Tests.Integration
Assert.Equal(datum.Y, transformed, 2);
// Until we get width from glyphs we're a bit out.
Assert.True(Math.Abs(datum.Width - letter.Width) < 0.03m);
Assert.True(Math.Abs(datum.Width - letter.Width) < 0.03);
index++;
}

View File

@@ -41,31 +41,31 @@
{
var page = document.GetPage(1);
var comparer = new DecimalComparer(3m);
var comparer = new DoubleComparer(3d);
Assert.Equal("I", page.Letters[0].Value);
Assert.Equal(90.1m, page.Letters[0].GlyphRectangle.BottomLeft.X, comparer);
Assert.Equal(709.2m, page.Letters[0].GlyphRectangle.BottomLeft.Y, comparer);
Assert.Equal(90.1d, page.Letters[0].GlyphRectangle.BottomLeft.X, comparer);
Assert.Equal(709.2d, page.Letters[0].GlyphRectangle.BottomLeft.Y, comparer);
Assert.Equal(94.0m, page.Letters[0].GlyphRectangle.TopRight.X, comparer);
Assert.Equal(719.89m, page.Letters[0].GlyphRectangle.TopRight.Y, comparer);
Assert.Equal(94.0d, page.Letters[0].GlyphRectangle.TopRight.X, comparer);
Assert.Equal(719.89d, page.Letters[0].GlyphRectangle.TopRight.Y, comparer);
Assert.Equal("a", page.Letters[5].Value);
Assert.Equal(114.5m, page.Letters[5].GlyphRectangle.BottomLeft.X, comparer);
Assert.Equal(709.2m, page.Letters[5].GlyphRectangle.BottomLeft.Y, comparer);
Assert.Equal(114.5d, page.Letters[5].GlyphRectangle.BottomLeft.X, comparer);
Assert.Equal(709.2d, page.Letters[5].GlyphRectangle.BottomLeft.Y, comparer);
Assert.Equal(119.82m, page.Letters[5].GlyphRectangle.TopRight.X, comparer);
Assert.Equal(714.89m, page.Letters[5].GlyphRectangle.TopRight.Y, comparer);
Assert.Equal(119.82d, page.Letters[5].GlyphRectangle.TopRight.X, comparer);
Assert.Equal(714.89d, page.Letters[5].GlyphRectangle.TopRight.Y, comparer);
Assert.Equal("f", page.Letters[16].Value);
Assert.Equal(169.9m, page.Letters[16].GlyphRectangle.BottomLeft.X, comparer);
Assert.Equal(709.2m, page.Letters[16].GlyphRectangle.BottomLeft.Y, comparer);
Assert.Equal(169.9d, page.Letters[16].GlyphRectangle.BottomLeft.X, comparer);
Assert.Equal(709.2d, page.Letters[16].GlyphRectangle.BottomLeft.Y, comparer);
Assert.Equal(176.89m, page.Letters[16].GlyphRectangle.TopRight.X, comparer);
Assert.Equal(719.89m, page.Letters[16].GlyphRectangle.TopRight.Y, comparer);
Assert.Equal(176.89d, page.Letters[16].GlyphRectangle.TopRight.X, comparer);
Assert.Equal(719.89d, page.Letters[16].GlyphRectangle.TopRight.Y, comparer);
}
}

View File

@@ -250,10 +250,10 @@
page1.AddText("incididunt ut labore et dolore magna aliqua.", 9, new PdfPoint(30, topLine.Y - letters.Max(x => x.GlyphRectangle.Height) - 5), font);
var page2Letters = page2.AddText("The very hungry caterpillar ate all the apples in the garden.", 12, topLine, font);
var left = page2Letters[0].GlyphRectangle.Left;
var bottom = page2Letters.Min(x => x.GlyphRectangle.Bottom);
var right = page2Letters[page2Letters.Count - 1].GlyphRectangle.Right;
var top = page2Letters.Max(x => x.GlyphRectangle.Top);
var left = (decimal)page2Letters[0].GlyphRectangle.Left;
var bottom = (decimal)page2Letters.Min(x => x.GlyphRectangle.Bottom);
var right = (decimal)page2Letters[page2Letters.Count - 1].GlyphRectangle.Right;
var top = (decimal)page2Letters.Max(x => x.GlyphRectangle.Top);
page2.SetStrokeColor(10, 250, 69);
page2.DrawRectangle(new PdfPoint(left, bottom), right - left, top - bottom);