public void Draw(Win32DCSafeHandle hdc, int lineThickness, uint rgbColor) { if (lineThickness < 1) { lineThickness = 1; } Win32.LOGBRUSH lOGBRUSH = default(Win32.LOGBRUSH); lOGBRUSH.lbColor = rgbColor; lOGBRUSH.lbHatch = 0; lOGBRUSH.lbStyle = 0u; Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.ExtCreatePen(66048u, (uint)lineThickness, ref lOGBRUSH, 0u, null); Win32ObjectSafeHandle win32ObjectSafeHandle2 = Win32ObjectSafeHandle.Zero; try { win32ObjectSafeHandle2 = Win32.SelectObject(hdc, win32ObjectSafeHandle); Win32.MoveToEx(hdc, this.m_startPoint.X, this.m_startPoint.Y, IntPtr.Zero); Win32.LineTo(hdc, this.m_endPoint.X, this.m_endPoint.Y); } finally { if (!win32ObjectSafeHandle2.IsInvalid) { Win32ObjectSafeHandle win32ObjectSafeHandle3 = Win32.SelectObject(hdc, win32ObjectSafeHandle2); win32ObjectSafeHandle3.SetHandleAsInvalid(); win32ObjectSafeHandle2.SetHandleAsInvalid(); } if (!win32ObjectSafeHandle.IsInvalid) { win32ObjectSafeHandle.Close(); win32ObjectSafeHandle = null; } } }
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 void SelectFontObject(Win32DCSafeHandle hdc, Win32ObjectSafeHandle hFont) { if (hdc != this.m_selectedHdc) { this.m_selectedHdc = hdc; this.m_selectedFont = Win32ObjectSafeHandle.Zero; } if (hFont != this.m_selectedFont) { Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, hFont); win32ObjectSafeHandle.SetHandleAsInvalid(); this.m_selectedFont = hFont; } }
private void Dispose(bool disposing) { if (disposing && this.m_font != null) { this.m_font.Dispose(); this.m_font = null; } if (this.m_hfont != null && !this.m_hfont.IsInvalid) { this.m_hfont.Close(); this.m_hfont = null; } this.ScriptCache.Close(); }
public 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) { Rectangle layoutRectangle2; Point point; if (unitsInMM) { layoutRectangle2 = new Rectangle(TextBox.ConvertToPixels(layoutRectangle.X, dpiX), TextBox.ConvertToPixels(layoutRectangle.Y, dpiX), TextBox.ConvertToPixels(layoutRectangle.Width, dpiX), TextBox.ConvertToPixels(layoutRectangle.Height, dpiX)); point = new Point(TextBox.ConvertToPixels(offset.X, dpiX), TextBox.ConvertToPixels(offset.Y, dpiX)); } else { layoutRectangle2 = new Rectangle((int)layoutRectangle.X, (int)layoutRectangle.Y, (int)layoutRectangle.Width, (int)layoutRectangle.Height); point = new Point((int)offset.X, (int)offset.Y); } 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 y = point.Y; for (int i = 0; i < paragraphs.Count; i++) { TextBox.RenderParagraph(textBox, paragraphs[i], hdc, fontCache, point.X, ref y, layoutRectangle2, dpiX); } } finally { fMode = Win32.SetTextAlign(hdc, fMode); iBkMode = Win32.SetBkMode(hdc, iBkMode); if (!win32ObjectSafeHandle.IsInvalid) { Win32ObjectSafeHandle win32ObjectSafeHandle2 = Win32.SelectObject(hdc, win32ObjectSafeHandle); win32ObjectSafeHandle2.SetHandleAsInvalid(); win32ObjectSafeHandle.SetHandleAsInvalid(); } } } }
public void ResetGraphics() { this.m_selectedHdc = Win32DCSafeHandle.Zero; this.m_selectedFont = Win32ObjectSafeHandle.Zero; }
public static extern int SelectClipRgn(Win32DCSafeHandle hdc, Win32ObjectSafeHandle hrgn);
public static extern bool SetViewportOrgEx(Win32DCSafeHandle hdc, int X, int Y, Win32ObjectSafeHandle lpPoint);
public static extern int DeleteObject(Win32ObjectSafeHandle hObject);
public static extern Win32ObjectSafeHandle SelectObject(Win32DCSafeHandle hDC, Win32ObjectSafeHandle gdiobj);
public static List <Paragraph> Flow(TextBox textBox, Win32DCSafeHandle hdc, float dpiX, FontCache fontCache, FlowContext flowContext, bool keepLines, out float height) { if (!(flowContext.Height <= 0.0) && !(flowContext.Width <= 0.0)) { int num = TextBox.ConvertToPixels(flowContext.ContentOffset, dpiX); int pixels = 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) { flowContext.VerticalCanGrow = textBox.TextBoxProps.CanGrow; flowContextSize = new SizeF((float)TextBox.ConvertToPixels(flowContext.Height, dpiX), (float)TextBox.ConvertToPixels(flowContext.Width, dpiX)); } else { flowContextSize = new SizeF((float)TextBox.ConvertToPixels(flowContext.Width, dpiX), (float)TextBox.ConvertToPixels(flowContext.Height, dpiX)); } fontCache.WritingMode = textBox.TextBoxProps.WritingMode; try { while (context.ParagraphIndex < textBox.Paragraphs.Count) { Paragraph paragraph = textBox.Paragraphs[context.ParagraphIndex]; paragraph.OffsetY = num; bool flag = LineBreaker.FlowParagraph(paragraph, direction, hdc, dpiX, fontCache, flowContext, keepLines, flowContextSize, ref pixels); num += paragraph.Height; if (!keepLines) { paragraph.TextLines = null; } if (!flag) { 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) { Win32ObjectSafeHandle win32ObjectSafeHandle2 = Win32.SelectObject(hdc, win32ObjectSafeHandle); win32ObjectSafeHandle2.SetHandleAsInvalid(); win32ObjectSafeHandle.SetHandleAsInvalid(); } } height = TextBox.ConvertToMillimeters(num, dpiX); flowContext.ContentOffset = TextBox.ConvertToMillimeters(pixels, dpiX); return(list); } height = 0f; return(null); }
public void ShapeAndPlace(Win32DCSafeHandle hdc, FontCache fontCache) { bool verticalFont = false; if (fontCache.AllowVerticalFont) { verticalFont = this.HasEastAsianChars; } if (this.m_cachedFont == null) { this.m_cachedFont = fontCache.GetFont(this.m_textRunProps, this.GetCharset(), verticalFont); this.FallbackFont = false; } CachedFont cachedFont = this.m_cachedFont; bool flag = false; bool flag2 = false; string text = this.m_text; int num = Convert.ToInt32((double)text.Length * 1.5 + 16.0); this.m_cachedGlyphData = new GlyphData(num, text.Length); GlyphShapeData glyphScriptShapeData = this.m_cachedGlyphData.GlyphScriptShapeData; int num2 = Win32.ScriptShape(IntPtr.Zero, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount); if (num2 == -2147483638) { flag = true; fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont); num2 = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount); } if (num2 == -2147024882) { num = text.Length * 3; this.m_cachedGlyphData = new GlyphData(num, text.Length); glyphScriptShapeData = this.m_cachedGlyphData.GlyphScriptShapeData; num2 = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount); } if (!this.FallbackFont) { if (num2 == -2147220992) { int num3 = 0; num3 = ((!this.m_itemizedScriptId.HasValue) ? this.ScriptAnalysis.eScript : this.m_itemizedScriptId.Value); this.m_cachedFont = fontCache.GetFallbackFont(this.m_textRunProps, this.GetCharset(), num3, verticalFont); fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont); flag = true; flag2 = true; num2 = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount); } else if (this.HasEastAsianChars) { if (!flag) { fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont); flag = true; } Win32.SCRIPT_FONTPROPERTIES sCRIPT_FONTPROPERTIES = default(Win32.SCRIPT_FONTPROPERTIES); sCRIPT_FONTPROPERTIES.cBytes = 16; num2 = Win32.ScriptGetFontProperties(hdc, ref this.m_cachedFont.ScriptCache, ref sCRIPT_FONTPROPERTIES); short wgDefault = sCRIPT_FONTPROPERTIES.wgDefault; int num4 = 0; num4 = ((!this.m_itemizedScriptId.HasValue) ? this.ScriptAnalysis.eScript : this.m_itemizedScriptId.Value); int num5 = 0; while (num5 < glyphScriptShapeData.GlyphCount) { if (glyphScriptShapeData.Glyphs[num5] != wgDefault) { num5++; continue; } this.m_cachedFont = fontCache.GetFallbackFont(this.m_textRunProps, this.GetCharset(), num4, verticalFont); this.m_cachedFont.DefaultGlyph = wgDefault; fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont); flag = true; flag2 = true; num2 = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount); break; } } } if (num2 == -2147220992) { this.m_cachedFont = cachedFont; if (!flag || flag2) { Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, this.m_cachedFont.Hfont); win32ObjectSafeHandle.SetHandleAsInvalid(); flag = true; } flag2 = false; this.SetUndefinedScript(); num2 = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount); } if (Win32.Failed(num2)) { Marshal.ThrowExceptionForHR(num2); } if (flag2) { this.FallbackFont = true; } this.m_cachedGlyphData.TrimToGlyphCount(); this.m_cachedGlyphData.ScaleFactor = this.m_cachedFont.ScaleFactor; this.TextScriptPlace(hdc, flag, fontCache); }