[Libreoffice-commits] core.git: sw/qa sw/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Sat Nov 14 11:02:28 UTC 2020
sw/qa/extras/ooxmlexport/data/conditional-text.fodt | 8 ++++++
sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx | 13 ++++++++++
sw/source/filter/ww8/docxattributeoutput.cxx | 24 +++++++++++++++++++-
3 files changed, 44 insertions(+), 1 deletion(-)
New commits:
commit 5d839ff8a81ade6453a239a258b2a2571e32001e
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Nov 13 16:26:43 2020 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Sat Nov 14 12:01:39 2020 +0100
DOCX export: handle conditional fields
At least the subset where the condition syntax matches between Writer
and Word.
Change-Id: I107f2b4caeda6f7777696af8d5c5b455854cfa92
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105798
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/sw/qa/extras/ooxmlexport/data/conditional-text.fodt b/sw/qa/extras/ooxmlexport/data/conditional-text.fodt
new file mode 100644
index 000000000000..296c1c4ecc4d
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/conditional-text.fodt
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooow="http://openoffice.org/2004/writer" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+ <office:text>
+ <text:p><text:conditional-text text:condition="ooow:1 < 2" text:string-value-if-true="True" text:string-value-if-false="False">True</text:conditional-text></text:p>
+ </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
index eaf33fdda6b0..1a94982df7e9 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
@@ -663,6 +663,19 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf132185, "tdf132185.docx")
assertXPathContent(pXmlDoc, "/w:ftr/w:p/w:r[2]/w:instrText", " PAGE \\* roman ");
}
+DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testConditionalText, "conditional-text.fodt")
+{
+ // Load a document which has a conditional text field in it.
+ xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+ std::u16string_view aExpected(u" IF 1 < 2 \"True\" \"False\"");
+
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expression: xmlXPathNodeSetGetLength(pXmlNodes) > 0
+ // - In <...>, XPath '/w:document/w:body/w:p/w:r[2]/w:instrText' not found
+ // i.e. the field was lost on export.
+ assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[2]/w:instrText", aExpected);
+}
+
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
index c2eeeec1bee6..99cd7eabd6c4 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -7881,8 +7881,30 @@ void DocxAttributeOutput::RefField( const SwField& rField, const OUString& rRef
// There is nothing to do here for the set fields
}
-void DocxAttributeOutput::HiddenField( const SwField& /*rField*/ )
+void DocxAttributeOutput::HiddenField(const SwField& rField)
{
+ auto eSubType = static_cast<SwFieldTypesEnum>(rField.GetSubType());
+ if (eSubType == SwFieldTypesEnum::ConditionalText)
+ {
+ OUString aCond = rField.GetPar1();
+ OUString aTrueFalse = rField.GetPar2();
+ sal_Int32 nPos = aTrueFalse.indexOf('|');
+ OUString aTrue;
+ OUString aFalse;
+ if (nPos == -1)
+ {
+ aTrue = aTrueFalse;
+ }
+ else
+ {
+ aTrue = aTrueFalse.subView(0, nPos);
+ aFalse = aTrueFalse.subView(nPos + 1);
+ }
+ OUString aCmd = FieldString(ww::eIF) + aCond + " \"" + aTrue + "\" \"" + aFalse + "\"";
+ m_rExport.OutputField(&rField, ww::eIF, aCmd);
+ return;
+ }
+
SAL_INFO("sw.ww8", "TODO DocxAttributeOutput::HiddenField()" );
}
More information about the Libreoffice-commits
mailing list