Ejemplo n.º 1
0
        public TextRun GetTextRun(Int32 characterIndex)
        {
            NormalizedSpan next = _predictedNode;

            do
            {
                if (characterIndex >= (next.StartCharacterIndex + next.Length))
                {
                    next = next.Next;
                }
                else
                {
                    if (characterIndex >= next.StartCharacterIndex)
                    {
                        TextRun textRun = next.GetTextRun(characterIndex);
                        if (next.Next != null)
                        {
                            _predictedNode = next.Next;
                        }
                        return(textRun);
                    }
                    next = next.Previous;
                }
            }while (next != null);
            return(_lineBreak);
        }
Ejemplo n.º 2
0
        private void CreateNormalizedSpans()
        {
            Int32          startCharacterIndex = _startCharacterIndex;
            Int32          length = _text.Length;
            NormalizedSpan span   = new NormalizedSpan("", "_gap_", _startCharacterIndex, TextFormattingRunProperties.DefaultProperties);

            _startNode = span;
            for (Int32 i = 0; i < _classificationSpanList.Count; i++)
            {
                ClassificationSpan span2 = _classificationSpanList[i];
                Span span3 = span2.Span();
                if (span3.Start >= (_startCharacterIndex + length))
                {
                    break;
                }
                Int32 num4 = span3.Start - startCharacterIndex;
                if (num4 > 0)
                {
                    NormalizedSpan span4 = new NormalizedSpan(_text.Substring(startCharacterIndex - _startCharacterIndex, span3.Start - startCharacterIndex), "_gap_", startCharacterIndex, TextFormattingRunProperties.DefaultProperties);
                    span = span.AddNode(span4);
                    startCharacterIndex += num4;
                }
                else if (num4 < 0)
                {
                    Int32 num5 = span3.Length + num4;
                    if (num5 <= 0)
                    {
                        continue;
                    }
                    span3 = new Span(startCharacterIndex, num5);
                }
                if (span3.Length > 0)
                {
                    Int32 num6 = startCharacterIndex - _startCharacterIndex;
                    TextFormattingRunProperties textProperties = _classificationFormatMap.GetTextProperties(span2.Classification);
                    if ((span3.Length + num6) > length)
                    {
                        Int32          num7  = length - num6;
                        NormalizedSpan span5 = new NormalizedSpan(_text.Substring(span3.Start - _startCharacterIndex, num7), span2.Classification, span3.Start, textProperties);
                        span = span.AddNode(span5);
                        startCharacterIndex = _startCharacterIndex + length;
                        break;
                    }
                    NormalizedSpan span6 = new NormalizedSpan(_text.Substring(span3.Start - _startCharacterIndex, span3.Length), span2.Classification, span3.Start, textProperties);
                    span = span.AddNode(span6);
                    startCharacterIndex += span3.Length;
                }
            }
            if (startCharacterIndex < (_startCharacterIndex + length))
            {
                Int32          num8  = length - (startCharacterIndex - _startCharacterIndex);
                NormalizedSpan span7 = new NormalizedSpan(_text.Substring(startCharacterIndex - _startCharacterIndex, num8), "_gap_", startCharacterIndex, TextFormattingRunProperties.DefaultProperties);
                span = span.AddNode(span7);
            }
            if (_startNode.Next != null)
            {
                _startNode          = _startNode.Next;
                _startNode.Previous = null;
            }
        }
Ejemplo n.º 3
0
        public Boolean AddTextModifiers()
        {
            if (!_canSplitOrMerge || !TextFormattingSource.ContainsBiDiCharacters(_text))
            {
                return(false);
            }
            NormalizedSpan span = new NormalizedSpan(new TextFormattingModifier(_properties), this.StartCharacterIndex);

            span.Next     = this;
            span.Previous = this.Previous;
            if (this.Previous != null)
            {
                this.Previous.Next = span;
            }
            this.Previous = span;
            NormalizedSpan span2 = new NormalizedSpan(new TextEndOfSegment(1), this.StartCharacterIndex + this.Length);

            span2.Next     = this.Next;
            span2.Previous = this;
            if (this.Next != null)
            {
                this.Next.Previous = span2;
            }
            this.Next = span2;
            return(true);
        }
		private void CreateNormalizedSpans()
		{
			Int32 startCharacterIndex = _startCharacterIndex;
			Int32 length = _text.Length;
			NormalizedSpan span = new NormalizedSpan("", "_gap_", _startCharacterIndex, TextFormattingRunProperties.DefaultProperties);
			_startNode = span;
			for (Int32 i = 0; i < _classificationSpanList.Count; i++)
			{
				ClassificationSpan span2 = _classificationSpanList[i];
				Span span3 = span2.Span();
				if (span3.Start >= (_startCharacterIndex + length))
				{
					break;
				}
				Int32 num4 = span3.Start - startCharacterIndex;
				if (num4 > 0)
				{
					NormalizedSpan span4 = new NormalizedSpan(_text.Substring(startCharacterIndex - _startCharacterIndex, span3.Start - startCharacterIndex), "_gap_", startCharacterIndex, TextFormattingRunProperties.DefaultProperties);
					span = span.AddNode(span4);
					startCharacterIndex += num4;
				}
				else if (num4 < 0)
				{
					Int32 num5 = span3.Length + num4;
					if (num5 <= 0)
					{
						continue;
					}
					span3 = new Span(startCharacterIndex, num5);
				}
				if (span3.Length > 0)
				{
					Int32 num6 = startCharacterIndex - _startCharacterIndex;
					TextFormattingRunProperties textProperties = _classificationFormatMap.GetTextProperties(span2.Classification);
					if ((span3.Length + num6) > length)
					{
						Int32 num7 = length - num6;
						NormalizedSpan span5 = new NormalizedSpan(_text.Substring(span3.Start - _startCharacterIndex, num7), span2.Classification, span3.Start, textProperties);
						span = span.AddNode(span5);
						startCharacterIndex = _startCharacterIndex + length;
						break;
					}
					NormalizedSpan span6 = new NormalizedSpan(_text.Substring(span3.Start - _startCharacterIndex, span3.Length), span2.Classification, span3.Start, textProperties);
					span = span.AddNode(span6);
					startCharacterIndex += span3.Length;
				}
			}
			if (startCharacterIndex < (_startCharacterIndex + length))
			{
				Int32 num8 = length - (startCharacterIndex - _startCharacterIndex);
				NormalizedSpan span7 = new NormalizedSpan(_text.Substring(startCharacterIndex - _startCharacterIndex, num8), "_gap_", startCharacterIndex, TextFormattingRunProperties.DefaultProperties);
				span = span.AddNode(span7);
			}
			if (_startNode.Next != null)
			{
				_startNode = _startNode.Next;
				_startNode.Previous = null;
			}
		}
Ejemplo n.º 5
0
		public NormalizedSpan(String text, String classification, Int32 startCharacterIndex, TextFormattingRunProperties properties)
		{
			_text = text;
			_length = text.Length;
			_classification = classification;
			_startCharacterIndex = startCharacterIndex;
			_properties = properties;
			_next = (NormalizedSpan)(_previous = null);
			_canSplitOrMerge = true;
		}
Ejemplo n.º 6
0
 public NormalizedSpan(String text, String classification, Int32 startCharacterIndex, TextFormattingRunProperties properties)
 {
     _text                = text;
     _length              = text.Length;
     _classification      = classification;
     _startCharacterIndex = startCharacterIndex;
     _properties          = properties;
     _next                = (NormalizedSpan)(_previous = null);
     _canSplitOrMerge     = true;
 }
Ejemplo n.º 7
0
 private void InsertSpaceNegotiationSpans()
 {
     if (_spaceNegotiationList != null)
     {
         NormalizedSpan span = _startNode;
         foreach (SpaceNegotiation negotiation in _spaceNegotiationList)
         {
             TextRun textRun = new TextEmbeddedSpace(negotiation.Size);
             span = span.AddNode(new NormalizedSpan(textRun, (Int32)negotiation.TextPosition));
             _virtualCharacterPositions.Add(((Int32)negotiation.TextPosition) - _startCharacterIndex);
         }
     }
 }
		private void AddTextModifiers()
		{
			for (NormalizedSpan next = _startNode; next != null; next = next.Next)
			{
				if (next.AddTextModifiers())
				{
					_containsBiDi = true;
					_virtualCharacterPositions.Add(next.StartCharacterIndex - _startCharacterIndex);
					_virtualCharacterPositions.Add((next.StartCharacterIndex + next.Length) - _startCharacterIndex);
					next = next.Next;
				}
			}
			if (_startNode.Previous != null)
			{
				_startNode = _startNode.Previous;
			}
		}
Ejemplo n.º 9
0
 private void AddTextModifiers()
 {
     for (NormalizedSpan next = _startNode; next != null; next = next.Next)
     {
         if (next.AddTextModifiers())
         {
             _containsBiDi = true;
             _virtualCharacterPositions.Add(next.StartCharacterIndex - _startCharacterIndex);
             _virtualCharacterPositions.Add((next.StartCharacterIndex + next.Length) - _startCharacterIndex);
             next = next.Next;
         }
     }
     if (_startNode.Previous != null)
     {
         _startNode = _startNode.Previous;
     }
 }
		public NormalizedSpanManager(String text, Int32 startCharacterIndex, IList<ClassificationSpan> classificationSpans, IList<SpaceNegotiation> spaceNegotiations, IClassificationFormatMap classificationFormatMap)
		{
			_text = text;
			_startCharacterIndex = startCharacterIndex;
			_classificationSpanList = classificationSpans;
			_spaceNegotiationList = spaceNegotiations;
			_classificationFormatMap = classificationFormatMap;
			_virtualCharacterPositions = new List<Int32>();
			this.CreateNormalizedSpans();
			this.InsertSpaceNegotiationSpans();
			this.AddTextModifiers();
			this.MergeSpans();
			NormalizedSpan next = _startNode;
			Int32 num = 0;
			while (next != null)
			{
				next.StartCharacterIndex = num;
				num += next.Length;
				next = next.Next;
			}
			_predictedNode = _startNode;
		}
Ejemplo n.º 11
0
        public NormalizedSpanManager(String text, Int32 startCharacterIndex, IList <ClassificationSpan> classificationSpans, IList <SpaceNegotiation> spaceNegotiations, IClassificationFormatMap classificationFormatMap)
        {
            _text = text;
            _startCharacterIndex       = startCharacterIndex;
            _classificationSpanList    = classificationSpans;
            _spaceNegotiationList      = spaceNegotiations;
            _classificationFormatMap   = classificationFormatMap;
            _virtualCharacterPositions = new List <Int32>();
            this.CreateNormalizedSpans();
            this.InsertSpaceNegotiationSpans();
            this.AddTextModifiers();
            this.MergeSpans();
            NormalizedSpan next = _startNode;
            Int32          num  = 0;

            while (next != null)
            {
                next.StartCharacterIndex = num;
                num += next.Length;
                next = next.Next;
            }
            _predictedNode = _startNode;
        }
Ejemplo n.º 12
0
		public Boolean AddTextModifiers()
		{
			if (!_canSplitOrMerge || !TextFormattingSource.ContainsBiDiCharacters(_text))
			{
				return false;
			}
			NormalizedSpan span = new NormalizedSpan(new TextFormattingModifier(_properties), this.StartCharacterIndex);
			span.Next = this;
			span.Previous = this.Previous;
			if (this.Previous != null)
			{
				this.Previous.Next = span;
			}
			this.Previous = span;
			NormalizedSpan span2 = new NormalizedSpan(new TextEndOfSegment(1), this.StartCharacterIndex + this.Length);
			span2.Next = this.Next;
			span2.Previous = this;
			if (this.Next != null)
			{
				this.Next.Previous = span2;
			}
			this.Next = span2;
			return true;
		}
Ejemplo n.º 13
0
		public NormalizedSpan AddNode(NormalizedSpan span)
		{
			if (span.StartCharacterIndex > (this.StartCharacterIndex + this.Length))
			{
				return this.Next.AddNode(span);
			}
			if (_canSplitOrMerge && (span.StartCharacterIndex < (this.StartCharacterIndex + this.Length)))
			{
				Int32 startCharacterIndex = span.StartCharacterIndex;
				NormalizedSpan span2 = new NormalizedSpan(_text.Substring(startCharacterIndex - this.StartCharacterIndex), _classification, startCharacterIndex, _properties);
				_length = startCharacterIndex - this.StartCharacterIndex;
				_text = _text.Substring(0, _length);
				this.AddNode(span);
				return span.AddNode(span2);
			}
			span.Previous = this;
			if (this.Next != null)
			{
				span.Next = this.Next;
				this.Next.Previous = span;
			}
			this.Next = span;
			return span;
		}
Ejemplo n.º 14
0
 public NormalizedSpan AddNode(NormalizedSpan span)
 {
     if (span.StartCharacterIndex > (this.StartCharacterIndex + this.Length))
     {
         return(this.Next.AddNode(span));
     }
     if (_canSplitOrMerge && (span.StartCharacterIndex < (this.StartCharacterIndex + this.Length)))
     {
         Int32          startCharacterIndex = span.StartCharacterIndex;
         NormalizedSpan span2 = new NormalizedSpan(_text.Substring(startCharacterIndex - this.StartCharacterIndex), _classification, startCharacterIndex, _properties);
         _length = startCharacterIndex - this.StartCharacterIndex;
         _text   = _text.Substring(0, _length);
         this.AddNode(span);
         return(span.AddNode(span2));
     }
     span.Previous = this;
     if (this.Next != null)
     {
         span.Next          = this.Next;
         this.Next.Previous = span;
     }
     this.Next = span;
     return(span);
 }
		public TextRun GetTextRun(Int32 characterIndex)
		{
			NormalizedSpan next = _predictedNode;
			do
			{
				if (characterIndex >= (next.StartCharacterIndex + next.Length))
				{
					next = next.Next;
				}
				else
				{
					if (characterIndex >= next.StartCharacterIndex)
					{
						TextRun textRun = next.GetTextRun(characterIndex);
						if (next.Next != null)
						{
							_predictedNode = next.Next;
						}
						return textRun;
					}
					next = next.Previous;
				}
			}
			while (next != null);
			return _lineBreak;
		}
Ejemplo n.º 16
0
 private void MergeSpans()
 {
     for (NormalizedSpan span = _startNode; span != null; span = span.TryMergeNextSpan())
     {
     }
 }