sw/inc/calc.hxx                              |    4 +++-
 sw/qa/extras/ooxmlexport/data/tdf123381.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport15.cxx   |   15 +++++++++++++++
 sw/source/core/bastyp/calc.cxx               |   11 +++++++++++
 sw/uiconfig/swriter/ui/inputwinmenu.ui       |    8 ++++++++
 5 files changed, 37 insertions(+), 1 deletion(-)

New commits:
commit 27953931d4f6a8c69b98a90c63db81ebb27cdf63
Author:     Xisco Fauli <[email protected]>
AuthorDate: Fri Apr 15 22:17:01 2022 +0200
Commit:     László Németh <[email protected]>
CommitDate: Fri Apr 22 14:44:42 2022 +0200

    tdf#123381: sw: add table formula INT
    
    for DOCX interoperability.
    
    Change-Id: I4e63e213ef0a6f3a775bdf3bedfb7aca8853b479
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133091
    Tested-by: Jenkins
    Tested-by: László Németh <[email protected]>
    Reviewed-by: László Németh <[email protected]>

diff --git a/sw/inc/calc.hxx b/sw/inc/calc.hxx
index 1fabeede4dab..7acfec20fde8 100644
--- a/sw/inc/calc.hxx
+++ b/sw/inc/calc.hxx
@@ -57,7 +57,8 @@ 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_SIGN=288,          CALC_ABS=289
+    CALC_COUNT=287,         CALC_SIGN=288,          CALC_ABS=289,
+    CALC_INT=290
 };
 
 // Calculate Operations Strings
@@ -95,6 +96,7 @@ extern const char sCalc_Round[];
 extern const char sCalc_Date[];
 extern const char sCalc_Sign[];
 extern const char sCalc_Abs[];
+extern const char sCalc_Int[];
 
 //  Calculate ErrorCodes
 enum class SwCalcError
diff --git a/sw/qa/extras/ooxmlexport/data/tdf123381.docx 
b/sw/qa/extras/ooxmlexport/data/tdf123381.docx
new file mode 100644
index 000000000000..a019560d51f7
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf123381.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
index 55a6200c7c5d..38ef89997d39 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
@@ -165,6 +165,21 @@ DECLARE_OOXMLEXPORT_TEST(testTdf123388, "tdf123388.docx")
     CPPUNIT_ASSERT_EQUAL(OUString("640"), 
xEnumerationAccess1->getPresentation(false).trim());
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf123381, "tdf123381.docx")
+{
+    uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> 
xFieldsAccess(xTextFieldsSupplier->getTextFields());
+    uno::Reference<container::XEnumeration> 
xFields(xFieldsAccess->createEnumeration());
+
+    uno::Reference<text::XTextField> 
xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("INT(5.65)"), 
xEnumerationAccess1->getPresentation(true).trim());
+    CPPUNIT_ASSERT_EQUAL(OUString("5"), 
xEnumerationAccess1->getPresentation(false).trim());
+
+    uno::Reference<text::XTextField> 
xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("INT(<A1>)"), 
xEnumerationAccess2->getPresentation(true).trim());
+    CPPUNIT_ASSERT_EQUAL(OUString("6"), 
xEnumerationAccess2->getPresentation(false).trim());
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf123401, "tdf123401.fodt")
 {
     uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, 
uno::UNO_QUERY);
diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx
index 04b3e94490c7..4132cbb1869b 100644
--- a/sw/source/core/bastyp/calc.cxx
+++ b/sw/source/core/bastyp/calc.cxx
@@ -88,6 +88,7 @@ const char sCalc_Average[] = "average";
 const char sCalc_Count[]=   "count";
 const char sCalc_Sign[] =   "sign";
 const char sCalc_Abs[]  =   "abs";
+const char sCalc_Int[]  =   "int";
 
 // ATTENTION: sorted list of all operators
 struct CalcOp
@@ -114,6 +115,7 @@ CalcOp const aOpTable[] = {
 /* EQ */      {{sCalc_Eq},         CALC_EQ},    // Equality
 /* G */       {{sCalc_G},          CALC_GRE},   // Greater than
 /* GEQ */     {{sCalc_Geq},        CALC_GEQ},   // Greater or equal
+/* INT */     {{sCalc_Int},        CALC_INT},   // Int (since LibreOffice 7.4)
 /* L */       {{sCalc_L},          CALC_LES},   // Less than
 /* LEQ */     {{sCalc_Leq},        CALC_LEQ},   // Less or equal
 /* MAX */     {{sCalc_Max},        CALC_MAX},   // Maximum value
@@ -1084,6 +1086,15 @@ SwSbxValue SwCalc::PrimFunc(bool &rChkPow)
             nErg.PutDouble( int(0 < nVal) - int(nVal < 0) );
             return nErg;
         }
+        case CALC_INT:
+        {
+            SAL_INFO("sw.calc", "int");
+            SwSbxValue nErg;
+            GetToken();
+            sal_Int32 nVal = static_cast<sal_Int32>( Prim().GetDouble() );
+            nErg.PutDouble( nVal );
+            return nErg;
+        }
         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 f06f67f82cf5..ad1506964ecc 100644
--- a/sw/uiconfig/swriter/ui/inputwinmenu.ui
+++ b/sw/uiconfig/swriter/ui/inputwinmenu.ui
@@ -422,6 +422,14 @@
                 <property name="use_underline">True</property>
               </object>
             </child>
+            <child>
+              <object class="GtkMenuItem" id="int">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes" 
context="inputwinmenu|int">Int</property>
+                <property name="use_underline">True</property>
+              </object>
+            </child>
           </object>
         </child>
         <child internal-child="accessible">

Reply via email to