internal 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 { underline?.Draw(hdc, (int)((double)run.UnderlineHeight * 0.085), fontColorOverride); RECT structure = default(RECT); structure.left = clipRect.Left; structure.right = clipRect.Right; structure.top = clipRect.Top; structure.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(structure)); Marshal.StructureToPtr(structure, intPtr, fDeleteOld: 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, null, glyphData.GOffsets); if (Win32.Failed(num)) { Marshal.ThrowExceptionForHR(num); } } finally { if (intPtr != IntPtr.Zero) { Marshal.FreeHGlobal(intPtr); } crColor = Win32.SetTextColor(hdc, crColor); } }
internal static void ExtDrawTextRun(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, int x, int baselineY, Underline underline) { uint crColor = 0u; try { uint colorInt = run.ColorInt; 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); } }
private void TextScriptPlace(Win32DCSafeHandle hdc, bool fontSelected, FontCache fontCache) { int num = 0; GlyphShapeData glyphScriptShapeData = m_cachedGlyphData.GlyphScriptShapeData; if (fontSelected) { num = Win32.ScriptPlace(hdc, ref m_cachedFont.ScriptCache, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.VisAttrs, ref SCRIPT_ANALYSIS, m_cachedGlyphData.RawAdvances, m_cachedGlyphData.RawGOffsets, ref m_cachedGlyphData.ABC); } else { num = Win32.ScriptPlace(IntPtr.Zero, ref m_cachedFont.ScriptCache, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.VisAttrs, ref SCRIPT_ANALYSIS, m_cachedGlyphData.RawAdvances, m_cachedGlyphData.RawGOffsets, ref m_cachedGlyphData.ABC); if (num == -2147483638) { fontCache.SelectFontObject(hdc, m_cachedFont.Hfont); num = Win32.ScriptPlace(hdc, ref m_cachedFont.ScriptCache, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.VisAttrs, ref SCRIPT_ANALYSIS, m_cachedGlyphData.RawAdvances, m_cachedGlyphData.RawGOffsets, ref m_cachedGlyphData.ABC); } } if (Win32.Failed(num)) { Marshal.ThrowExceptionForHR(num); } if (m_cachedGlyphData.ABC.Width > 0 && m_text.Length == 1 && TextBox.IsWhitespaceControlChar(m_text[0])) { m_cachedGlyphData.ABC.SetToZeroWidth(); } }
private void Initialize(Win32DCSafeHandle hdc, FontCache fontCache) { fontCache.SelectFontObject(hdc, m_hfont); Win32.GetTextMetrics(hdc, out m_textMetric); if (ScaleFactor != 1f) { m_textMetric.tmHeight = Scale(m_textMetric.tmHeight); m_textMetric.tmAscent = Scale(m_textMetric.tmAscent); m_textMetric.tmDescent = Scale(m_textMetric.tmDescent); m_textMetric.tminternalLeading = Scale(m_textMetric.tminternalLeading); } m_initialized = true; }
internal static void DrawTextRun(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, int x, int baselineY, Underline underline) { uint crColor = 0u; try { uint colorInt = run.ColorInt; 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, null, glyphData.GOffsets); if (Win32.Failed(num)) { Marshal.ThrowExceptionForHR(num); } } finally { crColor = Win32.SetTextColor(hdc, crColor); } }
internal void ShapeAndPlace(Win32DCSafeHandle hdc, FontCache fontCache) { bool verticalFont = false; if (fontCache.AllowVerticalFont) { verticalFont = HasEastAsianChars; } if (m_cachedFont == null) { m_cachedFont = fontCache.GetFont(m_textRunProps, GetCharset(), verticalFont); FallbackFont = false; } CachedFont cachedFont = m_cachedFont; bool flag = false; bool flag2 = false; string text = m_text; int num = Convert.ToInt32((double)text.Length * 1.5 + 16.0); m_cachedGlyphData = new GlyphData(num, text.Length); GlyphShapeData glyphScriptShapeData = m_cachedGlyphData.GlyphScriptShapeData; int num2 = Win32.ScriptShape(IntPtr.Zero, ref m_cachedFont.ScriptCache, text, text.Length, num, ref SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount); if (num2 == -2147483638) { flag = true; fontCache.SelectFontObject(hdc, m_cachedFont.Hfont); num2 = Win32.ScriptShape(hdc, ref m_cachedFont.ScriptCache, text, text.Length, num, ref SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount); } if (num2 == -2147024882) { num = text.Length * 3; m_cachedGlyphData = new GlyphData(num, text.Length); glyphScriptShapeData = m_cachedGlyphData.GlyphScriptShapeData; num2 = Win32.ScriptShape(hdc, ref m_cachedFont.ScriptCache, text, text.Length, num, ref SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount); } if (!FallbackFont) { if (num2 == -2147220992) { int num3 = 0; m_cachedFont = fontCache.GetFallbackFont(script: (!m_itemizedScriptId.HasValue) ? ScriptAnalysis.eScript : m_itemizedScriptId.Value, textRunProps: m_textRunProps, charset: GetCharset(), verticalFont: verticalFont); fontCache.SelectFontObject(hdc, m_cachedFont.Hfont); flag = true; flag2 = true; num2 = Win32.ScriptShape(hdc, ref m_cachedFont.ScriptCache, text, text.Length, num, ref SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount); } else if (HasEastAsianChars) { if (!flag) { fontCache.SelectFontObject(hdc, m_cachedFont.Hfont); flag = true; } Win32.SCRIPT_FONTPROPERTIES sfp = default(Win32.SCRIPT_FONTPROPERTIES); sfp.cBytes = 16; num2 = Win32.ScriptGetFontProperties(hdc, ref m_cachedFont.ScriptCache, ref sfp); short wgDefault = sfp.wgDefault; int num4 = 0; num4 = ((!m_itemizedScriptId.HasValue) ? ScriptAnalysis.eScript : m_itemizedScriptId.Value); for (int i = 0; i < glyphScriptShapeData.GlyphCount; i++) { if (glyphScriptShapeData.Glyphs[i] == wgDefault) { m_cachedFont = fontCache.GetFallbackFont(m_textRunProps, GetCharset(), num4, verticalFont); m_cachedFont.DefaultGlyph = wgDefault; fontCache.SelectFontObject(hdc, m_cachedFont.Hfont); flag = true; flag2 = true; num2 = Win32.ScriptShape(hdc, ref m_cachedFont.ScriptCache, text, text.Length, num, ref SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount); break; } } } } if (num2 == -2147220992) { m_cachedFont = cachedFont; if (!flag || flag2) { Win32.SelectObject(hdc, m_cachedFont.Hfont).SetHandleAsInvalid(); flag = true; } flag2 = false; SetUndefinedScript(); num2 = Win32.ScriptShape(hdc, ref m_cachedFont.ScriptCache, text, text.Length, num, ref SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount); } if (Win32.Failed(num2)) { Marshal.ThrowExceptionForHR(num2); } if (flag2) { FallbackFont = true; } m_cachedGlyphData.TrimToGlyphCount(); m_cachedGlyphData.ScaleFactor = m_cachedFont.ScaleFactor; TextScriptPlace(hdc, flag, fontCache); }