summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Wang <fred.wang@free.fr>2013-06-25 22:33:13 +0200
committerFridrich Strba <fridrich@documentfoundation.org>2013-06-28 09:52:55 +0000
commit4f294a90877d2f91bb88c7d6cd5b74e8e546a025 (patch)
treea127136041d85090122e24fdf3332dd2a2339026
parent16a0d06f900027401716ddaba25e5c8998562b2d (diff)
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@documentfoundation.org> Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
-rw-r--r--starmath/source/mathmlexport.cxx32
-rw-r--r--starmath/source/parse.cxx16
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]);
+ }
}