Kaydet (Commit) af64f430 authored tarafından Caolán McNamara's avatar Caolán McNamara

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
üst 93913ce2
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include <com/sun/star/text/XParagraphCursor.hpp> #include <com/sun/star/text/XParagraphCursor.hpp>
#include <com/sun/star/text/XRedline.hpp> #include <com/sun/star/text/XRedline.hpp>
#include <com/sun/star/text/XTextFieldsSupplier.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/style/DropCapFormat.hpp>
#include <com/sun/star/util/NumberFormatter.hpp> #include <com/sun/star/util/NumberFormatter.hpp>
#include <com/sun/star/util/XNumberFormatsSupplier.hpp> #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
...@@ -4416,11 +4417,34 @@ void DomainMapper_Impl::StartOrEndBookmark( const OUString& rId ) ...@@ -4416,11 +4417,34 @@ void DomainMapper_Impl::StartOrEndBookmark( const OUString& rId )
{ {
xCursor->goLeft( 1, false ); xCursor->goLeft( 1, false );
} }
uno::Reference< container::XNamed > xBkmNamed( xBookmark, uno::UNO_QUERY_THROW ); 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! bool bAllowInsert = true;
xBkmNamed->setName( aBookmarkIter->second.m_sBookmarkName ); uno::Reference<text::XTextRange> xRange(xCursor, uno::UNO_QUERY_THROW);
xTextAppend->insertTextContent( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW), xBookmark, !xCursor->isCollapsed() ); 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_aBookmarkMap.erase( aBookmarkIter );
m_sCurrentBkmkId.clear(); m_sCurrentBkmkId.clear();
......
...@@ -349,6 +349,8 @@ private: ...@@ -349,6 +349,8 @@ private:
LineNumberSettings m_aLineNumberSettings; LineNumberSettings m_aLineNumberSettings;
BookmarkMap_t m_aBookmarkMap; 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_sCurrentBkmkId;
OUString m_sCurrentBkmkName; OUString m_sCurrentBkmkName;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment