示例#1
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);
        }
示例#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);
        }