summaryrefslogtreecommitdiff
path: root/sd
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 /sd
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 'sd')
-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
5 files changed, 17 insertions, 15 deletions
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;