mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-14 10:55:04 +08:00
rename TextDirection into TextOrientation
This commit is contained in:
@@ -196,7 +196,7 @@
|
||||
|
||||
private static IEnumerable<TextLine> GetLines(List<Word> 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<IEnumerable<Word>, IReadOnlyList<Word>> 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();
|
||||
}
|
||||
|
@@ -17,9 +17,9 @@
|
||||
public string Text { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The text direction of the block.
|
||||
/// The text orientation of the block.
|
||||
/// </summary>
|
||||
public TextDirection TextDirection { get; }
|
||||
public TextOrientation TextOrientation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -17,9 +17,9 @@
|
||||
public string Text { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The text direction of the line.
|
||||
/// The text orientation of the line.
|
||||
/// </summary>
|
||||
public TextDirection TextDirection { get; }
|
||||
public TextOrientation TextOrientation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -47,14 +47,14 @@
|
||||
}
|
||||
|
||||
List<Word> 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)
|
||||
|
@@ -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",
|
||||
|
@@ -15,9 +15,9 @@
|
||||
public string Value { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Text direction of the letter.
|
||||
/// Text orientation of the letter.
|
||||
/// </summary>
|
||||
public TextDirection TextDirection { get; }
|
||||
public TextOrientation TextOrientation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The placement position of the character in PDF space. See <see cref="StartBaseLine"/>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -1,17 +1,17 @@
|
||||
namespace UglyToad.PdfPig.Content
|
||||
{
|
||||
/// <summary>
|
||||
/// Direction of the text.
|
||||
/// Orientation of the text.
|
||||
/// </summary>
|
||||
public enum TextDirection : byte
|
||||
public enum TextOrientation : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Other text direction.
|
||||
/// Other text orientation.
|
||||
/// </summary>
|
||||
Other = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Usual text direction (Left to Right).
|
||||
/// Usual text orientation (Left to Right).
|
||||
/// </summary>
|
||||
Horizontal = 1,
|
||||
|
@@ -18,9 +18,9 @@
|
||||
public string Text { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The text direction of the word.
|
||||
/// The text orientation of the word.
|
||||
/// </summary>
|
||||
public TextDirection TextDirection { get; }
|
||||
public TextOrientation TextOrientation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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<string, PdfRectangle> 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
|
||||
|
@@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user