summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-07-02 16:26:03 +0200
committerMiklos Vajna <vmiklos@collabora.com>2019-07-02 18:40:27 +0200
commit7fa96a3e4bdd384ad411e0bdc4e7c3f2ab920279 (patch)
treeb6b288df0995b3e1a7fece67f29cbf7f3b9c66ec /writerfilter
parentc28d92d157f7ee7edb4a151ec92f5284b4f3d45e (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
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx19
1 files changed, 19 insertions, 0 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 36174fa66cfb..21d6e65d1af3 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>
@@ -2233,12 +2234,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 );
}