[Libreoffice-commits] core.git: include/svx svx/source
Juan Picca
jumapico at gmail.com
Thu Dec 18 07:59:03 PST 2014
include/svx/svdtrans.hxx | 14 +++++++++----
svx/source/svdraw/svdtrans.cxx | 44 ++++++++++++++---------------------------
2 files changed, 26 insertions(+), 32 deletions(-)
New commits:
commit 82aa4dbd8330eb446cdf535794c13185f0c0ca81
Author: Juan Picca <jumapico at gmail.com>
Date: Mon Nov 3 22:33:52 2014 -0200
Fraction: rewrite 'GetDenominator()==0' conditions
Change-Id: Ie42972db98da48b60b3f5314e019046b2a2ee0e7
Reviewed-on: https://gerrit.libreoffice.org/12238
Reviewed-by: David Tardon <dtardon at redhat.com>
Tested-by: David Tardon <dtardon at redhat.com>
diff --git a/include/svx/svdtrans.hxx b/include/svx/svdtrans.hxx
index 0dca975..f2e1591 100644
--- a/include/svx/svdtrans.hxx
+++ b/include/svx/svdtrans.hxx
@@ -104,10 +104,16 @@ void CrookStretchPoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rR
inline void ResizePoint(Point& rPnt, const Point& rRef, Fraction xFact, Fraction yFact)
{
- if (xFact.GetDenominator()==0) xFact=Fraction(xFact.GetNumerator(),1); // DivZero abfangen
- if (yFact.GetDenominator()==0) yFact=Fraction(yFact.GetNumerator(),1); // DivZero abfangen
- rPnt.X()=rRef.X()+ Round(((double)(rPnt.X()-rRef.X())*xFact.GetNumerator())/xFact.GetDenominator());
- rPnt.Y()=rRef.Y()+ Round(((double)(rPnt.Y()-rRef.Y())*yFact.GetNumerator())/yFact.GetDenominator());
+ if (!xFact.IsValid()) {
+ SAL_WARN( "svx.svdraw", "invalid fraction xFact, using Fraction(1,1)" );
+ xFact = Fraction(1,1);
+ }
+ if (!yFact.IsValid()) {
+ SAL_WARN( "svx.svdraw", "invalid fraction yFact, using Fraction(1,1)" );
+ yFact = Fraction(1,1);
+ }
+ rPnt.X() = rRef.X() + Round( (rPnt.X() - rRef.X()) * double(xFact) );
+ rPnt.Y() = rRef.Y() + Round( (rPnt.Y() - rRef.Y()) * double(yFact) );
}
inline void RotatePoint(Point& rPnt, const Point& rRef, double sn, double cs)
diff --git a/svx/source/svdraw/svdtrans.cxx b/svx/source/svdraw/svdtrans.cxx
index fea8637..4de3f70 100644
--- a/svx/source/svdraw/svdtrans.cxx
+++ b/svx/source/svdraw/svdtrans.cxx
@@ -37,36 +37,24 @@ void ResizeRect(Rectangle& rRect, const Point& rRef, const Fraction& rxFact, con
Fraction xFact(rxFact);
Fraction yFact(ryFact);
- {
- 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 (!xFact.IsValid()) {
+ SAL_WARN( "svx.svdraw", "invalid fraction xFract, using Fraction(1,1)" );
+ xFact = Fraction(1,1);
+ long nWdt = rRect.Right() - rRect.Left();
+ if (nWdt == 0) rRect.Right()++;
}
- {
- 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());
+ rRect.Left() = rRef.X() + Round( (rRect.Left() - rRef.X()) * double(xFact) );
+ rRect.Right() = rRef.X() + Round( (rRect.Right() - rRef.X()) * double(xFact) );
+
+ if (!yFact.IsValid()) {
+ SAL_WARN( "svx.svdraw", "invalid fraction yFract, using Fraction(1,1)" );
+ yFact = Fraction(1,1);
+ long nHgt = rRect.Bottom() - rRect.Top();
+ if (nHgt == 0) rRect.Bottom()++;
}
+ rRect.Top() = rRef.Y() + Round( (rRect.Top() - rRef.Y()) * double(yFact) );
+ rRect.Bottom() = rRef.Y() + Round( (rRect.Bottom() - rRef.Y()) * double(yFact) );
+
if (!bNoJustify) rRect.Justify();
}
More information about the Libreoffice-commits
mailing list