From 8e21a02520cbd2fdc09df1ca675f4aa46a02d5f6 Mon Sep 17 00:00:00 2001 From: Norbert Thiebaud Date: Fri, 18 Jul 2014 08:45:32 +0200 Subject: vcl: add floating equivalent for MapRes Change-Id: I165e403d2834d341f7da7a280859afccb995a3bb --- include/vcl/outdev.hxx | 3 +++ include/vcl/outdevmap.hxx | 5 ++++- vcl/source/outdev/map.cxx | 52 +++++++++++++++++++++++++++++++++++++++++++- vcl/source/outdev/outdev.cxx | 4 ++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx index d59067a43177..66559c26ae11 100644 --- a/include/vcl/outdev.hxx +++ b/include/vcl/outdev.hxx @@ -1728,6 +1728,9 @@ public: */ SAL_DLLPRIVATE long ImplLogicWidthToDevicePixel( long nWidth ) const; + SAL_DLLPRIVATE DeviceCoordinate LogicWidthToDeviceCoordinate( long nWidth ) const; + SAL_DLLPRIVATE DeviceCoordinate LogicHeightToDeviceCoordinate( long nHeight ) const; + private: /** Convert a logical X coordinate to a device pixel's X coordinate. diff --git a/include/vcl/outdevmap.hxx b/include/vcl/outdevmap.hxx index d35c02b9c8ea..05f43c065c1e 100644 --- a/include/vcl/outdevmap.hxx +++ b/include/vcl/outdevmap.hxx @@ -20,7 +20,6 @@ #ifndef INCLUDED_VCL_OUTDEVMAP_HXX #define INCLUDED_VCL_OUTDEVMAP_HXX - struct ImplMapRes { long mnMapOfsX; // Offset in X direction @@ -29,6 +28,10 @@ struct ImplMapRes long mnMapScNumY; // Scaling factor - numerator in Y direction long mnMapScDenomX; // Scaling factor - denominator in X direction long mnMapScDenomY; // Scaling factor - denominator in Y direction + double mfOffsetX; + double mfOffsetY; + double mfScaleX; + double mfScaleY; }; struct ImplThresholdRes diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx index beb9424809da..eb82156c8e4f 100644 --- a/vcl/source/outdev/map.cxx +++ b/vcl/source/outdev/map.cxx @@ -149,6 +149,8 @@ static void ImplCalcBigIntThreshold( long nDPIX, long nDPIY, static void ImplCalcMapResolution( const MapMode& rMapMode, long nDPIX, long nDPIY, ImplMapRes& rMapRes ) { + rMapRes.mfScaleX = 1.0; + rMapRes.mfScaleY = 1.0; switch ( rMapMode.GetMapUnit() ) { case MAP_RELATIVE: @@ -254,9 +256,18 @@ static void ImplCalcMapResolution( const MapMode& rMapMode, { rMapRes.mnMapOfsX = aOrigin.X(); rMapRes.mnMapOfsY = aOrigin.Y(); + rMapRes.mfOffsetX = aOrigin.X(); + rMapRes.mfOffsetY = aOrigin.Y(); } else { + rMapRes.mfOffsetX *= aScaleX.GetDenominator(); + rMapRes.mfOffsetX /= aScaleX.GetNumerator(); + rMapRes.mfOffsetX += aOrigin.X(); + rMapRes.mfOffsetY *= aScaleY.GetDenominator(); + rMapRes.mfOffsetY /= aScaleY.GetNumerator(); + rMapRes.mfOffsetY += aOrigin.Y(); + BigInt aX( rMapRes.mnMapOfsX ); aX *= BigInt( aScaleX.GetDenominator() ); if ( rMapRes.mnMapOfsX >= 0 ) @@ -295,6 +306,11 @@ static void ImplCalcMapResolution( const MapMode& rMapMode, rMapRes.mnMapOfsY = (long)aY + aOrigin.Y(); } + rMapRes.mfScaleX *= (double)rMapRes.mnMapScNumX * (double)aScaleX.GetNumerator() / + ((double)rMapRes.mnMapScDenomX * (double)aScaleX.GetDenominator()); + rMapRes.mfScaleY *= (double)rMapRes.mnMapScNumY * (double)aScaleY.GetNumerator() / + ((double)rMapRes.mnMapScDenomY * (double)aScaleY.GetDenominator()); + // calculate scaling factor according to MapMode // aTemp? = rMapRes.mnMapSc? * aScale? Fraction aTempX = ImplMakeFraction( rMapRes.mnMapScNumX, @@ -351,7 +367,6 @@ void OutputDevice::ImplInvalidateViewTransform() } } - static long ImplLogicToPixel( long n, long nDPI, long nMapNum, long nMapDenom, long nThres ) { @@ -719,6 +734,8 @@ void OutputDevice::SetMapMode( const MapMode& rNewMapMode ) Point aOrigin = rNewMapMode.GetOrigin(); maMapRes.mnMapOfsX = aOrigin.X(); maMapRes.mnMapOfsY = aOrigin.Y(); + maMapRes.mfOffsetX = aOrigin.X(); + maMapRes.mfOffsetY = aOrigin.Y(); maMapMode = rNewMapMode; // #i75163# @@ -734,6 +751,10 @@ void OutputDevice::SetMapMode( const MapMode& rNewMapMode ) maMapRes.mnMapScDenomY = mnDPIY; maMapRes.mnMapOfsX = 0; maMapRes.mnMapOfsY = 0; + maMapRes.mfOffsetX = 0.0; + maMapRes.mfOffsetY = 0.0; + maMapRes.mfScaleX = (double)1/(double)mnDPIX; + maMapRes.mfScaleY = (double)1/(double)mnDPIY; } // calculate new MapMode-resolution @@ -2112,4 +2133,33 @@ long Window::ImplLogicUnitToPixelY( long nY, MapUnit eUnit ) return nY; } + +DeviceCoordinate OutputDevice::LogicWidthToDeviceCoordinate( long nWidth ) const +{ +#if VCL_FLOAT_DEVICE_PIXEL + return (double)nWidth * maMapRes.mfScaleX * mnDPIX; +#else + if ( !mbMap ) + return nWidth; + + return ImplLogicToPixel( nWidth, mnDPIX, + maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX, + maThresRes.mnThresLogToPixX ); +#endif +} + +DeviceCoordinate OutputDevice::LogicHeightToDeviceCoordinate( long nHeight ) const +{ +#if VCL_FLOAT_DEVICE_PIXEL + return (double)nHeight * maMapRes.mfScaleY * mnDPIY; +#else + if ( !mbMap ) + return nHeight; + + return ImplLogicToPixel( nHeight, mnDPIY, + maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY, + maThresRes.mnThresLogToPixY ); +#endif +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx index aa2cbc930f36..8717246d495c 100644 --- a/vcl/source/outdev/outdev.cxx +++ b/vcl/source/outdev/outdev.cxx @@ -159,6 +159,10 @@ OutputDevice::OutputDevice() : maMapRes.mnMapScNumY = 1; maMapRes.mnMapScDenomX = 1; maMapRes.mnMapScDenomY = 1; + maMapRes.mfOffsetX = 0.0; + maMapRes.mfOffsetY = 0.0; + maMapRes.mfScaleX = 1.0; + maMapRes.mfScaleY = 1.0; // struct ImplThresholdRes maThresRes.mnThresLogToPixX = 0; maThresRes.mnThresLogToPixY = 0; -- cgit v1.2.3