diff options
author | dante <dante19031999@gmail.com> | 2020-11-03 15:12:08 +0100 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-11-05 09:07:46 +0100 |
commit | d3abe0a1fb2f2b546b164280c5562443dc1f4300 (patch) | |
tree | abf3a1d495698dbfbe04c6c5425b21f1caf7f382 /starmath | |
parent | 03ef620caff59bf624b931646b21b239171511bd (diff) |
Added frac command. Sould solve tdf#137234.
Change-Id: I78dcd06a30b93c441dd5983711603f184d20c63b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105255
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/parse.hxx | 1 | ||||
-rw-r--r-- | starmath/inc/strings.hrc | 1 | ||||
-rw-r--r-- | starmath/inc/strings.hxx | 1 | ||||
-rw-r--r-- | starmath/inc/token.hxx | 2 | ||||
-rw-r--r-- | starmath/qa/extras/mmlimport-test.cxx | 4 | ||||
-rw-r--r-- | starmath/source/ElementsDockingWindow.cxx | 1 | ||||
-rw-r--r-- | starmath/source/mathmlimport.cxx | 2 | ||||
-rw-r--r-- | starmath/source/parse.cxx | 20 | ||||
-rw-r--r-- | starmath/source/visitors.cxx | 24 |
9 files changed, 45 insertions, 11 deletions
diff --git a/starmath/inc/parse.hxx b/starmath/inc/parse.hxx index 4f1e3024ccb3..e62f855bb723 100644 --- a/starmath/inc/parse.hxx +++ b/starmath/inc/parse.hxx @@ -116,6 +116,7 @@ class SmParser std::unique_ptr<SmBracebodyNode> DoBracebody(bool bIsLeftRight); std::unique_ptr<SmTextNode> DoFunction(); std::unique_ptr<SmTableNode> DoBinom(); + std::unique_ptr<SmBinVerNode> DoFrac(); std::unique_ptr<SmStructureNode> DoStack(); std::unique_ptr<SmStructureNode> DoMatrix(); std::unique_ptr<SmSpecialNode> DoSpecial(); diff --git a/starmath/inc/strings.hrc b/starmath/inc/strings.hrc index 7cd2c73c09d7..b9377eff1081 100644 --- a/starmath/inc/strings.hrc +++ b/starmath/inc/strings.hrc @@ -35,6 +35,7 @@ #define RID_XSYMDIVIDEY_HELP NC_("RID_XSYMDIVIDEY_HELP", "Division (Slash)" ) #define RID_XDIVY_HELP NC_("RID_XDIVY_HELP", "Division (รท)" ) #define RID_XOVERY_HELP NC_("RID_XOVERY_HELP", "Division (Fraction)" ) +#define RID_FRACXY_HELP NC_("RID_FRACXY_HELP", "Fraction" ) #define RID_XODIVIDEY_HELP NC_("RID_XODIVIDEY_HELP", "Circled Slash" ) #define RID_XODOTY_HELP NC_("RID_XODOTY_HELP", "Circled Dot" ) #define RID_XOMINUSY_HELP NC_("RID_XOMINUSY_HELP", "Circled Minus" ) diff --git a/starmath/inc/strings.hxx b/starmath/inc/strings.hxx index 17de13505fdf..c38419b5638e 100644 --- a/starmath/inc/strings.hxx +++ b/starmath/inc/strings.hxx @@ -25,6 +25,7 @@ #define RID_XSYMDIVIDEY "<?> / <?> " #define RID_XDIVY "<?> div <?> " #define RID_XOVERY "{<?>} over {<?>} " +#define RID_FRACXY "frac {<?>} {<?>} " #define RID_XODIVIDEY "<?> odivide <?> " #define RID_XODOTY "<?> odot <?> " #define RID_XOMINUSY "<?> ominus <?> " diff --git a/starmath/inc/token.hxx b/starmath/inc/token.hxx index f17d527fc54c..4153b91c0caa 100644 --- a/starmath/inc/token.hxx +++ b/starmath/inc/token.hxx @@ -56,7 +56,7 @@ enum SmTokenType TEND, TSPECIAL, TNONE, TESCAPE, TUNKNOWN, TBLANK, TSBLANK, TPLACE, TNOSPACE, TDOTSDOWN, TNEWLINE, TDOTSAXIS, TDOTSLOW, TDOTSVERT, TBACKEPSILON, - TDOTSDIAG, TDOTSUP, + TDOTSDIAG, TDOTSUP, TFRAC, // Basic TPLUS, TMINUS, TMULTIPLY, TDIVIDEBY, // +-*/ TGT, TLT, TGE, TLE, // > < >= <= diff --git a/starmath/qa/extras/mmlimport-test.cxx b/starmath/qa/extras/mmlimport-test.cxx index 279dbd56e4ad..4b204787a3cb 100644 --- a/starmath/qa/extras/mmlimport-test.cxx +++ b/starmath/qa/extras/mmlimport-test.cxx @@ -148,14 +148,14 @@ void Test::testtdf99556() void Test::testTdf103430() { loadURL(m_directories.getURLFromSrc("starmath/qa/extras/data/tdf103430.mml")); - CPPUNIT_ASSERT_EQUAL(OUString("{ { nitalic d ^ 2 nitalic color blue y } over { nitalic d font sans bold italic color red x } }"), + CPPUNIT_ASSERT_EQUAL(OUString("frac { { nitalic d ^ 2 nitalic color blue y } } { { nitalic d font sans bold italic color red x } }"), mxDocShell->GetText()); } void Test::testTdf103500() { loadURL(m_directories.getURLFromSrc("starmath/qa/extras/data/tdf103500.mml")); - CPPUNIT_ASSERT_EQUAL(OUString("{ { int csup b csub a { { 1 over x } ` nitalic d x } } = { intd csup b csub a { { 1 over y } ` nitalic d y } } }"), + CPPUNIT_ASSERT_EQUAL(OUString("{ { int csup b csub a { frac { 1 } { x } ` nitalic d x } } = { intd csup b csub a { frac { 1 } { y } ` nitalic d y } } }"), mxDocShell->GetText()); } diff --git a/starmath/source/ElementsDockingWindow.cxx b/starmath/source/ElementsDockingWindow.cxx index 1e2f295c3e09..8850ca49fcbb 100644 --- a/starmath/source/ElementsDockingWindow.cxx +++ b/starmath/source/ElementsDockingWindow.cxx @@ -63,6 +63,7 @@ const SmElementDescr SmElementsControl::m_aUnaryBinaryOperatorsList[] = {RID_XPLUSY, RID_XPLUSY_HELP}, {RID_XMINUSY, RID_XMINUSY_HELP}, {RID_XCDOTY, RID_XCDOTY_HELP}, {RID_XTIMESY, RID_XTIMESY_HELP}, {RID_XSYMTIMESY, RID_XSYMTIMESY_HELP}, {RID_XOVERY, RID_XOVERY_HELP}, + {RID_FRACXY, RID_FRACXY_HELP}, {RID_XDIVY, RID_XDIVY_HELP}, {RID_XSYMDIVIDEY, RID_XSYMDIVIDEY_HELP}, {RID_XOPLUSY, RID_XOPLUSY_HELP}, {RID_XOMINUSY, RID_XOMINUSY_HELP}, {RID_XODOTY, RID_XODOTY_HELP}, {RID_XOTIMESY, RID_XOTIMESY_HELP}, diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx index 6700afaa02de..db56d3ced2da 100644 --- a/starmath/source/mathmlimport.cxx +++ b/starmath/source/mathmlimport.cxx @@ -2084,7 +2084,7 @@ void SmXMLFracContext_Impl::endFastElement(sal_Int32 ) SmToken aToken; aToken.cMathChar = '\0'; - aToken.eType = TOVER; + aToken.eType = TFRAC; std::unique_ptr<SmStructureNode> pSNode(new SmBinVerNode(aToken)); std::unique_ptr<SmNode> pOper(new SmRectangleNode(aToken)); std::unique_ptr<SmNode> pSecond = popOrZero(rNodeStack); diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx index 13898f6edc0d..598ec121611b 100644 --- a/starmath/source/parse.cxx +++ b/starmath/source/parse.cxx @@ -130,6 +130,7 @@ const SmTokenTableEntry aTokenTable[] = { "font", TFONT, '\0', TG::FontAttr, 5}, { "forall", TFORALL, MS_FORALL, TG::Standalone, 5}, { "fourier", TFOURIER, MS_FOURIER, TG::Standalone, 5}, + { "frac", TFRAC, '\0', TG::NONE, 0}, { "from", TFROM, '\0', TG::Limit, 0}, { "func", TFUNC, '\0', TG::Function, 5}, { "ge", TGE, MS_GE, TG::Relation, 0}, @@ -1745,6 +1746,9 @@ std::unique_ptr<SmNode> SmParser::DoTerm(bool bGroupNumberIdent) case TBINOM: return DoBinom(); + case TFRAC: + return DoFrac(); + case TSTACK: return DoStack(); @@ -2403,6 +2407,22 @@ std::unique_ptr<SmTableNode> SmParser::DoBinom() return xSNode; } +std::unique_ptr<SmBinVerNode> SmParser::DoFrac() +{ + DepthProtect aDepthGuard(m_nParseDepth); + if (aDepthGuard.TooDeep()) throw std::range_error("parser depth limit"); + + std::unique_ptr<SmBinVerNode> xSNode = std::make_unique<SmBinVerNode>(m_aCurToken); + std::unique_ptr<SmNode> xOper = std::make_unique<SmRectangleNode>(m_aCurToken); + + NextToken(); + + auto xFirst = DoSum(); + auto xSecond = DoSum(); + xSNode->SetSubNodes(std::move(xFirst), std::move(xOper), std::move(xSecond)); + return xSNode; +} + std::unique_ptr<SmStructureNode> SmParser::DoStack() { DepthProtect aDepthGuard(m_nParseDepth); diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx index f6e030b298d7..9b8ac0d855aa 100644 --- a/starmath/source/visitors.cxx +++ b/starmath/source/visitors.cxx @@ -2280,13 +2280,23 @@ void SmNodeToTextVisitor::Visit( SmBinHorNode* pNode ) void SmNodeToTextVisitor::Visit( SmBinVerNode* pNode ) { - SmNode *pNum = pNode->GetSubNode( 0 ), - *pDenom = pNode->GetSubNode( 2 ); - Append( "{ " ); - LineToText( pNum ); - Append( "over" ); - LineToText( pDenom ); - Append( "} " ); + if( pNode->GetToken().eType == TOVER ){ + SmNode *pNum = pNode->GetSubNode( 0 ), + *pDenom = pNode->GetSubNode( 2 ); + Append( "{ " ); + LineToText( pNum ); + Append( "over" ); + LineToText( pDenom ); + Append( "} " ); + } else{ + SmNode *pNum = pNode->GetSubNode( 0 ), + *pDenom = pNode->GetSubNode( 2 ); + Append( "frac {" ); + LineToText( pNum ); + Append( "} {" ); + LineToText( pDenom ); + Append( "}" ); + } } void SmNodeToTextVisitor::Visit( SmBinDiagonalNode* pNode ) |