diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/PageSegmenter/DocstrumBoundingBoxes.cs b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/PageSegmenter/DocstrumBoundingBoxes.cs index 2488014b..c735b3e2 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/PageSegmenter/DocstrumBoundingBoxes.cs +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/PageSegmenter/DocstrumBoundingBoxes.cs @@ -196,7 +196,7 @@ private static IEnumerable GetLines(List words, double maxDist, AngleBounds withinLine, int maxDegreeOfParallelism) { - TextDirection textDirection = words[0].TextDirection; + TextOrientation TextOrientation = words[0].TextOrientation; var groupedIndexes = Clustering.NearestNeighbours(words, 2, Distances.Euclidean, (pivot, candidate) => maxDist, pivot => pivot.BoundingBox.BottomRight, candidate => candidate.BoundingBox.BottomLeft, @@ -205,15 +205,15 @@ maxDegreeOfParallelism).ToList(); Func, IReadOnlyList> orderFunc = l => l.OrderBy(x => x.BoundingBox.Left).ToList(); - if (textDirection == TextDirection.Rotate180) + if (TextOrientation == TextOrientation.Rotate180) { orderFunc = l => l.OrderByDescending(x => x.BoundingBox.Right).ToList(); } - else if (textDirection == TextDirection.Rotate90) + else if (TextOrientation == TextOrientation.Rotate90) { orderFunc = l => l.OrderByDescending(x => x.BoundingBox.Top).ToList(); } - else if (textDirection == TextDirection.Rotate270) + else if (TextOrientation == TextOrientation.Rotate270) { orderFunc = l => l.OrderBy(x => x.BoundingBox.Bottom).ToList(); } diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/TextBlock.cs b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/TextBlock.cs index 6e793104..000e4603 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/TextBlock.cs +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/TextBlock.cs @@ -17,9 +17,9 @@ public string Text { get; } /// - /// The text direction of the block. + /// The text orientation of the block. /// - public TextDirection TextDirection { get; } + public TextOrientation TextOrientation { get; } /// /// The rectangle completely containing the block. @@ -64,7 +64,7 @@ var maxY = lines.Max(x => x.BoundingBox.Top); BoundingBox = new PdfRectangle(minX, minY, maxX, maxY); - TextDirection = lines[0].TextDirection; + TextOrientation = lines[0].TextOrientation; } /// diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/TextLine.cs b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/TextLine.cs index 198ef724..22cd59f7 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/TextLine.cs +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/TextLine.cs @@ -17,9 +17,9 @@ public string Text { get; } /// - /// The text direction of the line. + /// The text orientation of the line. /// - public TextDirection TextDirection { get; } + public TextOrientation TextOrientation { get; } /// /// The rectangle completely containing the line. @@ -59,13 +59,13 @@ BoundingBox = new PdfRectangle(minX, minY, maxX, maxY); - if (words.All(x => x.TextDirection == words[0].TextDirection)) + if (words.All(x => x.TextOrientation == words[0].TextOrientation)) { - TextDirection = words[0].TextDirection; + TextOrientation = words[0].TextOrientation; } else { - TextDirection = TextDirection.Other; + TextOrientation = TextOrientation.Other; } } diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/WordExtractor/NearestNeighbourWordExtractor.cs b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/WordExtractor/NearestNeighbourWordExtractor.cs index 55c4d284..dca81b90 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/WordExtractor/NearestNeighbourWordExtractor.cs +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/WordExtractor/NearestNeighbourWordExtractor.cs @@ -47,14 +47,14 @@ } List wordsH = GetWords( - letters.Where(l => l.TextDirection == TextDirection.Horizontal).ToList(), + letters.Where(l => l.TextOrientation == TextOrientation.Horizontal).ToList(), (l1, l2) => maxDistFunc(l1, l2), Distances.Manhattan, filterFunc, MaxDegreeOfParallelism) .OrderByDescending(x => x.BoundingBox.Bottom) .ThenBy(x => x.BoundingBox.Left).ToList(); var words270 = GetWords( - letters.Where(l => l.TextDirection == TextDirection.Rotate270).ToList(), + letters.Where(l => l.TextOrientation == TextOrientation.Rotate270).ToList(), (l1, l2) => maxDistFunc(l1, l2), Distances.Manhattan, filterFunc, MaxDegreeOfParallelism) .OrderBy(x => x.BoundingBox.Right) @@ -62,7 +62,7 @@ wordsH.AddRange(words270); var words180 = GetWords( - letters.Where(l => l.TextDirection == TextDirection.Rotate180).ToList(), + letters.Where(l => l.TextOrientation == TextOrientation.Rotate180).ToList(), (l1, l2) => maxDistFunc(l1, l2), Distances.Manhattan, filterFunc, MaxDegreeOfParallelism) .OrderBy(x => x.BoundingBox.Top) @@ -70,7 +70,7 @@ wordsH.AddRange(words180); var words90 = GetWords( - letters.Where(l => l.TextDirection == TextDirection.Rotate90).ToList(), + letters.Where(l => l.TextOrientation == TextOrientation.Rotate90).ToList(), (l1, l2) => maxDistFunc(l1, l2), Distances.Manhattan, filterFunc, MaxDegreeOfParallelism) .OrderByDescending(x => x.BoundingBox.Left) @@ -78,7 +78,7 @@ wordsH.AddRange(words90); var wordsU = GetWords( - letters.Where(l => l.TextDirection == TextDirection.Other).ToList(), + letters.Where(l => l.TextOrientation == TextOrientation.Other).ToList(), (l1, l2) => maxDistFunc(l1, l2) * 2.0, // allow twice the distance for oriented text Distances.Euclidean, filterFunc, MaxDegreeOfParallelism) .OrderByDescending(x => x.BoundingBox.Bottom) diff --git a/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs b/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs index e8edbc20..11c8da14 100644 --- a/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs +++ b/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs @@ -79,7 +79,7 @@ "UglyToad.PdfPig.Content.PageSize", "UglyToad.PdfPig.Content.PageTreeNode", "UglyToad.PdfPig.Content.Word", - "UglyToad.PdfPig.Content.TextDirection", + "UglyToad.PdfPig.Content.TextOrientation", "UglyToad.PdfPig.Content.XmpMetadata", "UglyToad.PdfPig.CrossReference.CrossReferenceTable", "UglyToad.PdfPig.CrossReference.CrossReferenceType", diff --git a/src/UglyToad.PdfPig/Content/Letter.cs b/src/UglyToad.PdfPig/Content/Letter.cs index f6d2ca04..146b7d03 100644 --- a/src/UglyToad.PdfPig/Content/Letter.cs +++ b/src/UglyToad.PdfPig/Content/Letter.cs @@ -15,9 +15,9 @@ public string Value { get; } /// - /// Text direction of the letter. + /// Text orientation of the letter. /// - public TextDirection TextDirection { get; } + public TextOrientation TextOrientation { get; } /// /// The placement position of the character in PDF space. See @@ -100,32 +100,32 @@ Color = color ?? GrayColor.Black; PointSize = pointSize; TextSequence = textSequence; - TextDirection = GetTextDirection(); + TextOrientation = GetTextOrientation(); } - private TextDirection GetTextDirection() + private TextOrientation GetTextOrientation() { if (System.Math.Abs(StartBaseLine.Y - EndBaseLine.Y) < 10e-5) { if (StartBaseLine.X > EndBaseLine.X) { - return TextDirection.Rotate180; + return TextOrientation.Rotate180; } - return TextDirection.Horizontal; + return TextOrientation.Horizontal; } if (System.Math.Abs(StartBaseLine.X - EndBaseLine.X) < 10e-5) { if (StartBaseLine.Y > EndBaseLine.Y) { - return TextDirection.Rotate90; + return TextOrientation.Rotate90; } - return TextDirection.Rotate270; + return TextOrientation.Rotate270; } - return TextDirection.Other; + return TextOrientation.Other; } /// diff --git a/src/UglyToad.PdfPig/Content/TextDirection.cs b/src/UglyToad.PdfPig/Content/TextOrientation.cs similarity index 77% rename from src/UglyToad.PdfPig/Content/TextDirection.cs rename to src/UglyToad.PdfPig/Content/TextOrientation.cs index 85b2b7d0..a333b07b 100644 --- a/src/UglyToad.PdfPig/Content/TextDirection.cs +++ b/src/UglyToad.PdfPig/Content/TextOrientation.cs @@ -1,17 +1,17 @@ namespace UglyToad.PdfPig.Content { /// - /// Direction of the text. + /// Orientation of the text. /// - public enum TextDirection : byte + public enum TextOrientation : byte { /// - /// Other text direction. + /// Other text orientation. /// Other = 0, /// - /// Usual text direction (Left to Right). + /// Usual text orientation (Left to Right). /// Horizontal = 1, diff --git a/src/UglyToad.PdfPig/Content/Word.cs b/src/UglyToad.PdfPig/Content/Word.cs index 3c89c758..8cc14de2 100644 --- a/src/UglyToad.PdfPig/Content/Word.cs +++ b/src/UglyToad.PdfPig/Content/Word.cs @@ -18,9 +18,9 @@ public string Text { get; } /// - /// The text direction of the word. + /// The text orientation of the word. /// - public TextDirection TextDirection { get; } + public TextOrientation TextOrientation { get; } /// /// The rectangle completely containing the word. @@ -55,14 +55,14 @@ Letters = letters; - var tempTextDirection = letters[0].TextDirection; - if (tempTextDirection != TextDirection.Other) + var tempTextOrientation = letters[0].TextOrientation; + if (tempTextOrientation != TextOrientation.Other) { foreach (var letter in letters) { - if (letter.TextDirection != tempTextDirection) + if (letter.TextOrientation != tempTextOrientation) { - tempTextDirection = TextDirection.Other; + tempTextOrientation = TextOrientation.Other; break; } } @@ -70,25 +70,25 @@ Tuple data; - switch (tempTextDirection) + switch (tempTextOrientation) { - case TextDirection.Horizontal: + case TextOrientation.Horizontal: data = GetBoundingBoxH(letters); break; - case TextDirection.Rotate180: + case TextOrientation.Rotate180: data = GetBoundingBox180(letters); break; - case TextDirection.Rotate90: + case TextOrientation.Rotate90: data = GetBoundingBox90(letters); break; - case TextDirection.Rotate270: + case TextOrientation.Rotate270: data = GetBoundingBox270(letters); break; - case TextDirection.Other: + case TextOrientation.Other: default: data = GetBoundingBoxOther(letters); break; @@ -98,7 +98,7 @@ BoundingBox = data.Item2; FontName = letters[0].FontName; - TextDirection = tempTextDirection; + TextOrientation = tempTextOrientation; } #region Bounding box diff --git a/src/UglyToad.PdfPig/Util/DefaultWordExtractor.cs b/src/UglyToad.PdfPig/Util/DefaultWordExtractor.cs index ed6832b2..fcc316b8 100644 --- a/src/UglyToad.PdfPig/Util/DefaultWordExtractor.cs +++ b/src/UglyToad.PdfPig/Util/DefaultWordExtractor.cs @@ -74,9 +74,9 @@ var nextIsWhiteSpace = string.IsNullOrWhiteSpace(letter.Value); var nextFontDiffers = !string.Equals(letter.FontName, lastLetter.FontName, StringComparison.OrdinalIgnoreCase) && gap > letter.Width * 0.1; var nextFontSizeDiffers = Math.Abs(letter.FontSize - lastLetter.FontSize) > 0.1; - var nextTextDirectionDiffers = letter.TextDirection != lastLetter.TextDirection; + var nextTextOrientationDiffers = letter.TextOrientation != lastLetter.TextOrientation; - if (nextToLeft || nextBigSpace || nextIsWhiteSpace || nextFontDiffers || nextFontSizeDiffers || nextTextDirectionDiffers) + if (nextToLeft || nextBigSpace || nextIsWhiteSpace || nextFontDiffers || nextFontSizeDiffers || nextTextOrientationDiffers) { if (lettersSoFar.Count > 0) {