[Libreoffice-commits] core.git: sc/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Sun Feb 21 09:03:26 UTC 2021
sc/source/core/data/column2.cxx | 17 +++++++++++------
sc/source/core/data/documen9.cxx | 5 +++--
sc/source/core/data/global.cxx | 5 +++--
sc/source/core/data/stlsheet.cxx | 7 ++++---
sc/source/core/data/table1.cxx | 5 +++--
sc/source/core/data/table2.cxx | 13 ++++++++-----
sc/source/core/tool/detfunc.cxx | 5 +++--
sc/source/filter/excel/xechart.cxx | 4 ++--
sc/source/filter/excel/xeescher.cxx | 10 +---------
sc/source/filter/excel/xichart.cxx | 5 +++--
sc/source/filter/excel/xlescher.cxx | 28 +++++++++-------------------
sc/source/filter/excel/xlpage.cxx | 7 ++++---
sc/source/filter/excel/xlstyle.cxx | 5 +++--
sc/source/filter/excel/xltools.cxx | 16 +++++++++-------
sc/source/filter/html/htmlexp.cxx | 3 ++-
sc/source/filter/inc/xlconst.hxx | 5 -----
sc/source/filter/rtf/eeimpars.cxx | 5 +++--
17 files changed, 71 insertions(+), 74 deletions(-)
New commits:
commit cdc67f6da362cea008a780abe412403eae64d04c
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sun Feb 21 11:10:22 2021 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Feb 21 10:02:46 2021 +0100
Some more unit conversion unification
Change-Id: I1a906d918bb4255a75c62c68a57244f59d51d2b1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111269
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index d194ab134dd1..e6430758cc6f 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -44,6 +44,7 @@
#include <editeng/eeitem.hxx>
#include <o3tl/safeint.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <svx/algitem.hxx>
#include <editeng/editobj.hxx>
#include <editeng/editstat.hxx>
@@ -420,7 +421,7 @@ tools::Long ScColumn::GetNeededSize(
// to ensure the exact same paper width (and same line breaks) as in
// ScEditUtil::GetEditArea, used for output.
- fWidthFactor = HMM_PER_TWIPS;
+ fWidthFactor = o3tl::convert(1.0, o3tl::Length::twip, o3tl::Length::mm100);
}
// use original width for hidden columns:
@@ -438,8 +439,9 @@ tools::Long ScColumn::GetNeededSize(
// space for AutoFilter button: 20 * nZoom/100
constexpr tools::Long nFilterButtonWidthPix = 20; // Autofilter pixel width at 100% zoom.
if ( pFlag->HasAutoFilter() && !bTextWysiwyg )
- nDocWidth -= bInPrintTwips ?
- (nFilterButtonWidthPix * TWIPS_PER_PIXEL) : tools::Long(rZoomX * nFilterButtonWidthPix);
+ nDocWidth -= bInPrintTwips ? o3tl::convert(nFilterButtonWidthPix, o3tl::Length::px,
+ o3tl::Length::twip)
+ : tools::Long(rZoomX * nFilterButtonWidthPix);
aPaper.setWidth( nDocWidth );
@@ -572,7 +574,9 @@ tools::Long ScColumn::GetNeededSize(
{
// add 1pt extra (default margin value) for line breaks with SetVertical
constexpr tools::Long nDefaultMarginInPoints = 1;
- nValue += conditionalScaleFunc(nDefaultMarginInPoints * TWIPS_PER_POINT, nPPT);
+ nValue += conditionalScaleFunc(
+ o3tl::convert(nDefaultMarginInPoints, o3tl::Length::pt, o3tl::Length::twip),
+ nPPT);
}
}
}
@@ -594,8 +598,9 @@ tools::Long ScColumn::GetNeededSize(
constexpr tools::Long nFilterButtonWidthPix = 20; // Autofilter pixel width at 100% zoom.
ScMF nFlags = pPattern->GetItem(ATTR_MERGE_FLAG).GetValue();
if (nFlags & ScMF::Auto)
- nValue += bInPrintTwips ?
- (nFilterButtonWidthPix * TWIPS_PER_PIXEL) : tools::Long(rZoomX * nFilterButtonWidthPix);
+ nValue += bInPrintTwips ? o3tl::convert(nFilterButtonWidthPix, o3tl::Length::px,
+ o3tl::Length::twip)
+ : tools::Long(rZoomX * nFilterButtonWidthPix);
}
return nValue;
diff --git a/sc/source/core/data/documen9.cxx b/sc/source/core/data/documen9.cxx
index f44159d6c436..ff5eb488f858 100644
--- a/sc/source/core/data/documen9.cxx
+++ b/sc/source/core/data/documen9.cxx
@@ -23,6 +23,7 @@
#include <editeng/autokernitem.hxx>
#include <editeng/fontitem.hxx>
#include <editeng/langitem.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <osl/thread.h>
#include <svl/asiancfg.hxx>
#include <svx/svditer.hxx>
@@ -456,8 +457,8 @@ bool ScDocument::IsPrintEmpty( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
for (i=nStartCol; i<=nEndCol; i++)
nRight += GetColWidth(i,nTab);
- aMMRect.SetLeft( static_cast<tools::Long>(nLeft * HMM_PER_TWIPS) );
- aMMRect.SetRight( static_cast<tools::Long>(nRight * HMM_PER_TWIPS) );
+ aMMRect.SetLeft(o3tl::convert(nLeft, o3tl::Length::twip, o3tl::Length::mm100));
+ aMMRect.SetRight(o3tl::convert(nRight, o3tl::Length::twip, o3tl::Length::mm100));
}
else
aMMRect = GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx
index 458e81da5188..e47303bf7cab 100644
--- a/sc/source/core/data/global.cxx
+++ b/sc/source/core/data/global.cxx
@@ -23,6 +23,7 @@
#include <editeng/editobj.hxx>
#include <svl/srchitem.hxx>
#include <editeng/langitem.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/objsh.hxx>
@@ -461,8 +462,8 @@ void ScGlobal::InitPPT()
if (comphelper::LibreOfficeKit::isActive())
{
// LOK: the below limited precision is not enough for RowColumnHeader.
- nScreenPPTX = double(pDev->GetDPIX()) / double(TWIPS_PER_INCH);
- nScreenPPTY = double(pDev->GetDPIY()) / double(TWIPS_PER_INCH);
+ nScreenPPTX = o3tl::convert<double>(pDev->GetDPIX(), o3tl::Length::twip, o3tl::Length::in);
+ nScreenPPTY = o3tl::convert<double>(pDev->GetDPIY(), o3tl::Length::twip, o3tl::Length::in);
}
else
{
diff --git a/sc/source/core/data/stlsheet.cxx b/sc/source/core/data/stlsheet.cxx
index 13acfa8e9e56..20f4399dd98b 100644
--- a/sc/source/core/data/stlsheet.cxx
+++ b/sc/source/core/data/stlsheet.cxx
@@ -34,14 +34,15 @@
#include <svl/itempool.hxx>
#include <svl/itemset.hxx>
#include <svl/hint.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <attrib.hxx>
#include <globstr.hrc>
#include <scresid.hxx>
#include <sc.hrc>
-#define TWO_CM 1134
-#define HFDIST_CM 142
+constexpr auto TWO_CM = o3tl::convert(2, o3tl::Length::cm, o3tl::Length::twip); // 1134
+constexpr auto HFDIST_CM = o3tl::convert(250, o3tl::Length::mm100, o3tl::Length::twip); // 142
ScStyleSheet::ScStyleSheet( const OUString& rName,
const ScStyleSheetPool& rPoolP,
@@ -163,7 +164,7 @@ SfxItemSet& ScStyleSheet::GetItemSet()
SfxItemSet& rHFSet = aHFSetItem.GetItemSet();
SvxSizeItem aHFSizeItem( // 0,5 cm + distance
ATTR_PAGE_SIZE,
- Size( 0, tools::Long( 500 / HMM_PER_TWIPS ) + HFDIST_CM ) );
+ Size( 0, o3tl::convert(500, o3tl::Length::mm100, o3tl::Length::twip) + HFDIST_CM ) );
SvxULSpaceItem aHFDistItem ( HFDIST_CM,// nUp
HFDIST_CM,// nLow
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index af09507b5c20..459f804984ed 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -20,6 +20,7 @@
#include <scitems.hxx>
#include <editeng/justifyitem.hxx>
#include <o3tl/safeint.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <unotools/textsearch.hxx>
#include <unotools/charclass.hxx>
@@ -302,8 +303,8 @@ ScTable::ScTable( ScDocument& rDoc, SCTAB nNewTab, const OUString& rNewName,
if ( pDrawLayer->ScAddPage( nTab ) ) // sal_False (not inserted) during Undo
{
pDrawLayer->ScRenamePage( nTab, aName );
- sal_uLong const nx = sal_uLong(double(rDocument.MaxCol()+1) * STD_COL_WIDTH * HMM_PER_TWIPS );
- sal_uLong ny = static_cast<sal_uLong>(double(rDocument.MaxRow()+1) * ScGlobal::nStdRowHeight * HMM_PER_TWIPS );
+ sal_uLong const nx = o3tl::convert((rDocument.MaxCol()+1) * STD_COL_WIDTH, o3tl::Length::twip, o3tl::Length::mm100);
+ sal_uLong ny = o3tl::convert((rDocument.MaxRow()+1) * ScGlobal::nStdRowHeight, o3tl::Length::twip, o3tl::Length::mm10);
pDrawLayer->SetPageSize( static_cast<sal_uInt16>(nTab), Size( nx, ny ), false );
}
}
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index d25e7ce7c7f4..833b4edd13f7 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -58,6 +58,7 @@
#include <editeng/boxitem.hxx>
#include <editeng/editobj.hxx>
#include <o3tl/safeint.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <svl/poolcach.hxx>
#include <unotools/charclass.hxx>
#include <math.h>
@@ -3916,13 +3917,15 @@ void ScTable::SetDrawPageSize(bool bResetStreamValid, bool bUpdateNoteCaptionPos
ScDrawLayer* pDrawLayer = rDocument.GetDrawLayer();
if( pDrawLayer )
{
- double fValX = GetColOffset( rDocument.MaxCol() + 1 ) * HMM_PER_TWIPS;
- double fValY = GetRowOffset( rDocument.MaxRow() + 1 ) * HMM_PER_TWIPS;
- const tools::Long nMax = ::std::numeric_limits<tools::Long>::max();
+ const sal_Int64 nMax = ::std::numeric_limits<tools::Long>::max();
// #i113884# Avoid int32 overflow with possible negative results than can cause bad effects.
// If the draw page size is smaller than all rows, only the bottom of the sheet is affected.
- tools::Long x = ( fValX > static_cast<double>(nMax) ) ? nMax : static_cast<tools::Long>(fValX);
- tools::Long y = ( fValY > static_cast<double>(nMax) ) ? nMax : static_cast<tools::Long>(fValY);
+ tools::Long x = std::min(o3tl::convert(GetColOffset(rDocument.MaxCol() + 1),
+ o3tl::Length::twip, o3tl::Length::mm100),
+ nMax);
+ tools::Long y = std::min(o3tl::convert(GetRowOffset(rDocument.MaxRow() + 1),
+ o3tl::Length::twip, o3tl::Length::mm100),
+ nMax);
if ( IsLayoutRTL() ) // IsNegativePage
x = -x;
diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx
index f2d8f8254d20..2b525e8c0891 100644
--- a/sc/source/core/tool/detfunc.cxx
+++ b/sc/source/core/tool/detfunc.cxx
@@ -21,6 +21,7 @@
#include <svtools/colorcfg.hxx>
#include <editeng/eeitem.hxx>
#include <formula/errorcodes.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <svx/sdshitm.hxx>
#include <svx/sdsxyitm.hxx>
#include <svx/sdtditm.hxx>
@@ -328,8 +329,8 @@ Point ScDetectiveFunc::GetDrawPos( SCCOL nCol, SCROW nRow, DrawPosMode eMode ) c
aPos.AdjustX(rDoc.GetColWidth( i, nTab ) );
aPos.AdjustY(rDoc.GetRowHeight( 0, nRow - 1, nTab ) );
- aPos.setX( static_cast< tools::Long >( aPos.X() * HMM_PER_TWIPS ) );
- aPos.setY( static_cast< tools::Long >( aPos.Y() * HMM_PER_TWIPS ) );
+ aPos.setX(o3tl::convert(aPos.X(), o3tl::Length::twip, o3tl::Length::mm100));
+ aPos.setY(o3tl::convert(aPos.Y(), o3tl::Length::twip, o3tl::Length::mm100));
if ( rDoc.IsNegativePage( nTab ) )
aPos.setX( aPos.X() * -1 );
diff --git a/sc/source/filter/excel/xechart.cxx b/sc/source/filter/excel/xechart.cxx
index 0b1f109f665c..ad829a913f31 100644
--- a/sc/source/filter/excel/xechart.cxx
+++ b/sc/source/filter/excel/xechart.cxx
@@ -2302,8 +2302,8 @@ void XclExpChLegend::Convert( const ScfPropertySet& rPropSet )
// legend size, Excel expects points in CHFRAMEPOS record
rFramePos.mnBRMode = EXC_CHFRAMEPOS_ABSSIZE_POINTS;
css::awt::Size aLegendSize = xChart1Legend->getSize();
- rFramePos.maRect.mnWidth = static_cast< sal_uInt16 >( aLegendSize.Width * EXC_POINTS_PER_HMM + 0.5 );
- rFramePos.maRect.mnHeight = static_cast< sal_uInt16 >( aLegendSize.Height * EXC_POINTS_PER_HMM + 0.5 );
+ rFramePos.maRect.mnWidth = o3tl::convert(aLegendSize.Width, o3tl::Length::mm100, o3tl::Length::pt);
+ rFramePos.maRect.mnHeight = o3tl::convert(aLegendSize.Height, o3tl::Length::mm100, o3tl::Length::pt);
maData.maRect.mnWidth = CalcChartXFromHmm( aLegendSize.Width );
maData.maRect.mnHeight = CalcChartYFromHmm( aLegendSize.Height );
eApiExpand = cssc::ChartLegendExpansion_CUSTOM;
diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx
index 68cf336c88a8..eea83fbeaf70 100644
--- a/sc/source/filter/excel/xeescher.cxx
+++ b/sc/source/filter/excel/xeescher.cxx
@@ -94,11 +94,6 @@ using namespace oox;
namespace
{
-tools::Long lcl_hmm2px(tools::Long nPixel)
-{
- return static_cast<tools::Long>(nPixel*PIXEL_PER_INCH/1000.0/CM_PER_INCH + 0.5);
-}
-
const char *ToHorizAlign( SdrTextHorzAdjust eAdjust )
{
switch( eAdjust )
@@ -149,10 +144,7 @@ void lcl_WriteAnchorVertex( sax_fastparser::FSHelperPtr const & rComments, const
tools::Long lcl_hmm2output(tools::Long value, bool bInEMU)
{
- if (bInEMU)
- return oox::drawingml::convertHmmToEmu(value);
- else
- return lcl_hmm2px(value);
+ return o3tl::convert(value, o3tl::Length::mm100, bInEMU ? o3tl::Length::emu : o3tl::Length::px);
}
void lcl_GetFromTo( const XclExpRoot& rRoot, const tools::Rectangle &aRect, sal_Int32 nTab, tools::Rectangle &aFrom, tools::Rectangle &aTo, bool bInEMU = false )
diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx
index 55c13e592cd4..befd63b3414c 100644
--- a/sc/source/filter/excel/xichart.cxx
+++ b/sc/source/filter/excel/xichart.cxx
@@ -76,6 +76,7 @@
#include <com/sun/star/chart2/data/LabeledDataSequence.hpp>
#include <comphelper/processfactory.hxx>
#include <o3tl/numeric.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <sfx2/objsh.hxx>
#include <svx/svdpage.hxx>
#include <svx/unoapi.hxx>
@@ -2625,8 +2626,8 @@ Reference< XLegend > XclImpChLegend::CreateLegend() const
(pFramePos->maRect.mnWidth > 0) && (pFramePos->maRect.mnHeight > 0) )
{
eApiExpand = cssc::ChartLegendExpansion_CUSTOM;
- sal_Int32 nWidthHmm = static_cast< sal_Int32 >( pFramePos->maRect.mnWidth / EXC_POINTS_PER_HMM );
- sal_Int32 nHeightHmm = static_cast< sal_Int32 >( pFramePos->maRect.mnHeight / EXC_POINTS_PER_HMM );
+ sal_Int32 nWidthHmm = o3tl::convert(pFramePos->maRect.mnWidth, o3tl::Length::pt, o3tl::Length::mm100);
+ sal_Int32 nHeightHmm = o3tl::convert(pFramePos->maRect.mnHeight, o3tl::Length::pt, o3tl::Length::mm100);
RelativeSize aRelSize( CalcRelativeFromHmmX( nWidthHmm ), CalcRelativeFromHmmY( nHeightHmm ) );
aLegendProp.SetProperty( EXC_CHPROP_RELATIVESIZE, aRelSize );
}
diff --git a/sc/source/filter/excel/xlescher.cxx b/sc/source/filter/excel/xlescher.cxx
index bb59b851a9a8..8ae663cdda7c 100644
--- a/sc/source/filter/excel/xlescher.cxx
+++ b/sc/source/filter/excel/xlescher.cxx
@@ -25,6 +25,7 @@
#include <com/sun/star/drawing/XControlShape.hpp>
#include <com/sun/star/script/ScriptEventDescriptor.hpp>
+#include <tools/UnitConversion.hxx>
#include <document.hxx>
#include <xistream.hxx>
#include <xlroot.hxx>
@@ -42,20 +43,11 @@ namespace {
/** Returns the scaling factor to calculate coordinates from twips. */
double lclGetTwipsScale( MapUnit eMapUnit )
{
- /* We cannot use OutputDevice::LogicToLogic() or the XclTools
- conversion functions to calculate drawing layer coordinates due to
- Calc's strange definition of a point (1 inch == 72.27 points, instead
- of 72 points).
- NOTE: Calc's definition changed from TeX points (72.27) to PS points
- (72), so the MapUnit::MapTwip case now actually also delivers a scale of 1.0
- */
double fScale = 1.0;
- switch( eMapUnit )
- {
- case MapUnit::MapTwip: fScale = 1; break; // Calc twips <-> real twips
- case MapUnit::Map100thMM: fScale = HMM_PER_TWIPS; break; // Calc twips <-> 1/100mm
- default: OSL_FAIL( "lclGetTwipsScale - map unit not implemented" );
- }
+ if (const auto eTo = MapToO3tlLength(eMapUnit); eTo != o3tl::Length::invalid)
+ fScale = o3tl::convert(1.0, o3tl::Length::twip, eTo);
+ else
+ OSL_FAIL("lclGetTwipsScale - map unit not implemented");
return fScale;
}
@@ -183,12 +175,10 @@ void XclObjAnchor::SetRect( const Size& rPageSize, sal_Int32 nScaleX, sal_Int32
const tools::Rectangle& rRect, MapUnit eMapUnit )
{
double fScale = 1.0;
- switch( eMapUnit )
- {
- case MapUnit::MapTwip: fScale = HMM_PER_TWIPS; break; // Calc twips -> 1/100mm
- case MapUnit::Map100thMM: fScale = 1.0; break; // Calc 1/100mm -> 1/100mm
- default: OSL_FAIL( "XclObjAnchor::SetRect - map unit not implemented" );
- }
+ if (const auto eFrom = MapToO3tlLength(eMapUnit); eFrom != o3tl::Length::invalid)
+ fScale = o3tl::convert(1.0, eFrom, o3tl::Length::mm100);
+ else
+ OSL_FAIL("XclObjAnchor::SetRect - map unit not implemented");
/* In objects with DFF client anchor, the position of the shape is stored
in the cell address components of the client anchor. In old BIFF3-BIFF5
diff --git a/sc/source/filter/excel/xlpage.cxx b/sc/source/filter/excel/xlpage.cxx
index 6186266fafb0..ef1742dd51e3 100644
--- a/sc/source/filter/excel/xlpage.cxx
+++ b/sc/source/filter/excel/xlpage.cxx
@@ -20,6 +20,7 @@
#include <xlpage.hxx>
#include <xltools.hxx>
#include <editeng/paperinf.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <sal/macros.h>
#include <editeng/brushitem.hxx>
#include <global.hxx>
@@ -36,15 +37,15 @@ struct XclPaperSize
constexpr tools::Long in2twips(double n_inch)
{
- return static_cast<tools::Long>( (n_inch * EXC_TWIPS_PER_INCH) + 0.5);
+ return o3tl::convert(n_inch, o3tl::Length::in, o3tl::Length::twip) + 0.5;
}
constexpr tools::Long mm2twips(double n_mm)
{
- return static_cast<tools::Long>( (n_mm * EXC_TWIPS_PER_INCH / CM_PER_INCH / 10.0) + 0.5);
+ return o3tl::convert(n_mm, o3tl::Length::mm, o3tl::Length::twip) + 0.5;
}
constexpr tools::Long twips2mm(tools::Long n_twips)
{
- return static_cast<tools::Long>((static_cast<double>(n_twips) - 0.5) / EXC_TWIPS_PER_INCH * CM_PER_INCH * 10.0);
+ return o3tl::convert(n_twips, o3tl::Length::twip, o3tl::Length::mm);
}
// see ApiPaperSize spPaperSizeTable in filter and aDinTab in i18nutil
diff --git a/sc/source/filter/excel/xlstyle.cxx b/sc/source/filter/excel/xlstyle.cxx
index 0cc23ed90bfb..84d146c922fb 100644
--- a/sc/source/filter/excel/xlstyle.cxx
+++ b/sc/source/filter/excel/xlstyle.cxx
@@ -32,6 +32,7 @@
#include <svtools/colorcfg.hxx>
#include <vcl/unohelp.hxx>
#include <editeng/svxfont.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <global.hxx>
#include <xlroot.hxx>
#include <xltools.hxx>
@@ -389,7 +390,7 @@ void XclFontData::SetScStrikeout( FontStrikeout eScStrikeout )
float XclFontData::GetApiHeight() const
{
- return static_cast< float >( mnHeight / TWIPS_PER_POINT );
+ return o3tl::convert<double>(mnHeight, o3tl::Length::twip, o3tl::Length::pt);
}
sal_Int16 XclFontData::GetApiFamily() const
@@ -454,7 +455,7 @@ sal_Int16 XclFontData::GetApiStrikeout() const
void XclFontData::SetApiHeight( float fPoint )
{
- mnHeight = static_cast< sal_uInt16 >( ::std::min( fPoint * TWIPS_PER_POINT + 0.5, 32767.0 ) );
+ mnHeight = std::min(o3tl::convert(fPoint, o3tl::Length::pt, o3tl::Length::twip) + 0.5, 32767.0);
}
void XclFontData::SetApiFamily( sal_Int16 nApiFamily )
diff --git a/sc/source/filter/excel/xltools.cxx b/sc/source/filter/excel/xltools.cxx
index e4ffbebce44b..82c5c0449b25 100644
--- a/sc/source/filter/excel/xltools.cxx
+++ b/sc/source/filter/excel/xltools.cxx
@@ -21,6 +21,7 @@
#include <math.h>
#include <string_view>
+#include <o3tl/unit_conversion.hxx>
#include <sal/mathconf.h>
#include <sal/macros.h>
#include <sal/log.hxx>
@@ -271,35 +272,36 @@ XclBoolError XclTools::ErrorToEnum( double& rfDblValue, bool bErrOrBool, sal_uIn
return eType;
}
+template <typename N> static N to(double f) { return limit_cast<N>(f + 0.5); }
+
sal_uInt16 XclTools::GetTwipsFromInch( double fInches )
{
- return static_cast< sal_uInt16 >(
- ::std::clamp( fInches * EXC_TWIPS_PER_INCH + 0.5, 0.0, 65535.0 ) );
+ return to<sal_uInt16>(o3tl::convert(fInches, o3tl::Length::in, o3tl::Length::twip));
}
sal_uInt16 XclTools::GetTwipsFromHmm( sal_Int32 nHmm )
{
- return GetTwipsFromInch( static_cast< double >( nHmm ) / 1000.0 / CM_PER_INCH );
+ return limit_cast<sal_uInt16>(o3tl::convert(nHmm, o3tl::Length::mm100, o3tl::Length::twip));
}
double XclTools::GetInchFromTwips( sal_Int32 nTwips )
{
- return static_cast< double >( nTwips ) / EXC_TWIPS_PER_INCH;
+ return o3tl::convert<double>(nTwips, o3tl::Length::twip, o3tl::Length::in);
}
double XclTools::GetInchFromHmm( sal_Int32 nHmm )
{
- return GetInchFromTwips( GetTwipsFromHmm( nHmm ) );
+ return o3tl::convert<double>(nHmm, o3tl::Length::mm100, o3tl::Length::in);
}
sal_Int32 XclTools::GetHmmFromInch( double fInches )
{
- return static_cast< sal_Int32 >( fInches * CM_PER_INCH * 1000 );
+ return to<sal_Int32>(o3tl::convert(fInches, o3tl::Length::in, o3tl::Length::mm100));
}
sal_Int32 XclTools::GetHmmFromTwips( sal_Int32 nTwips )
{
- return GetHmmFromInch( GetInchFromTwips( nTwips ) );
+ return limit_cast<sal_Int32>(o3tl::convert(nTwips, o3tl::Length::twip, o3tl::Length::mm100));
}
sal_uInt16 XclTools::GetScColumnWidth( sal_uInt16 nXclWidth, tools::Long nScCharWidth )
diff --git a/sc/source/filter/html/htmlexp.cxx b/sc/source/filter/html/htmlexp.cxx
index b0402ada933a..5d527f6ca167 100644
--- a/sc/source/filter/html/htmlexp.cxx
+++ b/sc/source/filter/html/htmlexp.cxx
@@ -48,6 +48,7 @@
#include <vcl/outdev.hxx>
#include <stdio.h>
#include <osl/diagnose.h>
+#include <o3tl/unit_conversion.hxx>
#include <htmlexp.hxx>
#include <global.hxx>
@@ -494,7 +495,7 @@ OString ScHTMLExport::BorderToStyle(const char* pBorderName,
// thickness
int nWidth = pLine->GetWidth();
int nPxWidth = (nWidth > 0) ?
- std::max(int(nWidth / TWIPS_PER_PIXEL), 1) : 0;
+ std::max(o3tl::convert(nWidth, o3tl::Length::twip, o3tl::Length::px), sal_Int64(1)) : 0;
aOut.append(static_cast<sal_Int32>(nPxWidth)).
append("px ");
switch (pLine->GetBorderLineStyle())
diff --git a/sc/source/filter/inc/xlconst.hxx b/sc/source/filter/inc/xlconst.hxx
index 5a1c0dea585f..2338cf15417f 100644
--- a/sc/source/filter/inc/xlconst.hxx
+++ b/sc/source/filter/inc/xlconst.hxx
@@ -131,11 +131,6 @@ const sal_Int32 EXC_RK_INT100 = EXC_RK_100FLAG | EXC_RK_INTFLAG;
// Measures -------------------------------------------------------------------
-const sal_Int32 EXC_POINTS_PER_INCH = 72;
-const sal_Int32 EXC_TWIPS_PER_INCH = EXC_POINTS_PER_INCH * 20;
-
-const double EXC_POINTS_PER_HMM = static_cast< double >( EXC_POINTS_PER_INCH ) / 2540.0;
-
const sal_uInt8 EXC_ORIENT_NONE = 0; /// Text orientation: not rotated.
const sal_uInt8 EXC_ORIENT_STACKED = 1; /// Text orientation: vertically stacked.
const sal_uInt8 EXC_ORIENT_90CCW = 2; /// Text orientation: 90 deg counterclockwise.
diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx
index be0ecc4dd829..db15c1560e10 100644
--- a/sc/source/filter/rtf/eeimpars.cxx
+++ b/sc/source/filter/rtf/eeimpars.cxx
@@ -24,6 +24,7 @@
#include <editeng/editobj.hxx>
#include <editeng/escapementitem.hxx>
#include <editeng/langitem.hxx>
+#include <o3tl/unit_conversion.hxx>
#include <svx/svdograf.hxx>
#include <svx/svdpage.hxx>
#include <svtools/htmlcfg.hxx>
@@ -556,8 +557,8 @@ void ScEEImport::InsertGraphic( SCCOL nCol, SCROW nRow, SCTAB nTab,
OutputDevice* pDefaultDev = Application::GetDefaultDevice();
Point aCellInsertPos(
- static_cast<tools::Long>(static_cast<double>(mpDoc->GetColOffset( nCol, nTab )) * HMM_PER_TWIPS),
- static_cast<tools::Long>(static_cast<double>(mpDoc->GetRowOffset( nRow, nTab )) * HMM_PER_TWIPS) );
+ o3tl::convert(mpDoc->GetColOffset(nCol, nTab), o3tl::Length::twip, o3tl::Length::mm100),
+ o3tl::convert(mpDoc->GetRowOffset(nRow, nTab), o3tl::Length::twip, o3tl::Length::mm100));
Point aInsertPos( aCellInsertPos );
Point aSpace;
More information about the Libreoffice-commits
mailing list