// "Therefore those skilled at the unorthodox // are infinite as heaven and earth, // inexhaustible as the great rivers. // When they come to an end, // they begin again, // like the days and months; // they die and are reborn, // like the four seasons." // // - Sun Tsu, // "The Art of War" using System; using TheArtOfDev.HtmlRenderer.Adapters; using TheArtOfDev.HtmlRenderer.Adapters.Entities; using TheArtOfDev.HtmlRenderer.Core.Handlers; namespace TheArtOfDev.HtmlRenderer.Core.Dom { /// /// Represents a word inside an inline box /// /// /// Because of performance, words of text are the most atomic /// element in the project. It should be characters, but come on, /// imagine the performance when drawing char by char on the device.
/// It may change for future versions of the library. ///
internal abstract class CssRect { #region Fields and Consts /// /// the CSS box owner of the word /// private readonly CssBox _ownerBox; /// /// Rectangle /// private RRect _rect; /// /// If the word is selected this points to the selection handler for more data /// private SelectionHandler _selection; #endregion /// /// Init. /// /// the CSS box owner of the word protected CssRect(CssBox owner) { _ownerBox = owner; } /// /// Gets the Box where this word belongs. /// public CssBox OwnerBox { get { return _ownerBox; } } /// /// Gets or sets the bounds of the rectangle /// public RRect Rectangle { get { return _rect; } set { _rect = value; } } /// /// Left of the rectangle /// public double Left { get { return _rect.X; } set { _rect.X = value; } } /// /// Top of the rectangle /// public double Top { get { return _rect.Y; } set { _rect.Y = value; } } /// /// Width of the rectangle /// public double Width { get { return _rect.Width; } set { _rect.Width = value; } } /// /// Get the full width of the word including the spacing. /// public double FullWidth { get { return _rect.Width + ActualWordSpacing; } } /// /// Gets the actual width of whitespace between words. /// public double ActualWordSpacing { get { return (OwnerBox != null ? (HasSpaceAfter ? OwnerBox.ActualWordSpacing : 0) + (IsImage ? OwnerBox.ActualWordSpacing : 0) : 0); } } /// /// Height of the rectangle /// public double Height { get { return _rect.Height; } set { _rect.Height = value; } } /// /// Gets or sets the right of the rectangle. When setting, it only affects the Width of the rectangle. /// public double Right { get { return Rectangle.Right; } set { Width = value - Left; } } /// /// Gets or sets the bottom of the rectangle. When setting, it only affects the Height of the rectangle. /// public double Bottom { get { return Rectangle.Bottom; } set { Height = value - Top; } } /// /// If the word is selected this points to the selection handler for more data /// public SelectionHandler Selection { get { return _selection; } set { _selection = value; } } internal void SetPageLocation(double yLastPageRef, int iPage, PageList _pagelist) { } /// /// was there a whitespace before the word chars (before trim) /// public virtual bool HasSpaceBefore { get { return false; } } /// /// was there a whitespace after the word chars (before trim) /// public virtual bool HasSpaceAfter { get { return false; } } /// /// Gets the image this words represents (if one exists) /// public virtual RImage Image { get { return null; } // ReSharper disable ValueParameterNotUsed set { } // ReSharper restore ValueParameterNotUsed } /// /// Gets if the word represents an image. /// public virtual bool IsImage { get { return false; } } /// /// Gets a bool indicating if this word is composed only by spaces. /// Spaces include tabs and line breaks /// public virtual bool IsSpaces { get { return true; } } /// /// Gets if the word is composed by only a line break /// public virtual bool IsLineBreak { get { return false; } } /// /// Gets the text of the word /// public virtual string Text { get { return null; } } /// /// is the word is currently selected /// public bool Selected { get { return _selection != null; } } /// /// the selection start index if the word is partially selected (-1 if not selected or fully selected) /// public int SelectedStartIndex { get { return _selection != null ? _selection.GetSelectingStartIndex(this) : -1; } } /// /// the selection end index if the word is partially selected (-1 if not selected or fully selected) /// public int SelectedEndIndexOffset { get { return _selection != null ? _selection.GetSelectedEndIndexOffset(this) : -1; } } /// /// the selection start offset if the word is partially selected (-1 if not selected or fully selected) /// public double SelectedStartOffset { get { return _selection != null ? _selection.GetSelectedStartOffset(this) : -1; } } /// /// the selection end offset if the word is partially selected (-1 if not selected or fully selected) /// public double SelectedEndOffset { get { return _selection != null ? _selection.GetSelectedEndOffset(this) : -1; } } /// /// Gets or sets an offset to be considered in measurements /// internal double LeftGlyphPadding { get { return OwnerBox != null ? OwnerBox.ActualFont.LeftPadding : 0; } } /// /// Represents this word for debugging purposes /// /// public override string ToString() { return string.Format("{0} ({1} char{2})", Text.Replace(' ', '-').Replace("\n", "\\n"), Text.Length, Text.Length != 1 ? "s" : string.Empty); } internal void GetPages(PageList _pagelist) { } } }