diff options
Diffstat (limited to 'starmath/source')
-rw-r--r-- | starmath/source/mathmlexport.cxx | 32 | ||||
-rw-r--r-- | starmath/source/parse.cxx | 16 |
2 files changed, 43 insertions, 5 deletions
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 <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 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]); + } } |