/// <summary> /// Gets the line layout for a given line. /// </summary> /// <param name="lineIndex">The line.</param> /// <param name="lineContexts">The line contexts.</param> /// <returns></returns> public virtual Layout GetLineLayout( int lineIndex, LineContexts lineContexts) { // Get the layout. var layout = new Layout(DisplayContext.PangoContext); // Assign the given style to the layout. LineBlockStyle style = GetLineStyle(lineIndex, lineContexts); DisplayContext.SetLayout(layout, style, DisplayContext.TextWidth); // Set the markup and return. string markup = GetSelectionMarkup(lineIndex, lineContexts); string coloredMarkup = DrawingUtility.WrapColorMarkup( markup, style.GetForegroundColor()); layout.SetMarkup(coloredMarkup); return(layout); }
/// <summary> /// Draws the margin at the given position. /// </summary> /// <param name="displayContext">The display context.</param> /// <param name="renderContext">The render context.</param> /// <param name="lineIndex">The line index being rendered.</param> /// <param name="point">The point of the specific line number.</param> /// <param name="height">The height of the rendered line.</param> /// <param name="lineBlockStyle"></param> public override void Draw( IDisplayContext displayContext, IRenderContext renderContext, int lineIndex, PointD point, double height, LineBlockStyle lineBlockStyle) { // Figure out the style we need to use. MarginBlockStyle style = lineBlockStyle.MarginStyles.Get(Theme.LineNumberStyle); // Create a layout object if we don't have one. if (layout == null) { layout = new Layout(displayContext.PangoContext); displayContext.SetLayout(layout, style, Width); } // Figure out the line number. string lineNumber = displayContext.LineBuffer.GetLineNumber(lineIndex); if (string.IsNullOrEmpty(lineNumber)) { lineNumber = String.Empty; } // Wrap the text in a markup that includes the foreground color. string markup = DrawingUtility.WrapColorMarkup( lineNumber, style.GetForegroundColor()); layout.SetMarkup(markup); // Figure out if the current width of the margin is wider than what // we've already calculated. if (lineNumber.Length > maximumCharactersRendered) { // Get the new width as if we don't have line-wrapping. int layoutWidth, layoutHeight; layout.Width = Int32.MaxValue; layout.GetSize(out layoutWidth, out layoutHeight); // Set the layout width so we don't have to redo the entire // layout and update our margin width (including style). layout.Width = layoutWidth; SetWidth((int)(Units.ToPixels(layoutWidth) + style.Width)); // Since we are looking at a large length of line number, update // it so we don't continually calculate the line width. maximumCharactersRendered = lineNumber.Length; // Request a full redraw since this will change even the lines // we already drew. We draw the line anyways to avoid seeing a // white block. displayContext.RequestScrollToCaret(); displayContext.RequestRedraw(); } // Use the common drawing routine to handle the borders and padding. DrawingUtility.DrawLayout( displayContext, renderContext, new Rectangle(point.X, point.Y, Width, height), layout, style); }