Ejemplo n.º 1
0
        private CaretInfo MapLocation(Graphics g, TextBoxContext location, bool relativeToRun, bool moveCaretToNextLine, out TextRun run)
        {
            Win32DCSafeHandle win32DCSafeHandle = null;
            bool flag = false;

            try
            {
                if (g == null)
                {
                    flag = true;
                    g    = Graphics.FromHwnd(IntPtr.Zero);
                }
                win32DCSafeHandle = new Win32DCSafeHandle(g.GetHdc(), ownsHandle: false);
                return(MapLocation(win32DCSafeHandle, location, relativeToRun, moveCaretToNextLine, out run));
            }
            finally
            {
                if (!win32DCSafeHandle.IsInvalid)
                {
                    g.ReleaseHdc();
                }
                if (flag)
                {
                    g.Dispose();
                    g = null;
                }
            }
        }
Ejemplo n.º 2
0
        internal void AdvanceToNextRun(TextBoxContext context, bool skipEmptyRuns)
        {
            if (context == null || context.TextRunIndex >= m_runs.Count)
            {
                return;
            }
            TextRun textRun = m_runs[context.TextRunIndex];
            int     num     = (textRun.Text != null) ? textRun.Text.Length : 0;

            if (m_runs.Count == 1 && num == 0)
            {
                if (m_processedEmptyParagraph)
                {
                    context.TextRunIndex++;
                    context.TextRunCharacterIndex = 0;
                }
                else
                {
                    m_processedEmptyParagraph = true;
                }
            }
            else if (context.TextRunCharacterIndex == num && (skipEmptyRuns || num > 0))
            {
                context.TextRunIndex++;
                context.TextRunCharacterIndex = 0;
            }
        }
Ejemplo n.º 3
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.º 4
0
 private static bool HighlightStartLessThanOrEqualToEnd(TextBoxContext start, TextBoxContext end)
 {
     if (start.ParagraphIndex == end.ParagraphIndex)
     {
         if (start.TextRunIndex == end.TextRunIndex)
         {
             return(start.TextRunCharacterIndex <= end.TextRunCharacterIndex);
         }
         return(start.TextRunIndex <= end.TextRunIndex);
     }
     return(start.ParagraphIndex <= end.ParagraphIndex);
 }
Ejemplo n.º 5
0
 internal bool AtEndOfParagraph(TextBoxContext context)
 {
     if (context == null)
     {
         return(false);
     }
     if (context.TextRunIndex < m_runs.Count)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 6
0
        private CaretInfo MapLocation(Win32DCSafeHandle hdc, TextBoxContext location, bool relativeToRun, bool moveCaretToNextLine, out TextRun run)
        {
            CaretInfo caretInfo = null;

            run = null;
            int   lineYOffset;
            int   lineHeight;
            int   textRunCharacterIndex;
            bool  isFirstLine;
            bool  isLastLine;
            Point paragraphAndRunCoordinates = GetParagraphAndRunCoordinates(hdc, location, moveCaretToNextLine, out lineYOffset, out lineHeight, out run, out textRunCharacterIndex, out isFirstLine, out isLastLine);

            if (run != null)
            {
                GlyphData      glyphData            = run.GlyphData;
                GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData;
                int            piX = 0;
                if (glyphData != null && run.CharacterCount > 0)
                {
                    int num = Win32.ScriptCPtoX(textRunCharacterIndex, fTrailing: false, run.CharacterCount, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, glyphData.Advances, ref run.SCRIPT_ANALYSIS, ref piX);
                    if (Win32.Failed(num))
                    {
                        Marshal.ThrowExceptionForHR(num);
                    }
                }
                caretInfo = new CaretInfo();
                CachedFont cachedFont = run.GetCachedFont(hdc, FontCache);
                caretInfo.Height      = cachedFont.GetHeight(hdc, FontCache);
                caretInfo.Ascent      = cachedFont.GetAscent(hdc, FontCache);
                caretInfo.Descent     = cachedFont.GetDescent(hdc, FontCache);
                caretInfo.LineHeight  = lineHeight;
                caretInfo.LineYOffset = lineYOffset;
                caretInfo.IsFirstLine = isFirstLine;
                caretInfo.IsLastLine  = isLastLine;
                _ = RTParagraphs;
                int y = paragraphAndRunCoordinates.Y - caretInfo.Ascent;
                if (relativeToRun)
                {
                    caretInfo.Position = new Point(piX, y);
                }
                else
                {
                    caretInfo.Position = new Point(paragraphAndRunCoordinates.X + piX, y);
                }
            }
            return(caretInfo);
        }
Ejemplo n.º 7
0
        internal TextBoxContext MapPoint(Graphics g, PointF pt, out bool atEndOfLine)
        {
            TextBoxContext textBoxContext = null;

            atEndOfLine    = false;
            textBoxContext = GetParagraphAndRunIndex(g, (int)pt.X, (int)pt.Y, out TextRun run, out int runX, out atEndOfLine);
            if (run != null)
            {
                GlyphData      glyphData            = run.GlyphData;
                GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData;
                if (glyphData != null && run.CharacterCount > 0)
                {
                    int piCP       = 0;
                    int piTrailing = 0;
                    int num        = Win32.ScriptXtoCP(runX, run.CharacterCount, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, glyphData.Advances, ref run.SCRIPT_ANALYSIS, ref piCP, ref piTrailing);
                    if (Win32.Failed(num))
                    {
                        Marshal.ThrowExceptionForHR(num);
                    }
                    if (run.ScriptAnalysis.fLayoutRTL == 1)
                    {
                        if (piCP == -1)
                        {
                            textBoxContext.TextRunCharacterIndex += run.CharacterCount;
                        }
                        else if (pt.X <= 0f)
                        {
                            TextBoxContext textBoxContext2 = textBoxContext;
                            textBoxContext2.TextRunCharacterIndex = textBoxContext2.TextRunCharacterIndex;
                        }
                        else
                        {
                            textBoxContext.TextRunCharacterIndex += piCP + piTrailing;
                        }
                    }
                    else
                    {
                        textBoxContext.TextRunCharacterIndex += piCP + piTrailing;
                    }
                }
            }
            if (textBoxContext == null)
            {
                textBoxContext = new TextBoxContext();
            }
            return(textBoxContext);
        }
Ejemplo n.º 8
0
 internal TextRun GetSubRunForLine(TextBoxContext context, ref bool newLine)
 {
     AdvanceToNextRun(context);
     if (context.TextRunIndex < m_runs.Count)
     {
         TextRun textRun = m_runs[context.TextRunIndex];
         string  text    = null;
         bool    flag    = false;
         if (context.TextRunCharacterIndex == 0)
         {
             text = (textRun.Text ?? "");
         }
         else
         {
             flag = true;
             text = textRun.Text.Substring(context.TextRunCharacterIndex);
         }
         int num = text.IndexOf('\n');
         if (num != -1)
         {
             if (num + 1 < text.Length)
             {
                 text = text.Substring(0, num + 1);
                 flag = true;
             }
             newLine = true;
         }
         if (flag)
         {
             SCRIPT_LOGATTR[] array = new SCRIPT_LOGATTR[text.Length];
             Array.Copy(textRun.ScriptLogAttr, context.TextRunCharacterIndex, array, 0, array.Length);
             TextRun textRun2 = textRun.Split(text, array);
             textRun2.CharacterIndexInOriginal += context.TextRunCharacterIndex;
             textRun2.Clone = true;
             context.TextRunCharacterIndex += text.Length;
             return(textRun2);
         }
         context.TextRunCharacterIndex += text.Length;
         return(textRun);
     }
     return(null);
 }
Ejemplo n.º 9
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.º 10
0
        internal CaretInfo MapLocation(Graphics g, TextBoxContext location, bool moveCaretToNextLine)
        {
            TextRun run;

            return(MapLocation(g, location, relativeToRun: false, moveCaretToNextLine, out run));
        }
Ejemplo n.º 11
0
 internal CaretInfo MapLocation(TextBoxContext location, bool moveCaretToNextLine)
 {
     return(MapLocation(null, location, moveCaretToNextLine));
 }
Ejemplo n.º 12
0
 internal RTSelectionHighlight(TextBoxContext Start, TextBoxContext End)
 {
     m_selectionStart = Start;
     m_selectionEnd   = End;
 }
Ejemplo n.º 13
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.º 14
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.º 15
0
        private static void FoldLineAt(TextLine line, int runIndex, int runCharIndex, TextBoxContext context, Stack <int> lineRunsIndex, Stack <int> lineRunsCharIndex)
        {
            TextRun textRun = line.LogicalRuns[runIndex];

            for (int num = line.LogicalRuns.Count - 1; num > runIndex; num--)
            {
                context.TextRunIndex          = lineRunsIndex.Pop();
                context.TextRunCharacterIndex = lineRunsCharIndex.Pop();
                line.LogicalRuns.RemoveAt(num);
            }
            string text = textRun.Text;

            if (runCharIndex < text.Length)
            {
                context.TextRunCharacterIndex -= text.Length - runCharIndex;
                if (textRun.Clone)
                {
                    textRun.TerminateAt(runCharIndex);
                    return;
                }
                SCRIPT_LOGATTR[] array = new SCRIPT_LOGATTR[runCharIndex];
                Array.Copy(textRun.ScriptLogAttr, 0, array, 0, array.Length);
                string  text2    = text.Substring(0, runCharIndex);
                TextRun textRun2 = textRun.Split(text2, array);
                textRun2.Clone             = true;
                line.LogicalRuns[runIndex] = textRun2;
            }
        }
Ejemplo n.º 16
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.º 17
0
 internal void AdvanceToNextRun(TextBoxContext context)
 {
     AdvanceToNextRun(context, skipEmptyRuns: true);
 }
Ejemplo n.º 18
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.º 19
0
 internal CaretInfo MapLocation(Graphics g, TextBoxContext location)
 {
     return(MapLocation(g, location, moveCaretToNextLine: false));
 }
Ejemplo n.º 20
0
 internal RTSelectionHighlight(TextBoxContext Start, TextBoxContext End, Color Color)
 {
     m_selectionStart = Start;
     m_selectionEnd   = End;
     m_color          = Color;
 }