sw/qa/extras/ooxmlexport/ooxmlexport13.cxx | 1 + sw/source/filter/ww8/docxattributeoutput.cxx | 24 ++++++++++++++++++++++-- sw/source/filter/ww8/docxattributeoutput.hxx | 1 + 3 files changed, 24 insertions(+), 2 deletions(-)
New commits: commit 67580c2ee5ff62583d2e7b6a8c0b848ec258f17e Author: Michael Stahl <michael.st...@cib.de> AuthorDate: Fri Mar 6 13:10:48 2020 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Mar 10 17:14:56 2020 +0100 sw: DOCX export: fix bookmark inside sdtDropDown Word refuses to open a document that has a w:bookmarkEnd inside w:sdtContent but with no text content following it. It turns out that the bookmark position is wrong anyway, it should end before the text according to Writer's model. It shouldn't make a difference whether the end is inside the sdtContent or preceding the SDT, so write the text content of the SDT from the EndField_Impl(). Another idea would be to move the writing of bookmarks in EndRun() before the StartField_Impl() but who knows what that would break. (regression from d55b26a093bdbced08985dbc7113190b52a8bc66) Change-Id: I476c0829814b061d80811cc6817923ee06013a26 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90100 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@cib.de> (cherry picked from commit 1f5af453b5994c9e8ccd0756882b98715c75114b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90030 Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx index d0edf4d5fcd4..91817f2f2220 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -450,6 +450,7 @@ DECLARE_OOXMLEXPORT_TEST(testInputListExport, "tdf122186_input_list.odt") CPPUNIT_ASSERT_EQUAL(OUString("1"), items[0]); CPPUNIT_ASSERT_EQUAL(OUString("2"), items[1]); CPPUNIT_ASSERT_EQUAL(OUString("3"), items[2]); + CPPUNIT_ASSERT_EQUAL(OUString("1"), getProperty<OUString>(xPropertySet, "DefaultText")); } } diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 6885e002bf29..99aad24c3da2 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1964,6 +1964,17 @@ void DocxAttributeOutput::WriteSdtDropDownStart( m_pSerializer->endElementNS(XML_w, XML_sdtPr); m_pSerializer->startElementNS(XML_w, XML_sdtContent); +} + +void DocxAttributeOutput::WriteSdtDropDownEnd(OUString const& rSelected, + uno::Sequence<OUString> const& rListItems) +{ + // note: rSelected might be empty? + sal_Int32 nId = comphelper::findValue(rListItems, rSelected); + if (nId == -1) + { + nId = 0; + } // the lastValue only identifies the entry in the list, also export // currently selected item's displayText as run content (if one exists) @@ -1975,6 +1986,8 @@ void DocxAttributeOutput::WriteSdtDropDownStart( m_pSerializer->endElementNS(XML_w, XML_t); m_pSerializer->endElementNS(XML_w, XML_r); } + + WriteSdtEnd(); } void DocxAttributeOutput::StartField_Impl( const SwTextNode* pNode, sal_Int32 nPos, FieldInfos const & rInfos, bool bWriteRun ) @@ -2221,12 +2234,19 @@ void DocxAttributeOutput::DoWriteFieldRunProperties( const SwTextNode * pNode, s void DocxAttributeOutput::EndField_Impl( const SwTextNode* pNode, sal_Int32 nPos, FieldInfos& rInfos ) { - if (rInfos.eType == ww::eFORMDATE - || (rInfos.eType == ww::eFORMDROPDOWN && rInfos.pField)) + if (rInfos.eType == ww::eFORMDATE) { WriteSdtEnd(); return; } + if (rInfos.eType == ww::eFORMDROPDOWN && rInfos.pField) + { + // write selected item from End not Start to ensure that any bookmarks + // precede it + SwDropDownField const& rField(*static_cast<SwDropDownField const*>(rInfos.pField.get())); + WriteSdtDropDownEnd(rField.GetSelectedItem(), rField.GetItemSequence()); + return; + } // The command has to be written before for the hyperlinks if ( rInfos.pField ) diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index ef95f70fb881..edb6825f1fdc 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -718,6 +718,7 @@ private: void WriteFormDateStart(const OUString& sFullDate, const OUString& sDateFormat, const OUString& sLang); void WriteSdtDropDownStart(OUString const& rName, OUString const& rSelected, uno::Sequence<OUString> const& rListItems); + void WriteSdtDropDownEnd(OUString const& rSelected, uno::Sequence<OUString> const& rListItems); void WriteSdtEnd(); void StartField_Impl( const SwTextNode* pNode, sal_Int32 nPos, FieldInfos const & rInfos, bool bWriteRun = false ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits