mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
Get correct text orientation when base line points are equal and fix #741
This commit is contained in:
@@ -137,8 +137,14 @@
|
||||
|
||||
private TextOrientation GetTextOrientation()
|
||||
{
|
||||
if (System.Math.Abs(StartBaseLine.Y - EndBaseLine.Y) < 10e-5)
|
||||
if (Math.Abs(StartBaseLine.Y - EndBaseLine.Y) < 10e-5)
|
||||
{
|
||||
if (Math.Abs(StartBaseLine.X - EndBaseLine.X) < 10e-5)
|
||||
{
|
||||
// Start and End point are the same
|
||||
return GetTextOrientationRot();
|
||||
}
|
||||
|
||||
if (StartBaseLine.X > EndBaseLine.X)
|
||||
{
|
||||
return TextOrientation.Rotate180;
|
||||
@@ -147,8 +153,14 @@
|
||||
return TextOrientation.Horizontal;
|
||||
}
|
||||
|
||||
if (System.Math.Abs(StartBaseLine.X - EndBaseLine.X) < 10e-5)
|
||||
if (Math.Abs(StartBaseLine.X - EndBaseLine.X) < 10e-5)
|
||||
{
|
||||
if (Math.Abs(StartBaseLine.Y - EndBaseLine.Y) < 10e-5)
|
||||
{
|
||||
// Start and End point are the same
|
||||
return GetTextOrientationRot();
|
||||
}
|
||||
|
||||
if (StartBaseLine.Y > EndBaseLine.Y)
|
||||
{
|
||||
return TextOrientation.Rotate90;
|
||||
@@ -160,6 +172,35 @@
|
||||
return TextOrientation.Other;
|
||||
}
|
||||
|
||||
private TextOrientation GetTextOrientationRot()
|
||||
{
|
||||
double rotation = GlyphRectangle.Rotation;
|
||||
int rotationInt = (int)Math.Round(rotation, MidpointRounding.AwayFromZero);
|
||||
|
||||
if (Math.Abs(rotation - rotationInt) >= 10e-5)
|
||||
{
|
||||
return TextOrientation.Other;
|
||||
}
|
||||
|
||||
switch (rotationInt)
|
||||
{
|
||||
case 0:
|
||||
return TextOrientation.Horizontal;
|
||||
|
||||
case -90:
|
||||
return TextOrientation.Rotate90;
|
||||
|
||||
case 180:
|
||||
case -180:
|
||||
return TextOrientation.Rotate180;
|
||||
|
||||
case 90:
|
||||
return TextOrientation.Rotate270;
|
||||
}
|
||||
|
||||
throw new Exception($"Could not find TextOrientation for rotation '{rotation}'.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Produces a string representation of the letter and its position.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user