vcl/source/outdev/map.cxx |   63 ++++++++++++++++++----------------------------
 1 file changed, 25 insertions(+), 38 deletions(-)

New commits:
commit ece0132a574beb5e56cf7470a10c209c2a3df412
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Wed Jul 26 18:24:02 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jul 27 10:21:38 2023 +0200

    deduplicate some code in ImplCalcMapResolution
    
    Change-Id: I792394079c0efbea0ea62f580fbad3bd2a66f93a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154945
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx
index 7181b52db6b5..23c68a238551 100644
--- a/vcl/source/outdev/map.cxx
+++ b/vcl/source/outdev/map.cxx
@@ -124,46 +124,33 @@ static void ImplCalcMapResolution( const MapMode& 
rMapMode,
     }
     else
     {
-        auto nXNumerator = aScaleX.GetNumerator();
-        auto nYNumerator = aScaleY.GetNumerator();
-        assert(nXNumerator != 0 && nYNumerator != 0);
-
-        BigInt aX( rMapRes.mnMapOfsX );
-        aX *= BigInt( aScaleX.GetDenominator() );
-        if ( rMapRes.mnMapOfsX >= 0 )
-        {
-            if (nXNumerator >= 0)
-                aX += BigInt(nXNumerator / 2);
-            else
-                aX -= BigInt((nXNumerator + 1) / 2);
-        }
-        else
+        auto funcCalcOffset = [](const Fraction& rScale, tools::Long& 
rnMapOffset, tools::Long nOrigin)
         {
-            if (nXNumerator >= 0 )
-                aX -= BigInt((nXNumerator - 1) / 2);
-            else
-                aX += BigInt(nXNumerator / 2);
-        }
-        aX /= BigInt(nXNumerator);
-        rMapRes.mnMapOfsX = static_cast<tools::Long>(aX) + aOrigin.X();
-        BigInt aY( rMapRes.mnMapOfsY );
-        aY *= BigInt( aScaleY.GetDenominator() );
-        if( rMapRes.mnMapOfsY >= 0 )
-        {
-            if (nYNumerator >= 0)
-                aY += BigInt(nYNumerator / 2);
-            else
-                aY -= BigInt((nYNumerator + 1) / 2);
-        }
-        else
-        {
-            if (nYNumerator >= 0)
-                aY -= BigInt((nYNumerator - 1) / 2);
+            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
-                aY += BigInt(nYNumerator / 2);
-        }
-        aY /= BigInt(nYNumerator);
-        rMapRes.mnMapOfsY = static_cast<tools::Long>(aY) + aOrigin.Y();
+            {
+                if (nNumerator >= 0 )
+                    aX -= BigInt((nNumerator - 1) / 2);
+                else
+                    aX += BigInt(nNumerator / 2);
+            }
+            aX /= BigInt(nNumerator);
+            rnMapOffset = static_cast<tools::Long>(aX) + nOrigin;
+        };
+
+        funcCalcOffset(aScaleX, rMapRes.mnMapOfsX, aOrigin.X());
+        funcCalcOffset(aScaleY, rMapRes.mnMapOfsY, aOrigin.Y());
     }
 
     // calculate scaling factor according to MapMode

Reply via email to