Exemple #1
0
        private static bool GetLine(Paragraph paragraph, TextLine line, Win32DCSafeHandle hdc, FontCache fontCache, FlowContext flowContext, float left, float right, float height, Stack <int> lineRunsIndex, Stack <int> lineRunsCharIndex, int lineIndents)
        {
            float num     = right - left;
            float num2    = left;
            bool  newLine = false;
            int   num3    = 0;

            do
            {
                lineRunsIndex.Push(flowContext.Context.TextRunIndex);
                lineRunsCharIndex.Push(flowContext.Context.TextRunCharacterIndex);
                TextRun subRunForLine = paragraph.GetSubRunForLine(flowContext.Context, ref newLine);
                if (subRunForLine == null)
                {
                    break;
                }
                line.LogicalRuns.Add(subRunForLine);
                int width = subRunForLine.GetWidth(hdc, fontCache);
                num3  = Math.Max(subRunForLine.GetWidth(hdc, fontCache, isAtLineEnd: true) - width, num3);
                num2 += (float)width;
                if (!(num2 + (float)num3 > right))
                {
                    continue;
                }
                bool flag = flowContext.WordTrim;
                if (!flowContext.LineLimit && flag)
                {
                    if ((float)line.GetHeight(hdc, fontCache) >= height)
                    {
                        flag = false;
                    }
                    line.ResetHeight();
                }
                if (!subRunForLine.IsPlaceholderTextRun)
                {
                    FoldLine(paragraph, line, hdc, fontCache, flowContext, flag, lineRunsIndex, lineRunsCharIndex, num - (float)num3, lineIndents);
                    break;
                }
                lineRunsIndex.Push(flowContext.Context.TextRunIndex);
                lineRunsCharIndex.Push(flowContext.Context.TextRunCharacterIndex);
                bool    flag2          = true;
                TextRun subRunForLine2 = paragraph.GetSubRunForLine(flowContext.Context, ref newLine);
                if (subRunForLine2 != null)
                {
                    flag2 = (subRunForLine.TextRunProperties.IndexInParagraph < subRunForLine2.TextRunProperties.IndexInParagraph);
                }
                flowContext.Context.TextRunIndex          = lineRunsIndex.Pop();
                flowContext.Context.TextRunCharacterIndex = lineRunsCharIndex.Pop();
                if (flag2)
                {
                    FoldLine(paragraph, line, hdc, fontCache, flowContext, flag, lineRunsIndex, lineRunsCharIndex, num - (float)num3, lineIndents);
                    break;
                }
            }while (!newLine);
            if (line.LogicalRuns.Count == 0)
            {
                return(false);
            }
            return(true);
        }
Exemple #2
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;
            }
        }
Exemple #3
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;
                }
            }
        }
Exemple #4
0
        private Point GetParagraphAndRunCoordinates(Win32DCSafeHandle hdc, TextBoxContext location, bool moveCaretToNextLine, out int lineYOffset, out int lineHeight, out TextRun textRun, out int textRunCharacterIndex, out bool isFirstLine, out bool isLastLine)
        {
            int num          = 0;
            int textRunIndex = location.TextRunIndex;

            textRunCharacterIndex = location.TextRunCharacterIndex;
            lineYOffset           = 0;
            lineHeight            = 0;
            textRun     = null;
            isFirstLine = true;
            isLastLine  = true;
            List <Paragraph> rTParagraphs = RTParagraphs;

            if (rTParagraphs == null || location.ParagraphIndex >= rTParagraphs.Count)
            {
                return(Point.Empty);
            }
            Paragraph paragraph = rTParagraphs[location.ParagraphIndex];
            int       num2      = paragraph.OffsetY + TextBox.ConvertToPixels(paragraph.ParagraphProps.SpaceBefore, Dpi);
            int       num3      = TextBox.ConvertToPixels(paragraph.ParagraphProps.LeftIndent, Dpi);
            int       num4      = TextBox.ConvertToPixels(paragraph.ParagraphProps.RightIndent, Dpi);
            int       num5      = TextBox.ConvertToPixels(paragraph.ParagraphProps.HangingIndent, Dpi);
            bool      flag      = m_rttextbox.TextBoxProps.Direction == RPLFormat.Directions.LTR;

            if (num5 < 0)
            {
                if (flag)
                {
                    num3 -= num5;
                }
                else
                {
                    num4 -= num5;
                }
            }
            int listLevel = paragraph.ParagraphProps.ListLevel;

            if (listLevel > 0)
            {
                int num6 = listLevel * TextBox.ConvertToPixels(10.583333f, Dpi);
                if (flag)
                {
                    num3 += num6;
                }
                else
                {
                    num4 += num6;
                }
            }
            for (int i = 0; i < paragraph.TextLines.Count; i++)
            {
                TextLine textLine = paragraph.TextLines[i];
                int      descent  = textLine.GetDescent(hdc, FontCache);
                lineHeight  = textLine.GetHeight(hdc, FontCache);
                lineYOffset = num2;
                num2       += lineHeight;
                RPLFormat.TextAlignments textAlignments = paragraph.ParagraphProps.Alignment;
                if (textAlignments == RPLFormat.TextAlignments.General)
                {
                    textAlignments = m_rttextbox.TextBoxProps.DefaultAlignment;
                    if (!flag)
                    {
                        switch (textAlignments)
                        {
                        case RPLFormat.TextAlignments.Left:
                            textAlignments = RPLFormat.TextAlignments.Right;
                            break;

                        case RPLFormat.TextAlignments.Right:
                            textAlignments = RPLFormat.TextAlignments.Left;
                            break;
                        }
                    }
                }
                switch (textAlignments)
                {
                case RPLFormat.TextAlignments.Center:
                    num = num3 + (WidthInPX - num3 - num4) / 2 - textLine.GetWidth(hdc, FontCache) / 2;
                    break;

                case RPLFormat.TextAlignments.Right:
                    num = WidthInPX - textLine.GetWidth(hdc, FontCache) - num4;
                    break;

                default:
                    num = num3;
                    break;
                }
                if (textLine.FirstLine && num5 != 0)
                {
                    if (flag)
                    {
                        switch (textAlignments)
                        {
                        case RPLFormat.TextAlignments.Left:
                            num += num5;
                            break;

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

                        case RPLFormat.TextAlignments.Center:
                            num -= num5 / 2;
                            break;
                        }
                    }
                }
                int count = textLine.VisualRuns.Count;
                for (int j = 0; j < count; j++)
                {
                    textRun = textLine.VisualRuns[j];
                    if (textRun.TextRunProperties.IndexInParagraph == textRunIndex && textRunCharacterIndex >= textRun.CharacterIndexInOriginal)
                    {
                        bool flag2 = (moveCaretToNextLine || textRun.CharacterCount <= 0 || textRun.Text[textRun.CharacterCount - 1] != '\n') ? (textRunCharacterIndex <= textRun.CharacterIndexInOriginal + textRun.CharacterCount) : (textRunCharacterIndex < textRun.CharacterIndexInOriginal + textRun.CharacterCount);
                        if (flag2 || (i + 1 == paragraph.TextLines.Count && j + 1 == count))
                        {
                            if (moveCaretToNextLine && textRunCharacterIndex == textRun.CharacterIndexInOriginal + textRun.CharacterCount && j + 1 == count && i + 1 < paragraph.TextLines.Count)
                            {
                                location = location.Clone();
                                if (paragraph.TextLines[i + 1].VisualRuns[0].TextRunProperties.IndexInParagraph != textRunIndex)
                                {
                                    location.TextRunIndex++;
                                    location.TextRunCharacterIndex = 0;
                                }
                                Point paragraphAndRunCoordinates = GetParagraphAndRunCoordinates(hdc, location, moveCaretToNextLine: false, out lineYOffset, out lineHeight, out textRun, out textRunCharacterIndex, out isFirstLine, out isLastLine);
                                textRunCharacterIndex = Math.Max(textRunCharacterIndex - 1, 0);
                                return(paragraphAndRunCoordinates);
                            }
                            textRunCharacterIndex -= textRun.CharacterIndexInOriginal;
                            isFirstLine            = textLine.FirstLine;
                            isLastLine             = textLine.LastLine;
                            return(new Point(num, num2 - descent));
                        }
                    }
                    num += textRun.GetWidth(hdc, FontCache);
                }
            }
            textRun = null;
            return(Point.Empty);
        }
Exemple #5
0
        private TextBoxContext GetParagraphAndRunIndex(Win32DCSafeHandle hdc, Paragraph paragraph, TextLine line, int x, int lineWidth, bool lastParagraph, out TextRun run, ref int runX, out bool atEndOfLine)
        {
            atEndOfLine = false;
            run         = null;
            int count = line.VisualRuns.Count;

            for (int i = 0; i < count; i++)
            {
                run = line.VisualRuns[i];
                int width = run.GetWidth(hdc, FontCache, i == count - 1);
                if (runX - width <= 0 || i + 1 == count)
                {
                    if (runX - width > 0)
                    {
                        atEndOfLine = true;
                        if (run.ScriptAnalysis.fLayoutRTL == 1 && x >= lineWidth)
                        {
                            run = line.VisualRuns[count - 1];
                            return(new TextBoxContext
                            {
                                TextRunIndex = run.TextRunProperties.IndexInParagraph,
                                TextRunCharacterIndex = run.CharacterIndexInOriginal
                            });
                        }
                    }
                    int num            = 0;
                    int characterCount = run.CharacterCount;
                    if (characterCount > 0)
                    {
                        if ((run.ScriptAnalysis.fLayoutRTL == 0 && i + 1 == count) || (run.ScriptAnalysis.fLayoutRTL == 1 && i == 0))
                        {
                            if (width <= 0)
                            {
                                string text = run.Text;
                                if (characterCount > 1 && text[characterCount - 2] == '\r' && text[characterCount - 1] == '\n')
                                {
                                    num = ((run.ScriptAnalysis.fLayoutRTL != 0) ? (-1) : (-2));
                                }
                                else if (text[characterCount - 1] == '\n' && run.ScriptAnalysis.fLayoutRTL == 0)
                                {
                                    if (i > 0)
                                    {
                                        run = line.VisualRuns[i - 1];
                                        if (run.CharacterCount > 0 && run.Text[run.CharacterCount - 1] == '\r')
                                        {
                                            num = -1;
                                        }
                                    }
                                    else
                                    {
                                        num = -1;
                                    }
                                }
                            }
                            else if (i + 1 == count && (run.Text[characterCount - 1] == '\r' || run.Text[characterCount - 1] == '\n'))
                            {
                                num = -1;
                            }
                            else if (i == 0 && (run.Text[0] == '\r' || run.Text[0] == '\n'))
                            {
                                num = -1;
                            }
                        }
                        else if (i == 0 && (run.Text[0] == '\r' || run.Text[0] == '\n'))
                        {
                            num = -1;
                        }
                    }
                    else if (lastParagraph && line.LastLine && !line.FirstLine)
                    {
                        num = 1;
                    }
                    return(new TextBoxContext
                    {
                        TextRunIndex = run.TextRunProperties.IndexInParagraph,
                        TextRunCharacterIndex = run.CharacterIndexInOriginal + num
                    });
                }
                runX -= width;
            }
            return(null);
        }
Exemple #6
0
        private void SetHighlighting(List <Paragraph> paragraphs, Win32DCSafeHandle hdc, RTSelectionHighlight highlight, TextRun runStart, TextRun runEnd, int x1, int x2)
        {
            if (runStart == runEnd)
            {
                if (x1 != x2)
                {
                    if (x1 < x2)
                    {
                        runStart.HighlightStart = x1;
                        runStart.HighlightEnd   = x2;
                    }
                    else
                    {
                        runStart.HighlightStart = x2;
                        runStart.HighlightEnd   = x1;
                    }
                    runStart.HighlightColor      = highlight.Color;
                    runStart.AllowColorInversion = highlight.AllowColorInversion;
                }
                return;
            }
            bool  flag  = false;
            bool  flag2 = false;
            Color color = highlight.Color;
            bool  allowColorInversion = highlight.AllowColorInversion;

            for (int i = highlight.SelectionStart.ParagraphIndex; i <= highlight.SelectionEnd.ParagraphIndex; i++)
            {
                int count = paragraphs[i].TextLines.Count;
                for (int j = 0; j < count; j++)
                {
                    List <TextRun> logicalRuns = paragraphs[i].TextLines[j].LogicalRuns;
                    int            count2      = logicalRuns.Count;
                    for (int k = 0; k < count2; k++)
                    {
                        TextRun textRun = logicalRuns[k];
                        bool    flag3   = textRun.ScriptAnalysis.fLayoutRTL == 0;
                        if (textRun == runStart)
                        {
                            flag2 = true;
                            if (flag3 && x1 < textRun.GetWidth(hdc, FontCache))
                            {
                                textRun.HighlightStart      = x1;
                                textRun.HighlightEnd        = -1;
                                textRun.HighlightColor      = color;
                                textRun.AllowColorInversion = allowColorInversion;
                            }
                            else if (!flag3 && x1 > 0)
                            {
                                textRun.HighlightStart      = -1;
                                textRun.HighlightEnd        = x1;
                                textRun.HighlightColor      = color;
                                textRun.AllowColorInversion = allowColorInversion;
                            }
                            continue;
                        }
                        if (textRun == runEnd)
                        {
                            flag2 = false;
                            if (flag3 && x2 > 0)
                            {
                                textRun.HighlightStart      = -1;
                                textRun.HighlightEnd        = x2;
                                textRun.HighlightColor      = color;
                                textRun.AllowColorInversion = allowColorInversion;
                            }
                            else if (!flag3 && x2 < textRun.GetWidth(hdc, FontCache))
                            {
                                textRun.HighlightStart      = x2;
                                textRun.HighlightEnd        = -1;
                                textRun.HighlightColor      = color;
                                textRun.AllowColorInversion = allowColorInversion;
                            }
                            flag = true;
                            break;
                        }
                        if (flag2)
                        {
                            textRun.HighlightStart      = -1;
                            textRun.HighlightEnd        = -1;
                            textRun.HighlightColor      = color;
                            textRun.AllowColorInversion = allowColorInversion;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                }
                if (flag)
                {
                    break;
                }
            }
        }
Exemple #7
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);
            }
        }
Exemple #8
0
        private void CalculateDimensions(Win32DCSafeHandle hdc, FontCache fontCache, bool useVisualRunsIfAvailable)
        {
            if (m_calculatedDimensions)
            {
                return;
            }
            bool           flag = useVisualRunsIfAvailable && m_visualRuns != null;
            List <TextRun> list = flag ? m_visualRuns : m_logicalRuns;

            m_width       = 0;
            m_prefixWidth = 0;
            int count = list.Count;
            int num   = 0;

            for (int i = 0; i < count; i++)
            {
                TextRun textRun = list[i];
                int     width   = textRun.GetWidth(hdc, fontCache);
                m_width += width;
                if (!flag)
                {
                    num = Math.Max(textRun.GetWidth(hdc, fontCache, isAtLineEnd: true) - width, num);
                }
                else if (i == count - 1)
                {
                    num = textRun.GetWidth(hdc, fontCache, isAtLineEnd: true) - width;
                }
                if (!m_calculatedHeight)
                {
                    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;
                    }
                }
            }
            m_width += num;
            if (m_prefix != null)
            {
                for (int j = 0; j < m_prefix.Count; j++)
                {
                    TextRun textRun2 = m_prefix[j];
                    if (!m_calculatedHeight)
                    {
                        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;
                        }
                    }
                    m_prefixWidth += textRun2.GetWidth(hdc, fontCache);
                }
            }
            m_calculatedDimensions = true;
            m_calculatedHeight     = true;
        }