diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-07-02 16:26:03 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-07-03 16:53:23 +0200 |
commit | 01a181057484144f954c0e3a5e53ada72aeb675c (patch) | |
tree | 3f88711088b595e5d852ce3e0e27694530d84e08 /writerfilter | |
parent | ae62854895df02a62e74af1e25874e2e53df599f (diff) |
sw comments on frames: fix DOCX handling
We used to ignore annotation marks which just cover the comment anchor
since commit fff019debf14a0bf8cd358591a686191347f1542 (MSWordExportBase:
ignore empty annotation marks, 2014-09-17), but this means comments on
images are lost.
Pass around SwWW8AttrIter, so we can decide if we have a relevant
at-char anchored frame in MSWordExportBase::GetAnnotationMarks(),
without iterating over all frames in the document, which would be slow
for large documents.
Regarding the import side, the only problem was that the empty comment
range resulted in a loss of annotation marks; fix that by using a marker
while inserting.
Change-Id: I385677d74423bc05824dac4a12d1a991bb3983c4
Reviewed-on: https://gerrit.libreoffice.org/74996
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
(cherry picked from commit 7fa96a3e4bdd384ad411e0bdc4e7c3f2ab920279)
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index eb529ea8d00a..11bc5de450fd 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -58,6 +58,7 @@ #include <com/sun/star/text/XRedline.hpp> #include <com/sun/star/text/XTextFieldsSupplier.hpp> #include <com/sun/star/text/RubyPosition.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> @@ -2231,12 +2232,30 @@ void DomainMapper_Impl::PopAnnotation() // Create a range that points to the annotation start/end. uno::Reference<text::XText> const xText = aAnnotationPosition.m_xStart->getText(); uno::Reference<text::XTextCursor> const xCursor = xText->createTextCursorByRange(aAnnotationPosition.m_xStart); + + bool bMarker = false; + uno::Reference<text::XTextRangeCompare> xTextRangeCompare(xText, uno::UNO_QUERY); + if (xTextRangeCompare->compareRegionStarts(aAnnotationPosition.m_xStart, aAnnotationPosition.m_xEnd) == 0) + { + // Insert a marker so that comment around an anchored image is not collapsed during + // insertion. + xText->insertString(xCursor, "x", false); + bMarker = true; + } + xCursor->gotoRange(aAnnotationPosition.m_xEnd, true); uno::Reference<text::XTextRange> const xTextRange(xCursor, uno::UNO_QUERY_THROW); // Attach the annotation to the range. uno::Reference<text::XTextAppend> const xTextAppend = m_aTextAppendStack.top().xTextAppend; xTextAppend->insertTextContent(xTextRange, uno::Reference<text::XTextContent>(m_xAnnotationField, uno::UNO_QUERY_THROW), !xCursor->isCollapsed()); + + if (bMarker) + { + // Remove the marker. + xCursor->goLeft(1, true); + xCursor->setString(OUString()); + } } m_aAnnotationPositions.erase( m_nAnnotationId ); } |