diff options
author | László Németh <nemeth@numbertext.org> | 2020-08-26 12:41:02 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-08-27 09:18:30 +0200 |
commit | 305c8993788b32685a1e6bfc8999fd8a43fcfdaf (patch) | |
tree | 88cdd7feb1267283dd2c0fdf9b4ebf623ee58854 | |
parent | a2b48254e4ce731edcdbd2f3fa9f6720ae676ae8 (diff) |
tdf#123390 sw: add table formula SIGN
for DOCX interoperability.
See also commit 4d9b72d1c3929eca04c7a2e363ab6214676b0f64
(tdf#123390 DOCX import: fix SIGN formula).
Change-Id: I60896e2bf8fb96b8a71d426d50fdea3d212854b8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101398
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | sw/inc/calc.hxx | 3 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf123390.fodt | 40 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport15.cxx | 20 | ||||
-rw-r--r-- | sw/source/core/bastyp/calc.cxx | 12 | ||||
-rw-r--r-- | sw/uiconfig/swriter/ui/inputwinmenu.ui | 8 |
5 files changed, 82 insertions, 1 deletions
diff --git a/sw/inc/calc.hxx b/sw/inc/calc.hxx index e2b2677a1503..41b3cd0a8cec 100644 --- a/sw/inc/calc.hxx +++ b/sw/inc/calc.hxx @@ -55,7 +55,7 @@ enum SwCalcOper CALC_ACOS=278, CALC_ATAN=279, CALC_TDIF=280, CALC_ROUND=281, CALC_DATE=282, CALC_MONTH=283, CALC_DAY=284, CALC_PRODUCT=285, CALC_AVERAGE=286, - CALC_COUNT=287 + CALC_COUNT=287, CALC_SIGN=288 }; // Calculate Operations Strings @@ -91,6 +91,7 @@ extern const char sCalc_Acos[]; extern const char sCalc_Atan[]; extern const char sCalc_Round[]; extern const char sCalc_Date[]; +extern const char sCalc_Sign[]; // Calculate ErrorCodes enum class SwCalcError diff --git a/sw/qa/extras/ooxmlexport/data/tdf123390.fodt b/sw/qa/extras/ooxmlexport/data/tdf123390.fodt new file mode 100644 index 000000000000..6512425bda2c --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf123390.fodt @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:ooow="http://openoffice.org/2004/writer" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:styles> + <style:style style:name="Standard" style:family="paragraph" style:class="text"/> + <style:default-style style:family="paragraph"> + <style:text-properties fo:language="en" fo:country="US"/> + </style:default-style> + </office:styles> + <office:body> + <office:text> + <table:table> + <table:table-column/> + <table:table-column/> + <table:table-column/> + <table:table-row> + <table:table-cell office:value-type="string"> + <text:p>-10</text:p> + </table:table-cell> + <table:table-cell office:value-type="string"> + <text:p>0</text:p> + </table:table-cell> + <table:table-cell office:value-type="string"> + <text:p>10</text:p> + </table:table-cell> + </table:table-row> + <table:table-row> + <table:table-cell table:formula="ooow:SIGN(<A1>)" office:value-type="float" office:value="-1"> + <text:p>-1</text:p> + </table:table-cell> + <table:table-cell table:formula="ooow:SIGN(<B1>)" office:value-type="float" office:value="1"> + <text:p>0</text:p> + </table:table-cell> + <table:table-cell table:formula="ooow:SIGN(<C1>)" office:value-type="float" office:value="1"> + <text:p>1</text:p> + </table:table-cell> + </table:table-row> + </table:table> + </office:text> + </office:body> +</office:document> diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx index ae3e174ca911..6df8475aaa26 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx @@ -139,6 +139,26 @@ DECLARE_OOXMLEXPORT_TEST(testTdf123356, "tdf123356.fodt") CPPUNIT_ASSERT_EQUAL(OUString("4"), xEnumerationAccess2->getPresentation(false).trim()); } +DECLARE_OOXMLEXPORT_TEST(testTdf123390, "tdf123390.fodt") +{ + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + // Tests new cell formula SIGN + uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SIGN(<A1>)"), xEnumerationAccess1->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("-1"), xEnumerationAccess1->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SIGN(<C1>)"), xEnumerationAccess2->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess2->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SIGN(<B1>)"), xEnumerationAccess3->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("0"), xEnumerationAccess3->getPresentation(false).trim()); +} + DECLARE_OOXMLEXPORT_TEST(testTdf98000_changePageStyle, "tdf98000_changePageStyle.odt") { uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx index 9e206144e13e..3750aead867c 100644 --- a/sw/source/core/bastyp/calc.cxx +++ b/sw/source/core/bastyp/calc.cxx @@ -86,6 +86,7 @@ const char sCalc_Date[] = "date"; const char sCalc_Product[] = "product"; const char sCalc_Average[] = "average"; const char sCalc_Count[]= "count"; +const char sCalc_Sign[]= "sign"; // ATTENTION: sorted list of all operators struct CalcOp @@ -124,6 +125,7 @@ CalcOp const aOpTable[] = { /* POW */ {{sCalc_Pow}, CALC_POW}, // Exponentiation /* PRODUCT */ {{sCalc_Product}, CALC_PRODUCT}, // Product (since LibreOffice 7.1) /* ROUND */ {{sCalc_Round}, CALC_ROUND}, // Rounding +/* SIGN */ {{sCalc_Sign}, CALC_SIGN}, // Sign (since LibreOffice 7.1) /* SIN */ {{sCalc_Sin}, CALC_SIN}, // Sine /* SQRT */ {{sCalc_Sqrt}, CALC_SQRT}, // Square root /* SUB */ {{sCalc_Sub}, CALC_MINUS}, // Subtraction @@ -1070,6 +1072,16 @@ SwSbxValue SwCalc::PrimFunc(bool &rChkPow) SAL_INFO("sw.calc", "acos"); return StdFunc(&acos, true); break; + case CALC_SIGN: + { + SAL_INFO("sw.calc", "sign"); + SwSbxValue nErg; + GetToken(); + double nVal = Prim().GetDouble(); + nErg.PutDouble( int(0 < nVal) - int(nVal < 0) ); + return nErg; + break; + } case CALC_NOT: { SAL_INFO("sw.calc", "not"); diff --git a/sw/uiconfig/swriter/ui/inputwinmenu.ui b/sw/uiconfig/swriter/ui/inputwinmenu.ui index 5edaeefec5fa..947e78697c77 100644 --- a/sw/uiconfig/swriter/ui/inputwinmenu.ui +++ b/sw/uiconfig/swriter/ui/inputwinmenu.ui @@ -265,6 +265,14 @@ <property name="use_underline">True</property> </object> </child> + <child> + <object class="GtkMenuItem" id="sign"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes" context="inputwinmenu|sign">Sign</property> + <property name="use_underline">True</property> + </object> + </child> </object> </child> </object> |