public void Add(string text, FontAndColorSetting format)
            {
                SimpleTextRunProperties props;

                if (!propMap.TryGetValue(format.GetHashCode(), out props))
                {
                    props = new SimpleTextRunProperties(format);
                    propMap.Add(format.GetHashCode(), props);
                }

                var span = new FormattedSpan(textBuilder.Length, text.Length, props);

                textBuilder.Append(text);
                spans.Add(span);

                cache.Change(span.Start, span.Length, 0);
            }
Esempio n. 2
0
        public Collection <TextBounds> GetNormalizedTextBounds(SnapshotSpan bufferSpan)
        {
            if (!IsValid)
            {
                throw new ObjectDisposedException(nameof(WpfTextViewLineCollection));
            }
            if (bufferSpan.Snapshot != snapshot)
            {
                throw new ArgumentException();
            }
            var span = FormattedSpan.Overlap(bufferSpan);
            var list = new List <TextBounds>();

            if (span == null)
            {
                return(new Collection <TextBounds>(list));
            }

            bool found = false;

            for (int i = 0; i < lines.Count; i++)
            {
                var line = lines[i];
                if (line.IntersectsBufferSpan(span.Value))
                {
                    found = true;
                    if (line.Start >= span.Value.Start && line.EndIncludingLineBreak <= span.Value.End)
                    {
                        list.Add(new TextBounds(line.Left, line.Top, line.Width, line.Height, line.TextTop, line.TextHeight));
                    }
                    else
                    {
                        list.AddRange(line.GetNormalizedTextBounds(span.Value));
                    }
                }
                else if (found)
                {
                    break;
                }
            }

            return(new Collection <TextBounds>(list));
        }
Esempio n. 3
0
 public bool IntersectsBufferSpan(SnapshotSpan bufferSpan)
 {
     if (!IsValid)
     {
         throw new ObjectDisposedException(nameof(WpfTextViewLineCollection));
     }
     if (bufferSpan.Snapshot != snapshot)
     {
         throw new ArgumentException();
     }
     if (FormattedSpan.IntersectsWith(bufferSpan))
     {
         return(true);
     }
     if (lines.Count > 0 && lines[lines.Count - 1].IntersectsBufferSpan(bufferSpan))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 4
0
 public bool ContainsBufferPosition(SnapshotPoint bufferPosition)
 {
     if (!IsValid)
     {
         throw new ObjectDisposedException(nameof(WpfTextViewLineCollection));
     }
     if (bufferPosition.Snapshot != snapshot)
     {
         throw new ArgumentException();
     }
     if (FormattedSpan.Contains(bufferPosition))
     {
         return(true);
     }
     if (lines.Count > 0 && lines[lines.Count - 1].ContainsBufferPosition(bufferPosition))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 5
0
 public virtual void VisitFormattedSpan(FormattedSpan formattedSpan)
 {
 }