diff --git a/sw/qa/extras/ooxmlexport/data/tdf123354.docx b/sw/qa/extras/ooxmlexport/data/tdf123354.docx new file mode 100644 index 000000000000..15c7663c645c Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf123354.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx index 85e7097093d0..cd3dc8021f2a 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx @@ -16,6 +16,8 @@ #include #include #include +#include +#include char const DATA_DIRECTORY[] = "/sw/qa/extras/ooxmlexport/data/"; @@ -69,6 +71,26 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf118701, "tdf118701.docx") assertXPath(pXmlDoc, "/w:document/w:body/w:p[10]/w:pPr[1]/w:numPr", 1); } +DECLARE_OOXMLEXPORT_TEST(testTdf123354, "tdf123354.docx") +{ + // Tests cell formula ABS(x) to SQRT(x POW 2) conversion + uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + + uno::Reference xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SQRT((-234) POW 2)"), xEnumerationAccess1->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("234"), xEnumerationAccess1->getPresentation(false).trim()); + + uno::Reference xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SQRT((SUM()-SUM()*2) POW 2)"), xEnumerationAccess2->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("700035"), xEnumerationAccess2->getPresentation(false).trim()); + + uno::Reference xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SQRT(() POW 2)"), xEnumerationAccess3->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("233423"), xEnumerationAccess3->getPresentation(false).trim()); +} + DECLARE_OOXMLEXPORT_TEST(testTdf98000_changePageStyle, "tdf98000_changePageStyle.odt") { uno::Reference xModel(mxComponent, uno::UNO_QUERY); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 1d23295fd759..333f1170ea09 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -4259,9 +4259,13 @@ OUString DomainMapper_Impl::convertFieldFormula(const OUString& input) { usInput = rmatch4.replaceAll(icu::UnicodeString("<$1:$2>"), status); /* Fix up user defined names */ - icu::RegexMatcher rmatch5("DEFINED\\s*\\(<([A-Z]+[0-9]+)>\\)", usInput, rMatcherFlags, status); + icu::RegexMatcher rmatch5("\\bDEFINED\\s*\\(<([A-Z]+[0-9]+)>\\)", usInput, rMatcherFlags, status); usInput = rmatch5.replaceAll(icu::UnicodeString("DEFINED($1)"), status); + /* Fix up ABS(x) using SQRT(x POW 2) - it supports only 1-level nesting */ + icu::RegexMatcher rmatch6("\\bABS\\s*(\\(([^()]*|([^()])*\\([^()]*\\)[^()]*)*\\))", usInput, rMatcherFlags, status); + usInput = rmatch6.replaceAll(icu::UnicodeString("SQRT($1 POW 2)"), status); + return OUString(usInput.getTerminatedBuffer()); } @@ -4286,6 +4290,10 @@ void DomainMapper_Impl::handleFieldFormula // we don't copy the = symbol from the command OUString formula = convertFieldFormula(command.copy(1)); + xFieldProperties->setPropertyValue(getPropertyName(PROP_CONTENT), uno::makeAny(formula)); + xFieldProperties->setPropertyValue(getPropertyName(PROP_NUMBER_FORMAT), uno::makeAny(sal_Int32(0))); + xFieldProperties->setPropertyValue("IsShowFormula", uno::makeAny(false)); + // grab-bag the original and converted formula if (getTableManager().isInTable()) { @@ -4294,9 +4302,6 @@ void DomainMapper_Impl::handleFieldFormula pPropMap->Insert(PROP_CELL_FORMULA_CONVERTED, uno::makeAny(formula), true, CELL_GRAB_BAG); getTableManager().cellProps(pPropMap); } - xFieldProperties->setPropertyValue(getPropertyName(PROP_CONTENT), uno::makeAny(formula)); - xFieldProperties->setPropertyValue(getPropertyName(PROP_NUMBER_FORMAT), uno::makeAny(sal_Int32(0))); - xFieldProperties->setPropertyValue("IsShowFormula", uno::makeAny(false)); } void DomainMapper_Impl::handleRubyEQField( const FieldContextPtr& pContext)