Esempio n. 1
0
        public TextRun(string text, TextRun textRun, SCRIPT_LOGATTR[] scriptLogAttr)
            : this(text, textRun)
        {
            this.SCRIPT_ANALYSIS    = textRun.SCRIPT_ANALYSIS;
            this.ScriptLogAttr      = scriptLogAttr;
            this.m_cachedFont       = textRun.CachedFont;
            this.m_itemizedScriptId = textRun.ItemizedScriptId;
            bool hasEastAsianChars = this.HasEastAsianChars;

            this.m_runState        = textRun.State;
            this.HasEastAsianChars = hasEastAsianChars;
        }
        public string GetNextTextBlock()
        {
            if (this.m_lastRunIndex >= this.m_runs.Count)
            {
                this.m_lastCharIndexInRun = 0;
                this.m_lastRunIndex       = 0;
                return(null);
            }
            StringBuilder stringBuilder = new StringBuilder();
            bool          flag          = true;
            bool          flag2         = false;

            while (this.m_lastRunIndex < this.m_runs.Count)
            {
                TextRun textRun = this.m_runs[this.m_lastRunIndex];
                if (!flag)
                {
                    if (textRun.IsPlaceholderTextRun)
                    {
                        break;
                    }
                    if (flag2)
                    {
                        break;
                    }
                }
                int length = textRun.Text.Length;
                if (stringBuilder.Length + length - this.m_lastCharIndexInRun > 21845)
                {
                    int num  = 21845 - stringBuilder.Length + this.m_lastCharIndexInRun - 1;
                    int num2 = Math.Max(num - 100, this.m_lastCharIndexInRun);
                    for (int num3 = num; num3 >= num2; num3--)
                    {
                        char c = textRun.Text[num3];
                        if (!char.IsHighSurrogate(c) && !char.IsLetterOrDigit(c))
                        {
                            num = ((c != '\r' || num3 - 1 <= this.m_lastCharIndexInRun) ? num3 : (num3 - 1));
                            break;
                        }
                    }
                    stringBuilder.Append(textRun.Text, this.m_lastCharIndexInRun, num - this.m_lastCharIndexInRun + 1);
                    this.m_lastCharIndexInRun = num + 1;
                    flag2 = textRun.IsPlaceholderTextRun;
                    return(stringBuilder.ToString());
                }
                stringBuilder.Append(textRun.Text, this.m_lastCharIndexInRun, length - this.m_lastCharIndexInRun);
                this.m_lastCharIndexInRun = 0;
                flag  = false;
                flag2 = textRun.IsPlaceholderTextRun;
                this.m_lastRunIndex++;
            }
            return(stringBuilder.ToString());
        }
 public TexRunShapeData(TextRun run, bool storeGlyph, int startIndex)
     : this(run, storeGlyph)
 {
     SCRIPT_LOGATTR[] scriptLogAttr = run.ScriptLogAttr;
     if (startIndex > 0 && scriptLogAttr != null)
     {
         int num  = scriptLogAttr.Length;
         int num2 = num - startIndex;
         SCRIPT_LOGATTR[] array = new SCRIPT_LOGATTR[num2];
         Array.Copy(scriptLogAttr, startIndex, array, 0, num2);
         this.m_scriptLogAttr = array;
     }
 }
Esempio n. 4
0
        private static int FindFoldTextPosition_CharacterTrim(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, float maxWidth)
        {
            string text = run.Text;

            int[] logicalWidths = run.GetLogicalWidths(hdc, fontCache);
            int   i             = 0;

            for (int num = 0; i < text.Length && (float)(num + logicalWidths[i]) <= maxWidth; i++)
            {
                num += logicalWidths[i];
            }
            return(i);
        }
Esempio n. 5
0
 public AspNetCore.ReportingServices.Rendering.RichText.Paragraph GetRichTextParagraph()
 {
     AspNetCore.ReportingServices.Rendering.RichText.Paragraph paragraph = new AspNetCore.ReportingServices.Rendering.RichText.Paragraph(this, this.m_textRuns.Count);
     for (int i = 0; i < this.m_textRuns.Count; i++)
     {
         AspNetCore.ReportingServices.Rendering.RichText.TextRun richTextRun = this.m_textRuns[i].GetRichTextRun();
         if (richTextRun != null)
         {
             paragraph.Runs.Add(richTextRun);
         }
     }
     return(paragraph);
 }
Esempio n. 6
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);
        }
        private List <TextRun> ExtractRuns(int startingParaCharIndex, int endingParaCharIndex, SCRIPT_ANALYSIS analysis)
        {
            List <TextRun> list          = new List <TextRun>();
            StringBuilder  stringBuilder = new StringBuilder();
            int            num           = 0;
            int            num2          = 0;
            TextRun        textRun       = null;

            for (int i = 0; i < this.m_runs.Count; i++)
            {
                TextRun textRun2 = this.m_runs[i];
                num2 = num + textRun2.CharacterCount - 1;
                int num3 = -1;
                if (startingParaCharIndex <= num)
                {
                    num3 = 0;
                }
                else if (startingParaCharIndex <= num2)
                {
                    num3 = startingParaCharIndex - num;
                }
                if (num3 >= 0)
                {
                    if (endingParaCharIndex <= num2)
                    {
                        int num4 = endingParaCharIndex - num - num3 + 1;
                        textRun = textRun2.GetSubRun(num3, num4);
                        textRun.SCRIPT_ANALYSIS = analysis;
                        stringBuilder.Append(textRun.Text);
                        list.Add(textRun);
                        if (endingParaCharIndex == num2 && num4 == 1 && i == this.m_runs.Count - 1 && textRun.Text[0] == '\n')
                        {
                            textRun = textRun2.GetSubRun(num3 + 1, 0);
                            textRun.SCRIPT_ANALYSIS = analysis;
                            list.Add(textRun);
                        }
                        Paragraph.AnalyzeForBreakPositions(list, stringBuilder.ToString());
                        return(list);
                    }
                    textRun = textRun2.GetSubRun(num3);
                    textRun.SCRIPT_ANALYSIS = analysis;
                    stringBuilder.Append(textRun.Text);
                    list.Add(textRun);
                }
                num = num2 + 1;
            }
            Paragraph.AnalyzeForBreakPositions(list, stringBuilder.ToString());
            return(list);
        }
 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);
 }
Esempio n. 9
0
 public int GetHeight(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (!this.m_calculatedHeight)
     {
         this.m_calculatedHeight = true;
         for (int i = 0; i < this.m_logicalRuns.Count; i++)
         {
             TextRun textRun = this.m_logicalRuns[i];
             int     ascent  = textRun.GetAscent(hdc, fontCache);
             if (ascent > this.m_ascent)
             {
                 this.m_ascent = ascent;
             }
             int descent = textRun.GetDescent(hdc, fontCache);
             if (descent > this.m_descent)
             {
                 this.m_descent = descent;
             }
         }
         if (this.m_prefix != null)
         {
             for (int j = 0; j < this.m_prefix.Count; j++)
             {
                 TextRun textRun2 = this.m_prefix[j];
                 int     ascent2  = textRun2.GetAscent(hdc, fontCache);
                 if (ascent2 > this.m_ascent)
                 {
                     this.m_ascent = ascent2;
                 }
                 int descent2 = textRun2.GetDescent(hdc, fontCache);
                 if (descent2 > this.m_descent)
                 {
                     this.m_descent = descent2;
                 }
             }
         }
     }
     return(this.m_ascent + this.m_descent);
 }
Esempio n. 10
0
        public static void DrawClippedTextRun(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, int x, int baselineY, uint fontColorOverride, Rectangle clipRect, Underline underline)
        {
            uint   crColor = 0u;
            IntPtr intPtr  = IntPtr.Zero;

            try
            {
                if (underline != null)
                {
                    underline.Draw(hdc, (int)((double)run.UnderlineHeight * 0.085), fontColorOverride);
                }
                RECT rECT = default(RECT);
                rECT.left   = clipRect.Left;
                rECT.right  = clipRect.Right;
                rECT.top    = clipRect.Top;
                rECT.bottom = clipRect.Bottom;
                crColor     = Win32.SetTextColor(hdc, fontColorOverride);
                GlyphData      glyphData            = run.GetGlyphData(hdc, fontCache);
                GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData;
                CachedFont     cachedFont           = run.GetCachedFont(hdc, fontCache);
                fontCache.SelectFontObject(hdc, cachedFont.Hfont);
                intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(rECT));
                Marshal.StructureToPtr(rECT, intPtr, false);
                int num = Win32.ScriptTextOut(hdc, ref cachedFont.ScriptCache, x, baselineY, 4u, intPtr, ref run.SCRIPT_ANALYSIS, IntPtr.Zero, 0, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphData.Advances, (int[])null, glyphData.GOffsets);
                if (Win32.Failed(num))
                {
                    Marshal.ThrowExceptionForHR(num);
                }
            }
            finally
            {
                if (intPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(intPtr);
                }
                crColor = Win32.SetTextColor(hdc, crColor);
            }
        }
Esempio n. 11
0
 private static void AnalyzeForBreakPositions(List <TextRun> itemRuns, string itemsText)
 {
     if (itemsText.Length != 0)
     {
         SCRIPT_ANALYSIS  sCRIPT_ANALYSIS = itemRuns[0].SCRIPT_ANALYSIS;
         SCRIPT_LOGATTR[] array           = new SCRIPT_LOGATTR[itemsText.Length];
         int num = Win32.ScriptBreak(itemsText, itemsText.Length, ref sCRIPT_ANALYSIS, array);
         if (Win32.Failed(num))
         {
             Marshal.ThrowExceptionForHR(num);
         }
         int num2 = 0;
         for (int i = 0; i < itemRuns.Count; i++)
         {
             TextRun          textRun = itemRuns[i];
             int              length  = textRun.Text.Length;
             SCRIPT_LOGATTR[] array2  = new SCRIPT_LOGATTR[length];
             Array.Copy(array, num2, array2, 0, length);
             textRun.ScriptLogAttr = array2;
             num2 += length;
         }
     }
 }
Esempio n. 12
0
        public Underline(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, Rectangle layoutRectangle, int x, int baselineY, RPLFormat.WritingModes writingMode)
        {
            int width = run.GetWidth(hdc, fontCache);
            int num   = (int)((double)(int)((double)run.UnderlineHeight * 0.085) * 1.5);

            switch (writingMode)
            {
            case RPLFormat.WritingModes.Horizontal:
                this.m_startPoint = new Point(layoutRectangle.X + x, layoutRectangle.Y + baselineY + num);
                this.m_endPoint   = new Point(Math.Min(this.m_startPoint.X + width, layoutRectangle.Right), this.m_startPoint.Y);
                break;

            case RPLFormat.WritingModes.Vertical:
                this.m_startPoint = new Point(layoutRectangle.Right - baselineY - num - 1, layoutRectangle.Y + x);
                this.m_endPoint   = new Point(this.m_startPoint.X, Math.Min(this.m_startPoint.Y + width, layoutRectangle.Bottom));
                break;

            case RPLFormat.WritingModes.Rotate270:
                this.m_startPoint = new Point(layoutRectangle.X + baselineY + num, layoutRectangle.Bottom - x);
                this.m_endPoint   = new Point(this.m_startPoint.X, Math.Max(this.m_startPoint.Y - width, layoutRectangle.Top));
                break;
            }
        }
Esempio n. 13
0
 private TextRun GetLastNonLineBreakRun(List <TextRun> runs, out int charIndex, out bool hasNonCRLFChars)
 {
     for (int num = runs.Count - 1; num >= 0; num--)
     {
         TextRun textRun = runs[num];
         if (textRun.CharacterCount > 0)
         {
             string text = textRun.Text;
             for (charIndex = textRun.CharacterCount - 1; charIndex >= 0; charIndex--)
             {
                 char c = text[charIndex];
                 if (c != '\n' && c != '\r')
                 {
                     hasNonCRLFChars = true;
                     return(textRun);
                 }
             }
         }
     }
     charIndex       = 0;
     hasNonCRLFChars = false;
     return(runs[runs.Count - 1]);
 }
Esempio n. 14
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);
        }
Esempio n. 15
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);
        }
Esempio n. 16
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;
                }
            }
        }
Esempio n. 17
0
        public CaretInfo MapLocation(Graphics g, TextBoxContext location, bool moveCaretToNextLine)
        {
            TextRun textRun = default(TextRun);

            return(this.MapLocation(g, location, false, moveCaretToNextLine, out textRun));
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
 public HighlightTextRun(string text, TextRun textRun)
     : base(text, textRun.TextRunProperties)
 {
     this.m_charIndexInOriginal = textRun.CharacterIndexInOriginal;
 }
Esempio n. 20
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;
                    }
                }
            }
        }
Esempio n. 21
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);
        }
Esempio n. 22
0
 public TextRun(string text, TextRun textRun)
     : this(text, textRun.TextRunProperties)
 {
 }
Esempio n. 23
0
 private void SetHighlighting(List <Paragraph> paragraphs, Win32DCSafeHandle hdc, RTSelectionHighlight highlight, TextRun runStart, TextRun runEnd, int x1, int x2)
 {
     if (runStart == runEnd)
     {
         if (x1 != x2)
         {
             if (x1 < x2)
             {
                 runStart.HighlightStart = x1;
                 runStart.HighlightEnd   = x2;
             }
             else
             {
                 runStart.HighlightStart = x2;
                 runStart.HighlightEnd   = x1;
             }
             runStart.HighlightColor      = highlight.Color;
             runStart.AllowColorInversion = highlight.AllowColorInversion;
         }
     }
     else
     {
         bool  flag  = false;
         bool  flag2 = false;
         Color color = highlight.Color;
         bool  allowColorInversion = highlight.AllowColorInversion;
         for (int i = highlight.SelectionStart.ParagraphIndex; i <= highlight.SelectionEnd.ParagraphIndex; i++)
         {
             int count = paragraphs[i].TextLines.Count;
             for (int j = 0; j < count; j++)
             {
                 List <TextRun> logicalRuns = paragraphs[i].TextLines[j].LogicalRuns;
                 int            count2      = logicalRuns.Count;
                 for (int k = 0; k < count2; k++)
                 {
                     TextRun textRun = logicalRuns[k];
                     bool    flag3   = textRun.ScriptAnalysis.fLayoutRTL == 0;
                     if (textRun == runStart)
                     {
                         flag2 = true;
                         if (flag3 && x1 < textRun.GetWidth(hdc, this.FontCache))
                         {
                             textRun.HighlightStart      = x1;
                             textRun.HighlightEnd        = -1;
                             textRun.HighlightColor      = color;
                             textRun.AllowColorInversion = allowColorInversion;
                         }
                         else if (!flag3 && x1 > 0)
                         {
                             textRun.HighlightStart      = -1;
                             textRun.HighlightEnd        = x1;
                             textRun.HighlightColor      = color;
                             textRun.AllowColorInversion = allowColorInversion;
                         }
                     }
                     else
                     {
                         if (textRun == runEnd)
                         {
                             flag2 = false;
                             if (flag3 && x2 > 0)
                             {
                                 textRun.HighlightStart      = -1;
                                 textRun.HighlightEnd        = x2;
                                 textRun.HighlightColor      = color;
                                 textRun.AllowColorInversion = allowColorInversion;
                             }
                             else if (!flag3 && x2 < textRun.GetWidth(hdc, this.FontCache))
                             {
                                 textRun.HighlightStart      = x2;
                                 textRun.HighlightEnd        = -1;
                                 textRun.HighlightColor      = color;
                                 textRun.AllowColorInversion = allowColorInversion;
                             }
                             flag = true;
                             break;
                         }
                         if (flag2)
                         {
                             textRun.HighlightStart      = -1;
                             textRun.HighlightEnd        = -1;
                             textRun.HighlightColor      = color;
                             textRun.AllowColorInversion = allowColorInversion;
                         }
                     }
                 }
                 if (flag)
                 {
                     break;
                 }
             }
             if (flag)
             {
                 break;
             }
         }
     }
 }
Esempio n. 24
0
        public override void DrawTextRun(Win32DCSafeHandle hdc, FontCache fontCache, ReportTextBox textBox, AspNetCore.ReportingServices.Rendering.RichText.TextRun run, TypeCode typeCode, RPLFormat.TextAlignments textAlign, RPLFormat.VerticalAlignments verticalAlign, RPLFormat.WritingModes writingMode, RPLFormat.Directions direction, Point pointPosition, System.Drawing.Rectangle layoutRectangle, int lineHeight, int baselineY)
        {
            if (!string.IsNullOrEmpty(run.Text))
            {
                int x;
                int baselineY2;
                switch (writingMode)
                {
                case RPLFormat.WritingModes.Horizontal:
                    x          = layoutRectangle.X + pointPosition.X;
                    baselineY2 = layoutRectangle.Y + baselineY;
                    break;

                case RPLFormat.WritingModes.Vertical:
                    x          = layoutRectangle.X + (layoutRectangle.Width - baselineY);
                    baselineY2 = layoutRectangle.Y + pointPosition.X;
                    break;

                case RPLFormat.WritingModes.Rotate270:
                    x          = layoutRectangle.X + baselineY;
                    baselineY2 = layoutRectangle.Y + layoutRectangle.Height - pointPosition.X;
                    break;

                default:
                    throw new NotSupportedException();
                }
                Underline underline = null;
                if (run.UnderlineHeight > 0)
                {
                    underline = new Underline(run, hdc, fontCache, layoutRectangle, pointPosition.X, baselineY, writingMode);
                }
                if (!this.IsEmf)
                {
                    AspNetCore.ReportingServices.Rendering.RichText.TextBox.DrawTextRun(run, hdc, fontCache, x, baselineY2, underline);
                }
                else
                {
                    AspNetCore.ReportingServices.Rendering.RichText.TextBox.ExtDrawTextRun(run, hdc, fontCache, x, baselineY2, underline);
                }
            }
        }
Esempio n. 25
0
 private void CalculateDimensions(Win32DCSafeHandle hdc, FontCache fontCache, bool useVisualRunsIfAvailable)
 {
     if (!this.m_calculatedDimensions)
     {
         bool           flag = useVisualRunsIfAvailable && this.m_visualRuns != null;
         List <TextRun> list = flag ? this.m_visualRuns : this.m_logicalRuns;
         this.m_width       = 0;
         this.m_prefixWidth = 0;
         int count = list.Count;
         int num   = 0;
         for (int i = 0; i < count; i++)
         {
             TextRun textRun = list[i];
             int     width   = textRun.GetWidth(hdc, fontCache);
             this.m_width += width;
             if (!flag)
             {
                 num = Math.Max(textRun.GetWidth(hdc, fontCache, true) - width, num);
             }
             else if (i == count - 1)
             {
                 num = textRun.GetWidth(hdc, fontCache, true) - width;
             }
             if (!this.m_calculatedHeight)
             {
                 int ascent = textRun.GetAscent(hdc, fontCache);
                 if (ascent > this.m_ascent)
                 {
                     this.m_ascent = ascent;
                 }
                 int descent = textRun.GetDescent(hdc, fontCache);
                 if (descent > this.m_descent)
                 {
                     this.m_descent = descent;
                 }
             }
         }
         this.m_width += num;
         if (this.m_prefix != null)
         {
             for (int j = 0; j < this.m_prefix.Count; j++)
             {
                 TextRun textRun2 = this.m_prefix[j];
                 if (!this.m_calculatedHeight)
                 {
                     int ascent2 = textRun2.GetAscent(hdc, fontCache);
                     if (ascent2 > this.m_ascent)
                     {
                         this.m_ascent = ascent2;
                     }
                     int descent2 = textRun2.GetDescent(hdc, fontCache);
                     if (descent2 > this.m_descent)
                     {
                         this.m_descent = descent2;
                     }
                 }
                 this.m_prefixWidth += textRun2.GetWidth(hdc, fontCache);
             }
         }
         this.m_calculatedDimensions = true;
         this.m_calculatedHeight     = true;
     }
 }
Esempio n. 26
0
        private static void FoldLine(Paragraph paragraph, TextLine line, Win32DCSafeHandle hdc, FontCache fontCache, FlowContext flowContext, bool wordTrim, Stack <int> lineRunsIndex, Stack <int> lineRunsCharIndex, float maxWidth, int lineIndents)
        {
            int   count = line.LogicalRuns.Count;
            float num   = 0f;

            for (int i = 0; i < count; i++)
            {
                num += (float)line.LogicalRuns[i].GetWidth(hdc, fontCache);
            }
            int  num2 = -1;
            bool flag = false;

            for (int num3 = count - 1; num3 >= 0; num3--)
            {
                TextRun textRun = line.LogicalRuns[num3];
                num -= (float)textRun.GetWidth(hdc, fontCache);
                SCRIPT_LOGATTR?nextCharLogAttr = null;
                if (num3 != count - 1)
                {
                    TextRun textRun2 = line.LogicalRuns[num3 + 1];
                    if (textRun2.CharacterCount > 0)
                    {
                        nextCharLogAttr = textRun2.ScriptLogAttr[0];
                    }
                }
                if (!textRun.IsPlaceholderTextRun)
                {
                    flag = true;
                    int num4 = 0;
                    num4 = ((!wordTrim) ? LineBreaker.FindFoldTextPosition_CharacterTrim(textRun, hdc, fontCache, maxWidth - num) : LineBreaker.FindFoldTextPosition_TextRunTrim(textRun, hdc, fontCache, maxWidth - num, nextCharLogAttr));
                    if (num4 > 0)
                    {
                        LineBreaker.FoldLineAt(line, num3, num4, flowContext.Context, lineRunsIndex, lineRunsCharIndex);
                        return;
                    }
                }
                else if (num2 > 0 && textRun.TextRunProperties.IndexInParagraph != num2)
                {
                    flag = true;
                }
                num2 = textRun.TextRunProperties.IndexInParagraph;
            }
            if (line.LogicalRuns.Count > 1)
            {
                if (flag)
                {
                    int num5;
                    for (num5 = line.LogicalRuns.Count - 1; num5 > 0; num5--)
                    {
                        flowContext.Context.TextRunIndex          = lineRunsIndex.Pop();
                        flowContext.Context.TextRunCharacterIndex = lineRunsCharIndex.Pop();
                        TextRun textRun3 = line.LogicalRuns[num5];
                        if (!textRun3.IsPlaceholderTextRun)
                        {
                            break;
                        }
                        if (textRun3.CharacterIndexInOriginal == 0)
                        {
                            break;
                        }
                    }
                    line.LogicalRuns.RemoveRange(num5, line.LogicalRuns.Count - num5);
                }
            }
            else if (flag)
            {
                int num6 = 1;
                if (maxWidth > 0.0)
                {
                    flowContext.ForcedCharTrim = true;
                    if (flowContext.VerticalCanGrow)
                    {
                        int num7 = default(int);
                        num6 = LineBreaker.FindWidthToBreakPosition(line.LogicalRuns[0], hdc, fontCache, maxWidth, out num7);
                        flowContext.CharTrimmedRunWidth = Math.Max(flowContext.CharTrimmedRunWidth, num7 + lineIndents);
                    }
                    else
                    {
                        num6 = LineBreaker.FindFoldTextPosition_CharacterTrim(line.LogicalRuns[0], hdc, fontCache, maxWidth);
                    }
                    if (num6 == 0)
                    {
                        num6 = 1;
                    }
                }
                else if (line.FirstLine && paragraph.ParagraphProps.HangingIndent > 0.0)
                {
                    num6 = 0;
                    if (flowContext.Updatable)
                    {
                        paragraph.Updated = true;
                    }
                }
                LineBreaker.FoldLineAt(line, 0, num6, flowContext.Context, lineRunsIndex, lineRunsCharIndex);
            }
        }
Esempio n. 27
0
 public void ScriptLayout(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (this.m_visualRuns == null)
     {
         int count = this.m_logicalRuns.Count;
         if (count != 0)
         {
             byte[] array  = new byte[count];
             int[]  array2 = new int[count];
             for (int i = 0; i < count; i++)
             {
                 array[i] = (byte)this.m_logicalRuns[i].ScriptAnalysis.s.uBidiLevel;
             }
             int num = Win32.ScriptLayout(count, array, null, array2);
             if (Win32.Failed(num))
             {
                 Marshal.ThrowExceptionForHR(num);
             }
             this.m_visualRuns = new List <TextRun>(count);
             for (int j = 0; j < count; j++)
             {
                 this.m_visualRuns.Add(null);
             }
             for (int k = 0; k < count; k++)
             {
                 this.m_visualRuns[array2[k]] = this.m_logicalRuns[k];
             }
             int num2 = 0;
             int l    = -1;
             for (int m = 0; m < count; m++)
             {
                 TextRun textRun = this.m_visualRuns[m];
                 textRun.UnderlineHeight = 0;
                 if (textRun.TextRunProperties.TextDecoration == RPLFormat.TextDecorations.Underline)
                 {
                     if (l < 0)
                     {
                         l = m;
                     }
                     int height = textRun.GetHeight(hdc, fontCache);
                     if (height > num2)
                     {
                         num2 = height;
                     }
                 }
                 else if (l >= 0)
                 {
                     for (; l < m; l++)
                     {
                         this.m_visualRuns[l].UnderlineHeight = num2;
                     }
                     num2 = 0;
                     l    = -1;
                 }
             }
             if (l >= 0)
             {
                 for (; l < count; l++)
                 {
                     this.m_visualRuns[l].UnderlineHeight = num2;
                 }
             }
         }
     }
 }
Esempio n. 28
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;
                }
            }
        }
Esempio n. 29
0
 public PlaceholderTextRun(string text, TextRun textRun)
     : base(text, textRun.TextRunProperties)
 {
 }
Esempio n. 30
0
        private static void RenderHighlightedTextRun(TextBox textBox, Paragraph paragraph, TextRun run, TextRun prevRun, Win32DCSafeHandle hdc, Graphics g, FontCache fontCache, float dpiX, int x, int offsetY, int baselineY, int lineHeight, Rectangle layoutRectangle, int runWidth, int prevRunWidth, int prevRunX, bool lastRunInLine, bool lastLineInParagraph)
        {
            uint?     nullable  = null;
            Rectangle?nullable2 = null;
            bool      flag      = false;
            Color     color     = run.HighlightColor;
            int       num;
            int       num2;
            bool      flag2;

            if (!color.IsEmpty)
            {
                num  = ((run.HighlightStart >= 0) ? run.HighlightStart : 0);
                num2 = ((run.HighlightEnd >= 0) ? run.HighlightEnd : runWidth);
                if (lastRunInLine)
                {
                    flag2 = (run.ScriptAnalysis.fLayoutRTL == 1);
                    if (lastLineInParagraph && runWidth != 0)
                    {
                        if (num != num2)
                        {
                            if (flag2 && run.HighlightStart < 0)
                            {
                                goto IL_0094;
                            }
                            if (!flag2 && run.HighlightEnd < 0)
                            {
                                goto IL_0094;
                            }
                        }
                    }
                    else if (runWidth == 0)
                    {
                        if (flag2)
                        {
                            num -= 5;
                        }
                        else
                        {
                            num2 += 5;
                        }
                    }
                }
                goto IL_0102;
            }
            goto IL_024e;
IL_024e:
            if (runWidth > 0)
            {
                textBox.TextBoxProps.DrawTextRun(run, paragraph, hdc, dpiX, fontCache, x, offsetY, baselineY, lineHeight, layoutRectangle);
                if (nullable.HasValue)
                {
                    textBox.TextBoxProps.DrawClippedTextRun(run, paragraph, hdc, dpiX, fontCache, x, offsetY, baselineY, lineHeight, layoutRectangle, nullable.Value, nullable2.Value);
                }
            }
            if (flag)
            {
                Rectangle empty = Rectangle.Empty;
                empty = ((!textBox.HorizontalText) ? new Rectangle(layoutRectangle.Right - offsetY, layoutRectangle.Y + x, lineHeight, prevRunWidth) : new Rectangle(layoutRectangle.X + x, layoutRectangle.Y + offsetY - lineHeight, prevRunWidth, lineHeight));
                Color color2 = prevRun.TextRunProperties.Color;
                if (run.AllowColorInversion && TextBox.NeedsColorInversion(color, color2))
                {
                    color2   = TextBox.InvertColor(color2);
                    nullable = (uint)(color2.B << 16 | color2.G << 8 | color2.R);
                }
                else
                {
                    nullable = prevRun.ColorInt;
                }
                textBox.TextBoxProps.DrawClippedTextRun(prevRun, paragraph, hdc, dpiX, fontCache, prevRunX, offsetY, baselineY, lineHeight, layoutRectangle, nullable.Value, empty);
            }
            return;

IL_0094:
            if (flag2)
            {
                num -= 5;
                int abcA = run.GetGlyphData(hdc, fontCache).ABC.abcA;
                if (abcA < 0)
                {
                    num += abcA;
                }
            }
            else
            {
                num2 += 5;
                int abcC = run.GetGlyphData(hdc, fontCache).ABC.abcC;
                if (abcC < 0)
                {
                    num2 -= abcC;
                }
            }
            goto IL_0102;
IL_0102:
            if (num != num2)
            {
                if (num == 0 && prevRun != null && (prevRun.GetGlyphData(hdc, fontCache).ABC.abcC <= 0 || run.GetGlyphData(hdc, fontCache).ABC.abcA < 0))
                {
                    flag = true;
                }
                if (run.AllowColorInversion && TextBox.NeedsColorInversion(color, textBox.TextBoxProps.BackgroundColor))
                {
                    color = TextBox.InvertColor(textBox.TextBoxProps.BackgroundColor);
                }
                using (Brush brush = new SolidBrush(color))
                {
                    nullable2 = ((!textBox.HorizontalText) ? new Rectangle?(new Rectangle(layoutRectangle.Right - offsetY, layoutRectangle.Y + x + num, lineHeight, num2 - num)) : new Rectangle?(new Rectangle(layoutRectangle.X + x + num, layoutRectangle.Y + offsetY - lineHeight, num2 - num, lineHeight)));
                    g.FillRectangle(brush, nullable2.Value);
                }
                if (run.AllowColorInversion && TextBox.NeedsColorInversion(color, run.TextRunProperties.Color))
                {
                    Color color3 = TextBox.InvertColor(run.TextRunProperties.Color);
                    nullable = (uint)(color3.B << 16 | color3.G << 8 | color3.R);
                }
            }
            run.HighlightColor = Color.Empty;
            goto IL_024e;
        }