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 | |
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')
-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 | ||||
-rw-r--r-- | filter/source/msfilter/eschesdo.cxx | 2 | ||||
-rw-r--r-- | filter/source/msfilter/msdffimp.cxx | 44 | ||||
-rw-r--r-- | filter/source/msfilter/svdfppt.cxx | 6 | ||||
-rw-r--r-- | filter/source/pdf/pdfexport.cxx | 1 | ||||
-rw-r--r-- | filter/source/svg/svgwriter.cxx | 8 |
12 files changed, 77 insertions, 78 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)); } diff --git a/filter/source/msfilter/eschesdo.cxx b/filter/source/msfilter/eschesdo.cxx index 2e9227042eb7..0c2b757284a3 100644 --- a/filter/source/msfilter/eschesdo.cxx +++ b/filter/source/msfilter/eschesdo.cxx @@ -64,7 +64,7 @@ ImplEESdrWriter::ImplEESdrWriter( EscherEx& rEx ) : mpEscherEx(&rEx) , maMapModeSrc(MAP_100TH_MM) // PowerPoint: 576 dpi, WinWord: 1440 dpi, Excel: 1440 dpi - , maMapModeDest( MAP_INCH, Point(), Fraction( 1, EES_MAP_FRACTION ), Fraction( 1, EES_MAP_FRACTION ) ) + , maMapModeDest( MAP_INCH, Point(), boost::rational<long>( 1, EES_MAP_FRACTION ), boost::rational<long>( 1, EES_MAP_FRACTION ) ) , mpPicStrm(NULL) , mpHostAppData(NULL) , mnPagesWritten(0) diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx index 1fe026ce0fed..26db18f9b0f1 100644 --- a/filter/source/msfilter/msdffimp.cxx +++ b/filter/source/msfilter/msdffimp.cxx @@ -170,9 +170,9 @@ void Impl_OlePres::Write( SvStream & rStm ) { // Always to 1/100 mm, until Mtf-Solution found // Assumption (no scaling, no origin translation) - DBG_ASSERT( pMtf->GetPrefMapMode().GetScaleX() == Fraction( 1, 1 ), + DBG_ASSERT( pMtf->GetPrefMapMode().GetScaleX() == boost::rational<long>( 1, 1 ), "X-Skalierung im Mtf" ); - DBG_ASSERT( pMtf->GetPrefMapMode().GetScaleY() == Fraction( 1, 1 ), + DBG_ASSERT( pMtf->GetPrefMapMode().GetScaleY() == boost::rational<long>( 1, 1 ), "Y-Skalierung im Mtf" ); DBG_ASSERT( pMtf->GetPrefMapMode().GetOrigin() == Point(), "Origin-Verschiebung im Mtf" ); @@ -183,8 +183,8 @@ void Impl_OlePres::Write( SvStream & rStm ) Size aS( aPrefS ); aS = OutputDevice::LogicToLogic( aS, nMU, MAP_100TH_MM ); - pMtf->Scale( Fraction( aS.Width(), aPrefS.Width() ), - Fraction( aS.Height(), aPrefS.Height() ) ); + pMtf->Scale( boost::rational<long>( aS.Width(), aPrefS.Width() ), + boost::rational<long>( aS.Height(), aPrefS.Height() ) ); pMtf->SetPrefMapMode( MAP_100TH_MM ); pMtf->SetPrefSize( aS ); } @@ -3088,11 +3088,11 @@ void SvxMSDffManager::ScaleEmu( sal_Int32& rVal ) const sal_uInt32 SvxMSDffManager::ScalePt( sal_uInt32 nVal ) const { MapUnit eMap = pSdrModel->GetScaleUnit(); - Fraction aFact( GetMapFactor( MAP_POINT, eMap ).X() ); - long aMul = aFact.GetNumerator(); - long aDiv = aFact.GetDenominator() * 65536; - aFact = Fraction( aMul, aDiv ); // try again to shorten it - return BigMulDiv( nVal, aFact.GetNumerator(), aFact.GetDenominator() ); + boost::rational<long> aFact( GetMapFactor( MAP_POINT, eMap ).X() ); + long aMul = aFact.numerator(); + long aDiv = aFact.denominator() * 65536; + aFact = boost::rational<long>( aMul, aDiv ); // try again to shorten it + return BigMulDiv( nVal, aFact.numerator(), aFact.denominator() ); } sal_Int32 SvxMSDffManager::ScalePoint( sal_Int32 nVal ) const @@ -3108,31 +3108,31 @@ void SvxMSDffManager::SetModel(SdrModel* pModel, long nApplicationScale) // PPT works in units of 576DPI // WW on the other side uses twips, i.e. 1440DPI. MapUnit eMap = pSdrModel->GetScaleUnit(); - Fraction aFact( GetMapFactor(MAP_INCH, eMap).X() ); - long nMul=aFact.GetNumerator(); - long nDiv=aFact.GetDenominator()*nApplicationScale; - aFact=Fraction(nMul,nDiv); // try again to shorten it + boost::rational<long> aFact = GetMapFactor(MAP_INCH, eMap).X(); + long nMul=aFact.numerator(); + long nDiv=aFact.denominator()*nApplicationScale; + aFact=boost::rational<long>(nMul,nDiv); // try again to shorten it // For 100TH_MM -> 2540/576=635/144 // For Twip -> 1440/576=5/2 - nMapMul = aFact.GetNumerator(); - nMapDiv = aFact.GetDenominator(); + nMapMul = aFact.numerator(); + nMapDiv = aFact.denominator(); bNeedMap = nMapMul!=nMapDiv; // MS-DFF-Properties are mostly given in EMU (English Metric Units) // 1mm=36000emu, 1twip=635emu aFact=GetMapFactor(MAP_100TH_MM,eMap).X(); - nMul=aFact.GetNumerator(); - nDiv=aFact.GetDenominator()*360; - aFact=Fraction(nMul,nDiv); // try again to shorten it + nMul=aFact.numerator(); + nDiv=aFact.denominator()*360; + aFact=boost::rational<long>(nMul,nDiv); // try again to shorten it // For 100TH_MM -> 1/360 // For Twip -> 14,40/(25,4*360)=144/91440=1/635 - nEmuMul=aFact.GetNumerator(); - nEmuDiv=aFact.GetDenominator(); + nEmuMul=aFact.numerator(); + nEmuDiv=aFact.denominator(); // And something for typographic Points aFact=GetMapFactor(MAP_POINT,eMap).X(); - nPntMul=aFact.GetNumerator(); - nPntDiv=aFact.GetDenominator(); + nPntMul=aFact.numerator(); + nPntDiv=aFact.denominator(); } else { diff --git a/filter/source/msfilter/svdfppt.cxx b/filter/source/msfilter/svdfppt.cxx index e4c54f028c43..b6300bb03d38 100644 --- a/filter/source/msfilter/svdfppt.cxx +++ b/filter/source/msfilter/svdfppt.cxx @@ -2470,9 +2470,9 @@ Size SdrPowerPointImport::GetPageSize() const long nInchMul = 1, nInchDiv = 1; if ( bInch ) { // temporarily convert size (for rounding it) from inch to metric units - Fraction aFact(GetMapFactor(eMap,MAP_100TH_MM).X()); - nInchMul = aFact.GetNumerator(); - nInchDiv = aFact.GetDenominator(); + boost::rational<long> aFact = GetMapFactor(eMap,MAP_100TH_MM).X(); + nInchMul = aFact.numerator(); + nInchDiv = aFact.denominator(); aRet.Width() = BigMulDiv( aRet.Width(), nInchMul, nInchDiv ); aRet.Height() = BigMulDiv( aRet.Height(), nInchMul, nInchDiv ); } diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx index 8aceae6e9307..5d19fd77bd6f 100644 --- a/filter/source/pdf/pdfexport.cxx +++ b/filter/source/pdf/pdfexport.cxx @@ -23,7 +23,6 @@ #include "pdf.hrc" #include "tools/urlobj.hxx" -#include "tools/fract.hxx" #include "tools/poly.hxx" #include "vcl/mapmod.hxx" #include "vcl/virdev.hxx" diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx index 6d2efbad1713..6dff611d8519 100644 --- a/filter/source/svg/svgwriter.cxx +++ b/filter/source/svg/svgwriter.cxx @@ -3583,14 +3583,14 @@ void SVGActionWriter::WriteMetaFile( const Point& rPos100thmm, { MapMode aMapMode( rMtf.GetPrefMapMode() ); Size aPrefSize( rMtf.GetPrefSize() ); - Fraction aFractionX( aMapMode.GetScaleX() ); - Fraction aFractionY( aMapMode.GetScaleY() ); + boost::rational<long> aFractionX = aMapMode.GetScaleX(); + boost::rational<long> aFractionY = aMapMode.GetScaleY(); mpVDev->Push(); Size aSize( OutputDevice::LogicToLogic( rSize100thmm, MAP_100TH_MM, aMapMode ) ); - aMapMode.SetScaleX( aFractionX *= Fraction( aSize.Width(), aPrefSize.Width() ) ); - aMapMode.SetScaleY( aFractionY *= Fraction( aSize.Height(), aPrefSize.Height() ) ); + aMapMode.SetScaleX( aFractionX *= boost::rational<long>( aSize.Width(), aPrefSize.Width() ) ); + aMapMode.SetScaleY( aFractionY *= boost::rational<long>( aSize.Height(), aPrefSize.Height() ) ); Point aOffset( OutputDevice::LogicToLogic( rPos100thmm, MAP_100TH_MM, aMapMode ) ); aMapMode.SetOrigin( aOffset += aMapMode.GetOrigin() ); |