vcl: introduce parameterized ImplMapRes constructor
This commit introduces a parameterized constructor for ImplMapRes to streamline map resolution initialization across VCL mapping functions. Previously, instantiating a local ImplMapRes required an error-prone, two-step process: default construction followed by a call to the CalcMapResolution mutator. The new constructor elegantly bridges this by delegating the complex scaling math to CalcMapResolution() while explicitly handling the absolute origin offsets (mnMapOfs) required for a fresh resolution state. Key changes: - Added ImplMapRes(MapMode, nDPIX, nDPIY) constructor. - Refactored CoordinateMapper and OutputDevice mapping functions (LogicToPixel, PixelToLogic) to use the new single-line RAII-style initialization, eliminating repetitive two-step setup code. Change-Id: I68072cd66d01fd1663b58330890fe90a7bb8f94c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/203677 Tested-by: Jenkins Reviewed-by: Dan Williams <dcbw@libreoffice.org>
This commit is contained in:
committed by
Dan Williams
parent
1e3ace6710
commit
2a021a9e60
@@ -27,6 +27,8 @@ class MapMode;
|
||||
struct ImplMapRes
|
||||
{
|
||||
ImplMapRes() = default;
|
||||
ImplMapRes(const MapMode& rMapMode, tools::Long nDPIX, tools::Long nDPIY);
|
||||
|
||||
void SetMapRes(const o3tl::Length eUnit);
|
||||
void CalcMapResolution(const MapMode& rMapMode, tools::Long nDPIX, tools::Long nDPIY);
|
||||
ImplMapRes ResolveMapRes(const MapMode* pMode, const MapMode& rDefaultMapMode, bool bMap,
|
||||
|
||||
@@ -153,8 +153,7 @@ basegfx::B2DHomMatrix CoordinateMapper::GetInverseViewTransformation() const
|
||||
basegfx::B2DHomMatrix CoordinateMapper::GetViewTransformation(const MapMode& rMapMode) const
|
||||
{
|
||||
// #i82615#
|
||||
ImplMapRes aMapRes;
|
||||
aMapRes.CalcMapResolution(rMapMode, GetDPIX(), GetDPIY());
|
||||
ImplMapRes aMapRes(rMapMode, GetDPIX(), GetDPIY());
|
||||
|
||||
basegfx::B2DHomMatrix aTransform;
|
||||
|
||||
|
||||
@@ -29,6 +29,16 @@
|
||||
|
||||
#include <svdata.hxx>
|
||||
|
||||
ImplMapRes::ImplMapRes(const MapMode& rMapMode, tools::Long nDPIX, tools::Long nDPIY)
|
||||
{
|
||||
// Delegate the complex scaling math to the mutator
|
||||
CalcMapResolution(rMapMode, nDPIX, nDPIY);
|
||||
|
||||
// Because this is a fresh object, the origin is always absolute
|
||||
mnMapOfsX = rMapMode.GetOrigin().X();
|
||||
mnMapOfsY = rMapMode.GetOrigin().Y();
|
||||
}
|
||||
|
||||
void ImplMapRes::SetMapRes(const o3tl::Length eUnit)
|
||||
{
|
||||
const auto[nNum, nDen] = o3tl::getConversionMulDiv(eUnit, o3tl::Length::in);
|
||||
|
||||
@@ -593,8 +593,7 @@ Point OutputDevice::LogicToPixel( const Point& rLogicPt,
|
||||
return rLogicPt;
|
||||
|
||||
// convert MapMode resolution and convert
|
||||
ImplMapRes aMapRes;
|
||||
aMapRes.CalcMapResolution(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
ImplMapRes aMapRes(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
|
||||
return Point(
|
||||
mpMapper->ViewToWindowUnitsX(mpMapper->LogicUnitsToViewUnitsX(rLogicPt.X(), aMapRes)),
|
||||
@@ -610,8 +609,7 @@ Size OutputDevice::LogicToPixel( const Size& rLogicSize,
|
||||
return rLogicSize;
|
||||
|
||||
// convert MapMode resolution and convert
|
||||
ImplMapRes aMapRes;
|
||||
aMapRes.CalcMapResolution(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
ImplMapRes aMapRes(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
|
||||
return Size(mpMapper->LogicToViewDistanceX(rLogicSize.Width(), aMapRes.mfMapScX),
|
||||
mpMapper->LogicToViewDistanceY(rLogicSize.Height(), aMapRes.mfMapScY));
|
||||
@@ -625,8 +623,7 @@ tools::Rectangle OutputDevice::LogicToPixel( const tools::Rectangle& rLogicRect,
|
||||
return rLogicRect;
|
||||
|
||||
// convert MapMode resolution
|
||||
ImplMapRes aMapRes;
|
||||
aMapRes.CalcMapResolution(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
ImplMapRes aMapRes(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
|
||||
tools::Rectangle aRetval(
|
||||
mpMapper->LogicToWindowUnitsX(rLogicRect.Left(), aMapRes),
|
||||
@@ -650,8 +647,7 @@ tools::Polygon OutputDevice::LogicToPixel( const tools::Polygon& rLogicPoly,
|
||||
if ( rMapMode.IsDefault() )
|
||||
return rLogicPoly;
|
||||
|
||||
ImplMapRes aMapRes;
|
||||
aMapRes.CalcMapResolution(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
ImplMapRes aMapRes(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
|
||||
const sal_uInt16 nPoints = rLogicPoly.GetSize();
|
||||
tools::Polygon aPoly( rLogicPoly );
|
||||
@@ -825,8 +821,7 @@ Point OutputDevice::PixelToLogic( const Point& rDevicePt,
|
||||
return rDevicePt;
|
||||
|
||||
// calculate MapMode-resolution
|
||||
ImplMapRes aMapRes;
|
||||
aMapRes.CalcMapResolution(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
ImplMapRes aMapRes(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
|
||||
return Point(
|
||||
mpMapper->ViewSubPixelToLogicIntX(rDevicePt.X(), aMapRes),
|
||||
@@ -843,8 +838,7 @@ Size OutputDevice::PixelToLogic( const Size& rDeviceSize,
|
||||
return rDeviceSize;
|
||||
|
||||
// calculate MapMode-resolution and convert
|
||||
ImplMapRes aMapRes;
|
||||
aMapRes.CalcMapResolution(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
ImplMapRes aMapRes(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
|
||||
return Size(mpMapper->ViewToLogicDistanceX(rDeviceSize.Width(), aMapRes.mfMapScX),
|
||||
mpMapper->ViewToLogicDistanceY(rDeviceSize.Height(), aMapRes.mfMapScY));
|
||||
@@ -859,8 +853,7 @@ tools::Rectangle OutputDevice::PixelToLogic( const tools::Rectangle& rDeviceRect
|
||||
return rDeviceRect;
|
||||
|
||||
// calculate MapMode-resolution
|
||||
ImplMapRes aMapRes;
|
||||
aMapRes.CalcMapResolution(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
ImplMapRes aMapRes(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
|
||||
tools::Rectangle aRetval(
|
||||
mpMapper->ViewSubPixelToLogicIntX(rDeviceRect.Left(), aMapRes),
|
||||
@@ -886,8 +879,7 @@ tools::Polygon OutputDevice::PixelToLogic( const tools::Polygon& rDevicePoly,
|
||||
return rDevicePoly;
|
||||
|
||||
// calculate MapMode-resolution
|
||||
ImplMapRes aMapRes;
|
||||
aMapRes.CalcMapResolution(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
ImplMapRes aMapRes(rMapMode, mpMapper->GetDPIX(), mpMapper->GetDPIY());
|
||||
|
||||
const sal_uInt16 nPoints = rDevicePoly.GetSize();
|
||||
tools::Polygon aPoly( rDevicePoly );
|
||||
|
||||
Reference in New Issue
Block a user