From a6e5726f186bf9d2a0ea91169649504c7396c539 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 25 Jul 2022 08:10:07 +0200 Subject: sw content controls, plain text: add DOCX export Map the PlainText UNO property to: Change-Id: I57f365fcfb3a80acb74aa932432a8ae8f3acc92b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137398 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/qa/filter/ww8/ww8.cxx | 33 ++++++++++++++++++++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 5 +++++ 2 files changed, 38 insertions(+) (limited to 'sw') 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 +#include + 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(); CPPUNIT_ASSERT_EQUAL(static_cast(-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 xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference 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; -- cgit