Example #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);
            }
        }
Example #2
0
        private void TextScriptPlace(Win32DCSafeHandle hdc, bool fontSelected, FontCache fontCache)
        {
            int            num = 0;
            GlyphShapeData glyphScriptShapeData = m_cachedGlyphData.GlyphScriptShapeData;

            if (fontSelected)
            {
                num = Win32.ScriptPlace(hdc, ref m_cachedFont.ScriptCache, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.VisAttrs, ref SCRIPT_ANALYSIS, m_cachedGlyphData.RawAdvances, m_cachedGlyphData.RawGOffsets, ref m_cachedGlyphData.ABC);
            }
            else
            {
                num = Win32.ScriptPlace(IntPtr.Zero, ref m_cachedFont.ScriptCache, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.VisAttrs, ref SCRIPT_ANALYSIS, m_cachedGlyphData.RawAdvances, m_cachedGlyphData.RawGOffsets, ref m_cachedGlyphData.ABC);
                if (num == -2147483638)
                {
                    fontCache.SelectFontObject(hdc, m_cachedFont.Hfont);
                    num = Win32.ScriptPlace(hdc, ref m_cachedFont.ScriptCache, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.VisAttrs, ref SCRIPT_ANALYSIS, m_cachedGlyphData.RawAdvances, m_cachedGlyphData.RawGOffsets, ref m_cachedGlyphData.ABC);
                }
            }
            if (Win32.Failed(num))
            {
                Marshal.ThrowExceptionForHR(num);
            }
            if (m_cachedGlyphData.ABC.Width > 0 && m_text.Length == 1 && TextBox.IsWhitespaceControlChar(m_text[0]))
            {
                m_cachedGlyphData.ABC.SetToZeroWidth();
            }
        }
Example #3
0
        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);
            }
        }
Example #4
0
 internal int GetLeading(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (!m_initialized)
     {
         Initialize(hdc, fontCache);
     }
     return(m_textMetric.tminternalLeading);
 }
Example #5
0
 internal int GetDescent(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (!m_initialized)
     {
         Initialize(hdc, fontCache);
     }
     return(m_textMetric.tmDescent);
 }
Example #6
0
 public void Dispose()
 {
     if (m_fontCache != null)
     {
         m_fontCache.Dispose();
         m_fontCache = null;
     }
     GC.SuppressFinalize(this);
 }
Example #7
0
 internal int GetPrefixWidth(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (m_prefix == null)
     {
         return(0);
     }
     CalculateDimensions(hdc, fontCache, useVisualRunsIfAvailable: true);
     return(m_prefixWidth);
 }
Example #8
0
 private void LoadGlyphData(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (!m_clone && m_cachedGlyphData.NeedGlyphPlaceData)
     {
         m_cachedGlyphData.NeedGlyphPlaceData = false;
         m_cachedGlyphData.ScaleFactor        = m_cachedFont.ScaleFactor;
         TextScriptPlace(hdc, fontSelected: false, fontCache);
     }
 }
Example #9
0
 internal GlyphData GetGlyphData(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (m_cachedGlyphData == null)
     {
         ShapeAndPlace(hdc, fontCache);
     }
     else
     {
         LoadGlyphData(hdc, fontCache);
     }
     return(m_cachedGlyphData);
 }
Example #10
0
 internal int GetWidth(Win32DCSafeHandle hdc, FontCache fontCache, bool isAtLineEnd)
 {
     if (m_cachedGlyphData == null)
     {
         ShapeAndPlace(hdc, fontCache);
     }
     else
     {
         LoadGlyphData(hdc, fontCache);
     }
     return(m_cachedGlyphData.GetTotalWidth(isAtLineEnd));
 }
Example #11
0
 private void Initialize(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     fontCache.SelectFontObject(hdc, m_hfont);
     Win32.GetTextMetrics(hdc, out m_textMetric);
     if (ScaleFactor != 1f)
     {
         m_textMetric.tmHeight          = Scale(m_textMetric.tmHeight);
         m_textMetric.tmAscent          = Scale(m_textMetric.tmAscent);
         m_textMetric.tmDescent         = Scale(m_textMetric.tmDescent);
         m_textMetric.tminternalLeading = Scale(m_textMetric.tminternalLeading);
     }
     m_initialized = true;
 }
Example #12
0
        internal static List <Paragraph> Flow(TextBox textBox, Graphics g, FontCache fontCache, FlowContext flowContext, bool keepLines, out float height)
        {
            List <Paragraph>  list = null;
            float             dpiX = g.DpiX;
            Win32DCSafeHandle win32DCSafeHandle = new Win32DCSafeHandle(g.GetHdc(), ownsHandle: false);

            try
            {
                return(Flow(textBox, win32DCSafeHandle, dpiX, fontCache, flowContext, keepLines, out height));
            }
            finally
            {
                fontCache.ResetGraphics();
                if (!win32DCSafeHandle.IsInvalid)
                {
                    g.ReleaseHdc();
                }
            }
        }
Example #13
0
        internal int[] GetLogicalWidths(Win32DCSafeHandle hdc, FontCache fontCache)
        {
            GlyphData glyphData = GetGlyphData(hdc, fontCache);

            int[] array = new int[m_text.Length];
            int   num   = Win32.ScriptGetLogicalWidths(ref SCRIPT_ANALYSIS, m_text.Length, glyphData.GlyphScriptShapeData.GlyphCount, glyphData.ScaledAdvances, glyphData.GlyphScriptShapeData.Clusters, glyphData.GlyphScriptShapeData.VisAttrs, array);

            if (Win32.Failed(num))
            {
                Marshal.ThrowExceptionForHR(num);
            }
            if (glyphData.Scaled)
            {
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = glyphData.Scale(array[i]);
                }
            }
            return(array);
        }
Example #14
0
 internal int GetHeight(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (!m_calculatedHeight)
     {
         m_calculatedHeight = true;
         for (int i = 0; i < m_logicalRuns.Count; i++)
         {
             TextRun textRun = m_logicalRuns[i];
             int     ascent  = textRun.GetAscent(hdc, fontCache);
             if (ascent > m_ascent)
             {
                 m_ascent = ascent;
             }
             int descent = textRun.GetDescent(hdc, fontCache);
             if (descent > m_descent)
             {
                 m_descent = descent;
             }
         }
         if (m_prefix != null)
         {
             for (int j = 0; j < m_prefix.Count; j++)
             {
                 TextRun textRun2 = m_prefix[j];
                 int     ascent2  = textRun2.GetAscent(hdc, fontCache);
                 if (ascent2 > m_ascent)
                 {
                     m_ascent = ascent2;
                 }
                 int descent2 = textRun2.GetDescent(hdc, fontCache);
                 if (descent2 > m_descent)
                 {
                     m_descent = descent2;
                 }
             }
         }
     }
     return(m_ascent + m_descent);
 }
Example #15
0
        internal Underline(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, Rectangle layoutRectangle, int x, int baselineY, RPLFormat.WritingModes writingMode)
        {
            int width = run.GetWidth(hdc, fontCache);
            int num   = (int)((double)(int)((double)run.UnderlineHeight * 0.085) * 1.5);

            switch (writingMode)
            {
            case RPLFormat.WritingModes.Horizontal:
                m_startPoint = new Point(layoutRectangle.X + x, layoutRectangle.Y + baselineY + num);
                m_endPoint   = new Point(Math.Min(m_startPoint.X + width, layoutRectangle.Right), m_startPoint.Y);
                break;

            case RPLFormat.WritingModes.Vertical:
                m_startPoint = new Point(layoutRectangle.Right - baselineY - num - 1, layoutRectangle.Y + x);
                m_endPoint   = new Point(m_startPoint.X, Math.Min(m_startPoint.Y + width, layoutRectangle.Bottom));
                break;

            case RPLFormat.WritingModes.Rotate270:
                m_startPoint = new Point(layoutRectangle.X + baselineY + num, layoutRectangle.Bottom - x);
                m_endPoint   = new Point(m_startPoint.X, Math.Max(m_startPoint.Y - width, layoutRectangle.Top));
                break;
            }
        }
Example #16
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);
            }
        }
Example #17
0
        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);
        }
Example #18
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);
            }
        }
Example #19
0
        private static void RenderParagraph(TextBox textBox, Paragraph paragraph, Win32DCSafeHandle hdc, FontCache fontCache, int offsetX, ref int offsetY, Rectangle layoutRectangle, float dpiX)
        {
            List <TextLine> textLines      = paragraph.TextLines;
            IParagraphProps paragraphProps = paragraph.ParagraphProps;
            bool            flag           = textBox.TextBoxProps.Direction == RPLFormat.Directions.LTR;

            RPLFormat.TextAlignments textAlignments = paragraphProps.Alignment;
            if (textAlignments == RPLFormat.TextAlignments.General)
            {
                textAlignments = textBox.TextBoxProps.DefaultAlignment;
                if (!flag)
                {
                    switch (textAlignments)
                    {
                    case RPLFormat.TextAlignments.Right:
                        textAlignments = RPLFormat.TextAlignments.Left;
                        break;

                    case RPLFormat.TextAlignments.Left:
                        textAlignments = RPLFormat.TextAlignments.Right;
                        break;
                    }
                }
            }
            int num  = ConvertToPixels(paragraphProps.LeftIndent, dpiX);
            int num2 = ConvertToPixels(paragraphProps.RightIndent, dpiX);
            int num3 = ConvertToPixels(paragraphProps.HangingIndent, dpiX);

            if (num3 < 0)
            {
                if (flag)
                {
                    num -= num3;
                }
                else
                {
                    num2 -= num3;
                }
            }
            if (paragraphProps.ListLevel > 0)
            {
                int num4 = paragraphProps.ListLevel * ConvertToPixels(10.583333f, dpiX);
                if (flag)
                {
                    num += num4;
                }
                else
                {
                    num2 += num4;
                }
            }
            if (textLines == null || textLines.Count == 0)
            {
                offsetY += ConvertToPixels(paragraphProps.SpaceBefore, dpiX);
                offsetY += ConvertToPixels(paragraphProps.SpaceAfter, dpiX);
                return;
            }
            Graphics graphics = null;

            try
            {
                for (int i = 0; i < textLines.Count; i++)
                {
                    TextLine textLine = textLines[i];
                    int      ascent   = textLine.GetAscent(hdc, fontCache);
                    textLine.GetDescent(hdc, fontCache);
                    int height = textLine.GetHeight(hdc, fontCache);
                    if (textLine.FirstLine)
                    {
                        offsetY += ConvertToPixels(paragraphProps.SpaceBefore, dpiX);
                    }
                    int baselineY = offsetY + ascent;
                    offsetY += height;
                    int num5 = offsetX;
                    switch (textAlignments)
                    {
                    case RPLFormat.TextAlignments.Left:
                        num5 = num;
                        break;

                    case RPLFormat.TextAlignments.Center:
                    {
                        int num6 = 0;
                        num6 = ((!textBox.HorizontalText) ? layoutRectangle.Height : layoutRectangle.Width);
                        num5 = num + (num6 - num - num2) / 2 - textLine.GetWidth(hdc, fontCache) / 2;
                        break;
                    }

                    default:
                        num5 = ((!textBox.HorizontalText) ? (layoutRectangle.Height - num2 - textLine.GetWidth(hdc, fontCache)) : (layoutRectangle.Width - num2 - textLine.GetWidth(hdc, fontCache)));
                        break;
                    }
                    if (textLine.Prefix != null && textLine.Prefix.Count > 0)
                    {
                        int num7 = (!flag) ? (num5 + textLine.GetWidth(hdc, fontCache) + ConvertToPixels(4.233333f, dpiX)) : (num5 - ConvertToPixels(4.233333f, dpiX) - textLine.GetPrefixWidth(hdc, fontCache));
                        if (num3 < 0)
                        {
                            if (flag && textAlignments == RPLFormat.TextAlignments.Left)
                            {
                                num7 += num3;
                            }
                            else if (!flag && textAlignments == RPLFormat.TextAlignments.Right)
                            {
                                num7 -= num3;
                            }
                        }
                        for (int j = 0; j < textLine.Prefix.Count; j++)
                        {
                            TextRun textRun = textLine.Prefix[j];
                            textBox.TextBoxProps.DrawTextRun(textRun, paragraph, hdc, dpiX, fontCache, num7, offsetY, baselineY, height, layoutRectangle);
                            num7 += textRun.GetWidth(hdc, fontCache);
                        }
                    }
                    if (textLine.FirstLine && num3 != 0)
                    {
                        if (flag)
                        {
                            switch (textAlignments)
                            {
                            case RPLFormat.TextAlignments.Left:
                                num5 += num3;
                                break;

                            case RPLFormat.TextAlignments.Center:
                                num5 += num3 / 2;
                                break;
                            }
                        }
                        else
                        {
                            switch (textAlignments)
                            {
                            case RPLFormat.TextAlignments.Right:
                                num5 -= num3;
                                break;

                            case RPLFormat.TextAlignments.Center:
                                num5 -= num3 / 2;
                                break;
                            }
                        }
                    }
                    int     prevRunWidth = 0;
                    int     prevRunX     = 0;
                    TextRun prevRun      = null;
                    int     count        = textLine.VisualRuns.Count;
                    for (int k = 0; k < count; k++)
                    {
                        TextRun textRun2 = textLine.VisualRuns[k];
                        int     width    = textRun2.GetWidth(hdc, fontCache, k == count - 1);
                        if (!textRun2.IsHighlightTextRun)
                        {
                            if (width > 0)
                            {
                                textBox.TextBoxProps.DrawTextRun(textRun2, paragraph, hdc, dpiX, fontCache, num5, offsetY, baselineY, height, layoutRectangle);
                            }
                        }
                        else
                        {
                            bool flag2 = (flag && k + 1 == count) || (!flag && k == 0);
                            if (width > 0 || flag2)
                            {
                                if (graphics == null)
                                {
                                    graphics = Graphics.FromHdc(hdc.Handle);
                                }
                                RenderHighlightedTextRun(textBox, paragraph, textRun2, prevRun, hdc, graphics, fontCache, dpiX, num5, offsetY, baselineY, height, layoutRectangle, width, prevRunWidth, prevRunX, flag2, textLine.LastLine);
                            }
                        }
                        prevRunX     = num5;
                        prevRunWidth = width;
                        num5        += width;
                        prevRun      = textRun2;
                    }
                    if (textLine.LastLine)
                    {
                        offsetY += ConvertToPixels(paragraphProps.SpaceAfter, dpiX);
                    }
                }
            }
            finally
            {
                if (graphics != null)
                {
                    graphics.Dispose();
                    graphics = null;
                }
            }
        }
Example #20
0
        internal static void Render(TextBox textBox, List <Paragraph> paragraphs, Win32DCSafeHandle hdc, FontCache fontCache, PointF offset, RectangleF layoutRectangle, float dpiX, bool unitsInMM)
        {
            if (paragraphs == null || paragraphs.Count == 0)
            {
                return;
            }
            Rectangle layoutRectangle2;
            Point     point;

            if (!unitsInMM)
            {
                layoutRectangle2 = new Rectangle((int)layoutRectangle.X, (int)layoutRectangle.Y, (int)layoutRectangle.Width, (int)layoutRectangle.Height);
                point            = new Point((int)offset.X, (int)offset.Y);
            }
            else
            {
                layoutRectangle2 = new Rectangle(ConvertToPixels(layoutRectangle.X, dpiX), ConvertToPixels(layoutRectangle.Y, dpiX), ConvertToPixels(layoutRectangle.Width, dpiX), ConvertToPixels(layoutRectangle.Height, dpiX));
                point            = new Point(ConvertToPixels(offset.X, dpiX), ConvertToPixels(offset.Y, dpiX));
            }
            uint fMode   = Win32.SetTextAlign(hdc, 24u);
            int  iBkMode = Win32.SetBkMode(hdc, 1);
            Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, Win32ObjectSafeHandle.Zero);

            try
            {
                fontCache.WritingMode = textBox.TextBoxProps.WritingMode;
                int offsetY = point.Y;
                for (int i = 0; i < paragraphs.Count; i++)
                {
                    RenderParagraph(textBox, paragraphs[i], hdc, fontCache, point.X, ref offsetY, layoutRectangle2, dpiX);
                }
            }
            finally
            {
                fMode   = Win32.SetTextAlign(hdc, fMode);
                iBkMode = Win32.SetBkMode(hdc, iBkMode);
                if (!win32ObjectSafeHandle.IsInvalid)
                {
                    Win32.SelectObject(hdc, win32ObjectSafeHandle).SetHandleAsInvalid();
                    win32ObjectSafeHandle.SetHandleAsInvalid();
                }
            }
        }
Example #21
0
 internal static void Render(TextBox textBox, List <Paragraph> paragraphs, Win32DCSafeHandle hdc, FontCache fontCache, PointF offset, RectangleF layoutRectangle, float dpiX)
 {
     Render(textBox, paragraphs, hdc, fontCache, offset, layoutRectangle, dpiX, unitsInMM: true);
 }
Example #22
0
        internal static void Render(TextBox textBox, List <Paragraph> paragraphs, Graphics g, FontCache fontCache, PointF offset, RectangleF layoutRectangle)
        {
            float             dpiX = g.DpiX;
            Win32DCSafeHandle win32DCSafeHandle = new Win32DCSafeHandle(g.GetHdc(), ownsHandle: false);

            try
            {
                Render(textBox, paragraphs, win32DCSafeHandle, fontCache, offset, layoutRectangle, dpiX);
            }
            finally
            {
                fontCache.ResetGraphics();
                if (!win32DCSafeHandle.IsInvalid)
                {
                    g.ReleaseHdc();
                }
            }
        }
Example #23
0
        private static void FoldLine(Paragraph paragraph, TextLine line, Win32DCSafeHandle hdc, FontCache fontCache, FlowContext flowContext, bool wordTrim, Stack <int> lineRunsIndex, Stack <int> lineRunsCharIndex, float maxWidth, int lineIndents)
        {
            int   count = line.LogicalRuns.Count;
            float num   = 0f;

            for (int i = 0; i < count; i++)
            {
                num += (float)line.LogicalRuns[i].GetWidth(hdc, fontCache);
            }
            int  num2 = -1;
            bool flag = false;

            for (int num3 = count - 1; num3 >= 0; num3--)
            {
                TextRun textRun = line.LogicalRuns[num3];
                num -= (float)textRun.GetWidth(hdc, fontCache);
                SCRIPT_LOGATTR?nextCharLogAttr = null;
                if (num3 != count - 1)
                {
                    TextRun textRun2 = line.LogicalRuns[num3 + 1];
                    if (textRun2.CharacterCount > 0)
                    {
                        nextCharLogAttr = textRun2.ScriptLogAttr[0];
                    }
                }
                if (!textRun.IsPlaceholderTextRun)
                {
                    flag = true;
                    int num4 = 0;
                    num4 = ((!wordTrim) ? FindFoldTextPosition_CharacterTrim(textRun, hdc, fontCache, maxWidth - num) : FindFoldTextPosition_TextRunTrim(textRun, hdc, fontCache, maxWidth - num, nextCharLogAttr));
                    if (num4 > 0)
                    {
                        FoldLineAt(line, num3, num4, flowContext.Context, lineRunsIndex, lineRunsCharIndex);
                        return;
                    }
                }
                else if (num2 > 0 && textRun.TextRunProperties.IndexInParagraph != num2)
                {
                    flag = true;
                }
                num2 = textRun.TextRunProperties.IndexInParagraph;
            }
            if (line.LogicalRuns.Count > 1)
            {
                if (!flag)
                {
                    return;
                }
                int num5;
                for (num5 = line.LogicalRuns.Count - 1; num5 > 0; num5--)
                {
                    flowContext.Context.TextRunIndex          = lineRunsIndex.Pop();
                    flowContext.Context.TextRunCharacterIndex = lineRunsCharIndex.Pop();
                    TextRun textRun3 = line.LogicalRuns[num5];
                    if (!textRun3.IsPlaceholderTextRun || textRun3.CharacterIndexInOriginal == 0)
                    {
                        break;
                    }
                }
                line.LogicalRuns.RemoveRange(num5, line.LogicalRuns.Count - num5);
            }
            else
            {
                if (!flag)
                {
                    return;
                }
                int num6 = 1;
                if (maxWidth > 0f)
                {
                    flowContext.ForcedCharTrim = true;
                    if (flowContext.VerticalCanGrow)
                    {
                        num6 = FindWidthToBreakPosition(line.LogicalRuns[0], hdc, fontCache, maxWidth, out int width);
                        flowContext.CharTrimmedRunWidth = Math.Max(flowContext.CharTrimmedRunWidth, width + lineIndents);
                    }
                    else
                    {
                        num6 = FindFoldTextPosition_CharacterTrim(line.LogicalRuns[0], hdc, fontCache, maxWidth);
                    }
                    if (num6 == 0)
                    {
                        num6 = 1;
                    }
                }
                else if (line.FirstLine && paragraph.ParagraphProps.HangingIndent > 0f)
                {
                    num6 = 0;
                    if (flowContext.Updatable)
                    {
                        paragraph.Updated = true;
                    }
                }
                FoldLineAt(line, 0, num6, flowContext.Context, lineRunsIndex, lineRunsCharIndex);
            }
        }
Example #24
0
        internal static List <Paragraph> Flow(TextBox textBox, Win32DCSafeHandle hdc, float dpiX, FontCache fontCache, FlowContext flowContext, bool keepLines, out float height)
        {
            if (flowContext.Height <= 0f || flowContext.Width <= 0f)
            {
                height = 0f;
                return(null);
            }
            int            num           = TextBox.ConvertToPixels(flowContext.ContentOffset, dpiX);
            int            contentOffset = num;
            TextBoxContext context       = flowContext.Context;

            RPLFormat.Directions  direction             = textBox.TextBoxProps.Direction;
            List <Paragraph>      list                  = new List <Paragraph>();
            Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, Win32ObjectSafeHandle.Zero);
            SizeF flowContextSize;

            if (!textBox.VerticalText)
            {
                flowContextSize = new SizeF(TextBox.ConvertToPixels(flowContext.Width, dpiX), TextBox.ConvertToPixels(flowContext.Height, dpiX));
            }
            else
            {
                flowContext.VerticalCanGrow = textBox.TextBoxProps.CanGrow;
                flowContextSize             = new SizeF(TextBox.ConvertToPixels(flowContext.Height, dpiX), TextBox.ConvertToPixels(flowContext.Width, dpiX));
            }
            fontCache.WritingMode = textBox.TextBoxProps.WritingMode;
            try
            {
                while (context.ParagraphIndex < textBox.Paragraphs.Count)
                {
                    Paragraph paragraph = textBox.Paragraphs[context.ParagraphIndex];
                    paragraph.OffsetY = num;
                    bool num2 = FlowParagraph(paragraph, direction, hdc, dpiX, fontCache, flowContext, keepLines, flowContextSize, ref contentOffset);
                    num += paragraph.Height;
                    if (!keepLines)
                    {
                        paragraph.TextLines = null;
                    }
                    if (!num2)
                    {
                        break;
                    }
                    list.Add(paragraph);
                    if ((float)num >= flowContextSize.Height)
                    {
                        if (paragraph.AtEndOfParagraph(context))
                        {
                            context.IncrementParagraph();
                        }
                        break;
                    }
                    context.IncrementParagraph();
                }
                if ((float)num < flowContextSize.Height)
                {
                    flowContext.AtEndOfTextBox = true;
                }
            }
            finally
            {
                if (!win32ObjectSafeHandle.IsInvalid)
                {
                    Win32.SelectObject(hdc, win32ObjectSafeHandle).SetHandleAsInvalid();
                    win32ObjectSafeHandle.SetHandleAsInvalid();
                }
            }
            height = TextBox.ConvertToMillimeters(num, dpiX);
            flowContext.ContentOffset = TextBox.ConvertToMillimeters(contentOffset, dpiX);
            return(list);
        }
Example #25
0
 internal int GetDescent(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     return(GetCachedFont(hdc, fontCache).GetDescent(hdc, fontCache));
 }
Example #26
0
        private static int FindFoldTextPosition_TextRunTrim(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, float maxWidth, SCRIPT_LOGATTR?nextCharLogAttr)
        {
            string text = run.Text;
            int    i    = FindFoldTextPosition_CharacterTrim(run, hdc, fontCache, maxWidth);

            if (i == text.Length && i > 0 && !run.ScriptLogAttr[i - 1].IsWhiteSpace && nextCharLogAttr.HasValue && !nextCharLogAttr.Value.IsWhiteSpace && !nextCharLogAttr.Value.IsSoftBreak)
            {
                i--;
            }
            int num = i;

            if (i > 0)
            {
                if (i < text.Length)
                {
                    while (i > 0 && !run.ScriptLogAttr[i].IsWhiteSpace && !run.ScriptLogAttr[i].IsSoftBreak)
                    {
                        i--;
                    }
                    if (i <= 0)
                    {
                        return(-1);
                    }
                    for (; i < num + 1 && run.ScriptLogAttr[i].IsWhiteSpace; i++)
                    {
                    }
                }
                return(i);
            }
            return(-1);
        }
Example #27
0
        private static int FindFoldTextPosition_CharacterTrim(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, float maxWidth)
        {
            string text = run.Text;

            int[] logicalWidths = run.GetLogicalWidths(hdc, fontCache);
            int   i             = 0;

            for (int num = 0; i < text.Length && (float)(num + logicalWidths[i]) <= maxWidth; i++)
            {
                num += logicalWidths[i];
            }
            return(i);
        }
Example #28
0
        private static int FindWidthToBreakPosition(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, float maxWidth, out int width)
        {
            string text = run.Text;

            int[] logicalWidths = run.GetLogicalWidths(hdc, fontCache);
            int   i             = 0;

            for (width = 0; i < text.Length && ((float)(width + logicalWidths[i]) <= maxWidth || (!run.ScriptLogAttr[i].IsWhiteSpace && !run.ScriptLogAttr[i].IsSoftBreak)); i++)
            {
                width += logicalWidths[i];
            }
            return(i);
        }
Example #29
0
        internal static float MeasureFullHeight(TextBox textBox, Graphics g, FontCache fontCache, FlowContext flowContext, out float contentHeight)
        {
            if (flowContext.Width <= 0f)
            {
                contentHeight = 0f;
                return(0f);
            }
            FlowContext flowContext2 = flowContext.Clone();

            flowContext2.Reset();
            flowContext2.Height = float.MaxValue;
            float num = 0f;

            if (textBox.VerticalText)
            {
                flowContext2.LineLimit = false;
                float width     = 0f;
                float nextWidth = 0f;
                float num2      = 0f;
                float num3      = flowContext.Height;
                float num4      = 0f;
                if (flowContext.Height == float.MaxValue)
                {
                    num3 = 0f;
                }
                num2 = (contentHeight = LineBreaker.FlowVertical(textBox, g, fontCache, flowContext2, out width, out nextWidth));
                num  = width;
                num4 = width;
                bool  flag = flowContext2.CharTrimmedRunWidth > 0;
                float num5 = 0f;
                while (num2 < flowContext.Width && width > num3)
                {
                    flowContext2.Reset();
                    flowContext2.Height = Math.Max(nextWidth, num3);
                    flowContext2.Width  = float.MaxValue;
                    num2 = LineBreaker.FlowVertical(textBox, g, fontCache, flowContext2, out width, out nextWidth);
                    if (num2 < flowContext.Width)
                    {
                        num5 = num2 - contentHeight;
                        if (num2 <= contentHeight || num5 <= 0.1f)
                        {
                            if (flag)
                            {
                                contentHeight = num2;
                                num           = flowContext2.Height;
                                break;
                            }
                            if (flowContext2.CharTrimmedRunWidth <= 0)
                            {
                                break;
                            }
                        }
                        contentHeight = num2;
                        num           = flowContext2.Height;
                        num4          = width;
                    }
                    else
                    {
                        num5 = num - flowContext2.Height;
                        if (!(num5 > 0.1f))
                        {
                            break;
                        }
                        nextWidth     = flowContext2.Height + (num - flowContext2.Height) / 2f;
                        contentHeight = num2;
                        width         = num4;
                    }
                    flag = (flowContext2.CharTrimmedRunWidth > 0);
                }
            }
            else
            {
                LineBreaker.Flow(textBox, g, fontCache, flowContext2, keepLines: false, out contentHeight);
                num = contentHeight;
            }
            return(num);
        }
Example #30
0
 internal int GetWidth(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     return(GetWidth(hdc, fontCache, isAtLineEnd: false));
 }