Ejemplo n.º 1
0
        public void SetBold(int startIndex, int endIndex, bool bold)
        {
            if (startIndex < 0)
            {
                throw new ArgumentException("startIndex must be >= 0");
            }
            if (startIndex > endIndex)
            {
                throw new ArgumentException("startIndex must be <= endIndex");
            }
            if (startIndex == endIndex)
            {
                return;
            }
            var pos = 0;

            for (var i = 0; i < words.Count; i++)
            {
                var word = words[i];
                if (pos >= endIndex)
                {
                    break;
                }
                var wordEnd = pos + word.Word.Length;
                // 3 possibilities:
                if (startIndex <= pos && endIndex >= wordEnd)
                {
                    // word is fully in region:
                    word.Bold = bold;
                }
                else if (startIndex <= pos)
                {
                    // beginning of word is in region
                    var inRegionLength = endIndex - pos;
                    var newWord        = new SimpleTextWord(word.Type, word.Word.Substring(inRegionLength), word.Bold,
                                                            word.Color);
                    words.Insert(i + 1, newWord);

                    word.Bold = bold;
                    word.Word = word.Word.Substring(0, inRegionLength);
                }
                else if (startIndex < wordEnd)
                {
                    // end of word is in region (or middle of word is in region)
                    var notInRegionLength = startIndex - pos;

                    var newWord = new SimpleTextWord(word.Type, word.Word.Substring(notInRegionLength), word.Bold,
                                                     word.Color);
                    // newWord.Bold will be set in the next iteration
                    words.Insert(i + 1, newWord);

                    word.Word = word.Word.Substring(0, notInRegionLength);
                }

                pos = wordEnd;
            }
        }
Ejemplo n.º 2
0
        public void SetBold(int startIndex, int endIndex, bool bold)
        {
            if (startIndex < 0)
            {
                throw new ArgumentException("startIndex must be >= 0");
            }
            if (startIndex > endIndex)
            {
                throw new ArgumentException("startIndex must be <= endIndex");
            }
            if (startIndex == endIndex)
            {
                return;
            }
            int pos = 0;

            for (int i = 0; i < words.Count; i++)
            {
                SimpleTextWord word = words[i];
                if (pos >= endIndex)
                {
                    break;
                }
                int wordEnd = pos + word.Word.Length;
                if (startIndex <= pos && endIndex >= wordEnd)
                {
                    word.Bold = bold;
                }
                else if (startIndex <= pos)
                {
                    int            inRegionLength = endIndex - pos;
                    SimpleTextWord newWord        = new SimpleTextWord(word.Type, word.Word.Substring(inRegionLength), word.Bold, word.Color);
                    words.Insert(i + 1, newWord);
                    word.Bold = bold;
                    word.Word = word.Word.Substring(0, inRegionLength);
                }
                else if (startIndex < wordEnd)
                {
                    int            notInRegionLength = startIndex - pos;
                    SimpleTextWord newWord           = new SimpleTextWord(word.Type, word.Word.Substring(notInRegionLength), word.Bold, word.Color);
                    words.Insert(i + 1, newWord);
                    word.Word = word.Word.Substring(0, notInRegionLength);
                }
                pos = wordEnd;
            }
        }
Ejemplo n.º 3
0
		public void SetBold(int startIndex, int endIndex, bool bold)
		{
			if (startIndex < 0)
				throw new ArgumentException("startIndex must be >= 0");
			if (startIndex > endIndex)
				throw new ArgumentException("startIndex must be <= endIndex");
			if (startIndex == endIndex) return;
			int pos = 0;
			for (int i = 0; i < words.Count; i++) {
				SimpleTextWord word = words[i];
				if (pos >= endIndex)
					break;
				int wordEnd = pos + word.Word.Length;
				// 3 possibilities:
				if (startIndex <= pos && endIndex >= wordEnd) {
					// word is fully in region:
					word.Bold = bold;
				} else if (startIndex <= pos) {
					// beginning of word is in region
					int inRegionLength = endIndex - pos;
					SimpleTextWord newWord = new SimpleTextWord(word.Type, word.Word.Substring(inRegionLength), word.Bold, word.Color);
					words.Insert(i + 1, newWord);
					
					word.Bold = bold;
					word.Word = word.Word.Substring(0, inRegionLength);
				} else if (startIndex < wordEnd) {
					// end of word is in region (or middle of word is in region)
					int notInRegionLength = startIndex - pos;
					
					SimpleTextWord newWord = new SimpleTextWord(word.Type, word.Word.Substring(notInRegionLength), word.Bold, word.Color);
					// newWord.Bold will be set in the next iteration
					words.Insert(i + 1, newWord);
					
					word.Word = word.Word.Substring(0, notInRegionLength);
				}
				pos = wordEnd;
			}
		}