Exemplo 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) ? LineBreaker.FindFoldTextPosition_CharacterTrim(textRun, hdc, fontCache, maxWidth - num) : LineBreaker.FindFoldTextPosition_TextRunTrim(textRun, hdc, fontCache, maxWidth - num, nextCharLogAttr));
                    if (num4 > 0)
                    {
                        LineBreaker.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)
                {
                    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)
                        {
                            break;
                        }
                        if (textRun3.CharacterIndexInOriginal == 0)
                        {
                            break;
                        }
                    }
                    line.LogicalRuns.RemoveRange(num5, line.LogicalRuns.Count - num5);
                }
            }
            else if (flag)
            {
                int num6 = 1;
                if (maxWidth > 0.0)
                {
                    flowContext.ForcedCharTrim = true;
                    if (flowContext.VerticalCanGrow)
                    {
                        int num7 = default(int);
                        num6 = LineBreaker.FindWidthToBreakPosition(line.LogicalRuns[0], hdc, fontCache, maxWidth, out num7);
                        flowContext.CharTrimmedRunWidth = Math.Max(flowContext.CharTrimmedRunWidth, num7 + lineIndents);
                    }
                    else
                    {
                        num6 = LineBreaker.FindFoldTextPosition_CharacterTrim(line.LogicalRuns[0], hdc, fontCache, maxWidth);
                    }
                    if (num6 == 0)
                    {
                        num6 = 1;
                    }
                }
                else if (line.FirstLine && paragraph.ParagraphProps.HangingIndent > 0.0)
                {
                    num6 = 0;
                    if (flowContext.Updatable)
                    {
                        paragraph.Updated = true;
                    }
                }
                LineBreaker.FoldLineAt(line, 0, num6, flowContext.Context, lineRunsIndex, lineRunsCharIndex);
            }
        }
Exemplo n.º 2
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  = TextBox.ConvertToPixels(paragraphProps.LeftIndent, dpiX);
            int num2 = TextBox.ConvertToPixels(paragraphProps.RightIndent, dpiX);
            int num3 = TextBox.ConvertToPixels(paragraphProps.HangingIndent, dpiX);

            if (num3 < 0)
            {
                if (flag)
                {
                    num -= num3;
                }
                else
                {
                    num2 -= num3;
                }
            }
            if (paragraphProps.ListLevel > 0)
            {
                int num4 = paragraphProps.ListLevel * TextBox.ConvertToPixels(10.583333f, dpiX);
                if (flag)
                {
                    num += num4;
                }
                else
                {
                    num2 += num4;
                }
            }
            if (textLines == null || textLines.Count == 0)
            {
                offsetY += TextBox.ConvertToPixels(paragraphProps.SpaceBefore, dpiX);
                offsetY += TextBox.ConvertToPixels(paragraphProps.SpaceAfter, dpiX);
            }
            else
            {
                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 += TextBox.ConvertToPixels(paragraphProps.SpaceBefore, dpiX);
                        }
                        int baselineY = offsetY + ascent;
                        offsetY += height;
                        int num5;
                        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) + TextBox.ConvertToPixels(4.233333f, dpiX)) : (num5 - TextBox.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);
                                    }
                                    TextBox.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 += TextBox.ConvertToPixels(paragraphProps.SpaceAfter, dpiX);
                        }
                    }
                }
                finally
                {
                    if (graphics != null)
                    {
                        graphics.Dispose();
                        graphics = null;
                    }
                }
            }
        }
Exemplo n.º 3
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 num3 = 0f;
            float num4 = 0f;
            float num5 = 0f;

            paragraph.GetParagraphIndents(direction, dpiX, out num3, out num4, out num5);
            Stack <int> stack    = null;
            Stack <int> stack2   = null;
            TextLine    textLine = null;

            while (true)
            {
                float num6 = num3;
                float num7 = num4;
                if (flag)
                {
                    if (direction == RPLFormat.Directions.LTR)
                    {
                        num6 += num5;
                    }
                    else
                    {
                        num7 += num5;
                    }
                }
                stack    = new Stack <int>();
                stack2   = new Stack <int>();
                textLine = new TextLine();
                if (flag)
                {
                    textLine.Prefix    = LineBreaker.CreateLinePrefix(paragraph, direction);
                    textLine.FirstLine = true;
                }
                if (!LineBreaker.GetLine(paragraph, textLine, hdc, fontCache, flowContext, num6, flowContextSize.Width - num7, flowContextSize.Height - (float)num, stack, stack2, (int)(num6 + num7)))
                {
                    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, false);
                paragraph.AdvanceToNextRun(flowContext.ClipContext, 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);
        }