public void AddTextHighlighter(TextRange textRange, Color backgroundColor)
 {
     if (!_hasPendingHightlighter)
     {
         QueuePendingHightlighter(textRange, backgroundColor);
     }
     else
     {
         if (_lastEnd == textRange.StartIndex && _lastHightlightColor == backgroundColor)
         {
             _lastEnd += textRange.Length;
         }
         else
         {
             TextRange range = new TextRange()
             {
                 StartIndex = _lastStart, Length = _lastEnd - _lastStart
             };
             TextHighlighters.Add(new TextHighlighter()
             {
                 Background = BrushFactory.GetSolidColorBrush(_lastHightlightColor),
                 Ranges     = { range }
             });
             QueuePendingHightlighter(textRange, backgroundColor);
         }
     }
 }
        private void AppendParagraph(RichTextBlockDiffContext richTextBlockData, string text, ref int index, Color?background = null, Color?foreground = null)
        {
            var paragraph = new Paragraph
            {
                LineStackingStrategy = LineStackingStrategy.BlockLineHeight,
                Foreground           = foreground.HasValue
                    ? BrushFactory.GetSolidColorBrush(foreground.Value)
                    : _defaultForeground,
            };

            paragraph.LineHeight = paragraph.FontSize + 6;

            var run = new Run {
                Text = text
            };

            paragraph.Inlines.Add(run);

            richTextBlockData.Blocks.Add(paragraph);

            if (background != null)
            {
                richTextBlockData.AddTextHighlighter(new TextRange()
                {
                    StartIndex = index, Length = text.Length
                }, background.Value);
            }
            index += text.Length;
        }
 public IList <TextHighlighter> GetTextHighlighters()
 {
     if (_hasPendingHightlighter)
     {
         TextRange range = new TextRange()
         {
             StartIndex = _lastStart, Length = _lastEnd - _lastStart
         };
         TextHighlighters.Add(new TextHighlighter()
         {
             Background = BrushFactory.GetSolidColorBrush(_lastHightlightColor),
             Ranges     = { range }
         });
         _hasPendingHightlighter = false;
     }
     return(TextHighlighters);
 }
        private Inline NewRun(RichTextBlockDiffContext richTextBlockData, string text, ref int index, Color?background = null, Color?foreground = null)
        {
            var run = new Run
            {
                Text       = text,
                Foreground = foreground.HasValue
                            ? BrushFactory.GetSolidColorBrush(foreground.Value)
                            : _defaultForeground
            };

            if (background != null)
            {
                richTextBlockData.AddTextHighlighter(new TextRange()
                {
                    StartIndex = index, Length = text.Length
                }, background.Value);
            }
            index += text.Length;
            return(run);
        }
Esempio n. 5
0
 public RichTextBlockDiffRenderer()
 {
     differ        = new SideBySideDiffBuilder(new Differ());
     _brushFactory = new BrushFactory();
 }
 public RichTextBlockDiffContext(BrushFactory brushFactory)
 {
     Blocks        = new List <Block>();
     _brushFactory = brushFactory;
 }