GetRectsForSegment() public static method

public static GetRectsForSegment ( TextView textView, ISegment segment, bool extendToFullWidthAtLineEnd = false ) : IEnumerable
textView TextView
segment ISegment
extendToFullWidthAtLineEnd bool
return IEnumerable
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (textView.SelectionStart != textView.SelectionEnd && textView.SelectionEnd >= 0 && textView.SelectionStart >= 0)
            {
                TextSegment selection;

                if (textView.SelectionEnd > textView.SelectionStart)
                {
                    selection = new TextSegment {
                        StartOffset = textView.SelectionStart, EndOffset = textView.SelectionEnd
                    };
                }
                else
                {
                    selection = new TextSegment {
                        StartOffset = textView.SelectionEnd, EndOffset = textView.SelectionStart
                    };
                }

                var rects = VisualLineGeometryBuilder.GetRectsForSegment(textView, selection);

                foreach (var rect in rects)
                {
                    drawingContext.FillRectangle(selectionBrush, rect);
                }
            }
        }
Beispiel #2
0
        public void TransformLine(TextView textView, DrawingContext drawingContext, VisualLine line)
        {
            if (!string.IsNullOrEmpty(SelectedWord) && line.RenderedText.Text.Contains(SelectedWord))
            {
                var startIndex = 0;

                while (startIndex != -1)
                {
                    startIndex = line.RenderedText.Text.IndexOf(SelectedWord, startIndex);

                    if (startIndex != -1)
                    {
                        var rect =
                            VisualLineGeometryBuilder.GetRectsForSegment(textView,
                                                                         new TextSegment
                        {
                            StartOffset = startIndex + line.Offset,
                            EndOffset   = startIndex + line.Offset + SelectedWord.Length
                        }).First();

                        drawingContext.FillRectangle(highlightBrush, rect);

                        startIndex += SelectedWord.Length;
                    }
                }
            }
        }
        public void TransformLine(TextView textView, DrawingContext drawingContext, VisualLine line)
        {
            if (markers == null)
            {
                return;
            }

            var markersInLine = markers.FindOverlappingSegments(line);

            foreach (var marker in markersInLine)
            {
                if (marker.Length == 0)
                {
                    var endoffset = TextUtilities.GetNextCaretPosition(textView.TextDocument, marker.StartOffset,
                                                                       TextUtilities.LogicalDirection.Forward, TextUtilities.CaretPositioningMode.WordBorderOrSymbol);

                    if (endoffset == -1)
                    {
                        marker.Length = line.Length;
                    }
                    else
                    {
                        marker.EndOffset = endoffset;
                    }
                }

                if (marker.EndOffset < textView.TextDocument.TextLength)
                {
                    foreach (var r in VisualLineGeometryBuilder.GetRectsForSegment(textView, marker))
                    {
                        var startPoint = r.BottomLeft;
                        var endPoint   = r.BottomRight;

                        var usedPen = new Pen(new SolidColorBrush(marker.MarkerColor), 1);

                        const double offset = 2.5;

                        var count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                        var geometry = new StreamGeometry();

                        using (var ctx = geometry.Open())
                        {
                            ctx.BeginFigure(startPoint, false);

                            foreach (var point in CreatePoints(startPoint, endPoint, offset, count))
                            {
                                ctx.LineTo(point);
                            }

                            ctx.EndFigure(false);
                        }

                        drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                        break;
                    }
                }
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (line > 0 && line < textView.TextDocument.LineCount)
            {
                var currentLine = textView.TextDocument.GetLineByNumber(line);

                var rects = VisualLineGeometryBuilder.GetRectsForSegment(textView, currentLine);

                foreach (var rect in rects)
                {
                    var drawRect = new Rect(rect.TopLeft.X, rect.TopLeft.Y, textView.Bounds.Width, rect.Height);
                    drawingContext.FillRectangle(selectedLineBg, drawRect);
                }
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (textView.SelectionStart == textView.SelectionEnd && textView.CaretIndex != -1 &&
                textView.CaretIndex <= textView.TextDocument.TextLength)
            {
                var currentLine = textView.TextDocument.GetLineByOffset(textView.CaretIndex);

                var rects = VisualLineGeometryBuilder.GetRectsForSegment(textView, currentLine);

                foreach (var rect in rects)
                {
                    var drawRect = new Rect(rect.TopLeft.X, rect.TopLeft.Y, textView.Bounds.Width, rect.Height);
                    drawingContext.FillRectangle(selectedLineBg, drawRect);
                }
            }
        }