diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx index 1a2cc078f184..6e4d0a361b0a 100644 --- a/basic/source/runtime/methods1.cxx +++ b/basic/source/runtime/methods1.cxx @@ -1141,9 +1141,9 @@ static double GetDialogZoomFactor( bool bX, tools::Long nValue ) if( pDevice ) { Size aRefSize( nValue, nValue ); - Fraction aFracX( 1, 26 ); - Fraction aFracY( 1, 24 ); - MapMode aMap( MapUnit::MapAppFont, Point(), aFracX, aFracY ); + double fFracX = 1.0 / 26; + double fFracY = 1.0 / 24; + MapMode aMap( MapUnit::MapAppFont, Point(), fFracX, fFracY ); Size aScaledSize = pDevice->LogicToPixel( aRefSize, aMap ); aRefSize = pDevice->LogicToPixel( aRefSize, MapMode(MapUnit::MapTwip) ); diff --git a/chart2/source/controller/main/ChartController_Window.cxx b/chart2/source/controller/main/ChartController_Window.cxx index 5ca850eed685..3ef1b08e9ca1 100644 --- a/chart2/source/controller/main/ChartController_Window.cxx +++ b/chart2/source/controller/main/ChartController_Window.cxx @@ -249,26 +249,26 @@ void SAL_CALL ChartController::setPosSize( //todo: for standalone chart: detect whether we are standalone //change map mode to fit new size awt::Size aModelPageSize = getChartModel()->getPageSize(); - sal_Int32 nScaleXNumerator = aLogicSize.Width(); - sal_Int32 nScaleXDenominator = aModelPageSize.Width; - sal_Int32 nScaleYNumerator = aLogicSize.Height(); - sal_Int32 nScaleYDenominator = aModelPageSize.Height; + double fScaleX = double(aLogicSize.Width()) / aModelPageSize.Width; + double fScaleY = double(aLogicSize.Height()) / aModelPageSize.Height; MapMode aNewMapMode( MapUnit::Map100thMM, Point(0,0), - Fraction(nScaleXNumerator, nScaleXDenominator), - Fraction(nScaleYNumerator, nScaleYDenominator) ); + fScaleX, + fScaleY ); pChartWindow->SetMapMode(aNewMapMode); pChartWindow->setPosSizePixel( X, Y, Width, Height, static_cast(Flags) ); //#i75867# poor quality of ole's alternative view with 3D scenes and zoomfactors besides 100% if( m_xChartView.is() ) { + Fraction aScaleXFrac(fScaleX); + Fraction aScaleYFrac(fScaleY); auto aZoomFactors(::comphelper::InitPropertySequence({ - { "ScaleXNumerator", uno::Any( nScaleXNumerator ) }, - { "ScaleXDenominator", uno::Any( nScaleXDenominator ) }, - { "ScaleYNumerator", uno::Any( nScaleYNumerator ) }, - { "ScaleYDenominator", uno::Any( nScaleYDenominator ) } + { "ScaleXNumerator", uno::Any( aScaleXFrac.GetNumerator() ) }, + { "ScaleXDenominator", uno::Any( aScaleXFrac.GetDenominator() ) }, + { "ScaleYNumerator", uno::Any( aScaleYFrac.GetNumerator() ) }, + { "ScaleYDenominator", uno::Any( aScaleYFrac.GetDenominator() ) } })); m_xChartView->setPropertyValue( u"ZoomFactors"_ustr, uno::Any( aZoomFactors )); } diff --git a/chart2/source/controller/main/ChartWindow.cxx b/chart2/source/controller/main/ChartWindow.cxx index 44db06c5c368..2f0daadc1c07 100644 --- a/chart2/source/controller/main/ChartWindow.cxx +++ b/chart2/source/controller/main/ChartWindow.cxx @@ -287,20 +287,17 @@ void ChartWindow::LogicInvalidate(const tools::Rectangle* pRectangle) { MapMode aCWMapMode = GetMapMode(); constexpr auto p = o3tl::getConversionMulDiv(o3tl::Length::px, o3tl::Length::twip); - const auto& scaleX = aCWMapMode.GetScaleX(); - const auto& scaleY = aCWMapMode.GetScaleY(); - const auto nXNum = p.first * scaleX.GetDenominator(); - const auto nXDen = p.second * scaleX.GetNumerator(); - const auto nYNum = p.first * scaleY.GetDenominator(); - const auto nYDen = p.second * scaleY.GetNumerator(); + const double scaleX = aCWMapMode.GetScaleX(); + const double scaleY = aCWMapMode.GetScaleY(); + const double nX = p.first * scaleX / p.second; + const double nY = p.first * scaleY / p.second; if (!IsMapModeEnabled()) { - aRectangle = aRectangle.scale(scaleX.GetDenominator(), scaleX.GetNumerator(), - scaleY.GetDenominator(), scaleY.GetNumerator()); + aRectangle = aRectangle.scale(1.0 / scaleX, 1.0 / scaleY); } - Point aOffset = this->GetOffsetPixelFrom(*pEditWin).scale(nXNum, nXDen, nYNum, nYDen); + Point aOffset = this->GetOffsetPixelFrom(*pEditWin).scale(nX, nY); aRectangle = tools::Rectangle(aRectangle.TopLeft() + aOffset, aRectangle.GetSize()); } @@ -355,19 +352,17 @@ tools::Rectangle ChartWindow::GetBoundingBox() // returns the chart bounding box in twips. MapMode aCWMapMode = GetMapMode(); constexpr auto p = o3tl::getConversionMulDiv(o3tl::Length::px, o3tl::Length::twip); - const auto& scaleX = aCWMapMode.GetScaleX(); - const auto& scaleY = aCWMapMode.GetScaleY(); - const auto nXNum = p.first * scaleX.GetDenominator(); - const auto nXDen = p.second * scaleX.GetNumerator(); - const auto nYNum = p.first * scaleY.GetDenominator(); - const auto nYDen = p.second * scaleY.GetNumerator(); + const double scaleX = aCWMapMode.GetScaleX(); + const double scaleY = aCWMapMode.GetScaleY(); + const double nX = p.first * scaleX / p.second; + const double nY = p.first * scaleY / p.second; Point aOffset = GetOffsetPixelFrom(*pRootWin); - aOffset.setX( o3tl::convert(aOffset.X(), nXNum, nXDen) ); - aOffset.setY( o3tl::convert(aOffset.Y(), nYNum, nYDen) ); + aOffset.setX( aOffset.X() * nX ); + aOffset.setY( aOffset.Y() * nY ); Size aSize = GetSizePixel(); - aSize.setWidth( o3tl::convert(aSize.Width(), nXNum, nXDen) ); - aSize.setHeight( o3tl::convert(aSize.Height(), nYNum, nYDen) ); + aSize.setWidth( aSize.Width() * nX ); + aSize.setHeight( aSize.Height() * nY ); aBBox = tools::Rectangle(aOffset, aSize); } return aBBox; diff --git a/cui/source/tabpages/grfpage.cxx b/cui/source/tabpages/grfpage.cxx index a74d44a164e9..65ea7af8dc3f 100644 --- a/cui/source/tabpages/grfpage.cxx +++ b/cui/source/tabpages/grfpage.cxx @@ -824,14 +824,14 @@ void SvxCropExample::SetFrameSize( const Size& rSz ) if (!m_aFrameSize.Height()) m_aFrameSize.setHeight( 1 ); Size aWinSize( GetOutputSizePixel() ); - Fraction aXScale( aWinSize.Width() * 4, m_aFrameSize.Width() * 5 ); - Fraction aYScale( aWinSize.Height() * 4, m_aFrameSize.Height() * 5 ); + double fXScale = double( aWinSize.Width() * 4 ) / (m_aFrameSize.Width() * 5 ); + double fYScale = double( aWinSize.Height() * 4) / (m_aFrameSize.Height() * 5 ); - if( aYScale < aXScale ) - aXScale = aYScale; + if( fYScale < fXScale ) + fXScale = fYScale; - m_aMapMode.SetScaleX(aXScale); - m_aMapMode.SetScaleY(aXScale); + m_aMapMode.SetScaleX(fXScale); + m_aMapMode.SetScaleY(fXScale); Invalidate(); } diff --git a/drawinglayer/source/processor2d/vclprocessor2d.cxx b/drawinglayer/source/processor2d/vclprocessor2d.cxx index f07b4fa85a74..283decc5442c 100644 --- a/drawinglayer/source/processor2d/vclprocessor2d.cxx +++ b/drawinglayer/source/processor2d/vclprocessor2d.cxx @@ -98,7 +98,7 @@ namespace basegfx::B2DHomMatrix getTransformFromMapMode(const MapMode& rMapMode) { basegfx::B2DHomMatrix aMapping; - const Fraction aNoScale(1, 1); + const double fNoScale = 1.0; const Point& rOrigin(rMapMode.GetOrigin()); if (0 != rOrigin.X() || 0 != rOrigin.Y()) @@ -106,9 +106,9 @@ basegfx::B2DHomMatrix getTransformFromMapMode(const MapMode& rMapMode) aMapping.translate(rOrigin.X(), rOrigin.Y()); } - if (rMapMode.GetScaleX() != aNoScale || rMapMode.GetScaleY() != aNoScale) + if (rMapMode.GetScaleX() != fNoScale || rMapMode.GetScaleY() != fNoScale) { - aMapping.scale(double(rMapMode.GetScaleX()), double(rMapMode.GetScaleY())); + aMapping.scale(rMapMode.GetScaleX(), rMapMode.GetScaleY()); } return aMapping; @@ -361,22 +361,11 @@ void VclProcessor2D::RenderTextSimpleOrDecoratedPortionPrimitive2D( basegfx::fround(aCurrentTranslate.getY() / aCurrentScaling.getY())); - Fraction aScaleX(aCurrentScaling.getX()); - if (!aScaleX.IsValid()) - { - SAL_WARN("drawinglayer", "invalid X Scale"); - return; - } + double fScaleX(aCurrentScaling.getX()); + double fScaleY(aCurrentScaling.getY()); - Fraction aScaleY(aCurrentScaling.getY()); - if (!aScaleY.IsValid()) - { - SAL_WARN("drawinglayer", "invalid Y Scale"); - return; - } - - MapMode aMapMode(mpOutputDevice->GetMapMode().GetMapUnit(), aOrigin, aScaleX, - aScaleY); + MapMode aMapMode(mpOutputDevice->GetMapMode().GetMapUnit(), aOrigin, fScaleX, + fScaleY); bChangeMapMode = aMapMode != mpOutputDevice->GetMapMode(); if (bChangeMapMode) { @@ -434,24 +423,17 @@ void VclProcessor2D::RenderTextSimpleOrDecoratedPortionPrimitive2D( aMapMode.SetScaleX(aMapMode.GetScaleX() * nFontScalingFixX); aMapMode.SetScaleY(aMapMode.GetScaleY() * nFontScalingFixY); - const bool bValidScaling - = aMapMode.GetScaleX().IsValid() && aMapMode.GetScaleY().IsValid(); - if (!bValidScaling) - SAL_WARN("drawinglayer", "skipping invalid scaling"); - else - { - assert(nFontScalingFixX != 0 && nFontScalingFixY != 0 - && "or bValidScaling would be false"); + assert(nFontScalingFixX != 0 && nFontScalingFixY != 0 + && "or bValidScaling would be false"); - Point origin = aMapMode.GetOrigin(); + Point origin = aMapMode.GetOrigin(); - mpOutputDevice->Push(vcl::PushFlags::MAPMODE); - mpOutputDevice->SetRelativeMapMode(aMapMode); - bChangeMapMode = true; + mpOutputDevice->Push(vcl::PushFlags::MAPMODE); + mpOutputDevice->SetRelativeMapMode(aMapMode); + bChangeMapMode = true; - aPointX = (aPointX + origin.X()) / nFontScalingFixX - origin.X(); - aPointY = (aPointY + origin.Y()) / nFontScalingFixY - origin.Y(); - } + aPointX = (aPointX + origin.X()) / nFontScalingFixX - origin.X(); + aPointY = (aPointY + origin.Y()) / nFontScalingFixY - origin.Y(); } } diff --git a/drawinglayer/source/tools/wmfemfhelper.cxx b/drawinglayer/source/tools/wmfemfhelper.cxx index 444cb9bd0884..133aeb2051d2 100644 --- a/drawinglayer/source/tools/wmfemfhelper.cxx +++ b/drawinglayer/source/tools/wmfemfhelper.cxx @@ -406,7 +406,7 @@ namespace basegfx::B2DHomMatrix getTransformFromMapMode(const MapMode& rMapMode) { basegfx::B2DHomMatrix aMapping; - const Fraction aNoScale(1, 1); + const double fNoScale = 1.0; const Point& rOrigin(rMapMode.GetOrigin()); if(0 != rOrigin.X() || 0 != rOrigin.Y()) @@ -414,11 +414,9 @@ namespace aMapping.translate(rOrigin.X(), rOrigin.Y()); } - if(rMapMode.GetScaleX() != aNoScale || rMapMode.GetScaleY() != aNoScale) + if(rMapMode.GetScaleX() != fNoScale || rMapMode.GetScaleY() != fNoScale) { - aMapping.scale( - double(rMapMode.GetScaleX()), - double(rMapMode.GetScaleY())); + aMapping.scale(rMapMode.GetScaleX(), rMapMode.GetScaleY()); } return aMapping; diff --git a/emfio/source/reader/wmfreader.cxx b/emfio/source/reader/wmfreader.cxx index 6a321842a794..cb3e130cd551 100644 --- a/emfio/source/reader/wmfreader.cxx +++ b/emfio/source/reader/wmfreader.cxx @@ -1544,8 +1544,8 @@ namespace emfio Size aDevExt( 10000, 10000 ); if( ( std::abs( aWMFSize.Width() ) > 1 ) && ( std::abs( aWMFSize.Height() ) > 1 ) ) { - const Fraction aFrac( 1, mnUnitsPerInch); - MapMode aWMFMap( MapUnit::MapInch, Point(), aFrac, aFrac ); + const double fFrac = 1.0 / mnUnitsPerInch; + MapMode aWMFMap( MapUnit::MapInch, Point(), fFrac, fFrac ); Size aSize100(OutputDevice::LogicToLogic(aWMFSize, aWMFMap, MapMode(MapUnit::Map100thMM))); aDevExt = Size( std::abs( aSize100.Width() ), std::abs( aSize100.Height() ) ); } diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx index 473e991a52fc..4115a798740f 100644 --- a/filter/source/msfilter/msdffimp.cxx +++ b/filter/source/msfilter/msdffimp.cxx @@ -211,9 +211,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() == 1.0, "x-scale in the Mtf is wrong" ); - DBG_ASSERT( pMtf->GetPrefMapMode().GetScaleY() == Fraction( 1, 1 ), + DBG_ASSERT( pMtf->GetPrefMapMode().GetScaleY() == 1.0, "y-scale in the Mtf is wrong" ); DBG_ASSERT( pMtf->GetPrefMapMode().GetOrigin() == Point(), "origin-shift in the Mtf is wrong" ); diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx index b9d65661119f..e6fbdf8c3f92 100644 --- a/filter/source/svg/svgwriter.cxx +++ b/filter/source/svg/svgwriter.cxx @@ -4191,16 +4191,16 @@ void SVGActionWriter::WriteMetaFile( const Point& rPos100thmm, { MapMode aMapMode( rMtf.GetPrefMapMode() ); Size aPrefSize( rMtf.GetPrefSize() ); - Fraction aFractionX( aMapMode.GetScaleX() ); - Fraction aFractionY( aMapMode.GetScaleY() ); + double fFractionX( aMapMode.GetScaleX() ); + double fFractionY( aMapMode.GetScaleY() ); auto popIt = mpVDev->ScopedPush(); Size aSize( OutputDevice::LogicToLogic(rSize100thmm, MapMode(MapUnit::Map100thMM), aMapMode) ); - aFractionX *= Fraction( aSize.Width(), aPrefSize.Width() ); - aMapMode.SetScaleX( aFractionX ); - aFractionY *= Fraction( aSize.Height(), aPrefSize.Height() ); - aMapMode.SetScaleY( aFractionY ); + fFractionX *= double( aSize.Width() ) / aPrefSize.Width(); + aMapMode.SetScaleX( fFractionX ); + fFractionY *= double( aSize.Height() ) / aPrefSize.Height(); + aMapMode.SetScaleY( fFractionY ); Point aOffset( OutputDevice::LogicToLogic(rPos100thmm, MapMode(MapUnit::Map100thMM), aMapMode ) ); aOffset += aMapMode.GetOrigin(); diff --git a/include/sfx2/LokControlHandler.hxx b/include/sfx2/LokControlHandler.hxx index 3edbddf76f17..d7b7316f3b58 100644 --- a/include/sfx2/LokControlHandler.hxx +++ b/include/sfx2/LokControlHandler.hxx @@ -165,8 +165,8 @@ public: MapMode aDeviceMapMode(rDevice.GetMapMode()); const double scale = conversionFract(o3tl::Length::px, o3tl::Length::twip); - Fraction scaleX = Fraction(aOutputSize.Width(), rTileRect.GetWidth()) * scale; - Fraction scaleY = Fraction(aOutputSize.Height(), rTileRect.GetHeight()) * scale; + double scaleX = double(aOutputSize.Width()) / rTileRect.GetWidth() * scale; + double scaleY = double(aOutputSize.Height()) / rTileRect.GetHeight() * scale; aDeviceMapMode.SetScaleX(scaleX); aDeviceMapMode.SetScaleY(scaleY); aDeviceMapMode.SetMapUnit(MapUnit::MapPixel); @@ -189,8 +189,8 @@ public: // need to draw the control. if (aObjectRectHMM.Overlaps(aTileRectHMM)) { - drawUnoControl(pDrawView, pUnoObect, rMainWindow, rDevice, aTileRectHMM, - double(scaleX), double(scaleY)); + drawUnoControl(pDrawView, pUnoObect, rMainWindow, rDevice, aTileRectHMM, scaleX, + scaleY); } } } diff --git a/include/tools/gen.hxx b/include/tools/gen.hxx index 077d50e4743c..c920c5cfccd0 100644 --- a/include/tools/gen.hxx +++ b/include/tools/gen.hxx @@ -156,6 +156,12 @@ public: o3tl::convert(getY(), nMulY, nDivY)); } + // Scales relative to 0,0 + constexpr PointT scale(double fX, double fY) const + { + return PointT(std::llround(getX() * fX), std::llround(getY() * fY)); + } + using Pair::toString; using Pair::GetHashValue; }; @@ -863,6 +869,20 @@ public: aRect.SetBottom(o3tl::convert(Bottom(), nMulY, nDivY)); return aRect; } + + // Scales relative to 0,0 + constexpr RectangleT scale(double fX, double fY) const + { + // 1. Create an empty rectangle with correct left and top + RectangleT aRect(std::llround(Left() * fX), + std::llround(Top() * fY)); + // 2. If source has width/height, set respective right and bottom + if (!IsWidthEmpty()) + aRect.SetRight(std::llround(Right() * fX)); + if (!IsHeightEmpty()) + aRect.SetBottom(std::llround(Bottom() * fY)); + return aRect; + } }; namespace tools diff --git a/include/vcl/mapmod.hxx b/include/vcl/mapmod.hxx index 980aef7d0055..3fb4e114361b 100644 --- a/include/vcl/mapmod.hxx +++ b/include/vcl/mapmod.hxx @@ -26,7 +26,6 @@ #include class Point; -class Fraction; enum class MapUnit : sal_uInt8; class SAL_WARN_UNUSED VCL_DLLPUBLIC MapMode @@ -39,9 +38,7 @@ public: MapMode(); MapMode( const MapMode& rMapMode ); explicit MapMode( MapUnit eUnit ); - MapMode( MapUnit eUnit, const Point& rLogicOrg, - const Fraction& rScaleX, const Fraction& rScaleY ); - MapMode( MapUnit eUnit, const Point& rLogicOrg, double rScaleX, double rScaleY ); + MapMode( MapUnit eUnit, const Point& rLogicOrg, double fScaleX, double fScaleY ); ~MapMode(); void SetMapUnit( MapUnit eUnit ); @@ -50,13 +47,10 @@ public: void SetOrigin( const Point& rOrigin ); const Point& GetOrigin() const; - void SetScaleX( const Fraction& rScaleX ); - const Fraction& GetScaleX() const; - void SetScaleY( const Fraction& rScaleY ); - const Fraction& GetScaleY() const; - - void SetScaleX( double rScaleX ); - void SetScaleY( double rScaleY ); + void SetScaleX( double fScaleX ); + double GetScaleX() const; + void SetScaleY( double fScaleY ); + double GetScaleY() const; MapMode& operator=( const MapMode& rMapMode ); MapMode& operator=( MapMode&& rMapMode ); @@ -89,8 +83,6 @@ inline std::basic_ostream & operator <<( return rStream; } -bool TooLargeScaleForMapMode(const Fraction& rScale, int nDPI); - #endif // INCLUDED_VCL_MAPMOD_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/ui/report/SectionWindow.cxx b/reportdesign/source/ui/report/SectionWindow.cxx index ae6d723fa64a..648c82c91f92 100644 --- a/reportdesign/source/ui/report/SectionWindow.cxx +++ b/reportdesign/source/ui/report/SectionWindow.cxx @@ -62,10 +62,10 @@ OSectionWindow::OSectionWindow( OViewsWindow* _pParent,const uno::Reference< rep m_aStartMarker->setCollapsedHdl(LINK(this,OSectionWindow,Collapsed)); - m_aStartMarker->zoom(double(rMapMode.GetScaleX())); - setZoomFactor(double(rMapMode.GetScaleX()), *m_aReportSection); - setZoomFactor(double(rMapMode.GetScaleX()), *m_aSplitter); - setZoomFactor(double(rMapMode.GetScaleX()), *m_aEndMarker); + m_aStartMarker->zoom(rMapMode.GetScaleX()); + setZoomFactor(rMapMode.GetScaleX(), *m_aReportSection); + setZoomFactor(rMapMode.GetScaleX(), *m_aSplitter); + setZoomFactor(rMapMode.GetScaleX(), *m_aEndMarker); m_aSplitter->Show(); m_aStartMarker->Show(); @@ -260,7 +260,7 @@ void OSectionWindow::Resize() // set splitter aReportPos.AdjustY(aSectionSize.Height() ); m_aSplitter->SetPosSizePixel(aReportPos,Size(aSectionSize.Width(),m_aSplitter->GetSizePixel().Height())); - aSectionSize.setHeight( static_cast(1000 * static_cast(GetMapMode().GetScaleY())) ); + aSectionSize.setHeight( static_cast(1000 * GetMapMode().GetScaleY()) ); m_aSplitter->SetDragRectPixel( tools::Rectangle(Point(nStartWidth,0),aSectionSize)); // set end marker diff --git a/reportdesign/source/ui/report/StartMarker.cxx b/reportdesign/source/ui/report/StartMarker.cxx index 9ce70aea8fe4..21d6bd5ac729 100644 --- a/reportdesign/source/ui/report/StartMarker.cxx +++ b/reportdesign/source/ui/report/StartMarker.cxx @@ -102,7 +102,7 @@ void OStartMarker::Paint(vcl::RenderContext& rRenderContext, const tools::Rectan auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::TEXTCOLOR); Size aSize(GetOutputSizePixel()); - const tools::Long nCornerWidth = tools::Long(CORNER_SPACE * double(GetMapMode().GetScaleX())); + const tools::Long nCornerWidth = tools::Long(CORNER_SPACE * GetMapMode().GetScaleX()); if (isCollapsed()) { @@ -154,7 +154,7 @@ void OStartMarker::Paint(vcl::RenderContext& rRenderContext, const tools::Rectan if (m_bMarked) { - const tools::Long nCornerHeight = tools::Long(CORNER_SPACE * double(GetMapMode().GetScaleY())); + const tools::Long nCornerHeight = tools::Long(CORNER_SPACE * GetMapMode().GetScaleY()); tools::Rectangle aRect(Point(nCornerWidth, nCornerHeight), Size(aSize.Width() - nCornerWidth - nCornerWidth, aSize.Height() - nCornerHeight - nCornerHeight)); @@ -226,8 +226,8 @@ void OStartMarker::Resize() Size aImageSize = m_aImage.GetSizePixel(); const MapMode& rMapMode = GetMapMode(); - aImageSize.setWidth( tools::Long(aImageSize.Width() * static_cast(rMapMode.GetScaleX())) ); - aImageSize.setHeight( tools::Long(aImageSize.Height() * static_cast(rMapMode.GetScaleY())) ); + aImageSize.setWidth( tools::Long(aImageSize.Width() * rMapMode.GetScaleX()) ); + aImageSize.setHeight( tools::Long(aImageSize.Height() * rMapMode.GetScaleY()) ); tools::Long nExtraWidth = tools::Long(REPORT_EXTRA_SPACE * rMapMode.GetScaleX()); diff --git a/reportdesign/source/ui/report/ViewsWindow.cxx b/reportdesign/source/ui/report/ViewsWindow.cxx index 93b55fa84b4c..8a5950ee600d 100644 --- a/reportdesign/source/ui/report/ViewsWindow.cxx +++ b/reportdesign/source/ui/report/ViewsWindow.cxx @@ -201,7 +201,7 @@ void OViewsWindow::impl_resizeSectionWindow(OSectionWindow& _rSectionWindow,Poin { aSectionSize.setHeight( nMinHeight ); } - aSectionSize.AdjustHeight(static_cast(StyleSettings::GetSplitSize() * static_cast(_rSectionWindow.GetMapMode().GetScaleY())) ); + aSectionSize.AdjustHeight(static_cast(StyleSettings::GetSplitSize() * _rSectionWindow.GetMapMode().GetScaleY()) ); if ( _bSet ) _rSectionWindow.SetPosSizePixel(_rStartPoint,aSectionSize); @@ -1628,7 +1628,7 @@ void OViewsWindow::zoom(double _fZoom) const MapMode& aMapMode = GetMapMode(); Fraction aStartWidth(tools::Long(REPORT_STARTMARKER_WIDTH)); - if ( _fZoom < double(aMapMode.GetScaleX()) ) + if ( _fZoom < aMapMode.GetScaleX() ) aStartWidth *= aMapMode.GetScaleX(); else aStartWidth *= _fZoom; diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 752554f0abcc..f860c34078c5 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -3184,9 +3184,9 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testInputHandlerSyncedZoom) EditEngine& rEditEngine1 = pEditView1->getEditEngine(); // These must match, if they don't then text will have a different width in edit and view modes CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("EditEngine Ref Dev Zoom and ViewData Zoom should match", - pViewData1->GetZoomX(), double(rEditEngine1.GetRefMapMode().GetScaleX()), 0.000001); + pViewData1->GetZoomX(), rEditEngine1.GetRefMapMode().GetScaleX(), 0.000001); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("EditEngine Ref Dev Zoom and ViewData Zoom should match", - pViewData1->GetZoomY(), double(rEditEngine1.GetRefMapMode().GetScaleY()), 0.000001); + pViewData1->GetZoomY(), rEditEngine1.GetRefMapMode().GetScaleY(), 0.000001); // Create a View #2 SfxLokHelper::createView(); diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx index 0eebc2486b03..4754dfa6c2d7 100644 --- a/sc/source/core/data/patattr.cxx +++ b/sc/source/core/data/patattr.cxx @@ -733,19 +733,19 @@ void ScPatternAttr::fillFontOnly( if ( pOutDev != nullptr ) { Size aEffSize; - Fraction aFraction( 1,1 ); + double fFraction( 1.0 ); if (pScale) - aFraction = *pScale; + fFraction = *pScale; Size aSize( 0, static_cast(nFontHeight) ); MapMode aDestMode = pOutDev->GetMapMode(); - MapMode aSrcMode( MapUnit::MapTwip, Point(), aFraction, aFraction ); + MapMode aSrcMode( MapUnit::MapTwip, Point(), fFraction, fFraction ); if (aDestMode.GetMapUnit() == MapUnit::MapPixel && pOutDev->GetDPIX() > 0) aEffSize = pOutDev->LogicToPixel( aSize, aSrcMode ); else { - Fraction aFractOne(1,1); - aDestMode.SetScaleX( aFractOne ); - aDestMode.SetScaleY( aFractOne ); + double fFractOne(1.0); + aDestMode.SetScaleX( fFractOne ); + aDestMode.SetScaleY( fFractOne ); aEffSize = OutputDevice::LogicToLogic( aSize, aSrcMode, aDestMode ); } rFont.SetFontSize( aEffSize ); diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx index 3388901b111b..c1f942272e9d 100644 --- a/sc/source/ui/app/transobj.cxx +++ b/sc/source/ui/app/transobj.cxx @@ -422,13 +422,13 @@ bool ScTransferObj::GetData( const datatransfer::DataFlavor& rFlavor, const OUSt // that Skia can handle may need to be raised or lowered for // platforms other than macOS. static constexpr tools::Long nCopyToImageMaxPixels = 8192 * 8192; - Fraction aScale(1.0); + double fScale(1.0); Size aPixelSize = pVirtDev->LogicToPixel(aMMRect.GetSize(), MapMode(MapUnit::Map100thMM)); tools::Long nPixels(aPixelSize.Width() * aPixelSize.Height()); if (nPixels < 0 || nPixels > nCopyToImageMaxPixels) { - aScale = Fraction(nCopyToImageMaxPixels, nPixels); - aPixelSize = pVirtDev->LogicToPixel(aMMRect.GetSize(), MapMode(MapUnit::Map100thMM, Point(), aScale, aScale)); + fScale = double(nCopyToImageMaxPixels) / nPixels; + aPixelSize = pVirtDev->LogicToPixel(aMMRect.GetSize(), MapMode(MapUnit::Map100thMM, Point(), fScale, fScale)); nPixels = aPixelSize.Width() * aPixelSize.Height(); } @@ -436,7 +436,7 @@ bool ScTransferObj::GetData( const datatransfer::DataFlavor& rFlavor, const OUSt PaintToDev( pVirtDev, *m_pDoc, 1.0, aReducedBlock ); - pVirtDev->SetMapMode( MapMode( MapUnit::MapPixel, Point(), aScale, aScale ) ); + pVirtDev->SetMapMode( MapMode( MapUnit::MapPixel, Point(), fScale, fScale ) ); Bitmap aBmp( pVirtDev->GetBitmap( Point(), pVirtDev->GetOutputSize() ) ); bOK = SetBitmap(aBmp, rFlavor); } diff --git a/sc/source/ui/view/gridwin2.cxx b/sc/source/ui/view/gridwin2.cxx index 42755a3476b2..e7be8abde6e1 100644 --- a/sc/source/ui/view/gridwin2.cxx +++ b/sc/source/ui/view/gridwin2.cxx @@ -263,7 +263,7 @@ void ScGridWindow::DoPushPivotToggle( SCCOL nCol, SCROW nRow, const MouseEvent& sal_uInt16 nIndent = rIndentItem.GetValue(); // Check if the mouse cursor is clicking on the toggle +/- box. - ScDPFieldButton aBtn(GetOutDev(), GetSettings().GetStyleSettings(), double(GetMapMode().GetScaleY()), mrViewData.GetDocument()); + ScDPFieldButton aBtn(GetOutDev(), GetSettings().GetStyleSettings(), GetMapMode().GetScaleY(), mrViewData.GetDocument()); aBtn.setBoundingBox(aScrPos, aScrSize, bLayoutRTL); aBtn.setDrawToggleButton(true, true, nIndent); Point aPopupPos; @@ -408,7 +408,7 @@ bool ScGridWindow::DPTestFieldPopupArrow( Size aScrSize(nSizeX-1, nSizeY-1); // Check if the mouse cursor is clicking on the popup arrow box. - ScDPFieldButton aBtn(GetOutDev(), GetSettings().GetStyleSettings(), double(GetMapMode().GetScaleY()), mrViewData.GetDocument()); + ScDPFieldButton aBtn(GetOutDev(), GetSettings().GetStyleSettings(), GetMapMode().GetScaleY(), mrViewData.GetDocument()); aBtn.setBoundingBox(aScrPos, aScrSize, bLayoutRTL); aBtn.setPopupLeft(false); // DataPilot popup is always right-aligned for now Point aPopupPos; @@ -438,7 +438,7 @@ bool ScGridWindow::DPTestMultiFieldPopupArrow( Size aScrSize(nSizeX - 1, nSizeY - 1); // Check if the mouse cursor is clicking on the popup arrow box. - ScDPFieldButton aBtn(GetOutDev(), GetSettings().GetStyleSettings(), double(GetMapMode().GetScaleY()), mrViewData.GetDocument()); + ScDPFieldButton aBtn(GetOutDev(), GetSettings().GetStyleSettings(), GetMapMode().GetScaleY(), mrViewData.GetDocument()); aBtn.setBoundingBox(aScrPos, aScrSize, bLayoutRTL); aBtn.setPopupLeft(false); // DataPilot popup is always right-aligned for now aBtn.setDrawPopupButtonMulti(true); diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx index e45db253589a..26b8fc1c8616 100644 --- a/sc/source/ui/view/gridwin4.cxx +++ b/sc/source/ui/view/gridwin4.cxx @@ -1090,9 +1090,7 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI aOrigin.AdjustY(o3tl::toTwips(aOutputData.mnScrY, o3tl::Length::px)); aOrigin = o3tl::convert(aOrigin, o3tl::Length::twip, o3tl::Length::mm100); // keep into account the zoom factor - aOrigin = aOrigin.scale( - aDrawMode.GetScaleX().GetDenominator(), aDrawMode.GetScaleX().GetNumerator(), - aDrawMode.GetScaleY().GetDenominator(), aDrawMode.GetScaleY().GetNumerator()); + aOrigin = aOrigin.scale(1.0 / aDrawMode.GetScaleX(), 1.0 / aDrawMode.GetScaleY()); MapMode aNew = rDevice.GetMapMode(); aNew.SetOrigin(aOrigin); @@ -1187,9 +1185,7 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI // keep into account the zoom factor Point aNewOrigin(o3tl::convert(aOriginAbsTw, o3tl::Length::twip, o3tl::Length::mm100)); - aNewOrigin = aNewOrigin.scale( - aDrawMode.GetScaleX().GetDenominator(), aDrawMode.GetScaleX().GetNumerator(), - aDrawMode.GetScaleY().GetDenominator(), aDrawMode.GetScaleY().GetNumerator()); + aNewOrigin = aNewOrigin.scale(1.0 / aDrawMode.GetScaleX(), 1.0 / aDrawMode.GetScaleY()); MapMode aNewMM = rDevice.GetMapMode(); aNewMM.SetOrigin(aNewOrigin); @@ -1298,7 +1294,7 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI aCursorRect.setWidth(0); aCursorRect.Move(aCursPos.getX(), 0); // Sends view cursor position to views of all matching zooms if needed (avoids duplicates). - InvalidateLOKViewCursor(aCursorRect, double(aMM.GetScaleX()), double(aMM.GetScaleY())); + InvalidateLOKViewCursor(aCursorRect, aMM.GetScaleX(), aMM.GetScaleY()); } // Rollback the mapmode and 'output area'. diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx index f29f1ff7d9e2..ef16cb3ac2a6 100644 --- a/sc/source/ui/view/output2.cxx +++ b/sc/source/ui/view/output2.cxx @@ -864,7 +864,7 @@ double ScOutputData::GetStretch() const if ( mpRefDevice == pFmtDevice ) { MapMode aOld = mpRefDevice->GetMapMode(); - return static_cast(aOld.GetScaleY()) / static_cast(aOld.GetScaleX()) * mfZoomY / mfZoomX; + return aOld.GetScaleY() / aOld.GetScaleX() * mfZoomY / mfZoomX; } else { @@ -1392,7 +1392,7 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, tools::Long nPosX, too ( !bBreak || mpRefDevice == pFmtDevice ) ) { // filter drop-down width depends on row height - double fZoom = mpRefDevice ? static_cast(mpRefDevice->GetMapMode().GetScaleY()) : 1.0; + double fZoom = mpRefDevice ? mpRefDevice->GetMapMode().GetScaleY() : 1.0; fZoom = fZoom > 1.0 ? fZoom : 1.0; const tools::Long nFilter = fZoom * DROPDOWN_BITMAP_SIZE; bool bFit = ( nNeeded + nFilter <= nMergeSizeX ); @@ -5218,7 +5218,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic) pInfo->bAutoFilter) { // filter drop-down width depends on row height - double fZoom = mpRefDevice ? static_cast(mpRefDevice->GetMapMode().GetScaleY()) : 1.0; + double fZoom = mpRefDevice ? mpRefDevice->GetMapMode().GetScaleY() : 1.0; fZoom = fZoom > 1.0 ? fZoom : 1.0; if (bPixelToLogic) nAvailWidth -= mpRefDevice->PixelToLogic(Size(0,fZoom * DROPDOWN_BITMAP_SIZE)).Height(); diff --git a/sc/source/ui/view/preview.cxx b/sc/source/ui/view/preview.cxx index 7411c0b8fa85..c3a2938cd907 100644 --- a/sc/source/ui/view/preview.cxx +++ b/sc/source/ui/view/preview.cxx @@ -335,9 +335,9 @@ void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation ) UpdateDrawView(); // Spreadsheet eventually changes } - Fraction aPreviewZoom( nZoom, 100 ); - Fraction aHorPrevZoom( static_cast( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 ); - MapMode aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom ); + double fPreviewZoom = double(nZoom) / 100; + double fHorPrevZoom = 100.0 * nZoom / pDocShell->GetOutputFactor() / 10000; + MapMode aMMMode( MapUnit::Map100thMM, Point(), fHorPrevZoom, fPreviewZoom ); bool bDoPrint = ( pFillLocation == nullptr ); bool bValidPage = ( nPageNo < nTotalPages ); @@ -723,9 +723,9 @@ void ScPreview::SetZoom(sal_uInt16 nNewZoom) // apply new MapMode and call UpdateScrollBars to update aOffset - Fraction aPreviewZoom( nZoom, 100 ); - Fraction aHorPrevZoom( static_cast( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 ); - MapMode aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom ); + double fPreviewZoom = double(nZoom) / 100; + double fHorPrevZoom = 100.0 * nZoom / pDocShell->GetOutputFactor() / 10000; + MapMode aMMMode( MapUnit::Map100thMM, Point(), fHorPrevZoom, fPreviewZoom ); SetMapMode( aMMMode ); bInSetZoom = true; // don't scroll during SetYOffset in UpdateScrollBars @@ -950,9 +950,9 @@ void ScPreview::DataChanged( const DataChangedEvent& rDCEvt ) void ScPreview::MouseButtonDown( const MouseEvent& rMEvt ) { - Fraction aPreviewZoom( nZoom, 100 ); - Fraction aHorPrevZoom( static_cast( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 ); - MapMode aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom ); + double fPreviewZoom = double(nZoom) / 100; + double fHorPrevZoom = 100.0 * nZoom / pDocShell->GetOutputFactor() / 10000; + MapMode aMMMode( MapUnit::Map100thMM, Point(), fHorPrevZoom, fPreviewZoom ); aButtonDownChangePoint = PixelToLogic( rMEvt.GetPosPixel(),aMMMode ); aButtonDownPt = PixelToLogic( rMEvt.GetPosPixel(),aMMMode ); @@ -1033,9 +1033,9 @@ void ScPreview::MouseButtonDown( const MouseEvent& rMEvt ) void ScPreview::MouseButtonUp( const MouseEvent& rMEvt ) { - Fraction aPreviewZoom( nZoom, 100 ); - Fraction aHorPrevZoom( static_cast( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 ); - MapMode aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom ); + double fPreviewZoom = double(nZoom) / 100; + double fHorPrevZoom = 100.0 * nZoom / pDocShell->GetOutputFactor() / 10000; + MapMode aMMMode( MapUnit::Map100thMM, Point(), fHorPrevZoom, fPreviewZoom ); aButtonUpPt = PixelToLogic( rMEvt.GetPosPixel(),aMMMode ); @@ -1297,9 +1297,9 @@ void ScPreview::MouseButtonUp( const MouseEvent& rMEvt ) void ScPreview::MouseMove( const MouseEvent& rMEvt ) { - Fraction aPreviewZoom( nZoom, 100 ); - Fraction aHorPrevZoom( static_cast( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 ); - MapMode aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom ); + double fPreviewZoom = double(nZoom) / 100; + double fHorPrevZoom = 100.0 * nZoom / pDocShell->GetOutputFactor() / 10000; + MapMode aMMMode( MapUnit::Map100thMM, Point(), fHorPrevZoom, fPreviewZoom ); Point aMouseMovePoint = PixelToLogic( rMEvt.GetPosPixel(), aMMMode ); tools::Long nLeftMargin = 0; @@ -1527,9 +1527,9 @@ rtl::Reference ScPreview::CreateAccessible() void ScPreview::DragMove( tools::Long nDragMovePos, PointerStyle nFlags ) { - Fraction aPreviewZoom( nZoom, 100 ); - Fraction aHorPrevZoom( static_cast( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 ); - MapMode aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom ); + double fPreviewZoom = double(nZoom) / 100; + double fHorPrevZoom = 100.0 * nZoom / pDocShell->GetOutputFactor() / 10000; + MapMode aMMMode( MapUnit::Map100thMM, Point(), fHorPrevZoom, fPreviewZoom ); SetMapMode( aMMMode ); tools::Long nPos = nDragMovePos; if( nFlags == PointerStyle::HSizeBar || nFlags == PointerStyle::HSplit ) diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx index 3eae04d26ce3..426cdba011a8 100644 --- a/sc/source/ui/view/printfun.cxx +++ b/sc/source/ui/view/printfun.cxx @@ -1667,9 +1667,9 @@ void ScPrintFunc::PrintArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, if ( !pPrinter ) { OutputDevice* pRefDev = rDoc.GetPrinter(); // use the printer also for Preview - Fraction aPrintFrac( nZoom, 100 ); // without nManualZoom + double fPrintFrac = double(nZoom) / 100.0; // without nManualZoom // MapMode, as it would arrive at the printer: - pRefDev->SetMapMode( MapMode( MapUnit::Map100thMM, Point(), aPrintFrac, aPrintFrac ) ); + pRefDev->SetMapMode( MapMode( MapUnit::Map100thMM, Point(), fPrintFrac, fPrintFrac ) ); // when rendering (PDF), don't use printer as ref device, but printer's MapMode // has to be set anyway, as charts still use it (#106409#) @@ -2629,22 +2629,22 @@ void ScPrintFunc::InitModes() // set MapModes from nZoom etc. constexpr auto HMM_PER_TWIPS = o3tl::convert(1.0, o3tl::Length::twip, o3tl::Length::mm100); nScaleX = nScaleY = HMM_PER_TWIPS; // output in 1/100 mm - Fraction aZoomFract( nEffZoom,10000 ); - Fraction aHorFract = aZoomFract; + double fZoomFract = double(nEffZoom) / 10000; + double fHorFract = fZoomFract; if ( !pPrinter && !bIsRender ) // adjust scale for preview { double nFact = rDocShell.GetOutputFactor(); - aHorFract = Fraction( static_cast( nEffZoom / nFact ), 10000 ); + fHorFract = double(nEffZoom) / nFact / 10000; } - aLogicMode = MapMode( MapUnit::Map100thMM, Point(), aHorFract, aZoomFract ); + aLogicMode = MapMode( MapUnit::Map100thMM, Point(), fHorFract, fZoomFract ); Point aLogicOfs( -aOffset.X(), -aOffset.Y() ); - aOffsetMode = MapMode( MapUnit::Map100thMM, aLogicOfs, aHorFract, aZoomFract ); + aOffsetMode = MapMode( MapUnit::Map100thMM, aLogicOfs, fHorFract, fZoomFract ); Point aTwipsOfs( static_cast( -aOffset.X() / nScaleX + 0.5 ), static_cast( -aOffset.Y() / nScaleY + 0.5 ) ); - aTwipMode = MapMode( MapUnit::MapTwip, aTwipsOfs, aHorFract, aZoomFract ); + aTwipMode = MapMode( MapUnit::MapTwip, aTwipsOfs, fHorFract, fZoomFract ); } void ScPrintFunc::ApplyPrintSettings() diff --git a/sd/source/filter/eppt/pptx-epptbase.cxx b/sd/source/filter/eppt/pptx-epptbase.cxx index a3528f765ee8..9dd0d084f0b4 100644 --- a/sd/source/filter/eppt/pptx-epptbase.cxx +++ b/sd/source/filter/eppt/pptx-epptbase.cxx @@ -103,7 +103,7 @@ PHLayout const pPHLayout[] = { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x16, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x12, true, true, false } }; -const Fraction gPPTFraction(1,576); +const double gPPTFraction = 1.0 / 576; PPTWriterBase::PPTWriterBase() : mbStatusIndicator(false) diff --git a/sd/source/ui/docshell/docshel2.cxx b/sd/source/ui/docshell/docshel2.cxx index 83020e7df156..fdbf1bfc2cf3 100644 --- a/sd/source/ui/docshell/docshel2.cxx +++ b/sd/source/ui/docshell/docshel2.cxx @@ -189,17 +189,17 @@ Bitmap DrawDocShell::GetPagePreviewBitmap(SdPage* pPage) const Size aPixSize( pVDev->LogicToPixel( aSize ) ); const sal_uLong nMaxEdgePix = std::max( aPixSize.Width(), aPixSize.Height() ); - Fraction aFrac( nMaxEdgePixel, nMaxEdgePix ); + double fFrac = double(nMaxEdgePixel) / nMaxEdgePix; - aMapMode.SetScaleX( aFrac ); - aMapMode.SetScaleY( aFrac ); + aMapMode.SetScaleX( fFrac ); + aMapMode.SetScaleY( fFrac ); pVDev->SetMapMode( aMapMode ); pVDev->SetOutputSize( aSize ); // that we also get the dark lines at the right and bottom page margin - aFrac = Fraction( nMaxEdgePixel - 1, nMaxEdgePix ); - aMapMode.SetScaleX( aFrac ); - aMapMode.SetScaleY( aFrac ); + fFrac = double(nMaxEdgePixel - 1) / nMaxEdgePix; + aMapMode.SetScaleX( fFrac ); + aMapMode.SetScaleY( fFrac ); pVDev->SetMapMode( aMapMode ); std::optional pView( std::in_place, this, pVDev ); diff --git a/sd/source/ui/tools/PreviewRenderer.cxx b/sd/source/ui/tools/PreviewRenderer.cxx index 39bc644eeac7..42e3b8a997ef 100644 --- a/sd/source/ui/tools/PreviewRenderer.cxx +++ b/sd/source/ui/tools/PreviewRenderer.cxx @@ -159,9 +159,9 @@ Image PreviewRenderer::RenderSubstitution ( // visible. MapMode aMapMode (mpPreviewDevice->GetMapMode()); aMapMode.SetMapUnit(MapUnit::Map100thMM); - Fraction aFinalScale(25 * rPreviewPixelSize.Width(), 28000); - aMapMode.SetScaleX(aFinalScale); - aMapMode.SetScaleY(aFinalScale); + double fFinalScale = double(25 * rPreviewPixelSize.Width()) / 28000; + aMapMode.SetScaleX(fFinalScale); + aMapMode.SetScaleY(fFinalScale); const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0); aMapMode.SetOrigin(mpPreviewDevice->PixelToLogic( Point(nFrameWidth,nFrameWidth),aMapMode)); @@ -363,9 +363,9 @@ void PreviewRenderer::SetupOutputSize ( { const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0); aMapMode.SetScaleX( - Fraction(rFramePixelSize.Width()-2*nFrameWidth-1, aPageModelSize.Width())); + double(rFramePixelSize.Width()-2*nFrameWidth-1) / aPageModelSize.Width()); aMapMode.SetScaleY( - Fraction(rFramePixelSize.Height()-2*nFrameWidth-1, aPageModelSize.Height())); + double(rFramePixelSize.Height()-2*nFrameWidth-1) / aPageModelSize.Height()); aMapMode.SetOrigin(mpPreviewDevice->PixelToLogic(Point(nFrameWidth,nFrameWidth),aMapMode)); } else diff --git a/sd/source/ui/tools/SlideshowLayerRenderer.cxx b/sd/source/ui/tools/SlideshowLayerRenderer.cxx index d819036412b2..7644e956b76f 100644 --- a/sd/source/ui/tools/SlideshowLayerRenderer.cxx +++ b/sd/source/ui/tools/SlideshowLayerRenderer.cxx @@ -119,13 +119,13 @@ public: Size aPageSize(rPage.GetSize()); MapMode aMapMode(MapUnit::Map100thMM); - const Fraction aFracX(rSlideSize.Width(), - maVirtualDevice->LogicToPixel(aPageSize, aMapMode).Width()); - aMapMode.SetScaleX(aFracX); + const double fFracX = double(rSlideSize.Width()) + / maVirtualDevice->LogicToPixel(aPageSize, aMapMode).Width(); + aMapMode.SetScaleX(fFracX); - const Fraction aFracY(rSlideSize.Height(), - maVirtualDevice->LogicToPixel(aPageSize, aMapMode).Height()); - aMapMode.SetScaleY(aFracY); + const double fFracY = double(rSlideSize.Height()) + / maVirtualDevice->LogicToPixel(aPageSize, aMapMode).Height(); + aMapMode.SetScaleY(fFracY); maVirtualDevice->SetMapMode(aMapMode); } diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 73d269108520..ca01769bd077 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -3881,8 +3881,8 @@ void SdXImpressDocument::paintTile( VirtualDevice& rDevice, // We specifically calculate these scales first as we're still // in TWIPs, and might as well minimize the number of conversions. const double scale = conversionFract(o3tl::Length::px, o3tl::Length::twip); - Fraction scaleX = Fraction(nOutputWidth, nTileWidth) * scale; - Fraction scaleY = Fraction(nOutputHeight, nTileHeight) * scale; + double scaleX = double(nOutputWidth) / nTileWidth * scale; + double scaleY = double(nOutputHeight) / nTileHeight * scale; // svx seems to be the only component that works natively in // 100th mm rather than TWIP. It makes most sense just to diff --git a/sd/source/ui/view/DocumentRenderer.cxx b/sd/source/ui/view/DocumentRenderer.cxx index 6715e0a6284f..c0dcee33dfa8 100644 --- a/sd/source/ui/view/DocumentRenderer.cxx +++ b/sd/source/ui/view/DocumentRenderer.cxx @@ -2107,14 +2107,14 @@ private: const double fHorz = static_cast(aPrintSize.Width()) / aPageSize.Width(); const double fVert = static_cast(aPrintSize.Height()) / aPageSize.Height(); - Fraction aFract; + double fFract; if ( fHorz < fVert ) - aFract = Fraction(aPrintSize.Width(), aPageSize.Width()); + fFract = double(aPrintSize.Width()) / aPageSize.Width(); else - aFract = Fraction(aPrintSize.Height(), aPageSize.Height()); + fFract = double(aPrintSize.Height()) / aPageSize.Height(); - aMap.SetScaleX(aFract); - aMap.SetScaleY(aFract); + aMap.SetScaleX(fFract); + aMap.SetScaleY(fFract); aMap.SetOrigin(Point()); } @@ -2238,14 +2238,14 @@ private: const double fHorz(static_cast(aPrintSize.Width()) / aPageSize.Width()); const double fVert(static_cast(aPrintSize.Height()) / aPageSize.Height()); - Fraction aFract; + double fFract; if (fHorz < fVert) - aFract = Fraction(aPrintSize.Width(), aPageSize.Width()); + fFract = double(aPrintSize.Width()) / aPageSize.Width(); else - aFract = Fraction(aPrintSize.Height(), aPageSize.Height()); + fFract = double(aPrintSize.Height()) / aPageSize.Height(); - aMap.SetScaleX(aFract); - aMap.SetScaleY(aFract); + aMap.SetScaleX(fFract); + aMap.SetScaleY(fFract); aMap.SetOrigin(Point()); } diff --git a/sd/source/ui/view/sdwindow.cxx b/sd/source/ui/view/sdwindow.cxx index 308aac5e0b74..e14de2d7009e 100644 --- a/sd/source/ui/view/sdwindow.cxx +++ b/sd/source/ui/view/sdwindow.cxx @@ -182,7 +182,7 @@ void Window::SetMaxZoom (::tools::Long nMax) ::tools::Long Window::GetZoom() const { - if( GetMapMode().GetScaleX().GetDenominator() ) + if( GetMapMode().GetScaleX() != 0 ) { return ::tools::Long(GetMapMode().GetScaleX() * 100); } diff --git a/sfx2/source/view/lokcharthelper.cxx b/sfx2/source/view/lokcharthelper.cxx index 3b9db1fc530d..62137976a6f6 100644 --- a/sfx2/source/view/lokcharthelper.cxx +++ b/sfx2/source/view/lokcharthelper.cxx @@ -104,12 +104,10 @@ tools::Rectangle LokChartHelper::GetChartBoundingBox() // returns the chart bounding box in twips. const MapMode& aCWMapMode = pWindow->GetMapMode(); constexpr auto p = o3tl::getConversionMulDiv(o3tl::Length::px, o3tl::Length::twip); - const auto& scaleX = aCWMapMode.GetScaleX(); - const auto& scaleY = aCWMapMode.GetScaleY(); - const auto nXNum = p.first * scaleX.GetDenominator(); - const auto nXDen = p.second * scaleX.GetNumerator(); - const auto nYNum = p.first * scaleY.GetDenominator(); - const auto nYDen = p.second * scaleY.GetNumerator(); + const double scaleX = aCWMapMode.GetScaleX(); + const double scaleY = aCWMapMode.GetScaleY(); + const double nX = p.first * scaleX / p.second; + const double nY = p.first * scaleY / p.second; Point aOffset = pWindow->GetOffsetPixelFrom(*pRootWin); if (mbNegativeX && AllSettings::GetLayoutRTL()) @@ -121,8 +119,8 @@ tools::Rectangle LokChartHelper::GetChartBoundingBox() } - aOffset = aOffset.scale(nXNum, nXDen, nYNum, nYDen); - Size aSize = pWindow->GetSizePixel().scale(nXNum, nXDen, nYNum, nYDen); + aOffset = aOffset.scale(nX, nY); + Size aSize = pWindow->GetSizePixel().scale(nX, nY); aBBox = tools::Rectangle(aOffset, aSize); } } @@ -237,8 +235,8 @@ void LokChartHelper::PaintAllChartsOnTile(VirtualDevice& rDevice, // Scaling. Must convert from pixels to twips. We know // that VirtualDevices use a DPI of 96. const double scale = conversionFract(o3tl::Length::px, o3tl::Length::twip); - Fraction scaleX = Fraction(nOutputWidth, nTileWidth) * scale; - Fraction scaleY = Fraction(nOutputHeight, nTileHeight) * scale; + double scaleX = double(nOutputWidth) / nTileWidth * scale; + double scaleY = double(nOutputHeight) / nTileHeight * scale; aMapMode.SetScaleX(scaleX); aMapMode.SetScaleY(scaleY); rDevice.SetMapMode(aMapMode); diff --git a/sfx2/source/view/lokstarmathhelper.cxx b/sfx2/source/view/lokstarmathhelper.cxx index 8857bbf2b201..d80aaa43247a 100644 --- a/sfx2/source/view/lokstarmathhelper.cxx +++ b/sfx2/source/view/lokstarmathhelper.cxx @@ -228,8 +228,8 @@ void LokStarMathHelper::PaintAllInPlaceOnTile(VirtualDevice& rDevice, int nOutpu // Scaling. Must convert from pixels to twips. We know that VirtualDevices use a DPI of 96. const double scale = conversionFract(o3tl::Length::px, o3tl::Length::twip); - const Fraction scaleX = Fraction(nOutputWidth, nTileWidth) * scale; - const Fraction scaleY = Fraction(nOutputHeight, nTileHeight) * scale; + const double scaleX = double(nOutputWidth) / nTileWidth * scale; + const double scaleY = double(nOutputHeight) / nTileHeight * scale; aMapMode.SetScaleX(scaleX); aMapMode.SetScaleY(scaleY); aMapMode.SetMapUnit(MapUnit::MapTwip); diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx index 29a5fd5f6ea7..f562fbedf0c2 100644 --- a/starmath/source/document.cxx +++ b/starmath/source/document.cxx @@ -1536,9 +1536,9 @@ void SmDocShell::Impl_Print(OutputDevice& rOutDev, const SmPrintUIOptions& rPrin o3tl::convert(aOutRect.GetHeight(), 100, aSize.Height())); if (bIsPrintFrame && nZ > MINZOOM) nZ -= 10; - Fraction aFraction(std::clamp(nZ, MINZOOM, MAXZOOM), 100); + double fFraction(std::clamp(nZ, MINZOOM, MAXZOOM) / 100.0); - OutputMapMode = MapMode(SmMapUnit(), Point(), aFraction, aFraction); + OutputMapMode = MapMode(SmMapUnit(), Point(), fFraction, fFraction); } else OutputMapMode = MapMode(SmMapUnit()); @@ -1546,9 +1546,9 @@ void SmDocShell::Impl_Print(OutputDevice& rOutDev, const SmPrintUIOptions& rPrin case PRINT_SIZE_ZOOMED: { - Fraction aFraction(nZoomFactor, 100); + double fFraction = nZoomFactor / 100.0; - OutputMapMode = MapMode(SmMapUnit(), Point(), aFraction, aFraction); + OutputMapMode = MapMode(SmMapUnit(), Point(), fFraction, fFraction); break; } } diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx index e85159592f5e..fb00fff97f3c 100644 --- a/starmath/source/view.cxx +++ b/starmath/source/view.cxx @@ -340,8 +340,7 @@ void SmGraphicWidget::SetDrawingArea(weld::DrawingArea* pDrawingArea) } else { - const Fraction aFraction(1, 1); - rDevice.SetMapMode(MapMode(SmMapUnit(), Point(), aFraction, aFraction)); + rDevice.SetMapMode(MapMode(SmMapUnit(), Point(), 1.0, 1.0)); } SetTotalSize(); @@ -887,8 +886,8 @@ void SmGraphicWindow::SetZoom(sal_uInt16 Factor) if (comphelper::LibreOfficeKit::isActive()) return; nZoom = std::clamp(Factor, MINZOOM, MAXZOOM); - Fraction aFraction(nZoom, 100); - SetGraphicMapMode(MapMode(SmMapUnit(), Point(), aFraction, aFraction)); + double fFraction = nZoom / 100.0; + SetGraphicMapMode(MapMode(SmMapUnit(), Point(), fFraction, fFraction)); mxGraphic->SetTotalSize(); SmViewShell& rViewSh = mxGraphic->GetView(); rViewSh.GetViewFrame().GetBindings().Invalidate(SID_ATTR_ZOOM); @@ -1187,11 +1186,11 @@ void SmViewShell::InnerResizePixel(const Point &rOfs, const Size &rSize, bool) if ( !aObjSize.IsEmpty() ) { Size aProvidedSize = GetWindow()->PixelToLogic(rSize, MapMode(SmMapUnit())); - Fraction aZoomX(aProvidedSize.Width(), aObjSize.Width()); - Fraction aZoomY(aProvidedSize.Height(), aObjSize.Height()); + double fZoomX = double(aProvidedSize.Width()) / aObjSize.Width(); + double fZoomY = double(aProvidedSize.Height()) / aObjSize.Height(); MapMode aMap(mxGraphicWindow->GetGraphicMapMode()); - aMap.SetScaleX(aZoomX); - aMap.SetScaleY(aZoomY); + aMap.SetScaleX(fZoomX); + aMap.SetScaleY(fZoomY); mxGraphicWindow->SetGraphicMapMode(aMap); } diff --git a/svtools/source/filter/exportdialog.cxx b/svtools/source/filter/exportdialog.cxx index 3f36e163ea8a..289ff2e1c387 100644 --- a/svtools/source/filter/exportdialog.cxx +++ b/svtools/source/filter/exportdialog.cxx @@ -1072,11 +1072,11 @@ IMPL_LINK_NOARG(ExportDialog, UpdateHdlMtfSizeX, weld::SpinButton&, void) } else { - Fraction aFract( 1, 100 ); + double fFract = 1.0 / 100; sal_Int32 nWidth = mxMfSizeX->get_value(); sal_Int32 nHeight= static_cast< sal_Int32 >( nWidth * fRatio ); const Size aSource( nWidth, nHeight ); - MapMode aSourceMapMode( GetMapUnit( mxLbSizeX->get_active() ),Point(), aFract, aFract ); + MapMode aSourceMapMode( GetMapUnit( mxLbSizeX->get_active() ),Point(), fFract, fFract ); Size aDest(OutputDevice::LogicToLogic(aSource, aSourceMapMode, MapMode(MapUnit::Map100thMM))); maSize.Width = aDest.Width(); @@ -1108,11 +1108,11 @@ IMPL_LINK_NOARG(ExportDialog, UpdateHdlMtfSizeY, weld::SpinButton&, void) } else { - Fraction aFract( 1, 100 ); + double fFract = 1.0 / 100; sal_Int32 nHeight= mxMfSizeY->get_value(); sal_Int32 nWidth = static_cast< sal_Int32 >( nHeight * fRatio ); const Size aSource( nWidth, nHeight ); - MapMode aSourceMapMode( GetMapUnit( mxLbSizeX->get_active() ),Point(), aFract, aFract ); + MapMode aSourceMapMode( GetMapUnit( mxLbSizeX->get_active() ),Point(), fFract, fFract ); Size aDest( OutputDevice::LogicToLogic(aSource, aSourceMapMode, MapMode(MapUnit::Map100thMM)) ); maSize.Height = aDest.Height(); diff --git a/svx/source/dialog/connctrl.cxx b/svx/source/dialog/connctrl.cxx index 10d1d8b82bf4..780073251d6e 100644 --- a/svx/source/dialog/connctrl.cxx +++ b/svx/source/dialog/connctrl.cxx @@ -98,13 +98,13 @@ void SvxXConnectionPreview::AdaptSize() aNewSize.setHeight( static_cast( static_cast(nWidth) / fRectWH ) ); } - Fraction aFrac1( aWinSize.Width(), aRect.GetWidth() ); - Fraction aFrac2( aWinSize.Height(), aRect.GetHeight() ); - Fraction aMinFrac( aFrac1 <= aFrac2 ? aFrac1 : aFrac2 ); + double fFrac1 = double( aWinSize.Width() ) / aRect.GetWidth(); + double fFrac2 = double( aWinSize.Height() ) / aRect.GetHeight(); + double fMinFrac( fFrac1 <= fFrac2 ? fFrac1 : fFrac2 ); // Implement MapMode - aDisplayMap.SetScaleX( aMinFrac ); - aDisplayMap.SetScaleY( aMinFrac ); + aDisplayMap.SetScaleX( fMinFrac ); + aDisplayMap.SetScaleY( fMinFrac ); // Centering aNewPos.setX( ( nWidth - aNewSize.Width() ) >> 1 ); @@ -252,40 +252,40 @@ bool SvxXConnectionPreview::MouseButtonDown( const MouseEvent& rMEvt ) if( bZoomIn || bZoomOut ) { MapMode aMapMode = GetMapMode(); - Fraction aXFrac = aMapMode.GetScaleX(); - Fraction aYFrac = aMapMode.GetScaleY(); - std::optional oMultFrac; + double fXFrac = aMapMode.GetScaleX(); + double fYFrac = aMapMode.GetScaleY(); + double fMultFrac; if( bZoomIn ) { if( bCtrl ) - oMultFrac = 3.0 / 2; + fMultFrac = 3.0 / 2; else - oMultFrac = 11.0 / 10; + fMultFrac = 11.0 / 10; } else { if( bCtrl ) - oMultFrac = 2.0 / 3; + fMultFrac = 2.0 / 3; else - oMultFrac = 10.0 / 11; + fMultFrac = 10.0 / 11; } - aXFrac *= *oMultFrac; - aYFrac *= *oMultFrac; - if( static_cast(aXFrac) > 0.001 && static_cast(aXFrac) < 1000.0 && - static_cast(aYFrac) > 0.001 && static_cast(aYFrac) < 1000.0 ) + fXFrac *= fMultFrac; + fYFrac *= fMultFrac; + if( fXFrac > 0.001 && fXFrac < 1000.0 && + fYFrac > 0.001 && fYFrac < 1000.0 ) { - aMapMode.SetScaleX( aXFrac ); - aMapMode.SetScaleY( aYFrac ); + aMapMode.SetScaleX( fXFrac ); + aMapMode.SetScaleY( fYFrac ); SetMapMode( aMapMode ); Size aOutSize(GetOutputSizePixel()); aOutSize = GetDrawingArea()->get_ref_device().PixelToLogic(aOutSize); Point aPt( aMapMode.GetOrigin() ); - tools::Long nX = static_cast( ( static_cast(aOutSize.Width()) - ( static_cast(aOutSize.Width()) * *oMultFrac ) ) / 2.0 + 0.5 ); - tools::Long nY = static_cast( ( static_cast(aOutSize.Height()) - ( static_cast(aOutSize.Height()) * *oMultFrac ) ) / 2.0 + 0.5 ); + tools::Long nX = static_cast( ( static_cast(aOutSize.Width()) - ( static_cast(aOutSize.Width()) * fMultFrac ) ) / 2.0 + 0.5 ); + tools::Long nY = static_cast( ( static_cast(aOutSize.Height()) - ( static_cast(aOutSize.Height()) * fMultFrac ) ) / 2.0 + 0.5 ); aPt.AdjustX(nX ); aPt.AdjustY(nY ); diff --git a/svx/source/dialog/measctrl.cxx b/svx/source/dialog/measctrl.cxx index 7fefadbd45fb..9a51d75db829 100644 --- a/svx/source/dialog/measctrl.cxx +++ b/svx/source/dialog/measctrl.cxx @@ -99,33 +99,32 @@ bool SvxXMeasurePreview::MouseButtonDown(const MouseEvent& rMEvt) if (bZoomIn || bZoomOut) { - Fraction aXFrac = m_aMapMode.GetScaleX(); - Fraction aYFrac = m_aMapMode.GetScaleY(); - std::unique_ptr pMultFrac; + double fXFrac = m_aMapMode.GetScaleX(); + double fYFrac = m_aMapMode.GetScaleY(); + double fMultFrac; if (bZoomIn) { if (bCtrl) - pMultFrac.reset(new Fraction(3, 2)); + fMultFrac = 3.0 / 2; else - pMultFrac.reset(new Fraction(11, 10)); + fMultFrac = 11.0 / 10; } else { if (bCtrl) - pMultFrac.reset(new Fraction(2, 3)); + fMultFrac = 2.0 / 3; else - pMultFrac.reset(new Fraction(10, 11)); + fMultFrac = 10.0 / 11; } - aXFrac *= *pMultFrac; - aYFrac *= *pMultFrac; + fXFrac *= fMultFrac; + fYFrac *= fMultFrac; - if (double(aXFrac) > 0.001 && double(aXFrac) < 1000.0 && double(aYFrac) > 0.001 - && double(aYFrac) < 1000.0) + if (fXFrac > 0.001 && fXFrac < 1000.0 && fYFrac > 0.001 && fYFrac < 1000.0) { - m_aMapMode.SetScaleX(aXFrac); - m_aMapMode.SetScaleY(aYFrac); + m_aMapMode.SetScaleX(fXFrac); + m_aMapMode.SetScaleY(fYFrac); OutputDevice& rRefDevice = GetDrawingArea()->get_ref_device(); rRefDevice.Push(vcl::PushFlags::MAPMODE); @@ -135,11 +134,9 @@ bool SvxXMeasurePreview::MouseButtonDown(const MouseEvent& rMEvt) Point aPt(m_aMapMode.GetOrigin()); tools::Long nX = tools::Long( - (double(aOutSize.Width()) - (double(aOutSize.Width()) * double(*pMultFrac))) / 2.0 - + 0.5); + (double(aOutSize.Width()) - (double(aOutSize.Width()) * fMultFrac)) / 2.0 + 0.5); tools::Long nY = tools::Long( - (double(aOutSize.Height()) - (double(aOutSize.Height()) * double(*pMultFrac))) / 2.0 - + 0.5); + (double(aOutSize.Height()) - (double(aOutSize.Height()) * fMultFrac)) / 2.0 + 0.5); aPt.AdjustX(nX); aPt.AdjustY(nY); diff --git a/svx/source/dialog/pagectrl.cxx b/svx/source/dialog/pagectrl.cxx index 0d365f91449f..66f77b8af00d 100644 --- a/svx/source/dialog/pagectrl.cxx +++ b/svx/source/dialog/pagectrl.cxx @@ -73,8 +73,8 @@ void SvxPageWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Recta auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::MAPMODE); rRenderContext.SetMapMode(MapMode(MapUnit::MapTwip)); - Fraction aXScale(m_aWinSize.Width(), std::max(m_aSize.Width() * 2 + m_aSize.Width() / 8, tools::Long(1))); - Fraction aYScale(m_aWinSize.Height(), std::max(m_aSize.Height(), tools::Long(1))); + double aXScale = double(m_aWinSize.Width()) / std::max(m_aSize.Width() * 2 + m_aSize.Width() / 8, tools::Long(1)); + double aYScale = double(m_aWinSize.Height()) / std::max(m_aSize.Height(), tools::Long(1)); MapMode aMapMode(rRenderContext.GetMapMode()); if(aYScale < aXScale) @@ -97,9 +97,9 @@ void SvxPageWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Recta if (m_aSize.Width() > m_aSize.Height()) { // Draw Landscape page of the same size - Fraction aX = aMapMode.GetScaleX(); - Fraction aY = aMapMode.GetScaleY(); - Fraction a2(1.5); + double aX = aMapMode.GetScaleX(); + double aY = aMapMode.GetScaleY(); + double a2(1.5); aX *= a2; aY *= a2; aMapMode.SetScaleX(aX); diff --git a/svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx b/svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx index d05649b5e1cf..926e9580d0c7 100644 --- a/svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx +++ b/svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx @@ -862,8 +862,8 @@ namespace sdr::contact { ::basegfx::B2DHomMatrix aScaleNormalization; const MapMode& aCurrentDeviceMapMode( rPageViewDevice.GetMapMode() ); - aScaleNormalization.set( 0, 0, static_cast(aCurrentDeviceMapMode.GetScaleX()) ); - aScaleNormalization.set( 1, 1, static_cast(aCurrentDeviceMapMode.GetScaleY()) ); + aScaleNormalization.set( 0, 0, aCurrentDeviceMapMode.GetScaleX() ); + aScaleNormalization.set( 1, 1, aCurrentDeviceMapMode.GetScaleY() ); m_aZoomLevelNormalization *= aScaleNormalization; #if OSL_DEBUG_LEVEL > 0 diff --git a/svx/source/svdraw/svdpntv.cxx b/svx/source/svdraw/svdpntv.cxx index c755098e5fe7..f2d77c391c2c 100644 --- a/svx/source/svdraw/svdpntv.cxx +++ b/svx/source/svdraw/svdpntv.cxx @@ -1057,13 +1057,12 @@ void SdrPaintView::MakeVisible(const tools::Rectangle& rRect, vcl::Window& rWin) { bNewScale=true; // set new MapMode (Size+Org) and invalidate everything - Fraction aXFact(aNewSize.Width(),aActualSize.Width()); - Fraction aYFact(aNewSize.Height(),aActualSize.Height()); - if (aYFact>aXFact) aXFact=aYFact; - aXFact*=aMap.GetScaleX(); - aXFact.ReduceInaccurate(10); // to avoid runovers and BigInt mapping - aMap.SetScaleX(aXFact); - aMap.SetScaleY(aYFact); + double fXFact = double(aNewSize.Width()) / aActualSize.Width(); + double fYFact = double(aNewSize.Height()) / aActualSize.Height(); + if (fYFact>fXFact) fXFact=fYFact; + fXFact*=aMap.GetScaleX(); + aMap.SetScaleX(fXFact); + aMap.SetScaleY(fYFact); rWin.SetMapMode(aMap); aActualSize=rWin.GetOutDev()->GetOutputSize(); } diff --git a/svx/source/svdraw/svdxcgv.cxx b/svx/source/svdraw/svdxcgv.cxx index f9344fbef750..d6ba4fedbab9 100644 --- a/svx/source/svdraw/svdxcgv.cxx +++ b/svx/source/svdraw/svdxcgv.cxx @@ -396,8 +396,8 @@ void SdrExchangeView::ImpPasteObject(SdrObject* pObj, SdrObjList& rLst, const Po MapUnit eSrcMU=rMap.GetMapUnit(); MapUnit eDstMU = GetModel().GetScaleUnit(); FrPair aMapFact(GetMapFactor(eSrcMU,eDstMU)); - nSizX *= double(aMapFact.X() * rMap.GetScaleX()); - nSizY *= double(aMapFact.Y() * rMap.GetScaleY()); + nSizX *= aMapFact.X() * rMap.GetScaleX(); + nSizY *= aMapFact.Y() * rMap.GetScaleY(); tools::Long xs=nSizX; tools::Long ys=nSizY; // set the pos to 0, 0 for online case diff --git a/svx/source/unodraw/UnoGraphicExporter.cxx b/svx/source/unodraw/UnoGraphicExporter.cxx index 235ebc5d3752..9dd8da5d0170 100644 --- a/svx/source/unodraw/UnoGraphicExporter.cxx +++ b/svx/source/unodraw/UnoGraphicExporter.cxx @@ -312,22 +312,22 @@ VclPtr GraphicExporter::CreatePageVDev( SdrPage* pPage, tools::Lo // use scaling? if( nWidthPixel != 0 ) { - const Fraction aFrac( nWidthPixel, pVDev->LogicToPixel( aPageSize, aMM ).Width() ); + const double fFrac = double( nWidthPixel ) / pVDev->LogicToPixel( aPageSize, aMM ).Width(); - aMM.SetScaleX( aFrac ); + aMM.SetScaleX( fFrac ); if( nHeightPixel == 0 ) - aMM.SetScaleY( aFrac ); + aMM.SetScaleY( fFrac ); } if( nHeightPixel != 0 ) { - const Fraction aFrac( nHeightPixel, pVDev->LogicToPixel( aPageSize, aMM ).Height() ); + const double fFrac = double( nHeightPixel ) / pVDev->LogicToPixel( aPageSize, aMM ).Height(); if( nWidthPixel == 0 ) - aMM.SetScaleX( aFrac ); + aMM.SetScaleX( fFrac ); - aMM.SetScaleY( aFrac ); + aMM.SetScaleY( fFrac ); } pVDev->SetMapMode( aMM ); @@ -569,7 +569,7 @@ bool GraphicExporter::GetGraphic( ExportSettings const & rSettings, Graphic& aGr return false; ScopedVclPtrInstance< VirtualDevice > aVDev; - const MapMode aMap( mpDoc->GetScaleUnit(), Point(), rSettings.maScaleX, rSettings.maScaleY ); + const MapMode aMap( mpDoc->GetScaleUnit(), Point(), double(rSettings.maScaleX), double(rSettings.maScaleY) ); SdrOutliner& rOutl=mpDoc->GetDrawOutliner(); maOldCalcFieldValueHdl = rOutl.GetCalcFieldValueHdl(); diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx index fa389187f344..b0363a5d3388 100644 --- a/sw/source/core/layout/paintfrm.cxx +++ b/sw/source/core/layout/paintfrm.cxx @@ -404,8 +404,8 @@ void SwCalcPixStatics( vcl::RenderContext const *pOut ) gProp.nSMinDistPixelH = gProp.nSPixelSzH * 2 + 1; const MapMode &rMap = pOut->GetMapMode(); - gProp.aSScaleX = double(rMap.GetScaleX()); - gProp.aSScaleY = double(rMap.GetScaleY()); + gProp.aSScaleX = rMap.GetScaleX(); + gProp.aSScaleY = rMap.GetScaleY(); } namespace { diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx index 0e04f48cfe5f..c26bf14f4599 100644 --- a/sw/source/core/txtnode/fntcache.cxx +++ b/sw/source/core/txtnode/fntcache.cxx @@ -1146,9 +1146,9 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) if ( bDirectPrint ) { - const Fraction aTmp( 1, 1 ); + const double fTmp = 1.0; bool bStretch = rInf.GetWidth() && (rInf.GetLen() > TextFrameIndex(1)) && bPrt - && ( aTmp != rInf.GetOut().GetMapMode().GetScaleX() ); + && ( fTmp != rInf.GetOut().GetMapMode().GetScaleX() ); if ( bSwitchL2R ) rInf.GetFrame()->SwitchLTRtoRTL( aTextOriginPos ); diff --git a/sw/source/core/view/pagepreviewlayout.cxx b/sw/source/core/view/pagepreviewlayout.cxx index 4270a3e58a1c..4365515c993c 100644 --- a/sw/source/core/view/pagepreviewlayout.cxx +++ b/sw/source/core/view/pagepreviewlayout.cxx @@ -204,22 +204,16 @@ void SwPagePreviewLayout::Init( const sal_uInt16 _nCols, // calculate scaling MapMode aMapMode( MapUnit::MapTwip ); Size aWinSize = mrParentViewShell.GetOut()->PixelToLogic( _rPxWinSize, aMapMode ); - Fraction aXScale( aWinSize.Width(), mnPreviewLayoutWidth ); - Fraction aYScale( aWinSize.Height(), mnPreviewLayoutHeight ); - if( aXScale < aYScale ) - aYScale = aXScale; + double fXScale = double(aWinSize.Width()) / mnPreviewLayoutWidth; + double fYScale = double(aWinSize.Height()) / mnPreviewLayoutHeight; + if( fXScale < fYScale ) + fYScale = fXScale; { - // adjust scaling for Drawing layer. - aYScale *= Fraction( 1000, 1 ); - tools::Long nNewNuminator = aYScale.operator long(); - if( nNewNuminator < 1 ) - nNewNuminator = 1; - aYScale = Fraction( nNewNuminator, 1000 ); // propagate scaling as zoom percentage to view options for font cache - ApplyNewZoomAtViewShell( static_cast(nNewNuminator/10) ); + ApplyNewZoomAtViewShell( std::round(fYScale * 100) ); - aMapMode.SetScaleY( aYScale ); - aMapMode.SetScaleX( aYScale ); + aMapMode.SetScaleY( fYScale ); + aMapMode.SetScaleX( fYScale ); // set created mapping mode with calculated scaling at output device. mrParentViewShell.GetOut()->SetMapMode( aMapMode ); // update statics for paint. @@ -1141,7 +1135,7 @@ bool SwPagePreviewLayout::Paint(vcl::RenderContext& rRenderContext, const tools: // update at accessibility interface mrParentViewShell.Imp()->UpdateAccessiblePreview( maPreviewPages, - double(aMapMode.GetScaleX()), + aMapMode.GetScaleX(), mrLayoutRootFrame.GetPageByPageNum( mnSelectedPageNum ), maWinSize ); } diff --git a/sw/source/core/view/viewpg.cxx b/sw/source/core/view/viewpg.cxx index 535fb40000d3..adc924d2d6ce 100644 --- a/sw/source/core/view/viewpg.cxx +++ b/sw/source/core/view/viewpg.cxx @@ -159,24 +159,13 @@ void SwViewShell::PrintProspect( // set the MapMode aMapMode.SetOrigin( Point() ); { - Fraction aScX( aPrtSize.Width(), nMaxColSz ); - Fraction aScY( aPrtSize.Height(), nMaxRowSz ); - if( aScX < aScY ) - aScY = aScX; + double fScX = double(aPrtSize.Width()) / nMaxColSz; + double fScY = double(aPrtSize.Height()) / nMaxRowSz; + if( fScX < fScY ) + fScY = fScX; - { - // Round percentages for Drawings so that these can paint their objects properly - aScY *= Fraction( 1000, 1 ); - tools::Long nTmp = static_cast(aScY); - if( 1 < nTmp ) - --nTmp; - else - nTmp = 1; - aScY = Fraction( nTmp, 1000 ); - } - - aMapMode.SetScaleY( aScY ); - aMapMode.SetScaleX( aScY ); + aMapMode.SetScaleY( fScY ); + aMapMode.SetScaleX( fScY ); } Size aTmpPrtSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), aMapMode ) ); diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx index 384df677299a..8f923643fca6 100644 --- a/sw/source/core/view/viewsh.cxx +++ b/sw/source/core/view/viewsh.cxx @@ -2177,8 +2177,8 @@ void SwViewShell::PaintTile(VirtualDevice &rDevice, int contextWidth, int contex // Scaling. Must convert from pixels to twips. We know // that VirtualDevices use a DPI of 96. const double scale = conversionFract(o3tl::Length::px, o3tl::Length::twip); - Fraction scaleX = Fraction(contextWidth, tileWidth) * scale; - Fraction scaleY = Fraction(contextHeight, tileHeight) * scale; + double scaleX = double(contextWidth) / tileWidth * scale; + double scaleY = double(contextHeight) / tileHeight * scale; aMapMode.SetScaleX(scaleX); aMapMode.SetScaleY(scaleY); rDevice.SetMapMode(aMapMode); @@ -2187,7 +2187,7 @@ void SwViewShell::PaintTile(VirtualDevice &rDevice, int contextWidth, int contex sal_uInt16 nOldZoomValue = 0; if (GetWin() && GetWin()->GetMapMode().GetScaleX() != scaleX) { - double fScale = double(scaleX); + double fScale = scaleX; SwViewOption aOption(*GetViewOptions()); nOldZoomValue = aOption.GetZoom(); aOption.SetZoom(fScale * 100); @@ -2502,9 +2502,9 @@ void SwViewShell::ImplApplyViewOptions( const SwViewOption &rOpt ) if( mpOpt->GetZoom() != rOpt.GetZoom() && !IsPreview() ) { MapMode aMode( pMyWin->GetMapMode() ); - Fraction aNewFactor( rOpt.GetZoom(), 100 ); - aMode.SetScaleX( aNewFactor ); - aMode.SetScaleY( aNewFactor ); + double fNewFactor = double(rOpt.GetZoom()) / 100; + aMode.SetScaleX( fNewFactor ); + aMode.SetScaleY( fNewFactor ); pMyWin->SetMapMode( aMode ); // if not a reference device (printer) is used for formatting, // but the screen, new formatting is needed for zoomfactor changes. @@ -2758,7 +2758,7 @@ rtl::Reference SwViewShell::CreateAccessiblePreview() { return Imp()->GetAccessibleMap().GetDocumentPreview( PagePreviewLayout()->maPreviewPages, - double(GetWin()->GetMapMode().GetScaleX()), + GetWin()->GetMapMode().GetScaleX(), GetLayout()->GetPageByPageNum( PagePreviewLayout()->mnSelectedPageNum ), PagePreviewLayout()->maWinSize ); } diff --git a/sw/source/core/view/vnew.cxx b/sw/source/core/view/vnew.cxx index f85d5c6c94c1..87e5b19f348e 100644 --- a/sw/source/core/view/vnew.cxx +++ b/sw/source/core/view/vnew.cxx @@ -81,9 +81,9 @@ void SwViewShell::Init( const SwViewOption *pNewOpt, tools::Long const nFlags) if( GetWin() && 100 != mpOpt->GetZoom() ) { MapMode aMode( mpWin->GetMapMode() ); - const Fraction aNewFactor( mpOpt->GetZoom(), 100 ); - aMode.SetScaleX( aNewFactor ); - aMode.SetScaleY( aNewFactor ); + double fNewFactor = double(mpOpt->GetZoom()) / 100; + aMode.SetScaleX( fNewFactor ); + aMode.SetScaleY( fNewFactor ); mpWin->SetMapMode( aMode ); } } diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx b/sw/source/uibase/docvw/AnnotationWin2.cxx index 801e21892e6f..ec8d2bf999dc 100644 --- a/sw/source/uibase/docvw/AnnotationWin2.cxx +++ b/sw/source/uibase/docvw/AnnotationWin2.cxx @@ -494,11 +494,11 @@ void SwAnnotationWin::SetMenuButtonColors() SwWrtShell* pWrtShell = mrView.GetWrtShellPtr(); if (!pWrtShell) return; - const Fraction& rFraction = pWrtShell->GetOut()->GetMapMode().GetScaleY(); + double fFraction = pWrtShell->GetOut()->GetMapMode().GetScaleY(); ScopedVclPtrInstance xVirDev; - Size aSize(tools::Long(METABUTTON_WIDTH * rFraction), - tools::Long(METABUTTON_HEIGHT * rFraction)); + Size aSize(tools::Long(METABUTTON_WIDTH * fFraction), + tools::Long(METABUTTON_HEIGHT * fFraction)); tools::Rectangle aRect(Point(0, 0), aSize); xVirDev->SetOutputSizePixel(aSize); @@ -552,10 +552,10 @@ void SwAnnotationWin::Rescale() SwWrtShell* pWrtShell = mrView.GetWrtShellPtr(); if (!pWrtShell) return; - const Fraction& rFraction = pWrtShell->GetOut()->GetMapMode().GetScaleY(); + double fFraction = pWrtShell->GetOut()->GetMapMode().GetScaleY(); vcl::Font aFont = maLabelFont; - sal_Int32 nHeight = tools::Long(aFont.GetFontHeight() * rFraction); + sal_Int32 nHeight = tools::Long(aFont.GetFontHeight() * fFraction); aFont.SetFontHeight( nHeight ); if (mxMetadataAuthor) @@ -1306,7 +1306,7 @@ int SwAnnotationWin::GetPrefScrollbarWidth() const { if (SwWrtShell* pWrtShell = mrView.GetWrtShellPtr()) { - const Fraction& f(pWrtShell->GetOut()->GetMapMode().GetScaleY()); + double f(pWrtShell->GetOut()->GetMapMode().GetScaleY()); return tools::Long(Application::GetSettings().GetStyleSettings().GetScrollBarSize() * f); } else @@ -1339,7 +1339,7 @@ sal_Int32 SwAnnotationWin::GetMinimumSizeWithoutMeta() const { if (SwWrtShell* pWrtShell = mrView.GetWrtShellPtr()) { - const Fraction& f(pWrtShell->GetOut()->GetMapMode().GetScaleY()); + double f(pWrtShell->GetOut()->GetMapMode().GetScaleY()); return tools::Long(POSTIT_MINIMUMSIZE_WITHOUT_META * f); } else diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx index 9a437c36412b..91729bc48205 100644 --- a/sw/source/uibase/docvw/PostItMgr.cxx +++ b/sw/source/uibase/docvw/PostItMgr.cxx @@ -2476,7 +2476,7 @@ tools::ULong SwPostItMgr::GetSidebarWidth(bool bPx) const if (comphelper::LibreOfficeKit::isActive() && !bEnableMapMode) { // The output device is the tile and contains the real wanted scale factor. - double fScaleX = double(mpWrtShell->GetOut()->GetMapMode().GetScaleX()); + double fScaleX = mpWrtShell->GetOut()->GetMapMode().GetScaleX(); nZoom = fScaleX * 100; } double fDisplayWidthFactor; @@ -2610,31 +2610,31 @@ void SwPostItMgr::Rescale() sal_Int32 SwPostItMgr::GetInitialAnchorDistance() const { - const Fraction& f( mpEditWin->GetMapMode().GetScaleY() ); + double f( mpEditWin->GetMapMode().GetScaleY() ); return sal_Int32(POSTIT_INITIAL_ANCHOR_DISTANCE * f); } sal_Int32 SwPostItMgr::GetSpaceBetween() const { - const Fraction& f( mpEditWin->GetMapMode().GetScaleY() ); + double f( mpEditWin->GetMapMode().GetScaleY() ); return sal_Int32(POSTIT_SPACE_BETWEEN * f); } sal_Int32 SwPostItMgr::GetScrollSize() const { - const Fraction& f( mpEditWin->GetMapMode().GetScaleY() ); + double f( mpEditWin->GetMapMode().GetScaleY() ); return sal_Int32((POSTIT_SPACE_BETWEEN + POSTIT_MINIMUMSIZE_WITH_META) * f); } sal_Int32 SwPostItMgr::GetMinimumSizeWithMeta() const { - const Fraction& f( mpEditWin->GetMapMode().GetScaleY() ); + double f( mpEditWin->GetMapMode().GetScaleY() ); return sal_Int32(POSTIT_MINIMUMSIZE_WITH_META * f); } sal_Int32 SwPostItMgr::GetSidebarScrollerHeight() const { - const Fraction& f( mpEditWin->GetMapMode().GetScaleY() ); + double f( mpEditWin->GetMapMode().GetScaleY() ); return sal_Int32(POSTIT_SCROLL_SIDEBAR_HEIGHT * f); } diff --git a/sw/source/uibase/frmdlg/colex.cxx b/sw/source/uibase/frmdlg/colex.cxx index 26b08f1faf08..651abfe67880 100644 --- a/sw/source/uibase/frmdlg/colex.cxx +++ b/sw/source/uibase/frmdlg/colex.cxx @@ -316,10 +316,10 @@ void SwColumnOnlyExample::Paint(vcl::RenderContext& rRenderContext, const tools: auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::MAPMODE); rRenderContext.Erase(); - Fraction aScale(m_aWinSize.Height(), m_aFrameSize.Height()); + double fScale = double(m_aWinSize.Height()) / m_aFrameSize.Height(); MapMode aMapMode(MapUnit::MapTwip); - aMapMode.SetScaleX(aScale); - aMapMode.SetScaleY(aScale); + aMapMode.SetScaleX(fScale); + aMapMode.SetScaleY(fScale); rRenderContext.SetMapMode(aMapMode); const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); diff --git a/sw/source/uibase/uiview/pview.cxx b/sw/source/uibase/uiview/pview.cxx index 1c2b1e39cd66..3820878a76da 100644 --- a/sw/source/uibase/uiview/pview.cxx +++ b/sw/source/uibase/uiview/pview.cxx @@ -236,7 +236,7 @@ void SwPagePreviewWin::CalcWish( sal_Int16 nNewRow, sal_Int16 nNewCol ) mnSttPage, maPaintedPreviewDocRect ); SetSelectedPage( mnSttPage ); SetPagePreview(mnRow, mnCol); - mfScale = double(GetMapMode().GetScaleX()); + mfScale = GetMapMode().GetScaleX(); // If changes have taken place at the columns, the special case "single column" // must be considered and corrected if necessary. @@ -379,7 +379,7 @@ void SwPagePreviewWin::SetWinSize( const Size& rNewSize ) if ( mbCalcScaleForPreviewLayout ) { mpPgPreviewLayout->Init( mnCol, mnRow, maPxWinSize ); - mfScale = double(GetMapMode().GetScaleX()); + mfScale = GetMapMode().GetScaleX(); } mpPgPreviewLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize, mnSttPage, maPaintedPreviewDocRect ); @@ -389,7 +389,7 @@ void SwPagePreviewWin::SetWinSize( const Size& rNewSize ) mbCalcScaleForPreviewLayout = false; } SetPagePreview(mnRow, mnCol); - mfScale = double(GetMapMode().GetScaleX()); + mfScale = GetMapMode().GetScaleX(); } OUString SwPagePreviewWin::GetStatusStr( sal_uInt16 nPageCnt ) const @@ -1751,7 +1751,7 @@ void SwPagePreviewWin::AdjustPreviewToNewZoom( const sal_uInt16 _nZoomFactor, mnSttPage, maPaintedPreviewDocRect ); SetSelectedPage( mnSttPage ); SetPagePreview(mnRow, mnCol); - mfScale = double(GetMapMode().GetScaleX()); + mfScale = GetMapMode().GetScaleX(); } else if ( _nZoomFactor != 0 ) { diff --git a/sw/source/uibase/uiview/viewport.cxx b/sw/source/uibase/uiview/viewport.cxx index 8d289755dcff..c541e6ff98e0 100644 --- a/sw/source/uibase/uiview/viewport.cxx +++ b/sw/source/uibase/uiview/viewport.cxx @@ -1003,14 +1003,12 @@ void SwView::InnerResizePixel( const Point &rOfst, const Size &rSize, bool ) if( m_pHRuler->IsVisible() || m_pVRuler->IsVisible() ) { - const Fraction& rFrac = GetEditWin().GetMapMode().GetScaleX(); - tools::Long nZoom = 100; - if (rFrac.IsValid()) - nZoom = tools::Long(rFrac * 100); + double fFrac = GetEditWin().GetMapMode().GetScaleX(); + tools::Long nZoom = tools::Long(fFrac * 100); - const double aFrac = double(nZoom) / 100; - m_pVRuler->SetZoom( aFrac ); - m_pHRuler->SetZoom( aFrac ); + fFrac = double(nZoom) / 100; + m_pVRuler->SetZoom( fFrac ); + m_pHRuler->SetZoom( fFrac ); InvalidateRulerPos(); // Invalidate content. } // Reset the cursor stack because the cursor positions for PageUp/Down diff --git a/vcl/qa/cppunit/TypeSerializerTest.cxx b/vcl/qa/cppunit/TypeSerializerTest.cxx index 344aae9efe5d..e255f83ee669 100644 --- a/vcl/qa/cppunit/TypeSerializerTest.cxx +++ b/vcl/qa/cppunit/TypeSerializerTest.cxx @@ -346,7 +346,7 @@ void TypeSerializerTest::testMapMode() CPPUNIT_ASSERT_EQUAL(true, aReadMapMode.IsSimple()); } { // "complex" case - map unit, origin and scale are set, IsSimple = false - MapMode aMapMode(MapUnit::MapTwip, Point(5, 10), Fraction(1, 2), Fraction(2, 3)); + MapMode aMapMode(MapUnit::MapTwip, Point(5, 10), 1.0 / 2, 2.0 / 3); SvMemoryStream aStream; TypeSerializer aSerializer(aStream); @@ -358,10 +358,8 @@ void TypeSerializerTest::testMapMode() CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aReadMapMode.GetMapUnit()); CPPUNIT_ASSERT_EQUAL(tools::Long(5), aReadMapMode.GetOrigin().X()); CPPUNIT_ASSERT_EQUAL(tools::Long(10), aReadMapMode.GetOrigin().Y()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aReadMapMode.GetScaleX().GetNumerator()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aReadMapMode.GetScaleX().GetDenominator()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aReadMapMode.GetScaleY().GetNumerator()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aReadMapMode.GetScaleY().GetDenominator()); + CPPUNIT_ASSERT_EQUAL(0.5, aReadMapMode.GetScaleX()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0 / 3, aReadMapMode.GetScaleY(), 1E-9); CPPUNIT_ASSERT_EQUAL(false, aReadMapMode.IsSimple()); } } diff --git a/vcl/qa/cppunit/svm/data/eps.svm b/vcl/qa/cppunit/svm/data/eps.svm index 33b923a14adc..ed8a32417a67 100644 Binary files a/vcl/qa/cppunit/svm/data/eps.svm and b/vcl/qa/cppunit/svm/data/eps.svm differ diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx index f2452c135de0..37e939df3537 100644 --- a/vcl/qa/cppunit/svm/svmtest.cxx +++ b/vcl/qa/cppunit/svm/svmtest.cxx @@ -1957,14 +1957,14 @@ void SvmTest::checkMapMode(const GDIMetaFile& rMetafile) {"x", u"0"}, {"y", u"1"}, {"scalex", u"(1/2)"}, - {"scaley", u"(2/3)"} + {"scaley", u"(333333333/500000000)"} // approximation of 2/3 }); assertXPathAttrs(pDoc, "/metafile/mapmode[3]", { {"mapunit", u"MapRelative"}, {"x", u"0"}, {"y", u"-1"}, - {"scalex", u"(25/12)"}, + {"scalex", u"(2083333333/1000000000)"}, // approximation of 25/12 {"scaley", u"(25/16)"} }); } @@ -1983,8 +1983,8 @@ void SvmTest::testMapMode() MapMode aMapMode1(MapUnit::Map100thInch); aMapMode1.SetOrigin(Point(0, 1)); - aMapMode1.SetScaleX(Fraction(1, 2)); - aMapMode1.SetScaleY(Fraction(2, 3)); + aMapMode1.SetScaleX(1.0 / 2); + aMapMode1.SetScaleY(2.0 / 3); pVirtualDev->SetMetafileMapMode(aMapMode1, false); @@ -2220,7 +2220,7 @@ void SvmTest::checkEPS(const GDIMetaFile& rMetaFile) {"x", u"0"}, {"y", u"1"}, {"scalex", u"(1/2)"}, - {"scaley", u"(2/3)"} + {"scaley", u"(333333333/500000000)"} // approximation of 2/3 }); assertXPathAttrs(pDoc, "/metafile/eps[1]/metafile[1]/point[1]", { @@ -2246,8 +2246,8 @@ void SvmTest::testEPS() MapMode aMapMode1(MapUnit::Map100thInch); aMapMode1.SetOrigin(Point(0, 1)); - aMapMode1.SetScaleX(Fraction(1, 2)); - aMapMode1.SetScaleY(Fraction(2, 3)); + aMapMode1.SetScaleX(1.0 / 2); + aMapMode1.SetScaleY(2.0 / 3); GDIMetaFile aGDIMetaFile1; ScopedVclPtrInstance pVirtualDev1; diff --git a/vcl/qa/cppunit/vclmaptest.cxx b/vcl/qa/cppunit/vclmaptest.cxx index 438a39e894cc..78d510e770cd 100644 --- a/vcl/qa/cppunit/vclmaptest.cxx +++ b/vcl/qa/cppunit/vclmaptest.cxx @@ -50,8 +50,8 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testFractionScaling) // Converting 100 Source -> 50 Dest MapMode aSource(MapUnit::MapMM); - aSource.SetScaleX(Fraction(1, 2)); - aSource.SetScaleY(Fraction(1, 2)); + aSource.SetScaleX(0.5); + aSource.SetScaleY(0.5); MapMode aDest(MapUnit::MapMM); // Default 1:1 @@ -70,10 +70,10 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testIntermediateOverflow) constexpr tools::Long nExpected = static_cast(25400000000); MapMode aSource(MapUnit::MapInch); - aSource.SetScaleX(Fraction(nLarge, 1)); + aSource.SetScaleX(nLarge); MapMode aDest(MapUnit::Map100thMM); - aDest.SetScaleX(Fraction(nLarge, 1)); + aDest.SetScaleX(nLarge); // n1 (Coord) = 10,000,000 // n2 (Scale) = 2^30 (~10^9) @@ -219,8 +219,8 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testZoomScaling) // Dest: 100thMM at 100% zoom (Scale 1:1) MapMode aSource(MapUnit::Map100thMM); - aSource.SetScaleX(Fraction(4, 1)); - aSource.SetScaleY(Fraction(4, 1)); + aSource.SetScaleX(4.0); + aSource.SetScaleY(4.0); MapMode aDest(MapUnit::Map100thMM); @@ -244,10 +244,10 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testComplexFractions) // Conversion: Val * (1/3) / (1/7) = Val * 7/3 ~= Val * 2.333 MapMode aSource(MapUnit::MapMM); - aSource.SetScaleX(Fraction(1, 3)); + aSource.SetScaleX(1.0 / 3); MapMode aDest(MapUnit::MapMM); - aDest.SetScaleX(Fraction(1, 7)); + aDest.SetScaleX(1.0 / 7); Point aPt(300, 0); // 300 * 7 / 3 = 100 * 7 = 700 diff --git a/vcl/source/bitmap/dibtools.cxx b/vcl/source/bitmap/dibtools.cxx index 55457c1820ee..a29d51a28ec3 100644 --- a/vcl/source/bitmap/dibtools.cxx +++ b/vcl/source/bitmap/dibtools.cxx @@ -1012,8 +1012,8 @@ bool ImplReadDIBBody(SvStream& rIStm, Bitmap& rBmp, AlphaMask* pBmpAlpha, sal_uI MapMode aMapMode( MapUnit::MapMM, Point(), - Fraction(1000, aHeader.nXPelsPerMeter), - Fraction(1000, aHeader.nYPelsPerMeter)); + 1000.0 / aHeader.nXPelsPerMeter, + 1000.0 / aHeader.nYPelsPerMeter); aNewBmp.SetPrefMapMode(aMapMode); aNewBmp.SetPrefSize(Size(aHeader.nWidth, aHeader.nHeight)); diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 63dc0670172a..4664fdeb61e8 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -223,10 +223,10 @@ static Graphic ImpGetScaledGraphic( const Graphic& rGraphic, FilterConfigItem& r MapMode aMap( MapUnit::Map100thInch ); sal_Int32 nDPI = rConfigItem.ReadInt32( u"Resolution"_ustr, 75 ); - Fraction aFrac( 1, std::clamp( nDPI, sal_Int32(75), sal_Int32(600) ) ); + double fFrac = 1.0 / std::clamp( nDPI, sal_Int32(75), sal_Int32(600) ); - aMap.SetScaleX( aFrac ); - aMap.SetScaleY( aFrac ); + aMap.SetScaleX( fFrac ); + aMap.SetScaleY( fFrac ); Size aOldSize = aBitmap.GetSizePixel(); aGraphic = rGraphic; diff --git a/vcl/source/filter/ipsd/ipsd.cxx b/vcl/source/filter/ipsd/ipsd.cxx index e669e2227c79..4de0c89df280 100644 --- a/vcl/source/filter/ipsd/ipsd.cxx +++ b/vcl/source/filter/ipsd/ipsd.cxx @@ -147,9 +147,9 @@ bool PSDReader::ReadPSD(Graphic & rGraphic ) if ( mnXResFixed && mnYResFixed ) { - Fraction aFractX( 1, mnXResFixed >> 16 ); - Fraction aFractY( 1, mnYResFixed >> 16 ); - MapMode aMapMode( MapUnit::MapInch, Point(), aFractX, aFractY ); + double fFractX = 1.0 / (mnXResFixed >> 16); + double fFractY = 1.0 / (mnYResFixed >> 16); + MapMode aMapMode( MapUnit::MapInch, Point(), fFractX, fFractY ); Size aPrefSize = OutputDevice::LogicToLogic(aBitmapSize, aMapMode, MapMode(MapUnit::Map100thMM)); rGraphic.SetPrefSize( aPrefSize ); rGraphic.SetPrefMapMode( MapMode( MapUnit::Map100thMM ) ); diff --git a/vcl/source/filter/jpeg/JpegReader.cxx b/vcl/source/filter/jpeg/JpegReader.cxx index b497dd751786..ca2597de49a8 100644 --- a/vcl/source/filter/jpeg/JpegReader.cxx +++ b/vcl/source/filter/jpeg/JpegReader.cxx @@ -222,9 +222,9 @@ bool JPEGReader::CreateBitmap(JPEGCreateBitmapParam const & rParam) if (((1 == nUnit) || (2 == nUnit)) && rParam.X_density && rParam.Y_density ) { - Fraction aFractX( 1, rParam.X_density ); - Fraction aFractY( 1, rParam.Y_density ); - MapMode aMapMode( nUnit == 1 ? MapUnit::MapInch : MapUnit::MapCM, Point(), aFractX, aFractY ); + double fFractX = 1.0 / rParam.X_density; + double fFractY = 1.0 / rParam.Y_density; + MapMode aMapMode( nUnit == 1 ? MapUnit::MapInch : MapUnit::MapCM, Point(), fFractX, fFractY ); Size aPrefSize = OutputDevice::LogicToLogic(aSize, aMapMode, MapMode(MapUnit::Map100thMM)); mpBitmap->SetPrefSize(aPrefSize); diff --git a/vcl/source/filter/wmf/wmfwr.cxx b/vcl/source/filter/wmf/wmfwr.cxx index b695841529bb..d5c30e5a3aa0 100644 --- a/vcl/source/filter/wmf/wmfwr.cxx +++ b/vcl/source/filter/wmf/wmfwr.cxx @@ -1398,44 +1398,20 @@ void WMFWriter::WriteRecords( const GDIMetaFile & rMTF ) if( pA->GetMapMode().GetMapUnit() == MapUnit::MapRelative ) { const MapMode& aMM = pA->GetMapMode(); - Fraction aScaleX = aMM.GetScaleX(); - Fraction aScaleY = aMM.GetScaleY(); + double fScaleX = aMM.GetScaleX(); + double fScaleY = aMM.GetScaleY(); Point aOrigin = aSrcMapMode.GetOrigin(); - BigInt aX( aOrigin.X() ); - aX *= BigInt( aScaleX.GetDenominator() ); - if( aOrigin.X() >= 0 ) - if( aScaleX.GetNumerator() >= 0 ) - aX += BigInt( aScaleX.GetNumerator()/2 ); - else - aX -= BigInt( (aScaleX.GetNumerator()+1)/2 ); - else - if( aScaleX.GetNumerator() >= 0 ) - aX -= BigInt( (aScaleX.GetNumerator()-1)/2 ); - else - aX += BigInt( aScaleX.GetNumerator()/2 ); - aX /= BigInt( aScaleX.GetNumerator() ); - aOrigin.setX( static_cast(aX) + aMM.GetOrigin().X() ); - BigInt aY( aOrigin.Y() ); - aY *= BigInt( aScaleY.GetDenominator() ); - if( aOrigin.Y() >= 0 ) - if( aScaleY.GetNumerator() >= 0 ) - aY += BigInt( aScaleY.GetNumerator()/2 ); - else - aY -= BigInt( (aScaleY.GetNumerator()+1)/2 ); - else - if( aScaleY.GetNumerator() >= 0 ) - aY -= BigInt( (aScaleY.GetNumerator()-1)/2 ); - else - aY += BigInt( aScaleY.GetNumerator()/2 ); - aY /= BigInt( aScaleY.GetNumerator() ); - aOrigin.setY( static_cast(aY) + aMM.GetOrigin().Y() ); + tools::Long aX = std::llround(double( aOrigin.X() ) / fScaleX); + aOrigin.setX( aX + aMM.GetOrigin().X() ); + tools::Long aY = std::llround(double( aOrigin.Y() ) / fScaleY); + aOrigin.setY( aY + aMM.GetOrigin().Y() ); aSrcMapMode.SetOrigin( aOrigin ); - aScaleX *= aSrcMapMode.GetScaleX(); - aScaleY *= aSrcMapMode.GetScaleY(); - aSrcMapMode.SetScaleX( aScaleX ); - aSrcMapMode.SetScaleY( aScaleY ); + fScaleX *= aSrcMapMode.GetScaleX(); + fScaleY *= aSrcMapMode.GetScaleY(); + aSrcMapMode.SetScaleX( fScaleX ); + aSrcMapMode.SetScaleY( fScaleY ); } else aSrcMapMode=pA->GetMapMode(); @@ -1724,10 +1700,10 @@ bool WMFWriter::WriteWMF( const GDIMetaFile& rMTF, SvStream& rTargetStream, aTargetMapMode = MapMode( MapUnit::MapInch ); const tools::Long nUnit = pVirDev->LogicToPixel( Size( 1, 1 ), aTargetMapMode ).Width(); - const Fraction aFrac( 1, nUnit ); + const double fFrac = 1.0 / nUnit; - aTargetMapMode.SetScaleX( aFrac ); - aTargetMapMode.SetScaleY( aFrac ); + aTargetMapMode.SetScaleX( fFrac ); + aTargetMapMode.SetScaleY( fFrac ); aTargetSize = OutputDevice::LogicToLogic( rMTF.GetPrefSize(), aSrcMapMode, aTargetMapMode ); } @@ -1807,20 +1783,20 @@ bool WMFWriter::WriteWMF( const GDIMetaFile& rMTF, SvStream& rTargetStream, sal_uInt16 WMFWriter::CalcSaveTargetMapMode(MapMode& rMapMode, const Size& rPrefSize) { - Fraction aDivFrac(2, 1); + double fDivFrac = 2.0; sal_uInt16 nDivisor = 1; Size aSize = OutputDevice::LogicToLogic( rPrefSize, aSrcMapMode, rMapMode ); while( nDivisor <= 64 && (aSize.Width() > 32767 || aSize.Height() > 32767) ) { - Fraction aFrac = rMapMode.GetScaleX(); + double fFrac = rMapMode.GetScaleX(); - aFrac *= aDivFrac; - rMapMode.SetScaleX(aFrac); - aFrac = rMapMode.GetScaleY(); - aFrac *= aDivFrac; - rMapMode.SetScaleY(aFrac); + fFrac *= fDivFrac; + rMapMode.SetScaleX(fFrac); + fFrac = rMapMode.GetScaleY(); + fFrac *= fDivFrac; + rMapMode.SetScaleY(fFrac); nDivisor <<= 1; aSize = OutputDevice::LogicToLogic( rPrefSize, aSrcMapMode, rMapMode ); } diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx index dc21b03bdda9..8ea9d85477ea 100644 --- a/vcl/source/gdi/TypeSerializer.cxx +++ b/vcl/source/gdi/TypeSerializer.cxx @@ -444,17 +444,6 @@ void TypeSerializer::writeGraphic(const Graphic& rGraphic) } } -bool TooLargeScaleForMapMode(const Fraction& rScale, int nDPI) -{ - // ImplLogicToPixel will multiply its values by this numerator * dpi and then double that - // result before dividing - if (rScale.GetNumerator() > std::numeric_limits::max() / nDPI / 2) - return true; - if (rScale.GetNumerator() < std::numeric_limits::min() / nDPI / 2) - return true; - return false; -} - static bool UselessScaleForMapMode(const Fraction& rScale) { if (!rScale.IsValid()) @@ -517,7 +506,7 @@ bool TypeSerializer::readMapMode(MapMode& rMapMode) SAL_WARN("vcl", "invalid scale"); return false; } - rMapMode = MapMode(eUnit, aOrigin, aScaleX, aScaleY); + rMapMode = MapMode(eUnit, aOrigin, double(aScaleX), double(aScaleY)); } return true; } @@ -528,8 +517,8 @@ void TypeSerializer::writeMapMode(MapMode const& rMapMode) mrStream.WriteUInt16(sal_uInt16(rMapMode.GetMapUnit())); writePoint(rMapMode.GetOrigin()); - writeFraction(rMapMode.GetScaleX()); - writeFraction(rMapMode.GetScaleY()); + writeFraction(Fraction(rMapMode.GetScaleX())); + writeFraction(Fraction(rMapMode.GetScaleY())); mrStream.WriteBool(rMapMode.IsSimple()); } diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx index f6962397eb68..e099841656d3 100644 --- a/vcl/source/gdi/gdimtf.cxx +++ b/vcl/source/gdi/gdimtf.cxx @@ -472,26 +472,14 @@ void GDIMetaFile::Play(OutputDevice& rOut, const Point& rPos, if( !aTmpPrefSize.Height() ) aTmpPrefSize.setHeight( aDestSize.Height() ); - Fraction aScaleX( aDestSize.Width(), aTmpPrefSize.Width() ); - Fraction aScaleY( aDestSize.Height(), aTmpPrefSize.Height() ); + double fScaleX = double( aDestSize.Width() ) / aTmpPrefSize.Width(); + double fScaleY = double( aDestSize.Height() ) / aTmpPrefSize.Height(); - aScaleX *= aDrawMap.GetScaleX(); - aScaleY *= aDrawMap.GetScaleY(); - // try reducing inaccurary first and abandon if the scaling - // still cannot be achieved - if (TooLargeScaleForMapMode(aScaleX, rOut.GetDPIX())) - aScaleX.ReduceInaccurate(10); - if (TooLargeScaleForMapMode(aScaleY, rOut.GetDPIY())) - aScaleY.ReduceInaccurate(10); - if (TooLargeScaleForMapMode(aScaleX, rOut.GetDPIX()) || - TooLargeScaleForMapMode(aScaleY, rOut.GetDPIY())) - { - SAL_WARN("vcl", "GDIMetaFile Scaling is too high"); - return; - } + fScaleX *= aDrawMap.GetScaleX(); + fScaleY *= aDrawMap.GetScaleY(); - aDrawMap.SetScaleX(aScaleX); - aDrawMap.SetScaleY(aScaleY); + aDrawMap.SetScaleX(fScaleX); + aDrawMap.SetScaleY(fScaleY); // #i47260# Convert logical output position to offset within // the metafile's mapmode. Therefore, disable pixel offset on @@ -703,8 +691,8 @@ void GDIMetaFile::Move( tools::Long nX, tools::Long nY, tools::Long nDPIX, tools { aOffset = aMapVDev->LogicToPixel( aBaseOffset, GetPrefMapMode() ); MapMode aMap( aMapVDev->GetMapMode() ); - aOffset.setWidth( static_cast(aOffset.Width() * static_cast(aMap.GetScaleX())) ); - aOffset.setHeight( static_cast(aOffset.Height() * static_cast(aMap.GetScaleY())) ); + aOffset.setWidth( static_cast(aOffset.Width() * aMap.GetScaleX()) ); + aOffset.setHeight( static_cast(aOffset.Height() * aMap.GetScaleY()) ); } else aOffset = OutputDevice::LogicToLogic( aBaseOffset, GetPrefMapMode(), aMapVDev->GetMapMode() ); diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx index 310a2eb7a880..966e8d8bedfd 100644 --- a/vcl/source/gdi/graph.cxx +++ b/vcl/source/gdi/graph.cxx @@ -395,7 +395,7 @@ basegfx::B2DSize Graphic::GetPPI() const { return GetPPUnit(MapMode(MapUnit::Map basegfx::B2DSize Graphic::GetPPM() const { - return GetPPUnit(MapMode(MapUnit::MapMM, {}, { 1000, 1 }, { 1000, 1 })); + return GetPPUnit(MapMode(MapUnit::MapMM, {}, 1000.0, 1000.0)); } Size Graphic::GetSizePixel( const OutputDevice* pRefDevice ) const diff --git a/vcl/source/gdi/mapmod.cxx b/vcl/source/gdi/mapmod.cxx index eca8abd61baf..e277e6d6b54e 100644 --- a/vcl/source/gdi/mapmod.cxx +++ b/vcl/source/gdi/mapmod.cxx @@ -36,8 +36,8 @@ struct MapMode::ImplMapMode // because ReadFraction / WriteFraction do only 32 bits, so more than // that cannot be stored in MetaFiles! // => call ReduceInaccurate whenever setting these - Fraction maScaleX; - Fraction maScaleY; + double mfScaleX; + double mfScaleY; ImplMapMode(); ImplMapMode(MapUnit eMapUnit); @@ -48,8 +48,8 @@ struct MapMode::ImplMapMode MapMode::ImplMapMode::ImplMapMode() : maOrigin( 0, 0 ), - maScaleX( 1, 1 ), - maScaleY( 1, 1 ) + mfScaleX( 1.0 ), + mfScaleY( 1.0 ) { meUnit = MapUnit::MapPixel; mbSimple = true; @@ -57,8 +57,8 @@ MapMode::ImplMapMode::ImplMapMode() : MapMode::ImplMapMode::ImplMapMode(MapUnit eMapUnit) : maOrigin( 0, 0 ), - maScaleX( 1, 1 ), - maScaleY( 1, 1 ) + mfScaleX( 1.0 ), + mfScaleY( 1.0 ) { meUnit = eMapUnit; mbSimple = true; @@ -70,8 +70,8 @@ bool MapMode::ImplMapMode::operator==( const ImplMapMode& rImpMapMode ) const { return meUnit == rImpMapMode.meUnit && maOrigin == rImpMapMode.maOrigin - && maScaleX == rImpMapMode.maScaleX - && maScaleY == rImpMapMode.maScaleY; + && mfScaleX == rImpMapMode.mfScaleX + && mfScaleY == rImpMapMode.mfScaleY; } namespace @@ -120,22 +120,12 @@ MapMode::MapMode( MapUnit eUnit ) : mpImplMapMode(GetUnitDefault(eUnit)) } MapMode::MapMode( MapUnit eUnit, const Point& rLogicOrg, - const Fraction& rScaleX, const Fraction& rScaleY ) + double fScaleX, double fScaleY ) { mpImplMapMode->meUnit = eUnit; mpImplMapMode->maOrigin = rLogicOrg; - mpImplMapMode->maScaleX = rScaleX; - mpImplMapMode->maScaleY = rScaleY; - mpImplMapMode->mbSimple = false; -} - -MapMode::MapMode( MapUnit eUnit, const Point& rLogicOrg, - double rScaleX, double rScaleY ) -{ - mpImplMapMode->meUnit = eUnit; - mpImplMapMode->maOrigin = rLogicOrg; - mpImplMapMode->maScaleX = rScaleX; - mpImplMapMode->maScaleY = rScaleY; + mpImplMapMode->mfScaleX = fScaleX; + mpImplMapMode->mfScaleY = fScaleY; mpImplMapMode->mbSimple = false; } @@ -152,27 +142,15 @@ void MapMode::SetOrigin( const Point& rLogicOrg ) mpImplMapMode->mbSimple = false; } -void MapMode::SetScaleX( const Fraction& rScaleX ) +void MapMode::SetScaleX( double fScaleX ) { - mpImplMapMode->maScaleX = rScaleX; + mpImplMapMode->mfScaleX = fScaleX; mpImplMapMode->mbSimple = false; } -void MapMode::SetScaleX( double rScaleX ) +void MapMode::SetScaleY( double fScaleY ) { - mpImplMapMode->maScaleX = rScaleX; - mpImplMapMode->mbSimple = false; -} - -void MapMode::SetScaleY( const Fraction& rScaleY ) -{ - mpImplMapMode->maScaleY = rScaleY; - mpImplMapMode->mbSimple = false; -} - -void MapMode::SetScaleY( double rScaleY ) -{ - mpImplMapMode->maScaleY = rScaleY; + mpImplMapMode->mfScaleY = fScaleY; mpImplMapMode->mbSimple = false; } @@ -195,8 +173,8 @@ size_t MapMode::GetHashValue() const size_t hash = 0; o3tl::hash_combine( hash, mpImplMapMode->meUnit ); o3tl::hash_combine( hash, mpImplMapMode->maOrigin.GetHashValue()); - o3tl::hash_combine( hash, mpImplMapMode->maScaleX.GetHashValue()); - o3tl::hash_combine( hash, mpImplMapMode->maScaleY.GetHashValue()); + o3tl::hash_combine( hash, mpImplMapMode->mfScaleX); + o3tl::hash_combine( hash, mpImplMapMode->mfScaleY); o3tl::hash_combine( hash, mpImplMapMode->mbSimple ); return hash; } @@ -205,9 +183,9 @@ MapUnit MapMode::GetMapUnit() const { return mpImplMapMode->meUnit; } const Point& MapMode::GetOrigin() const { return mpImplMapMode->maOrigin; } -const Fraction& MapMode::GetScaleX() const { return mpImplMapMode->maScaleX; } +double MapMode::GetScaleX() const { return mpImplMapMode->mfScaleX; } -const Fraction& MapMode::GetScaleY() const { return mpImplMapMode->maScaleY; } +double MapMode::GetScaleY() const { return mpImplMapMode->mfScaleY; } bool MapMode::IsSimple() const { return mpImplMapMode->mbSimple; } diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx index 6dc825403e37..2807b36a70cb 100644 --- a/vcl/source/gdi/mtfxmldump.cxx +++ b/vcl/source/gdi/mtfxmldump.cxx @@ -377,11 +377,11 @@ OUString convertMapUnitToString(MapUnit eUnit) } } -OUString convertFractionToString(const Fraction& aFraction) +OUString convertFractionToString(double fFraction) { std::stringstream ss; - ss << aFraction; + ss << Fraction(fFraction); return OUString::createFromAscii(ss.str()); } diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx index 4d188f1d5b69..2538527de570 100644 --- a/vcl/source/outdev/map.cxx +++ b/vcl/source/outdev/map.cxx @@ -108,8 +108,8 @@ static void ImplCalcMapResolution( const MapMode& rMapMode, break; } - const Fraction& aScaleX = rMapMode.GetScaleX(); - const Fraction& aScaleY = rMapMode.GetScaleY(); + double fScaleX = rMapMode.GetScaleX(); + double fScaleY = rMapMode.GetScaleY(); // set offset according to MapMode Point aOrigin = rMapMode.GetOrigin(); @@ -120,39 +120,20 @@ static void ImplCalcMapResolution( const MapMode& rMapMode, } else { - auto funcCalcOffset = [](const Fraction& rScale, tools::Long& rnMapOffset, tools::Long nOrigin) + auto funcCalcOffset = [](double fScale, tools::Long& rnMapOffset, tools::Long nOrigin) { - auto nNumerator = rScale.GetNumerator(); - assert(nNumerator != 0); - - BigInt aX( rnMapOffset ); - aX *= BigInt( rScale.GetDenominator() ); - if ( rnMapOffset >= 0 ) - { - if (nNumerator >= 0) - aX += BigInt(nNumerator / 2); - else - aX -= BigInt((nNumerator + 1) / 2); - } - else - { - if (nNumerator >= 0 ) - aX -= BigInt((nNumerator - 1) / 2); - else - aX += BigInt(nNumerator / 2); - } - aX /= BigInt(nNumerator); - rnMapOffset = static_cast(aX) + nOrigin; + assert(fScale != 0); + rnMapOffset = std::llround(double( rnMapOffset ) / fScale) + nOrigin; }; - funcCalcOffset(aScaleX, rMapRes.mnMapOfsX, aOrigin.X()); - funcCalcOffset(aScaleY, rMapRes.mnMapOfsY, aOrigin.Y()); + funcCalcOffset(fScaleX, rMapRes.mnMapOfsX, aOrigin.X()); + funcCalcOffset(fScaleY, rMapRes.mnMapOfsY, aOrigin.Y()); } // calculate scaling factor according to MapMode // aTemp? = rMapRes.mnMapSc? * aScale? - rMapRes.mfMapScX = double(aScaleX) * rMapRes.mfMapScX; - rMapRes.mfMapScY = double(aScaleY) * rMapRes.mfMapScY; + rMapRes.mfMapScX = fScaleX * rMapRes.mfMapScX; + rMapRes.mfMapScY = fScaleY * rMapRes.mfMapScY; } // #i75163# @@ -639,13 +620,9 @@ void OutputDevice::SetMapMode( const MapMode& rNewMapMode ) // set new MapMode if (bRelMap) { - maMapMode.SetScaleX(Fraction::MakeFraction( - maMapMode.GetScaleX().GetNumerator(), rNewMapMode.GetScaleX().GetNumerator(), - maMapMode.GetScaleX().GetDenominator(), rNewMapMode.GetScaleX().GetDenominator())); + maMapMode.SetScaleX(maMapMode.GetScaleX() * rNewMapMode.GetScaleX()); - maMapMode.SetScaleY(Fraction::MakeFraction( - maMapMode.GetScaleY().GetNumerator(), rNewMapMode.GetScaleY().GetNumerator(), - maMapMode.GetScaleY().GetDenominator(), rNewMapMode.GetScaleY().GetDenominator())); + maMapMode.SetScaleY(maMapMode.GetScaleY() * rNewMapMode.GetScaleY()); maMapMode.SetOrigin(Point(maMapRes.mnMapOfsX, maMapRes.mnMapOfsY)); } @@ -689,14 +666,8 @@ void OutputDevice::SetRelativeMapMode( const MapMode& rNewMapMode ) MapUnit eNew = rNewMapMode.GetMapUnit(); // a?F = rNewMapMode.GetScale?() / maMapMode.GetScale?() - Fraction aXF = Fraction::MakeFraction( rNewMapMode.GetScaleX().GetNumerator(), - maMapMode.GetScaleX().GetDenominator(), - rNewMapMode.GetScaleX().GetDenominator(), - maMapMode.GetScaleX().GetNumerator() ); - Fraction aYF = Fraction::MakeFraction( rNewMapMode.GetScaleY().GetNumerator(), - maMapMode.GetScaleY().GetDenominator(), - rNewMapMode.GetScaleY().GetDenominator(), - maMapMode.GetScaleY().GetNumerator() ); + double fXF = rNewMapMode.GetScaleX() / maMapMode.GetScaleX(); + double fYF = rNewMapMode.GetScaleY() / maMapMode.GetScaleY(); Point aPt( LogicToLogic( Point(), nullptr, &rNewMapMode ) ); if ( eNew != eOld ) @@ -714,27 +685,25 @@ void OutputDevice::SetRelativeMapMode( const MapMode& rNewMapMode ) const auto eFrom = MapToO3tlLength(eOld, o3tl::Length::in); const auto eTo = MapToO3tlLength(eNew, o3tl::Length::in); const auto [mul, div] = o3tl::getConversionMulDiv(eFrom, eTo); - Fraction aF(div, mul); + double aF = double(div) / mul; // a?F = a?F * aF - aXF = Fraction::MakeFraction( aXF.GetNumerator(), aF.GetNumerator(), - aXF.GetDenominator(), aF.GetDenominator() ); - aYF = Fraction::MakeFraction( aYF.GetNumerator(), aF.GetNumerator(), - aYF.GetDenominator(), aF.GetDenominator() ); + fXF = fXF * aF; + fYF = fYF * aF; if ( eOld == MapUnit::MapPixel ) { - aXF *= Fraction( mnDPIX, 1 ); - aYF *= Fraction( mnDPIY, 1 ); + fXF *= mnDPIX; + fYF *= mnDPIY; } else if ( eNew == MapUnit::MapPixel ) { - aXF *= Fraction( 1, mnDPIX ); - aYF *= Fraction( 1, mnDPIY ); + fXF /= mnDPIX; + fYF /= mnDPIY; } } } - MapMode aNewMapMode( MapUnit::MapRelative, Point( -aPt.X(), -aPt.Y() ), aXF, aYF ); + MapMode aNewMapMode( MapUnit::MapRelative, Point( -aPt.X(), -aPt.Y() ), fXF, fYF ); SetMapMode( aNewMapMode ); if ( eNew != eOld ) diff --git a/vcl/source/pdf/pdfwriter_impl.cxx b/vcl/source/pdf/pdfwriter_impl.cxx index f59604f976fd..a1688dcace6e 100644 --- a/vcl/source/pdf/pdfwriter_impl.cxx +++ b/vcl/source/pdf/pdfwriter_impl.cxx @@ -603,7 +603,7 @@ void PDFWriterImpl::newPage( double nPageWidth, double nPageHeight, PDFWriter::O m_nCurrentPage = m_aPages.size(); m_aPages.emplace_back(this, nPageWidth, nPageHeight, eOrientation ); - const Fraction frac(m_aPages.back().m_nUserUnit, pointToPixel(1)); + const double frac = double(m_aPages.back().m_nUserUnit) / pointToPixel(1); m_aMapMode = MapMode(MapUnit::MapPoint, Point(), frac, frac); m_aPages.back().beginStream(); @@ -5891,7 +5891,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 *= m_aCurrentPDFState.m_aMapMode.GetScaleX() / m_aCurrentPDFState.m_aMapMode.GetScaleY(); } Degree10 nAngle = m_aCurrentPDFState.m_aFont.GetOrientation();