namespace UglyToad.PdfPig.DocumentLayoutAnalysis
{
using System;
using System.Collections.Generic;
using System.Linq;
using Content;
using Core;
///
/// A block of text.
///
public class TextBlock
{
///
/// The text of the block.
///
public string Text { get; }
///
/// The text direction of the block.
///
public TextDirection TextDirection { get; }
///
/// The rectangle completely containing the block.
///
public PdfRectangle BoundingBox { get; }
///
/// The text lines contained in the block.
///
public IReadOnlyList TextLines { get; }
///
/// Create a new .
///
///
public TextBlock(IReadOnlyList lines)
{
if (lines == null)
{
throw new ArgumentNullException(nameof(lines));
}
if (lines.Count == 0)
{
throw new ArgumentException("Empty lines provided.", nameof(lines));
}
TextLines = lines;
Text = string.Join(" ", lines.Select(x => x.Text));
var minX = lines.Min(x => x.BoundingBox.Left);
var minY = lines.Min(x => x.BoundingBox.Bottom);
var maxX = lines.Max(x => x.BoundingBox.Right);
var maxY = lines.Max(x => x.BoundingBox.Top);
BoundingBox = new PdfRectangle(minX, minY, maxX, maxY);
TextDirection = lines[0].TextDirection;
}
///
public override string ToString()
{
return Text;
}
}
}