public void AdvanceToNextRun(TextBoxContext context, bool skipEmptyRuns)
 {
     if (context != null && context.TextRunIndex < this.m_runs.Count)
     {
         TextRun textRun = this.m_runs[context.TextRunIndex];
         int     num     = (textRun.Text != null) ? textRun.Text.Length : 0;
         if (this.m_runs.Count == 1 && num == 0)
         {
             if (this.m_processedEmptyParagraph)
             {
                 context.TextRunIndex++;
                 context.TextRunCharacterIndex = 0;
             }
             else
             {
                 this.m_processedEmptyParagraph = true;
             }
         }
         else if (context.TextRunCharacterIndex == num)
         {
             if (!skipEmptyRuns && num <= 0)
             {
                 return;
             }
             context.TextRunIndex++;
             context.TextRunCharacterIndex = 0;
         }
     }
 }
示例#2
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(), false);
                return(this.MapLocation(win32DCSafeHandle, location, relativeToRun, moveCaretToNextLine, out run));
            }
            finally
            {
                if (!win32DCSafeHandle.IsInvalid)
                {
                    g.ReleaseHdc();
                }
                if (flag)
                {
                    g.Dispose();
                    g = null;
                }
            }
        }
        public TextBoxContext Clone()
        {
            TextBoxContext textBoxContext = new TextBoxContext();

            textBoxContext.ParagraphIndex        = this.ParagraphIndex;
            textBoxContext.TextRunIndex          = this.TextRunIndex;
            textBoxContext.TextRunCharacterIndex = this.TextRunCharacterIndex;
            return(textBoxContext);
        }
示例#4
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());
                    }
                }
            }
        }
 public bool AtEndOfParagraph(TextBoxContext context)
 {
     if (context == null)
     {
         return(false);
     }
     if (context.TextRunIndex < this.m_runs.Count)
     {
         return(false);
     }
     return(true);
 }
示例#6
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);
 }
示例#7
0
        public TextBoxContext MapPoint(Graphics g, PointF pt, out bool atEndOfLine)
        {
            TextBoxContext textBoxContext = null;

            atEndOfLine = false;
            TextRun textRun = default(TextRun);
            int     iX      = default(int);

            textBoxContext = this.GetParagraphAndRunIndex(g, (int)pt.X, (int)pt.Y, out textRun, out iX, out atEndOfLine);
            if (textRun != null)
            {
                GlyphData      glyphData            = textRun.GlyphData;
                GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData;
                if (glyphData != null && textRun.CharacterCount > 0)
                {
                    int num  = 0;
                    int num2 = 0;
                    int num3 = Win32.ScriptXtoCP(iX, textRun.CharacterCount, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, glyphData.Advances, ref textRun.SCRIPT_ANALYSIS, ref num, ref num2);
                    if (Win32.Failed(num3))
                    {
                        Marshal.ThrowExceptionForHR(num3);
                    }
                    if (textRun.ScriptAnalysis.fLayoutRTL == 1)
                    {
                        if (num == -1)
                        {
                            textBoxContext.TextRunCharacterIndex += textRun.CharacterCount;
                        }
                        else if (pt.X <= 0.0)
                        {
                            TextBoxContext textBoxContext2 = textBoxContext;
                            textBoxContext2.TextRunCharacterIndex = textBoxContext2.TextRunCharacterIndex;
                        }
                        else
                        {
                            textBoxContext.TextRunCharacterIndex += num + num2;
                        }
                    }
                    else
                    {
                        textBoxContext.TextRunCharacterIndex += num + num2;
                    }
                }
            }
            if (textBoxContext == null)
            {
                textBoxContext = new TextBoxContext();
            }
            return(textBoxContext);
        }
示例#8
0
        private CaretInfo MapLocation(Win32DCSafeHandle hdc, TextBoxContext location, bool relativeToRun, bool moveCaretToNextLine, out TextRun run)
        {
            CaretInfo caretInfo = null;

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

            if (run != null)
            {
                GlyphData      glyphData            = run.GlyphData;
                GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData;
                int            num = 0;
                if (glyphData != null && run.CharacterCount > 0)
                {
                    int num2 = Win32.ScriptCPtoX(iCP, false, run.CharacterCount, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, glyphData.Advances, ref run.SCRIPT_ANALYSIS, ref num);
                    if (Win32.Failed(num2))
                    {
                        Marshal.ThrowExceptionForHR(num2);
                    }
                }
                caretInfo = new CaretInfo();
                CachedFont cachedFont = run.GetCachedFont(hdc, this.FontCache);
                caretInfo.Height      = cachedFont.GetHeight(hdc, this.FontCache);
                caretInfo.Ascent      = cachedFont.GetAscent(hdc, this.FontCache);
                caretInfo.Descent     = cachedFont.GetDescent(hdc, this.FontCache);
                caretInfo.LineHeight  = lineHeight;
                caretInfo.LineYOffset = lineYOffset;
                caretInfo.IsFirstLine = isFirstLine;
                caretInfo.IsLastLine  = isLastLine;
                List <Paragraph> rTParagraph = this.RTParagraphs;
                int y = paragraphAndRunCoordinates.Y - caretInfo.Ascent;
                if (relativeToRun)
                {
                    caretInfo.Position = new Point(num, y);
                }
                else
                {
                    caretInfo.Position = new Point(paragraphAndRunCoordinates.X + num, y);
                }
            }
            return(caretInfo);
        }
 public TextRun GetSubRunForLine(TextBoxContext context, ref bool newLine)
 {
     this.AdvanceToNextRun(context);
     if (context.TextRunIndex < this.m_runs.Count)
     {
         TextRun textRun = this.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);
 }
 public RTSelectionHighlight(TextBoxContext Start, TextBoxContext End, Color Color)
 {
     this.m_selectionStart = Start;
     this.m_selectionEnd   = End;
     this.m_color          = Color;
 }
示例#11
0
        public CaretInfo MapLocation(Graphics g, TextBoxContext location, bool moveCaretToNextLine)
        {
            TextRun textRun = default(TextRun);

            return(this.MapLocation(g, location, false, moveCaretToNextLine, out textRun));
        }
示例#12
0
 public CaretInfo MapLocation(TextBoxContext location, bool moveCaretToNextLine)
 {
     return(this.MapLocation(null, location, moveCaretToNextLine));
 }
示例#13
0
 public CaretInfo MapLocation(Graphics g, TextBoxContext location)
 {
     return(this.MapLocation(g, location, false));
 }
示例#14
0
 public CaretInfo MapLocation(TextBoxContext location)
 {
     return(this.MapLocation(null, location, false));
 }
示例#15
0
        private TextBoxContext GetParagraphAndRunIndex(Win32DCSafeHandle hdc, Paragraph paragraph, TextLine line, int x, int lineWidth, bool lastParagraph, out TextRun run, ref int runX, out bool atEndOfLine)
        {
            atEndOfLine = false;
            run         = null;
            int count = line.VisualRuns.Count;
            int num   = 0;

            while (num < count)
            {
                run = line.VisualRuns[num];
                int width = run.GetWidth(hdc, this.FontCache, num == count - 1);
                if (runX - width > 0 && num + 1 != count)
                {
                    runX -= width;
                    num++;
                    continue;
                }
                TextBoxContext textBoxContext;
                if (runX - width > 0)
                {
                    atEndOfLine = true;
                    if (run.ScriptAnalysis.fLayoutRTL == 1 && x >= lineWidth)
                    {
                        run            = line.VisualRuns[count - 1];
                        textBoxContext = new TextBoxContext();
                        textBoxContext.TextRunIndex          = run.TextRunProperties.IndexInParagraph;
                        textBoxContext.TextRunCharacterIndex = run.CharacterIndexInOriginal;
                        return(textBoxContext);
                    }
                }
                int num2           = 0;
                int characterCount = run.CharacterCount;
                if (characterCount > 0)
                {
                    if (run.ScriptAnalysis.fLayoutRTL == 0 && num + 1 == count)
                    {
                        goto IL_00f0;
                    }
                    if (run.ScriptAnalysis.fLayoutRTL == 1 && num == 0)
                    {
                        goto IL_00f0;
                    }
                    if (num == 0 && (run.Text[0] == '\r' || run.Text[0] == '\n'))
                    {
                        num2 = -1;
                    }
                }
                else if (lastParagraph && line.LastLine && !line.FirstLine)
                {
                    num2 = 1;
                }
                goto IL_025d;
IL_025d:
                textBoxContext = new TextBoxContext();
                textBoxContext.TextRunIndex          = run.TextRunProperties.IndexInParagraph;
                textBoxContext.TextRunCharacterIndex = run.CharacterIndexInOriginal + num2;
                return(textBoxContext);

IL_00f0:
                if (width <= 0)
                {
                    string text = run.Text;
                    if (characterCount > 1 && text[characterCount - 2] == '\r' && text[characterCount - 1] == '\n')
                    {
                        num2 = ((run.ScriptAnalysis.fLayoutRTL != 0) ? (-1) : (-2));
                    }
                    else if (text[characterCount - 1] == '\n' && run.ScriptAnalysis.fLayoutRTL == 0)
                    {
                        if (num > 0)
                        {
                            run = line.VisualRuns[num - 1];
                            if (run.CharacterCount > 0 && run.Text[run.CharacterCount - 1] == '\r')
                            {
                                num2 = -1;
                            }
                        }
                        else
                        {
                            num2 = -1;
                        }
                    }
                }
                else if (num + 1 == count && (run.Text[characterCount - 1] == '\r' || run.Text[characterCount - 1] == '\n'))
                {
                    num2 = -1;
                }
                else if (num == 0 && (run.Text[0] == '\r' || run.Text[0] == '\n'))
                {
                    num2 = -1;
                }
                goto IL_025d;
            }
            return(null);
        }
示例#16
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;
                }
            }
        }
示例#17
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);
        }
 public RTSelectionHighlight(TextBoxContext Start, TextBoxContext End)
 {
     this.m_selectionStart = Start;
     this.m_selectionEnd   = End;
 }
示例#19
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);
                }
                else
                {
                    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;
                }
            }
        }
示例#20
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);
 }
示例#21
0
 public void AdvanceToNextRun(TextBoxContext context)
 {
     this.AdvanceToNextRun(context, true);
 }
示例#22
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);
        }
示例#23
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);
        }