[Libreoffice-commits] core.git: sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Thu Jan 30 10:07:01 UTC 2020


 sw/qa/extras/ooxmlexport/ooxmlexport14.cxx |   32 +++++++++++++++++++++++++++++
 sw/source/filter/ww8/ww8atr.cxx            |    7 ++++++
 2 files changed, 39 insertions(+)

New commits:
commit 676862bb8aa043f116615e5d0dac59254eaa8138
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Jan 30 10:21:08 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Jan 30 11:06:20 2020 +0100

    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 at collabora.com>
    Tested-by: Jenkins

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;


More information about the Libreoffice-commits mailing list