2018-11-25 04:51:27 +08:00
|
|
|
|
namespace UglyToad.PdfPig.Content
|
|
|
|
|
{
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Geometry;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A word.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Word
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The text of the word.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Text { get; }
|
|
|
|
|
|
2019-05-13 02:34:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The text direction of the word.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public TextDirection TextDirection { get; }
|
|
|
|
|
|
2018-11-25 04:51:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The rectangle completely containing the word.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public PdfRectangle BoundingBox { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The name of the font for the word.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string FontName { get; }
|
|
|
|
|
|
2019-05-13 02:34:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The letters contained in the word.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IReadOnlyList<Letter> Letters { get; }
|
|
|
|
|
|
2018-11-25 04:51:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new <see cref="Word"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="letters">The letters contained in the word.</param>
|
|
|
|
|
public Word(IReadOnlyList<Letter> letters)
|
|
|
|
|
{
|
|
|
|
|
if (letters == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(letters));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (letters.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Empty letters provided.", nameof(letters));
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-13 02:34:00 +08:00
|
|
|
|
Letters = letters;
|
|
|
|
|
|
2018-11-25 04:51:27 +08:00
|
|
|
|
Text = string.Join(string.Empty, letters.Select(x => x.Value));
|
|
|
|
|
|
2018-11-27 04:18:00 +08:00
|
|
|
|
var minX = letters.Min(x => x.Location.X);
|
|
|
|
|
var minY = letters.Min(x => x.Location.Y);
|
|
|
|
|
var maxX = letters.Max(x => x.Location.X + x.Width);
|
2018-11-25 04:51:27 +08:00
|
|
|
|
var maxY = letters.Max(x => x.GlyphRectangle.Top);
|
|
|
|
|
BoundingBox = new PdfRectangle(minX, minY, maxX, maxY);
|
2019-05-13 02:34:00 +08:00
|
|
|
|
|
2018-11-25 04:51:27 +08:00
|
|
|
|
FontName = letters[0].FontName;
|
2019-05-13 02:34:00 +08:00
|
|
|
|
TextDirection = letters[0].TextDirection;
|
2018-11-25 04:51:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return Text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|