コード例 #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
        /// <inheritdoc/>
        public override VisualLineElement ConstructElement(int offset)
        {
            if (foldingManager == null)
            {
                return(null);
            }
            int            foldedUntil    = -1;
            FoldingSection foldingSection = null;

            foreach (FoldingSection fs in foldingManager.GetFoldingsContaining(offset))
            {
                if (fs.IsFolded)
                {
                    if (fs.EndOffset > foldedUntil)
                    {
                        foldedUntil    = fs.EndOffset;
                        foldingSection = fs;
                    }
                }
            }
            if (foldedUntil > offset && foldingSection != null)
            {
                // Handle overlapping foldings: if there's another folded folding
                // (starting within the foldingSection) that continues after the end of the folded section,
                // then we'll extend our fold element to cover that overlapping folding.
                bool foundOverlappingFolding;
                do
                {
                    foundOverlappingFolding = false;
                    foreach (FoldingSection fs in FoldingManager.GetFoldingsContaining(foldedUntil))
                    {
                        if (fs.IsFolded && fs.EndOffset > foldedUntil)
                        {
                            foldedUntil             = fs.EndOffset;
                            foundOverlappingFolding = true;
                        }
                    }
                } while (foundOverlappingFolding);

                string title = foldingSection.Title;
                if (string.IsNullOrEmpty(title))
                {
                    title = "...";
                }
                var p = new VisualLineElementTextRunProperties(CurrentContext.GlobalTextRunProperties);
                p.SetForegroundBrush(textBrush);
                var textFormatter = TextFormatterFactory.Create(CurrentContext.TextView);
                var text          = FormattedTextElement.PrepareText(textFormatter, title, p);
                return(new FoldingLineElement(foldingSection, text, foldedUntil - offset)
                {
                    textBrush = textBrush
                });
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
 /// <inheritdoc/>
 public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructionContext context)
 {
     if (textLine == null)
     {
         var formatter = TextFormatterFactory.Create(context.TextView);
         textLine  = PrepareText(formatter, this.text, this.TextRunProperties);
         this.text = null;
     }
     return(new FormattedTextRun(this, this.TextRunProperties));
 }
コード例 #4
0
ファイル: FastTextBlock.cs プロジェクト: zstreamer/dnSpy
        void MakeNewText()
        {
            if (fmt == null)
            {
                fmt = TextFormatterFactory.Create(this, provider);
            }

            if (line != null)
            {
                line.Dispose();
            }

            src.UpdateParent(this);
            line = fmt.FormatLine(src.Source, 0, 0, new ParaProps(this), null);
        }
コード例 #5
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);
        }
コード例 #6
0
        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);
        }