diff options
-rw-r--r-- | include/vbahelper/vbahelper.hxx | 3 | ||||
-rw-r--r-- | sc/source/ui/vba/vbasheetobject.cxx | 10 | ||||
-rw-r--r-- | sc/source/ui/vba/vbasheetobjects.cxx | 10 | ||||
-rw-r--r-- | vbahelper/source/vbahelper/vbahelper.cxx | 26 |
4 files changed, 23 insertions, 26 deletions
diff --git a/include/vbahelper/vbahelper.hxx b/include/vbahelper/vbahelper.hxx index 07c5fce6ec6b..01366d9ad771 100644 --- a/include/vbahelper/vbahelper.hxx +++ b/include/vbahelper/vbahelper.hxx @@ -121,11 +121,8 @@ namespace ooo::vba /// @throws css::uno::RuntimeException VBAHELPER_DLLPUBLIC OUString getAnyAsString( const css::uno::Any& pvargItem ); VBAHELPER_DLLPUBLIC OUString VBAToRegexp(const OUString &rIn); // needs to be in a uno service ( already this code is duplicated in basic ) - VBAHELPER_DLLPUBLIC double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, bool bVertical); VBAHELPER_DLLPUBLIC double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, bool bVertical); VBAHELPER_DLLPUBLIC double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, bool bVertical); - VBAHELPER_DLLPUBLIC sal_Int32 PointsToHmm( double fPoints ); - VBAHELPER_DLLPUBLIC double HmmToPoints( sal_Int32 nHmm ); VBAHELPER_DLLPUBLIC PointerStyle getPointerStyle( const css::uno::Reference< css::frame::XModel >& ); VBAHELPER_DLLPUBLIC void setCursorHelper( const css::uno::Reference< css::frame::XModel >& xModel, PointerStyle nPointer, bool bOverWrite ); /// @throws css::uno::RuntimeException diff --git a/sc/source/ui/vba/vbasheetobject.cxx b/sc/source/ui/vba/vbasheetobject.cxx index 52513095fac4..ff37ab8addfb 100644 --- a/sc/source/ui/vba/vbasheetobject.cxx +++ b/sc/source/ui/vba/vbasheetobject.cxx @@ -27,6 +27,7 @@ #include <com/sun/star/script/XEventAttacherManager.hpp> #include <com/sun/star/style/VerticalAlignment.hpp> #include <comphelper/documentinfo.hxx> +#include <o3tl/unit_conversion.hxx> #include <ooo/vba/excel/Constants.hpp> #include <ooo/vba/excel/XlOrientation.hpp> #include <ooo/vba/excel/XlPlacement.hpp> @@ -39,6 +40,15 @@ using namespace ::ooo::vba; constexpr OUStringLiteral gaListenerType = u"XActionListener"; constexpr OUStringLiteral gaEventMethod = u"actionPerformed"; +static double HmmToPoints(double nHmm) +{ + return o3tl::convert(nHmm, o3tl::Length::mm100, o3tl::Length::pt); +} + +static sal_Int32 PointsToHmm(double fPoints) +{ + return std::round(o3tl::convert(fPoints, o3tl::Length::pt, o3tl::Length::mm100)); +} ScVbaButtonCharacters::ScVbaButtonCharacters( const uno::Reference< XHelperInterface >& rxParent, diff --git a/sc/source/ui/vba/vbasheetobjects.cxx b/sc/source/ui/vba/vbasheetobjects.cxx index 32e025a3ca7e..a6a9a1233b8e 100644 --- a/sc/source/ui/vba/vbasheetobjects.cxx +++ b/sc/source/ui/vba/vbasheetobjects.cxx @@ -19,6 +19,7 @@ #include "vbasheetobjects.hxx" #include <vector> +#include <o3tl/unit_conversion.hxx> #include <rtl/math.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/container/XIndexContainer.hpp> @@ -58,9 +59,10 @@ bool lclGetProperty( Type& orValue, const uno::Reference< beans::XPropertySet >& @throws uno::RuntimeException */ -double lclPointsToHmm( const uno::Any& rPoints ) +sal_Int32 lclPointsToHmm( const uno::Any& rPoints ) { - return PointsToHmm( ::rtl::math::approxFloor( rPoints.get< double >() / 0.75 ) * 0.75 ); + return std::round(o3tl::convert(::rtl::math::approxFloor(rPoints.get<double>() / 0.75) * 0.75, + o3tl::Length::pt, o3tl::Length::mm100)); } } // namespace @@ -349,8 +351,8 @@ uno::Any SAL_CALL ScVbaGraphicObjectsBase::Add( const uno::Any& rLeft, const uno /* Extract double values from passed Anys (the lclPointsToHmm() helper function will throw a RuntimeException on any error), and convert from points to 1/100 mm. */ - awt::Point aPos( static_cast<sal_Int32>(lclPointsToHmm( rLeft )), static_cast<sal_Int32>(lclPointsToHmm( rTop )) ); - awt::Size aSize( static_cast<sal_Int32>(lclPointsToHmm( rWidth )), static_cast<sal_Int32>(lclPointsToHmm( rHeight )) ); + awt::Point aPos( lclPointsToHmm( rLeft ), lclPointsToHmm( rTop ) ); + awt::Size aSize( lclPointsToHmm( rWidth ), lclPointsToHmm( rHeight ) ); // TODO: translate coordinates for RTL sheets if( (aPos.X < 0) || (aPos.Y < 0) || (aSize.Width <= 0) || (aSize.Height <= 0) ) throw uno::RuntimeException(); diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx index a6e7ac1da2aa..be4098ce6ae9 100644 --- a/vbahelper/source/vbahelper/vbahelper.cxx +++ b/vbahelper/source/vbahelper/vbahelper.cxx @@ -62,6 +62,7 @@ #include <basic/sbmod.hxx> #include <basic/sbuno.hxx> #include <basic/sberrors.hxx> +#include <o3tl/unit_conversion.hxx> #include <rtl/ustrbuf.hxx> #include <sfx2/viewsh.hxx> #include <sal/log.hxx> @@ -607,35 +608,22 @@ OUString VBAToRegexp(const OUString &rIn) return sResult.makeStringAndClear( ); } -double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, bool bVertical) +static double getPixelToMeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, bool bVertical) { - double fConvertFactor = 1.0; - if( bVertical ) - { - fConvertFactor = xDevice->getInfo().PixelPerMeterY/100000; - } - else - { - fConvertFactor = xDevice->getInfo().PixelPerMeterX/100000; - } - return fConvertFactor; + return bVertical ? xDevice->getInfo().PixelPerMeterY : xDevice->getInfo().PixelPerMeterX; } double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, bool bVertical) { - double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical ); - return convertPointToMm100(fPoints) * fConvertFactor; + double fConvertFactor = getPixelToMeterConversionFactor( xDevice, bVertical ); + return o3tl::convert(fPoints, o3tl::Length::pt, o3tl::Length::m) * fConvertFactor; } double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, bool bVertical) { - double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical ); - return convertMm100ToPoint(fPixels / fConvertFactor); + double fConvertFactor = getPixelToMeterConversionFactor( xDevice, bVertical ); + return o3tl::convert(fPixels / fConvertFactor, o3tl::Length::m, o3tl::Length::pt); } -sal_Int32 PointsToHmm(double fPoints) { return std::round(convertPointToMm100(fPoints)); } - -double HmmToPoints(sal_Int32 nHmm) { return convertMm100ToPoint<double>(nHmm); } - ConcreteXShapeGeometryAttributes::ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::drawing::XShape >& xShape ) { m_pShapeHelper.reset( new ShapeHelper( xShape ) ); |