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

Takeshi Abe tabe at fixedpoint.jp
Thu Apr 27 00:35:45 UTC 2017


 starmath/inc/node.hxx            |    7 ++++++-
 starmath/source/cursor.cxx       |    6 +++---
 starmath/source/mathmlexport.cxx |    4 ++--
 starmath/source/mathmlimport.cxx |   18 +++++++++---------
 starmath/source/node.cxx         |   18 +++++++++---------
 starmath/source/parse.cxx        |   14 +++++++-------
 starmath/source/visitors.cxx     |    4 ++--
 7 files changed, 38 insertions(+), 33 deletions(-)

New commits:
commit 437105b940d997d742bd5e31cfa0ce4b949b29f2
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Wed Apr 26 18:27:43 2017 +0900

    starmath: Convert SmScaleMode to scoped enum
    
    Change-Id: I88024e9cc1147cc44a087315968c3462ab5baf73
    Reviewed-on: https://gerrit.libreoffice.org/36978
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Takeshi Abe <tabe at fixedpoint.jp>

diff --git a/starmath/inc/node.hxx b/starmath/inc/node.hxx
index 52487fcef0ae..dd0a4c663216 100644
--- a/starmath/inc/node.hxx
+++ b/starmath/inc/node.hxx
@@ -77,7 +77,12 @@ class SmStructureNode;
 
 typedef std::vector< SmNode * > SmNodeArray;
 
-enum SmScaleMode    { SCALE_NONE, SCALE_WIDTH, SCALE_HEIGHT };
+enum class SmScaleMode
+{
+    None,
+    Width,
+    Height
+};
 
 enum class SmNodeType
 {
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index e09496260329..c4c798452406 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -694,7 +694,7 @@ void SmCursor::InsertBrackets(SmBracketType eBracketType) {
     //Create SmBraceNode
     SmToken aTok(TLEFT, '\0', "left", TG::NONE, 5);
     SmBraceNode *pBrace = new SmBraceNode(aTok);
-    pBrace->SetScaleMode(SCALE_HEIGHT);
+    pBrace->SetScaleMode(SmScaleMode::Height);
     SmNode *pLeft = CreateBracket(eBracketType, true),
            *pRight = CreateBracket(eBracketType, false);
     SmBracebodyNode *pBody = new SmBracebodyNode(SmToken());
@@ -741,7 +741,7 @@ SmNode *SmCursor::CreateBracket(SmBracketType eBracketType, bool bIsLeft) {
         }
     }
     SmNode* pRetVal = new SmMathSymbolNode(aTok);
-    pRetVal->SetScaleMode(SCALE_HEIGHT);
+    pRetVal->SetScaleMode(SmScaleMode::Height);
     return pRetVal;
 }
 
@@ -1317,7 +1317,7 @@ void SmCursor::FinishEdit(SmNodeList* pLineList,
         //Wrap pLine in scalable round brackets
         SmToken aTok(TLEFT, '\0', "left", TG::NONE, 5);
         SmBraceNode *pBrace = new SmBraceNode(aTok);
-        pBrace->SetScaleMode(SCALE_HEIGHT);
+        pBrace->SetScaleMode(SmScaleMode::Height);
         SmNode *pLeft  = CreateBracket(SmBracketType::Round, true),
                *pRight = CreateBracket(SmBracketType::Round, false);
         SmBracebodyNode *pBody = new SmBracebodyNode(SmToken());
diff --git a/starmath/source/mathmlexport.cxx b/starmath/source/mathmlexport.cxx
index 9bc174abe026..69546741e792 100644
--- a/starmath/source/mathmlexport.cxx
+++ b/starmath/source/mathmlexport.cxx
@@ -1052,7 +1052,7 @@ void SmXMLExport::ExportBrace(const SmNode *pNode, int nLevel)
     if (pLeft && (pLeft->GetToken().eType != TNONE))
     {
         AddAttribute(XML_NAMESPACE_MATH, XML_FENCE, XML_TRUE);
-        if (pNode->GetScaleMode() == SCALE_HEIGHT)
+        if (pNode->GetScaleMode() == SmScaleMode::Height)
             AddAttribute(XML_NAMESPACE_MATH, XML_STRETCHY, XML_TRUE);
         else
             AddAttribute(XML_NAMESPACE_MATH, XML_STRETCHY, XML_FALSE);
@@ -1072,7 +1072,7 @@ void SmXMLExport::ExportBrace(const SmNode *pNode, int nLevel)
     if (pRight && (pRight->GetToken().eType != TNONE))
     {
         AddAttribute(XML_NAMESPACE_MATH, XML_FENCE, XML_TRUE);
-        if (pNode->GetScaleMode() == SCALE_HEIGHT)
+        if (pNode->GetScaleMode() == SmScaleMode::Height)
             AddAttribute(XML_NAMESPACE_MATH, XML_STRETCHY, XML_TRUE);
         else
             AddAttribute(XML_NAMESPACE_MATH, XML_STRETCHY, XML_FALSE);
diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx
index 96c2aa05ae70..583c0b925821 100644
--- a/starmath/source/mathmlimport.cxx
+++ b/starmath/source/mathmlimport.cxx
@@ -1160,7 +1160,7 @@ void SmXMLFencedContext_Impl::EndElement()
 
 
     pSNode->SetSubNodes(pLeft,pBody,pRight);
-    pSNode->SetScaleMode(SCALE_HEIGHT);
+    pSNode->SetScaleMode(SmScaleMode::Height);
     GetSmImport().GetNodeStack().push_front(std::move(pSNode));
 }
 
@@ -1438,7 +1438,7 @@ void SmXMLOperatorContext_Impl::EndElement()
     //and applied to the expression itself so as to get the expression
     //to scale the operator to the height of the expression itself
     if (bIsStretchy)
-        pNode->SetScaleMode(SCALE_HEIGHT);
+        pNode->SetScaleMode(SmScaleMode::Height);
     GetSmImport().GetNodeStack().push_front(std::move(pNode));
 
     // TODO: apply to non-alphabetic characters too
@@ -1716,7 +1716,7 @@ void SmXMLUnderContext_Impl::HandleAccent()
 
     SmNode *pSecond = popOrZero(rNodeStack);
     pNode->SetSubNodes(pFirst, pSecond);
-    pNode->SetScaleMode(SCALE_WIDTH);
+    pNode->SetScaleMode(SmScaleMode::Width);
     rNodeStack.push_front(std::move(pNode));
 }
 
@@ -1779,7 +1779,7 @@ void SmXMLOverContext_Impl::HandleAccent()
     SmNode *pFirst = popOrZero(rNodeStack);
     SmNode *pSecond = popOrZero(rNodeStack);
     pNode->SetSubNodes(pFirst, pSecond);
-    pNode->SetScaleMode(SCALE_WIDTH);
+    pNode->SetScaleMode(SmScaleMode::Width);
     rNodeStack.push_front(std::move(pNode));
 
 }
@@ -2410,9 +2410,9 @@ void SmXMLRowContext_Impl::EndElement()
         //removing the stretchness from the operators and applying it to
         //ourselves, and creating the appropriate dummy StarMath none bracket
         //to balance the arrangement
-        if (((aRelationArray[0]->GetScaleMode() == SCALE_HEIGHT)
+        if (((aRelationArray[0]->GetScaleMode() == SmScaleMode::Height)
             && (aRelationArray[0]->GetType() == SmNodeType::Math))
-        || ((aRelationArray[nSize-1]->GetScaleMode() == SCALE_HEIGHT)
+        || ((aRelationArray[nSize-1]->GetScaleMode() == SmScaleMode::Height)
             && (aRelationArray[nSize-1]->GetType() == SmNodeType::Math)))
         {
             SmToken aToken;
@@ -2420,7 +2420,7 @@ void SmXMLRowContext_Impl::EndElement()
             aToken.nLevel = 5;
 
             int nLeft=0,nRight=0;
-            if ((aRelationArray[0]->GetScaleMode() == SCALE_HEIGHT)
+            if ((aRelationArray[0]->GetScaleMode() == SmScaleMode::Height)
                 && (aRelationArray[0]->GetType() == SmNodeType::Math))
             {
                 aToken = aRelationArray[0]->GetToken();
@@ -2432,7 +2432,7 @@ void SmXMLRowContext_Impl::EndElement()
             aToken.eType = TLPARENT;
             SmNode *pLeft = new SmMathSymbolNode(aToken);
 
-            if ((aRelationArray[nSize-1]->GetScaleMode() == SCALE_HEIGHT)
+            if ((aRelationArray[nSize-1]->GetScaleMode() == SmScaleMode::Height)
                 && (aRelationArray[nSize-1]->GetType() == SmNodeType::Math))
             {
                 aToken = aRelationArray[nSize-1]->GetToken();
@@ -2461,7 +2461,7 @@ void SmXMLRowContext_Impl::EndElement()
             pBody->SetSubNodes(aRelationArray2);
 
             pSNode->SetSubNodes(pLeft,pBody,pRight);
-            pSNode->SetScaleMode(SCALE_HEIGHT);
+            pSNode->SetScaleMode(SmScaleMode::Height);
             rNodeStack.push_front(std::move(pSNode));
             return;
         }
diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx
index 8cf71b772232..2907ca4bd5b1 100644
--- a/starmath/source/node.cxx
+++ b/starmath/source/node.cxx
@@ -58,7 +58,7 @@ void ForEachNonNull(SmNode *pNode, F && f)
 SmNode::SmNode(SmNodeType eNodeType, const SmToken &rNodeToken)
     : maNodeToken( rNodeToken )
     , meType( eNodeType )
-    , meScaleMode( SCALE_NONE )
+    , meScaleMode( SmScaleMode::None )
     , meRectHorAlign( RectHorAlign::Left )
     , mnFlags( FontChangeMask::None )
     , mnAttributes( FontAttribute::None )
@@ -1293,7 +1293,7 @@ void SmSubSupNode::CreateTextFromNode(OUString &rText)
 
 void SmBraceNode::CreateTextFromNode(OUString &rText)
 {
-    if (GetScaleMode() == SCALE_HEIGHT)
+    if (GetScaleMode() == SmScaleMode::Height)
         rText += "left ";
     {
         OUString aStr;
@@ -1316,7 +1316,7 @@ void SmBraceNode::CreateTextFromNode(OUString &rText)
             rText += "none ";
     }
     Body()->CreateTextFromNode(rText);
-    if (GetScaleMode() == SCALE_HEIGHT)
+    if (GetScaleMode() == SmScaleMode::Height)
         rText += "right ";
     {
         OUString aStr;
@@ -1355,7 +1355,7 @@ void SmBraceNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
 
     bool  bIsScaleNormal = rFormat.IsScaleNormalBrackets(),
           bScale         = pBody->GetHeight() > 0  &&
-                           (GetScaleMode() == SCALE_HEIGHT  ||  bIsScaleNormal),
+                           (GetScaleMode() == SmScaleMode::Height  ||  bIsScaleNormal),
           bIsABS         = GetToken().eType == TABS;
 
     long  nFaceHeight = GetFont().GetFontSize().Height();
@@ -1364,7 +1364,7 @@ void SmBraceNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
     sal_uInt16  nPerc = 0;
     if (!bIsABS && bScale)
     {   // in case of oversize braces...
-        sal_uInt16 nIndex = GetScaleMode() == SCALE_HEIGHT ?
+        sal_uInt16 nIndex = GetScaleMode() == SmScaleMode::Height ?
                             DIS_BRACKETSIZE : DIS_NORMALBRACKETSIZE;
         nPerc = rFormat.GetDistance(nIndex);
     }
@@ -1459,9 +1459,9 @@ void SmBracebodyNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
     mnBodyHeight = aRefRect.GetHeight();
 
     // scale separators to required height and arrange them
-    bool bScale  = GetScaleMode() == SCALE_HEIGHT  ||  rFormat.IsScaleNormalBrackets();
+    bool bScale  = GetScaleMode() == SmScaleMode::Height  ||  rFormat.IsScaleNormalBrackets();
     long nHeight = bScale ? aRefRect.GetHeight() : GetFont().GetFontSize().Height();
-    sal_uInt16 nIndex  = GetScaleMode() == SCALE_HEIGHT ?
+    sal_uInt16 nIndex  = GetScaleMode() == SmScaleMode::Height ?
                         DIS_BRACKETSIZE : DIS_NORMALBRACKETSIZE;
     sal_uInt16 nPerc   = rFormat.GetDistance(nIndex);
     if (bScale)
@@ -1681,7 +1681,7 @@ void SmAttributNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
 
     pBody->Arrange(rDev, rFormat);
 
-    if (GetScaleMode() == SCALE_WIDTH)
+    if (GetScaleMode() == SmScaleMode::Width)
         pAttr->AdaptToX(rDev, pBody->GetItalicWidth());
     pAttr->Arrange(rDev, rFormat);
 
@@ -2450,7 +2450,7 @@ void SmMathSymbolNode::CreateTextFromNode(OUString &rText)
 {
     OUString sStr;
     sal_Unicode cChar = GetToken().cMathChar;
-    if (cChar == MS_INT && GetScaleMode() == SCALE_HEIGHT)
+    if (cChar == MS_INT && GetScaleMode() == SmScaleMode::Height)
         sStr = "intd ";
     else
         MathType::LookupChar(cChar, sStr, 3);
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index 836e8c682000..9941d97c9cfa 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -1617,7 +1617,7 @@ SmStructureNode *SmParser::DoUnOper()
     if (eType == TABS)
     {
         pSNode.reset(new SmBraceNode(aNodeToken));
-        pSNode->SetScaleMode(SCALE_HEIGHT);
+        pSNode->SetScaleMode(SmScaleMode::Height);
 
         // build nodes for left & right lines
         // (text, group, level of the used token are of no interest here)
@@ -1656,7 +1656,7 @@ SmAttributNode *SmParser::DoAttribut()
 
     auto pSNode = o3tl::make_unique<SmAttributNode>(m_aCurToken);
     SmNode      *pAttr;
-    SmScaleMode  eScaleMode = SCALE_NONE;
+    SmScaleMode  eScaleMode = SmScaleMode::None;
 
     // get appropriate node for the attribute itself
     switch (m_aCurToken.eType)
@@ -1664,14 +1664,14 @@ SmAttributNode *SmParser::DoAttribut()
         case TOVERLINE :
         case TOVERSTRIKE :
             pAttr = new SmRectangleNode(m_aCurToken);
-            eScaleMode = SCALE_WIDTH;
+            eScaleMode = SmScaleMode::Width;
             break;
 
         case TWIDEVEC :
         case TWIDEHAT :
         case TWIDETILDE :
             pAttr = new SmMathSymbolNode(m_aCurToken);
-            eScaleMode = SCALE_WIDTH;
+            eScaleMode = SmScaleMode::Width;
             break;
 
         default :
@@ -1849,13 +1849,13 @@ SmStructureNode *SmParser::DoBrace()
 
     std::unique_ptr<SmStructureNode> pSNode(new SmBraceNode(m_aCurToken));
     std::unique_ptr<SmNode> pBody, pLeft, pRight;
-    SmScaleMode   eScaleMode = SCALE_NONE;
+    SmScaleMode   eScaleMode = SmScaleMode::None;
     SmParseError  eError     = SmParseError::None;
 
     if (m_aCurToken.eType == TLEFT)
     {   NextToken();
 
-        eScaleMode = SCALE_HEIGHT;
+        eScaleMode = SmScaleMode::Height;
 
         // check for left bracket
         if (TokenInGroup(TG::LBrace) || TokenInGroup(TG::RBrace))
@@ -1968,7 +1968,7 @@ SmBracebodyNode *SmParser::DoBracebody(bool bIsLeftRight)
     }
 
     pBody->SetSubNodes(aNodes);
-    pBody->SetScaleMode(bIsLeftRight ? SCALE_HEIGHT : SCALE_NONE);
+    pBody->SetScaleMode(bIsLeftRight ? SmScaleMode::Height : SmScaleMode::None);
     return pBody.release();
 }
 
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index 0174b53a486d..93d935a099ab 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -1975,13 +1975,13 @@ void SmNodeToTextVisitor::Visit( SmBraceNode* pNode )
         Append( "abs" );
         LineToText( pBody );
     } else {
-        if( pNode->GetScaleMode( ) == SCALE_HEIGHT )
+        if( pNode->GetScaleMode( ) == SmScaleMode::Height )
             Append( "left " );
         pLeftBrace->Accept( this );
         Separate( );
         pBody->Accept( this );
         Separate( );
-        if( pNode->GetScaleMode( ) == SCALE_HEIGHT )
+        if( pNode->GetScaleMode( ) == SmScaleMode::Height )
             Append( "right " );
         pRightBrace->Accept( this );
     }


More information about the Libreoffice-commits mailing list