sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx | 4 +++- sw/qa/extras/ww8export/data/tdf141649_conditionalText.doc |binary sw/qa/extras/ww8export/ww8export4.cxx | 9 +++++++++ sw/source/filter/ww8/ww8par5.cxx | 10 ++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-)
New commits: commit 85ae3d1513d4be3eb102bf3065ddfba27cb1f1c3 Author: Justin Luth <[email protected]> AuthorDate: Wed Jan 18 14:32:21 2023 -0500 Commit: Justin Luth <[email protected]> CommitDate: Thu Jan 19 23:57:28 2023 +0000 tdf#141649 doc import: do not duplicate conditional text This patch is a mixed blessing. It will be a regression if an IF FIELD was bogus, and the user only wanted to see the modified, unrefreshed text. That is because in MS Word, most fields do not update automatically, but require the user to press F9 to refresh the contents. The contents are also editable, so the result might not match either the true or false result-string. However, in LO the IF FIELD is always refreshed, and thus will never display any bogus hand-modifications. The import of these IF fields started in DOC in LO 6.1, but it was never correct and immediately duplicated content. Additionally, DOC format didn't export at all, so anything to do with IF FIELDS was lost - meaning that after a round-trip the result was the same as what MS Word last saw with the field gone. So in the eyes of the user, the fixing of import and export might be causing a regression of changed text. So be it. I can only assume that in most cases the use of an IF FIELD is intentional and that it would be desirsable to have it working. Change-Id: If90f6f4cddcefebf379352aac6519595c1bf2b23 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145821 Tested-by: Jenkins Reviewed-by: Justin Luth <[email protected]> diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx index d20cf2338a07..11ddc54f1717 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx @@ -824,7 +824,9 @@ CPPUNIT_TEST_FIXTURE(Test, testConditionalText2) // Load a document which has a conditional text field in it. xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); std::u16string_view aExpected(u" IF 1 = 1 \"test1\" \"test2\""); - assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[3]/w:instrText", OUString(aExpected)); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[2]/w:instrText", OUString(aExpected)); + + getParagraph(1, "test1"); } DECLARE_OOXMLEXPORT_TEST(testTdf142464_ampm, "tdf142464_ampm.docx") diff --git a/sw/qa/extras/ww8export/data/tdf141649_conditionalText.doc b/sw/qa/extras/ww8export/data/tdf141649_conditionalText.doc new file mode 100644 index 000000000000..9e4ec49e38a6 Binary files /dev/null and b/sw/qa/extras/ww8export/data/tdf141649_conditionalText.doc differ diff --git a/sw/qa/extras/ww8export/ww8export4.cxx b/sw/qa/extras/ww8export/ww8export4.cxx index 1910178d0ac8..6889b587ac6a 100644 --- a/sw/qa/extras/ww8export/ww8export4.cxx +++ b/sw/qa/extras/ww8export/ww8export4.cxx @@ -78,6 +78,15 @@ DECLARE_WW8EXPORT_TEST(testTdf151548_formFieldMacros, "tdf151548_formFieldMacros } } +DECLARE_WW8EXPORT_TEST(testTdf141649_conditionalText, "tdf141649_conditionalText.doc") +{ + // In MS Word, the IF field is editable and requires manual update, so the most correct + // result is "manual refresh with F9" inside a text field, + // but for our purposes, a single instance of "trueResult" is appropriate. + getParagraph(1, "trueResult"); +} + + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx index 35cb2b507369..ddaad0e3f741 100644 --- a/sw/source/filter/ww8/ww8par5.cxx +++ b/sw/source/filter/ww8/ww8par5.cxx @@ -1026,6 +1026,16 @@ tools::Long SwWW8ImplReader::Read_Field(WW8PLCFManResult* pRes) m_bEmbeddObj = true; // Field not supported: store the field code for later use m_aFieldStack.back().SetBookmarkCode( aStr ); + + if (aF.nId == ww::eIF) + { + // In MS Word, the IF field is editable and requires a manual refresh + // so the last, saved result might not match either of the true or false options. + // But in LO the field is automatically updated and not editable, + // so the previous result is of no value to import since it could never be seen. + return aF.nLen; + } + return aF.nLen - aF.nLRes - 1; // skipped too many, the resulted field will be read like main text } }
