summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-11-13 16:26:43 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-11-16 16:26:05 +0100
commite30fa3a342e2cdff131fc3ae17acf94e9afe521e (patch)
tree118fbe1d49c1cf1d45cea4547236270e2828f144 /sw
parente1826cabdbb8f8c177f10497aec55539e523c268 (diff)
DOCX export: handle conditional fields
At least the subset where the condition syntax matches between Writer and Word. (cherry picked from commit 5d839ff8a81ade6453a239a258b2a2571e32001e) Change-Id: I107f2b4caeda6f7777696af8d5c5b455854cfa92 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105947 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/data/conditional-text.fodt8
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx13
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx24
3 files changed, 44 insertions, 1 deletions
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 &lt; 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 9d89184cde74..094a9262ace7 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
@@ -745,6 +745,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.
+ xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+ OUString 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 bce9737c7737..0e849c8142d7 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -7463,8 +7463,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.copy(0, nPos);
+ aFalse = aTrueFalse.copy(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()" );
}