/// <summary>
        /// Adds the specified segment to the geometry.
        /// </summary>
        public void AddSegment(TextView textView, ISegment segment)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }
            Size pixelSize = PixelSnapHelpers.GetPixelSize(textView);

            foreach (Rect r in GetRectsForSegment(textView, segment))
            {
                if (AlignToWholePixels)
                {
                    AddRectangle(PixelSnapHelpers.Round(r.Left, pixelSize.Width),
                                 PixelSnapHelpers.Round(r.Top, pixelSize.Height),
                                 PixelSnapHelpers.Round(r.Right, pixelSize.Width),
                                 PixelSnapHelpers.Round(r.Bottom, pixelSize.Height));
                }
                else if (AlignToMiddleOfPixels)
                {
                    AddRectangle(PixelSnapHelpers.PixelAlign(r.Left, pixelSize.Width),
                                 PixelSnapHelpers.PixelAlign(r.Top, pixelSize.Height),
                                 PixelSnapHelpers.PixelAlign(r.Right, pixelSize.Width),
                                 PixelSnapHelpers.PixelAlign(r.Bottom, pixelSize.Height));
                }
                else
                {
                    AddRectangle(r.Left, r.Top, r.Right, r.Bottom);
                }
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (_textEditor.SelectionLength == 0 && _textEditor.CaretOffset != -1 &&
                _textEditor.CaretOffset <= textView.Document.TextLength)
            {
                var currentLine = textView.Document.GetLocation(_textEditor.CaretOffset).Line;

                var visualLine = textView.GetVisualLine(currentLine);
                if (visualLine == null)
                {
                    return;
                }

                BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();

                var linePosY   = visualLine.VisualTop - textView.ScrollOffset.Y;
                var lineBottom = linePosY + visualLine.Height;

                Size pixelSize = PixelSnapHelpers.GetPixelSize(textView);


                double x  = PixelSnapHelpers.PixelAlign(0, pixelSize.Width);
                double y  = PixelSnapHelpers.PixelAlign(linePosY, pixelSize.Height);
                var    x2 = PixelSnapHelpers.PixelAlign(textView.Bounds.Width, pixelSize.Width);
                var    y2 = PixelSnapHelpers.PixelAlign(lineBottom, pixelSize.Height);

                builder.AddRectangle(textView, new Rect(new Point(x, y), new Point(x2, y2)));

                Geometry geometry = builder.CreateGeometry();
                if (geometry != null)
                {
                    drawingContext.DrawGeometry(BackgroundBrush, BorderPen, geometry);
                }
            }
        }
        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);
                    }
                }
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            double offset     = textView.WideSpaceWidth * _column;
            Size   pixelSize  = PixelSnapHelpers.GetPixelSize(textView);
            double markerXPos = PixelSnapHelpers.PixelAlign(offset, pixelSize.Width);

            markerXPos -= textView.ScrollOffset.X;
            Point start = new Point(markerXPos, 0);
            Point end   = new Point(markerXPos, Math.Max(textView.DocumentHeight, textView.Bounds.Height));

            drawingContext.DrawLine(_pen, start, end);
        }
        public void Draw(TextView textView, System.Windows.Media.DrawingContext drawingContext)
        {
            if (column < 1)
            {
                return;
            }
            double offset     = textView.WideSpaceWidth * column;
            Size   pixelSize  = PixelSnapHelpers.GetPixelSize(textView);
            double markerXPos = PixelSnapHelpers.PixelAlign(offset, pixelSize.Width);
            Point  start      = new Point(markerXPos, 0);
            Point  end        = new Point(markerXPos, Math.Max(textView.DocumentHeight, textView.ActualHeight));

            drawingContext.DrawLine(pen, start, end);
        }
		void AddRectangle(Size pixelSize, Rect r)
		{
			if (AlignToWholePixels) {
				AddRectangle(PixelSnapHelpers.Round(r.Left, pixelSize.Width),
				             PixelSnapHelpers.Round(r.Top + 1, pixelSize.Height),
				             PixelSnapHelpers.Round(r.Right, pixelSize.Width),
				             PixelSnapHelpers.Round(r.Bottom + 1, pixelSize.Height));
			} else if (AlignToMiddleOfPixels) {
				AddRectangle(PixelSnapHelpers.PixelAlign(r.Left, pixelSize.Width),
				             PixelSnapHelpers.PixelAlign(r.Top + 1, pixelSize.Height),
				             PixelSnapHelpers.PixelAlign(r.Right, pixelSize.Width),
				             PixelSnapHelpers.PixelAlign(r.Bottom + 1, pixelSize.Height));
			} else {
				AddRectangle(r.Left, r.Top + 1, r.Right, r.Bottom + 1);
			}
		}
Beispiel #7
0
        /// <summary>
        /// Draws the lines for the folding sections (vertical line with 'color', horizontal lines with 'endMarker')
        /// Each entry in the input arrays corresponds to one TextLine.
        /// </summary>
        void DrawFoldLines(DrawingContext drawingContext, Pen[] colors, Pen[] endMarker)
        {
            // Because we are using PenLineCap.Flat (the default), for vertical lines,
            // Y coordinates must be on pixel boundaries, whereas the X coordinate must be in the
            // middle of a pixel. (and the other way round for horizontal lines)
            Size   pixelSize  = PixelSnapHelpers.GetPixelSize(this);
            double markerXPos = PixelSnapHelpers.PixelAlign(RenderSize.Width / 2, pixelSize.Width);
            double startY     = 0;
            Pen    currentPen = colors[0];
            int    tlNumber   = 0;

            foreach (VisualLine vl in TextView.VisualLines)
            {
                foreach (TextLine tl in vl.TextLines)
                {
                    if (endMarker[tlNumber] != null)
                    {
                        double visualPos = GetVisualPos(vl, tl, pixelSize.Height);
                        drawingContext.DrawLine(endMarker[tlNumber], new Point(markerXPos - pixelSize.Width / 2, visualPos), new Point(RenderSize.Width, visualPos));
                    }
                    if (colors[tlNumber + 1] != currentPen)
                    {
                        double visualPos = GetVisualPos(vl, tl, pixelSize.Height);
                        if (currentPen != null)
                        {
                            drawingContext.DrawLine(currentPen, new Point(markerXPos, startY + pixelSize.Height / 2), new Point(markerXPos, visualPos - pixelSize.Height / 2));
                        }
                        currentPen = colors[tlNumber + 1];
                        startY     = visualPos;
                    }
                    tlNumber++;
                }
            }
            if (currentPen != null)
            {
                drawingContext.DrawLine(currentPen, new Point(markerXPos, startY + pixelSize.Height / 2), new Point(markerXPos, RenderSize.Height));
            }
        }
 void AddRectangle(Size pixelSize, Rect r)
 {
     if (AlignToWholePixels)
     {
         double halfBorder = 0.5 * BorderThickness;
         AddRectangle(PixelSnapHelpers.Round(r.Left - halfBorder, pixelSize.Width) + halfBorder,
                      PixelSnapHelpers.Round(r.Top - halfBorder, pixelSize.Height) + halfBorder,
                      PixelSnapHelpers.Round(r.Right + halfBorder, pixelSize.Width) - halfBorder,
                      PixelSnapHelpers.Round(r.Bottom + halfBorder, pixelSize.Height) - halfBorder);
         //Debug.WriteLine(r.ToString() + " -> " + new Rect(lastLeft, lastTop, lastRight-lastLeft, lastBottom-lastTop).ToString());
     }
     else if (alignToMiddleOfPixels)
     {
         AddRectangle(PixelSnapHelpers.PixelAlign(r.Left, pixelSize.Width),
                      PixelSnapHelpers.PixelAlign(r.Top, pixelSize.Height),
                      PixelSnapHelpers.PixelAlign(r.Right, pixelSize.Width),
                      PixelSnapHelpers.PixelAlign(r.Bottom, pixelSize.Height));
     }
     else
     {
         AddRectangle(r.Left, r.Top, r.Right, r.Bottom);
     }
 }
Beispiel #9
0
        double GetVisualPos(VisualLine vl, TextLine tl, double pixelHeight)
        {
            double pos = vl.GetTextLineVisualYPosition(tl, VisualYPosition.LineTop) + tl.Height / 2 - TextView.VerticalOffset;

            return(PixelSnapHelpers.PixelAlign(pos, pixelHeight));
        }