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); }