using System; using System.Collections.Generic; namespace Topten.RichTextKit { partial class TextBlock { /// /// Determines whether to add ellipsis symbol automatically to a truncated text. /// public bool AllowEllipsis { get; set; } = true; /// /// Corresponds to LineLimit flag of gdi+ StringFormat. Allows to draw a partially visible text line if set to false. /// public bool LineLimit { get; set; } = true; /// /// Gets or sets the tab stop list. /// public float[] TabStops { get; set; } /// /// Gets or sets the default tab width, in pixels. /// public float FirstTabOffset { get; set; } private float GetTabStopPositionOffset(float pos) { float result = FirstTabOffset; if (TabStops != null && TabStops.Length > 0) { float tabWidth = 0; for (int i = 0; i < TabStops.Length; i++) { tabWidth = TabStops[i]; result += tabWidth; if (result > pos) return result - pos; if (i == 0 && tabWidth > 0) result -= result % tabWidth; } if (tabWidth <= 0) return 0; while (result < pos) { result += tabWidth; } return result - pos; } if (result > pos) return result - pos; return 0; } /// /// Adds a text that may contain tabs. /// /// The text to add. /// The style. public void AddTextWithTabs(string text, Style style) { // each tab is added as a separate symbol if (text.Contains("\t")) { while (text != "") { int tabPos = text.IndexOf("\t"); if (tabPos == -1) break; if (tabPos != 0) AddText(text.Substring(0, tabPos), style); AddText("\t", style); text = text.Substring(tabPos + 1); } } AddText(text, style); } } }