internal void Draw(Win32DCSafeHandle hdc, int lineThickness, uint rgbColor) { if (lineThickness < 1) { lineThickness = 1; } Win32.LOGBRUSH lplb = default(Win32.LOGBRUSH); lplb.lbColor = rgbColor; lplb.lbHatch = 0; lplb.lbStyle = 0u; Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.ExtCreatePen(66048u, (uint)lineThickness, ref lplb, 0u, null); Win32ObjectSafeHandle win32ObjectSafeHandle2 = Win32ObjectSafeHandle.Zero; try { win32ObjectSafeHandle2 = Win32.SelectObject(hdc, win32ObjectSafeHandle); Win32.MoveToEx(hdc, m_startPoint.X, m_startPoint.Y, IntPtr.Zero); Win32.LineTo(hdc, m_endPoint.X, m_endPoint.Y); } finally { if (!win32ObjectSafeHandle2.IsInvalid) { Win32.SelectObject(hdc, win32ObjectSafeHandle2).SetHandleAsInvalid(); win32ObjectSafeHandle2.SetHandleAsInvalid(); } if (!win32ObjectSafeHandle.IsInvalid) { win32ObjectSafeHandle.Close(); win32ObjectSafeHandle = null; } } }
internal void Render(Graphics g, RectangleF rectangle, PointF offset, IEnumerable <RTSelectionHighlight> highlights, bool unitsInMM) { List <Paragraph> rTParagraphs = RTParagraphs; if (rTParagraphs == null || rTParagraphs.Count == 0) { return; } using (RevertingDeviceContext revertingDeviceContext = new RevertingDeviceContext(g, Dpi)) { Win32DCSafeHandle hdc = revertingDeviceContext.Hdc; if (highlights != null) { _ = RTTextbox.TextBoxProps.Direction; foreach (RTSelectionHighlight highlight in highlights) { if (!HighlightStartLessThanOrEqualToEnd(highlight.SelectionStart, highlight.SelectionEnd)) { TextBoxContext selectionStart = highlight.SelectionStart; highlight.SelectionStart = highlight.SelectionEnd; highlight.SelectionEnd = selectionStart; } TextRun run; CaretInfo caretInfo = MapLocation(hdc, highlight.SelectionStart, relativeToRun: true, moveCaretToNextLine: true, out run); TextRun run2; CaretInfo caretInfo2 = MapLocation(hdc, highlight.SelectionEnd, relativeToRun: true, moveCaretToNextLine: true, out run2); if (caretInfo != null && caretInfo2 != null && run != null && run2 != null) { SetHighlighting(rTParagraphs, hdc, highlight, run, run2, caretInfo.Position.X, caretInfo2.Position.X); } } } Rectangle rect = (!unitsInMM) ? Rectangle.Round(rectangle) : new Rectangle(TextBox.ConvertToPixels(rectangle.X, m_dpi), TextBox.ConvertToPixels(rectangle.Y, m_dpi), TextBox.ConvertToPixels(rectangle.Width, m_dpi), TextBox.ConvertToPixels(rectangle.Height, m_dpi)); revertingDeviceContext.XForm.Transform(ref rect); Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.CreateRectRgn(rect.Left - 1, rect.Top - 1, rect.Right + 1, rect.Bottom + 1); if (!win32ObjectSafeHandle.IsInvalid) { try { if (Win32.SelectClipRgn(hdc, win32ObjectSafeHandle) == 0) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } finally { win32ObjectSafeHandle.Close(); } } TextBox.Render(RTTextbox, rTParagraphs, hdc, FontCache, offset, rectangle, m_dpi, unitsInMM); if (Win32.SelectClipRgn(hdc, Win32ObjectSafeHandle.Zero) == 0) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } }
private void Dispose(bool disposing) { if (disposing && m_font != null) { m_font.Dispose(); m_font = null; } if (m_hfont != null && !m_hfont.IsInvalid) { m_hfont.Close(); m_hfont = null; } ScriptCache.Close(); }