public void Render(Graphics g, RectangleF rectangle, PointF offset, IEnumerable <RTSelectionHighlight> highlights, bool unitsInMM) { List <Paragraph> rTParagraphs = this.RTParagraphs; if (rTParagraphs != null && rTParagraphs.Count != 0) { using (RevertingDeviceContext revertingDeviceContext = new RevertingDeviceContext(g, this.Dpi)) { Win32DCSafeHandle hdc = revertingDeviceContext.Hdc; if (highlights != null) { RPLFormat.Directions direction = this.RTTextbox.TextBoxProps.Direction; foreach (RTSelectionHighlight highlight in highlights) { if (!RichTextRenderer.HighlightStartLessThanOrEqualToEnd(highlight.SelectionStart, highlight.SelectionEnd)) { TextBoxContext selectionStart = highlight.SelectionStart; highlight.SelectionStart = highlight.SelectionEnd; highlight.SelectionEnd = selectionStart; } TextRun textRun = default(TextRun); CaretInfo caretInfo = this.MapLocation(hdc, highlight.SelectionStart, true, true, out textRun); TextRun textRun2 = default(TextRun); CaretInfo caretInfo2 = this.MapLocation(hdc, highlight.SelectionEnd, true, true, out textRun2); if (caretInfo != null && caretInfo2 != null && textRun != null && textRun2 != null) { this.SetHighlighting(rTParagraphs, hdc, highlight, textRun, textRun2, caretInfo.Position.X, caretInfo2.Position.X); } } } Rectangle rectangle2 = (!unitsInMM) ? Rectangle.Round(rectangle) : new Rectangle(TextBox.ConvertToPixels(rectangle.X, this.m_dpi), TextBox.ConvertToPixels(rectangle.Y, this.m_dpi), TextBox.ConvertToPixels(rectangle.Width, this.m_dpi), TextBox.ConvertToPixels(rectangle.Height, this.m_dpi)); revertingDeviceContext.XForm.Transform(ref rectangle2); Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.CreateRectRgn(rectangle2.Left - 1, rectangle2.Top - 1, rectangle2.Right + 1, rectangle2.Bottom + 1); if (!win32ObjectSafeHandle.IsInvalid) { try { if (Win32.SelectClipRgn(hdc, win32ObjectSafeHandle) == 0) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } finally { win32ObjectSafeHandle.Close(); } } TextBox.Render(this.RTTextbox, rTParagraphs, hdc, this.FontCache, offset, rectangle, this.m_dpi, unitsInMM); if (Win32.SelectClipRgn(hdc, Win32ObjectSafeHandle.Zero) == 0) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } } }
public static void Render(TextBox textBox, List <Paragraph> paragraphs, Graphics g, FontCache fontCache, PointF offset, RectangleF layoutRectangle) { float dpiX = g.DpiX; Win32DCSafeHandle win32DCSafeHandle = new Win32DCSafeHandle(g.GetHdc(), false); try { TextBox.Render(textBox, paragraphs, win32DCSafeHandle, fontCache, offset, layoutRectangle, dpiX); } finally { fontCache.ResetGraphics(); if (!win32DCSafeHandle.IsInvalid) { g.ReleaseHdc(); } } }
public static void Render(TextBox textBox, List <Paragraph> paragraphs, Win32DCSafeHandle hdc, FontCache fontCache, PointF offset, RectangleF layoutRectangle, float dpiX) { TextBox.Render(textBox, paragraphs, hdc, fontCache, offset, layoutRectangle, dpiX, true); }