public void GetParagraphIndents(RPLFormat.Directions direction, float dpiX, out float leftIndent, out float rightIndent, out float hangingIndent)
 {
     leftIndent    = (float)TextBox.ConvertToPixels(this.m_paragraphProps.LeftIndent, dpiX);
     rightIndent   = (float)TextBox.ConvertToPixels(this.m_paragraphProps.RightIndent, dpiX);
     hangingIndent = (float)TextBox.ConvertToPixels(this.m_paragraphProps.HangingIndent, dpiX);
     if (hangingIndent < 0.0)
     {
         if (direction == RPLFormat.Directions.LTR)
         {
             leftIndent -= hangingIndent;
         }
         else
         {
             rightIndent -= hangingIndent;
         }
     }
     if (this.m_paragraphProps.ListLevel > 0)
     {
         float num = (float)(this.m_paragraphProps.ListLevel * TextBox.ConvertToPixels(10.583333f, dpiX));
         if (direction == RPLFormat.Directions.LTR)
         {
             leftIndent += num;
         }
         else
         {
             rightIndent += num;
         }
     }
 }
Exemple #2
0
 public static void Render(TextBox textBox, List <Paragraph> paragraphs, Win32DCSafeHandle hdc, FontCache fontCache, PointF offset, RectangleF layoutRectangle, float dpiX, bool unitsInMM)
 {
     if (paragraphs != null && paragraphs.Count != 0)
     {
         Rectangle layoutRectangle2;
         Point     point;
         if (unitsInMM)
         {
             layoutRectangle2 = new Rectangle(TextBox.ConvertToPixels(layoutRectangle.X, dpiX), TextBox.ConvertToPixels(layoutRectangle.Y, dpiX), TextBox.ConvertToPixels(layoutRectangle.Width, dpiX), TextBox.ConvertToPixels(layoutRectangle.Height, dpiX));
             point            = new Point(TextBox.ConvertToPixels(offset.X, dpiX), TextBox.ConvertToPixels(offset.Y, dpiX));
         }
         else
         {
             layoutRectangle2 = new Rectangle((int)layoutRectangle.X, (int)layoutRectangle.Y, (int)layoutRectangle.Width, (int)layoutRectangle.Height);
             point            = new Point((int)offset.X, (int)offset.Y);
         }
         uint fMode   = Win32.SetTextAlign(hdc, 24u);
         int  iBkMode = Win32.SetBkMode(hdc, 1);
         Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, Win32ObjectSafeHandle.Zero);
         try
         {
             fontCache.WritingMode = textBox.TextBoxProps.WritingMode;
             int y = point.Y;
             for (int i = 0; i < paragraphs.Count; i++)
             {
                 TextBox.RenderParagraph(textBox, paragraphs[i], hdc, fontCache, point.X, ref y, layoutRectangle2, dpiX);
             }
         }
         finally
         {
             fMode   = Win32.SetTextAlign(hdc, fMode);
             iBkMode = Win32.SetBkMode(hdc, iBkMode);
             if (!win32ObjectSafeHandle.IsInvalid)
             {
                 Win32ObjectSafeHandle win32ObjectSafeHandle2 = Win32.SelectObject(hdc, win32ObjectSafeHandle);
                 win32ObjectSafeHandle2.SetHandleAsInvalid();
                 win32ObjectSafeHandle.SetHandleAsInvalid();
             }
         }
     }
 }
Exemple #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 = this.RTParagraphs;

            if (rTParagraphs != null && location.ParagraphIndex < rTParagraphs.Count)
            {
                Paragraph paragraph = rTParagraphs[location.ParagraphIndex];
                int       num2      = paragraph.OffsetY + TextBox.ConvertToPixels(paragraph.ParagraphProps.SpaceBefore, this.Dpi);
                int       num3      = TextBox.ConvertToPixels(paragraph.ParagraphProps.LeftIndent, this.Dpi);
                int       num4      = TextBox.ConvertToPixels(paragraph.ParagraphProps.RightIndent, this.Dpi);
                int       num5      = TextBox.ConvertToPixels(paragraph.ParagraphProps.HangingIndent, this.Dpi);
                bool      flag      = this.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, this.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, this.FontCache);
                    lineHeight  = textLine.GetHeight(hdc, this.FontCache);
                    lineYOffset = num2;
                    num2       += lineHeight;
                    RPLFormat.TextAlignments textAlignments = paragraph.ParagraphProps.Alignment;
                    if (textAlignments == RPLFormat.TextAlignments.General)
                    {
                        textAlignments = this.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 + (this.WidthInPX - num3 - num4) / 2 - textLine.GetWidth(hdc, this.FontCache) / 2;
                        break;

                    case RPLFormat.TextAlignments.Right:
                        num = this.WidthInPX - textLine.GetWidth(hdc, this.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; num += textRun.GetWidth(hdc, this.FontCache), 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))
                            {
                                continue;
                            }
                            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 = this.GetParagraphAndRunCoordinates(hdc, location, 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));
                        }
                    }
                }
                textRun = null;
                return(Point.Empty);
            }
            return(Point.Empty);
        }
Exemple #4
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(), false);
                runX        = x;
                run         = null;
                atEndOfLine = false;
                int num = 0;
                while (num < paragraph.TextLines.Count)
                {
                    TextLine textLine = paragraph.TextLines[num];
                    y -= textLine.GetHeight(win32DCSafeHandle, this.FontCache);
                    if (textLine.FirstLine)
                    {
                        y -= TextBox.ConvertToPixels(paragraph.ParagraphProps.SpaceBefore, this.Dpi);
                    }
                    else if (textLine.LastLine)
                    {
                        y -= TextBox.ConvertToPixels(paragraph.ParagraphProps.SpaceAfter, this.Dpi);
                    }
                    if (y >= 0 && num + 1 != paragraph.TextLines.Count)
                    {
                        num++;
                        continue;
                    }
                    int width = textLine.GetWidth(win32DCSafeHandle, this.FontCache);
                    if (x > this.WidthInPX)
                    {
                        atEndOfLine = (width > 0);
                        int  num2  = default(int);
                        bool flag2 = default(bool);
                        run = this.GetLastNonLineBreakRun(textLine.LogicalRuns, out num2, out flag2);
                        TextBoxContext textBoxContext = new TextBoxContext();
                        textBoxContext.TextRunIndex = run.TextRunProperties.IndexInParagraph;
                        if (flag2 && run.CharacterCount > 0)
                        {
                            textBoxContext.TextRunCharacterIndex = run.CharacterIndexInOriginal + num2 + 1;
                        }
                        else
                        {
                            textBoxContext.TextRunCharacterIndex = run.CharacterIndexInOriginal;
                        }
                        run = null;
                        return(textBoxContext);
                    }
                    if (x < 0)
                    {
                        atEndOfLine = false;
                        int num3 = default(int);
                        run = this.GetFirstNonLineBreakRun(textLine.LogicalRuns, out num3);
                        TextBoxContext textBoxContext2 = new TextBoxContext();
                        textBoxContext2.TextRunIndex          = run.TextRunProperties.IndexInParagraph;
                        textBoxContext2.TextRunCharacterIndex = run.CharacterIndexInOriginal + num3;
                        run = null;
                        return(textBoxContext2);
                    }
                    RPLFormat.TextAlignments textAlignments = paragraph.ParagraphProps.Alignment;
                    if (textAlignments == RPLFormat.TextAlignments.General)
                    {
                        textAlignments = this.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 + (this.WidthInPX - leftIndent - rightIndent) / 2 - width / 2);
                        break;

                    case RPLFormat.TextAlignments.Right:
                        runX = x - (this.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(this.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;
                }
            }
        }
Exemple #5
0
        private TextBoxContext GetParagraphAndRunIndex(Graphics g, int x, int y, out TextRun run, out int runX, out bool atEndOfLine)
        {
            List <Paragraph> rTParagraphs = this.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)
            {
                if (y < 0)
                {
                    y = 0;
                }
                for (; i < rTParagraphs.Count; i++)
                {
                    paragraph = rTParagraphs[i];
                    if (y >= paragraph.OffsetY && y < paragraph.OffsetY + paragraph.Height)
                    {
                        goto IL_006f;
                    }
                    if (i + 1 == rTParagraphs.Count)
                    {
                        goto IL_006f;
                    }
                    continue;
IL_006f:
                    y   -= paragraph.OffsetY;
                    num  = TextBox.ConvertToPixels(paragraph.ParagraphProps.LeftIndent, this.Dpi);
                    num2 = TextBox.ConvertToPixels(paragraph.ParagraphProps.RightIndent, this.Dpi);
                    num3 = TextBox.ConvertToPixels(paragraph.ParagraphProps.HangingIndent, this.Dpi);
                    flag = (this.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, this.Dpi);
                        if (flag)
                        {
                            num += num4;
                        }
                        else
                        {
                            num2 += num4;
                        }
                    }
                    break;
                }
                TextBoxContext paragraphAndRunIndex = this.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);
            }
            return(null);
        }
Exemple #6
0
        public Rectangle GetTextBoundingBoxPx(Rectangle rect, RPLFormat.VerticalAlignments vAlign)
        {
            if (this.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 (this.RTTextbox.VerticalText)
            {
                size2 = new Size(size2.Height, size2.Width);
            }
            foreach (Paragraph rTParagraph in this.RTParagraphs)
            {
                int num2 = 0;
                if (rTParagraph.TextLines.Count == 1 && rTParagraph.ParagraphProps.HangingIndent > 0.0)
                {
                    num2 += TextBox.ConvertToPixels(rTParagraph.ParagraphProps.HangingIndent, this.Dpi);
                }
                foreach (TextLine textLine in rTParagraph.TextLines)
                {
                    size.Width   = Math.Max(Math.Max(size.Width, textLine.GetWidth(Win32DCSafeHandle.Zero, this.FontCache)), 10);
                    size.Height += textLine.GetHeight(Win32DCSafeHandle.Zero, this.FontCache);
                }
                switch (rTParagraph.ParagraphProps.Alignment)
                {
                case RPLFormat.TextAlignments.General:
                    if (this.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.ToString());
                }
                num2 = ((this.RTTextbox.TextBoxProps.Direction != 0) ? (num2 - TextBox.ConvertToPixels((float)(rTParagraph.ParagraphProps.RightIndent + 10.583333015441895 * (float)rTParagraph.ParagraphProps.ListLevel), this.Dpi)) : (num2 + TextBox.ConvertToPixels((float)(rTParagraph.ParagraphProps.LeftIndent + 10.583333015441895 * (float)rTParagraph.ParagraphProps.ListLevel), this.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 (this.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));
        }
Exemple #7
0
        public void Render(Graphics g, RectangleF rectangle, PointF offset, IEnumerable <RTSelectionHighlight> highlights, bool unitsInMM)
        {
            List <Paragraph> rTParagraphs = this.RTParagraphs;

            if (rTParagraphs != null && rTParagraphs.Count != 0)
            {
                using (RevertingDeviceContext revertingDeviceContext = new RevertingDeviceContext(g, this.Dpi))
                {
                    Win32DCSafeHandle hdc = revertingDeviceContext.Hdc;
                    if (highlights != null)
                    {
                        RPLFormat.Directions direction = this.RTTextbox.TextBoxProps.Direction;
                        foreach (RTSelectionHighlight highlight in highlights)
                        {
                            if (!RichTextRenderer.HighlightStartLessThanOrEqualToEnd(highlight.SelectionStart, highlight.SelectionEnd))
                            {
                                TextBoxContext selectionStart = highlight.SelectionStart;
                                highlight.SelectionStart = highlight.SelectionEnd;
                                highlight.SelectionEnd   = selectionStart;
                            }
                            TextRun   textRun    = default(TextRun);
                            CaretInfo caretInfo  = this.MapLocation(hdc, highlight.SelectionStart, true, true, out textRun);
                            TextRun   textRun2   = default(TextRun);
                            CaretInfo caretInfo2 = this.MapLocation(hdc, highlight.SelectionEnd, true, true, out textRun2);
                            if (caretInfo != null && caretInfo2 != null && textRun != null && textRun2 != null)
                            {
                                this.SetHighlighting(rTParagraphs, hdc, highlight, textRun, textRun2, caretInfo.Position.X, caretInfo2.Position.X);
                            }
                        }
                    }
                    Rectangle rectangle2 = (!unitsInMM) ? Rectangle.Round(rectangle) : new Rectangle(TextBox.ConvertToPixels(rectangle.X, this.m_dpi), TextBox.ConvertToPixels(rectangle.Y, this.m_dpi), TextBox.ConvertToPixels(rectangle.Width, this.m_dpi), TextBox.ConvertToPixels(rectangle.Height, this.m_dpi));
                    revertingDeviceContext.XForm.Transform(ref rectangle2);
                    Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.CreateRectRgn(rectangle2.Left - 1, rectangle2.Top - 1, rectangle2.Right + 1, rectangle2.Bottom + 1);
                    if (!win32ObjectSafeHandle.IsInvalid)
                    {
                        try
                        {
                            if (Win32.SelectClipRgn(hdc, win32ObjectSafeHandle) == 0)
                            {
                                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                            }
                        }
                        finally
                        {
                            win32ObjectSafeHandle.Close();
                        }
                    }
                    TextBox.Render(this.RTTextbox, rTParagraphs, hdc, this.FontCache, offset, rectangle, this.m_dpi, unitsInMM);
                    if (Win32.SelectClipRgn(hdc, Win32ObjectSafeHandle.Zero) == 0)
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }
                }
            }
        }
Exemple #8
0
 public int GetHeightInPX()
 {
     return(TextBox.ConvertToPixels(this.GetHeight(), this.Dpi));
 }
Exemple #9
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;
                    }
                }
            }
        }
Exemple #10
0
 public static List <Paragraph> Flow(TextBox textBox, Win32DCSafeHandle hdc, float dpiX, FontCache fontCache, FlowContext flowContext, bool keepLines, out float height)
 {
     if (!(flowContext.Height <= 0.0) && !(flowContext.Width <= 0.0))
     {
         int                   num                   = TextBox.ConvertToPixels(flowContext.ContentOffset, dpiX);
         int                   pixels                = 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)
         {
             flowContext.VerticalCanGrow = textBox.TextBoxProps.CanGrow;
             flowContextSize             = new SizeF((float)TextBox.ConvertToPixels(flowContext.Height, dpiX), (float)TextBox.ConvertToPixels(flowContext.Width, dpiX));
         }
         else
         {
             flowContextSize = new SizeF((float)TextBox.ConvertToPixels(flowContext.Width, dpiX), (float)TextBox.ConvertToPixels(flowContext.Height, dpiX));
         }
         fontCache.WritingMode = textBox.TextBoxProps.WritingMode;
         try
         {
             while (context.ParagraphIndex < textBox.Paragraphs.Count)
             {
                 Paragraph paragraph = textBox.Paragraphs[context.ParagraphIndex];
                 paragraph.OffsetY = num;
                 bool flag = LineBreaker.FlowParagraph(paragraph, direction, hdc, dpiX, fontCache, flowContext, keepLines, flowContextSize, ref pixels);
                 num += paragraph.Height;
                 if (!keepLines)
                 {
                     paragraph.TextLines = null;
                 }
                 if (!flag)
                 {
                     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)
             {
                 Win32ObjectSafeHandle win32ObjectSafeHandle2 = Win32.SelectObject(hdc, win32ObjectSafeHandle);
                 win32ObjectSafeHandle2.SetHandleAsInvalid();
                 win32ObjectSafeHandle.SetHandleAsInvalid();
             }
         }
         height = TextBox.ConvertToMillimeters(num, dpiX);
         flowContext.ContentOffset = TextBox.ConvertToMillimeters(pixels, dpiX);
         return(list);
     }
     height = 0f;
     return(null);
 }
Exemple #11
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);
        }
Exemple #12
0
        public 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               = 2147483647;
            int               num2              = 0;
            float             result            = 0f;
            int               num3              = 0;
            List <TextLine>   list2             = null;
            float             dpiX              = g.DpiX;
            Win32DCSafeHandle win32DCSafeHandle = new Win32DCSafeHandle(g.GetHdc(), false);

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