summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-01-10 13:20:40 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-01-10 14:13:05 +0100
commit04b2310aaa094794ceedaa1bb6ff1823a2d29d3e (patch)
tree6ed8c727ef149a6443a06cca064e7612340a33fb /sw/qa
parentd9c535ead688e9f156dbcf43948df08a69e218be (diff)
DOCX import: fix lost objects anchored to the single para of a linked header
Regression from commit 08f13ab85b5c65b5dc8adfa15918fb3e426fcc3c (tdf#112202 writerfilter,sw: fix loss of headers, 2019-12-16), the problem is that on one hand, copyText() is meant to copy a complete XText (header, table cell, footnote, etc), OTOH the internal API use used only copies at-para anchored objects for complete text nodes, so a one-paragraph header will loose its anchored objects when a linked header is copied. Introduce a new "CopyText" flag that provides the expected copyText() behavior and use that when the copyText() UNO API is invoked, but leave the selection behavior unchanged. Perform the inclusive check in IsSelectFrameAnchoredAtPara(), opt in for that from SwXText::copyText(), the rest is just passing the flag around. Change-Id: Id727f7ca4f6121a7050340359716a52ecb4886f2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86529 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/extras/ooxmlimport/data/text-copy.docxbin0 -> 16306 bytes
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport2.cxx28
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx4
3 files changed, 30 insertions, 2 deletions
diff --git a/sw/qa/extras/ooxmlimport/data/text-copy.docx b/sw/qa/extras/ooxmlimport/data/text-copy.docx
new file mode 100644
index 000000000000..9c871e633517
--- /dev/null
+++ b/sw/qa/extras/ooxmlimport/data/text-copy.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index f5ff5b3b53e8..11243d14e33d 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -283,6 +283,34 @@ DECLARE_OOXMLIMPORT_TEST(testTdf124754, "tdf124754.docx")
getProperty<sal_Int32>(xText, "CharColor"));
}
+DECLARE_OOXMLIMPORT_TEST(testTextCopy, "text-copy.docx")
+{
+ // The document has a header on the second page that is copied as part of the import process.
+ // The header has a single paragraph: make sure shapes anchored to it are not lost.
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
+ uno::Reference<beans::XPropertySet> xPara;
+ while (xParaEnum->hasMoreElements())
+ {
+ xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
+ }
+ auto aPageStyleName = getProperty<OUString>(xPara, "PageStyleName");
+ uno::Reference<beans::XPropertySet> xPageStyle(
+ getStyles("PageStyles")->getByName(aPageStyleName), uno::UNO_QUERY);
+ auto xHeaderText = getProperty<uno::Reference<text::XText>>(xPageStyle, "HeaderText");
+ uno::Reference<container::XContentEnumerationAccess> xHeaderPara(
+ getParagraphOfText(1, xHeaderText), uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xHeaderShapes
+ = xHeaderPara->createContentEnumeration("com.sun.star.text.TextContent");
+ // Without the accompanying fix in place, this test would have failed with:
+ // assertion failed
+ // - Expression: xHeaderShapes->hasMoreElements()
+ // i.e. the second page's header had no anchored shapes.
+ CPPUNIT_ASSERT(xHeaderShapes->hasMoreElements());
+}
+
DECLARE_OOXMLIMPORT_TEST(testTdf112443, "tdf112443.docx")
{
// the position of the flying text frame should be off page
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index db26e92aca24..76a1054c441a 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -748,7 +748,7 @@ void SwUiWriterTest::testBookmarkCopy()
aPaM.SttEndDoc(true/*start*/);
aPaM.Move(fnMoveForward, GoInContent); // partially select 1st para
- rIDCO.CopyRange(aPaM, target, /*bCopyAll=*/false, /*bCheckPos=*/true);
+ rIDCO.CopyRange(aPaM, target, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false);
// check bookmark was copied to correct position
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), rIDMA.getBookmarksCount());
@@ -764,7 +764,7 @@ void SwUiWriterTest::testBookmarkCopy()
rIDCO.SplitNode(*aPaM.GetPoint(), false);
aPaM.SttEndDoc(true/*start*/);
- rIDCO.CopyRange(aCopyPaM, *aPaM.GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true);
+ rIDCO.CopyRange(aCopyPaM, *aPaM.GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false);
// check bookmark was copied to correct position
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), rIDMA.getBookmarksCount());