summaryrefslogtreecommitdiffstats
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
parentUpdate git submodules (diff)
downloadcore-956c09ca7d690471f62e8e2e14ad04fefcebf7e7.tar.gz
core-956c09ca7d690471f62e8e2e14ad04fefcebf7e7.zip
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>
-rw-r--r--chart2/source/view/charttypes/VSeriesPlotter.cxx4
-rw-r--r--chart2/source/view/main/ShapeFactory.cxx3
-rw-r--r--chart2/source/view/main/VLegend.cxx4
-rw-r--r--filter/source/msfilter/svdfppt.cxx12
-rw-r--r--include/tools/UnitConversion.hxx66
-rw-r--r--oox/source/drawingml/chart/typegroupconverter.cxx3
-rw-r--r--oox/source/ole/vbacontrol.cxx4
-rw-r--r--sd/source/core/drawdoc4.cxx4
-rw-r--r--sd/source/core/stlpool.cxx3
-rw-r--r--sd/source/filter/eppt/epptso.cxx3
-rw-r--r--sd/source/filter/eppt/pptx-epptooxml.cxx5
-rw-r--r--sd/source/filter/eppt/pptx-text.cxx17
-rw-r--r--vbahelper/source/vbahelper/vbahelper.cxx23
-rw-r--r--vcl/unx/gtk3/a11y/gtk3atktextattributes.cxx9
14 files changed, 83 insertions, 77 deletions
diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx
index f405396e113c..92cb3786d594 100644
--- a/chart2/source/view/charttypes/VSeriesPlotter.cxx
+++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx
@@ -61,6 +61,7 @@
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/chart2/RelativePosition.hpp>
#include <tools/color.hxx>
+#include <tools/UnitConversion.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/math.hxx>
#include <basegfx/vector/b2dvector.hxx>
@@ -451,8 +452,7 @@ uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Re
uno::Reference< beans::XPropertySet > xProps( rDataSeries.getPropertiesOfPoint( nPointIndex ) );
if( xProps.is() )
xProps->getPropertyValue( "CharHeight") >>= fViewFontSize;
- // pt -> 1/100th mm
- fViewFontSize *= (2540.0f / 72.0f);
+ fViewFontSize = convertPointToMm100(fViewFontSize);
}
// the font height is used for computing the size of an optional legend
diff --git a/chart2/source/view/main/ShapeFactory.cxx b/chart2/source/view/main/ShapeFactory.cxx
index 22b9f8d07820..5b7c4859beb8 100644
--- a/chart2/source/view/main/ShapeFactory.cxx
+++ b/chart2/source/view/main/ShapeFactory.cxx
@@ -56,6 +56,7 @@
#include <basegfx/matrix/b3dhommatrix.hxx>
#include <tools/diagnose_ex.h>
#include <tools/helpers.hxx>
+#include <tools/UnitConversion.hxx>
#include <sal/log.hxx>
#include <algorithm>
@@ -2391,7 +2392,7 @@ uno::Reference< drawing::XShape >
float fFontHeight = 0.0;
if ( xShapeProp.is() && ( xShapeProp->getPropertyValue( "CharHeight" ) >>= fFontHeight ) )
{
- fFontHeight *= ( 2540.0f / 72.0f ); // pt -> 1/100 mm
+ fFontHeight = convertPointToMm100(fFontHeight);
sal_Int32 nXDistance = static_cast< sal_Int32 >( ::rtl::math::round( fFontHeight * 0.18f ) );
sal_Int32 nYDistance = static_cast< sal_Int32 >( ::rtl::math::round( fFontHeight * 0.30f ) );
xShapeProp->setPropertyValue( "TextLeftDistance", uno::Any( nXDistance ) );
diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx
index 77e6b5800dc5..e05aa94db702 100644
--- a/chart2/source/view/main/VLegend.cxx
+++ b/chart2/source/view/main/VLegend.cxx
@@ -42,6 +42,7 @@
#include <rtl/math.hxx>
#include <svl/languageoptions.hxx>
#include <tools/diagnose_ex.h>
+#include <tools/UnitConversion.hxx>
#include <vector>
#include <algorithm>
@@ -85,8 +86,7 @@ double lcl_CalcViewFontSize(
}
}
- // pt -> 1/100th mm
- return (fResult * (2540.0 / 72.0));
+ return convertPointToMm100(fResult);
}
void lcl_getProperties(
diff --git a/filter/source/msfilter/svdfppt.cxx b/filter/source/msfilter/svdfppt.cxx
index 1d7a36032d4c..8cfbf6ed3922 100644
--- a/filter/source/msfilter/svdfppt.cxx
+++ b/filter/source/msfilter/svdfppt.cxx
@@ -3800,8 +3800,8 @@ void PPTNumberFormatCreator::ImplGetNumberFormat( SdrPowerPointImport const & rM
rNumberFormat.SetBulletChar( nBuChar );
rNumberFormat.SetBulletRelSize( static_cast<sal_uInt16>(nBulletHeight) );
rNumberFormat.SetBulletColor( aCol );
- sal_uInt32 nAbsLSpace = ( nTextOfs * 2540 ) / 576;
- sal_uInt32 nFirstLineOffset = nAbsLSpace - ( nBulletOfs * 2540 ) / 576;
+ sal_uInt32 nAbsLSpace = convertMasterUnitToMm100(nTextOfs);
+ sal_uInt32 nFirstLineOffset = nAbsLSpace - convertMasterUnitToMm100(nBulletOfs);
rNumberFormat.SetAbsLSpace( nAbsLSpace );
rNumberFormat.SetFirstLineOffset( -static_cast<sal_Int32>(nFirstLineOffset) );
}
@@ -6211,8 +6211,8 @@ void PPTParagraphObj::ApplyTo( SfxItemSet& rSet, std::optional< sal_Int16 >& rS
if ( !nIsBullet2 )
{
SvxLRSpaceItem aLRSpaceItem( EE_PARA_LRSPACE );
- sal_uInt16 nAbsLSpace = static_cast<sal_uInt16>( ( _nTextOfs * 2540 ) / 576 );
- auto const nFirstLineOffset = nAbsLSpace - static_cast<sal_uInt16>( ( _nBulletOfs * 2540 ) / 576 );
+ auto const nAbsLSpace = convertMasterUnitToMm100(_nTextOfs);
+ auto const nFirstLineOffset = nAbsLSpace - convertMasterUnitToMm100(_nBulletOfs);
aLRSpaceItem.SetLeft( nAbsLSpace );
aLRSpaceItem.SetTextFirstLineOffsetValue( -nFirstLineOffset );
rSet.Put( aLRSpaceItem );
@@ -6290,7 +6290,7 @@ void PPTParagraphObj::ApplyTo( SfxItemSet& rSet, std::optional< sal_Int16 >& rS
SvxULSpaceItem aULSpaceItem( EE_PARA_ULSPACE );
nVal2 = static_cast<sal_Int16>(nUpperDist);
if ( nVal2 <= 0 )
- aULSpaceItem.SetUpper( static_cast<sal_uInt16>((static_cast<sal_uInt32>(- nVal2) * 2540 ) / ( 72 * 8 ) ) );
+ aULSpaceItem.SetUpper(static_cast<sal_uInt16>(convertMasterUnitToMm100(-nVal2)));
else
{
aULSpaceItem.SetUpperValue( 0 );
@@ -6298,7 +6298,7 @@ void PPTParagraphObj::ApplyTo( SfxItemSet& rSet, std::optional< sal_Int16 >& rS
}
nVal2 = static_cast<sal_Int16>(nLowerDist);
if ( nVal2 <= 0 )
- aULSpaceItem.SetLower( static_cast<sal_uInt16>((static_cast<sal_uInt32>(- nVal2) * 2540 ) / ( 72 * 8 ) ) );
+ aULSpaceItem.SetLower(static_cast<sal_uInt16>(convertMasterUnitToMm100(-nVal2)));
else
{
aULSpaceItem.SetLowerValue( 0 );
diff --git a/include/tools/UnitConversion.hxx b/include/tools/UnitConversion.hxx
index 57f8e39119f0..7aac3f36ebd0 100644
--- a/include/tools/UnitConversion.hxx
+++ b/include/tools/UnitConversion.hxx
@@ -12,46 +12,60 @@
#include <sal/types.h>
#include <cassert>
-#include <limits>
+#include <type_traits>
-constexpr sal_Int64 convertTwipToMm100(sal_Int64 n)
+template <typename I> constexpr bool isBetween(I n, sal_Int64 min, sal_Int64 max)
{
- assert(n < std::numeric_limits<sal_Int64>::max() / 127
- && n > std::numeric_limits<sal_Int64>::min() / 127);
- return (n >= 0) ? (n * 127 + 36) / 72 : (n * 127 - 36) / 72;
+ assert(max > 0 && min < 0);
+ if constexpr (std::is_signed_v<I>)
+ return n >= min && n <= max;
+ else
+ return n <= sal_uInt64(max);
}
-constexpr sal_Int64 convertMm100ToTwip(sal_Int64 n)
+constexpr int actualMul(int m, int d) { return (m % d == 0) ? m / d : (d % m == 0) ? 1 : m; }
+constexpr int actualDiv(int m, int d) { return (m % d == 0) ? 1 : (d % m == 0) ? d / m : d; }
+
+// Ensure correct rounding for both positive and negative integers
+template <int mul, int div, typename I, std::enable_if_t<std::is_integral_v<I>, int> = 0>
+constexpr sal_Int64 MulDiv(I n)
{
- assert(n < std::numeric_limits<sal_Int64>::max() / 72
- && n > std::numeric_limits<sal_Int64>::min() / 72);
- return (n >= 0) ? (n * 72 + 63) / 127 : (n * 72 - 63) / 127;
+ static_assert(mul > 0 && div > 0);
+ constexpr int m = actualMul(mul, div), d = actualDiv(mul, div);
+ assert(isBetween(n, (SAL_MIN_INT64 + d / 2) / m, (SAL_MAX_INT64 - d / 2) / m));
+ return (n >= 0 ? (sal_Int64(n) * m + d / 2) : (sal_Int64(n) * m - d / 2)) / d;
}
-
-constexpr sal_Int64 sanitiseMm100ToTwip(sal_Int64 n)
+template <int mul, int div, typename F, std::enable_if_t<std::is_floating_point_v<F>, int> = 0>
+constexpr double MulDiv(F f)
{
- if (n >= std::numeric_limits<sal_Int64>::max() / 72
- || n <= std::numeric_limits<sal_Int64>::min() / 72)
- return n / 127 * 72; // do without correction; can not overflow here
- else
- return convertMm100ToTwip(n);
+ static_assert(mul > 0 && div > 0);
+ return f * (double(mul) / div);
}
-constexpr sal_Int64 convertPointToTwip(sal_Int64 nNumber) { return nNumber * 20; }
-
-constexpr sal_Int64 convertPointToMm100(sal_Int64 nNumber)
+template <int mul, int div, typename I, std::enable_if_t<std::is_integral_v<I>, int> = 0>
+constexpr sal_Int64 sanitizeMulDiv(I n)
{
- return convertTwipToMm100(convertPointToTwip(nNumber));
+ constexpr int m = actualMul(mul, div), d = actualDiv(mul, div);
+ if constexpr (m > d)
+ if (!isBetween(n, SAL_MIN_INT64 / m * d + d / 2, SAL_MAX_INT64 / m * d - d / 2))
+ return n > 0 ? SAL_MAX_INT64 : SAL_MIN_INT64; // saturate
+ if (!isBetween(n, (SAL_MIN_INT64 + d / 2) / m, (SAL_MAX_INT64 - d / 2) / m))
+ return (n >= 0 ? n + d / 2 : n - d / 2) / d * m; // divide before multiplication
+ return MulDiv<mul, div>(n);
}
-constexpr double convertPointToTwip(double fNumber) { return fNumber * 20.0; }
+template <typename N> constexpr auto convertTwipToMm100(N n) { return MulDiv<127, 72>(n); }
+template <typename N> constexpr auto convertMm100ToTwip(N n) { return MulDiv<72, 127>(n); }
+
+constexpr sal_Int64 sanitiseMm100ToTwip(sal_Int64 n) { return sanitizeMulDiv<72, 127>(n); }
-constexpr double convertPointToMm100(double fNumber) { return fNumber * (2540.0 / 72.0); }
+template <typename N> constexpr auto convertPointToTwip(N n) { return MulDiv<20, 1>(n); }
-// Convert PPT's "master unit" (1/576 inch) to mm/100
-constexpr sal_Int64 convertMasterUnitToMm100(sal_Int64 n) { return n * (2540.0 / 576.0); }
+template <typename N> constexpr auto convertPointToMm100(N n) { return MulDiv<2540, 72>(n); }
+template <typename N> constexpr auto convertMm100ToPoint(N n) { return MulDiv<72, 2540>(n); }
-// Convert mm/100 to PPT's "master unit"
-constexpr sal_Int64 convertMm100ToMasterUnit(sal_Int64 n) { return n / (2540.0 / 576.0); }
+// PPT's "master unit" (1/576 inch) <=> mm/100
+template <typename N> constexpr auto convertMasterUnitToMm100(N n) { return MulDiv<2540, 576>(n); }
+template <typename N> constexpr auto convertMm100ToMasterUnit(N n) { return MulDiv<576, 2540>(n); }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/drawingml/chart/typegroupconverter.cxx b/oox/source/drawingml/chart/typegroupconverter.cxx
index f6cea5df9b38..6cc4d81eba25 100644
--- a/oox/source/drawingml/chart/typegroupconverter.cxx
+++ b/oox/source/drawingml/chart/typegroupconverter.cxx
@@ -43,6 +43,7 @@
#include <oox/token/namespaces.hxx>
#include <oox/token/properties.hxx>
#include <oox/token/tokens.hxx>
+#include <tools/UnitConversion.hxx>
namespace oox::drawingml::chart {
@@ -489,7 +490,7 @@ void TypeGroupConverter::convertMarker( PropertySet& rPropSet, sal_Int32 nOoxSym
}
// symbol size (points in OOXML, 1/100 mm in Chart2)
- sal_Int32 nSize = static_cast< sal_Int32 >( nOoxSize * (2540.0 / 72.0) + 0.5 );
+ sal_Int32 nSize = convertPointToMm100(nOoxSize);
aSymbol.Size.Width = aSymbol.Size.Height = nSize;
if(xShapeProps.is())
diff --git a/oox/source/ole/vbacontrol.cxx b/oox/source/ole/vbacontrol.cxx
index 1b85c27dd6f6..07c91483c773 100644
--- a/oox/source/ole/vbacontrol.cxx
+++ b/oox/source/ole/vbacontrol.cxx
@@ -30,6 +30,7 @@
#include <osl/diagnose.h>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
+#include <tools/UnitConversion.hxx>
#include <xmlscript/xmldlg_imexp.hxx>
#include <oox/helper/attributelist.hxx>
#include <oox/helper/binaryinputstream.hxx>
@@ -706,8 +707,7 @@ void VbaFormControl::moveEmbeddedToAbsoluteParent()
const AxFontDataModel* pFontModel = dynamic_cast< const AxFontDataModel* >( mxCtrlModel.get() );
if( pFontModel && (pFontModel->getControlType() == API_CONTROL_GROUPBOX) )
{
- // convert points to 1/100 mm (1 pt = 1/72 inch = 2.54/72 cm = 2540/72 1/100 mm)
- sal_Int32 nFontHeight = static_cast< sal_Int32 >( pFontModel->getFontHeight() * 2540 / 72 );
+ sal_Int32 nFontHeight = convertPointToMm100(pFontModel->getFontHeight());
aDistance.second += nFontHeight / 2;
}
diff --git a/sd/source/core/drawdoc4.cxx b/sd/source/core/drawdoc4.cxx
index 48ad50b89ced..a71b9ea8b6bc 100644
--- a/sd/source/core/drawdoc4.cxx
+++ b/sd/source/core/drawdoc4.cxx
@@ -30,6 +30,7 @@
#include <DrawDocShell.hxx>
#include <editeng/eeitem.hxx>
#include <tools/diagnose_ex.h>
+#include <tools/UnitConversion.hxx>
#include <vcl/idle.hxx>
#include <vcl/settings.hxx>
@@ -1342,8 +1343,7 @@ sal_uInt32 SdDrawDocument::convertFontHeightToCTL( sal_uInt32 nWesternFontHeight
double fTemp = double(nWesternFontHeight) * 1.333;
nWesternFontHeight = static_cast<sal_uInt32>(fTemp);
// make some nice values for UI that displays PT instead of 1/100th mm
- nWesternFontHeight = ((nWesternFontHeight * 72) + 1270) / 2540L;
- nWesternFontHeight = ((nWesternFontHeight * 2540L) + 36) / 72;
+ nWesternFontHeight = convertPointToMm100(convertMm100ToPoint(nWesternFontHeight));
}
return nWesternFontHeight;
}
diff --git a/sd/source/core/stlpool.cxx b/sd/source/core/stlpool.cxx
index f1ff79ac566d..8345ba75ed60 100644
--- a/sd/source/core/stlpool.cxx
+++ b/sd/source/core/stlpool.cxx
@@ -47,6 +47,7 @@
#include <svx/sdr/table/tabledesign.hxx>
#include <editeng/autokernitem.hxx>
#include <tools/diagnose_ex.h>
+#include <tools/UnitConversion.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/adjustitem.hxx>
@@ -284,7 +285,7 @@ void SdStyleSheetPool::CreateLayoutStyleSheets(std::u16string_view rLayoutName,
}
// FontSize
- nFontSize = static_cast<sal_uInt16>((nFontSize * 2540L) / 72); // Pt --> 1/100 mm
+ nFontSize = static_cast<sal_uInt16>(convertPointToMm100(nFontSize));
SfxItemSet& rOutlineSet = pSheet->GetItemSet();
rOutlineSet.Put( SvxFontHeightItem( nFontSize, 100, EE_CHAR_FONTHEIGHT ) );
rOutlineSet.Put( SvxFontHeightItem( nFontSize, 100, EE_CHAR_FONTHEIGHT_CJK ) );
diff --git a/sd/source/filter/eppt/epptso.cxx b/sd/source/filter/eppt/epptso.cxx
index c42848ae4aff..77095a8e497e 100644
--- a/sd/source/filter/eppt/epptso.cxx
+++ b/sd/source/filter/eppt/epptso.cxx
@@ -1011,8 +1011,7 @@ void PPTWriter::ImplAdjustFirstLineLineSpacing( TextObj& rTextObj, EscherPropert
if ( ( nLineSpacing > 0 ) && ( nLineSpacing < 100 ) )
{
- double fCharHeight = rPortion.mnCharHeight;
- fCharHeight *= 2540 / 72.0;
+ double fCharHeight = convertPointToMm100<double>(rPortion.mnCharHeight);
fCharHeight *= 100 - nLineSpacing;
fCharHeight /= 100;
diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx
index ce4e103edc91..4028523698ac 100644
--- a/sd/source/filter/eppt/pptx-epptooxml.cxx
+++ b/sd/source/filter/eppt/pptx-epptooxml.cxx
@@ -31,6 +31,7 @@
#include <sax/fshelper.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
+#include <tools/UnitConversion.hxx>
#include <com/sun/star/animations/TransitionType.hpp>
#include <com/sun/star/animations/TransitionSubType.hpp>
#include <com/sun/star/beans/XPropertySetInfo.hpp>
@@ -1025,8 +1026,8 @@ bool PowerPointExport::WriteComments(sal_uInt32 nPageNum)
XML_idx, OString::number(nLastIndex));
pFS->singleElementNS(XML_p, XML_pos,
- XML_x, OString::number(static_cast<sal_Int64>((57600*aRealPoint2D.X + 1270)/2540.0)),
- XML_y, OString::number(static_cast<sal_Int64>((57600*aRealPoint2D.Y + 1270)/2540.0)));
+ XML_x, OString::number(std::round(convertMm100ToMasterUnit(aRealPoint2D.X * 100))),
+ XML_y, OString::number(std::round(convertMm100ToMasterUnit(aRealPoint2D.Y * 100))));
pFS->startElementNS(XML_p, XML_text);
pFS->write(xText->getString());
diff --git a/sd/source/filter/eppt/pptx-text.cxx b/sd/source/filter/eppt/pptx-text.cxx
index f18c7c449ff1..fa030624a798 100644
--- a/sd/source/filter/eppt/pptx-text.cxx
+++ b/sd/source/filter/eppt/pptx-text.cxx
@@ -49,6 +49,7 @@
#include <svl/languageoptions.hxx>
#include <osl/diagnose.h>
#include <i18nlangtag/languagetag.hxx>
+#include <tools/UnitConversion.hxx>
#include <vcl/settings.hxx>
#include <vcl/metric.hxx>
@@ -775,12 +776,12 @@ void ParagraphObj::ImplGetNumberingLevel( PPTExBulletProvider* pBuProv, sal_Int1
{
sal_Int32 nVal(0);
if ( aAny >>= nVal )
- nTextOfs = static_cast< sal_Int16 >( nVal / ( 2540.0 / 576 ) + 0.5 ) ;
+ nTextOfs = convertMm100ToMasterUnit(nVal);
}
if ( GetPropertyValue( aAny, mXPropSet, "ParaFirstLineIndent" ) )
{
if ( aAny >>= nBulletOfs )
- nBulletOfs = static_cast< sal_Int32 >( nBulletOfs / ( 2540.0 / 576 ) + 0.5 );
+ nBulletOfs = convertMm100ToMasterUnit(nBulletOfs);
}
if ( GetPropertyValue( aAny, mXPropSet, "NumberingIsNumber" ) )
aAny >>= bNumberingIsNumber;
@@ -843,9 +844,9 @@ void ParagraphObj::ImplGetNumberingLevel( PPTExBulletProvider* pBuProv, sal_Int1
else if ( aPropName == "StartWith" )
nStartWith = *o3tl::doAccess<sal_Int16>(rPropValue.Value);
else if ( aPropName == "LeftMargin" )
- nTextOfs = nTextOfs + static_cast< sal_Int16 >( *o3tl::doAccess<sal_Int32>(rPropValue.Value) / ( 2540.0 / 576 ) );
+ nTextOfs += convertMm100ToMasterUnit(*o3tl::doAccess<sal_Int32>(rPropValue.Value));
else if ( aPropName == "FirstLineOffset" )
- nBulletOfs += static_cast<sal_Int16>( *o3tl::doAccess<sal_Int32>(rPropValue.Value) / ( 2540.0 / 576 ) );
+ nBulletOfs += convertMm100ToMasterUnit(*o3tl::doAccess<sal_Int32>(rPropValue.Value));
else if ( aPropName == "BulletColor" )
{
sal_uInt32 nSOColor = *o3tl::doAccess<sal_uInt32>(rPropValue.Value);
@@ -1143,15 +1144,15 @@ void ParagraphObj::ImplGetParagraphValues( PPTExBulletProvider* pBuProv, bool bG
if ( ImplGetPropertyValue( "ParaBottomMargin", bGetPropStateValue ) )
{
- double fSpacing = *o3tl::doAccess<sal_uInt32>(mAny) + ( 2540.0 / 576.0 ) - 1;
- mnLineSpacingBottom = static_cast<sal_Int16>(-( fSpacing * 576.0 / 2540.0 ) );
+ double fSpacing = *o3tl::doAccess<sal_uInt32>(mAny) + convertMasterUnitToMm100(1.0) - 1;
+ mnLineSpacingBottom = std::round(-convertMm100ToMasterUnit(fSpacing));
}
meLineSpacingBottom = ePropState;
if ( ImplGetPropertyValue( "ParaTopMargin", bGetPropStateValue ) )
{
- double fSpacing = *o3tl::doAccess<sal_uInt32>(mAny) + ( 2540.0 / 576.0 ) - 1;
- mnLineSpacingTop = static_cast<sal_Int16>(-( fSpacing * 576.0 / 2540.0 ) );
+ double fSpacing = *o3tl::doAccess<sal_uInt32>(mAny) + convertMasterUnitToMm100(1.0) - 1;
+ mnLineSpacingTop = std::round(-convertMm100ToMasterUnit(fSpacing));
}
meLineSpacingTop = ePropState;
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;
}
diff --git a/vcl/unx/gtk3/a11y/gtk3atktextattributes.cxx b/vcl/unx/gtk3/a11y/gtk3atktextattributes.cxx
index 914466315ce2..31c5ebd3585b 100644
--- a/vcl/unx/gtk3/a11y/gtk3atktextattributes.cxx
+++ b/vcl/unx/gtk3/a11y/gtk3atktextattributes.cxx
@@ -37,6 +37,7 @@
#include <com/sun/star/accessibility/XAccessibleComponent.hpp>
#include <i18nlangtag/languagetag.hxx>
+#include <tools/UnitConversion.hxx>
#include <stdio.h>
#include <string.h>
@@ -173,12 +174,6 @@ get_value( const uno::Sequence< beans::PropertyValue >& rAttributeList,
#define get_weight_value( list, index ) get_value( list, index, Weight2String )
#define get_language_string( list, index ) get_value( list, index, Locale2String )
-static double toPoint(sal_Int16 n)
-{
- // 100th mm -> pt
- return static_cast<double>(n * 72) / 2540;
-}
-
/*****************************************************************************/
static bool
@@ -908,7 +903,7 @@ LineSpacing2LineHeight( const uno::Any& rAny )
if( ls.Mode == style::LineSpacingMode::PROP )
ret = g_strdup_printf( "%d%%", ls.Height );
else if( ls.Mode == style::LineSpacingMode::FIX )
- ret = g_strdup_printf( "%.3gpt", toPoint(ls.Height) );
+ ret = g_strdup_printf("%.3gpt", convertMm100ToPoint<double>(ls.Height));
}
return ret;