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 static void Render(TextBox textBox, List <Paragraph> paragraphs, Win32DCSafeHandle hdc, FontCache fontCache, PointF offset, RectangleF layoutRectangle, float dpiX, bool unitsInMM) { if (paragraphs == null || paragraphs.Count == 0) { return; } Rectangle layoutRectangle2; Point point; if (!unitsInMM) { layoutRectangle2 = new Rectangle((int)layoutRectangle.X, (int)layoutRectangle.Y, (int)layoutRectangle.Width, (int)layoutRectangle.Height); point = new Point((int)offset.X, (int)offset.Y); } else { layoutRectangle2 = new Rectangle(ConvertToPixels(layoutRectangle.X, dpiX), ConvertToPixels(layoutRectangle.Y, dpiX), ConvertToPixels(layoutRectangle.Width, dpiX), ConvertToPixels(layoutRectangle.Height, dpiX)); point = new Point(ConvertToPixels(offset.X, dpiX), ConvertToPixels(offset.Y, dpiX)); } uint fMode = Win32.SetTextAlign(hdc, 24u); int iBkMode = Win32.SetBkMode(hdc, 1); Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, Win32ObjectSafeHandle.Zero); try { fontCache.WritingMode = textBox.TextBoxProps.WritingMode; int offsetY = point.Y; for (int i = 0; i < paragraphs.Count; i++) { RenderParagraph(textBox, paragraphs[i], hdc, fontCache, point.X, ref offsetY, layoutRectangle2, dpiX); } } finally { fMode = Win32.SetTextAlign(hdc, fMode); iBkMode = Win32.SetBkMode(hdc, iBkMode); if (!win32ObjectSafeHandle.IsInvalid) { Win32.SelectObject(hdc, win32ObjectSafeHandle).SetHandleAsInvalid(); win32ObjectSafeHandle.SetHandleAsInvalid(); } } }
internal static List <Paragraph> Flow(TextBox textBox, Win32DCSafeHandle hdc, float dpiX, FontCache fontCache, FlowContext flowContext, bool keepLines, out float height) { if (flowContext.Height <= 0f || flowContext.Width <= 0f) { height = 0f; return(null); } int num = TextBox.ConvertToPixels(flowContext.ContentOffset, dpiX); int contentOffset = num; TextBoxContext context = flowContext.Context; RPLFormat.Directions direction = textBox.TextBoxProps.Direction; List <Paragraph> list = new List <Paragraph>(); Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, Win32ObjectSafeHandle.Zero); SizeF flowContextSize; if (!textBox.VerticalText) { flowContextSize = new SizeF(TextBox.ConvertToPixels(flowContext.Width, dpiX), TextBox.ConvertToPixels(flowContext.Height, dpiX)); } else { flowContext.VerticalCanGrow = textBox.TextBoxProps.CanGrow; flowContextSize = new SizeF(TextBox.ConvertToPixels(flowContext.Height, dpiX), TextBox.ConvertToPixels(flowContext.Width, dpiX)); } fontCache.WritingMode = textBox.TextBoxProps.WritingMode; try { while (context.ParagraphIndex < textBox.Paragraphs.Count) { Paragraph paragraph = textBox.Paragraphs[context.ParagraphIndex]; paragraph.OffsetY = num; bool num2 = FlowParagraph(paragraph, direction, hdc, dpiX, fontCache, flowContext, keepLines, flowContextSize, ref contentOffset); num += paragraph.Height; if (!keepLines) { paragraph.TextLines = null; } if (!num2) { break; } list.Add(paragraph); if ((float)num >= flowContextSize.Height) { if (paragraph.AtEndOfParagraph(context)) { context.IncrementParagraph(); } break; } context.IncrementParagraph(); } if ((float)num < flowContextSize.Height) { flowContext.AtEndOfTextBox = true; } } finally { if (!win32ObjectSafeHandle.IsInvalid) { Win32.SelectObject(hdc, win32ObjectSafeHandle).SetHandleAsInvalid(); win32ObjectSafeHandle.SetHandleAsInvalid(); } } height = TextBox.ConvertToMillimeters(num, dpiX); flowContext.ContentOffset = TextBox.ConvertToMillimeters(contentOffset, dpiX); return(list); }