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 /vcl | |
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 'vcl')
25 files changed, 148 insertions, 175 deletions
diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h index ba0814be8671..59af7ffba0f0 100644 --- a/vcl/inc/unx/salgdi.h +++ b/vcl/inc/unx/salgdi.h @@ -22,7 +22,7 @@ #include <prex.h> #include <postx.h> -#include <tools/fract.hxx> +#include <tools/rational.hxx> #include "vcl/salgtype.hxx" #include "vcl/vclenum.hxx" diff --git a/vcl/inc/window.h b/vcl/inc/window.h index 53d077f200e8..b6ffa3d41640 100644 --- a/vcl/inc/window.h +++ b/vcl/inc/window.h @@ -231,7 +231,7 @@ public: void* mpUserData; vcl::Cursor* mpCursor; Pointer maPointer; - Fraction maZoom; + boost::rational<long> maZoom; OUString maText; vcl::Font* mpControlFont; Color maControlForeground; diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 79be1aadf326..1bad8034d929 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -860,7 +860,7 @@ static Graphic ImpGetScaledGraphic( const Graphic& rGraphic, FilterConfigItem& r MapMode aMap( MAP_100TH_INCH ); sal_Int32 nDPI = rConfigItem.ReadInt32( "Resolution", 75 ); - Fraction aFrac( 1, std::min( std::max( nDPI, sal_Int32( 75 ) ), sal_Int32( 600 ) ) ); + boost::rational<long> aFrac( 1, std::min( std::max( nDPI, sal_Int32( 75 ) ), sal_Int32( 600 ) ) ); aMap.SetScaleX( aFrac ); aMap.SetScaleY( aFrac ); @@ -900,8 +900,8 @@ static Graphic ImpGetScaledGraphic( const Graphic& rGraphic, FilterConfigItem& r if( aNewSize.Width() && aNewSize.Height() ) { const Size aPreferredSize( aMtf.GetPrefSize() ); - aMtf.Scale( Fraction( aNewSize.Width(), aPreferredSize.Width() ), - Fraction( aNewSize.Height(), aPreferredSize.Height() ) ); + aMtf.Scale( boost::rational<long>( aNewSize.Width(), aPreferredSize.Width() ), + boost::rational<long>( aNewSize.Height(), aPreferredSize.Height() ) ); } aGraphic = Graphic( aMtf ); } diff --git a/vcl/source/filter/graphicfilter2.cxx b/vcl/source/filter/graphicfilter2.cxx index a2bf39b7a58a..9f552e96a953 100644 --- a/vcl/source/filter/graphicfilter2.cxx +++ b/vcl/source/filter/graphicfilter2.cxx @@ -336,8 +336,8 @@ bool GraphicDescriptor::ImpDetectJPG( SvStream& rStm, bool bExtendedInfo ) { MapMode aMap; aMap.SetMapUnit( nUnits == 1 ? MAP_INCH : MAP_CM ); - aMap.SetScaleX( Fraction( 1, nHorizontalResolution ) ); - aMap.SetScaleY( Fraction( 1, nVerticalResolution ) ); + aMap.SetScaleX( boost::rational<long>( 1, nHorizontalResolution ) ); + aMap.SetScaleY( boost::rational<long>( 1, nVerticalResolution ) ); aLogSize = OutputDevice::LogicToLogic( aPixSize, aMap, MapMode( MAP_100TH_MM ) ); } } @@ -489,7 +489,7 @@ bool GraphicDescriptor::ImpDetectPCX( SvStream& rStm, bool bExtendedInfo ) // set logical size MapMode aMap( MAP_INCH, Point(), - Fraction( 1, nDPIx ), Fraction( 1, nDPIy ) ); + boost::rational<long>( 1, nDPIx ), boost::rational<long>( 1, nDPIy ) ); aLogSize = OutputDevice::LogicToLogic( aPixSize, aMap, MapMode( MAP_100TH_MM ) ); diff --git a/vcl/source/filter/jpeg/JpegReader.cxx b/vcl/source/filter/jpeg/JpegReader.cxx index 08fdf1dfd328..5d4c0479e1cf 100644 --- a/vcl/source/filter/jpeg/JpegReader.cxx +++ b/vcl/source/filter/jpeg/JpegReader.cxx @@ -258,8 +258,8 @@ unsigned char * JPEGReader::CreateBitmap( JPEGCreateBitmapParam * pParam ) if( ( ( 1 == nUnit ) || ( 2 == nUnit ) ) && pParam->X_density && pParam->Y_density ) { Point aEmptyPoint; - Fraction aFractX( 1, pParam->X_density ); - Fraction aFractY( 1, pParam->Y_density ); + boost::rational<long> aFractX( 1, pParam->X_density ); + boost::rational<long> aFractY( 1, pParam->Y_density ); MapMode aMapMode( nUnit == 1 ? MAP_INCH : MAP_CM, aEmptyPoint, aFractX, aFractY ); Size aPrefSize = OutputDevice::LogicToLogic( aSize, aMapMode, MAP_100TH_MM ); diff --git a/vcl/source/filter/sgfbram.cxx b/vcl/source/filter/sgfbram.cxx index 733b9c01b47a..ac119cae625b 100644 --- a/vcl/source/filter/sgfbram.cxx +++ b/vcl/source/filter/sgfbram.cxx @@ -447,7 +447,7 @@ bool SgfFilterVect(SvStream& rInp, SgfHeader& rHead, SgfEntry&, GDIMetaFile& rMt rMtf.Stop(); rMtf.WindStart(); MapMode aMap( MAP_10TH_MM, Point(), - Fraction( 1, 4 ), Fraction( 1, 4 ) ); + boost::rational<long>( 1, 4 ), boost::rational<long>( 1, 4 ) ); rMtf.SetPrefMapMode( aMap ); rMtf.SetPrefSize( Size( (short)rHead.Xsize, (short)rHead.Ysize ) ); return true; diff --git a/vcl/source/filter/sgvmain.cxx b/vcl/source/filter/sgvmain.cxx index 33219b626f99..089573a36e17 100644 --- a/vcl/source/filter/sgvmain.cxx +++ b/vcl/source/filter/sgvmain.cxx @@ -830,7 +830,7 @@ bool SgfFilterSDrw( SvStream& rInp, SgfHeader&, SgfEntry&, GDIMetaFile& rMtf ) rMtf.Stop(); rMtf.WindStart(); - MapMode aMap(MAP_10TH_MM,Point(),Fraction(1,4),Fraction(1,4)); + MapMode aMap(MAP_10TH_MM,Point(),boost::rational<long>(1,4),boost::rational<long>(1,4)); rMtf.SetPrefMapMode(aMap); rMtf.SetPrefSize(Size((sal_Int16)aPage.Paper.Size.x,(sal_Int16)aPage.Paper.Size.y)); bRet=true; diff --git a/vcl/source/filter/sgvtext.cxx b/vcl/source/filter/sgvtext.cxx index e8c31aaae39c..7cbf6bf9732f 100644 --- a/vcl/source/filter/sgvtext.cxx +++ b/vcl/source/filter/sgvtext.cxx @@ -688,7 +688,7 @@ void FormatLine(UCHAR* TBuf, sal_uInt16& Index, ObjTextType& Atr0, ObjTextType& sal_uInt16 i,j,k,h; sal_uInt16 re,li; - vOut.SetMapMode(MapMode(MAP_10TH_MM,Point(),Fraction(1,4),Fraction(1,4))); + vOut.SetMapMode(MapMode(MAP_10TH_MM,Point(),boost::rational<long>(1,4),boost::rational<long>(1,4))); nChars=0; SetTextContext(vOut,AktAtr,false,0,1,1,1,1); diff --git a/vcl/source/filter/wmf/emfwr.cxx b/vcl/source/filter/wmf/emfwr.cxx index 20d57534ce7a..f54fcd76607a 100644 --- a/vcl/source/filter/wmf/emfwr.cxx +++ b/vcl/source/filter/wmf/emfwr.cxx @@ -1252,8 +1252,8 @@ void EMFWriter::ImplWrite( const GDIMetaFile& rMtf ) MapMode aMapMode( aSubstitute.GetPrefMapMode() ); Size aOutSize( OutputDevice::LogicToLogic( pA->GetSize(), maVDev.GetMapMode(), aMapMode ) ); - aMapMode.SetScaleX( Fraction( aOutSize.Width(), aSubstitute.GetPrefSize().Width() ) ); - aMapMode.SetScaleY( Fraction( aOutSize.Height(), aSubstitute.GetPrefSize().Height() ) ); + aMapMode.SetScaleX( boost::rational<long>( aOutSize.Width(), aSubstitute.GetPrefSize().Width() ) ); + aMapMode.SetScaleY( boost::rational<long>( aOutSize.Height(), aSubstitute.GetPrefSize().Height() ) ); aMapMode.SetOrigin( OutputDevice::LogicToLogic( pA->GetPoint(), maVDev.GetMapMode(), aMapMode ) ); maVDev.SetMapMode( aMapMode ); ImplWrite( aSubstitute ); diff --git a/vcl/source/filter/wmf/winmtf.cxx b/vcl/source/filter/wmf/winmtf.cxx index 91d495c305b4..a6cddf1d9bf6 100644 --- a/vcl/source/filter/wmf/winmtf.cxx +++ b/vcl/source/filter/wmf/winmtf.cxx @@ -1510,8 +1510,8 @@ void WinMtfOutput::ImplDrawBitmap( const Point& rPos, const Size& rSize, const B const Size aSizePixel( rBitmap.GetSizePixel() ); if ( aOutputSizePixel.Width() && aOutputSizePixel.Height() ) { - aMapMode.SetScaleX( Fraction( aSizePixel.Width(), aOutputSizePixel.Width() ) ); - aMapMode.SetScaleY( Fraction( aSizePixel.Height(), aOutputSizePixel.Height() ) ); + aMapMode.SetScaleX( boost::rational<long>( aSizePixel.Width(), aOutputSizePixel.Width() ) ); + aMapMode.SetScaleY( boost::rational<long>( aSizePixel.Height(), aOutputSizePixel.Height() ) ); } aVDev.SetMapMode( aMapMode ); aVDev.SetOutputSizePixel( aSizePixel ); diff --git a/vcl/source/filter/wmf/winwmf.cxx b/vcl/source/filter/wmf/winwmf.cxx index 9c818292b1e1..919e9f1caeb5 100644 --- a/vcl/source/filter/wmf/winwmf.cxx +++ b/vcl/source/filter/wmf/winwmf.cxx @@ -1196,7 +1196,7 @@ bool WMFReader::ReadHeader() Size aDevExt( 10000, 10000 ); if( ( labs( aWMFSize.Width() ) > 1 ) && ( labs( aWMFSize.Height() ) > 1 ) ) { - const Fraction aFrac( 1, nUnitsPerInch ); + const boost::rational<long> aFrac( 1, nUnitsPerInch ); MapMode aWMFMap( MAP_INCH, Point(), aFrac, aFrac ); Size aSize100( OutputDevice::LogicToLogic( aWMFSize, aWMFMap, MAP_100TH_MM ) ); aDevExt = Size( labs( aSize100.Width() ), labs( aSize100.Height() ) ); diff --git a/vcl/source/filter/wmf/wmfwr.cxx b/vcl/source/filter/wmf/wmfwr.cxx index ee3beebacf70..ddfa18fc0e5c 100644 --- a/vcl/source/filter/wmf/wmfwr.cxx +++ b/vcl/source/filter/wmf/wmfwr.cxx @@ -1391,37 +1391,37 @@ void WMFWriter::WriteRecords( const GDIMetaFile & rMTF ) if( pA->GetMapMode().GetMapUnit() == MAP_RELATIVE ) { MapMode aMM = pA->GetMapMode(); - Fraction aScaleX = aMM.GetScaleX(); - Fraction aScaleY = aMM.GetScaleY(); + boost::rational<long> aScaleX = aMM.GetScaleX(); + boost::rational<long> aScaleY = aMM.GetScaleY(); Point aOrigin = aSrcMapMode.GetOrigin(); BigInt aX( aOrigin.X() ); - aX *= BigInt( aScaleX.GetDenominator() ); + aX *= BigInt( aScaleX.denominator() ); if( aOrigin.X() >= 0 ) - if( aScaleX.GetNumerator() >= 0 ) - aX += BigInt( aScaleX.GetNumerator()/2 ); + if( aScaleX.numerator() >= 0 ) + aX += BigInt( aScaleX.numerator()/2 ); else - aX -= BigInt( (aScaleX.GetNumerator()+1)/2 ); + aX -= BigInt( (aScaleX.numerator()+1)/2 ); else - if( aScaleX.GetNumerator() >= 0 ) - aX -= BigInt( (aScaleX.GetNumerator()-1)/2 ); + if( aScaleX.numerator() >= 0 ) + aX -= BigInt( (aScaleX.numerator()-1)/2 ); else - aX += BigInt( aScaleX.GetNumerator()/2 ); - aX /= BigInt( aScaleX.GetNumerator() ); + aX += BigInt( aScaleX.numerator()/2 ); + aX /= BigInt( aScaleX.numerator() ); aOrigin.X() = (long)aX + aMM.GetOrigin().X(); BigInt aY( aOrigin.Y() ); - aY *= BigInt( aScaleY.GetDenominator() ); + aY *= BigInt( aScaleY.denominator() ); if( aOrigin.Y() >= 0 ) - if( aScaleY.GetNumerator() >= 0 ) - aY += BigInt( aScaleY.GetNumerator()/2 ); + if( aScaleY.numerator() >= 0 ) + aY += BigInt( aScaleY.numerator()/2 ); else - aY -= BigInt( (aScaleY.GetNumerator()+1)/2 ); + aY -= BigInt( (aScaleY.numerator()+1)/2 ); else - if( aScaleY.GetNumerator() >= 0 ) - aY -= BigInt( (aScaleY.GetNumerator()-1)/2 ); + if( aScaleY.numerator() >= 0 ) + aY -= BigInt( (aScaleY.numerator()-1)/2 ); else - aY += BigInt( aScaleY.GetNumerator()/2 ); - aY /= BigInt( aScaleY.GetNumerator() ); + aY += BigInt( aScaleY.numerator()/2 ); + aY /= BigInt( aScaleY.numerator() ); aOrigin.Y() = (long)aY + aMM.GetOrigin().Y(); aSrcMapMode.SetOrigin( aOrigin ); @@ -1730,7 +1730,7 @@ bool WMFWriter::WriteWMF( const GDIMetaFile& rMTF, SvStream& rTargetStream, aTargetMapMode = MapMode( MAP_INCH ); const long nUnit = pVirDev->LogicToPixel( Size( 1, 1 ), aTargetMapMode ).Width(); - const Fraction aFrac( 1, nUnit ); + const boost::rational<long> aFrac( 1, nUnit ); aTargetMapMode.SetScaleX( aFrac ); aTargetMapMode.SetScaleY( aFrac ); @@ -1814,14 +1814,14 @@ bool WMFWriter::WriteWMF( const GDIMetaFile& rMTF, SvStream& rTargetStream, sal_uInt16 WMFWriter::CalcSaveTargetMapMode(MapMode& rMapMode, const Size& rPrefSize) { - Fraction aDivFrac(2, 1); + boost::rational<long> aDivFrac(2, 1); sal_uInt16 nDivisor = 1; Size aSize = OutputDevice::LogicToLogic( rPrefSize, aSrcMapMode, rMapMode ); while( nDivisor <= 64 && (aSize.Width() > 32767 || aSize.Height() > 32767) ) { - Fraction aFrac = rMapMode.GetScaleX(); + boost::rational<long> aFrac = rMapMode.GetScaleX(); aFrac *= aDivFrac; rMapMode.SetScaleX(aFrac); diff --git a/vcl/source/gdi/cvtsvm.cxx b/vcl/source/gdi/cvtsvm.cxx index 1caf85742d6a..2667f23b419e 100644 --- a/vcl/source/gdi/cvtsvm.cxx +++ b/vcl/source/gdi/cvtsvm.cxx @@ -139,17 +139,17 @@ void ImplReadMapMode( SvStream& rIStm, MapMode& rMapMode ) rIStm.ReadInt16( nUnit ); ReadPair( rIStm, aOrg ); rIStm.ReadInt32( nXNum ).ReadInt32( nXDenom ).ReadInt32( nYNum ).ReadInt32( nYDenom ); - rMapMode = MapMode( (MapUnit) nUnit, aOrg, Fraction( nXNum, nXDenom ), Fraction( nYNum, nYDenom ) ); + rMapMode = MapMode( (MapUnit) nUnit, aOrg, boost::rational<long>( nXNum, nXDenom ), boost::rational<long>( nYNum, nYDenom ) ); } void ImplWriteMapMode( SvStream& rOStm, const MapMode& rMapMode ) { rOStm.WriteInt16( rMapMode.GetMapUnit() ); WritePair( rOStm, rMapMode.GetOrigin() ); - rOStm.WriteInt32( rMapMode.GetScaleX().GetNumerator() ); - rOStm.WriteInt32( rMapMode.GetScaleX().GetDenominator() ); - rOStm.WriteInt32( rMapMode.GetScaleY().GetNumerator() ); - rOStm.WriteInt32( rMapMode.GetScaleY().GetDenominator() ); + rOStm.WriteInt32( rMapMode.GetScaleX().numerator() ); + rOStm.WriteInt32( rMapMode.GetScaleX().denominator() ); + rOStm.WriteInt32( rMapMode.GetScaleY().numerator() ); + rOStm.WriteInt32( rMapMode.GetScaleY().denominator() ); } void ImplWritePushAction( SvStream& rOStm ) diff --git a/vcl/source/gdi/dibtools.cxx b/vcl/source/gdi/dibtools.cxx index a37d5c21e3a0..2e503ed7dc6b 100644 --- a/vcl/source/gdi/dibtools.cxx +++ b/vcl/source/gdi/dibtools.cxx @@ -766,8 +766,8 @@ bool ImplReadDIBBody( SvStream& rIStm, Bitmap& rBmp, Bitmap* pBmpAlpha, sal_uLon MapMode aMapMode( MAP_MM, Point(), - Fraction(1000, aHeader.nXPelsPerMeter), - Fraction(1000, aHeader.nYPelsPerMeter)); + boost::rational<long>(1000, aHeader.nXPelsPerMeter), + boost::rational<long>(1000, aHeader.nYPelsPerMeter)); aNewBmp.SetPrefMapMode(aMapMode); aNewBmp.SetPrefSize(Size(aHeader.nWidth, aHeader.nHeight)); diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx index d6b8e51da237..b1e4f8e7d29f 100644 --- a/vcl/source/gdi/gdimtf.cxx +++ b/vcl/source/gdi/gdimtf.cxx @@ -550,8 +550,8 @@ void GDIMetaFile::Play( OutputDevice* pOut, const Point& rPos, if( !aTmpPrefSize.Height() ) aTmpPrefSize.Height() = aDestSize.Height(); - Fraction aScaleX( aDestSize.Width(), aTmpPrefSize.Width() ); - Fraction aScaleY( aDestSize.Height(), aTmpPrefSize.Height() ); + boost::rational<long> aScaleX( aDestSize.Width(), aTmpPrefSize.Width() ); + boost::rational<long> aScaleY( aDestSize.Height(), aTmpPrefSize.Height() ); aScaleX *= aDrawMap.GetScaleX(); aDrawMap.SetScaleX( aScaleX ); aScaleY *= aDrawMap.GetScaleY(); aDrawMap.SetScaleY( aScaleY ); @@ -784,8 +784,8 @@ void GDIMetaFile::Move( long nX, long nY, long nDPIX, long nDPIY ) { aOffset = aMapVDev.LogicToPixel( aBaseOffset, GetPrefMapMode() ); MapMode aMap( aMapVDev.GetMapMode() ); - aOffset.Width() = static_cast<long>(aOffset.Width() * (double)aMap.GetScaleX()); - aOffset.Height() = static_cast<long>(aOffset.Height() * (double)aMap.GetScaleY()); + aOffset.Width() = static_cast<long>(aOffset.Width() * boost::rational_cast<double>(aMap.GetScaleX())); + aOffset.Height() = static_cast<long>(aOffset.Height() * boost::rational_cast<double>(aMap.GetScaleY())); } else aOffset = OutputDevice::LogicToLogic( aBaseOffset, GetPrefMapMode(), aMapVDev.GetMapMode() ); @@ -816,9 +816,9 @@ void GDIMetaFile::Scale( double fScaleX, double fScaleY ) aPrefSize.Height() = FRound( aPrefSize.Height() * fScaleY ); } -void GDIMetaFile::Scale( const Fraction& rScaleX, const Fraction& rScaleY ) +void GDIMetaFile::Scale( const boost::rational<long>& rScaleX, const boost::rational<long>& rScaleY ) { - Scale( (double) rScaleX, (double) rScaleY ); + Scale( boost::rational_cast<double>(rScaleX), boost::rational_cast<double>(rScaleY) ); } void GDIMetaFile::Clip( const Rectangle& i_rClipRect ) diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index d48432941f0c..9ec9a2887728 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -1039,8 +1039,8 @@ bool ImpGraphic::ImplReadEmbedded( SvStream& rIStm, bool bSwap ) aSize = Size( nWidth, nHeight ); aMapMode = MapMode( (MapUnit) nMapMode, Point( nOffsX, nOffsY ), - Fraction( nScaleNumX, nScaleDenomX ), - Fraction( nScaleNumY, nScaleDenomY ) ); + boost::rational<long>( nScaleNumX, nScaleDenomX ), + boost::rational<long>( nScaleNumY, nScaleDenomY ) ); } nHeaderLen = rIStm.Tell() - nStartPos; @@ -1246,10 +1246,10 @@ bool ImpGraphic::ImplWriteEmbedded( SvStream& rOStm ) rOStm.WriteInt32( aSize.Width() ); rOStm.WriteInt32( aSize.Height() ); rOStm.WriteInt32( aMapMode.GetMapUnit() ); - rOStm.WriteInt32( aMapMode.GetScaleX().GetNumerator() ); - rOStm.WriteInt32( aMapMode.GetScaleX().GetDenominator() ); - rOStm.WriteInt32( aMapMode.GetScaleY().GetNumerator() ); - rOStm.WriteInt32( aMapMode.GetScaleY().GetDenominator() ); + rOStm.WriteInt32( aMapMode.GetScaleX().numerator() ); + rOStm.WriteInt32( aMapMode.GetScaleX().denominator() ); + rOStm.WriteInt32( aMapMode.GetScaleY().numerator() ); + rOStm.WriteInt32( aMapMode.GetScaleY().denominator() ); rOStm.WriteInt32( aMapMode.GetOrigin().X() ); rOStm.WriteInt32( aMapMode.GetOrigin().Y() ); } diff --git a/vcl/source/gdi/mapmod.cxx b/vcl/source/gdi/mapmod.cxx index 992898e0164e..2ac95ed54b11 100644 --- a/vcl/source/gdi/mapmod.cxx +++ b/vcl/source/gdi/mapmod.cxx @@ -80,7 +80,7 @@ ImplMapMode* ImplMapMode::ImplGetStaticMapMode( MapUnit eUnit ) ImplMapMode* pImplMapMode = ((ImplMapMode*)aStaticImplMapModeAry)+eUnit; if ( !pImplMapMode->mbSimple ) { - Fraction aDefFraction( 1, 1 ); + boost::rational<long> aDefFraction( 1, 1 ); pImplMapMode->maScaleX = aDefFraction; pImplMapMode->maScaleY = aDefFraction; pImplMapMode->meUnit = eUnit; @@ -125,7 +125,7 @@ MapMode::MapMode( MapUnit eUnit ) } MapMode::MapMode( MapUnit eUnit, const Point& rLogicOrg, - const Fraction& rScaleX, const Fraction& rScaleY ) + const boost::rational<long>& rScaleX, const boost::rational<long>& rScaleY ) { mpImplMapMode = new ImplMapMode; @@ -163,14 +163,14 @@ void MapMode::SetOrigin( const Point& rLogicOrg ) mpImplMapMode->maOrigin = rLogicOrg; } -void MapMode::SetScaleX( const Fraction& rScaleX ) +void MapMode::SetScaleX( const boost::rational<long>& rScaleX ) { ImplMakeUnique(); mpImplMapMode->maScaleX = rScaleX; } -void MapMode::SetScaleY( const Fraction& rScaleY ) +void MapMode::SetScaleY( const boost::rational<long>& rScaleY ) { ImplMakeUnique(); diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index fcaa685ce77e..2fc71954f756 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -1705,7 +1705,7 @@ void PDFWriterImpl::PDFPage::appendWaveLine( sal_Int32 nWidth, sal_Int32 nY, sal PDFWriter& i_rOuterFace) : m_pReferenceDevice( NULL ), - m_aMapMode( MAP_POINT, Point(), Fraction( 1L, pointToPixel(1) ), Fraction( 1L, pointToPixel(1) ) ), + m_aMapMode( MAP_POINT, Point(), boost::rational<long>( 1L, pointToPixel(1) ), boost::rational<long>( 1L, pointToPixel(1) ) ), m_nCurrentStructElement( 0 ), m_bEmitStructure( true ), m_bNewMCID( false ), @@ -7465,7 +7465,7 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const OUString& rText, bool // if the mapmode is distorted we need to adjust for that also if( m_aCurrentPDFState.m_aMapMode.GetScaleX() != m_aCurrentPDFState.m_aMapMode.GetScaleY() ) { - fXScale *= double(m_aCurrentPDFState.m_aMapMode.GetScaleX()) / double(m_aCurrentPDFState.m_aMapMode.GetScaleY()); + fXScale *= boost::rational_cast<double>(m_aCurrentPDFState.m_aMapMode.GetScaleX()) / boost::rational_cast<double>(m_aCurrentPDFState.m_aMapMode.GetScaleY()); } int nAngle = m_aCurrentPDFState.m_aFont.GetOrientation(); diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx index 3c0aaf7f76b5..a43e61245e52 100644 --- a/vcl/source/gdi/pdfwriter_impl2.cxx +++ b/vcl/source/gdi/pdfwriter_impl2.cxx @@ -497,8 +497,8 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa MapMode aMapMode( aSubstitute.GetPrefMapMode() ); Size aOutSize( OutputDevice::LogicToLogic( pA->GetSize(), pDummyVDev->GetMapMode(), aMapMode ) ); - aMapMode.SetScaleX( Fraction( aOutSize.Width(), aSubstitute.GetPrefSize().Width() ) ); - aMapMode.SetScaleY( Fraction( aOutSize.Height(), aSubstitute.GetPrefSize().Height() ) ); + aMapMode.SetScaleX( boost::rational<long>( aOutSize.Width(), aSubstitute.GetPrefSize().Width() ) ); + aMapMode.SetScaleY( boost::rational<long>( aOutSize.Height(), aSubstitute.GetPrefSize().Height() ) ); aMapMode.SetOrigin( OutputDevice::LogicToLogic( pA->GetPoint(), pDummyVDev->GetMapMode(), aMapMode ) ); m_rOuterFace.SetMapMode( aMapMode ); diff --git a/vcl/source/gdi/textlayout.cxx b/vcl/source/gdi/textlayout.cxx index f7d3b81d3cac..237971dbff8b 100644 --- a/vcl/source/gdi/textlayout.cxx +++ b/vcl/source/gdi/textlayout.cxx @@ -103,7 +103,7 @@ namespace vcl OutputDevice& m_rTargetDevice; OutputDevice& m_rReferenceDevice; Font m_aUnzoomedPointFont; - const Fraction m_aZoom; + const boost::rational<long> m_aZoom; const bool m_bRTLEnabled; Rectangle m_aCompleteTextRect; diff --git a/vcl/source/gdi/virdev.cxx b/vcl/source/gdi/virdev.cxx index bfd57164abbd..1655dd664174 100644 --- a/vcl/source/gdi/virdev.cxx +++ b/vcl/source/gdi/virdev.cxx @@ -451,7 +451,7 @@ bool VirtualDevice::SetOutputSizePixel( const Size& rNewSize, bool bErase ) } bool VirtualDevice::SetOutputSizePixelScaleOffsetAndBuffer( - const Size& rNewSize, const Fraction& rScale, const Point& rNewOffset, + const Size& rNewSize, const boost::rational<long>& rScale, const Point& rNewOffset, const basebmp::RawMemorySharedArray &pBuffer, const bool bTopDown ) { if (pBuffer) { diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx index 0a7733df8253..0931f79e369e 100644 --- a/vcl/source/outdev/font.cxx +++ b/vcl/source/outdev/font.cxx @@ -122,7 +122,7 @@ Size OutputDevice::GetDevFontSize( const vcl::Font& rFont, int nSizeIndex ) cons if ( mbMap ) { aSize.Height() *= 10; - 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 ) ); aSize = PixelToLogic( aSize, aMap ); aSize.Height() += 5; aSize.Height() /= 10; diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx index 125b8e33345b..9de77a74bb23 100644 --- a/vcl/source/outdev/map.cxx +++ b/vcl/source/outdev/map.cxx @@ -43,41 +43,14 @@ Reduces accuracy until it is a fraction (should become ctor fraction once); we could also do this with BigInts */ -static Fraction ImplMakeFraction( long nN1, long nN2, long nD1, long nD2 ) +static boost::rational<long> ImplMakeFraction( long nN1, long nN2, long nD1, long nD2 ) { - long i = 1; - - if ( nN1 < 0 ) { i = -i; nN1 = -nN1; } - if ( nN2 < 0 ) { i = -i; nN2 = -nN2; } - if ( nD1 < 0 ) { i = -i; nD1 = -nD1; } - if ( nD2 < 0 ) { i = -i; nD2 = -nD2; } - // all positive; i sign - - Fraction aF( i*nN1, nD1 ); - aF *= Fraction( nN2, nD2 ); - - if( nD1 == 0 || nD2 == 0 ) //under these bad circumstances the following while loop will be endless + if( nD1 == 0 || nD2 == 0 ) { DBG_ASSERT(false,"Invalid parameter for ImplMakeFraction"); - return Fraction( 1, 1 ); - } - - while ( aF.GetDenominator() == -1 ) - { - if ( nN1 > nN2 ) - nN1 = (nN1 + 1) / 2; - else - nN2 = (nN2 + 1) / 2; - if ( nD1 > nD2 ) - nD1 = (nD1 + 1) / 2; - else - nD2 = (nD2 + 1) / 2; - - aF = Fraction( i*nN1, nD1 ); - aF *= Fraction( nN2, nD2 ); + return boost::rational<long>( 1, 1 ); } - - return aF; + return boost::rational<long>( nN1, nD1 ) * boost::rational<long>( nN2, nD2 ); } // Fraction.GetNumerator() @@ -247,8 +220,8 @@ static void ImplCalcMapResolution( const MapMode& rMapMode, break; } - Fraction aScaleX = rMapMode.GetScaleX(); - Fraction aScaleY = rMapMode.GetScaleY(); + boost::rational<long> aScaleX = rMapMode.GetScaleX(); + boost::rational<long> aScaleY = rMapMode.GetScaleY(); // set offset according to MapMode Point aOrigin = rMapMode.GetOrigin(); @@ -261,70 +234,70 @@ static void ImplCalcMapResolution( const MapMode& rMapMode, } else { - rMapRes.mfOffsetX *= aScaleX.GetDenominator(); - rMapRes.mfOffsetX /= aScaleX.GetNumerator(); + rMapRes.mfOffsetX *= aScaleX.denominator(); + rMapRes.mfOffsetX /= aScaleX.numerator(); rMapRes.mfOffsetX += aOrigin.X(); - rMapRes.mfOffsetY *= aScaleY.GetDenominator(); - rMapRes.mfOffsetY /= aScaleY.GetNumerator(); + rMapRes.mfOffsetY *= aScaleY.denominator(); + rMapRes.mfOffsetY /= aScaleY.numerator(); rMapRes.mfOffsetY += aOrigin.Y(); BigInt aX( rMapRes.mnMapOfsX ); - aX *= BigInt( aScaleX.GetDenominator() ); + aX *= BigInt( aScaleX.denominator() ); if ( rMapRes.mnMapOfsX >= 0 ) { - if ( aScaleX.GetNumerator() >= 0 ) - aX += BigInt( aScaleX.GetNumerator()/2 ); + if ( aScaleX.numerator() >= 0 ) + aX += BigInt( aScaleX.numerator()/2 ); else - aX -= BigInt( (aScaleX.GetNumerator()+1)/2 ); + aX -= BigInt( (aScaleX.numerator()+1)/2 ); } else { - if ( aScaleX.GetNumerator() >= 0 ) - aX -= BigInt( (aScaleX.GetNumerator()-1)/2 ); + if ( aScaleX.numerator() >= 0 ) + aX -= BigInt( (aScaleX.numerator()-1)/2 ); else - aX += BigInt( aScaleX.GetNumerator()/2 ); + aX += BigInt( aScaleX.numerator()/2 ); } - aX /= BigInt( aScaleX.GetNumerator() ); + aX /= BigInt( aScaleX.numerator() ); rMapRes.mnMapOfsX = (long)aX + aOrigin.X(); BigInt aY( rMapRes.mnMapOfsY ); - aY *= BigInt( aScaleY.GetDenominator() ); + aY *= BigInt( aScaleY.denominator() ); if( rMapRes.mnMapOfsY >= 0 ) { - if ( aScaleY.GetNumerator() >= 0 ) - aY += BigInt( aScaleY.GetNumerator()/2 ); + if ( aScaleY.numerator() >= 0 ) + aY += BigInt( aScaleY.numerator()/2 ); else - aY -= BigInt( (aScaleY.GetNumerator()+1)/2 ); + aY -= BigInt( (aScaleY.numerator()+1)/2 ); } else { - if ( aScaleY.GetNumerator() >= 0 ) - aY -= BigInt( (aScaleY.GetNumerator()-1)/2 ); + if ( aScaleY.numerator() >= 0 ) + aY -= BigInt( (aScaleY.numerator()-1)/2 ); else - aY += BigInt( aScaleY.GetNumerator()/2 ); + aY += BigInt( aScaleY.numerator()/2 ); } - aY /= BigInt( aScaleY.GetNumerator() ); + aY /= BigInt( aScaleY.numerator() ); rMapRes.mnMapOfsY = (long)aY + aOrigin.Y(); } - rMapRes.mfScaleX *= (double)rMapRes.mnMapScNumX * (double)aScaleX.GetNumerator() / - ((double)rMapRes.mnMapScDenomX * (double)aScaleX.GetDenominator()); - rMapRes.mfScaleY *= (double)rMapRes.mnMapScNumY * (double)aScaleY.GetNumerator() / - ((double)rMapRes.mnMapScDenomY * (double)aScaleY.GetDenominator()); + rMapRes.mfScaleX *= (double)rMapRes.mnMapScNumX * (double)aScaleX.numerator() / + ((double)rMapRes.mnMapScDenomX * (double)aScaleX.denominator()); + rMapRes.mfScaleY *= (double)rMapRes.mnMapScNumY * (double)aScaleY.numerator() / + ((double)rMapRes.mnMapScDenomY * (double)aScaleY.denominator()); // calculate scaling factor according to MapMode // aTemp? = rMapRes.mnMapSc? * aScale? - Fraction aTempX = ImplMakeFraction( rMapRes.mnMapScNumX, - aScaleX.GetNumerator(), + boost::rational<long> aTempX = ImplMakeFraction( rMapRes.mnMapScNumX, + aScaleX.numerator(), rMapRes.mnMapScDenomX, - aScaleX.GetDenominator() ); - Fraction aTempY = ImplMakeFraction( rMapRes.mnMapScNumY, - aScaleY.GetNumerator(), + aScaleX.denominator() ); + boost::rational<long> aTempY = ImplMakeFraction( rMapRes.mnMapScNumY, + aScaleY.numerator(), rMapRes.mnMapScDenomY, - aScaleY.GetDenominator() ); - rMapRes.mnMapScNumX = aTempX.GetNumerator(); - rMapRes.mnMapScDenomX = aTempX.GetDenominator(); - rMapRes.mnMapScNumY = aTempY.GetNumerator(); - rMapRes.mnMapScDenomY = aTempY.GetDenominator(); + aScaleY.denominator() ); + rMapRes.mnMapScNumX = aTempX.numerator(); + rMapRes.mnMapScDenomX = aTempX.denominator(); + rMapRes.mnMapScNumY = aTempY.numerator(); + rMapRes.mnMapScDenomY = aTempY.denominator(); // hack: 0/n approximately 1/max if ( !rMapRes.mnMapScNumX ) @@ -766,14 +739,14 @@ void OutputDevice::SetMapMode( const MapMode& rNewMapMode ) { Point aOrigin( maMapRes.mnMapOfsX, maMapRes.mnMapOfsY ); // aScale? = maMapMode.GetScale?() * rNewMapMode.GetScale?() - Fraction aScaleX = ImplMakeFraction( maMapMode.GetScaleX().GetNumerator(), - rNewMapMode.GetScaleX().GetNumerator(), - maMapMode.GetScaleX().GetDenominator(), - rNewMapMode.GetScaleX().GetDenominator() ); - Fraction aScaleY = ImplMakeFraction( maMapMode.GetScaleY().GetNumerator(), - rNewMapMode.GetScaleY().GetNumerator(), - maMapMode.GetScaleY().GetDenominator(), - rNewMapMode.GetScaleY().GetDenominator() ); + boost::rational<long> aScaleX = ImplMakeFraction( maMapMode.GetScaleX().numerator(), + rNewMapMode.GetScaleX().numerator(), + maMapMode.GetScaleX().denominator(), + rNewMapMode.GetScaleX().denominator() ); + boost::rational<long> aScaleY = ImplMakeFraction( maMapMode.GetScaleY().numerator(), + rNewMapMode.GetScaleY().numerator(), + maMapMode.GetScaleY().denominator(), + rNewMapMode.GetScaleY().denominator() ); maMapMode.SetOrigin( aOrigin ); maMapMode.SetScaleX( aScaleX ); maMapMode.SetScaleY( aScaleY ); @@ -812,14 +785,14 @@ void OutputDevice::SetRelativeMapMode( const MapMode& rNewMapMode ) MapUnit eNew = rNewMapMode.GetMapUnit(); // a?F = rNewMapMode.GetScale?() / maMapMode.GetScale?() - Fraction aXF = ImplMakeFraction( rNewMapMode.GetScaleX().GetNumerator(), - maMapMode.GetScaleX().GetDenominator(), - rNewMapMode.GetScaleX().GetDenominator(), - maMapMode.GetScaleX().GetNumerator() ); - Fraction aYF = ImplMakeFraction( rNewMapMode.GetScaleY().GetNumerator(), - maMapMode.GetScaleY().GetDenominator(), - rNewMapMode.GetScaleY().GetDenominator(), - maMapMode.GetScaleY().GetNumerator() ); + boost::rational<long> aXF = ImplMakeFraction( rNewMapMode.GetScaleX().numerator(), + maMapMode.GetScaleX().denominator(), + rNewMapMode.GetScaleX().denominator(), + maMapMode.GetScaleX().numerator() ); + boost::rational<long> aYF = ImplMakeFraction( rNewMapMode.GetScaleY().numerator(), + maMapMode.GetScaleY().denominator(), + rNewMapMode.GetScaleY().denominator(), + maMapMode.GetScaleY().numerator() ); Point aPt( LogicToLogic( Point(), NULL, &rNewMapMode ) ); if ( eNew != eOld ) @@ -834,23 +807,23 @@ void OutputDevice::SetRelativeMapMode( const MapMode& rNewMapMode ) } else { - Fraction aF( aImplNumeratorAry[eNew] * aImplDenominatorAry[eOld], + boost::rational<long> aF( aImplNumeratorAry[eNew] * aImplDenominatorAry[eOld], aImplNumeratorAry[eOld] * aImplDenominatorAry[eNew] ); // a?F = a?F * aF - aXF = ImplMakeFraction( aXF.GetNumerator(), aF.GetNumerator(), - aXF.GetDenominator(), aF.GetDenominator() ); - aYF = ImplMakeFraction( aYF.GetNumerator(), aF.GetNumerator(), - aYF.GetDenominator(), aF.GetDenominator() ); + aXF = ImplMakeFraction( aXF.numerator(), aF.numerator(), + aXF.denominator(), aF.denominator() ); + aYF = ImplMakeFraction( aYF.numerator(), aF.numerator(), + aYF.denominator(), aF.denominator() ); if ( eOld == MAP_PIXEL ) { - aXF *= Fraction( mnDPIX, 1 ); - aYF *= Fraction( mnDPIY, 1 ); + aXF *= boost::rational<long>( mnDPIX, 1 ); + aYF *= boost::rational<long>( mnDPIY, 1 ); } else if ( eNew == MAP_PIXEL ) { - aXF *= Fraction( 1, mnDPIX ); - aYF *= Fraction( 1, mnDPIY ); + aXF *= boost::rational<long>( 1, mnDPIX ); + aYF *= boost::rational<long>( 1, mnDPIY ); } } } diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index 8b52d5c5804e..be0e35cd1613 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -572,7 +572,7 @@ Window::~Window() WindowImpl::WindowImpl( WindowType nType ) { - maZoom = Fraction( 1, 1 ); + maZoom = boost::rational<long>( 1, 1 ); maWinRegion = vcl::Region(true); maWinClipRegion = vcl::Region(true); mpWinData = NULL; // Extra Window Data, that we dont need for all windows diff --git a/vcl/source/window/window2.cxx b/vcl/source/window/window2.cxx index 48faf1f2f8f7..f3588f59e548 100644 --- a/vcl/source/window/window2.cxx +++ b/vcl/source/window/window2.cxx @@ -507,7 +507,7 @@ bool Window::EndSaveFocus( sal_uIntPtr nSaveId, bool bRestore ) } } -void Window::SetZoom( const Fraction& rZoom ) +void Window::SetZoom( const boost::rational<long>& rZoom ) { if ( mpWindowImpl->maZoom != rZoom ) { @@ -523,18 +523,18 @@ inline long WinFloatRound( double fVal ) void Window::SetZoomedPointFont( const vcl::Font& rFont ) { - const Fraction& rZoom = GetZoom(); - if ( rZoom.GetNumerator() != rZoom.GetDenominator() ) + const boost::rational<long>& rZoom = GetZoom(); + if ( rZoom.numerator() != rZoom.denominator() ) { vcl::Font aFont( rFont ); Size aSize = aFont.GetSize(); double n = (double)aSize.Width(); - n *= (double)rZoom.GetNumerator(); - n /= (double)rZoom.GetDenominator(); + n *= (double)rZoom.numerator(); + n /= (double)rZoom.denominator(); aSize.Width() = WinFloatRound( n ); n = (double)aSize.Height(); - n *= (double)rZoom.GetNumerator(); - n /= (double)rZoom.GetDenominator(); + n *= (double)rZoom.numerator(); + n /= (double)rZoom.denominator(); aSize.Height() = WinFloatRound( n ); aFont.SetSize( aSize ); SetPointFont( aFont ); @@ -562,12 +562,12 @@ void Window::SetZoomedPointFont( const vcl::Font& rFont ) long Window::CalcZoom( long nCalc ) const { - const Fraction& rZoom = GetZoom(); - if ( rZoom.GetNumerator() != rZoom.GetDenominator() ) + const boost::rational<long>& rZoom = GetZoom(); + if ( rZoom.numerator() != rZoom.denominator() ) { double n = (double)nCalc; - n *= (double)rZoom.GetNumerator(); - n /= (double)rZoom.GetDenominator(); + n *= (double)rZoom.numerator(); + n /= (double)rZoom.denominator(); nCalc = WinFloatRound( n ); } return nCalc; @@ -1318,14 +1318,14 @@ vcl::Cursor* Window::GetCursor() const return mpWindowImpl->mpCursor; } -const Fraction& Window::GetZoom() const +const boost::rational<long>& Window::GetZoom() const { return mpWindowImpl->maZoom; } bool Window::IsZoom() const { - return mpWindowImpl->maZoom.GetNumerator() != mpWindowImpl->maZoom.GetDenominator(); + return mpWindowImpl->maZoom.numerator() != mpWindowImpl->maZoom.denominator(); } void Window::SetHelpText( const OUString& rHelpText ) |