[Libreoffice-commits] core.git: starmath/source

Frédéric Wang fred.wang at free.fr
Fri Jun 28 02:53:14 PDT 2013


 starmath/source/mathmlexport.cxx |   32 +++++++++++++++++++++++++++++++-
 starmath/source/parse.cxx        |   16 ++++++++++++----
 2 files changed, 43 insertions(+), 5 deletions(-)

New commits:
commit 4f294a90877d2f91bb88c7d6cd5b74e8e546a025
Author: Frédéric Wang <fred.wang at free.fr>
Date:   Tue Jun 25 22:33:13 2013 +0200

     fdo#66081 - reduce the number of nested <mrow>'s in MathML
    
    Change-Id: I768db4719119e53961c9cfa6a864daad7f1f7873
    Reviewed-on: https://gerrit.libreoffice.org/4520
    Reviewed-by: Fridrich Strba <fridrich at documentfoundation.org>
    Tested-by: Fridrich Strba <fridrich at documentfoundation.org>

diff --git a/starmath/source/mathmlexport.cxx b/starmath/source/mathmlexport.cxx
index e18a69e..d23662c 100644
--- a/starmath/source/mathmlexport.cxx
+++ b/starmath/source/mathmlexport.cxx
@@ -734,7 +734,37 @@ void SmXMLExport::ExportLine(const SmNode *pNode, int nLevel)
 
 void SmXMLExport::ExportBinaryHorizontal(const SmNode *pNode, int nLevel)
 {
-    ExportExpression(pNode, nLevel);
+    sal_uLong nGroup = pNode->GetToken().nGroup;
+
+    SvXMLElementExport* pRow = new SvXMLElementExport(*this,
+        XML_NAMESPACE_MATH, XML_MROW, sal_True, sal_True);
+
+    // Unfold the binary tree structure as long as the nodes are SmBinHorNode
+    // with the same nGroup. This will reduce the number of nested <mrow>
+    // elements e.g. we only need three <mrow> levels to export
+    //
+    // "a*b*c*d+e*f*g*h+i*j*k*l = a*b*c*d+e*f*g*h+i*j*k*l =
+    //  a*b*c*d+e*f*g*h+i*j*k*l = a*b*c*d+e*f*g*h+i*j*k*l"
+    //
+    // See https://www.libreoffice.org/bugzilla/show_bug.cgi?id=66081
+    ::std::stack< const SmNode* > s;
+    s.push(pNode);
+    while (!s.empty())
+    {
+        const SmNode *node = s.top();
+        s.pop();
+        if (node->GetType() != NBINHOR || node->GetToken().nGroup != nGroup)
+        {
+            ExportNodes(node, nLevel+1);
+            continue;
+        }
+        const SmBinHorNode* binNode = static_cast<const SmBinHorNode*>(node);
+        s.push(binNode->RightOperand());
+        s.push(binNode->Symbol());
+        s.push(binNode->LeftOperand());
+    }
+
+    delete pRow;
 }
 
 void SmXMLExport::ExportUnaryHorizontal(const SmNode *pNode, int nLevel)
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index cc35a66..cdb6865 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -1108,10 +1108,18 @@ void SmParser::Expression()
         RelationArray[n - 1] = lcl_popOrZero(m_aNodeStack);
     }
 
-    SmExpressionNode *pSNode = new SmExpressionNode(m_aCurToken);
-    pSNode->SetSubNodes(RelationArray);
-    pSNode->SetUseExtraSpaces(bUseExtraSpaces);
-    m_aNodeStack.push(pSNode);
+    if (n > 1)
+    {
+        SmExpressionNode *pSNode = new SmExpressionNode(m_aCurToken);
+        pSNode->SetSubNodes(RelationArray);
+        pSNode->SetUseExtraSpaces(bUseExtraSpaces);
+        m_aNodeStack.push(pSNode);
+    }
+    else
+    {
+        // This expression has only one node so just push this node.
+        m_aNodeStack.push(RelationArray[0]);
+    }
 }
 
 


More information about the Libreoffice-commits mailing list