diff options
author | Juan Picca <jumapico@gmail.com> | 2014-09-19 14:19:30 -0300 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-10-09 11:33:33 +0000 |
commit | 47a2d7642d249d70b5da0c330a73f3a0032e4bba (patch) | |
tree | 202b04810382ea87cf8015a7b4de29e931408948 /svtools | |
parent | ae77dc81c33ab0817264bcf5fc8bb71a55b78a73 (diff) |
fdo#81356: convert Fraction to boost::rational<long> - wip
* Added rational util functions used by Fraction class not
available in the boost::rational class.
* Replaced usage of Fraction by boost::rational<long>
* Removed code that relies on:
1. fraction.IsValid() -- rational only allow valid values, ie
denominator() != 0
2. rational.denominator() == 0 -- always false
3. rational.denominator() < 0 -- always false but implementation
detail: http://www.boost.org/doc/libs/release/libs/rational/rational.html#Internal%20representation
* Simplified code that relies on:
1. rational.denominator() != 0 -- always true
* BUGS EXIST because Fraction allows the creation of invalid values but
boost::rational throws the exception boost::bad_rational
Change-Id: I84970a4956afb3f91ac0c8f726547466319420f9
Reviewed-on: https://gerrit.libreoffice.org/11551
Reviewed-by: David Tardon <dtardon@redhat.com>
Tested-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/brwbox/brwbox1.cxx | 6 | ||||
-rw-r--r-- | svtools/source/brwbox/brwbox2.cxx | 4 | ||||
-rw-r--r-- | svtools/source/brwbox/datwin.cxx | 18 | ||||
-rw-r--r-- | svtools/source/brwbox/datwin.hxx | 6 | ||||
-rw-r--r-- | svtools/source/control/ctrltool.cxx | 2 | ||||
-rw-r--r-- | svtools/source/control/ruler.cxx | 6 | ||||
-rw-r--r-- | svtools/source/filter/exportdialog.cxx | 4 | ||||
-rw-r--r-- | svtools/source/graphic/grfmgr.cxx | 2 | ||||
-rw-r--r-- | svtools/source/misc/imap.cxx | 42 |
9 files changed, 39 insertions, 51 deletions
diff --git a/svtools/source/brwbox/brwbox1.cxx b/svtools/source/brwbox/brwbox1.cxx index bb4b392942d4..e69a4e0f8450 100644 --- a/svtools/source/brwbox/brwbox1.cxx +++ b/svtools/source/brwbox/brwbox1.cxx @@ -2423,10 +2423,10 @@ long BrowseBox::CalcReverseZoom(long nVal) { if (IsZoom()) { - const Fraction& rZoom = GetZoom(); + const boost::rational<long>& rZoom = GetZoom(); double n = (double)nVal; - n *= (double)rZoom.GetDenominator(); - n /= (double)rZoom.GetNumerator(); + n *= (double)rZoom.denominator(); + n /= (double)rZoom.numerator(); nVal = n>0 ? (long)(n + 0.5) : -(long)(-n + 0.5); } diff --git a/svtools/source/brwbox/brwbox2.cxx b/svtools/source/brwbox/brwbox2.cxx index fe822bb3c618..d4c0e7d46f4e 100644 --- a/svtools/source/brwbox/brwbox2.cxx +++ b/svtools/source/brwbox/brwbox2.cxx @@ -549,7 +549,7 @@ void BrowseBox::Resize() // resized - which is done in UpdateScrollbars) sal_uLong nSBSize = GetSettings().GetStyleSettings().GetScrollBarSize(); if (IsZoom()) - nSBSize = (sal_uLong)(nSBSize * (double)GetZoom()); + nSBSize = (sal_uLong)(nSBSize * boost::rational_cast<double>(GetZoom())); DoHideCursor( "Resize" ); sal_uInt16 nOldVisibleRows = 0; @@ -1136,7 +1136,7 @@ void BrowseBox::UpdateScrollbars() // the size of the corner window (and the width of the VSB/height of the HSB) sal_uLong nCornerSize = GetSettings().GetStyleSettings().GetScrollBarSize(); if (IsZoom()) - nCornerSize = (sal_uLong)(nCornerSize * (double)GetZoom()); + nCornerSize = (sal_uLong)(nCornerSize * boost::rational_cast<double>(GetZoom())); bool bNeedsVScroll = false; long nMaxRows = 0; diff --git a/svtools/source/brwbox/datwin.cxx b/svtools/source/brwbox/datwin.cxx index 91bff8b52be8..e8ac1d0e6d3b 100644 --- a/svtools/source/brwbox/datwin.cxx +++ b/svtools/source/brwbox/datwin.cxx @@ -104,7 +104,7 @@ void ButtonFrame::Draw( OutputDevice& rDev ) BrowserColumn::BrowserColumn( sal_uInt16 nItemId, const class Image &rImage, - const OUString& rTitle, sal_uLong nWidthPixel, const Fraction& rCurrentZoom ) + const OUString& rTitle, sal_uLong nWidthPixel, const boost::rational<long>& rCurrentZoom ) : _nId( nItemId ), _nWidth( nWidthPixel ), _aImage( rImage ), @@ -112,8 +112,8 @@ BrowserColumn::BrowserColumn( sal_uInt16 nItemId, const class Image &rImage, _bFrozen( false ) { double n = (double)_nWidth; - n *= (double)rCurrentZoom.GetDenominator(); - n /= (double)rCurrentZoom.GetNumerator(); + n *= (double)rCurrentZoom.denominator(); + n /= (double)rCurrentZoom.numerator(); _nOriginalWidth = n>0 ? (long)(n+0.5) : -(long)(-n+0.5); } @@ -123,12 +123,12 @@ BrowserColumn::~BrowserColumn() -void BrowserColumn::SetWidth(sal_uLong nNewWidthPixel, const Fraction& rCurrentZoom) +void BrowserColumn::SetWidth(sal_uLong nNewWidthPixel, const boost::rational<long>& rCurrentZoom) { _nWidth = nNewWidthPixel; double n = (double)_nWidth; - n *= (double)rCurrentZoom.GetDenominator(); - n /= (double)rCurrentZoom.GetNumerator(); + n *= (double)rCurrentZoom.denominator(); + n /= (double)rCurrentZoom.numerator(); _nOriginalWidth = n>0 ? (long)(n+0.5) : -(long)(-n+0.5); } @@ -174,11 +174,11 @@ void BrowserColumn::Draw( BrowseBox& rBox, OutputDevice& rDev, const Point& rPos -void BrowserColumn::ZoomChanged(const Fraction& rNewZoom) +void BrowserColumn::ZoomChanged(const boost::rational<long>& rNewZoom) { double n = (double)_nOriginalWidth; - n *= (double)rNewZoom.GetNumerator(); - n /= (double)rNewZoom.GetDenominator(); + n *= (double)rNewZoom.numerator(); + n /= (double)rNewZoom.denominator(); _nWidth = n>0 ? (long)(n+0.5) : -(long)(-n+0.5); } diff --git a/svtools/source/brwbox/datwin.hxx b/svtools/source/brwbox/datwin.hxx index bff17665e392..1bbe57a684d9 100644 --- a/svtools/source/brwbox/datwin.hxx +++ b/svtools/source/brwbox/datwin.hxx @@ -76,7 +76,7 @@ class BrowserColumn public: BrowserColumn( sal_uInt16 nItemId, const Image &rImage, - const OUString& rTitle, sal_uLong nWidthPixel, const Fraction& rCurrentZoom ); + const OUString& rTitle, sal_uLong nWidthPixel, const boost::rational<long>& rCurrentZoom ); virtual ~BrowserColumn(); sal_uInt16 GetId() const { return _nId; } @@ -91,8 +91,8 @@ public: virtual void Draw( BrowseBox& rBox, OutputDevice& rDev, const Point& rPos, bool bCurs ); - void SetWidth(sal_uLong nNewWidthPixel, const Fraction& rCurrentZoom); - void ZoomChanged(const Fraction& rNewZoom); + void SetWidth(sal_uLong nNewWidthPixel, const boost::rational<long>& rCurrentZoom); + void ZoomChanged(const boost::rational<long>& rNewZoom); }; diff --git a/svtools/source/control/ctrltool.cxx b/svtools/source/control/ctrltool.cxx index 4308379d6012..587174e88491 100644 --- a/svtools/source/control/ctrltool.cxx +++ b/svtools/source/control/ctrltool.cxx @@ -737,7 +737,7 @@ const sal_IntPtr* FontList::GetSizeAry( const vcl::FontInfo& rInfo ) const return aStdSizeAry; MapMode aOldMapMode = pDevice->GetMapMode(); - MapMode aMap( MAP_10TH_INCH, Point(), Fraction( 1, 72 ), Fraction( 1, 72 ) ); + MapMode aMap( MAP_10TH_INCH, Point(), boost::rational<long>( 1, 72 ), boost::rational<long>( 1, 72 ) ); pDevice->SetMapMode( aMap ); sal_uInt16 i; diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx index 6dfce365f415..a74ce2d4fcae 100644 --- a/svtools/source/control/ruler.cxx +++ b/svtools/source/control/ruler.cxx @@ -256,7 +256,7 @@ void Ruler::ImplInit( WinBits nWinBits ) // Initialize Units mnUnitIndex = RULER_UNIT_CM; meUnit = FUNIT_CM; - maZoom = Fraction( 1, 1 ); + maZoom = boost::rational<long>( 1, 1 ); meSourceUnit = MAP_100TH_MM; // Recalculate border widths @@ -2478,9 +2478,9 @@ void Ruler::SetUnit( FieldUnit eNewUnit ) } } -void Ruler::SetZoom( const Fraction& rNewZoom ) +void Ruler::SetZoom( const boost::rational<long>& rNewZoom ) { - DBG_ASSERT( rNewZoom.GetNumerator(), "Ruler::SetZoom() with scale 0 is not allowed" ); + DBG_ASSERT( rNewZoom.numerator(), "Ruler::SetZoom() with scale 0 is not allowed" ); if ( maZoom != rNewZoom ) { diff --git a/svtools/source/filter/exportdialog.cxx b/svtools/source/filter/exportdialog.cxx index 78ee4385a2e4..808a4205d37f 100644 --- a/svtools/source/filter/exportdialog.cxx +++ b/svtools/source/filter/exportdialog.cxx @@ -1017,7 +1017,7 @@ IMPL_LINK_NOARG(ExportDialog, UpdateHdlMtfSizeX) } else { - Fraction aFract( 1, 100 ); + boost::rational<long> aFract( 1, 100 ); sal_Int32 nWidth = mpMfSizeX->GetValue(); sal_Int32 nHeight= static_cast< sal_Int32 >( nWidth * fRatio ); const Size aSource( static_cast< sal_Int32 >( nWidth ), static_cast< sal_Int32 >( nHeight ) ); @@ -1051,7 +1051,7 @@ IMPL_LINK_NOARG(ExportDialog, UpdateHdlMtfSizeY) } else { - Fraction aFract( 1, 100 ); + boost::rational<long> aFract( 1, 100 ); sal_Int32 nHeight= mpMfSizeY->GetValue(); sal_Int32 nWidth = static_cast< sal_Int32 >( nHeight * fRatio ); const Size aSource( static_cast< sal_Int32 >( nWidth ), static_cast< sal_Int32 >( nHeight ) ); diff --git a/svtools/source/graphic/grfmgr.cxx b/svtools/source/graphic/grfmgr.cxx index 8a6497eab841..be4baa30e6ea 100644 --- a/svtools/source/graphic/grfmgr.cxx +++ b/svtools/source/graphic/grfmgr.cxx @@ -887,7 +887,7 @@ Graphic GraphicObject::GetTransformedGraphic( const Size& rDestSize, const MapMo } else { - aMtf.Scale( Fraction( rDestSize.Width(), aSrcSize.Width() ), Fraction( rDestSize.Height(), aSrcSize.Height() ) ); + aMtf.Scale( boost::rational<long>( rDestSize.Width(), aSrcSize.Width() ), boost::rational<long>( rDestSize.Height(), aSrcSize.Height() ) ); aMtf.SetPrefMapMode( rDestMap ); } diff --git a/svtools/source/misc/imap.cxx b/svtools/source/misc/imap.cxx index 705021afe3fb..967724923ed8 100644 --- a/svtools/source/misc/imap.cxx +++ b/svtools/source/misc/imap.cxx @@ -35,8 +35,8 @@ #include <boost/scoped_ptr.hpp> -#define SCALEPOINT(aPT,aFracX,aFracY) (aPT).X()=((aPT).X()*(aFracX).GetNumerator())/(aFracX).GetDenominator(); \ - (aPT).Y()=((aPT).Y()*(aFracY).GetNumerator())/(aFracY).GetDenominator(); +#define SCALEPOINT(aPT,aFracX,aFracY) (aPT).X()=((aPT).X()*(aFracX).numerator())/(aFracX).denominator(); \ + (aPT).Y()=((aPT).Y()*(aFracY).numerator())/(aFracY).denominator(); /******************************************************************************/ @@ -226,16 +226,13 @@ Rectangle IMapRectangleObject::GetRectangle( bool bPixelCoords ) const return aNewRect; } -void IMapRectangleObject::Scale( const Fraction& rFracX, const Fraction& rFracY ) +void IMapRectangleObject::Scale( const boost::rational<long>& rFracX, const boost::rational<long>& rFracY ) { Point aTL( aRect.TopLeft() ); Point aBR( aRect.BottomRight() ); - if ( rFracX.GetDenominator() && rFracY.GetDenominator() ) - { - SCALEPOINT( aTL, rFracX, rFracY ); - SCALEPOINT( aBR, rFracX, rFracY ); - } + SCALEPOINT( aTL, rFracX, rFracY ); + SCALEPOINT( aBR, rFracX, rFracY ); aRect = Rectangle( aTL, aBR ); } @@ -371,19 +368,16 @@ Rectangle IMapCircleObject::GetBoundRect() const Size( nWidth, nWidth ) ); } -void IMapCircleObject::Scale( const Fraction& rFracX, const Fraction& rFracY ) +void IMapCircleObject::Scale( const boost::rational<long>& rFracX, const boost::rational<long>& rFracY ) { - Fraction aAverage( rFracX ); + boost::rational<long> aAverage( rFracX ); aAverage += rFracY; - aAverage *= Fraction( 1, 2 ); + aAverage *= boost::rational<long>( 1, 2 ); - if ( rFracX.GetDenominator() && rFracY.GetDenominator() ) - { - SCALEPOINT( aCenter, rFracX, rFracY ); - } + SCALEPOINT( aCenter, rFracX, rFracY ); - nRadius = ( nRadius * aAverage.GetNumerator() ) / aAverage.GetDenominator(); + nRadius = ( nRadius * aAverage.numerator() ) / aAverage.denominator(); } bool IMapCircleObject::IsEqual( const IMapCircleObject& rEqObj ) @@ -493,7 +487,7 @@ void IMapPolygonObject::SetExtraEllipse( const Rectangle& rEllipse ) } } -void IMapPolygonObject::Scale( const Fraction& rFracX, const Fraction& rFracY ) +void IMapPolygonObject::Scale( const boost::rational<long>& rFracX, const boost::rational<long>& rFracY ) { sal_uInt16 nCount = aPoly.GetSize(); @@ -501,10 +495,7 @@ void IMapPolygonObject::Scale( const Fraction& rFracX, const Fraction& rFracY ) { Point aScaledPt( aPoly[ i ] ); - if ( rFracX.GetDenominator() && rFracY.GetDenominator() ) - { - SCALEPOINT( aScaledPt, rFracX, rFracY ); - } + SCALEPOINT( aScaledPt, rFracX, rFracY ); aPoly[ i ] = aScaledPt; } @@ -514,11 +505,8 @@ void IMapPolygonObject::Scale( const Fraction& rFracX, const Fraction& rFracY ) Point aTL( aEllipse.TopLeft() ); Point aBR( aEllipse.BottomRight() ); - if ( rFracX.GetDenominator() && rFracY.GetDenominator() ) - { - SCALEPOINT( aTL, rFracX, rFracY ); - SCALEPOINT( aBR, rFracX, rFracY ); - } + SCALEPOINT( aTL, rFracX, rFracY ); + SCALEPOINT( aBR, rFracX, rFracY ); aEllipse = Rectangle( aTL, aBR ); } @@ -824,7 +812,7 @@ IMapObject* ImageMap::GetHitIMapObject( const Size& rTotalSize, return( pObj ? ( pObj->IsActive() ? pObj : NULL ) : NULL ); } -void ImageMap::Scale( const Fraction& rFracX, const Fraction& rFracY ) +void ImageMap::Scale( const boost::rational<long>& rFracX, const boost::rational<long>& rFracY ) { size_t nCount = maList.size(); |