Example #1
0
        private void CreateFlatTextRanges()
        {
            foreach (XDocument document in this.documents)
            {
                FlatTextRange currentRange = null;
                foreach (XElement run in document.Descendants(FlatConstants.RunElementName))
                {
                    if (!run.HasElements)
                    {
                        continue;
                    }

                    FlatText flatText = FlattenRunElement(run);
                    if (flatText == null)
                    {
                        continue;
                    }

                    // If current Run doesn't belong to same parent (like paragraph, hyperlink, etc.)
                    // create new FlatTextRange, otherwise use current one.
                    if (currentRange == null || currentRange.Parent != run.Parent)
                    {
                        currentRange = this.CreateFlatTextRange(run.Parent);
                    }
                    currentRange.AddFlatText(flatText);
                }
            }
        }
Example #2
0
        private static void ReplaceText(FlatText flatText, int searchStartIndex, int searchEndIndex, string replace)
        {
            string text = string.Empty;

            if (flatText.StartIndex < searchStartIndex)
            {
                // Leave text that is before the searched text.
                text = flatText.Text.Remove(searchStartIndex - flatText.StartIndex);
            }

            text += replace;

            if (flatText.EndIndex > searchEndIndex)
            {
                // Leave text that is after the searched text.
                text += flatText.Text.Substring(searchEndIndex - flatText.StartIndex + 1);
            }

            flatText.Text = text;
        }
Example #3
0
        public void FindAndReplace(string find, string replace, StringComparison comparisonType)
        {
            int searchStartIndex = -1, searchEndIndex = -1, searchPosition = 0;

            while ((searchStartIndex = this.rangeText.ToString().IndexOf(find, searchPosition, comparisonType)) != -1)
            {
                searchEndIndex = searchStartIndex + find.Length - 1;

                // Find FlatText that contains the beginning of the searched text.
                LinkedListNode <FlatText> node = this.FindNode(searchStartIndex);
                FlatText flatText = node.Value;

                ReplaceText(flatText, searchStartIndex, searchEndIndex, replace);

                // Remove next FlatTexts that contain parts of the searched text.
                this.RemoveNodes(node, searchEndIndex);

                this.ResetRangeText();
                searchPosition = searchStartIndex + replace.Length;
            }
        }
Example #4
0
 private void AddRangeText(FlatText flatText)
 {
     flatText.SetIndexes(this.rangeText.Length);
     this.rangeText.Append(flatText.Text);
 }
Example #5
0
 public void AddFlatText(FlatText flatText)
 {
     this.range.AddLast(flatText);
     this.AddRangeText(flatText);
 }