Ejemplo n.º 1
0
 internal void GetParagraphIndents(RPLFormat.Directions direction, float dpiX, out float leftIndent, out float rightIndent, out float hangingIndent)
 {
     leftIndent    = TextBox.ConvertToPixels(m_paragraphProps.LeftIndent, dpiX);
     rightIndent   = TextBox.ConvertToPixels(m_paragraphProps.RightIndent, dpiX);
     hangingIndent = TextBox.ConvertToPixels(m_paragraphProps.HangingIndent, dpiX);
     if (hangingIndent < 0f)
     {
         if (direction == RPLFormat.Directions.LTR)
         {
             leftIndent -= hangingIndent;
         }
         else
         {
             rightIndent -= hangingIndent;
         }
     }
     if (m_paragraphProps.ListLevel > 0)
     {
         float num = m_paragraphProps.ListLevel * TextBox.ConvertToPixels(10.583333f, dpiX);
         if (direction == RPLFormat.Directions.LTR)
         {
             leftIndent += num;
         }
         else
         {
             rightIndent += num;
         }
     }
 }
Ejemplo n.º 2
0
        private TextBoxContext GetParagraphAndRunIndex(Graphics g, Paragraph paragraph, int leftIndent, int rightIndent, int hangingIndent, int x, int y, bool isLTR, bool lastParagraph, out TextRun run, out int runX, out bool atEndOfLine)
        {
            Win32DCSafeHandle win32DCSafeHandle = null;
            bool flag = false;

            try
            {
                if (g == null)
                {
                    flag = true;
                    g    = Graphics.FromHwnd(IntPtr.Zero);
                }
                win32DCSafeHandle = new Win32DCSafeHandle(g.GetHdc(), ownsHandle: false);
                runX        = x;
                run         = null;
                atEndOfLine = false;
                for (int i = 0; i < paragraph.TextLines.Count; i++)
                {
                    TextLine textLine = paragraph.TextLines[i];
                    y -= textLine.GetHeight(win32DCSafeHandle, FontCache);
                    if (textLine.FirstLine)
                    {
                        y -= TextBox.ConvertToPixels(paragraph.ParagraphProps.SpaceBefore, Dpi);
                    }
                    else if (textLine.LastLine)
                    {
                        y -= TextBox.ConvertToPixels(paragraph.ParagraphProps.SpaceAfter, Dpi);
                    }
                    if (y >= 0 && i + 1 != paragraph.TextLines.Count)
                    {
                        continue;
                    }
                    int width = textLine.GetWidth(win32DCSafeHandle, FontCache);
                    if (x > WidthInPX)
                    {
                        atEndOfLine = (width > 0);
                        run         = GetLastNonLineBreakRun(textLine.LogicalRuns, out int charIndex, out bool hasNonCRLFChars);
                        TextBoxContext textBoxContext = new TextBoxContext();
                        textBoxContext.TextRunIndex = run.TextRunProperties.IndexInParagraph;
                        if (hasNonCRLFChars && run.CharacterCount > 0)
                        {
                            textBoxContext.TextRunCharacterIndex = run.CharacterIndexInOriginal + charIndex + 1;
                        }
                        else
                        {
                            textBoxContext.TextRunCharacterIndex = run.CharacterIndexInOriginal;
                        }
                        run = null;
                        return(textBoxContext);
                    }
                    if (x < 0)
                    {
                        atEndOfLine = false;
                        run         = GetFirstNonLineBreakRun(textLine.LogicalRuns, out int charIndex2);
                        TextBoxContext result = new TextBoxContext
                        {
                            TextRunIndex          = run.TextRunProperties.IndexInParagraph,
                            TextRunCharacterIndex = run.CharacterIndexInOriginal + charIndex2
                        };
                        run = null;
                        return(result);
                    }
                    RPLFormat.TextAlignments textAlignments = paragraph.ParagraphProps.Alignment;
                    if (textAlignments == RPLFormat.TextAlignments.General)
                    {
                        textAlignments = m_rttextbox.TextBoxProps.DefaultAlignment;
                        if (!isLTR)
                        {
                            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:
                        runX = x - (leftIndent + (WidthInPX - leftIndent - rightIndent) / 2 - width / 2);
                        break;

                    case RPLFormat.TextAlignments.Right:
                        runX = x - (WidthInPX - width - rightIndent);
                        break;

                    default:
                        runX = x - leftIndent;
                        break;
                    }
                    if (textLine.FirstLine && hangingIndent != 0)
                    {
                        if (isLTR)
                        {
                            switch (textAlignments)
                            {
                            case RPLFormat.TextAlignments.Left:
                                runX -= hangingIndent;
                                break;

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

                            case RPLFormat.TextAlignments.Center:
                                runX += hangingIndent / 2;
                                break;
                            }
                        }
                    }
                    runX = Math.Max(0, runX);
                    return(GetParagraphAndRunIndex(win32DCSafeHandle, paragraph, textLine, x, width, lastParagraph, out run, ref runX, out atEndOfLine));
                }
                return(null);
            }
            finally
            {
                if (!win32DCSafeHandle.IsInvalid)
                {
                    g.ReleaseHdc();
                }
                if (flag)
                {
                    g.Dispose();
                    g = null;
                }
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        internal Rectangle GetTextBoundingBoxPx(Rectangle rect, RPLFormat.VerticalAlignments vAlign)
        {
            if (RTParagraphs == null)
            {
                return(new Rectangle(rect.Location, Size.Empty));
            }
            Rectangle rectangle = Rectangle.Empty;
            Size      size      = default(Size);
            int       num       = rect.Top;
            Size      size2     = rect.Size;

            if (RTTextbox.VerticalText)
            {
                size2 = new Size(size2.Height, size2.Width);
            }
            foreach (Paragraph rTParagraph in RTParagraphs)
            {
                int num2 = 0;
                if (rTParagraph.TextLines.Count == 1 && rTParagraph.ParagraphProps.HangingIndent > 0f)
                {
                    num2 += TextBox.ConvertToPixels(rTParagraph.ParagraphProps.HangingIndent, Dpi);
                }
                foreach (TextLine textLine in rTParagraph.TextLines)
                {
                    size.Width   = Math.Max(Math.Max(size.Width, textLine.GetWidth(Win32DCSafeHandle.Zero, FontCache)), 10);
                    size.Height += textLine.GetHeight(Win32DCSafeHandle.Zero, FontCache);
                }
                switch (rTParagraph.ParagraphProps.Alignment)
                {
                case RPLFormat.TextAlignments.General:
                    if (RTTextbox.TextBoxProps.Direction != RPLFormat.Directions.RTL)
                    {
                        goto case RPLFormat.TextAlignments.Left;
                    }
                    goto case RPLFormat.TextAlignments.Right;

                case RPLFormat.TextAlignments.Left:
                    num2 += rect.Left;
                    break;

                case RPLFormat.TextAlignments.Center:
                    num2 += rect.Left + (size2.Width - size.Width) / 2;
                    break;

                case RPLFormat.TextAlignments.Right:
                    num2 += rect.Left + size2.Width - size.Width;
                    break;

                default:
                    throw new ArgumentException("Unknown TextAlignment: " + rTParagraph.ParagraphProps.Alignment);
                }
                num2 = ((RTTextbox.TextBoxProps.Direction != 0) ? (num2 - TextBox.ConvertToPixels(rTParagraph.ParagraphProps.RightIndent + 10.583333f * (float)rTParagraph.ParagraphProps.ListLevel, Dpi)) : (num2 + TextBox.ConvertToPixels(rTParagraph.ParagraphProps.LeftIndent + 10.583333f * (float)rTParagraph.ParagraphProps.ListLevel, Dpi)));
                Rectangle rectangle2 = new Rectangle(new Point(num2, num), size);
                num      += size.Height;
                rectangle = ((!rectangle.IsEmpty) ? Rectangle.Union(rectangle, rectangle2) : rectangle2);
            }
            if (rectangle.Height < size2.Height)
            {
                switch (vAlign)
                {
                case RPLFormat.VerticalAlignments.Middle:
                    rectangle.Y += (size2.Height - rectangle.Height) / 2;
                    break;

                case RPLFormat.VerticalAlignments.Bottom:
                    rectangle.Y = rect.Top + size2.Height - rectangle.Height;
                    break;
                }
            }
            if (RTTextbox.VerticalText)
            {
                Point location = new Point(rect.Right - (rectangle.Top - rect.Top) - rectangle.Height, rectangle.Left);
                Size  size3    = new Size(rectangle.Height, rectangle.Width);
                rectangle = new Rectangle(location, size3);
            }
            return(Rectangle.Intersect(rect, rectangle));
        }
Ejemplo n.º 5
0
        private TextBoxContext GetParagraphAndRunIndex(Graphics g, int x, int y, out TextRun run, out int runX, out bool atEndOfLine)
        {
            List <Paragraph> rTParagraphs = RTParagraphs;
            Paragraph        paragraph    = null;
            int  num  = 0;
            int  num2 = 0;
            int  num3 = 0;
            int  i    = 0;
            bool flag = true;

            run         = null;
            runX        = 0;
            atEndOfLine = false;
            if (rTParagraphs == null || rTParagraphs.Count == 0)
            {
                return(null);
            }
            if (y < 0)
            {
                y = 0;
            }
            for (; i < rTParagraphs.Count; i++)
            {
                paragraph = rTParagraphs[i];
                if ((y < paragraph.OffsetY || y >= paragraph.OffsetY + paragraph.Height) && i + 1 != rTParagraphs.Count)
                {
                    continue;
                }
                y   -= paragraph.OffsetY;
                num  = TextBox.ConvertToPixels(paragraph.ParagraphProps.LeftIndent, Dpi);
                num2 = TextBox.ConvertToPixels(paragraph.ParagraphProps.RightIndent, Dpi);
                num3 = TextBox.ConvertToPixels(paragraph.ParagraphProps.HangingIndent, Dpi);
                flag = (m_rttextbox.TextBoxProps.Direction == RPLFormat.Directions.LTR);
                if (num3 < 0)
                {
                    if (flag)
                    {
                        num -= num3;
                    }
                    else
                    {
                        num2 -= num3;
                    }
                }
                int listLevel = paragraph.ParagraphProps.ListLevel;
                if (listLevel > 0)
                {
                    int num4 = listLevel * TextBox.ConvertToPixels(10.583333f, Dpi);
                    if (flag)
                    {
                        num += num4;
                    }
                    else
                    {
                        num2 += num4;
                    }
                }
                break;
            }
            TextBoxContext paragraphAndRunIndex = GetParagraphAndRunIndex(g, paragraph, num, num2, num3, x, y, flag, i == rTParagraphs.Count - 1, out run, out runX, out atEndOfLine);

            if (paragraphAndRunIndex != null)
            {
                paragraphAndRunIndex.ParagraphIndex = i;
            }
            return(paragraphAndRunIndex);
        }
Ejemplo n.º 6
0
        internal void Render(Graphics g, RectangleF rectangle, PointF offset, IEnumerable <RTSelectionHighlight> highlights, bool unitsInMM)
        {
            List <Paragraph> rTParagraphs = RTParagraphs;

            if (rTParagraphs == null || rTParagraphs.Count == 0)
            {
                return;
            }
            using (RevertingDeviceContext revertingDeviceContext = new RevertingDeviceContext(g, Dpi))
            {
                Win32DCSafeHandle hdc = revertingDeviceContext.Hdc;
                if (highlights != null)
                {
                    _ = RTTextbox.TextBoxProps.Direction;
                    foreach (RTSelectionHighlight highlight in highlights)
                    {
                        if (!HighlightStartLessThanOrEqualToEnd(highlight.SelectionStart, highlight.SelectionEnd))
                        {
                            TextBoxContext selectionStart = highlight.SelectionStart;
                            highlight.SelectionStart = highlight.SelectionEnd;
                            highlight.SelectionEnd   = selectionStart;
                        }
                        TextRun   run;
                        CaretInfo caretInfo = MapLocation(hdc, highlight.SelectionStart, relativeToRun: true, moveCaretToNextLine: true, out run);
                        TextRun   run2;
                        CaretInfo caretInfo2 = MapLocation(hdc, highlight.SelectionEnd, relativeToRun: true, moveCaretToNextLine: true, out run2);
                        if (caretInfo != null && caretInfo2 != null && run != null && run2 != null)
                        {
                            SetHighlighting(rTParagraphs, hdc, highlight, run, run2, caretInfo.Position.X, caretInfo2.Position.X);
                        }
                    }
                }
                Rectangle rect = (!unitsInMM) ? Rectangle.Round(rectangle) : new Rectangle(TextBox.ConvertToPixels(rectangle.X, m_dpi), TextBox.ConvertToPixels(rectangle.Y, m_dpi), TextBox.ConvertToPixels(rectangle.Width, m_dpi), TextBox.ConvertToPixels(rectangle.Height, m_dpi));
                revertingDeviceContext.XForm.Transform(ref rect);
                Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.CreateRectRgn(rect.Left - 1, rect.Top - 1, rect.Right + 1, rect.Bottom + 1);
                if (!win32ObjectSafeHandle.IsInvalid)
                {
                    try
                    {
                        if (Win32.SelectClipRgn(hdc, win32ObjectSafeHandle) == 0)
                        {
                            Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                        }
                    }
                    finally
                    {
                        win32ObjectSafeHandle.Close();
                    }
                }
                TextBox.Render(RTTextbox, rTParagraphs, hdc, FontCache, offset, rectangle, m_dpi, unitsInMM);
                if (Win32.SelectClipRgn(hdc, Win32ObjectSafeHandle.Zero) == 0)
                {
                    Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                }
            }
        }
Ejemplo n.º 7
0
 internal int GetHeightInPX()
 {
     return(TextBox.ConvertToPixels(GetHeight(), Dpi));
 }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        internal static float FlowVertical(TextBox textBox, Graphics g, FontCache fontCache, FlowContext flowContext, out float width, out float nextWidth)
        {
            width = (nextWidth = 0f);
            List <Paragraph> list               = null;
            int               num               = 0;
            int               val               = int.MaxValue;
            int               num2              = 0;
            float             height            = 0f;
            int               num3              = 0;
            List <TextLine>   list2             = null;
            float             dpiX              = g.DpiX;
            Win32DCSafeHandle win32DCSafeHandle = new Win32DCSafeHandle(g.GetHdc(), ownsHandle: false);

            if (textBox.VerticalText)
            {
                flowContext.VerticalCanGrow = textBox.TextBoxProps.CanGrow;
                num3 = TextBox.ConvertToPixels(flowContext.Height, dpiX);
            }
            else
            {
                num3 = TextBox.ConvertToPixels(flowContext.Width, dpiX);
            }
            try
            {
                list = Flow(textBox, win32DCSafeHandle, dpiX, fontCache, flowContext, keepLines: true, out height);
                if (list != null)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        list2 = list[i].TextLines;
                        if (list2 != null)
                        {
                            float leftIndent               = 0f;
                            float rightIndent              = 0f;
                            float hangingIndent            = 0f;
                            float num4                     = 0f;
                            RPLFormat.Directions direction = textBox.TextBoxProps.Direction;
                            list[i].GetParagraphIndents(direction, dpiX, out leftIndent, out rightIndent, out hangingIndent);
                            num4 = leftIndent + rightIndent;
                            if (list2[0].FirstLine)
                            {
                                num4 += hangingIndent;
                            }
                            num2 = Math.Max(num2, (int)num4);
                            for (int j = 0; j < list2.Count; j++)
                            {
                                num = Math.Max(num, list2[j].GetWidth(win32DCSafeHandle, fontCache, useVisualRunsIfAvailable: false) + (int)num4);
                                val = Math.Min(val, list2[j].GetWidth(win32DCSafeHandle, fontCache, useVisualRunsIfAvailable: false) + (int)num4);
                            }
                            list[i].TextLines = null;
                        }
                    }
                }
                val = Math.Max(val, num2);
                if (num > 0)
                {
                    int num5 = 0;
                    if (flowContext.VerticalCanGrow && flowContext.ForcedCharTrim)
                    {
                        num5 = flowContext.CharTrimmedRunWidth;
                    }
                    else
                    {
                        num5 = (num - val) / 2;
                        if (num5 == 0)
                        {
                            num5 = num / 2;
                        }
                        else
                        {
                            num5 += val;
                            if (num5 >= num3)
                            {
                                num5 /= 2;
                            }
                        }
                    }
                    width     = TextBox.ConvertToMillimeters(num, dpiX);
                    nextWidth = TextBox.ConvertToMillimeters(num5, dpiX);
                    return(height);
                }
                return(height);
            }
            finally
            {
                fontCache.ResetGraphics();
                if (!win32DCSafeHandle.IsInvalid)
                {
                    g.ReleaseHdc();
                }
            }
        }