summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-07-25 08:10:07 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-07-25 08:49:00 +0200
commita6e5726f186bf9d2a0ea91169649504c7396c539 (patch)
tree602864bcb21300d82d15b11a41a1b153dd420c25 /sw
parentebed8dc382817b8f356d090ac4794a3eee8f1f0f (diff)
sw content controls, plain text: add DOCX export
Map the PlainText UNO property to: <w:sdtPr> <w:text/> </w:sdtPr> Change-Id: I57f365fcfb3a80acb74aa932432a8ae8f3acc92b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137398 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/filter/ww8/ww8.cxx33
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx5
2 files changed, 38 insertions, 0 deletions
diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx
index 7ccb1299769e..4f33e781d05d 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -9,6 +9,8 @@
#include <swmodeltestbase.hxx>
+#include <com/sun/star/text/XTextDocument.hpp>
+
namespace
{
constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/filter/ww8/data/";
@@ -48,6 +50,37 @@ CPPUNIT_TEST_FIXTURE(Test, testNegativePageBorderDocImport)
auto nTopBorderDistance = xStyle->getPropertyValue("TopBorderDistance").get<sal_Int32>();
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-646), nTopBorderDistance);
}
+
+CPPUNIT_TEST_FIXTURE(Test, testPlainTextContentControlExport)
+{
+ // Given a document with a plain text content control around a text portion:
+ mxComponent = loadFromDesktop("private:factory/swriter");
+ uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> xText = xTextDocument->getText();
+ uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
+ xText->insertString(xCursor, "test", /*bAbsorb=*/false);
+ xCursor->gotoStart(/*bExpand=*/false);
+ xCursor->gotoEnd(/*bExpand=*/true);
+ uno::Reference<text::XTextContent> xContentControl(
+ xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY);
+ xContentControlProps->setPropertyValue("PlainText", uno::Any(true));
+ xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
+
+ // When exporting to DOCX:
+ save("Office Open XML Text", maTempFile);
+ mbExported = true;
+
+ // Then make sure the expected markup is used:
+ xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 1
+ // - Actual : 0
+ // - XPath '//w:sdt/w:sdtPr/w:text' number of nodes is incorrect
+ // i.e. the plain text content control was turned into a rich text one on export.
+ assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:text", 1);
+}
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index abbe2f8bb06f..f525aadf460f 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2423,6 +2423,11 @@ void DocxAttributeOutput::WriteContentControlStart()
m_pSerializer->endElementNS(XML_w, XML_date);
}
+ if (m_pContentControl->GetPlainText())
+ {
+ m_pSerializer->singleElementNS(XML_w, XML_text);
+ }
+
m_pSerializer->endElementNS(XML_w, XML_sdtPr);
m_pSerializer->startElementNS(XML_w, XML_sdtContent);
m_pContentControl = nullptr;