public override VisualLineElement ConstructElement(int offset)
        {
            var c = CurrentContext.Document.GetCharAt(offset);

            if (ShowSpaces && c == ' ')
            {
                return(new SpaceTextElement(CurrentContext.TextView.CachedElements.GetTextForNonPrintableCharacter("\u00B7", CurrentContext)));
            }
            if (ShowTabs && c == '\t')
            {
                return(new TabTextElement(CurrentContext.TextView.CachedElements.GetTextForNonPrintableCharacter("\u00BB", CurrentContext)));
            }
            if (ShowBoxForControlCharacters && char.IsControl(c))
            {
                var p = CurrentContext.GlobalTextRunProperties.Clone();
                p.ForegroundBrush = Brushes.White;
                var textFormatter = TextFormatterFactory.Create();
                var text          = FormattedTextElement.PrepareText(textFormatter,
                                                                     TextUtilities.GetControlCharacterName(c), p);
                return(new SpecialCharacterBoxElement(text));
            }
            return(null);
        }
        public TextLine GetTextForNonPrintableCharacter(string text, ITextRunConstructionContext context)
        {
            if (_nonPrintableCharacterTexts == null)
            {
                _nonPrintableCharacterTexts = new Dictionary <string, TextLine>();
            }

            if (_nonPrintableCharacterTexts.TryGetValue(text, out var textLine))
            {
                return(textLine);
            }

            var properties = context.GlobalTextRunProperties.Clone();

            properties.ForegroundBrush = context.TextView.NonPrintableCharacterBrush;
            if (_formatter == null)
            {
                _formatter = TextFormatterFactory.Create();
            }

            textLine = FormattedTextElement.PrepareText(_formatter, text, properties);
            _nonPrintableCharacterTexts[text] = textLine;
            return(textLine);
        }
 public SpecialCharacterTextRun(FormattedTextElement element, TextRunProperties properties)
     : base(element, properties)
 {
 }
 /// <summary>
 /// Creates a new FormattedTextRun.
 /// </summary>
 public FormattedTextRun(FormattedTextElement element, TextRunProperties properties)
 {
     Properties = properties ?? throw new ArgumentNullException(nameof(properties));
     Element    = element ?? throw new ArgumentNullException(nameof(element));
 }