From 4f294a90877d2f91bb88c7d6cd5b74e8e546a025 Mon Sep 17 00:00:00 2001 From: Frédéric Wang Date: Tue, 25 Jun 2013 22:33:13 +0200 Subject: fdo#66081 - reduce the number of nested 's in MathML Change-Id: I768db4719119e53961c9cfa6a864daad7f1f7873 Reviewed-on: https://gerrit.libreoffice.org/4520 Reviewed-by: Fridrich Strba Tested-by: Fridrich Strba --- starmath/source/mathmlexport.cxx | 32 +++++++++++++++++++++++++++++++- starmath/source/parse.cxx | 16 ++++++++++++---- 2 files changed, 43 insertions(+), 5 deletions(-) (limited to 'starmath') diff --git a/starmath/source/mathmlexport.cxx b/starmath/source/mathmlexport.cxx index e18a69ec78cf..d23662c47065 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 + // elements e.g. we only need three 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(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 cc35a6698775..cdb6865db623 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]); + } } -- cgit