using System.Drawing; namespace GreenshotPlugin.Interfaces.Ocr { /// /// Describes a line of words /// public class Line { private Rectangle? _calculatedBounds; /// /// Constructor will preallocate the number of words /// /// int public Line(int wordCount) { Words = new Word[wordCount]; for (int i = 0; i < wordCount; i++) { Words[i] = new Word(); } } /// /// The text of the line /// public string Text { get; set; } /// /// An array with words /// public Word[] Words { get; } /// /// Calculate the bounds of the words /// /// Rectangle private Rectangle CalculateBounds() { if (Words.Length == 0) { return Rectangle.Empty; } var result = Words[0].Bounds; for (var index = 0; index < Words.Length; index++) { result = Rectangle.Union(result, Words[index].Bounds); } return result; } /// /// Return the calculated bounds for the whole line /// public Rectangle CalculatedBounds { get { return _calculatedBounds ??= CalculateBounds(); } } /// /// Offset the words with the specified x and y coordinates /// /// int /// int public void Offset(int x, int y) { foreach (var word in Words) { var location = word.Bounds; location.Offset(x,y); word.Bounds = location; } _calculatedBounds = null; CalculateBounds(); } } }