summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-01-30 10:21:08 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-01-30 11:06:20 +0100
commit676862bb8aa043f116615e5d0dac59254eaa8138 (patch)
treef5d59315908a17ad1d99c2690b4b394571a96565
parent4223ff2be69f03e571464b0b09ad0d278918631b (diff)
DOCX export: implement support for user fields
Updating the field doesn't work yet, that'll need additional markup in settings.xml. Change-Id: I562ae62cebcbd5ca474bd0f7a181773f8e515f5e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87720 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport14.cxx32
-rw-r--r--sw/source/filter/ww8/ww8atr.cxx7
2 files changed, 39 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
index 398ba1fabbd2..b79850140144 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/text/RelOrientation.hpp>
#include <com/sun/star/style/LineSpacing.hpp>
#include <com/sun/star/style/LineSpacingMode.hpp>
+#include <com/sun/star/text/XDependentTextField.hpp>
class Test : public SwModelTestBase
{
@@ -279,6 +280,37 @@ CPPUNIT_TEST_FIXTURE(SwModelTestBase, testSemiTransparentText)
CPPUNIT_ASSERT_EQUAL(nTransparence, nActual);
}
+CPPUNIT_TEST_FIXTURE(SwModelTestBase, testUserField)
+{
+ // Create an in-memory empty document with a user field.
+ loadURL("private:factory/swriter", nullptr);
+ uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XDependentTextField> xField(
+ xFactory->createInstance("com.sun.star.text.TextField.User"), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xMaster(
+ xFactory->createInstance("com.sun.star.text.FieldMaster.User"), uno::UNO_QUERY);
+ xMaster->setPropertyValue("Name", uno::makeAny(OUString("foo")));
+ xField->attachTextFieldMaster(xMaster);
+ xField->getTextFieldMaster()->setPropertyValue("Content", uno::makeAny(OUString("bar")));
+ uno::Reference<text::XTextDocument> xDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> xText = xDocument->getText();
+ xText->insertTextContent(xText->createTextCursor(), xField, /*bAbsorb=*/false);
+
+ // Export to docx.
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= OUString("Office Open XML Text");
+ xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+ mbExported = true;
+ xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+ CPPUNIT_ASSERT(pXmlDoc);
+
+ // Without the accompanying fix in place, this test would have failed, the user field was
+ // exported as <w:t>User Field foo = bar</w:t>.
+ assertXPathContent(pXmlDoc, "//w:p/w:r[2]/w:instrText", " DOCVARIABLE foo ");
+ assertXPathContent(pXmlDoc, "//w:p/w:r[4]/w:t", "bar");
+}
+
DECLARE_OOXMLEXPORT_TEST(testTdf124367, "tdf124367.docx")
{
uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 945badc3bfb1..038630b2c081 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -3267,6 +3267,13 @@ void AttributeOutputBase::TextField( const SwFormatField& rField )
GetExport().OutputField( pField, ww::eMACROBUTTON, sStr );
}
break;
+ case SwFieldIds::User:
+ {
+ ww::eField eField = ww::eDOCVARIABLE;
+ OUString aExpand = FieldString(eField) + pField->GetPar1() + " ";
+ GetExport().OutputField(pField, eField, aExpand);
+ }
+ break;
default:
bWriteExpand = true;
break;