diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-01-27 09:18:41 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-01-27 15:12:48 +0100 |
commit | 75036ee916046b9d1bfd705b368ffe94cc7cfa79 (patch) | |
tree | dc3c771b286c5ed79be87f52398963a5220a1df4 /sc/source/filter/oox/worksheethelper.cxx | |
parent | 5d388b94735e34ba445d65e1d5030a646aad7dbe (diff) |
Simplify oox::xls::UnitConverter and its uses
Use o3tl::convert where it was used to convert between two fixed units.
Simplify cases where several conversions were performed in a row.
Use EMUs as UnitConverter base unit, to have simplest quotients and
increase accuracy.
Change-Id: I07c197dba470cfe289cef84e82b78547635cf9af
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129016
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc/source/filter/oox/worksheethelper.cxx')
-rw-r--r-- | sc/source/filter/oox/worksheethelper.cxx | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx index 40a99cdb444b..f2f4c2005d98 100644 --- a/sc/source/filter/oox/worksheethelper.cxx +++ b/sc/source/filter/oox/worksheethelper.cxx @@ -743,9 +743,7 @@ void WorksheetGlobals::setBaseColumnWidth( sal_Int32 nWidth ) if( !mbHasDefWidth && (nWidth > 0) ) { // #i3006# add 5 pixels padding to the width - const UnitConverter& rUnitConv = getUnitConverter(); - maDefColModel.mfWidth = rUnitConv.scaleFromMm100( - rUnitConv.scaleToMm100( nWidth, Unit::Digit ) + rUnitConv.scaleToMm100( 5, Unit::ScreenX ), Unit::Digit ); + maDefColModel.mfWidth = nWidth + getUnitConverter().scaleValue( 5, Unit::ScreenX, Unit::Digit ); } } @@ -1206,12 +1204,8 @@ void WorksheetGlobals::convertColumns() void WorksheetGlobals::convertColumns( OutlineLevelVec& orColLevels, const ValueRange& rColRange, const ColumnModel& rModel ) { - // column width: convert 'number of characters' to column width in 1/100 mm - sal_Int32 nWidth = getUnitConverter().scaleToMm100( rModel.mfWidth, Unit::Digit ); - - // macro sheets have double width - if( meSheetType == WorksheetType::Macro ) - nWidth *= 2; + // column width: convert 'number of characters' to column width in twips + sal_Int32 nWidth = std::round(getUnitConverter().scaleValue( rModel.mfWidth, Unit::Digit, Unit::Twip )); SCTAB nTab = getSheetIndex(); ScDocument& rDoc = getScDocument(); @@ -1220,9 +1214,13 @@ void WorksheetGlobals::convertColumns( OutlineLevelVec& orColLevels, if( nWidth > 0 ) { + // macro sheets have double width + if( meSheetType == WorksheetType::Macro ) + nWidth *= 2; + for( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol ) { - rDoc.SetColWidthOnly(nCol, nTab, o3tl::toTwips(nWidth, o3tl::Length::mm100)); + rDoc.SetColWidthOnly(nCol, nTab, nWidth); } } @@ -1267,9 +1265,9 @@ void WorksheetGlobals::convertRows(OutlineLevelVec& orRowLevels, const ValueRang const RowModel& rModel, const std::vector<sc::ColRowSpan>& rSpans, double fDefHeight) { - // row height: convert points to row height in 1/100 mm + // row height: convert points to row height in twips double fHeight = (rModel.mfHeight >= 0.0) ? rModel.mfHeight : fDefHeight; - sal_Int32 nHeight = getUnitConverter().scaleToMm100( fHeight, Unit::Point ); + sal_Int32 nHeight = std::round(o3tl::toTwips( fHeight, o3tl::Length::pt )); SCROW nStartRow = rRowRange.mnFirst; SCROW nEndRow = rRowRange.mnLast; SCTAB nTab = getSheetIndex(); @@ -1277,8 +1275,7 @@ void WorksheetGlobals::convertRows(OutlineLevelVec& orRowLevels, const ValueRang { /* always import the row height, ensures better layout */ ScDocument& rDoc = getScDocument(); - rDoc.SetRowHeightOnly(nStartRow, nEndRow, nTab, - o3tl::toTwips(nHeight, o3tl::Length::mm100)); + rDoc.SetRowHeightOnly(nStartRow, nEndRow, nTab, nHeight); if(rModel.mbCustomHeight) rDoc.SetManualHeight( nStartRow, nEndRow, nTab, true ); } |