예제 #1
0
        /// <inheritdoc/>
        protected override Size MeasureOverride(Size availableSize)
        {
            Typeface = GetValue(TextBlock.FontFamilyProperty);
            EmSize   = GetValue(TextBlock.FontSizeProperty);

            var text = TextFormatterFactory.CreateFormattedText(
                this,
                new string('9', MaxLineNumberLength),
                Typeface,
                EmSize,
                GetValue(TemplatedControl.ForegroundProperty)
                );

            var textRight = TextFormatterFactory.CreateFormattedText(
                this,
                new string('9', RightMarginChars),
                Typeface,
                EmSize,
                GetValue(TemplatedControl.ForegroundProperty)
                );

            RightMarginSize = textRight.Measure().Width;

            return(new Size(text.Measure().Width + RightMarginSize, 0));
        }
예제 #2
0
        /// <inheritdoc/>
        public override void Render(DrawingContext drawingContext)
        {
            var textView   = TextView;
            var renderSize = Bounds.Size;

            if (textView != null && textView.VisualLinesValid)
            {
                int currentLine = -1;

                if (_editor.SelectionLength == 0 && _editor.CaretOffset >= 0 && _editor.CaretOffset <= _editor.Document.TextLength)
                {
                    currentLine = _editor.Document.GetLineByOffset(_editor.CaretOffset).LineNumber;
                }

                foreach (var line in textView.VisualLines)
                {
                    var lineNumber = line.FirstDocumentLine.LineNumber;

                    var foreground = lineNumber != currentLine ? Foreground : SelectedLineForeground;

                    var text = TextFormatterFactory.CreateFormattedText(
                        this,
                        lineNumber.ToString(CultureInfo.CurrentCulture),
                        Typeface, EmSize, foreground
                        );

                    var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop);
                    drawingContext.DrawText(foreground, new Point(renderSize.Width - text.Measure().Width, y - textView.VerticalOffset),
                                            text);
                }
            }
        }
예제 #3
0
        /// <inheritdoc/>
        protected override void OnRender(DrawingContext drawingContext)
        {
            TextView textView   = this.TextView;
            Size     renderSize = this.RenderSize;

            if (textView != null && textView.VisualLinesValid)
            {
                var foreground = (Brush)GetValue(Control.ForegroundProperty);
                foreach (VisualLine line in textView.VisualLines)
                {
                    int           lineNumber = line.FirstDocumentLine.LineNumber;
                    FormattedText text       = TextFormatterFactory.CreateFormattedText(
                        this,
                        lineNumber.ToString(CultureInfo.CurrentCulture),
                        typeface, emSize, foreground
                        );
                    double y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop);
                    y = y - textView.VerticalOffset;
                    if (this.FlowDirection == FlowDirection.RightToLeft)
                    {
                        MatrixTransform antiMirror = new MatrixTransform(-1, 0, 0, 1, renderSize.Width, 0);
                        drawingContext.PushTransform(antiMirror);
                        drawingContext.DrawText(text, new Point(0, y));
                        drawingContext.Pop();
                    }
                    else
                    {
                        drawingContext.DrawText(text, new Point(renderSize.Width - text.Width, y));
                    }
                }
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            var typeface = textView.GetValue(TextBlock.FontFamilyProperty);
            var emSize   = textView.GetValue(TextBlock.FontSizeProperty);

            var formattedText = TextFormatterFactory.CreateFormattedText(
                textView,
                "9",
                typeface,
                emSize,
                Brushes.Black
                );

            var charSize  = formattedText.Measure();
            var pixelSize = PixelSnapHelpers.GetPixelSize(textView);

            foreach (var entry in markers)
            {
                var startLine = textView.Document.GetLineByOffset(entry.StartOffset);

                var start = entry.StartOffset;

                var startChar = textView.Document.GetCharAt(startLine.Offset);

                if (char.IsWhiteSpace(startChar))
                {
                    start = TextUtilities.GetNextCaretPosition(textView.Document, startLine.Offset, LogicalDirection.Forward,
                                                               CaretPositioningMode.WordBorder);
                }

                var endLine = textView.Document.GetLineByOffset(entry.EndOffset <= textView.Document.TextLength ? entry.EndOffset : textView.Document.TextLength);

                if (endLine.EndOffset > start && startLine != endLine)
                {
                    var newEntry = new TextSegment()
                    {
                        StartOffset = start, EndOffset = endLine.EndOffset
                    };

                    var rects = BackgroundGeometryBuilder.GetRectsForSegment(textView, newEntry);

                    var rect = GetRectForRange(rects);

                    if (!rect.IsEmpty)
                    {
                        var xPos = charSize.Width * (textView.Document.GetLocation(newEntry.StartOffset).Column - 1);

                        rect = rect.WithX(xPos + (charSize.Width / 2));

                        rect = rect.WithX(PixelSnapHelpers.PixelAlign(rect.X, pixelSize.Width));
                        rect = rect.WithY(PixelSnapHelpers.PixelAlign(rect.Y, pixelSize.Height));

                        drawingContext.DrawLine(_pen, rect.TopLeft, rect.BottomLeft);
                    }
                }
            }
        }
예제 #5
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            TextView textView   = this.TextView;
            Size     renderSize = this.RenderSize;

            if (_DiffView == null)
            {
                return;
            }

            var srcLineDiffs = _DiffView.ItemsSource as IReadOnlyList <IDiffLineInfo>;

            if (srcLineDiffs == null)
            {
                return;
            }

            if (textView != null && textView.VisualLinesValid)
            {
                var foreground = _DiffView.LineNumbersForeground;
                foreach (VisualLine line in textView.VisualLines)
                {
                    // AvalonEdit is 1 based but the collection is of course zero based :-(
                    int lineNumber = line.FirstDocumentLine.LineNumber - 1;

                    if (lineNumber >= srcLineDiffs.Count)
                    {
                        continue;
                    }

                    // Find a diff context for a given line
                    if (srcLineDiffs.Count < lineNumber)
                    {
                        continue;
                    }

                    var srcLineDiff = srcLineDiffs[lineNumber];

                    if (srcLineDiff.ImaginaryLineNumber.HasValue)
                    {
                        // Render displayed numbers in a 1-based format
                        int           imaginaryLineNumber = (int)srcLineDiff.ImaginaryLineNumber + 1;
                        FormattedText text = TextFormatterFactory.CreateFormattedText(
                            this,
                            imaginaryLineNumber.ToString(CultureInfo.CurrentCulture),
                            typeface, emSize, foreground
                            );

                        double y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop);
                        drawingContext.DrawText(text, new Point(renderSize.Width - text.Width, y - textView.VerticalOffset));
                    }
                }
            }
        }
예제 #6
0
        /// <inheritdoc/>
        protected override Size MeasureOverride(Size availableSize)
        {
            typeface = this.CreateTypeface();
            emSize   = (double)GetValue(TextBlock.FontSizeProperty);

            var text = TextFormatterFactory.CreateFormattedText(this,
                                                                new string('9', maxLineNumberLength),
                                                                typeface,
                                                                emSize,
                                                                (Brush)GetValue(Control.ForegroundProperty)
                                                                );

            return(new Size(text.Width + 20, 0));
        }
예제 #7
0
        /// <inheritdoc/>
        protected override void OnRender(DrawingContext drawingContext)
        {
            var textView   = TextView;
            var renderSize = RenderSize;

            if (textView != null && textView.VisualLinesValid)
            {
                var foreground = (Brush)GetValue(Control.ForegroundProperty);
                foreach (var line in textView.VisualLines)
                {
                    var lineNumber = line.FirstDocumentLine.LineNumber;
                    var text       = TextFormatterFactory.CreateFormattedText(this, lineNumber.ToString(), typeface, emSize, foreground);
                    var y          = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop);

                    drawingContext.DrawText(text, new Point(renderSize.Width - text.Width, y - textView.VerticalOffset));
                }
            }
        }
        /// <inheritdoc/>
        public override VisualLineElement ConstructElement(int offset)
        {
            char c = CurrentContext.Document.GetCharAt(offset);

            if (ShowSpaces && c == ' ')
            {
                FormattedText text = TextFormatterFactory.CreateFormattedText(
                    CurrentContext.TextView,
                    "\u00B7",
                    CurrentContext.GlobalTextRunProperties.Typeface,
                    CurrentContext.GlobalTextRunProperties.FontRenderingEmSize,
                    Brushes.LightGray
                    );
                return(new SpaceTextElement(text));
            }
            else if (ShowTabs && c == '\t')
            {
                FormattedText text = TextFormatterFactory.CreateFormattedText(
                    CurrentContext.TextView,
                    "\u00BB",
                    CurrentContext.GlobalTextRunProperties.Typeface,
                    CurrentContext.GlobalTextRunProperties.FontRenderingEmSize,
                    Brushes.LightGray
                    );
                return(new TabTextElement(text));
            }
            else if (ShowBoxForControlCharacters && char.IsControl(c))
            {
                FormattedText text = TextFormatterFactory.CreateFormattedText(
                    CurrentContext.TextView,
                    TextUtilities.GetControlCharacterName(c),
                    CurrentContext.GlobalTextRunProperties.Typeface,
                    CurrentContext.GlobalTextRunProperties.FontRenderingEmSize * 0.9,
                    Brushes.White
                    );
                return(new SpecialCharacterBoxElement(text));
            }
            else
            {
                return(null);
            }
        }
예제 #9
0
        /// <inheritdoc/>
        protected override void OnRender(DrawingContext drawingContext)
        {
            TextView textView = this.TextView;

            System.Windows.Size renderSize = this.RenderSize;// new System.Windows.Size(((FrameworkElement)this).Width, ((FrameworkElement)this).RenderSize.Height);
            drawingContext.DrawRectangle(background, null,
                                         new Rect(0, 0, renderSize.Width, renderSize.Height));

            renderSize = this.RenderSize;

            renderSize = this.RenderSize;
            if (textView != null && textView.VisualLinesValid)
            {
                var foreground = (System.Windows.Media.Brush)GetValue(Control.ForegroundProperty);
                foreach (VisualLine line in textView.VisualLines)
                {
                    if (enableLineExtended == true)
                    {
                        if (line.FirstDocumentLine.obs != null)
                        {
                            continue;
                        }
                    }

                    int lineNumber = line.FirstDocumentLine.LineNumberExtended;

                    if (enableLineExtended == false)
                    {
                        lineNumber = line.FirstDocumentLine.LineNumber;
                    }

                    FormattedText text = TextFormatterFactory.CreateFormattedText(
                        this,
                        lineNumber.ToString(CultureInfo.CurrentCulture),
                        typeface, emSize, foreground
                        );
                    double y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop);

                    drawingContext.DrawText(text, new System.Windows.Point(renderSize.Width - text.Width, y - textView.VerticalOffset));
                }
            }
        }
예제 #10
0
        /// <inheritdoc/>
        protected override void OnRender(DrawingContext drawingContext)
        {
            TextView textView   = this.TextView;
            Size     renderSize = this.RenderSize;

            if (textView != null && textView.VisualLinesValid)
            {
                var foreground = (Brush)GetValue(Control.ForegroundProperty);
                foreach (VisualLine line in textView.VisualLines)
                {
                    int           lineNumber = line.FirstDocumentLine.LineNumber;
                    FormattedText text       = TextFormatterFactory.CreateFormattedText(
                        this,
                        lineNumber.ToString(CultureInfo.CurrentCulture),
                        typeface, emSize, foreground
                        );
                    drawingContext.DrawText(text, new Point(renderSize.Width - text.Width,
                                                            line.VisualTop - textView.VerticalOffset));
                }
            }
        }
예제 #11
0
 /// <inheritdoc/>
 public override void Render(DrawingContext drawingContext)
 {
     var textView = TextView;
     var renderSize = Bounds.Size;
     if (textView != null && textView.VisualLinesValid)
     {
         var foreground = GetValue(TemplatedControl.ForegroundProperty);
         foreach (var line in textView.VisualLines)
         {
             var lineNumber = line.FirstDocumentLine.LineNumber;
             var text = TextFormatterFactory.CreateFormattedText(
                 this,
                 lineNumber.ToString(CultureInfo.CurrentCulture),
                 Typeface, EmSize, foreground
             );
             var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop);
             drawingContext.DrawText(foreground, new Point(renderSize.Width - text.Bounds.Width, y - textView.VerticalOffset),
                 text);
         }
     }
 }
        /// <inheritdoc/>
        public override VisualLineElement ConstructElement(int offset)
        {
            if (FoldingManager == null)
            {
                return(null);
            }
            int    foldedUntil = -1;
            string title       = null;

            foreach (FoldingSection fs in FoldingManager.GetFoldingsAt(offset))
            {
                if (fs.IsFolded)
                {
                    if (fs.EndOffset > foldedUntil)
                    {
                        foldedUntil = fs.EndOffset;
                        title       = fs.Title;
                    }
                }
            }
            if (foldedUntil > offset)
            {
                if (string.IsNullOrEmpty(title))
                {
                    title = "...";
                }
                FormattedText text = TextFormatterFactory.CreateFormattedText(
                    CurrentContext.TextView,
                    title,
                    CurrentContext.GlobalTextRunProperties.Typeface,
                    CurrentContext.GlobalTextRunProperties.FontRenderingEmSize,
                    Brushes.Gray
                    );
                return(new FoldingLineElement(text, foldedUntil - offset));
            }
            else
            {
                return(null);
            }
        }
예제 #13
0
        /// <inheritdoc/>
        public override VisualLineElement ConstructElement(int offset)
        {
            string       newlineText;
            DocumentLine lastDocumentLine = CurrentContext.VisualLine.LastDocumentLine;

            if (lastDocumentLine.DelimiterLength == 2)
            {
                newlineText = "\u00B6";
            }
            else if (lastDocumentLine.DelimiterLength == 1)
            {
                char newlineChar = CurrentContext.Document.GetCharAt(lastDocumentLine.Offset + lastDocumentLine.Length);
                if (newlineChar == '\r')
                {
                    newlineText = "\\r";
                }
                else if (newlineChar == '\n')
                {
                    newlineText = "\\n";
                }
                else
                {
                    newlineText = "?";
                }
            }
            else
            {
                return(null);
            }
            FormattedText text = TextFormatterFactory.CreateFormattedText(
                CurrentContext.TextView,
                newlineText,
                CurrentContext.GlobalTextRunProperties.Typeface,
                CurrentContext.GlobalTextRunProperties.FontRenderingEmSize,
                Brushes.LightGray
                );

            return(new NewLineTextElement(text));
        }
예제 #14
0
        /// <inheritdoc/>
        protected override void OnRender(DrawingContext drawingContext)
        {
            TextView textView   = this.TextView;
            Size     renderSize = this.RenderSize;

            if (textView != null && textView.VisualLinesValid)
            {
                var foreground = (Brush)GetValue(Control.ForegroundProperty);
                foreach (VisualLine line in textView.VisualLines)
                {
                    // Telerik Authorship
                    string        lineNumber = GetLineNumberAsString(line);
                    FormattedText text       = TextFormatterFactory.CreateFormattedText(
                        this,
                        lineNumber.ToString(CultureInfo.CurrentCulture),
                        typeface, emSize, foreground
                        );
                    double y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop);
                    drawingContext.DrawText(text, new Point(renderSize.Width - text.Width, y - textView.VerticalOffset));
                }
            }
        }