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 /filter/source/graphicfilter | |
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 'filter/source/graphicfilter')
-rw-r--r-- | filter/source/graphicfilter/eos2met/eos2met.cxx | 36 | ||||
-rw-r--r-- | filter/source/graphicfilter/epict/epict.cxx | 38 | ||||
-rw-r--r-- | filter/source/graphicfilter/eps/eps.cxx | 4 | ||||
-rw-r--r-- | filter/source/graphicfilter/ios2met/ios2met.cxx | 4 | ||||
-rw-r--r-- | filter/source/graphicfilter/ipict/ipict.cxx | 6 | ||||
-rw-r--r-- | filter/source/graphicfilter/ipsd/ipsd.cxx | 4 | ||||
-rw-r--r-- | filter/source/graphicfilter/itiff/itiff.cxx | 2 |
7 files changed, 47 insertions, 47 deletions
diff --git a/filter/source/graphicfilter/eos2met/eos2met.cxx b/filter/source/graphicfilter/eos2met/eos2met.cxx index d1a145941272..33f5f514b713 100644 --- a/filter/source/graphicfilter/eos2met/eos2met.cxx +++ b/filter/source/graphicfilter/eos2met/eos2met.cxx @@ -2169,50 +2169,50 @@ void METWriter::WriteOrders( const GDIMetaFile* pMTF ) 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 = aPictureMapMode.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.numerator()/2 ); } - aX /= BigInt( aScaleX.GetNumerator() ); + 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.numerator()/2 ); } - aY /= BigInt( aScaleY.GetNumerator() ); + aY /= BigInt( aScaleY.numerator() ); aOrigin.Y() = (long)aY + aMM.GetOrigin().Y(); aPictureMapMode.SetOrigin( aOrigin ); diff --git a/filter/source/graphicfilter/epict/epict.cxx b/filter/source/graphicfilter/epict/epict.cxx index 1aad8c1e22db..b0f61f328bc6 100644 --- a/filter/source/graphicfilter/epict/epict.cxx +++ b/filter/source/graphicfilter/epict/epict.cxx @@ -1962,48 +1962,48 @@ void PictWriter::WriteOpcodes( 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.numerator()/2 ); } - aX /= BigInt( aScaleX.GetNumerator() ); + 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.numerator()/2 ); } - aY /= BigInt( aScaleY.GetNumerator() ); + aY /= BigInt( aScaleY.numerator() ); aOrigin.Y() = (long)aY + aMM.GetOrigin().Y(); aSrcMapMode.SetOrigin( aOrigin ); @@ -2183,7 +2183,7 @@ bool PictWriter::WritePict(const GDIMetaFile & rMTF, SvStream & rTargetStream, F { PictWriterAttrStackMember* pAt; MapMode aMap72( MAP_INCH ); - Fraction aDPIFrac( 1, 72 ); + boost::rational<long> aDPIFrac( 1, 72 ); bStatus=true; nLastPercent=0; diff --git a/filter/source/graphicfilter/eps/eps.cxx b/filter/source/graphicfilter/eps/eps.cxx index 19465a6505bd..c9b1314078db 100644 --- a/filter/source/graphicfilter/eps/eps.cxx +++ b/filter/source/graphicfilter/eps/eps.cxx @@ -2376,8 +2376,8 @@ void PSWriter::ImplGetMapMode( const MapMode& rMapMode ) { ImplWriteLine( "tm setmatrix" ); double fMul = ImplGetScaling( rMapMode ); - double fScaleX = (double)rMapMode.GetScaleX() * fMul; - double fScaleY = (double)rMapMode.GetScaleY() * fMul; + double fScaleX = boost::rational_cast<double>(rMapMode.GetScaleX()) * fMul; + double fScaleY = boost::rational_cast<double>(rMapMode.GetScaleY()) * fMul; ImplTranslate( rMapMode.GetOrigin().X() * fScaleX, rMapMode.GetOrigin().Y() * fScaleY ); ImplScale( fScaleX, fScaleY ); } diff --git a/filter/source/graphicfilter/ios2met/ios2met.cxx b/filter/source/graphicfilter/ios2met/ios2met.cxx index cc2d6bbecef7..f3b61dcafae6 100644 --- a/filter/source/graphicfilter/ios2met/ios2met.cxx +++ b/filter/source/graphicfilter/ios2met/ios2met.cxx @@ -2125,9 +2125,9 @@ void OS2METReader::ReadDsc(sal_uInt16 nDscID, sal_uInt16 /*nDscLen*/) ReadCoord(b32); if (nUnitType==0x00 && xr>0 && yr>0) - aGlobMapMode=MapMode(MAP_INCH,Point(0,0),Fraction(10,xr),Fraction(10,yr)); + aGlobMapMode=MapMode(MAP_INCH,Point(0,0),boost::rational<long>(10,xr),boost::rational<long>(10,yr)); else if (nUnitType==0x01 && xr>0 && yr>0) - aGlobMapMode=MapMode(MAP_CM,Point(0,0),Fraction(10,xr),Fraction(10,yr)); + aGlobMapMode=MapMode(MAP_CM,Point(0,0),boost::rational<long>(10,xr),boost::rational<long>(10,yr)); else aGlobMapMode=MapMode(); diff --git a/filter/source/graphicfilter/ipict/ipict.cxx b/filter/source/graphicfilter/ipict/ipict.cxx index 41ba717b6b13..b0d07d805a3b 100644 --- a/filter/source/graphicfilter/ipict/ipict.cxx +++ b/filter/source/graphicfilter/ipict/ipict.cxx @@ -166,8 +166,8 @@ private: Size aActOvalSize; vcl::Font aActFont; - Fraction aHRes; - Fraction aVRes; + boost::rational<long> aHRes; + boost::rational<long> aVRes; bool Callback(sal_uInt16 nPercent); @@ -1841,7 +1841,7 @@ void PictReader::ReadPict( SvStream & rStreamPict, GDIMetaFile & rGDIMetaFile ) aActFont.SetSize(Size(0,12)); aActFont.SetAlign(ALIGN_BASELINE); - aHRes = aVRes = Fraction( 1, 1 ); + aHRes = aVRes = boost::rational<long>( 1, 1 ); pVirDev = new VirtualDevice(); pVirDev->EnableOutput(false); diff --git a/filter/source/graphicfilter/ipsd/ipsd.cxx b/filter/source/graphicfilter/ipsd/ipsd.cxx index c95991d5e2da..dbba04cb9983 100644 --- a/filter/source/graphicfilter/ipsd/ipsd.cxx +++ b/filter/source/graphicfilter/ipsd/ipsd.cxx @@ -148,8 +148,8 @@ bool PSDReader::ReadPSD(Graphic & rGraphic ) if ( mnXResFixed && mnYResFixed ) { Point aEmptyPoint; - Fraction aFractX( 1, mnXResFixed >> 16 ); - Fraction aFractY( 1, mnYResFixed >> 16 ); + boost::rational<long> aFractX( 1, mnXResFixed >> 16 ); + boost::rational<long> aFractY( 1, mnYResFixed >> 16 ); MapMode aMapMode( MAP_INCH, aEmptyPoint, aFractX, aFractY ); Size aPrefSize = OutputDevice::LogicToLogic( aBitmapSize, aMapMode, MAP_100TH_MM ); rGraphic.SetPrefSize( aPrefSize ); diff --git a/filter/source/graphicfilter/itiff/itiff.cxx b/filter/source/graphicfilter/itiff/itiff.cxx index 4606271017a9..82575a5d057c 100644 --- a/filter/source/graphicfilter/itiff/itiff.cxx +++ b/filter/source/graphicfilter/itiff/itiff.cxx @@ -1127,7 +1127,7 @@ void TIFFReader::MakePalCol( void ) nRX=(sal_uLong)(fXResolution*2.54+0.5); nRY=(sal_uLong)(fYResolution*2.54+0.5); } - MapMode aMapMode(MAP_INCH,Point(0,0),Fraction(1,nRX),Fraction(1,nRY)); + MapMode aMapMode(MAP_INCH,Point(0,0),boost::rational<long>(1,nRX),boost::rational<long>(1,nRY)); aBitmap.SetPrefMapMode(aMapMode); aBitmap.SetPrefSize(Size(nImageWidth,nImageLength)); } |