summaryrefslogtreecommitdiff
path: root/vcl/source
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2023-07-26 18:24:02 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-07-27 10:21:38 +0200
commitece0132a574beb5e56cf7470a10c209c2a3df412 (patch)
tree58a82ae108c01dd808ce94b9544c4c46b4ac64a0 /vcl/source
parent175c01e4307ba04883e531fd7899d35f160c2d6b (diff)
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.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/source')
-rw-r--r--vcl/source/outdev/map.cxx63
1 files changed, 25 insertions, 38 deletions
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