diff options
author | Caolán McNamara <caolanm@redhat.com> | 2014-12-08 16:11:41 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-12-08 16:24:27 +0000 |
commit | af64f430181088460d5c574683dd1fdfd377ebcd (patch) | |
tree | cee7754e021d60de8cb8d0f796f28577b4c06fd5 | |
parent | 93913ce2a71c66f57c9fe6a4b12c12ca6f7f473e (diff) |
writer won't allow us to enter multiple CrossRefBookmarks on the same node
e.g. fdo63164-1.docx and loads more like that, and the .docx genuinely has
multiple bookmarks at the same place, so just allow the first one and discard
the following ones
Change-Id: Ida2f5d79fdef4ed3e2d8c1e96ca6a086004f6c7d
-rw-r--r-- | sw/qa/core/data/ooxml/pass/fdo63164-1.docx | bin | 0 -> 48419 bytes | |||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 32 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.hxx | 2 |
3 files changed, 30 insertions, 4 deletions
diff --git a/sw/qa/core/data/ooxml/pass/fdo63164-1.docx b/sw/qa/core/data/ooxml/pass/fdo63164-1.docx Binary files differnew file mode 100644 index 000000000000..768ec6ce38f7 --- /dev/null +++ b/sw/qa/core/data/ooxml/pass/fdo63164-1.docx diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 7176485c047a..6c7bbdb06dbc 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -55,6 +55,7 @@ #include <com/sun/star/text/XParagraphCursor.hpp> #include <com/sun/star/text/XRedline.hpp> #include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/text/XTextRangeCompare.hpp> #include <com/sun/star/style/DropCapFormat.hpp> #include <com/sun/star/util/NumberFormatter.hpp> #include <com/sun/star/util/XNumberFormatsSupplier.hpp> @@ -4416,11 +4417,34 @@ void DomainMapper_Impl::StartOrEndBookmark( const OUString& rId ) { xCursor->goLeft( 1, false ); } + uno::Reference< container::XNamed > xBkmNamed( xBookmark, uno::UNO_QUERY_THROW ); - assert(!aBookmarkIter->second.m_sBookmarkName.isEmpty()); - //todo: make sure the name is not used already! - xBkmNamed->setName( aBookmarkIter->second.m_sBookmarkName ); - xTextAppend->insertTextContent( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW), xBookmark, !xCursor->isCollapsed() ); + + bool bAllowInsert = true; + uno::Reference<text::XTextRange> xRange(xCursor, uno::UNO_QUERY_THROW); + if (m_xPrevBookmark.is()) + { + fprintf(stderr, "ok here\n"); + uno::Reference<text::XTextRangeCompare> xTextRangeCompare(xRange->getText(), uno::UNO_QUERY_THROW); + fprintf(stderr, "still ok here\n"); + + if (xTextRangeCompare->compareRegionStarts(m_xPrevBookmark, xRange) == 0 && + xTextRangeCompare->compareRegionEnds(m_xPrevBookmark, xRange) == 0) + { + SAL_WARN("writerfilter", "Cannot insert bookmark " << aBookmarkIter->second.m_sBookmarkName + << " because another one is already inserted at this point"); + bAllowInsert = false; + } + } + + if (bAllowInsert) + { + assert(!aBookmarkIter->second.m_sBookmarkName.isEmpty()); + //todo: make sure the name is not used already! + xBkmNamed->setName( aBookmarkIter->second.m_sBookmarkName ); + xTextAppend->insertTextContent(xRange, xBookmark, !xCursor->isCollapsed()); + m_xPrevBookmark = xRange; + } } m_aBookmarkMap.erase( aBookmarkIter ); m_sCurrentBkmkId.clear(); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index 11e58cd9ff1f..c218f53559f5 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -349,6 +349,8 @@ private: LineNumberSettings m_aLineNumberSettings; BookmarkMap_t m_aBookmarkMap; + /// Detect attempt to insert multiple bookmarks at the same position + css::uno::Reference<css::text::XTextRange> m_xPrevBookmark; OUString m_sCurrentBkmkId; OUString m_sCurrentBkmkName; |