Пример #1
0
 public void TestEqualsReturnsFalseForDiffStartProperty()
 {
     OxmlRange target = new OxmlRange(0, 1, 2);
     OxmlRange other = new OxmlRange(0, 3, 2);
     bool expected = false;
     bool actual = target.Equals(other);
     Assert.AreEqual(expected, actual);
 }
Пример #2
0
 public void TestEqualsReturnsFalseIfOtherIsNull()
 {
     OxmlRange target = new OxmlRange(0, 1, 2);
     OxmlRange other = null;
     bool expected = false;
     bool actual = target.Equals(other);
     Assert.AreEqual(expected, actual);
 }
Пример #3
0
        public void BookmarkRange(OxmlRange range, string bookmarkName)
        {
            /*
             * This function loops over the runs of paragraph the range is in and keeps
             * track of the ecnountered text size to find the range start and end.
             * Bookmark start and end tags are then inserted at sais locations.
             */

            Debug.Assert(range.BlockId >= 0, "Block ID is negative.");
            Debug.Assert(range.BlockId < this._paragraphs.Count, "Block ID exceeds number of paragraphs.");

            var paragraph = this._paragraphs[range.BlockId];
            int cursor = 0;

            BookmarkStart bookmarkStart = null;
            BookmarkEnd bookmarkEnd = null;

            foreach (var run in paragraph.Descendants<Run>())
            {
                if (bookmarkStart == null)
                {
                    if (cursor == range.Start)
                    {
                        bookmarkStart = GenerateNewBookmarkStart(bookmarkName);
                        run.InsertBeforeSelf<BookmarkStart>(bookmarkStart);
                    }
                    else if (cursor + run.InnerText.Length > range.Start)
                    {
                        SplitRunAtIndex(run, range.Start - cursor);
                        bookmarkStart = GenerateNewBookmarkStart(bookmarkName);
                        run.InsertAfterSelf<BookmarkStart>(bookmarkStart);
                    }
                }
                if (bookmarkStart != null && bookmarkEnd == null)
                {
                    if (cursor == range.End)
                    {
                        bookmarkEnd = new BookmarkEnd();
                        bookmarkEnd.Id = bookmarkStart.Id;
                        run.InsertAfterSelf<BookmarkEnd>(bookmarkEnd);
                    }
                    else if (cursor + run.InnerText.Length >= range.End)
                    {
                        SplitRunAtIndex(run, range.End - cursor);
                        bookmarkEnd = new BookmarkEnd();
                        bookmarkEnd.Id = bookmarkStart.Id;
                        run.InsertAfterSelf<BookmarkEnd>(bookmarkEnd);
                    }
                }
                if (bookmarkStart != null && bookmarkEnd != null) break;
                cursor += run.InnerText.Length;
            }

            Debug.Assert(bookmarkStart != null, "Start of bookmark range was not found.");
            Debug.Assert(bookmarkEnd != null, "End of bookmark range was not found.");
        }
Пример #4
0
 public bool Equals(OxmlRange other)
 {
     if (other == null)
     {
         return false;
     }
     else
     {
         return this._blockId == other._blockId &&
                this._start == other._start &&
                this._end == other._end;
     }
 }
Пример #5
0
 public void TestEqualsReturnsTrueIfAllPropertiesEqual()
 {
     OxmlRange target = new OxmlRange(0, 1, 2);
     OxmlRange other = new OxmlRange(0, 1, 2);
     bool expected = true;
     bool actual = target.Equals(other);
     Assert.AreEqual(expected, actual);
 }