Exemple #1
0
        public void SplitSpan(RtPosition pos, out int nextSpanIndex)
        {
            GetParaAndSpan(pos, out var para, out var span);
            if (pos.CharIndex == 0)
            {
                nextSpanIndex = pos.SpanIndex;
                return;
            }
            if (pos.CharIndex == span.LayoutTextLength)
            {
                nextSpanIndex = pos.SpanIndex + 1;
                return;
            }
            if (!(span is IRtPureSpan pureSpan))
            {
                throw new InvalidOperationException("Cannot split non-pure spans in the middle");
            }
            var secondSpan = AmFactory.Create <RtPureSpan>();

            secondSpan.Style = span.Style.CloneTyped();
            secondSpan.Text  = pureSpan.Text.Substring(pos.CharIndex);
            pureSpan.Text    = pureSpan.Text.Substring(0, pos.CharIndex);
            para.Spans.Insert(pos.SpanIndex + 1, secondSpan);
            nextSpanIndex = pos.SpanIndex + 1;
        }
Exemple #2
0
        public int GetGlobalIndex(RtPosition pos)
        {
            int globalSpanOffset = 0;

            foreach (var para in Paragraphs.Take(pos.ParaIndex))
            {
                foreach (var span in para.Spans)
                {
                    globalSpanOffset += span.LayoutTextLength;
                }
                globalSpanOffset++;
            }
            var exactPara = Paragraphs[pos.ParaIndex];

            foreach (var span in exactPara.Spans.Take(pos.SpanIndex))
            {
                globalSpanOffset += span.LayoutTextLength;
            }

            globalSpanOffset += pos.CharIndex;
            return(globalSpanOffset);
        }
Exemple #3
0
 public void GetParaAndSpan(RtPosition pos, out IRtParagraph para, out IRtSpan span)
 {
     para = Paragraphs[pos.ParaIndex];
     span = para.Spans[pos.SpanIndex];
 }
Exemple #4
0
 public IRtSpan GetSpan(RtPosition pos) => Paragraphs[pos.ParaIndex].Spans[pos.SpanIndex];
Exemple #5
0
 public IRtParagraph GetPara(RtPosition pos) => Paragraphs[pos.ParaIndex];