[Libreoffice-commits] core.git: starmath/inc starmath/source
Takeshi Abe
tabe at fixedpoint.jp
Wed Jan 27 07:48:33 PST 2016
starmath/inc/rect.hxx | 12 ++++++-----
starmath/source/node.cxx | 48 +++++++++++++++++++++++------------------------
starmath/source/rect.cxx | 23 ++++++++++------------
3 files changed, 42 insertions(+), 41 deletions(-)
New commits:
commit 1e4433bf52f0b242b769d8d34e02ff5610d75839
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date: Mon Jan 25 17:36:14 2016 +0900
starmath: Convert RectPos to scoped enum
Change-Id: I726ae06b1a9bef4feec77cbd9171b8b9353a0267
Reviewed-on: https://gerrit.libreoffice.org/21766
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Michael Stahl <mstahl at redhat.com>
diff --git a/starmath/inc/rect.hxx b/starmath/inc/rect.hxx
index 2058e0d..c7dcaf0 100644
--- a/starmath/inc/rect.hxx
+++ b/starmath/inc/rect.hxx
@@ -52,11 +52,13 @@ inline long SmFromTo(long nFrom, long nTo, double fRelDist)
// possible positions and alignments for the 'AlignTo' function
-enum RectPos
- // (RP_LEFT : align the current object to the left of the argument, ...)
-{ RP_LEFT, RP_RIGHT,
- RP_TOP, RP_BOTTOM,
- RP_ATTRIBUT
+enum class RectPos
+{
+ Left, // align the current object to the left of the argument
+ Right,
+ Top,
+ Bottom,
+ Attribute
};
enum RectHorAlign
{ RHA_LEFT, RHA_CENTER, RHA_RIGHT
diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx
index 518db56..d7a1592 100644
--- a/starmath/source/node.cxx
+++ b/starmath/source/node.cxx
@@ -710,7 +710,7 @@ void SmTableNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
const SmNode *pCoNode = pNode->GetLeftMost();
RectHorAlign eHorAlign = pCoNode->GetRectHorAlign();
- aPos = rNodeRect.AlignTo(*this, RP_BOTTOM,
+ aPos = rNodeRect.AlignTo(*this, RectPos::Bottom,
eHorAlign, RVA_BASELINE);
if (i)
aPos.Y() += nDist;
@@ -806,7 +806,7 @@ void SmLineNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
for (i = 1; i < nSize; i++)
if (nullptr != (pNode = GetSubNode(i)))
{
- aPos = pNode->AlignTo(*this, RP_RIGHT, RHA_CENTER, RVA_BASELINE);
+ aPos = pNode->AlignTo(*this, RectPos::Right, RHA_CENTER, RVA_BASELINE);
// add horizontal space to the left for each but the first sub node
aPos.X() += nDist;
@@ -848,7 +848,7 @@ void SmUnHorNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
pOper->Arrange(rDev, rFormat);
pBody->Arrange(rDev, rFormat);
- Point aPos = pOper->AlignTo(*pBody, bIsPostfix ? RP_RIGHT : RP_LEFT,
+ Point aPos = pOper->AlignTo(*pBody, bIsPostfix ? RectPos::Right : RectPos::Left,
RHA_CENTER, RVA_BASELINE);
// add a bit space between operator and argument
// (worst case -{1 over 2} where - and over have almost no space inbetween)
@@ -934,7 +934,7 @@ void SmRootNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
pRootSym->Arrange(rDev, rFormat);
- Point aPos = pRootSym->AlignTo(*pBody, RP_LEFT, RHA_CENTER, RVA_BASELINE);
+ Point aPos = pRootSym->AlignTo(*pBody, RectPos::Left, RHA_CENTER, RVA_BASELINE);
//! override calculated vertical position
aPos.Y() = pRootSym->GetTop() + pBody->GetBottom() - pRootSym->GetBottom();
aPos.Y() -= nVerOffset;
@@ -992,7 +992,7 @@ void SmDynIntegralNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
pDynIntegralSym->Arrange(rDev, rFormat);
- Point aPos = pDynIntegralSym->AlignTo(*pBody, RP_LEFT, RHA_CENTER, RVA_BASELINE);
+ Point aPos = pDynIntegralSym->AlignTo(*pBody, RectPos::Left, RHA_CENTER, RVA_BASELINE);
//! override calculated vertical position
aPos.Y() = pDynIntegralSym->GetTop() + pBody->GetBottom() - pDynIntegralSym->GetBottom();
pDynIntegralSym->MoveTo(aPos);
@@ -1049,12 +1049,12 @@ void SmBinHorNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
SmRect::operator = (*pLeft);
Point aPos;
- aPos = pOper->AlignTo(*this, RP_RIGHT, RHA_CENTER, RVA_BASELINE);
+ aPos = pOper->AlignTo(*this, RectPos::Right, RHA_CENTER, RVA_BASELINE);
aPos.X() += nDist;
pOper->MoveTo(aPos);
ExtendBy(*pOper, RCP_XOR);
- aPos = pRight->AlignTo(*this, RP_RIGHT, RHA_CENTER, RVA_BASELINE);
+ aPos = pRight->AlignTo(*this, RectPos::Right, RHA_CENTER, RVA_BASELINE);
aPos.X() += nDist;
pRight->MoveTo(aPos);
@@ -1105,7 +1105,7 @@ void SmBinVerNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
RectHorAlign eHorAlign = pLM->GetRectHorAlign();
// move numerator to its position
- Point aPos = pNum->AlignTo(*pLine, RP_TOP, eHorAlign, RVA_BASELINE);
+ Point aPos = pNum->AlignTo(*pLine, RectPos::Top, eHorAlign, RVA_BASELINE);
aPos.Y() -= nNumDist;
pNum->MoveTo(aPos);
@@ -1114,7 +1114,7 @@ void SmBinVerNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
eHorAlign = pLM->GetRectHorAlign();
// move denominator to its position
- aPos = pDenom->AlignTo(*pLine, RP_BOTTOM, eHorAlign, RVA_BASELINE);
+ aPos = pDenom->AlignTo(*pLine, RectPos::Bottom, eHorAlign, RVA_BASELINE);
aPos.Y() += nDenomDist;
pDenom->MoveTo(aPos);
@@ -1457,7 +1457,7 @@ void SmSubSupNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
nDist = nOrigHeight
* rFormat.GetDistance(DIS_SUBSCRIPT) / 100L;
aPos = pSubSup->GetRect().AlignTo(aTmpRect,
- eSubSup == LSUB ? RP_LEFT : RP_RIGHT,
+ eSubSup == LSUB ? RectPos::Left : RectPos::Right,
RHA_CENTER, RVA_BOTTOM);
aPos.Y() += nDist;
nDelta = nDelimLine - aPos.Y();
@@ -1470,7 +1470,7 @@ void SmSubSupNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
nDist = nOrigHeight
* rFormat.GetDistance(DIS_SUPERSCRIPT) / 100L;
aPos = pSubSup->GetRect().AlignTo(aTmpRect,
- eSubSup == LSUP ? RP_LEFT : RP_RIGHT,
+ eSubSup == LSUP ? RectPos::Left : RectPos::Right,
RHA_CENTER, RVA_TOP);
aPos.Y() -= nDist;
nDelta = aPos.Y() + pSubSup->GetHeight() - nDelimLine;
@@ -1481,7 +1481,7 @@ void SmSubSupNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
if (!bIsTextmode)
nDist = nOrigHeight
* rFormat.GetDistance(DIS_LOWERLIMIT) / 100L;
- aPos = pSubSup->GetRect().AlignTo(rBodyRect, RP_BOTTOM,
+ aPos = pSubSup->GetRect().AlignTo(rBodyRect, RectPos::Bottom,
RHA_CENTER, RVA_BASELINE);
aPos.Y() += nDist;
break;
@@ -1489,7 +1489,7 @@ void SmSubSupNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
if (!bIsTextmode)
nDist = nOrigHeight
* rFormat.GetDistance(DIS_UPPERLIMIT) / 100L;
- aPos = pSubSup->GetRect().AlignTo(rBodyRect, RP_TOP,
+ aPos = pSubSup->GetRect().AlignTo(rBodyRect, RectPos::Top,
RHA_CENTER, RVA_BASELINE);
aPos.Y() -= nDist;
break;
@@ -1675,11 +1675,11 @@ void SmBraceNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
RectVerAlign eVerAlign = bScale ? RVA_CENTERY : RVA_BASELINE;
Point aPos;
- aPos = pLeft->AlignTo(*pBody, RP_LEFT, RHA_CENTER, eVerAlign);
+ aPos = pLeft->AlignTo(*pBody, RectPos::Left, RHA_CENTER, eVerAlign);
aPos.X() -= nDist;
pLeft->MoveTo(aPos);
- aPos = pRight->AlignTo(*pBody, RP_RIGHT, RHA_CENTER, eVerAlign);
+ aPos = pRight->AlignTo(*pBody, RectPos::Right, RHA_CENTER, eVerAlign);
aPos.X() += nDist;
pRight->MoveTo(aPos);
@@ -1707,7 +1707,7 @@ void SmBracebodyNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
for (i = 0; i < nNumSubNodes; i += 2)
{
SmRect aTmpRect (*GetSubNode(i));
- Point aPos = aTmpRect.AlignTo(aRefRect, RP_RIGHT, RHA_CENTER, RVA_BASELINE);
+ Point aPos = aTmpRect.AlignTo(aRefRect, RectPos::Right, RHA_CENTER, RVA_BASELINE);
aTmpRect.MoveTo(aPos);
aRefRect.ExtendBy(aTmpRect, RCP_XOR);
}
@@ -1741,8 +1741,8 @@ void SmBracebodyNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
RectVerAlign eVerAlign = bIsSeparator ? RVA_CENTERY : RVA_BASELINE;
SmNode *pRight = GetSubNode(i);
- Point aPosX = pRight->AlignTo(*pLeft, RP_RIGHT, RHA_CENTER, eVerAlign),
- aPosY = pRight->AlignTo(aRefRect, RP_RIGHT, RHA_CENTER, eVerAlign);
+ Point aPosX = pRight->AlignTo(*pLeft, RectPos::Right, RHA_CENTER, eVerAlign),
+ aPosY = pRight->AlignTo(aRefRect, RectPos::Right, RHA_CENTER, eVerAlign);
aPosX.X() += nDist;
pRight->MoveTo(Point(aPosX.X(), aPosY.Y()));
@@ -1789,13 +1789,13 @@ void SmVerticalBraceNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
nDistScript = nFontHeight;
if (GetToken().eType == TOVERBRACE)
{
- eRectPos = RP_TOP;
+ eRectPos = RectPos::Top;
nDistBody = - nDistBody;
nDistScript *= - rFormat.GetDistance(DIS_UPPERLIMIT);
}
else // TUNDERBRACE
{
- eRectPos = RP_BOTTOM;
+ eRectPos = RectPos::Bottom;
nDistScript *= + rFormat.GetDistance(DIS_LOWERLIMIT);
}
nDistBody /= 100L;
@@ -1877,7 +1877,7 @@ void SmOperNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
nDist = nOrigHeight
* rFormat.GetDistance(DIS_OPERATORSPACE) / 100L;
- Point aPos = pOper->AlignTo(*pBody, RP_LEFT, RHA_CENTER, /*RVA_CENTERY*/RVA_MID);
+ Point aPos = pOper->AlignTo(*pBody, RectPos::Left, RHA_CENTER, /*RVA_CENTERY*/RVA_MID);
aPos.X() -= nDist;
pOper->MoveTo(aPos);
@@ -1945,7 +1945,7 @@ void SmAttributNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
nDist = GetFont().GetSize().Height()
* rFormat.GetDistance(DIS_ORNAMENTSPACE) / 100L;
}
- Point aPos = pAttr->AlignTo(*pBody, RP_ATTRIBUT, RHA_CENTER, eVerAlign);
+ Point aPos = pAttr->AlignTo(*pBody, RectPos::Attribute, RHA_CENTER, eVerAlign);
aPos.Y() -= nDist;
pAttr->MoveTo(aPos);
@@ -2535,7 +2535,7 @@ void SmMatrixNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
const SmRect &rNodeRect = pTmpNode->GetRect();
// align all baselines in that row if possible
- aPos = rNodeRect.AlignTo(aLineRect, RP_RIGHT, RHA_CENTER, RVA_BASELINE);
+ aPos = rNodeRect.AlignTo(aLineRect, RectPos::Right, RHA_CENTER, RVA_BASELINE);
aPos.X() += nHorDist;
// get horizontal alignment
@@ -2563,7 +2563,7 @@ void SmMatrixNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
aLineRect.ExtendBy(rNodeRect, RCP_XOR);
}
- aPos = aLineRect.AlignTo(*this, RP_BOTTOM, RHA_CENTER, RVA_BASELINE);
+ aPos = aLineRect.AlignTo(*this, RectPos::Bottom, RHA_CENTER, RVA_BASELINE);
aPos.Y() += nVerDist;
// move 'aLineRect' and rectangles in that line to final position
diff --git a/starmath/source/rect.cxx b/starmath/source/rect.cxx
index 08168e4..e341a2b 100644
--- a/starmath/source/rect.cxx
+++ b/starmath/source/rect.cxx
@@ -28,7 +28,7 @@
#include "utility.hxx"
#include "smmod.hxx"
-
+#include <cassert>
@@ -307,32 +307,31 @@ const Point SmRect::AlignTo(const SmRect &rRect, RectPos ePos,
{ Point aPos (GetTopLeft());
// will become the topleft point of the new rectangle position
- // set horizontal or vertical new rectangle position depending on
- // 'ePos' is one of 'RP_LEFT', 'RP_RIGHT' or 'RP_TOP', 'RP_BOTTOM'
+ // set horizontal or vertical new rectangle position depending on ePos
switch (ePos)
- { case RP_LEFT :
+ { case RectPos::Left:
aPos.X() = rRect.GetItalicLeft() - GetItalicRightSpace()
- GetWidth();
break;
- case RP_RIGHT :
+ case RectPos::Right:
aPos.X() = rRect.GetItalicRight() + 1 + GetItalicLeftSpace();
break;
- case RP_TOP :
+ case RectPos::Top:
aPos.Y() = rRect.GetTop() - GetHeight();
break;
- case RP_BOTTOM :
+ case RectPos::Bottom:
aPos.Y() = rRect.GetBottom() + 1;
break;
- case RP_ATTRIBUT :
+ case RectPos::Attribute:
aPos.X() = rRect.GetItalicCenterX() - GetItalicWidth() / 2
+ GetItalicLeftSpace();
break;
- default :
- SAL_WARN("starmath", "unknown case");
+ default:
+ assert(false);
}
// check if horizontal position is already set
- if (ePos == RP_LEFT || ePos == RP_RIGHT || ePos == RP_ATTRIBUT)
+ if (ePos == RectPos::Left || ePos == RectPos::Right || ePos == RectPos::Attribute)
// correct error in current vertical position
switch (eVer)
{ case RVA_TOP :
@@ -369,7 +368,7 @@ const Point SmRect::AlignTo(const SmRect &rRect, RectPos ePos,
}
// check if vertical position is already set
- if (ePos == RP_TOP || ePos == RP_BOTTOM)
+ if (ePos == RectPos::Top || ePos == RectPos::Bottom)
// correct error in current horizontal position
switch (eHor)
{ case RHA_LEFT :
More information about the Libreoffice-commits
mailing list