コード例 #1
0
        public override VisualLineElement ConstructElement(int offset)
        {
            char c = CurrentContext.Document.GetCharAt(offset);

            if (ShowSpaces && c == ' ')
            {
                return(new SpaceTextElement(CurrentContext.TextView.cachedElements.GetTextForNonPrintableCharacter("\u00B7", CurrentContext)));
            }
            else if (ShowTabs && c == '\t')
            {
                return(new TabTextElement(CurrentContext.TextView.cachedElements.GetTextForNonPrintableCharacter("\u00BB", CurrentContext)));
            }
            else if (ShowBoxForControlCharacters && char.IsControl(c))
            {
                var p = new VisualLineElementTextRunProperties(CurrentContext.GlobalTextRunProperties);
                p.SetForegroundBrush(Brushes.White);
                var textFormatter = TextFormatterFactory.Create(CurrentContext.TextView);
                var text          = FormattedTextElement.PrepareText(textFormatter,
                                                                     TextUtilities.GetControlCharacterName(c), p);
                return(new SpecialCharacterBoxElement(text));
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        public TextLine GetTextForNonPrintableCharacter(string text, ITextRunConstructionContext context)
        {
            if (nonPrintableCharacterTexts == null)
            {
                nonPrintableCharacterTexts = new Dictionary <string, TextLine>();
            }
            TextLine textLine;

            if (!nonPrintableCharacterTexts.TryGetValue(text, out textLine))
            {
                var p = new VisualLineElementTextRunProperties(context.GlobalTextRunProperties);
                p.SetForegroundBrush(context.TextView.NonPrintableCharacterBrush);
                if (formatter == null)
                {
                    formatter = TextFormatterFactory.Create(context.TextView);
                }
                textLine = FormattedTextElement.PrepareText(formatter, text, p);
                nonPrintableCharacterTexts[text] = textLine;
            }
            return(textLine);
        }