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 /cui/source | |
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 'cui/source')
-rw-r--r-- | cui/source/tabpages/grfpage.cxx | 4 | ||||
-rw-r--r-- | cui/source/tabpages/transfrm.cxx | 28 |
2 files changed, 16 insertions, 16 deletions
diff --git a/cui/source/tabpages/grfpage.cxx b/cui/source/tabpages/grfpage.cxx index 0fcd835987ab..59e24f9f7c34 100644 --- a/cui/source/tabpages/grfpage.cxx +++ b/cui/source/tabpages/grfpage.cxx @@ -812,8 +812,8 @@ void SvxCropExample::SetFrameSize( const Size& rSz ) if(!aFrameSize.Height()) aFrameSize.Height() = 1; Size aWinSize( GetOutputSizePixel() ); - Fraction aXScale( aWinSize.Width() * 4, aFrameSize.Width() * 5 ); - Fraction aYScale( aWinSize.Height() * 4, aFrameSize.Height() * 5 ); + boost::rational<long> aXScale( aWinSize.Width() * 4, aFrameSize.Width() * 5 ); + boost::rational<long> aYScale( aWinSize.Height() * 4, aFrameSize.Height() * 5 ); if( aYScale < aXScale ) aXScale = aYScale; diff --git a/cui/source/tabpages/transfrm.cxx b/cui/source/tabpages/transfrm.cxx index c6273945c7cb..ff024add4d14 100644 --- a/cui/source/tabpages/transfrm.cxx +++ b/cui/source/tabpages/transfrm.cxx @@ -90,9 +90,9 @@ static void lcl_ConvertRect(basegfx::B2DRange& rRange, const sal_uInt16 nDigits, rRange = basegfx::B2DRange(aTopLeft, aBottomRight); } -static void lcl_ScaleRect(basegfx::B2DRange& rRange, const Fraction aUIScale) +static void lcl_ScaleRect(basegfx::B2DRange& rRange, const boost::rational<long> aUIScale) { - const double fFactor(1.0 / double(aUIScale)); + const double fFactor(1.0 / boost::rational_cast<double>(aUIScale)); rRange = basegfx::B2DRange(rRange.getMinimum() * fFactor, rRange.getMaximum() * fFactor); } @@ -254,7 +254,7 @@ void SvxAngleTabPage::Construct() } // take scale into account - const Fraction aUIScale(pView->GetModel()->GetUIScale()); + const boost::rational<long> aUIScale = pView->GetModel()->GetUIScale(); lcl_ScaleRect(maRange, aUIScale); // take UI units into account @@ -274,7 +274,7 @@ bool SvxAngleTabPage::FillItemSet(SfxItemSet* rSet) if(m_pCtlAngle->IsValueModified() || m_pMtrPosX->IsValueModified() || m_pMtrPosY->IsValueModified()) { - const double fUIScale(double(pView->GetModel()->GetUIScale())); + const double fUIScale(boost::rational_cast<double>(this->pView->GetModel()->GetUIScale())); const double fTmpX((GetCoreValue(*m_pMtrPosX, ePoolUnit) + maAnchor.getX()) * fUIScale); const double fTmpY((GetCoreValue(*m_pMtrPosY, ePoolUnit) + maAnchor.getY()) * fUIScale); @@ -292,7 +292,7 @@ bool SvxAngleTabPage::FillItemSet(SfxItemSet* rSet) void SvxAngleTabPage::Reset(const SfxItemSet* rAttrs) { - const double fUIScale(double(pView->GetModel()->GetUIScale())); + const double fUIScale(boost::rational_cast<double>(this->pView->GetModel()->GetUIScale())); const SfxPoolItem* pItem = GetItem( *rAttrs, SID_ATTR_TRANSFORM_ROT_X ); if(pItem) @@ -475,9 +475,9 @@ bool SvxSlantTabPage::FillItemSet(SfxItemSet* rAttrs) if( m_pMtrRadius->IsValueChangedFromSaved() ) { - Fraction aUIScale = pView->GetModel()->GetUIScale(); + boost::rational<long> aUIScale = pView->GetModel()->GetUIScale(); long nTmp = GetCoreValue( *m_pMtrRadius, ePoolUnit ); - nTmp = Fraction( nTmp ) * aUIScale; + nTmp = boost::rational_cast<long>(nTmp * aUIScale); rAttrs->Put( makeSdrEckenradiusItem( nTmp ) ); bModified = true; @@ -527,7 +527,7 @@ void SvxSlantTabPage::Reset(const SfxItemSet* rAttrs) if( pItem ) { - const double fUIScale(double(pView->GetModel()->GetUIScale())); + const double fUIScale(boost::rational_cast<double>(this->pView->GetModel()->GetUIScale())); const double fTmp((double)((const SdrMetricItem*)pItem)->GetValue() / fUIScale); SetMetricValue(*m_pMtrRadius, basegfx::fround(fTmp), ePoolUnit); } @@ -758,7 +758,7 @@ void SvxPositionSizeTabPage::Construct() } // take scale into account - const Fraction aUIScale(mpView->GetModel()->GetUIScale()); + const boost::rational<long> aUIScale = mpView->GetModel()->GetUIScale(); lcl_ScaleRect( maWorkRange, aUIScale ); lcl_ScaleRect( maRange, aUIScale ); @@ -790,7 +790,7 @@ bool SvxPositionSizeTabPage::FillItemSet( SfxItemSet* rOutAttrs ) { if ( m_pMtrPosX->IsValueModified() || m_pMtrPosY->IsValueModified() ) { - const double fUIScale(double(mpView->GetModel()->GetUIScale())); + const double fUIScale(boost::rational_cast<double>(this->mpView->GetModel()->GetUIScale())); double fX((GetCoreValue( *m_pMtrPosX, mePoolUnit ) + maAnchor.getX()) * fUIScale); double fY((GetCoreValue( *m_pMtrPosY, mePoolUnit ) + maAnchor.getY()) * fUIScale); @@ -828,19 +828,19 @@ bool SvxPositionSizeTabPage::FillItemSet( SfxItemSet* rOutAttrs ) if ( m_pMtrWidth->IsValueModified() || m_pMtrHeight->IsValueModified() ) { - Fraction aUIScale = mpView->GetModel()->GetUIScale(); + boost::rational<long> aUIScale = mpView->GetModel()->GetUIScale(); // get Width double nWidth = static_cast<double>(m_pMtrWidth->GetValue( meDlgUnit )); nWidth = MetricField::ConvertDoubleValue( nWidth, m_pMtrWidth->GetBaseValue(), m_pMtrWidth->GetDecimalDigits(), meDlgUnit, FUNIT_100TH_MM ); - long lWidth = long(nWidth * (double)aUIScale); + long lWidth = long(nWidth * boost::rational_cast<double>(aUIScale)); lWidth = OutputDevice::LogicToLogic( lWidth, MAP_100TH_MM, (MapUnit)mePoolUnit ); lWidth = static_cast<long>(m_pMtrWidth->Denormalize( lWidth )); // get Height double nHeight = static_cast<double>(m_pMtrHeight->GetValue( meDlgUnit )); nHeight = MetricField::ConvertDoubleValue( nHeight, m_pMtrHeight->GetBaseValue(), m_pMtrHeight->GetDecimalDigits(), meDlgUnit, FUNIT_100TH_MM ); - long lHeight = long(nHeight * (double)aUIScale); + long lHeight = long(nHeight * boost::rational_cast<double>(aUIScale)); lHeight = OutputDevice::LogicToLogic( lHeight, MAP_100TH_MM, (MapUnit)mePoolUnit ); lHeight = static_cast<long>(m_pMtrHeight->Denormalize( lHeight )); @@ -899,7 +899,7 @@ bool SvxPositionSizeTabPage::FillItemSet( SfxItemSet* rOutAttrs ) void SvxPositionSizeTabPage::Reset( const SfxItemSet* ) { const SfxPoolItem* pItem; - const double fUIScale(double(mpView->GetModel()->GetUIScale())); + const double fUIScale(boost::rational_cast<double>(this->mpView->GetModel()->GetUIScale())); if ( !mbPageDisabled ) { |