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); } }
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); } }
private CachedFont CreateFont(ITextRunProps textRun, string key, byte charset, bool verticalFont, string fontFamily, float fontSize) { CachedFont cachedFont = new CachedFont(); m_fontDict.Add(key, cachedFont); bool bold = textRun.Bold; bool italic = textRun.Italic; bool lineThrough = textRun.TextDecoration == RPLFormat.TextDecorations.LineThrough; cachedFont.Font = CreateGdiPlusFont(fontFamily, textRun.FontSize, ref bold, ref italic, lineThrough, underLine: false); int num = 0; if (UseEmSquare) { int emHeight = cachedFont.Font.FontFamily.GetEmHeight(cachedFont.Font.Style); cachedFont.ScaleFactor = (float)emHeight / fontSize; num = emHeight; } else { num = (int)(fontSize + 0.5f); } cachedFont.Hfont = CreateGdiFont(m_writingMode, num, bold, italic, lineThrough, charset, verticalFont, cachedFont.Font.FontFamily.Name); return(cachedFont); }
internal TextRun(string text, TextRun textRun, SCRIPT_LOGATTR[] scriptLogAttr) : this(text, textRun) { SCRIPT_ANALYSIS = textRun.SCRIPT_ANALYSIS; ScriptLogAttr = scriptLogAttr; m_cachedFont = textRun.CachedFont; m_itemizedScriptId = textRun.ItemizedScriptId; bool hasEastAsianChars = HasEastAsianChars; m_runState = textRun.State; HasEastAsianChars = hasEastAsianChars; }
internal TexRunShapeData(TextRun run, bool storeGlyph) { if (storeGlyph && run.GlyphData != null) { m_glyphData = run.GlyphData.GlyphScriptShapeData; } m_analysis = run.SCRIPT_ANALYSIS; m_scriptLogAttr = run.ScriptLogAttr; m_cachedFont = run.CachedFont; m_runState = run.State; m_itemizedScriptId = run.ItemizedScriptId; }
internal CachedFont GetFont(ITextRunProps textRunProps, byte charset, float fontSize, bool verticalFont) { string fontFamily = null; float fontSize2 = 0f; string runKey = GetRunKey(textRunProps, out fontFamily, out fontSize2); string key = GetKey(runKey, charset, verticalFont, null, fontSize); CachedFont value = null; if (!m_fontDict.TryGetValue(key, out value)) { return(CreateFont(textRunProps, key, charset, verticalFont, fontFamily, fontSize)); } return(value); }
internal TextRun(string text, ITextRunProps props, TexRunShapeData shapeData) : this(text, props) { if (shapeData != null) { SCRIPT_ANALYSIS = shapeData.Analysis; ScriptLogAttr = shapeData.ScriptLogAttr; m_cachedFont = shapeData.Font; m_itemizedScriptId = shapeData.ItemizedScriptId; m_runState = shapeData.State; if (shapeData.GlyphData != null) { m_cachedGlyphData = new GlyphData(shapeData.GlyphData); } } }
private CaretInfo MapLocation(Win32DCSafeHandle hdc, TextBoxContext location, bool relativeToRun, bool moveCaretToNextLine, out TextRun run) { CaretInfo caretInfo = null; run = null; int lineYOffset; int lineHeight; int textRunCharacterIndex; bool isFirstLine; bool isLastLine; Point paragraphAndRunCoordinates = GetParagraphAndRunCoordinates(hdc, location, moveCaretToNextLine, out lineYOffset, out lineHeight, out run, out textRunCharacterIndex, out isFirstLine, out isLastLine); if (run != null) { GlyphData glyphData = run.GlyphData; GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData; int piX = 0; if (glyphData != null && run.CharacterCount > 0) { int num = Win32.ScriptCPtoX(textRunCharacterIndex, fTrailing: false, run.CharacterCount, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, glyphData.Advances, ref run.SCRIPT_ANALYSIS, ref piX); if (Win32.Failed(num)) { Marshal.ThrowExceptionForHR(num); } } caretInfo = new CaretInfo(); CachedFont cachedFont = run.GetCachedFont(hdc, FontCache); caretInfo.Height = cachedFont.GetHeight(hdc, FontCache); caretInfo.Ascent = cachedFont.GetAscent(hdc, FontCache); caretInfo.Descent = cachedFont.GetDescent(hdc, FontCache); caretInfo.LineHeight = lineHeight; caretInfo.LineYOffset = lineYOffset; caretInfo.IsFirstLine = isFirstLine; caretInfo.IsLastLine = isLastLine; _ = RTParagraphs; int y = paragraphAndRunCoordinates.Y - caretInfo.Ascent; if (relativeToRun) { caretInfo.Position = new Point(piX, y); } else { caretInfo.Position = new Point(paragraphAndRunCoordinates.X + piX, y); } } return(caretInfo); }
internal CachedFont GetFallbackFont(ITextRunProps textRunProps, byte charset, int script, bool verticalFont) { string fontFamily = null; float fontSize = 0f; string runKey = GetRunKey(textRunProps, out fontFamily, out fontSize); int value = 0; if (!ScriptFontMapping.TryGetValue(script, out value)) { value = 0; } fontFamily = FontFallback[value]; string key = GetKey(runKey, charset, verticalFont, fontFamily, null); CachedFont value2 = null; if (!m_fontDict.TryGetValue(key, out value2)) { return(CreateFont(textRunProps, key, charset, verticalFont, fontFamily, fontSize)); } return(value2); }
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); }