Beispiel #1
0
        public static void ExtDrawTextRun(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);
                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);
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        private CaretInfo MapLocation(Win32DCSafeHandle hdc, TextBoxContext location, bool relativeToRun, bool moveCaretToNextLine, out TextRun run)
        {
            CaretInfo caretInfo = null;

            run = null;
            int   lineYOffset = default(int);
            int   lineHeight  = default(int);
            int   iCP         = default(int);
            bool  isFirstLine = default(bool);
            bool  isLastLine  = default(bool);
            Point paragraphAndRunCoordinates = this.GetParagraphAndRunCoordinates(hdc, location, moveCaretToNextLine, out lineYOffset, out lineHeight, out run, out iCP, out isFirstLine, out isLastLine);

            if (run != null)
            {
                GlyphData      glyphData            = run.GlyphData;
                GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData;
                int            num = 0;
                if (glyphData != null && run.CharacterCount > 0)
                {
                    int num2 = Win32.ScriptCPtoX(iCP, false, run.CharacterCount, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, glyphData.Advances, ref run.SCRIPT_ANALYSIS, ref num);
                    if (Win32.Failed(num2))
                    {
                        Marshal.ThrowExceptionForHR(num2);
                    }
                }
                caretInfo = new CaretInfo();
                CachedFont cachedFont = run.GetCachedFont(hdc, this.FontCache);
                caretInfo.Height      = cachedFont.GetHeight(hdc, this.FontCache);
                caretInfo.Ascent      = cachedFont.GetAscent(hdc, this.FontCache);
                caretInfo.Descent     = cachedFont.GetDescent(hdc, this.FontCache);
                caretInfo.LineHeight  = lineHeight;
                caretInfo.LineYOffset = lineYOffset;
                caretInfo.IsFirstLine = isFirstLine;
                caretInfo.IsLastLine  = isLastLine;
                List <Paragraph> rTParagraph = this.RTParagraphs;
                int y = paragraphAndRunCoordinates.Y - caretInfo.Ascent;
                if (relativeToRun)
                {
                    caretInfo.Position = new Point(num, y);
                }
                else
                {
                    caretInfo.Position = new Point(paragraphAndRunCoordinates.X + num, y);
                }
            }
            return(caretInfo);
        }
Beispiel #4
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);
            }
        }