Minor modifications and updates

This commit is contained in:
BobLd
2019-05-14 20:56:34 +01:00
parent de421d65a1
commit 97f0f6fe75
3 changed files with 30 additions and 16 deletions

View File

@@ -1,15 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using UglyToad.PdfPig.Geometry;
using System.Linq; using System.Linq;
using UglyToad.PdfPig.Geometry;
namespace UglyToad.PdfPig.Content namespace UglyToad.PdfPig.Content
{ {
/// <summary> /// <summary>
/// A line. /// A line of text.
/// </summary> /// </summary>
public class Line public class TextLine
{ {
/// <summary> /// <summary>
/// The text of the line. /// The text of the line.
@@ -32,10 +31,10 @@ namespace UglyToad.PdfPig.Content
public IReadOnlyList<Word> Words { get; } public IReadOnlyList<Word> Words { get; }
/// <summary> /// <summary>
/// Create a new <see cref="Word"/>. /// Create a new <see cref="TextLine"/>.
/// </summary> /// </summary>
/// <param name="words">The letters contained in the word.</param> /// <param name="words">The words contained in the word.</param>
public Line(IReadOnlyList<Word> words) public TextLine(IReadOnlyList<Word> words)
{ {
if (words == null) if (words == null)
{ {
@@ -57,7 +56,14 @@ namespace UglyToad.PdfPig.Content
var maxY = words.Max(x => x.BoundingBox.Top); var maxY = words.Max(x => x.BoundingBox.Top);
BoundingBox = new PdfRectangle(minX, minY, maxX, maxY); BoundingBox = new PdfRectangle(minX, minY, maxX, maxY);
TextDirection = words[0].TextDirection; if (words.All(x => x.TextDirection == words[0].TextDirection))
{
TextDirection = words[0].TextDirection;
}
else
{
TextDirection = TextDirection.Unknown;
}
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -1,8 +1,4 @@
using System; namespace UglyToad.PdfPig.Geometry
using System.Collections.Generic;
using System.Text;
namespace UglyToad.PdfPig.Geometry
{ {
/// <summary> /// <summary>
/// A line in a PDF file. /// A line in a PDF file.
@@ -14,6 +10,18 @@ namespace UglyToad.PdfPig.Geometry
/// </remarks> /// </remarks>
public struct PdfLine public struct PdfLine
{ {
/// <summary>
/// Length of the line.
/// </summary>
public decimal Length
{
get
{
decimal l = (Point1.X - Point1.X) * (Point1.X - Point1.X) + (Point1.Y - Point1.Y) * (Point1.Y - Point1.Y);
return (decimal)System.Math.Sqrt((double)l);
}
}
/// <summary> /// <summary>
/// First point of the line. /// First point of the line.
/// </summary> /// </summary>
@@ -25,7 +33,7 @@ namespace UglyToad.PdfPig.Geometry
public PdfPoint Point2 { get; } public PdfPoint Point2 { get; }
/// <summary> /// <summary>
/// A line in a PDF file. /// Create a new <see cref="PdfLine"/>.
/// </summary> /// </summary>
/// <param name="x1"></param> /// <param name="x1"></param>
/// <param name="y1"></param> /// <param name="y1"></param>
@@ -34,7 +42,7 @@ namespace UglyToad.PdfPig.Geometry
public PdfLine(decimal x1, decimal y1, decimal x2, decimal y2) : this(new PdfPoint(x1, y1), new PdfPoint(x2, y2)) { } public PdfLine(decimal x1, decimal y1, decimal x2, decimal y2) : this(new PdfPoint(x1, y1), new PdfPoint(x2, y2)) { }
/// <summary> /// <summary>
/// A line in a PDF file. /// Create a new <see cref="PdfLine"/>.
/// </summary> /// </summary>
/// <param name="point1">First point of the line.</param> /// <param name="point1">First point of the line.</param>
/// <param name="point2">Second point of the line.</param> /// <param name="point2">Second point of the line.</param>

View File

@@ -69,7 +69,7 @@
internal PdfRectangle(short x1, short y1, short x2, short y2) : this((decimal) x1, y1, x2, y2) { } internal PdfRectangle(short x1, short y1, short x2, short y2) : this((decimal) x1, y1, x2, y2) { }
/// <summary> /// <summary>
/// A rectangle in a PDF file. /// Create a new <see cref="PdfRectangle"/>.
/// </summary> /// </summary>
/// <param name="x1"></param> /// <param name="x1"></param>
/// <param name="y1"></param> /// <param name="y1"></param>