Fix GetTextOrientation by cleanly checking if rotation is divisible by 90 and fix #913
Some checks failed
Build and test / build (push) Has been cancelled
Run Integration Tests / build (push) Has been cancelled

This commit is contained in:
BobLd
2024-10-07 06:17:00 +01:00
parent c46722fa26
commit a258090e1c
3 changed files with 32 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
namespace UglyToad.PdfPig.Tests.Integration
{
using Content;
public class GithubIssuesTests
{
[Fact]
@@ -22,5 +24,32 @@
Assert.StartsWith("Value cannot be null.", ex.Message);
}
}
[Fact]
public void Issue913()
{
var doc = IntegrationHelpers.GetSpecificTestDocumentPath("Rotation 45.pdf");
using (var document = PdfDocument.Open(doc))
{
var page1 = document.GetPage(1);
for (int l = 131; l <= 137; ++l)
{
var letter = page1.Letters[l];
Assert.Equal(TextOrientation.Other, letter.TextOrientation);
Assert.Equal(45.0, letter.GlyphRectangle.Rotation, 5);
}
var page2 = document.GetPage(2);
Assert.Equal(157, page2.Letters.Count);
var page3 = document.GetPage(3);
Assert.Equal(283, page3.Letters.Count);
var page4 = document.GetPage(4);
Assert.Equal(304, page4.Letters.Count);
}
}
}
}

View File

@@ -175,13 +175,12 @@
private TextOrientation GetTextOrientationRot()
{
double rotation = GlyphRectangle.Rotation;
int rotationInt = (int)Math.Round(rotation, MidpointRounding.AwayFromZero);
if (Math.Abs(rotation - rotationInt) >= 10e-5)
if (Math.Abs(rotation % 90) >= 10e-5)
{
return TextOrientation.Other;
}
}
int rotationInt = (int)Math.Round(rotation, MidpointRounding.AwayFromZero);
switch (rotationInt)
{
case 0: