Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        private static bool FlowParagraph(Paragraph paragraph, RPLFormat.Directions direction, Win32DCSafeHandle hdc, float dpiX, FontCache fontCache, FlowContext flowContext, bool keepLines, SizeF flowContextSize, ref int contentOffset)
        {
            List <TextLine> list    = new List <TextLine>();
            TextBoxContext  context = flowContext.Context;
            int             num     = paragraph.OffsetY;

            paragraph.ProcessedEmptyParagraph = false;
            bool            flag           = false;
            IParagraphProps paragraphProps = paragraph.ParagraphProps;

            if (!flowContext.Updatable || !paragraph.Updated)
            {
                flag = (context.TextRunIndex == 0 && context.TextRunCharacterIndex == 0);
            }
            if (flag)
            {
                num += TextBox.ConvertToPixels(paragraphProps.SpaceBefore, dpiX);
                if ((float)num >= flowContextSize.Height)
                {
                    paragraph.Height = num - paragraph.OffsetY;
                    return(false);
                }
            }
            int   num2          = contentOffset;
            float leftIndent    = 0f;
            float rightIndent   = 0f;
            float hangingIndent = 0f;

            paragraph.GetParagraphIndents(direction, dpiX, out leftIndent, out rightIndent, out hangingIndent);
            Stack <int> stack    = null;
            Stack <int> stack2   = null;
            TextLine    textLine = null;

            while (true)
            {
                float num3 = leftIndent;
                float num4 = rightIndent;
                if (flag)
                {
                    if (direction == RPLFormat.Directions.LTR)
                    {
                        num3 += hangingIndent;
                    }
                    else
                    {
                        num4 += hangingIndent;
                    }
                }
                stack    = new Stack <int>();
                stack2   = new Stack <int>();
                textLine = new TextLine();
                if (flag)
                {
                    textLine.Prefix    = CreateLinePrefix(paragraph, direction);
                    textLine.FirstLine = true;
                }
                if (!GetLine(paragraph, textLine, hdc, fontCache, flowContext, num3, flowContextSize.Width - num4, flowContextSize.Height - (float)num, stack, stack2, (int)(num3 + num4)))
                {
                    if (list.Count > 0)
                    {
                        list[list.Count - 1].LastLine = true;
                    }
                    num += TextBox.ConvertToPixels(paragraphProps.SpaceAfter, dpiX);
                    break;
                }
                if (keepLines)
                {
                    textLine.ScriptLayout(hdc, fontCache);
                }
                num += textLine.GetHeight(hdc, fontCache);
                list.Add(textLine);
                num2 = num;
                if ((float)num >= flowContextSize.Height)
                {
                    break;
                }
                flag = false;
            }
            paragraph.Height = num - paragraph.OffsetY;
            if ((float)num > flowContextSize.Height)
            {
                if (list.Count > 0 && (float)num2 > flowContextSize.Height)
                {
                    TextLine textLine2             = list[list.Count - 1];
                    int      textRunIndex          = 0;
                    int      textRunCharacterIndex = 0;
                    while (stack.Count > 0)
                    {
                        textRunIndex = stack.Pop();
                    }
                    while (stack2.Count > 0)
                    {
                        textRunCharacterIndex = stack2.Pop();
                    }
                    if (flowContext.LineLimit)
                    {
                        context.TextRunIndex          = textRunIndex;
                        context.TextRunCharacterIndex = textRunCharacterIndex;
                        list.RemoveAt(list.Count - 1);
                        flowContext.OmittedLineHeight = TextBox.ConvertToMillimeters(textLine2.GetHeight(hdc, fontCache), dpiX);
                        if (textLine2.FirstLine)
                        {
                            num2 -= TextBox.ConvertToPixels(paragraphProps.SpaceBefore, dpiX);
                        }
                    }
                    else
                    {
                        TextBoxContext textBoxContext = context.Clone();
                        textBoxContext.TextRunIndex          = textRunIndex;
                        textBoxContext.TextRunCharacterIndex = textRunCharacterIndex;
                        flowContext.ClipContext = textBoxContext;
                    }
                    num2 -= textLine2.GetHeight(hdc, fontCache);
                }
                paragraph.AdvanceToNextRun(context, skipEmptyRuns: false);
                paragraph.AdvanceToNextRun(flowContext.ClipContext, skipEmptyRuns: false);
                if (list.Count > 0)
                {
                    if (flowContext.ClipContext == null && paragraph.AtEndOfParagraph(context))
                    {
                        contentOffset = num;
                    }
                    else
                    {
                        contentOffset = num2;
                    }
                    paragraph.TextLines = list;
                    return(true);
                }
                paragraph.TextLines = null;
                if (paragraph.AtEndOfParagraph(context))
                {
                    contentOffset = num;
                }
                return(false);
            }
            paragraph.AdvanceToNextRun(context);
            paragraph.TextLines = list;
            contentOffset       = num;
            return(true);
        }