public static void ExtDrawTextRun(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, int x, int baselineY, Underline underline) { uint crColor = 0u; try { uint colorInt = run.ColorInt; if (underline != null) { underline.Draw(hdc, (int)((double)run.UnderlineHeight * 0.085), colorInt); } crColor = Win32.SetTextColor(hdc, colorInt); CachedFont cachedFont = run.GetCachedFont(hdc, fontCache); fontCache.SelectFontObject(hdc, cachedFont.Hfont); int[] lpDx = null; uint fuOptions = 0u; if (run.ScriptAnalysis.fRTL == 1) { fuOptions = 128u; } if (!Win32.ExtTextOut(hdc, x, baselineY, fuOptions, IntPtr.Zero, run.Text, (uint)run.Text.Length, lpDx)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } finally { crColor = Win32.SetTextColor(hdc, crColor); } }
public static void DrawTextRun(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, int x, int baselineY, Underline underline) { uint crColor = 0u; try { uint colorInt = run.ColorInt; if (underline != null) { underline.Draw(hdc, (int)((double)run.UnderlineHeight * 0.085), colorInt); } crColor = Win32.SetTextColor(hdc, colorInt); GlyphData glyphData = run.GetGlyphData(hdc, fontCache); GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData; CachedFont cachedFont = run.GetCachedFont(hdc, fontCache); fontCache.SelectFontObject(hdc, cachedFont.Hfont); int num = Win32.ScriptTextOut(hdc, ref cachedFont.ScriptCache, x, baselineY, 4u, IntPtr.Zero, ref run.SCRIPT_ANALYSIS, IntPtr.Zero, 0, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphData.Advances, (int[])null, glyphData.GOffsets); if (Win32.Failed(num)) { Marshal.ThrowExceptionForHR(num); } } finally { crColor = Win32.SetTextColor(hdc, crColor); } }
private void TextScriptPlace(Win32DCSafeHandle hdc, bool fontSelected, FontCache fontCache) { int num = 0; GlyphShapeData glyphScriptShapeData = this.m_cachedGlyphData.GlyphScriptShapeData; if (fontSelected) { num = Win32.ScriptPlace(hdc, ref this.m_cachedFont.ScriptCache, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.VisAttrs, ref this.SCRIPT_ANALYSIS, this.m_cachedGlyphData.RawAdvances, this.m_cachedGlyphData.RawGOffsets, ref this.m_cachedGlyphData.ABC); } else { num = Win32.ScriptPlace(IntPtr.Zero, ref this.m_cachedFont.ScriptCache, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.VisAttrs, ref this.SCRIPT_ANALYSIS, this.m_cachedGlyphData.RawAdvances, this.m_cachedGlyphData.RawGOffsets, ref this.m_cachedGlyphData.ABC); if (num == -2147483638) { fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont); num = Win32.ScriptPlace(hdc, ref this.m_cachedFont.ScriptCache, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.VisAttrs, ref this.SCRIPT_ANALYSIS, this.m_cachedGlyphData.RawAdvances, this.m_cachedGlyphData.RawGOffsets, ref this.m_cachedGlyphData.ABC); } } if (Win32.Failed(num)) { Marshal.ThrowExceptionForHR(num); } if (this.m_cachedGlyphData.ABC.Width > 0 && this.m_text.Length == 1 && TextBox.IsWhitespaceControlChar(this.m_text[0])) { this.m_cachedGlyphData.ABC.SetToZeroWidth(); } }
private void Initialize(Win32DCSafeHandle hdc, FontCache fontCache) { fontCache.SelectFontObject(hdc, this.m_hfont); Win32.GetTextMetrics(hdc, out this.m_textMetric); if (this.ScaleFactor != 1.0) { this.m_textMetric.tmHeight = this.Scale(this.m_textMetric.tmHeight); this.m_textMetric.tmAscent = this.Scale(this.m_textMetric.tmAscent); this.m_textMetric.tmDescent = this.Scale(this.m_textMetric.tmDescent); this.m_textMetric.tminternalLeading = this.Scale(this.m_textMetric.tminternalLeading); } this.m_initialized = true; }
public static void DrawClippedTextRun(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, int x, int baselineY, uint fontColorOverride, Rectangle clipRect, Underline underline) { uint crColor = 0u; IntPtr intPtr = IntPtr.Zero; try { if (underline != null) { underline.Draw(hdc, (int)((double)run.UnderlineHeight * 0.085), fontColorOverride); } RECT rECT = default(RECT); rECT.left = clipRect.Left; rECT.right = clipRect.Right; rECT.top = clipRect.Top; rECT.bottom = clipRect.Bottom; crColor = Win32.SetTextColor(hdc, fontColorOverride); GlyphData glyphData = run.GetGlyphData(hdc, fontCache); GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData; CachedFont cachedFont = run.GetCachedFont(hdc, fontCache); fontCache.SelectFontObject(hdc, cachedFont.Hfont); intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(rECT)); Marshal.StructureToPtr(rECT, intPtr, false); int num = Win32.ScriptTextOut(hdc, ref cachedFont.ScriptCache, x, baselineY, 4u, intPtr, ref run.SCRIPT_ANALYSIS, IntPtr.Zero, 0, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphData.Advances, (int[])null, glyphData.GOffsets); if (Win32.Failed(num)) { Marshal.ThrowExceptionForHR(num); } } finally { if (intPtr != IntPtr.Zero) { Marshal.FreeHGlobal(intPtr); } crColor = Win32.SetTextColor(hdc, crColor); } }
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); }