sw/qa/extras/ooxmlexport/ooxmlexport13.cxx | 32 +++++++++++++++++++++++++++++ sw/source/filter/ww8/ww8atr.cxx | 7 ++++++ 2 files changed, 39 insertions(+)
New commits: commit 24073d986988c51425b3eb3c8d6aef171e914eaf Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Jan 30 10:21:08 2020 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Jan 30 16:36:37 2020 +0100 DOCX export: implement support for user fields Updating the field doesn't work yet, that'll need additional markup in settings.xml. (cherry picked from commit 676862bb8aa043f116615e5d0dac59254eaa8138) Conflicts: sw/qa/extras/ooxmlexport/ooxmlexport14.cxx Change-Id: I562ae62cebcbd5ca474bd0f7a181773f8e515f5e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87729 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx index 8706782b6d9c..32e7ad309664 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -17,6 +17,7 @@ #include <com/sun/star/drawing/XControlShape.hpp> #include <com/sun/star/style/LineSpacing.hpp> #include <com/sun/star/style/LineSpacingMode.hpp> +#include <com/sun/star/text/XDependentTextField.hpp> #include <sfx2/docfile.hxx> #include <sfx2/docfilt.hxx> @@ -417,6 +418,37 @@ CPPUNIT_TEST_FIXTURE(SwModelTestBase, testZeroLineSpacing) assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:spacing", "line", "0"); } +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"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index 86b2b56f4889..f7fad56a52f6 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -3250,6 +3250,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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits