private RtPosition ToRelPos(int absPos, out IRtParagraph para, out IRtSpan span)
        {
            para = text.Paragraphs[0];
            span = para.Spans[0];

            var toSkip = absPos;

            for (var paraIndex = 0; paraIndex < text.Paragraphs.Count; paraIndex++)
            {
                para = text.Paragraphs[paraIndex];
                for (var spanIndex = 0; spanIndex < para.Spans.Count; spanIndex++)
                {
                    span = para.Spans[spanIndex];
                    if (span.LayoutTextLength > toSkip)
                    {
                        return(new RtPosition(paraIndex, spanIndex, toSkip));
                    }
                    toSkip -= span.LayoutTextLength;
                }

                if (toSkip == 0)
                {
                    var lastSpanIndex = para.Spans.Count - 1;
                    var lastSpan      = para.Spans[lastSpanIndex];
                    return(new RtPosition(paraIndex, lastSpanIndex, lastSpan.LayoutTextLength));
                }

                toSkip--;
            }

            throw new ArgumentOutOfRangeException();
        }
Example #2
0
        private void ApplyMarginUp(BuildingContext context, IRtParagraph para)
        {
            var marginUp = para.Style.MarginUp;
            var oldShape = context.RemainingShape;

            context.StripStartPoint.Y += marginUp;
            context.RemainingShape     = new AaRectangle2(oldShape.MinMin + new Vector2(0, marginUp), oldShape.MaxMax);
        }
 private static void NormalizePara(IRtParagraph para, IRtSpanStyle prevSpanStyle)
 {
     if (para.LayoutTextLength == 0)
     {
         if (para.Spans.IsEmptyL())
         {
             para.Spans.Add(CreatePureSpan(prevSpanStyle));
         }
         else
         {
             for (var i = para.Spans.Count - 1; i >= 1; i--)
             {
                 para.Spans.RemoveAt(i);
             }
         }
     }
     else
     {
         for (var i = para.Spans.Count - 1; i >= 0; i--)
         {
             if (para.Spans[i].IsEmpty)
             {
                 para.Spans.RemoveAt(i);
             }
         }
     }
     for (var i = para.Spans.Count - 2; i >= 0; i--)
     {
         if (para.Spans[i] is IRtPureSpan span1 &&
             para.Spans[i + 1] is IRtPureSpan span2 &&
             span1.Style.Equals(span2.Style))
         {
             span1.Text += span2.Text;
             para.Spans.RemoveAt(i + 1);
         }
     }
 }
Example #4
0
 public void GetParaAndSpan(RtPosition pos, out IRtParagraph para, out IRtSpan span)
 {
     para = Paragraphs[pos.ParaIndex];
     span = para.Spans[pos.SpanIndex];
 }