Skip to content

Commit

Permalink
Fix GetTextOrientation by cleanly checking if rotation is divisible b…
Browse files Browse the repository at this point in the history
…y 90 and fix #913
  • Loading branch information
BobLd committed Oct 7, 2024
1 parent c46722f commit a258090
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
29 changes: 29 additions & 0 deletions src/UglyToad.PdfPig.Tests/Integration/GithubIssuesTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace UglyToad.PdfPig.Tests.Integration
{
using Content;

public class GithubIssuesTests
{
[Fact]
Expand All @@ -22,5 +24,32 @@ public void Issue874()
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);
}
}
}
}
Binary file not shown.
7 changes: 3 additions & 4 deletions src/UglyToad.PdfPig/Content/Letter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,12 @@ private TextOrientation GetTextOrientation()
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:
Expand Down

0 comments on commit a258090

Please sign in to comment.