oox/source/export/drawingml.cxx |   52 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 47 insertions(+), 5 deletions(-)

New commits:
commit 0f0bb6ba234c371e1c5a6420ba1e441322c9c354
Author:     Karthik Godha <[email protected]>
AuthorDate: Thu Dec 25 15:11:01 2025 +0530
Commit:     Michael Stahl <[email protected]>
CommitDate: Fri Jan 2 13:50:41 2026 +0100

    tdf#170035:Add OOXML formula check for guidelist
    
    Add condition check to skip exported of internal names/equations to
    OOXML.
    
    Change-Id: I0c03bbaa7ea61dd4f526fc0476482571df7e7cf7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196209
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 8877ab0a8914..c4747fa9ccab 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -39,6 +39,7 @@
 #include <sax/fastattribs.hxx>
 #include <comphelper/diagnose_ex.hxx>
 #include <comphelper/processfactory.hxx>
+#include <comphelper/string.hxx>
 #include <i18nlangtag/languagetag.hxx>
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
 #include <basegfx/range/b2drange.hxx>
@@ -46,6 +47,7 @@
 
 #include <numeric>
 #include <string_view>
+#include <set>
 
 #include <com/sun/star/awt/CharSet.hpp>
 #include <com/sun/star/awt/FontDescriptor.hpp>
@@ -4897,12 +4899,49 @@ void prepareTextArea(const EnhancedCustomShape2d& 
rEnhancedCustomShape2d,
     return;
 }
 
-OUString GetFormula(const OUString& sEquation, const OUString& sReplace, const 
OUString& sNewStr)
+bool IsValidOOXMLFormula(std::u16string_view sFormula)
 {
-    // 'logheight' and `logwidth` are only used for calculating shape's 
rectangle
-    if (sEquation == "logheight" || sEquation == "logwidth")
-        return OUString();
+    // Accepted Formulas
+    // "val n1"
+    // "abs n1"
+    // "sqrt n1"
+    // "min n1 n2"
+    // "max n1 n2"
+    // "*/ n1 n2 n3"
+    // "+- n1 n2 n3"
+    // "?: n1 n2 n3"
+
+    // Below vector contains validTokens for the 1st token based on the number 
of tokens in the formula. The order is: 2, 3, 4
+    const std::vector<std::set<OUString>> validTokens
+        = { { "val", "abs", "sqrt" }, { "min", "max" }, { "*/", "+-", "?:" } };
+    const std::set<OUString> builtInVariables = { "w", "h", "t", "b", "l", "r" 
};
+    const std::vector<OUString> strTokens = 
comphelper::string::split(sFormula, ' ');
+    sal_uInt16 nSize = strTokens.size();
+
+    if (nSize > 1 && nSize < 5)
+    {
+        auto aTokens = validTokens[nSize - 2];
+
+        // Check whether the 1st token is valid
+        if (aTokens.find(strTokens[0]) == aTokens.end())
+            return false;
+
+        // Check that the remaining tokens are either numbers or buit-in 
variables
+        for (sal_Int16 i = 1; i < nSize; i++)
+        {
+            OUString sVal = strTokens[i];
+            sal_Int64 nVal = sVal.toInt64();
+            if (builtInVariables.find(sVal) == builtInVariables.end()
+                && OUString::number(nVal) != sVal)
+                return false;
+        }
+        return true;
+    }
+    return false;
+}
 
+OUString GetFormula(const OUString& sEquation, const OUString& sReplace, const 
OUString& sNewStr)
+{
     OUString sFormula = sEquation;
     size_t nPos = sFormula.indexOf(sReplace);
     if (nPos != std::string::npos)
@@ -4911,7 +4950,10 @@ OUString GetFormula(const OUString& sEquation, const 
OUString& sReplace, const O
         sFormula = "*/ " + sModifiedEquation;
     }
 
-    return sFormula;
+    if (IsValidOOXMLFormula(sFormula))
+        return sFormula;
+
+    return OUString();
 }
 
 void prepareGluePoints(std::vector<Guide>& rGuideList,

Reply via email to