diff options
author | Juan Picca <jumapico@gmail.com> | 2014-11-03 22:33:52 -0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-12-18 15:58:42 +0000 |
commit | 82aa4dbd8330eb446cdf535794c13185f0c0ca81 (patch) | |
tree | 2aef1fa53c830b00085bab8f6a98ded1a755aec7 /svx/source/svdraw/svdtrans.cxx | |
parent | 3f66df98050175dfbab2026661c0cba734885e05 (diff) |
Fraction: rewrite 'GetDenominator()==0' conditions
Change-Id: Ie42972db98da48b60b3f5314e019046b2a2ee0e7
Reviewed-on: https://gerrit.libreoffice.org/12238
Reviewed-by: David Tardon <dtardon@redhat.com>
Tested-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'svx/source/svdraw/svdtrans.cxx')
-rw-r--r-- | svx/source/svdraw/svdtrans.cxx | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/svx/source/svdraw/svdtrans.cxx b/svx/source/svdraw/svdtrans.cxx index fea86370ea5a..4de3f7033571 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(); } |