diff options
-rw-r--r-- | sw/qa/extras/rtfexport/data/tdf156030.rtf | 11 | ||||
-rw-r--r-- | sw/qa/extras/rtfexport/rtfexport7.cxx | 38 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 30 |
3 files changed, 78 insertions, 1 deletions
diff --git a/sw/qa/extras/rtfexport/data/tdf156030.rtf b/sw/qa/extras/rtfexport/data/tdf156030.rtf new file mode 100644 index 000000000000..db501d5bffac --- /dev/null +++ b/sw/qa/extras/rtfexport/data/tdf156030.rtf @@ -0,0 +1,11 @@ +{\rtf1
+{\field{\*\fldinst IF 1 = 2 "true value 1" "false value 1"}}\par
+{\field{\*\fldinst IF 1 == 2 "true value 2" "false value 2"}}\par
+{\field{\*\fldinst IF 1 != 2 "true value 3" "false value 3"}}\par
+{\field{\*\fldinst IF 1 <> 2 "true value 4" "false value 4"}}\par
+{\field{\*\fldinst IF 1 > 2 "true value 5" "false value 5"}}\par
+{\field{\*\fldinst IF 1 < 2 "true value 6" "false value 6"}}\par
+{\field{\*\fldinst IF 1 1 = 1 2 1 true value 7 false value 7}}\par
+{\field{\*\fldinst IF 1 1 = "1 2 1 true value 8 fal"se "value 8}}\par
+{\field{\*\fldinst IF a}}\par
+}
diff --git a/sw/qa/extras/rtfexport/rtfexport7.cxx b/sw/qa/extras/rtfexport/rtfexport7.cxx index 11eaadee6a88..ad9249bedeb8 100644 --- a/sw/qa/extras/rtfexport/rtfexport7.cxx +++ b/sw/qa/extras/rtfexport/rtfexport7.cxx @@ -683,6 +683,44 @@ DECLARE_RTFEXPORT_TEST(testTdf113202, "tdf113202.rtf") CPPUNIT_ASSERT(getProperty<bool>(getParagraph(4), "ParaContextMargin")); } +DECLARE_RTFEXPORT_TEST(testTdf156030, "tdf156030.rtf") +{ + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess( + xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + // As usual, fields given by FieldsAccess are not in same order as in the document + std::vector<std::vector<OUString>> aExpectedValues = { + { "1 FORMULA 2", "true value 1", "false value 1" }, // #1, condition should be 1 = 2 + { "", "", "" }, // #9, not enough field params + { "1 1 FORMULA 1 2 1 true value 8 fal", "se", "value 8" }, // #8, nonsense in field params + { "1 1 FORMULA 1 2 1 true value 7 false", "value", "7" }, // #7, another parse error + { "1 < 2", "true value 6", "false value 6" }, // #6 + { "1 > 2", "true value 5", "false value 5" }, // #5 + { "1 <> 2", "true value 4", "false value 4" }, // #4 + { "1 != 2", "true value 3", "false value 3" }, // #3 + { "1 FORMULA FORMULA 2", "true value 2", "false value 2" }, // #2, condition expected 1 == 2 + }; + uno::Reference<beans::XPropertySet> xPropertySet; + OUString sValue; + + for (const auto& aValues : aExpectedValues) + { + xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xPropertySet.is()); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("Condition") >>= sValue); + CPPUNIT_ASSERT_EQUAL(aValues[0], sValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("TrueContent") >>= sValue); + CPPUNIT_ASSERT_EQUAL(aValues[1], sValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("FalseContent") >>= sValue); + CPPUNIT_ASSERT_EQUAL(aValues[2], sValue); + } + + // No more fields + CPPUNIT_ASSERT(!xFields->hasMoreElements()); +} + DECLARE_RTFEXPORT_TEST(testTdf153195, "tdf153195.rtf") { uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 491c755206b7..bf433e2b8d33 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -7447,7 +7447,35 @@ void DomainMapper_Impl::CloseFieldCommand() pContext->SetHyperlinkTarget(sTarget); } break; - case FIELD_IF : break; + case FIELD_IF: + { + if (vArguments.size() < 3) + { + SAL_WARN("writerfilter.dmapper", "IF field requires at lest 3 parameters!"); + break; + } + + if (xFieldProperties.is()) + { + // Following code assumes that last argument in field is false value + // before it - true value and everything before them is a condition + OUString sCondition; + size_t i = 0; + while (i < vArguments.size() - 2) { + if (!sCondition.isEmpty()) + sCondition += " "; + sCondition += vArguments[i++]; + } + + xFieldProperties->setPropertyValue( + "TrueContent", uno::Any(vArguments[vArguments.size() - 2])); + xFieldProperties->setPropertyValue( + "FalseContent", uno::Any(vArguments[vArguments.size() - 1])); + xFieldProperties->setPropertyValue( + "Condition", uno::Any(sCondition)); + } + } + break; case FIELD_INFO : break; case FIELD_INCLUDEPICTURE: break; case FIELD_KEYWORDS : |