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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Jan 12 00:02:39 UTC 2019


 sw/qa/extras/ooxmlexport/data/empty-date-control.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport13.cxx           |   20 +++++++++++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx         |    6 +++++
 writerfilter/source/dmapper/SdtHelper.cxx            |    2 -
 4 files changed, 27 insertions(+), 1 deletion(-)

New commits:
commit 24613d7abf820aff639a276a1819ada8d83e9063
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Fri Jan 11 19:58:02 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Sat Jan 12 01:02:11 2019 +0100

    tdf#122658: Empty date form field is not exported correctly to DOCX file
    
    We need to export date format and also text content
    in case of empty date field. Otherwise the exported
    date field will be lost during import into LO Writer
    or MSO Word.
    
    Change-Id: I5cf65bedba010f64ca8f56262057f3cce32b0943
    Reviewed-on: https://gerrit.libreoffice.org/66194
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/data/empty-date-control.odt b/sw/qa/extras/ooxmlexport/data/empty-date-control.odt
new file mode 100755
index 000000000000..acd5b8b94e73
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/empty-date-control.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index b22c5cd96083..dac93371abb6 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -14,6 +14,7 @@
 #include <com/sun/star/text/WritingMode2.hpp>
 #include <com/sun/star/text/XTextFrame.hpp>
 #include <com/sun/star/text/XTextFramesSupplier.hpp>
+#include <com/sun/star/drawing/XControlShape.hpp>
 
 #include <sfx2/docfile.hxx>
 #include <sfx2/docfilt.hxx>
@@ -66,6 +67,25 @@ DECLARE_OOXMLEXPORT_TEST(testendingSectionProps, "endingSectionProps.docx")
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Section Left Margin", sal_Int32(2540), getProperty<sal_Int32>(xSect, "SectionLeftMargin"));
 }
 
+DECLARE_OOXMLEXPORT_TEST(testDateControl, "empty-date-control.odt")
+{
+    // Check that we did not lost the date control
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xDraws->getCount());
+    uno::Reference<drawing::XControlShape> xControl(getShape(1), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xControl->getControl().is());
+
+    // check XML
+    xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+    if (!pXmlDoc)
+        return;
+
+    // We need to export date format and a dummy character (" ") for empty date control
+    assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date/w:dateFormat", "val", "dd/MM/yyyy");
+    assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", u" ");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
old mode 100644
new mode 100755
index c655d991c7aa..e845fe0655c7
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5037,7 +5037,13 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject)
             }
         }
         else
+        {
             aContentText = xPropertySet->getPropertyValue("HelpText").get<OUString>();
+            if(aContentText.isEmpty())
+                aContentText = " "; // Need to write out something to have it imported by MS Word
+            if(sDateFormat.isEmpty())
+                sDateFormat = "dd/MM/yyyy"; // Need to set date format even if there is no date set
+        }
 
         // output component
 
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index 316980aa067e..0b870749313b 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -163,7 +163,7 @@ void SdtHelper::createDateControl(OUString const& rContentText, const beans::Pro
         xPropertySet->setPropertyValue("Date", uno::makeAny(aDate));
     }
     else
-        xPropertySet->setPropertyValue("HelpText", uno::makeAny(rContentText));
+        xPropertySet->setPropertyValue("HelpText", uno::makeAny(rContentText.trim()));
 
     // append date format to grab bag
     comphelper::SequenceAsHashMap aGrabBag;


More information about the Libreoffice-commits mailing list