summaryrefslogtreecommitdiff
path: root/svx/source/svdraw/svdtrans.cxx
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2014-10-23 17:41:47 +0200
committerJan Holesovsky <kendy@collabora.com>2014-10-23 18:34:39 +0200
commit31af61ea091cc895b893c849f2130aa35792b7db (patch)
tree6c7b63c5b538034bd5d356c5a8667b7e95d59b9c /svx/source/svdraw/svdtrans.cxx
parente92c0d6f9b7a6251e00dc55219a203a7e53c96e2 (diff)
Fraction: Revert "fdo#81356: convert Fraction to boost::rational<long> - wip"
This reverts commit 47a2d7642d249d70b5da0c330a73f3a0032e4bba. Conflicts: cui/source/tabpages/transfrm.cxx svx/source/svdraw/svdedtv1.cxx svx/source/svdraw/svdibrow.cxx sw/source/filter/ww1/w1filter.cxx tools/source/generic/rational.cxx Change-Id: I4849916f5f277a4afef0e279b0135c76b36b9d15
Diffstat (limited to 'svx/source/svdraw/svdtrans.cxx')
-rw-r--r--svx/source/svdraw/svdtrans.cxx72
1 files changed, 49 insertions, 23 deletions
diff --git a/svx/source/svdraw/svdtrans.cxx b/svx/source/svdraw/svdtrans.cxx
index e1d7104656da..f3cccd0db8e0 100644
--- a/svx/source/svdraw/svdtrans.cxx
+++ b/svx/source/svdraw/svdtrans.cxx
@@ -32,20 +32,46 @@ void MoveXPoly(XPolygon& rPoly, const Size& S)
rPoly.Move(S.Width(),S.Height());
}
-void ResizeRect(Rectangle& rRect, const Point& rRef, const boost::rational<long>& rxFact, const boost::rational<long>& ryFact, bool bNoJustify)
+void ResizeRect(Rectangle& rRect, const Point& rRef, const Fraction& rxFact, const Fraction& ryFact, bool bNoJustify)
{
- boost::rational<long> xFact(rxFact);
- boost::rational<long> yFact(ryFact);
+ Fraction xFact(rxFact);
+ Fraction yFact(ryFact);
- rRect.Left() =rRef.X()+Round(((double)(rRect.Left() -rRef.X())*xFact.numerator())/xFact.denominator());
- rRect.Right() =rRef.X()+Round(((double)(rRect.Right() -rRef.X())*xFact.numerator())/xFact.denominator());
- rRect.Top() =rRef.Y()+Round(((double)(rRect.Top() -rRef.Y())*yFact.numerator())/yFact.denominator());
- rRect.Bottom()=rRef.Y()+Round(((double)(rRect.Bottom()-rRef.Y())*yFact.numerator())/yFact.denominator());
+ {
+ if (xFact.GetDenominator()==0) {
+ long nWdt=rRect.Right()-rRect.Left();
+ if (xFact.GetNumerator()>=0) { // catch divisions by zero
+ xFact=Fraction(xFact.GetNumerator(),1);
+ if (nWdt==0) rRect.Right()++;
+ } else {
+ xFact=Fraction(xFact.GetNumerator(),-1);
+ if (nWdt==0) rRect.Left()--;
+ }
+ }
+ rRect.Left() =rRef.X()+Round(((double)(rRect.Left() -rRef.X())*xFact.GetNumerator())/xFact.GetDenominator());
+ rRect.Right() =rRef.X()+Round(((double)(rRect.Right() -rRef.X())*xFact.GetNumerator())/xFact.GetDenominator());
+ }
+ {
+ if (yFact.GetDenominator()==0) {
+ long nHgt=rRect.Bottom()-rRect.Top();
+ if (yFact.GetNumerator()>=0) { // catch divisions by zero
+ yFact=Fraction(yFact.GetNumerator(),1);
+ if (nHgt==0) rRect.Bottom()++;
+ } else {
+ yFact=Fraction(yFact.GetNumerator(),-1);
+ if (nHgt==0) rRect.Top()--;
+ }
+
+ yFact=Fraction(yFact.GetNumerator(),1); // catch divisions by zero
+ }
+ rRect.Top() =rRef.Y()+Round(((double)(rRect.Top() -rRef.Y())*yFact.GetNumerator())/yFact.GetDenominator());
+ rRect.Bottom()=rRef.Y()+Round(((double)(rRect.Bottom()-rRef.Y())*yFact.GetNumerator())/yFact.GetDenominator());
+ }
if (!bNoJustify) rRect.Justify();
}
-void ResizePoly(Polygon& rPoly, const Point& rRef, const boost::rational<long>& xFact, const boost::rational<long>& yFact)
+void ResizePoly(Polygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact)
{
sal_uInt16 nAnz=rPoly.GetSize();
for (sal_uInt16 i=0; i<nAnz; i++) {
@@ -53,7 +79,7 @@ void ResizePoly(Polygon& rPoly, const Point& rRef, const boost::rational<long>&
}
}
-void ResizeXPoly(XPolygon& rPoly, const Point& rRef, const boost::rational<long>& xFact, const boost::rational<long>& yFact)
+void ResizeXPoly(XPolygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact)
{
sal_uInt16 nAnz=rPoly.GetPointCount();
for (sal_uInt16 i=0; i<nAnz; i++) {
@@ -570,10 +596,10 @@ long BigMulDiv(long nVal, long nMul, long nDiv)
return 0x7fffffff;
}
-void Kuerzen(boost::rational<long>& rF, unsigned nDigits)
+void Kuerzen(Fraction& rF, unsigned nDigits)
{
- sal_Int32 nMul=rF.numerator();
- sal_Int32 nDiv=rF.denominator();
+ sal_Int32 nMul=rF.GetNumerator();
+ sal_Int32 nDiv=rF.GetDenominator();
bool bNeg = false;
if (nMul<0) { nMul=-nMul; bNeg=!bNeg; }
if (nDiv<0) { nDiv=-nDiv; bNeg=!bNeg; }
@@ -599,7 +625,7 @@ void Kuerzen(boost::rational<long>& rF, unsigned nDigits)
return;
}
if (bNeg) nMul=-nMul;
- rF=boost::rational<long>(nMul,nDiv);
+ rF=Fraction(nMul,nDiv);
}
@@ -635,7 +661,7 @@ FrPair GetInchOrMM(MapUnit eU)
}
default: break;
}
- return boost::rational<long>(1,1);
+ return Fraction(1,1);
}
FrPair GetInchOrMM(FieldUnit eU)
@@ -654,7 +680,7 @@ FrPair GetInchOrMM(FieldUnit eU)
case FUNIT_MILE : return FrPair( 1,63360);
default: break;
}
- return boost::rational<long>(1,1);
+ return Fraction(1,1);
}
// Calculate the factor that we need to convert units from eS to eD.
@@ -668,8 +694,8 @@ FrPair GetMapFactor(MapUnit eS, MapUnit eD)
bool bSInch=IsInch(eS);
bool bDInch=IsInch(eD);
FrPair aRet(aD.X()/aS.X(),aD.Y()/aS.Y());
- if (bSInch && !bDInch) { aRet.X()*=boost::rational<long>(127,5); aRet.Y()*=boost::rational<long>(127,5); }
- if (!bSInch && bDInch) { aRet.X()*=boost::rational<long>(5,127); aRet.Y()*=boost::rational<long>(5,127); }
+ if (bSInch && !bDInch) { aRet.X()*=Fraction(127,5); aRet.Y()*=Fraction(127,5); }
+ if (!bSInch && bDInch) { aRet.X()*=Fraction(5,127); aRet.Y()*=Fraction(5,127); }
return aRet;
};
@@ -681,8 +707,8 @@ FrPair GetMapFactor(FieldUnit eS, FieldUnit eD)
bool bSInch=IsInch(eS);
bool bDInch=IsInch(eD);
FrPair aRet(aD.X()/aS.X(),aD.Y()/aS.Y());
- if (bSInch && !bDInch) { aRet.X()*=boost::rational<long>(127,5); aRet.Y()*=boost::rational<long>(127,5); }
- if (!bSInch && bDInch) { aRet.X()*=boost::rational<long>(5,127); aRet.Y()*=boost::rational<long>(5,127); }
+ if (bSInch && !bDInch) { aRet.X()*=Fraction(127,5); aRet.Y()*=Fraction(127,5); }
+ if (!bSInch && bDInch) { aRet.X()*=Fraction(5,127); aRet.Y()*=Fraction(5,127); }
return aRet;
};
@@ -763,7 +789,7 @@ void GetMeterOrInch(FieldUnit eFU, short& rnKomma, long& rnMul, long& rnDiv, boo
void SdrFormatter::Undirty()
{
- if (aScale.numerator()==0) aScale=boost::rational<long>(1,1);
+ if (aScale.GetNumerator()==0 || aScale.GetDenominator()==0) aScale=Fraction(1,1);
bool bSrcMetr,bSrcInch,bDstMetr,bDstInch;
long nMul1,nDiv1,nMul2,nDiv2;
short nKomma1,nKomma2;
@@ -792,9 +818,9 @@ void SdrFormatter::Undirty()
}
// temporary fraction for canceling
- boost::rational<long> aTempFract(nMul1,nDiv1);
- nMul1=aTempFract.numerator();
- nDiv1=aTempFract.denominator();
+ Fraction aTempFract(nMul1,nDiv1);
+ nMul1=aTempFract.GetNumerator();
+ nDiv1=aTempFract.GetDenominator();
nMul_=nMul1;
nDiv_=nDiv1;