123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using System;
- using System.Collections.Generic;
- namespace Topten.RichTextKit
- {
- partial class TextBlock
- {
- /// <summary>
- /// Determines whether to add ellipsis symbol automatically to a truncated text.
- /// </summary>
- public bool AllowEllipsis { get; set; } = true;
- /// <summary>
- /// Corresponds to LineLimit flag of gdi+ StringFormat. Allows to draw a partially visible text line if set to false.
- /// </summary>
- public bool LineLimit { get; set; } = true;
- /// <summary>
- /// Gets or sets the tab stop list.
- /// </summary>
- public float[] TabStops { get; set; }
- /// <summary>
- /// Gets or sets the default tab width, in pixels.
- /// </summary>
- 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;
- }
- /// <summary>
- /// Adds a text that may contain tabs.
- /// </summary>
- /// <param name="text">The text to add.</param>
- /// <param name="style">The style.</param>
- 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);
- }
- }
- }
|