From 08874223db78571f75640aa2a4afc6d6cdd83d0f Mon Sep 17 00:00:00 2001 From: Christopher Sherlock Date: Tue, 14 Apr 2026 23:06:57 +1000 Subject: [PATCH] vcl: refactor Polygon PixelToLogic() with MapMode to use wrappers This commit refactors OutputDevice::PixelToLogic(Polygon, MapMode) to use the ViewSubPixelToLogicIntX/Y() overloads that accept custom mapping resolutions (ImplMapRes). Key changes: - Replaced manual coordinate scaling and sequential subtraction of mapping and logical offsets with encapsulated master wrappers. - Preserved the "Round-then-Shift" order of operations to ensure polygon vertices maintain legacy rounding symmetry and pass unit tests. - Modernized the loop by removing legacy pointer-based array access in favor of direct index assignment and Point construction. - Further reduced the footprint of coordinate mathematics within map.cxx. Change-Id: Ided023472c28d9bdd2e0c35c5f00705b58435bff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/203676 Tested-by: Jenkins Reviewed-by: Dan Williams --- vcl/source/outdev/map.cxx | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx index d79dbed3efbd..27427b756e10 100644 --- a/vcl/source/outdev/map.cxx +++ b/vcl/source/outdev/map.cxx @@ -881,28 +881,23 @@ tools::Rectangle OutputDevice::PixelToLogic( const tools::Rectangle& rDeviceRect tools::Polygon OutputDevice::PixelToLogic( const tools::Polygon& rDevicePoly, const MapMode& rMapMode ) const { - // calculate nothing if default-MapMode if ( rMapMode.IsDefault() ) return rDevicePoly; - // calculate MapMode-resolution and convert - ImplMapRes aMapRes; + // calculate MapMode-resolution + ImplMapRes aMapRes; aMapRes.CalcMapResolution(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY()); const sal_uInt16 nPoints = rDevicePoly.GetSize(); tools::Polygon aPoly( rDevicePoly ); - // get pointer to Point-array (copy data) - const Point* pPointAry = aPoly.GetConstPointAry(); - - for (sal_uInt16 i = 0; i < nPoints; i++) + for (sal_uInt16 i = 0; i < nPoints; ++i) { - const Point* pPt = &(pPointAry[i]); - Point aPt; - aPt.setX(mpMapper->ViewToLogicDistanceX(pPt->X(), aMapRes.mfMapScX) - aMapRes.mnMapOfsX - mpMapper->GetLogicalXOffset()); - aPt.setY(mpMapper->ViewToLogicDistanceY(pPt->Y(), aMapRes.mfMapScY) - aMapRes.mnMapOfsY - mpMapper->GetLogicalYOffset()); - aPoly[i] = aPt; + aPoly[i] = Point( + mpMapper->ViewSubPixelToLogicIntX(aPoly[i].X(), aMapRes), + mpMapper->ViewSubPixelToLogicIntY(aPoly[i].Y(), aMapRes) + ); } return aPoly;