internal RTSelectionHighlight GetSearchHit(GdiContext context)
        {
            if (string.IsNullOrEmpty(context.SearchText))
            {
                return(null);
            }
            RTSelectionHighlight result = null;

            if (context.SearchMatches != null)
            {
                int num = context.SearchMatchIndex;
                if (num >= context.SearchMatches.Count)
                {
                    num -= context.SearchMatches.Count;
                }
                if (m_searchResults != null && m_firstSearchIndex <= num && num <= m_lastSearchIndex)
                {
                    result = m_searchResults[num - m_firstSearchIndex].Match;
                }
            }
            return(result);
        }
        internal override void DrawContent(GdiContext context)
        {
            RPLTextBoxPropsDef rPLTextBoxPropsDef = DefinitionProperties as RPLTextBoxPropsDef;
            RPLTextBoxProps    rPLTextBoxProps    = InstanceProperties as RPLTextBoxProps;

            if (rPLTextBoxProps.IsToggleParent)
            {
                GetToggleImage(context.GdiWriter, out Bitmap image);
                if (m_toggleRectangleMM.Width > 0f)
                {
                    DrawResourceImage(imageRectanglePX: new RectangleF(0f, 0f, image.Width, image.Height), context: context, image: image, itemRectangleMM: m_toggleRectangleMM);
                }
            }
            if (rPLTextBoxPropsDef.CanSort)
            {
                GetSortImage(context.GdiWriter, out Bitmap image2, out SortOrder _);
                if (m_sortRectangleMM.Width > 0f)
                {
                    DrawResourceImage(imageRectanglePX: new RectangleF(0f, 0f, image2.Width, image2.Height), context: context, image: image2, itemRectangleMM: m_sortRectangleMM);
                }
            }
            if (TextPosition.Width <= 0f || TextPosition.Height <= 0f)
            {
                return;
            }
            RPLFormat.WritingModes writingMode = WritingMode;
            float contentHeight  = 0f;
            float contentHeight2 = 0f;

            if (writingMode == RPLFormat.WritingModes.Horizontal)
            {
                contentHeight = rPLTextBoxProps.ContentHeight;
            }
            else
            {
                contentHeight2 = rPLTextBoxProps.ContentHeight;
            }
            List <Paragraph>            list  = null;
            List <RTSelectionHighlight> list2 = null;
            FlowContext flowContext           = new FlowContext(TextPosition.Width, TextPosition.Height);
            bool        flag = !rPLTextBoxPropsDef.CanGrow && !rPLTextBoxPropsDef.CanShrink;

            if (flag)
            {
                m_richTextBox.Paragraphs = new List <Paragraph>(m_paragraphs.Count);
                for (int i = 0; i < m_paragraphs.Count; i++)
                {
                    RTSelectionHighlight searchHit = m_paragraphs[i].GetSearchHit(context);
                    if (searchHit != null)
                    {
                        context.TextRunIndexHitStart = searchHit.SelectionStart.TextRunIndex;
                        context.TextRunIndexHitEnd   = searchHit.SelectionEnd.TextRunIndex;
                    }
                    m_paragraphs[i].DrawContent(context);
                    m_richTextBox.Paragraphs.Add(m_paragraphs[i].RichParagraph);
                    context.TextRunIndexHitStart = -1;
                    context.TextRunIndexHitEnd   = -1;
                }
                m_richTextBox.ScriptItemize();
                if (writingMode == RPLFormat.WritingModes.Horizontal)
                {
                    TextBox.MeasureFullHeight(m_richTextBox, context.Graphics, context.FontCache, flowContext, out contentHeight);
                }
                else
                {
                    TextBox.MeasureFullHeight(m_richTextBox, context.Graphics, context.FontCache, flowContext, out contentHeight2);
                }
                list = m_richTextBox.Paragraphs;
                m_richTextBox.Paragraphs = null;
            }
            if (writingMode == RPLFormat.WritingModes.Horizontal)
            {
                if (contentHeight + 0.001f > TextPosition.Height)
                {
                    flowContext.LineLimit = false;
                }
            }
            else if (contentHeight2 + 0.001f > TextPosition.Width)
            {
                flowContext.LineLimit = false;
            }
            m_richTextBox.Paragraphs = new List <Paragraph>(1);
            bool  flag2 = true;
            float num   = 0f;
            float num2  = 0f;

            for (int j = 0; j < m_paragraphs.Count; j++)
            {
                if (writingMode == RPLFormat.WritingModes.Horizontal)
                {
                    if (num > 0f)
                    {
                        if (num >= TextPosition.Height)
                        {
                            break;
                        }
                        flowContext.Height = TextPosition.Height - num;
                    }
                }
                else if (num2 > 0f)
                {
                    if (num2 >= TextPosition.Width)
                    {
                        break;
                    }
                    flowContext.Width = TextPosition.Width - num2;
                }
                RTSelectionHighlight searchHit2 = m_paragraphs[j].GetSearchHit(context);
                if (!flag)
                {
                    if (searchHit2 != null)
                    {
                        context.TextRunIndexHitStart = searchHit2.SelectionStart.TextRunIndex;
                        context.TextRunIndexHitEnd   = searchHit2.SelectionEnd.TextRunIndex;
                    }
                    m_paragraphs[j].DrawContent(context);
                    m_richTextBox.Paragraphs.Add(m_paragraphs[j].RichParagraph);
                    context.TextRunIndexHitStart = -1;
                    context.TextRunIndexHitEnd   = -1;
                    m_richTextBox.ScriptItemize();
                }
                else
                {
                    m_richTextBox.Paragraphs.Add(list[0]);
                }
                if (searchHit2 != null)
                {
                    searchHit2.SelectionStart.ParagraphIndex = 0;
                    searchHit2.SelectionEnd.ParagraphIndex   = 0;
                    list2 = new List <RTSelectionHighlight>(0);
                    list2.Add(searchHit2);
                }
                float            height          = 0f;
                List <Paragraph> rTParagraphs    = LineBreaker.Flow(m_richTextBox, context.Graphics, context.FontCache, flowContext, keepLines: true, out height);
                RectangleF       layoutParagraph = RectangleF.Empty;
                PointF           offset          = PointF.Empty;
                float            delta           = 0f;
                if (writingMode == RPLFormat.WritingModes.Horizontal)
                {
                    AdjustParagraphLayout(contentHeight, height, num, flag2, writingMode, ref delta, ref layoutParagraph, ref offset);
                }
                else
                {
                    AdjustParagraphLayout(contentHeight2, height, num2, flag2, writingMode, ref delta, ref layoutParagraph, ref offset);
                }
                m_context = context;
                m_paragraphs[j].TextPosition = layoutParagraph;
                RichTextRenderer richTextRenderer = new RichTextRenderer();
                try
                {
                    richTextRenderer.SetTextbox(m_richTextBox);
                    richTextRenderer.RTParagraphs = rTParagraphs;
                    richTextRenderer.FontCache    = context.FontCache;
                    if (writingMode == RPLFormat.WritingModes.Horizontal)
                    {
                        RenderRichText(richTextRenderer, context.Graphics, TextPosition, offset, list2);
                    }
                    else
                    {
                        RenderRichText(richTextRenderer, context.Graphics, layoutParagraph, offset, list2);
                    }
                    richTextRenderer.FontCache = null;
                }
                finally
                {
                    if (richTextRenderer != null)
                    {
                        richTextRenderer.Dispose();
                        richTextRenderer = null;
                    }
                }
                m_context = null;
                flowContext.Reset();
                if (writingMode == RPLFormat.WritingModes.Horizontal)
                {
                    if (flag2)
                    {
                        num  += delta;
                        flag2 = false;
                    }
                    num += height;
                }
                else
                {
                    if (flag2)
                    {
                        num2 += delta;
                        flag2 = false;
                    }
                    num2 += height;
                }
                if (searchHit2 != null)
                {
                    searchHit2.SelectionStart.ParagraphIndex = j;
                    searchHit2.SelectionEnd.ParagraphIndex   = j;
                }
                m_richTextBox.Paragraphs.RemoveAt(0);
                if (!flag)
                {
                    m_paragraphs[j].RichParagraph = null;
                }
                else
                {
                    list.RemoveAt(0);
                }
            }
            if (list != null && list.Count > 0)
            {
                list.Clear();
            }
            list = null;
        }
Ejemplo n.º 3
0
 internal SearchMatch(RTSelectionHighlight match)
 {
     m_match = match;
 }