示例#1
0
        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);
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        private static void RenderHighlightedTextRun(TextBox textBox, Paragraph paragraph, TextRun run, TextRun prevRun, Win32DCSafeHandle hdc, Graphics g, FontCache fontCache, float dpiX, int x, int offsetY, int baselineY, int lineHeight, Rectangle layoutRectangle, int runWidth, int prevRunWidth, int prevRunX, bool lastRunInLine, bool lastLineInParagraph)
        {
            uint?     nullable  = null;
            Rectangle?nullable2 = null;
            bool      flag      = false;
            Color     color     = run.HighlightColor;
            int       num;
            int       num2;
            bool      flag2;

            if (!color.IsEmpty)
            {
                num  = ((run.HighlightStart >= 0) ? run.HighlightStart : 0);
                num2 = ((run.HighlightEnd >= 0) ? run.HighlightEnd : runWidth);
                if (lastRunInLine)
                {
                    flag2 = (run.ScriptAnalysis.fLayoutRTL == 1);
                    if (lastLineInParagraph && runWidth != 0)
                    {
                        if (num != num2)
                        {
                            if (flag2 && run.HighlightStart < 0)
                            {
                                goto IL_0094;
                            }
                            if (!flag2 && run.HighlightEnd < 0)
                            {
                                goto IL_0094;
                            }
                        }
                    }
                    else if (runWidth == 0)
                    {
                        if (flag2)
                        {
                            num -= 5;
                        }
                        else
                        {
                            num2 += 5;
                        }
                    }
                }
                goto IL_0102;
            }
            goto IL_024e;
IL_024e:
            if (runWidth > 0)
            {
                textBox.TextBoxProps.DrawTextRun(run, paragraph, hdc, dpiX, fontCache, x, offsetY, baselineY, lineHeight, layoutRectangle);
                if (nullable.HasValue)
                {
                    textBox.TextBoxProps.DrawClippedTextRun(run, paragraph, hdc, dpiX, fontCache, x, offsetY, baselineY, lineHeight, layoutRectangle, nullable.Value, nullable2.Value);
                }
            }
            if (flag)
            {
                Rectangle empty = Rectangle.Empty;
                empty = ((!textBox.HorizontalText) ? new Rectangle(layoutRectangle.Right - offsetY, layoutRectangle.Y + x, lineHeight, prevRunWidth) : new Rectangle(layoutRectangle.X + x, layoutRectangle.Y + offsetY - lineHeight, prevRunWidth, lineHeight));
                Color color2 = prevRun.TextRunProperties.Color;
                if (run.AllowColorInversion && TextBox.NeedsColorInversion(color, color2))
                {
                    color2   = TextBox.InvertColor(color2);
                    nullable = (uint)(color2.B << 16 | color2.G << 8 | color2.R);
                }
                else
                {
                    nullable = prevRun.ColorInt;
                }
                textBox.TextBoxProps.DrawClippedTextRun(prevRun, paragraph, hdc, dpiX, fontCache, prevRunX, offsetY, baselineY, lineHeight, layoutRectangle, nullable.Value, empty);
            }
            return;

IL_0094:
            if (flag2)
            {
                num -= 5;
                int abcA = run.GetGlyphData(hdc, fontCache).ABC.abcA;
                if (abcA < 0)
                {
                    num += abcA;
                }
            }
            else
            {
                num2 += 5;
                int abcC = run.GetGlyphData(hdc, fontCache).ABC.abcC;
                if (abcC < 0)
                {
                    num2 -= abcC;
                }
            }
            goto IL_0102;
IL_0102:
            if (num != num2)
            {
                if (num == 0 && prevRun != null && (prevRun.GetGlyphData(hdc, fontCache).ABC.abcC <= 0 || run.GetGlyphData(hdc, fontCache).ABC.abcA < 0))
                {
                    flag = true;
                }
                if (run.AllowColorInversion && TextBox.NeedsColorInversion(color, textBox.TextBoxProps.BackgroundColor))
                {
                    color = TextBox.InvertColor(textBox.TextBoxProps.BackgroundColor);
                }
                using (Brush brush = new SolidBrush(color))
                {
                    nullable2 = ((!textBox.HorizontalText) ? new Rectangle?(new Rectangle(layoutRectangle.Right - offsetY, layoutRectangle.Y + x + num, lineHeight, num2 - num)) : new Rectangle?(new Rectangle(layoutRectangle.X + x + num, layoutRectangle.Y + offsetY - lineHeight, num2 - num, lineHeight)));
                    g.FillRectangle(brush, nullable2.Value);
                }
                if (run.AllowColorInversion && TextBox.NeedsColorInversion(color, run.TextRunProperties.Color))
                {
                    Color color3 = TextBox.InvertColor(run.TextRunProperties.Color);
                    nullable = (uint)(color3.B << 16 | color3.G << 8 | color3.R);
                }
            }
            run.HighlightColor = Color.Empty;
            goto IL_024e;
        }