From bfed58821fc3a83fec4a985087cd45fa963bed3e Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Wed, 11 Aug 2021 13:13:35 +0300 Subject: Drop convertMm100ToTwip in favor of the new o3tl::toTwips Step by step, duplicates from may go Change-Id: Id4c03ff8adc120ae06dbfdbdfb4f5ff0bb51f489 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120315 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- editeng/source/items/frmitems.cxx | 68 +++++++++++++++++++-------------------- editeng/source/items/numitem.cxx | 4 +-- editeng/source/items/paraitem.cxx | 8 ++--- editeng/source/items/textitem.cxx | 34 ++++++++------------ 4 files changed, 54 insertions(+), 60 deletions(-) (limited to 'editeng') diff --git a/editeng/source/items/frmitems.cxx b/editeng/source/items/frmitems.cxx index add9c3654f65..6aec451c8024 100644 --- a/editeng/source/items/frmitems.cxx +++ b/editeng/source/items/frmitems.cxx @@ -181,8 +181,8 @@ bool SvxSizeItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) { if(bConvert) { - aTmp.Height = convertMm100ToTwip(aTmp.Height); - aTmp.Width = convertMm100ToTwip(aTmp.Width); + aTmp.Height = o3tl::toTwips(aTmp.Height, o3tl::Length::mm100); + aTmp.Width = o3tl::toTwips(aTmp.Width, o3tl::Length::mm100); } m_aSize = Size( aTmp.Width, aTmp.Height ); } @@ -198,7 +198,7 @@ bool SvxSizeItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) if(!(rVal >>= nVal )) return false; - m_aSize.setWidth( bConvert ? convertMm100ToTwip(nVal) : nVal ); + m_aSize.setWidth( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal ); } break; case MID_SIZE_HEIGHT: @@ -207,7 +207,7 @@ bool SvxSizeItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) if(!(rVal >>= nVal)) return true; - m_aSize.setHeight( bConvert ? convertMm100ToTwip(nVal) : nVal ); + m_aSize.setHeight( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal ); } break; default: OSL_FAIL("Wrong MemberId!"); @@ -407,26 +407,26 @@ bool SvxLRSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) if(!(rVal >>= aLRSpace)) return false; - SetLeft( bConvert ? convertMm100ToTwip(aLRSpace.Left) : aLRSpace.Left ); - SetTextLeft( bConvert ? convertMm100ToTwip(aLRSpace.TextLeft) : aLRSpace.TextLeft ); - SetRight(bConvert ? convertMm100ToTwip(aLRSpace.Right) : aLRSpace.Right); + SetLeft( bConvert ? o3tl::toTwips(aLRSpace.Left, o3tl::Length::mm100) : aLRSpace.Left ); + SetTextLeft( bConvert ? o3tl::toTwips(aLRSpace.TextLeft, o3tl::Length::mm100) : aLRSpace.TextLeft ); + SetRight(bConvert ? o3tl::toTwips(aLRSpace.Right, o3tl::Length::mm100) : aLRSpace.Right); nPropLeftMargin = aLRSpace.ScaleLeft; nPropRightMargin = aLRSpace.ScaleRight; - SetTextFirstLineOffset(static_cast(bConvert ? convertMm100ToTwip(aLRSpace.FirstLine) : aLRSpace.FirstLine)); - SetPropTextFirstLineOffset ( static_cast(aLRSpace.ScaleFirstLine) ); + SetTextFirstLineOffset(bConvert ? o3tl::toTwips(aLRSpace.FirstLine, o3tl::Length::mm100) : aLRSpace.FirstLine); + SetPropTextFirstLineOffset ( aLRSpace.ScaleFirstLine ); SetAutoFirst( aLRSpace.AutoFirstLine ); break; } case MID_L_MARGIN: - SetLeft( bConvert ? convertMm100ToTwip(nVal) : nVal ); + SetLeft( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal ); break; case MID_TXT_LMARGIN : - SetTextLeft( bConvert ? convertMm100ToTwip(nVal) : nVal ); + SetTextLeft( bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal ); break; case MID_R_MARGIN: - SetRight(bConvert ? convertMm100ToTwip(nVal) : nVal); + SetRight(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal); break; case MID_L_REL_MARGIN: case MID_R_REL_MARGIN: @@ -444,11 +444,11 @@ bool SvxLRSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) } break; case MID_FIRST_LINE_INDENT : - SetTextFirstLineOffset(static_cast(bConvert ? convertMm100ToTwip(nVal) : nVal)); + SetTextFirstLineOffset(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal); break; case MID_FIRST_LINE_REL_INDENT: - SetPropTextFirstLineOffset ( static_cast(nVal) ); + SetPropTextFirstLineOffset ( nVal ); break; case MID_FIRST_AUTO: @@ -456,7 +456,7 @@ bool SvxLRSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) break; case MID_GUTTER_MARGIN: - SetGutterMargin(bConvert ? convertMm100ToTwip(nVal) : nVal); + SetGutterMargin(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal); break; default: @@ -716,8 +716,8 @@ bool SvxULSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) if ( !(rVal >>= aUpperLowerMarginScale )) return false; { - SetUpper(static_cast(bConvert ? convertMm100ToTwip( aUpperLowerMarginScale.Upper ) : aUpperLowerMarginScale.Upper)); - SetLower(static_cast(bConvert ? convertMm100ToTwip( aUpperLowerMarginScale.Lower ) : aUpperLowerMarginScale.Lower)); + SetUpper(bConvert ? o3tl::toTwips(aUpperLowerMarginScale.Upper, o3tl::Length::mm100) : aUpperLowerMarginScale.Upper); + SetLower(bConvert ? o3tl::toTwips(aUpperLowerMarginScale.Lower, o3tl::Length::mm100) : aUpperLowerMarginScale.Lower); if( aUpperLowerMarginScale.ScaleUpper > 1 ) nPropUpper = aUpperLowerMarginScale.ScaleUpper; if( aUpperLowerMarginScale.ScaleLower > 1 ) @@ -728,12 +728,12 @@ bool SvxULSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) case MID_UP_MARGIN : if(!(rVal >>= nVal)) return false; - SetUpper(static_cast(bConvert ? convertMm100ToTwip(nVal) : nVal)); + SetUpper(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal); break; case MID_LO_MARGIN : if(!(rVal >>= nVal) || nVal < 0) return false; - SetLower(static_cast(bConvert ? convertMm100ToTwip(nVal) : nVal)); + SetLower(bConvert ? o3tl::toTwips(nVal, o3tl::Length::mm100) : nVal); break; case MID_CTX_MARGIN : if (!(rVal >>= bVal)) @@ -1125,7 +1125,7 @@ bool SvxShadowItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) default: ; // prevent warning } - nWidth = bConvert ? convertMm100ToTwip(aShadow.ShadowWidth) : aShadow.ShadowWidth; + nWidth = bConvert ? o3tl::toTwips(aShadow.ShadowWidth, o3tl::Length::mm100) : aShadow.ShadowWidth; Color aSet(ColorTransparency, aShadow.Color); aShadowColor = aSet; } @@ -1462,9 +1462,9 @@ lcl_lineToSvxLine(const table::BorderLine& rLine, SvxBorderLine& rSvxLine, bool if ( bGuessWidth ) { rSvxLine.GuessLinesWidths( rSvxLine.GetBorderLineStyle(), - sal_uInt16( bConvert ? convertMm100ToTwip(rLine.OuterLineWidth) : rLine.OuterLineWidth ), - sal_uInt16( bConvert ? convertMm100ToTwip(rLine.InnerLineWidth) : rLine.InnerLineWidth ), - sal_uInt16( bConvert ? convertMm100ToTwip(rLine.LineDistance ) : rLine.LineDistance )); + bConvert ? o3tl::toTwips(rLine.OuterLineWidth, o3tl::Length::mm100) : rLine.OuterLineWidth, + bConvert ? o3tl::toTwips(rLine.InnerLineWidth, o3tl::Length::mm100) : rLine.InnerLineWidth, + bConvert ? o3tl::toTwips(rLine.LineDistance, o3tl::Length::mm100) : rLine.LineDistance ); } bool bRet = !rSvxLine.isEmpty(); @@ -1492,7 +1492,7 @@ SvxBoxItem::LineToSvxLine(const css::table::BorderLine2& rLine, SvxBorderLine& r bool bGuessWidth = true; if ( rLine.LineWidth ) { - rSvxLine.SetWidth( bConvert? convertMm100ToTwip( rLine.LineWidth ) : rLine.LineWidth ); + rSvxLine.SetWidth( bConvert? o3tl::toTwips(rLine.LineWidth, o3tl::Length::mm100) : rLine.LineWidth ); // fdo#46112: double does not necessarily mean symmetric // for backwards compatibility bGuessWidth = (SvxBorderLineStyle::DOUBLE == nStyle || SvxBorderLineStyle::DOUBLE_THIN == nStyle) && @@ -1573,11 +1573,11 @@ bool SvxBoxItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) if ( aSeq[n] >>= nDist ) { if( bConvert ) - nDist = convertMm100ToTwip(nDist); + nDist = o3tl::toTwips(nDist, o3tl::Length::mm100); if ( n == 4 ) - SetAllDistances(sal_uInt16(nDist)); + SetAllDistances(nDist); else - SetDistance( sal_uInt16( nDist ), nLines[n-5] ); + SetDistance( nDist, nLines[n-5] ); } else return false; @@ -1650,7 +1650,7 @@ bool SvxBoxItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) tools::Long nWidth(0); rVal >>= nWidth; if( bConvert ) - nWidth = convertMm100ToTwip( nWidth ); + nWidth = o3tl::toTwips(nWidth, o3tl::Length::mm100); // Set the line Width on all borders for( SvxBoxItemLine n : o3tl::enumrange() ) @@ -1672,11 +1672,11 @@ bool SvxBoxItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) if(nDist >= 0) { if( bConvert ) - nDist = convertMm100ToTwip(nDist); + nDist = o3tl::toTwips(nDist, o3tl::Length::mm100); if( nMemberId == BORDER_DISTANCE ) - SetAllDistances(sal_uInt16(nDist)); + SetAllDistances(nDist); else - SetDistance( sal_uInt16( nDist ), nLine ); + SetDistance( nDist, nLine ); } } else @@ -2294,8 +2294,8 @@ bool SvxBoxInfoItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) if (( aSeq[4] >>= nVal ) && ( nVal >= 0 )) { if( bConvert ) - nVal = convertMm100ToTwip(nVal); - SetDefDist( static_cast(nVal) ); + nVal = o3tl::toTwips(nVal, o3tl::Length::mm100); + SetDefDist( nVal ); } } return true; @@ -2411,7 +2411,7 @@ bool SvxBoxInfoItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) if ( bRet && nVal>=0 ) { if( bConvert ) - nVal = convertMm100ToTwip(nVal); + nVal = o3tl::toTwips(nVal, o3tl::Length::mm100); SetDefDist( static_cast(nVal) ); } break; diff --git a/editeng/source/items/numitem.cxx b/editeng/source/items/numitem.cxx index 12ee8dbe533d..229ac4affd2c 100644 --- a/editeng/source/items/numitem.cxx +++ b/editeng/source/items/numitem.cxx @@ -671,8 +671,8 @@ SvxNumRule::SvxNumRule( SvxNumRuleFlags nFeatures, if ( eDefaultNumberFormatPositionAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION ) { - aFmts[i]->SetAbsLSpace( convertMm100ToTwip(DEF_WRITER_LSPACE * (i+1)) ); - aFmts[i]->SetFirstLineOffset(convertMm100ToTwip(-DEF_WRITER_LSPACE)); + aFmts[i]->SetAbsLSpace(o3tl::toTwips(DEF_WRITER_LSPACE * (i+1), o3tl::Length::mm100)); + aFmts[i]->SetFirstLineOffset(o3tl::toTwips(-DEF_WRITER_LSPACE, o3tl::Length::mm100)); } else if ( eDefaultNumberFormatPositionAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT ) diff --git a/editeng/source/items/paraitem.cxx b/editeng/source/items/paraitem.cxx index 4dc508a6939f..3d097e7f040d 100644 --- a/editeng/source/items/paraitem.cxx +++ b/editeng/source/items/paraitem.cxx @@ -188,7 +188,7 @@ bool SvxLineSpacingItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) eLineSpaceRule = SvxLineSpaceRule::Auto; nInterLineSpace = aLSp.Height; if(bConvert) - nInterLineSpace = static_cast(convertMm100ToTwip(nInterLineSpace)); + nInterLineSpace = o3tl::toTwips(nInterLineSpace, o3tl::Length::mm100); } break; @@ -209,7 +209,7 @@ bool SvxLineSpacingItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) eLineSpaceRule = aLSp.Mode == style::LineSpacingMode::FIX ? SvxLineSpaceRule::Fix : SvxLineSpaceRule::Min; nLineHeight = aLSp.Height; if(bConvert) - nLineHeight = static_cast(convertMm100ToTwip(nLineHeight)); + nLineHeight = o3tl::toTwips(nLineHeight, o3tl::Length::mm100); } break; } @@ -880,7 +880,7 @@ bool SvxTabStopItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) } sal_Unicode cFill = pArr[i].FillChar; sal_Unicode cDecimal = pArr[i].DecimalChar; - SvxTabStop aTab( bConvert ? convertMm100ToTwip(pArr[i].Position) : pArr[i].Position, + SvxTabStop aTab( bConvert ? o3tl::toTwips(pArr[i].Position, o3tl::Length::mm100) : pArr[i].Position, eAdjust, cDecimal, cFill ); @@ -894,7 +894,7 @@ bool SvxTabStopItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) if (!(rVal >>= nNewPos) ) return false; if (bConvert) - nNewPos = convertMm100ToTwip ( nNewPos ); + nNewPos = o3tl::toTwips(nNewPos, o3tl::Length::mm100); if (nNewPos <= 0) return false; const SvxTabStop& rTab = maTabStops.front(); diff --git a/editeng/source/items/textitem.cxx b/editeng/source/items/textitem.cxx index 433352b4653f..64236dd542f1 100644 --- a/editeng/source/items/textitem.cxx +++ b/editeng/source/items/textitem.cxx @@ -594,33 +594,30 @@ bool SvxFontHeightItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const // CONVERT_TWIPS is not set. if( bConvert ) { - aFontHeight.Height = static_cast( nHeight / 20.0 ); + aFontHeight.Height = o3tl::convert(nHeight, o3tl::Length::twip, o3tl::Length::pt); } else { - double fPoints = convertMm100ToTwip(nHeight) / 20.0; - float fRoundPoints = - static_cast(::rtl::math::round(fPoints, 1)); - aFontHeight.Height = fRoundPoints; + double fPoints = o3tl::convert(nHeight, o3tl::Length::mm100, o3tl::Length::pt); + aFontHeight.Height = rtl::math::round(fPoints, 1); } - aFontHeight.Prop = static_cast(MapUnit::MapRelative == ePropUnit ? nProp : 100); + aFontHeight.Prop = MapUnit::MapRelative == ePropUnit ? nProp : 100; - float fRet = static_cast(static_cast(nProp)); + float fRet = nProp; switch( ePropUnit ) { case MapUnit::MapRelative: fRet = 0.; break; case MapUnit::Map100thMM: - fRet = convertMm100ToTwip(fRet); - fRet /= 20.; + fRet = o3tl::convert(fRet, o3tl::Length::mm100, o3tl::Length::pt); break; case MapUnit::MapPoint: break; case MapUnit::MapTwip: - fRet /= 20.; + fRet = o3tl::convert(fRet, o3tl::Length::twip, o3tl::Length::pt); break; default: ;//prevent warning } @@ -634,14 +631,12 @@ bool SvxFontHeightItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const // CONVERT_TWIPS is not set. if( bConvert ) { - rVal <<= static_cast( nHeight / 20.0 ); + rVal <<= static_cast(o3tl::convert(nHeight, o3tl::Length::twip, o3tl::Length::pt)); } else { - double fPoints = convertMm100ToTwip(nHeight) / 20.0; - float fRoundPoints = - static_cast(::rtl::math::round(fPoints, 1)); - rVal <<= fRoundPoints; + double fPoints = o3tl::convert(nHeight, o3tl::Length::mm100, o3tl::Length::pt); + rVal <<= static_cast(::rtl::math::round(fPoints, 1)); } } break; @@ -650,21 +645,20 @@ bool SvxFontHeightItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const break; case MID_FONTHEIGHT_DIFF: { - float fRet = static_cast(static_cast(nProp)); + float fRet = nProp; switch( ePropUnit ) { case MapUnit::MapRelative: fRet = 0.; break; case MapUnit::Map100thMM: - fRet = convertMm100ToTwip(fRet); - fRet /= 20.; + fRet = o3tl::convert(fRet, o3tl::Length::mm100, o3tl::Length::pt); break; case MapUnit::MapPoint: break; case MapUnit::MapTwip: - fRet /= 20.; + fRet = o3tl::convert(fRet, o3tl::Length::twip, o3tl::Length::pt); break; default: ;//prevent warning } @@ -1500,7 +1494,7 @@ bool SvxKerningItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId) if(!(rVal >>= nVal)) return false; if(nMemberId & CONVERT_TWIPS) - nVal = static_cast(convertMm100ToTwip(nVal)); + nVal = o3tl::toTwips(nVal, o3tl::Length::mm100); SetValue(nVal); return true; } -- cgit