summaryrefslogtreecommitdiff
path: root/vbahelper
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-02-05 19:35:14 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-02-06 17:05:44 +0100
commit956c09ca7d690471f62e8e2e14ad04fefcebf7e7 (patch)
treec681ace388370acf5842c73d45e9e9d8880777af /vbahelper
parentca074a47e8fdae396633dad6f59450508bb2c9f0 (diff)
Use more conversion functions from <tools/UnitConversion.hxx>
This unifies conversion functions to provide both floating-point and integral overloads, with correct rounding for the latter. Also sanitizing code it templatized to allow reuse if needed. Change-Id: Ibe1c9fe4d5baa226c600445779dbaf7dc41a02cb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110487 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vbahelper')
-rw-r--r--vbahelper/source/vbahelper/vbahelper.cxx23
1 files changed, 8 insertions, 15 deletions
diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx
index 7859c84018c2..17fc5ce651f0 100644
--- a/vbahelper/source/vbahelper/vbahelper.cxx
+++ b/vbahelper/source/vbahelper/vbahelper.cxx
@@ -69,6 +69,7 @@
#include <vcl/window.hxx>
#include <vcl/syswin.hxx>
#include <tools/diagnose_ex.h>
+#include <tools/UnitConversion.hxx>
#include <vbahelper/vbahelper.hxx>
using namespace ::com::sun::star;
@@ -78,8 +79,6 @@ using namespace ::ooo::vba;
namespace ooo::vba
{
-namespace { const double factor = 2540.0 / 72.0; }
-
// helper method to determine if the view ( calc ) is in print-preview mode
static bool isInPrintPreview( SfxViewFrame* pView )
{
@@ -624,23 +623,17 @@ double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css
double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, bool bVertical)
{
double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical );
- return PointsToHmm( fPoints ) * fConvertFactor;
+ return convertPointToMm100(fPoints) * fConvertFactor;
}
double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, bool bVertical)
{
double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical );
- return HmmToPoints(static_cast<sal_Int32>(fPixels/fConvertFactor));
+ return convertMm100ToPoint(fPixels / fConvertFactor);
}
-sal_Int32 PointsToHmm( double fPoints )
-{
- return static_cast<sal_Int32>( fPoints * factor + 0.5 );
-}
+sal_Int32 PointsToHmm(double fPoints) { return std::round(convertPointToMm100(fPoints)); }
-double HmmToPoints( sal_Int32 nHmm )
-{
- return nHmm / factor;
-}
+double HmmToPoints(sal_Int32 nHmm) { return convertMm100ToPoint<double>(nHmm); }
ConcreteXShapeGeometryAttributes::ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::drawing::XShape >& xShape )
{
@@ -1047,7 +1040,7 @@ Millimeter::Millimeter(double mm):m_nMillimeter(mm) {}
void Millimeter::setInPoints(double points)
{
- m_nMillimeter = points * factor / 100.0;
+ m_nMillimeter = convertPointToMm100(points) / 100.0;
}
double Millimeter::getInHundredthsOfOneMillimeter() const
@@ -1057,13 +1050,13 @@ double Millimeter::getInHundredthsOfOneMillimeter() const
sal_Int32 Millimeter::getInHundredthsOfOneMillimeter(double points)
{
- sal_Int32 mm = static_cast<sal_Int32>(points * factor);
+ sal_Int32 mm = std::round(convertPointToMm100(points));
return mm;
}
double Millimeter::getInPoints(int _hmm)
{
- double points = double( static_cast<double>(_hmm) / factor);
+ double points = convertMm100ToPoint<double>(_hmm);
return points;
}