Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 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?     num       = null;
            Rectangle?rectangle = null;
            bool      flag      = false;
            Color     color     = run.HighlightColor;

            if (!color.IsEmpty)
            {
                int num2 = (run.HighlightStart >= 0) ? run.HighlightStart : 0;
                int num3 = (run.HighlightEnd >= 0) ? run.HighlightEnd : runWidth;
                if (lastRunInLine)
                {
                    bool flag2 = run.ScriptAnalysis.fLayoutRTL == 1;
                    if (lastLineInParagraph && runWidth != 0)
                    {
                        if (num2 != num3 && ((flag2 && run.HighlightStart < 0) || (!flag2 && run.HighlightEnd < 0)))
                        {
                            if (flag2)
                            {
                                num2 -= 5;
                                int abcA = run.GetGlyphData(hdc, fontCache).ABC.abcA;
                                if (abcA < 0)
                                {
                                    num2 += abcA;
                                }
                            }
                            else
                            {
                                num3 += 5;
                                int abcC = run.GetGlyphData(hdc, fontCache).ABC.abcC;
                                if (abcC < 0)
                                {
                                    num3 -= abcC;
                                }
                            }
                        }
                    }
                    else if (runWidth == 0)
                    {
                        if (flag2)
                        {
                            num2 -= 5;
                        }
                        else
                        {
                            num3 += 5;
                        }
                    }
                }
                if (num2 != num3)
                {
                    if (num2 == 0 && prevRun != null && (prevRun.GetGlyphData(hdc, fontCache).ABC.abcC <= 0 || run.GetGlyphData(hdc, fontCache).ABC.abcA < 0))
                    {
                        flag = true;
                    }
                    if (run.AllowColorInversion && NeedsColorInversion(color, textBox.TextBoxProps.BackgroundColor))
                    {
                        color = InvertColor(textBox.TextBoxProps.BackgroundColor);
                    }
                    using (Brush brush = new SolidBrush(color))
                    {
                        rectangle = ((!textBox.HorizontalText) ? new Rectangle?(new Rectangle(layoutRectangle.Right - offsetY, layoutRectangle.Y + x + num2, lineHeight, num3 - num2)) : new Rectangle?(new Rectangle(layoutRectangle.X + x + num2, layoutRectangle.Y + offsetY - lineHeight, num3 - num2, lineHeight)));
                        g.FillRectangle(brush, rectangle.Value);
                    }
                    if (run.AllowColorInversion && NeedsColorInversion(color, run.TextRunProperties.Color))
                    {
                        Color color2 = InvertColor(run.TextRunProperties.Color);
                        num = (uint)((color2.B << 16) | (color2.G << 8) | color2.R);
                    }
                }
                run.HighlightColor = Color.Empty;
            }
            if (runWidth > 0)
            {
                textBox.TextBoxProps.DrawTextRun(run, paragraph, hdc, dpiX, fontCache, x, offsetY, baselineY, lineHeight, layoutRectangle);
                if (num.HasValue)
                {
                    textBox.TextBoxProps.DrawClippedTextRun(run, paragraph, hdc, dpiX, fontCache, x, offsetY, baselineY, lineHeight, layoutRectangle, num.Value, rectangle.Value);
                }
            }
            if (flag)
            {
                Rectangle empty = Rectangle.Empty;
                empty = (textBox.HorizontalText ? new Rectangle(layoutRectangle.X + x, layoutRectangle.Y + offsetY - lineHeight, prevRunWidth, lineHeight) : new Rectangle(layoutRectangle.Right - offsetY, layoutRectangle.Y + x, lineHeight, prevRunWidth));
                Color color3 = prevRun.TextRunProperties.Color;
                if (!run.AllowColorInversion || !NeedsColorInversion(color, color3))
                {
                    num = prevRun.ColorInt;
                }
                else
                {
                    color3 = InvertColor(color3);
                    num    = (uint)((color3.B << 16) | (color3.G << 8) | color3.R);
                }
                textBox.TextBoxProps.DrawClippedTextRun(prevRun, paragraph, hdc, dpiX, fontCache, prevRunX, offsetY, baselineY, lineHeight, layoutRectangle, num.Value, empty);
            }
        }