diff options
31 files changed, 155 insertions, 165 deletions
diff --git a/editeng/source/uno/unoipset.cxx b/editeng/source/uno/unoipset.cxx index 417e62d771e0..fc70a623d0ef 100644 --- a/editeng/source/uno/unoipset.cxx +++ b/editeng/source/uno/unoipset.cxx @@ -19,7 +19,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <svl/itemprop.hxx> -#include <tools/helpers.hxx> +#include <tools/UnitConversion.hxx> #include <editeng/unoipset.hxx> #include <svl/itempool.hxx> #include <svl/solar.hrc> @@ -271,19 +271,19 @@ void SvxUnoConvertToMM( const MapUnit eSourceMapUnit, uno::Any & rMetric ) throw switch( rMetric.getValueTypeClass() ) { case uno::TypeClass_BYTE: - rMetric <<= static_cast<sal_Int8>(TwipsToHMM(*o3tl::forceAccess<sal_Int8>(rMetric))); + rMetric <<= static_cast<sal_Int8>(convertTwipToMm100(*o3tl::forceAccess<sal_Int8>(rMetric))); break; case uno::TypeClass_SHORT: - rMetric <<= static_cast<sal_Int16>(TwipsToHMM(*o3tl::forceAccess<sal_Int16>(rMetric))); + rMetric <<= static_cast<sal_Int16>(convertTwipToMm100(*o3tl::forceAccess<sal_Int16>(rMetric))); break; case uno::TypeClass_UNSIGNED_SHORT: - rMetric <<= static_cast<sal_uInt16>(TwipsToHMM(*o3tl::forceAccess<sal_uInt16>(rMetric))); + rMetric <<= static_cast<sal_uInt16>(convertTwipToMm100(*o3tl::forceAccess<sal_uInt16>(rMetric))); break; case uno::TypeClass_LONG: - rMetric <<= static_cast<sal_Int32>(TwipsToHMM(*o3tl::forceAccess<sal_Int32>(rMetric))); + rMetric <<= static_cast<sal_Int32>(convertTwipToMm100(*o3tl::forceAccess<sal_Int32>(rMetric))); break; case uno::TypeClass_UNSIGNED_LONG: - rMetric <<= static_cast<sal_uInt32>(TwipsToHMM(*o3tl::forceAccess<sal_uInt32>(rMetric))); + rMetric <<= static_cast<sal_uInt32>(convertTwipToMm100(*o3tl::forceAccess<sal_uInt32>(rMetric))); break; default: SAL_WARN("editeng", "AW: Missing unit translation to 100th mm, " << OString::number(static_cast<sal_Int32>(rMetric.getValueTypeClass()))); diff --git a/include/tools/UnitConversion.hxx b/include/tools/UnitConversion.hxx index e78ef315b432..57f8e39119f0 100644 --- a/include/tools/UnitConversion.hxx +++ b/include/tools/UnitConversion.hxx @@ -11,17 +11,32 @@ #pragma once #include <sal/types.h> +#include <cassert> +#include <limits> constexpr sal_Int64 convertTwipToMm100(sal_Int64 n) { + 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; } constexpr sal_Int64 convertMm100ToTwip(sal_Int64 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; } +constexpr sal_Int64 sanitiseMm100ToTwip(sal_Int64 n) +{ + 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); +} + constexpr sal_Int64 convertPointToTwip(sal_Int64 nNumber) { return nNumber * 20; } constexpr sal_Int64 convertPointToMm100(sal_Int64 nNumber) diff --git a/include/tools/helpers.hxx b/include/tools/helpers.hxx index 381ecb206d18..abce49b3d469 100644 --- a/include/tools/helpers.hxx +++ b/include/tools/helpers.hxx @@ -98,38 +98,4 @@ template <typename T> [[nodiscard]] inline T NormAngle360(T angle) return angle; } -/** Convert 100th-mm to twips - - A twip is 1/20 of a point, one inch is equal to 72 points, and - one inch is 2,540 100th-mm. - - Thus: - twips = n * 72 / 2,540 / 20 - = n * 72 / 127 - - Adding 63 (half of 127) fixes truncation issues in int arithmetic. - - This formula is (n>=0) ? (n*72+63) / 127 : (n*72-63) / 127 - */ -inline sal_Int64 sanitiseMm100ToTwip(sal_Int64 n) -{ - if (n >= 0) - { - if (o3tl::checked_multiply<sal_Int64>(n, 72, n) || o3tl::checked_add<sal_Int64>(n, 63, n)) - n = SAL_MAX_INT64; - } - else - { - if (o3tl::checked_multiply<sal_Int64>(n, 72, n) || o3tl::checked_sub<sal_Int64>(n, 63, n)) - n = SAL_MIN_INT64; - } - return n / 127; // 127 is 2,540 100th-mm divided by 20pts -} - -/** -* Convert Twips <-> 100th-mm -*/ -inline constexpr sal_Int64 TwipsToHMM(sal_Int64 nTwips) { return (nTwips * 127 + 36) / 72; } -inline constexpr sal_Int64 HMMToTwips(sal_Int64 nHMM) { return (nHMM * 72 + 63) / 127; } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/textparagraphpropertiescontext.cxx b/oox/source/drawingml/textparagraphpropertiescontext.cxx index 6aa8fef0cd04..e7e77da8564f 100644 --- a/oox/source/drawingml/textparagraphpropertiescontext.cxx +++ b/oox/source/drawingml/textparagraphpropertiescontext.cxx @@ -29,6 +29,7 @@ #include <svx/unopage.hxx> #include <sal/log.hxx> #include <tools/diagnose_ex.h> +#include <tools/UnitConversion.hxx> #include <drawingml/colorchoicecontext.hxx> #include <drawingml/misccontexts.hxx> @@ -305,7 +306,7 @@ ContextHandlerRef TextParagraphPropertiesContext::onCreateContext( sal_Int32 aEl { TextSpacing& rSpacing = mrTextParagraphProperties.getParaTopMargin(); rSpacing.nUnit = TextSpacing::Unit::Points; - rSpacing.nValue = TwipsToHMM(oBefore.get()); + rSpacing.nValue = convertTwipToMm100(oBefore.get()); rSpacing.bHasValue = true; } else @@ -329,7 +330,7 @@ ContextHandlerRef TextParagraphPropertiesContext::onCreateContext( sal_Int32 aEl { TextSpacing& rSpacing = mrTextParagraphProperties.getParaBottomMargin(); rSpacing.nUnit = TextSpacing::Unit::Points; - rSpacing.nValue = TwipsToHMM(oAfter.get()); + rSpacing.nValue = convertTwipToMm100(oAfter.get()); rSpacing.bHasValue = true; } else @@ -359,7 +360,7 @@ ContextHandlerRef TextParagraphPropertiesContext::onCreateContext( sal_Int32 aEl else { rLineSpacing.nUnit = TextSpacing::Unit::Points; - rLineSpacing.nValue = TwipsToHMM(oLineSpacing.get()); + rLineSpacing.nValue = convertTwipToMm100(oLineSpacing.get()); } rLineSpacing.bHasValue = true; } diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx index aa691d53a754..ed13b7058786 100644 --- a/sc/qa/unit/helper/qahelper.cxx +++ b/sc/qa/unit/helper/qahelper.cxx @@ -19,6 +19,7 @@ #include <formulacell.hxx> #include <svx/svdpage.hxx> #include <svx/svdoole2.hxx> +#include <tools/UnitConversion.hxx> #include <tools/urlobj.hxx> #include <editeng/brushitem.hxx> #include <editeng/justifyitem.hxx> @@ -797,12 +798,12 @@ void ScBootstrapFixture::miscRowHeightsTest( TestParam const * aTestValues, unsi SCTAB nTab = aTestValues[ index ].pData[ i ].nTab; int nExpectedHeight = aTestValues[ index ].pData[ i ].nExpectedHeight; if ( nExpectedHeight == -1 ) - nExpectedHeight = TwipsToHMM( ScGlobal::GetStandardRowHeight() ); + nExpectedHeight = convertTwipToMm100(ScGlobal::GetStandardRowHeight()); bool bCheckOpt = ( ( aTestValues[ index ].pData[ i ].nCheck & CHECK_OPTIMAL ) == CHECK_OPTIMAL ); for ( ; nRow <= nEndRow; ++nRow ) { SAL_INFO( "sc.qa", " checking row " << nRow << " for height " << nExpectedHeight ); - int nHeight = TwipsToHMM( rDoc.GetRowHeight(nRow, nTab, false) ); + int nHeight = convertTwipToMm100(rDoc.GetRowHeight(nRow, nTab, false)); if ( bCheckOpt ) { bool bOpt = !(rDoc.GetRowFlags( nRow, nTab ) & CRFlags::ManualSize); diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index a8e62602713b..75d6e806f950 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -81,6 +81,7 @@ #include <com/sun/star/text/textfield/Type.hpp> #include <comphelper/scopeguard.hxx> +#include <tools/UnitConversion.hxx> #include <unotools/syslocaleoptions.hxx> #include "helper/qahelper.hxx" #include "helper/shared_test_impl.hxx" @@ -3093,7 +3094,7 @@ void ScFiltersTest::testOptimalHeightReset() ScDocument& rDoc = xDocSh->GetDocument(); // open document in read/write mode ( otherwise optimal height stuff won't // be triggered ) *and* you can't delete cell contents. - int nHeight = TwipsToHMM ( rDoc.GetRowHeight(nRow, nTab, false) ); + int nHeight = convertTwipToMm100(rDoc.GetRowHeight(nRow, nTab, false)); CPPUNIT_ASSERT_EQUAL(1236, nHeight); ScDocFunc &rFunc = xDocSh->GetDocFunc(); @@ -3106,14 +3107,14 @@ void ScFiltersTest::testOptimalHeightReset() CPPUNIT_ASSERT_MESSAGE("DeleteContents failed", bRet); // get the new height of A1 - nHeight = TwipsToHMM( rDoc.GetRowHeight(nRow, nTab, false) ); + nHeight = convertTwipToMm100(rDoc.GetRowHeight(nRow, nTab, false)); // set optimal height for empty row 2 std::vector<sc::ColRowSpan> aRowArr(1, sc::ColRowSpan(2,2)); rFunc.SetWidthOrHeight(false, aRowArr, nTab, SC_SIZE_OPTIMAL, 0, true, true); // retrieve optimal height - int nOptimalHeight = TwipsToHMM( rDoc.GetRowHeight(aRowArr[0].mnStart, nTab, false) ); + int nOptimalHeight = convertTwipToMm100(rDoc.GetRowHeight(aRowArr[0].mnStart, nTab, false)); // check if the new height of A1 ( after delete ) is now the optimal height of an empty cell CPPUNIT_ASSERT_EQUAL(nOptimalHeight, nHeight ); diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 28533ea54e43..25b276fe7b87 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -84,6 +84,7 @@ #include <svx/svdocapt.hxx> #include <svl/srchitem.hxx> #include <svl/sharedstringpool.hxx> +#include <tools/UnitConversion.hxx> #include <unotools/collatorwrapper.hxx> #include <sfx2/docfile.hxx> @@ -5703,10 +5704,10 @@ void Test::testAnchoredRotatedShape() CPPUNIT_ASSERT_MESSAGE("must have a draw layer", pDrawLayer != nullptr); SdrPage* pPage = pDrawLayer->GetPage(0); CPPUNIT_ASSERT_MESSAGE("must have a draw page", pPage != nullptr); - m_pDoc->SetRowHeightRange( 0, MAXROW, 0, HMMToTwips( 1000 ) ); + m_pDoc->SetRowHeightRange(0, MAXROW, 0, convertMm100ToTwip(1000)); constexpr tools::Long TOLERANCE = 30; //30 hmm for ( SCCOL nCol = 0; nCol < MAXCOL; ++nCol ) - m_pDoc->SetColWidth( nCol, 0, HMMToTwips( 1000 ) ); + m_pDoc->SetColWidth(nCol, 0, convertMm100ToTwip(1000)); { //Add a rect tools::Rectangle aRect( 4000, 5000, 10000, 7000 ); @@ -5738,9 +5739,9 @@ void Test::testAnchoredRotatedShape() m_pDoc->SetDrawPageSize(0); // increase row 5 by 2000 hmm - m_pDoc->SetRowHeight( 5, 0, HMMToTwips( 3000 ) ); + m_pDoc->SetRowHeight(5, 0, convertMm100ToTwip(3000)); // increase col 6 by 1000 hmm - m_pDoc->SetColWidth( 6, 0, HMMToTwips( 2000 ) ); + m_pDoc->SetColWidth(6, 0, convertMm100ToTwip(2000)); aRotRect.setWidth( aRotRect.GetWidth() + 1000 ); aRotRect.setHeight( aRotRect.GetHeight() + 2000 ); diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx index 6142cc35fb60..63d4cb8518d2 100644 --- a/sc/source/core/data/drwlayer.cxx +++ b/sc/source/core/data/drwlayer.cxx @@ -52,6 +52,7 @@ #include <vcl/svapp.hxx> #include <vcl/settings.hxx> #include <tools/globname.hxx> +#include <tools/UnitConversion.hxx> #include <basegfx/polygon/b2dpolygon.hxx> #include <basegfx/polygon/b2dpolygontools.hxx> @@ -207,10 +208,10 @@ ScTabSizeChangedHint::~ScTabSizeChangedHint() static void lcl_ReverseTwipsToMM( tools::Rectangle& rRect ) { - rRect.SetLeft( HMMToTwips( rRect.Left() ) ); - rRect.SetRight( HMMToTwips( rRect.Right() ) ); - rRect.SetTop( HMMToTwips( rRect.Top()) ); - rRect.SetBottom( HMMToTwips(rRect.Bottom()) ); + rRect.SetLeft(convertMm100ToTwip(rRect.Left())); + rRect.SetRight(convertMm100ToTwip(rRect.Right())); + rRect.SetTop(convertMm100ToTwip(rRect.Top())); + rRect.SetBottom(convertMm100ToTwip(rRect.Bottom())); } static ScRange lcl_getClipRangeFromClipDoc(ScDocument* pClipDoc, SCTAB nClipTab) @@ -753,8 +754,8 @@ void ScDrawLayer::ResizeLastRectFromAnchor(const SdrObject* pObj, ScDrawObjData& SCTAB nTab2 = rData.maEnd.Tab(); Point aPos(pDoc->GetColOffset(nCol1, nTab1, /*bHiddenAsZero*/true), pDoc->GetRowOffset(nRow1, nTab1, /*bHiddenAsZero*/true)); - aPos.setX(TwipsToHMM(aPos.X())); - aPos.setY(TwipsToHMM(aPos.Y())); + aPos.setX(convertTwipToMm100(aPos.X())); + aPos.setY(convertTwipToMm100(aPos.Y())); aPos += lcl_calcAvailableDiff(*pDoc, nCol1, nRow1, nTab1, rData.maStartOffset); // this sets the needed changed position (translation) @@ -773,8 +774,8 @@ void ScDrawLayer::ResizeLastRectFromAnchor(const SdrObject* pObj, ScDrawObjData& { Point aEnd(pDoc->GetColOffset(nCol2, nTab2, /*bHiddenAsZero*/true), pDoc->GetRowOffset(nRow2, nTab2, /*bHiddenAsZero*/true)); - aEnd.setX(TwipsToHMM(aEnd.X())); - aEnd.setY(TwipsToHMM(aEnd.Y())); + aEnd.setX(convertTwipToMm100(aEnd.X())); + aEnd.setY(convertTwipToMm100(aEnd.Y())); aEnd += lcl_calcAvailableDiff(*pDoc, nCol2, nRow2, nTab2, rData.maEndOffset); aRect = tools::Rectangle(aPos, aEnd); @@ -1083,8 +1084,8 @@ void ScDrawLayer::RecalcPos( SdrObject* pObj, ScDrawObjData& rData, bool bNegati aPos.AdjustX(pDoc->GetColWidth( nCol1, nTab1 ) / 4 ); if (!pDoc->RowHidden(nRow1, nTab1, nullptr, &nLastRow)) aPos.AdjustY(pDoc->GetRowHeight( nRow1, nTab1 ) / 2 ); - aPos.setX(TwipsToHMM( aPos.X() )); - aPos.setY(TwipsToHMM( aPos.Y() )); + aPos.setX(convertTwipToMm100(aPos.X())); + aPos.setY(convertTwipToMm100(aPos.Y())); Point aStartPos = aPos; if ( bNegativePage ) aStartPos.setX( -aStartPos.X() ); // don't modify aPos - used below @@ -1121,8 +1122,8 @@ void ScDrawLayer::RecalcPos( SdrObject* pObj, ScDrawObjData& rData, bool bNegati aPos.AdjustX(pDoc->GetColWidth( nCol2, nTab2 ) / 4 ); if (!pDoc->RowHidden(nRow2, nTab2, nullptr, &nLastRow)) aPos.AdjustY(pDoc->GetRowHeight( nRow2, nTab2 ) / 2 ); - aPos.setX(TwipsToHMM( aPos.X() )); - aPos.setY(TwipsToHMM( aPos.Y() )); + aPos.setX(convertTwipToMm100(aPos.X())); + aPos.setY(convertTwipToMm100(aPos.Y())); Point aEndPos = aPos; if ( bNegativePage ) aEndPos.setX( -aEndPos.X() ); // don't modify aPos - used below @@ -1268,16 +1269,16 @@ bool ScDrawLayer::GetPrintArea( ScRange& rRange, bool bSetHor, bool bSetVer ) co SCCOL nEndCol = rRange.aEnd.Col(); for (i=nStartCol; i<=nEndCol; i++) nEndX += pDoc->GetColWidth(i,nTab); - nStartX = TwipsToHMM( nStartX ); - nEndX = TwipsToHMM( nEndX ); + nStartX = convertTwipToMm100(nStartX); + nEndX = convertTwipToMm100(nEndX); } if (!bSetVer) { nStartY = pDoc->GetRowHeight( 0, rRange.aStart.Row()-1, nTab); nEndY = nStartY + pDoc->GetRowHeight( rRange.aStart.Row(), rRange.aEnd.Row(), nTab); - nStartY = TwipsToHMM( nStartY ); - nEndY = TwipsToHMM( nEndY ); + nStartY = convertTwipToMm100(nStartY); + nEndY = convertTwipToMm100(nEndY); } if ( bNegativePage ) @@ -1336,8 +1337,8 @@ bool ScDrawLayer::GetPrintArea( ScRange& rRange, bool bSetHor, bool bSetVer ) co if (bSetHor) { - nStartX = HMMToTwips( nStartX ); - nEndX = HMMToTwips( nEndX ); + nStartX = convertMm100ToTwip(nStartX); + nEndX = convertMm100ToTwip(nEndX); tools::Long nWidth; nWidth = 0; @@ -1373,8 +1374,8 @@ bool ScDrawLayer::GetPrintArea( ScRange& rRange, bool bSetHor, bool bSetVer ) co if (bSetVer) { - nStartY = HMMToTwips( nStartY ); - nEndY = HMMToTwips( nEndY ); + nStartY = convertMm100ToTwip(nStartY); + nEndY = convertMm100ToTwip(nEndY); SCROW nRow = pDoc->GetRowForHeight( nTab, nStartY); rRange.aStart.SetRow( nRow>0 ? (nRow-1) : 0); nRow = pDoc->GetRowForHeight( nTab, nEndY); @@ -1495,10 +1496,10 @@ bool ScDrawLayer::HasObjectsInRows( SCTAB nTab, SCROW nStartRow, SCROW nEndRow ) { aTestRect.SetBottom( aTestRect.Top() ); aTestRect.AdjustBottom(pDoc->GetRowHeight( nStartRow, nEndRow, nTab) ); - aTestRect.SetBottom(TwipsToHMM( aTestRect.Bottom() )); + aTestRect.SetBottom(convertTwipToMm100(aTestRect.Bottom())); } - aTestRect.SetTop(TwipsToHMM( aTestRect.Top() )); + aTestRect.SetTop(convertTwipToMm100(aTestRect.Top())); aTestRect.SetLeft( 0 ); aTestRect.SetRight( MAXMM ); diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx index 8db02dcda632..548eb6ef1f91 100644 --- a/sc/source/core/data/patattr.cxx +++ b/sc/source/core/data/patattr.cxx @@ -49,7 +49,7 @@ #include <svl/zforlist.hxx> #include <vcl/outdev.hxx> #include <tools/fract.hxx> -#include <tools/helpers.hxx> +#include <tools/UnitConversion.hxx> #include <osl/diagnose.h> #include <attrib.hxx> @@ -710,9 +710,9 @@ void ScPatternAttr::FillToEditItemSet( SfxItemSet& rEditSet, const SfxItemSet& r // Expect to be compatible to LogicToLogic, ie. 2540/1440 = 127/72, and round - tools::Long nHeight = TwipsToHMM(nTHeight); - tools::Long nCjkHeight = TwipsToHMM(nCjkTHeight); - tools::Long nCtlHeight = TwipsToHMM(nCtlTHeight); + tools::Long nHeight = convertTwipToMm100(nTHeight); + tools::Long nCjkHeight = convertTwipToMm100(nCjkTHeight); + tools::Long nCtlHeight = convertTwipToMm100(nCtlTHeight); // put items into EditEngine ItemSet @@ -792,13 +792,13 @@ void ScPatternAttr::GetFromEditItemSet( SfxItemSet& rDestSet, const SfxItemSet& rDestSet.Put( *static_cast<const SvxFontItem*>(pItem), ATTR_CTL_FONT ); if (rEditSet.GetItemState(EE_CHAR_FONTHEIGHT,true,&pItem) == SfxItemState::SET) - rDestSet.Put( SvxFontHeightItem( HMMToTwips( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() ), + rDestSet.Put( SvxFontHeightItem( convertMm100ToTwip( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() ), 100, ATTR_FONT_HEIGHT ) ); if (rEditSet.GetItemState(EE_CHAR_FONTHEIGHT_CJK,true,&pItem) == SfxItemState::SET) - rDestSet.Put( SvxFontHeightItem( HMMToTwips( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() ), + rDestSet.Put( SvxFontHeightItem( convertMm100ToTwip( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() ), 100, ATTR_CJK_FONT_HEIGHT ) ); if (rEditSet.GetItemState(EE_CHAR_FONTHEIGHT_CTL,true,&pItem) == SfxItemState::SET) - rDestSet.Put( SvxFontHeightItem( HMMToTwips( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() ), + rDestSet.Put( SvxFontHeightItem( convertMm100ToTwip( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() ), 100, ATTR_CTL_FONT_HEIGHT ) ); if (rEditSet.GetItemState(EE_CHAR_WEIGHT,true,&pItem) == SfxItemState::SET) diff --git a/sc/source/core/tool/docoptio.cxx b/sc/source/core/tool/docoptio.cxx index d70d2eb80d1f..631581375bce 100644 --- a/sc/source/core/tool/docoptio.cxx +++ b/sc/source/core/tool/docoptio.cxx @@ -18,7 +18,7 @@ */ #include <svl/zforlist.hxx> -#include <tools/helpers.hxx> +#include <tools/UnitConversion.hxx> #include <osl/diagnose.h> #include <com/sun/star/uno/Any.hxx> @@ -272,7 +272,7 @@ ScDocCfg::ScDocCfg() : case SCDOCLAYOUTOPT_TABSTOP: // TabDistance in ScDocOptions is in twips if (pValues[nProp] >>= nIntVal) - SetTabDistance( static_cast<sal_uInt16>(HMMToTwips( nIntVal )) ); + SetTabDistance(static_cast<sal_uInt16>(convertMm100ToTwip(nIntVal))); break; } } diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx index 6596ea369060..32b6f4220370 100644 --- a/sc/source/filter/excel/xetable.cxx +++ b/sc/source/filter/excel/xetable.cxx @@ -25,7 +25,7 @@ #include <scitems.hxx> #include <svl/intitem.hxx> #include <svl/stritem.hxx> -#include <tools/helpers.hxx> +#include <tools/UnitConversion.hxx> #include <editeng/flditem.hxx> #include <document.hxx> #include <dociter.hxx> @@ -1632,7 +1632,7 @@ XclExpColinfo::XclExpColinfo( const XclExpRoot& rRoot, // column width. If column is hidden then we should return real value (not zero) sal_uInt16 nScWidth = rDoc.GetColWidth( nScCol, nScTab, false ); mnWidth = XclTools::GetXclColumnWidth( nScWidth, GetCharWidth() ); - mnScWidth = TwipsToHMM( nScWidth ); + mnScWidth = convertTwipToMm100(nScWidth); // column flags ::set_flag( mnFlags, EXC_COLINFO_HIDDEN, rDoc.ColHidden(nScCol, nScTab) ); @@ -1689,7 +1689,7 @@ void XclExpColinfo::WriteBody( XclExpStream& rStrm ) void XclExpColinfo::SaveXml( XclExpXmlStream& rStrm ) { - const double nExcelColumnWidth = mnScWidth / static_cast< double >( TwipsToHMM( GetCharWidth() ) ); + const double nExcelColumnWidth = mnScWidth / static_cast< double >( convertTwipToMm100( GetCharWidth() ) ); // tdf#101363 In MS specification the output value is set with double precision after delimiter: // =Truncate(({width in pixels} - 5)/{Maximum Digit Width} * 100 + 0.5)/100 diff --git a/sc/source/filter/excel/xistyle.cxx b/sc/source/filter/excel/xistyle.cxx index e92e868afca5..995219fc710a 100644 --- a/sc/source/filter/excel/xistyle.cxx +++ b/sc/source/filter/excel/xistyle.cxx @@ -46,6 +46,7 @@ #include <editeng/editids.hrc> #include <sal/macros.h> #include <sal/log.hxx> +#include <tools/UnitConversion.hxx> #include <vcl/fontcharmap.hxx> #include <vcl/outdev.hxx> #include <document.hxx> @@ -355,7 +356,7 @@ void XclImpFont::FillToItemSet( SfxItemSet& rItemSet, XclFontItemType eType, boo { sal_Int32 nHeight = maData.mnHeight; if( bEE && (eType != XclFontItemType::HeaderFooter) ) // do not convert header/footer height - nHeight = (nHeight * 127 + 36) / EXC_POINTS_PER_INCH; // 1 in == 72 pt + nHeight = convertTwipToMm100(nHeight); SvxFontHeightItem aHeightItem( nHeight, 100, ATTR_FONT_HEIGHT ); PUTITEM( aHeightItem, ATTR_FONT_HEIGHT, EE_CHAR_FONTHEIGHT ); diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx index 153948cd0422..7834d5e5a058 100644 --- a/sc/source/filter/oox/stylesbuffer.cxx +++ b/sc/source/filter/oox/stylesbuffer.cxx @@ -55,6 +55,7 @@ #include <editeng/brushitem.hxx> #include <svx/rotmodit.hxx> #include <tools/fontenum.hxx> +#include <tools/UnitConversion.hxx> #include <vcl/unohelp.hxx> #include <rtl/tencinfo.h> #include <rtl/ustrbuf.hxx> @@ -902,7 +903,7 @@ void Font::fillToItemSet( SfxItemSet& rItemSet, bool bEditEngineText, bool bSkip sal_Int32 nHeight = maApiData.maDesc.Height; // do we use XclFontItemType::HeaderFooter ( or is it just relevant for the binary filter ) if( bEditEngineText/* && (eType != XclFontItemType::HeaderFooter) */) // do not convert header/footer height - nHeight = (nHeight * 127 + 36) / EXC_POINTS_PER_INCH; // 1 in == 72 pt + nHeight = convertTwipToMm100(nHeight); SvxFontHeightItem aHeightItem( nHeight, 100, ATTR_FONT_HEIGHT ); ScfTools::PutItem( rItemSet, aHeightItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_FONTHEIGHT) : ATTR_FONT_HEIGHT, bSkipPoolDefs ); ScfTools::PutItem( rItemSet, aHeightItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_FONTHEIGHT_CJK) : ATTR_CJK_FONT_HEIGHT, bSkipPoolDefs ); diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx index 737a9a432709..fe30d788b623 100644 --- a/sc/source/filter/oox/worksheethelper.cxx +++ b/sc/source/filter/oox/worksheethelper.cxx @@ -73,7 +73,7 @@ #include <editeng/eeitem.hxx> #include <editeng/editobj.hxx> #include <editeng/flditem.hxx> -#include <tools/helpers.hxx> +#include <tools/UnitConversion.hxx> namespace oox::xls { @@ -1187,7 +1187,7 @@ void WorksheetGlobals::convertColumns( OutlineLevelVec& orColLevels, { for( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol ) { - rDoc.SetColWidthOnly( nCol, nTab, static_cast<sal_uInt16>(HMMToTwips( nWidth )) ); + rDoc.SetColWidthOnly(nCol, nTab, static_cast<sal_uInt16>(convertMm100ToTwip(nWidth))); } } @@ -1240,7 +1240,8 @@ void WorksheetGlobals::convertRows( OutlineLevelVec& orRowLevels, { /* always import the row height, ensures better layout */ ScDocument& rDoc = getScDocument(); - rDoc.SetRowHeightOnly( nStartRow, nEndRow, nTab, static_cast<sal_uInt16>(HMMToTwips(nHeight)) ); + rDoc.SetRowHeightOnly(nStartRow, nEndRow, nTab, + static_cast<sal_uInt16>(convertMm100ToTwip(nHeight))); if(rModel.mbCustomHeight) rDoc.SetManualHeight( nStartRow, nEndRow, nTab, true ); } diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index f332a27d1b93..5f22480879e3 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -44,7 +44,7 @@ #include <cppuhelper/supportsservice.hxx> #include <float.h> #include <tools/diagnose_ex.h> -#include <tools/helpers.hxx> +#include <tools/UnitConversion.hxx> #include <com/sun/star/awt/XBitmap.hpp> #include <com/sun/star/util/CellProtection.hpp> @@ -968,7 +968,7 @@ template<typename TableBorderType> void lcl_fillBoxItems( SvxBoxItem& rOuter, SvxBoxInfoItem& rInner, const TableBorderType& rBorder ) { ::editeng::SvxBorderLine aLine; - rOuter.SetAllDistances(static_cast<sal_uInt16>(HMMToTwips(rBorder.Distance))); + rOuter.SetAllDistances(static_cast<sal_uInt16>(convertMm100ToTwip(rBorder.Distance))); rOuter.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.TopLine ), SvxBoxItemLine::TOP ); rOuter.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.BottomLine ), SvxBoxItemLine::BOTTOM ); rOuter.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.LeftLine ), SvxBoxItemLine::LEFT ); @@ -1954,7 +1954,7 @@ uno::Any SAL_CALL ScCellRangesBase::getPropertyDefault( const OUString& aPropert aAny <<= static_cast<sal_Int32>( static_cast<const SfxUInt32Item&>(rSet.Get(pEntry->nWID)).GetValue() ); break; case ATTR_INDENT: - aAny <<= static_cast<sal_Int16>( TwipsToHMM(static_cast<const ScIndentItem&>( + aAny <<= static_cast<sal_Int16>( convertTwipToMm100(static_cast<const ScIndentItem&>( rSet.Get(pEntry->nWID)).GetValue()) ); break; default: @@ -2092,7 +2092,7 @@ static void lcl_SetCellProperty( const SfxItemPropertySimpleEntry& rEntry, const if ( !(rValue >>= nIntVal) ) throw lang::IllegalArgumentException(); - rSet.Put( ScIndentItem( static_cast<sal_uInt16>(HMMToTwips(nIntVal)) ) ); + rSet.Put(ScIndentItem(static_cast<sal_uInt16>(convertMm100ToTwip(nIntVal)))); } break; @@ -2405,7 +2405,7 @@ void ScCellRangesBase::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pE } break; case ATTR_INDENT: - rAny <<= static_cast<sal_Int16>( TwipsToHMM(static_cast<const ScIndentItem&>( + rAny <<= static_cast<sal_Int16>( convertTwipToMm100(static_cast<const ScIndentItem&>( pDataSet->Get(pEntry->nWID)).GetValue()) ); break; case ATTR_STACKED: @@ -8412,7 +8412,7 @@ void ScTableColumnObj::SetOnePropertyValue(const SfxItemPropertySimpleEntry* pEn if ( aValue >>= nNewWidth ) { // property is 1/100mm, column width is twips - nNewWidth = HMMToTwips(nNewWidth); + nNewWidth = convertMm100ToTwip(nNewWidth); rFunc.SetWidthOrHeight( true, aColArr, nTab, SC_SIZE_ORIGINAL, static_cast<sal_uInt16>(nNewWidth), true, true); } @@ -8464,7 +8464,7 @@ void ScTableColumnObj::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pE // for hidden column, return original height sal_uInt16 nWidth = rDoc.GetOriginalWidth( nCol, nTab ); // property is 1/100mm, column width is twips - nWidth = static_cast<sal_uInt16>(TwipsToHMM(nWidth)); + nWidth = static_cast<sal_uInt16>(convertTwipToMm100(nWidth)); rAny <<= static_cast<sal_Int32>(nWidth); } else if ( pEntry->nWID == SC_WID_UNO_CELLVIS ) @@ -8549,7 +8549,7 @@ void ScTableRowObj::SetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntr if ( aValue >>= nNewHeight ) { // property is 1/100mm, row height is twips - nNewHeight = HMMToTwips(nNewHeight); + nNewHeight = convertMm100ToTwip(nNewHeight); rFunc.SetWidthOrHeight( false, aRowArr, nTab, SC_SIZE_ORIGINAL, static_cast<sal_uInt16>(nNewHeight), true, true); } @@ -8610,7 +8610,7 @@ void ScTableRowObj::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pEntr // for hidden row, return original height sal_uInt16 nHeight = rDoc.GetOriginalHeight( nRow, nTab ); // property is 1/100mm, row height is twips - nHeight = static_cast<sal_uInt16>(TwipsToHMM(nHeight)); + nHeight = static_cast<sal_uInt16>(convertTwipToMm100(nHeight)); rAny <<= static_cast<sal_Int32>(nHeight); } else if ( pEntry->nWID == SC_WID_UNO_CELLVIS ) diff --git a/sc/source/ui/unoobj/defltuno.cxx b/sc/source/ui/unoobj/defltuno.cxx index 923178244dbc..22a98d6bd3eb 100644 --- a/sc/source/ui/unoobj/defltuno.cxx +++ b/sc/source/ui/unoobj/defltuno.cxx @@ -20,7 +20,7 @@ #include <editeng/memberids.h> #include <svl/hint.hxx> #include <svl/itemprop.hxx> -#include <tools/helpers.hxx> +#include <tools/UnitConversion.hxx> #include <vcl/svapp.hxx> #include <i18nlangtag/languagetag.hxx> @@ -144,7 +144,7 @@ void SAL_CALL ScDocDefaultsObj::setPropertyValue( sal_Int32 nValue = 0; if (aValue >>= nValue) { - aDocOpt.SetTabDistance(static_cast<sal_uInt16>(HMMToTwips(nValue))); + aDocOpt.SetTabDistance(static_cast<sal_uInt16>(convertMm100ToTwip(nValue))); rDoc.SetDocOptions(aDocOpt); } } diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 47d1e1f85bf2..6af98b387a1b 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -1799,8 +1799,8 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 SCTAB const nCurTab = 0; //! use current sheet from view? ScPrintFunc aDefaultFunc( pDocShell, pDocShell->GetPrinter(), nCurTab ); Size aTwips = aDefaultFunc.GetPageSize(); - aPageSize.Width = TwipsToHMM( aTwips.Width()); - aPageSize.Height = TwipsToHMM( aTwips.Height()); + aPageSize.Width = convertTwipToMm100(aTwips.Width()); + aPageSize.Height = convertTwipToMm100(aTwips.Height()); } uno::Sequence<beans::PropertyValue> aSequence( comphelper::InitPropertySequence({ @@ -1946,8 +1946,8 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 pPrintFunc->GetPrintState(*m_pPrintState, true); } - aPageSize.Width = TwipsToHMM( aTwips.Width()); - aPageSize.Height = TwipsToHMM( aTwips.Height()); + aPageSize.Width = convertTwipToMm100(aTwips.Width()); + aPageSize.Height = convertTwipToMm100(aTwips.Height()); } tools::Long nPropCount = bWasCellRange ? 5 : 4; @@ -4103,7 +4103,7 @@ void SAL_CALL ScTableColumnsObj::setPropertyValue( sal_Int32 nNewWidth = 0; if ( aValue >>= nNewWidth ) rFunc.SetWidthOrHeight( - true, aColArr, nTab, SC_SIZE_ORIGINAL, static_cast<sal_uInt16>(HMMToTwips(nNewWidth)), true, true); + true, aColArr, nTab, SC_SIZE_ORIGINAL, static_cast<sal_uInt16>(convertMm100ToTwip(nNewWidth)), true, true); } else if ( aPropertyName == SC_UNONAME_CELLVIS ) { @@ -4147,7 +4147,7 @@ uno::Any SAL_CALL ScTableColumnsObj::getPropertyValue( const OUString& aProperty { // for hidden column, return original height sal_uInt16 nWidth = rDoc.GetOriginalWidth( nStartCol, nTab ); - aAny <<= static_cast<sal_Int32>(TwipsToHMM(nWidth)); + aAny <<= static_cast<sal_Int32>(convertTwipToMm100(nWidth)); } else if ( aPropertyName == SC_UNONAME_CELLVIS ) { @@ -4318,7 +4318,7 @@ void SAL_CALL ScTableRowsObj::setPropertyValue( // TODO: It's probably cleaner to use a different property name // for this. - rDoc.SetRowHeightOnly( nStartRow, nEndRow, nTab, static_cast<sal_uInt16>(HMMToTwips(nNewHeight)) ); + rDoc.SetRowHeightOnly( nStartRow, nEndRow, nTab, static_cast<sal_uInt16>(convertMm100ToTwip(nNewHeight)) ); } else { @@ -4341,12 +4341,12 @@ void SAL_CALL ScTableRowsObj::setPropertyValue( // TODO: This is a band-aid fix. Eventually we need to // re-work ods' style import to get it to set styles to // ScDocument directly. - rDoc.SetRowHeightOnly( nStartRow, nEndRow, nTab, static_cast<sal_uInt16>(HMMToTwips(nNewHeight)) ); + rDoc.SetRowHeightOnly( nStartRow, nEndRow, nTab, static_cast<sal_uInt16>(convertMm100ToTwip(nNewHeight)) ); rDoc.SetManualHeight( nStartRow, nEndRow, nTab, true ); } else rFunc.SetWidthOrHeight( - false, aRowArr, nTab, SC_SIZE_ORIGINAL, static_cast<sal_uInt16>(HMMToTwips(nNewHeight)), true, true); + false, aRowArr, nTab, SC_SIZE_ORIGINAL, static_cast<sal_uInt16>(convertMm100ToTwip(nNewHeight)), true, true); } } else if ( aPropertyName == SC_UNONAME_CELLVIS ) @@ -4409,7 +4409,7 @@ uno::Any SAL_CALL ScTableRowsObj::getPropertyValue( const OUString& aPropertyNam { // for hidden row, return original height sal_uInt16 nHeight = rDoc.GetOriginalHeight( nStartRow, nTab ); - aAny <<= static_cast<sal_Int32>(TwipsToHMM(nHeight)); + aAny <<= static_cast<sal_Int32>(convertTwipToMm100(nHeight)); } else if ( aPropertyName == SC_UNONAME_CELLVIS ) { diff --git a/sc/source/ui/unoobj/styleuno.cxx b/sc/source/ui/unoobj/styleuno.cxx index 55c317f81901..81cf3a048067 100644 --- a/sc/source/ui/unoobj/styleuno.cxx +++ b/sc/source/ui/unoobj/styleuno.cxx @@ -37,7 +37,7 @@ #include <svl/intitem.hxx> #include <svl/zformat.hxx> #include <tools/fract.hxx> -#include <tools/helpers.hxx> +#include <tools/UnitConversion.hxx> #include <osl/diagnose.h> #include <com/sun/star/table/BorderLine.hpp> @@ -1254,7 +1254,7 @@ uno::Any ScStyleObj::getPropertyDefault_Impl( std::u16string_view aPropertyName aAny <<= sal_Int32( static_cast<const SfxUInt32Item&>(pItemSet->Get(nWhich)).GetValue() ); break; case ATTR_INDENT: - aAny <<= sal_Int16( TwipsToHMM(static_cast<const ScIndentItem&>( + aAny <<= sal_Int16( convertTwipToMm100(static_cast<const ScIndentItem&>( pItemSet->Get(nWhich)).GetValue()) ); break; case ATTR_PAGE_SCALE: @@ -1537,7 +1537,7 @@ void ScStyleObj::setPropertyValue_Impl( std::u16string_view rPropertyName, const { sal_Int16 nVal = 0; *pValue >>= nVal; - rSet.Put(ScIndentItem(static_cast<sal_uInt16>(HMMToTwips(nVal)))); + rSet.Put(ScIndentItem(static_cast<sal_uInt16>(convertMm100ToTwip(nVal)))); } break; case ATTR_ROTATE_VALUE: @@ -1804,7 +1804,7 @@ uno::Any ScStyleObj::getPropertyValue_Impl( std::u16string_view aPropertyName ) } break; case ATTR_INDENT: - aAny <<= sal_Int16( TwipsToHMM(static_cast<const ScIndentItem&>( + aAny <<= sal_Int16( convertTwipToMm100(static_cast<const ScIndentItem&>( pItemSet->Get(nWhich)).GetValue()) ); break; case ATTR_STACKED: diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx index 040b01178f62..c809c79fce60 100644 --- a/sc/source/ui/view/cellsh3.cxx +++ b/sc/source/ui/view/cellsh3.cxx @@ -26,6 +26,7 @@ #include <sfx2/dispatch.hxx> #include <sfx2/request.hxx> #include <svl/stritem.hxx> +#include <tools/UnitConversion.hxx> #include <vcl/svapp.hxx> #include <vcl/weld.hxx> #include <globstr.hrc> @@ -675,15 +676,15 @@ void ScCellShell::Execute( SfxRequest& rReq ) aRanges.emplace_back(nRow, nRow); } - pTabViewShell->SetWidthOrHeight(false, aRanges, SC_SIZE_DIRECT, HMMToTwips(nHeight)); + pTabViewShell->SetWidthOrHeight(false, aRanges, SC_SIZE_DIRECT, convertMm100ToTwip(nHeight)); } else if ( pReqArgs && pReqArgs->HasItem( FID_ROW_HEIGHT, &pHeight ) ) { nHeight = static_cast<const SfxUInt16Item*>(pHeight)->GetValue(); - // #101390#; the value of the macro is in HMM so use HMMToTwips to convert + // #101390#; the value of the macro is in HMM so use convertMm100ToTwip to convert pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, - sal::static_int_cast<sal_uInt16>( HMMToTwips(nHeight) ) ); + sal::static_int_cast<sal_uInt16>(convertMm100ToTwip(nHeight))); if( ! rReq.IsAPI() ) rReq.Done(); } @@ -720,9 +721,9 @@ void ScCellShell::Execute( SfxRequest& rReq ) { const SfxUInt16Item& rUInt16Item = static_cast<const SfxUInt16Item&>(pReqArgs->Get( FID_ROW_OPT_HEIGHT )); - // #101390#; the value of the macro is in HMM so use HMMToTwips to convert + // #101390#; the value of the macro is in HMM so use convertMm100ToTwip to convert pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL, - sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) ); + sal::static_int_cast<sal_uInt16>( convertMm100ToTwip(rUInt16Item.GetValue()) ) ); ScGlobal::nLastRowHeightExtra = rUInt16Item.GetValue(); if( ! rReq.IsAPI() ) @@ -774,15 +775,15 @@ void ScCellShell::Execute( SfxRequest& rReq ) aRanges.emplace_back(nColumn, nColumn); } - pTabViewShell->SetWidthOrHeight(true, aRanges, SC_SIZE_DIRECT, HMMToTwips(nWidth)); + pTabViewShell->SetWidthOrHeight(true, aRanges, SC_SIZE_DIRECT, convertMm100ToTwip(nWidth)); } else if ( pReqArgs && pReqArgs->HasItem( FID_COL_WIDTH, &pWidth ) ) { nWidth = static_cast<const SfxUInt16Item*>(pWidth)->GetValue(); - // #101390#; the value of the macro is in HMM so use HMMToTwips to convert + // #101390#; the value of the macro is in HMM so use convertMm100ToTwip to convert pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT, - sal::static_int_cast<sal_uInt16>( HMMToTwips(nWidth) ) ); + sal::static_int_cast<sal_uInt16>(convertMm100ToTwip(nWidth))); if( ! rReq.IsAPI() ) rReq.Done(); } @@ -817,9 +818,9 @@ void ScCellShell::Execute( SfxRequest& rReq ) { const SfxUInt16Item& rUInt16Item = static_cast<const SfxUInt16Item&>(pReqArgs->Get( FID_COL_OPT_WIDTH )); - // #101390#; the value of the macro is in HMM so use HMMToTwips to convert + // #101390#; the value of the macro is in HMM so use convertMm100ToTwip to convert pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL, - sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) ); + sal::static_int_cast<sal_uInt16>( convertMm100ToTwip(rUInt16Item.GetValue()) ) ); ScGlobal::nLastColWidthExtra = rUInt16Item.GetValue(); if( ! rReq.IsAPI() ) diff --git a/sc/source/ui/view/drawview.cxx b/sc/source/ui/view/drawview.cxx index bb6d3834cdc4..a1efca1748e4 100644 --- a/sc/source/ui/view/drawview.cxx +++ b/sc/source/ui/view/drawview.cxx @@ -41,6 +41,7 @@ #include <svx/sdr/contact/viewobjectcontact.hxx> #include <svx/sdr/contact/viewcontact.hxx> #include <svx/sdrpagewindow.hxx> +#include <tools/UnitConversion.hxx> #include <drawview.hxx> #include <global.hxx> @@ -958,8 +959,8 @@ void ScDrawView::SyncForGrid( SdrObject* pObj ) MapMode aDrawMode = pGridWin->GetDrawMapMode(); // find pos anchor position Point aOldPos( rDoc.GetColOffset( aOldStt.Col(), aOldStt.Tab() ), rDoc.GetRowOffset( aOldStt.Row(), aOldStt.Tab() ) ); - aOldPos.setX( TwipsToHMM( aOldPos.X() ) ); - aOldPos.setY( TwipsToHMM( aOldPos.Y() ) ); + aOldPos.setX(convertTwipToMm100(aOldPos.X())); + aOldPos.setY(convertTwipToMm100(aOldPos.Y())); // find position of same point on the screen ( e.g. grid ) Point aCurPos = pViewData->GetScrPos( aOldStt.Col(), aOldStt.Row(), eWhich, true ); Point aCurPosHmm = pGridWin->PixelToLogic(aCurPos, aDrawMode ); @@ -1035,8 +1036,8 @@ bool ScDrawView::calculateGridOffsetForSdrObject( // find pos anchor position Point aOldPos(rDoc.GetColOffset(aOldStt.Col(), aOldStt.Tab()), rDoc.GetRowOffset(aOldStt.Row(), aOldStt.Tab())); - aOldPos.setX(TwipsToHMM(aOldPos.X())); - aOldPos.setY(TwipsToHMM(aOldPos.Y())); + aOldPos.setX(convertTwipToMm100(aOldPos.X())); + aOldPos.setY(convertTwipToMm100(aOldPos.Y())); // find position of same point on the screen ( e.g. grid ) ScSplitPos eWhich(pViewData->GetActivePart()); @@ -1083,8 +1084,8 @@ bool ScDrawView::calculateGridOffsetForB2DRange( // find pos anchor position Point aOldPos(rDoc.GetColOffset(aOldStt.Col(), aOldStt.Tab()), rDoc.GetRowOffset(aOldStt.Row(), aOldStt.Tab())); - aOldPos.setX(TwipsToHMM(aOldPos.X())); - aOldPos.setY(TwipsToHMM(aOldPos.Y())); + aOldPos.setX(convertTwipToMm100(aOldPos.X())); + aOldPos.setY(convertTwipToMm100(aOldPos.Y())); // find position of same point on the screen ( e.g. grid ) ScSplitPos eWhich(pViewData->GetActivePart()); diff --git a/sc/source/ui/view/tabvwsh2.cxx b/sc/source/ui/view/tabvwsh2.cxx index a2e5f43c9d56..f213c5b822ef 100644 --- a/sc/source/ui/view/tabvwsh2.cxx +++ b/sc/source/ui/view/tabvwsh2.cxx @@ -24,6 +24,7 @@ #include <unotools/moduleoptions.hxx> #include <svl/languageoptions.hxx> #include <sfx2/dispatch.hxx> +#include <tools/UnitConversion.hxx> #include <tabvwsh.hxx> #include <drawview.hxx> @@ -337,8 +338,8 @@ void ScTabViewShell::ExecDraw(SfxRequest& rReq) comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs)) aInsertPos = rViewData.GetPrintTwipsPosFromTileTwips(aInsertPos); - aInsertPos.setX(TwipsToHMM(aInsertPos.X())); - aInsertPos.setY(TwipsToHMM(aInsertPos.Y())); + aInsertPos.setX(convertTwipToMm100(aInsertPos.X())); + aInsertPos.setY(convertTwipToMm100(aInsertPos.Y())); aInsertPos.AdjustX( -sal_Int32(nDefaultObjectSizeWidth / 2) ); aInsertPos.AdjustY( -sal_Int32(nDefaultObjectSizeHeight / 2) ); diff --git a/svx/source/table/tablertfexporter.cxx b/svx/source/table/tablertfexporter.cxx index f3cde67471b5..135693ea67b0 100644 --- a/svx/source/table/tablertfexporter.cxx +++ b/svx/source/table/tablertfexporter.cxx @@ -25,6 +25,7 @@ #include <tools/diagnose_ex.h> #include <tools/stream.hxx> +#include <tools/UnitConversion.hxx> #include <svtools/rtfkeywd.hxx> #include <svtools/rtfout.hxx> @@ -95,7 +96,7 @@ void SdrTableRtfExporter::Write() Reference< XPropertySet > xSet( xColumns->getByIndex(nCol), UNO_QUERY_THROW ); sal_Int32 nWidth = 0; xSet->getPropertyValue( gsSize ) >>= nWidth; - nPos += HMMToTwips( nWidth ); + nPos += convertMm100ToTwip(nWidth); aColumnStart.push_back( nPos ); } catch( Exception& ) diff --git a/svx/source/table/tablertfimporter.cxx b/svx/source/table/tablertfimporter.cxx index cdf25aa67306..74e127b03f91 100644 --- a/svx/source/table/tablertfimporter.cxx +++ b/svx/source/table/tablertfimporter.cxx @@ -25,6 +25,7 @@ #include <com/sun/star/table/XMergeableCellRange.hpp> #include <tools/stream.hxx> +#include <tools/UnitConversion.hxx> #include <svtools/rtftoken.h> #include <svx/svdetc.hxx> @@ -429,7 +430,7 @@ void SdrTableRTFParser::ProcToken( RtfImportInfo* pInfo ) maDefaultList.push_back( pDefault ); - const sal_Int32 nSize = TwipsToHMM( pInfo->nTokenValue ); + const sal_Int32 nSize = convertTwipToMm100(pInfo->nTokenValue); if ( nSize > mnLastEdge ) InsertColumnEdge( nSize ); diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx index 74f71049db2d..c44d3e62daa6 100644 --- a/svx/source/unodraw/unoshape.cxx +++ b/svx/source/unodraw/unoshape.cxx @@ -55,6 +55,7 @@ #include <svx/svdpool.hxx> #include <tools/stream.hxx> #include <tools/gen.hxx> +#include <tools/UnitConversion.hxx> #include <svx/svdoedge.hxx> #include <svx/svdocapt.hxx> #include <svx/obj3d.hxx> @@ -464,8 +465,8 @@ void SvxShape::ForceMetricToItemPoolMetric(Pair& rPoint) const throw() { case MapUnit::MapTwip : { - rPoint.A() = HMMToTwips(rPoint.A()); - rPoint.B() = HMMToTwips(rPoint.B()); + rPoint.A() = convertMm100ToTwip(rPoint.A()); + rPoint.B() = convertMm100ToTwip(rPoint.B()); break; } default: @@ -548,8 +549,8 @@ void SvxShape::ForceMetricTo100th_mm(Pair& rPoint) const throw() { case MapUnit::MapTwip : { - rPoint.A() = TwipsToHMM(rPoint.A()); - rPoint.B() = TwipsToHMM(rPoint.B()); + rPoint.A() = convertTwipToMm100(rPoint.A()); + rPoint.B() = convertTwipToMm100(rPoint.B()); break; } default: diff --git a/sw/qa/core/objectpositioning/objectpositioning.cxx b/sw/qa/core/objectpositioning/objectpositioning.cxx index 2a35a41f1ec2..7b9a3eca2831 100644 --- a/sw/qa/core/objectpositioning/objectpositioning.cxx +++ b/sw/qa/core/objectpositioning/objectpositioning.cxx @@ -67,10 +67,10 @@ CPPUNIT_TEST_FIXTURE(SwCoreObjectpositioningTest, testVertPosFromBottom) sal_Int32 nAnchoredBottom = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "bottom").toInt32(); // Without the accompanying fix in place, this test would have failed with: - // - Expected: 564 + // - Expected: 565 // - Actual : 9035 // i.e. the vertical position was from-top, not from-bottom. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(564), nBodyBottom - nAnchoredBottom); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(565), nBodyBottom - nAnchoredBottom); } CPPUNIT_TEST_FIXTURE(SwCoreObjectpositioningTest, testVertAlignBottomMargin) diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx index a2391cbe31b3..72dc978a4c8e 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx @@ -360,17 +360,17 @@ DECLARE_OOXMLEXPORT_TEST(testDMLGroupShapeChildPosition, "dml-groupshape-childpo uno::Reference<drawing::XShapes> xGroup(getShape(1), uno::UNO_QUERY); uno::Reference<drawing::XShape> xChildGroup(xGroup->getByIndex(1), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? -2120 : -2122), xChildGroup->getPosition().X); - CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? 11336 : 11333), xChildGroup->getPosition().Y); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-2123), xChildGroup->getPosition().X); + CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? 11333 : 11331), xChildGroup->getPosition().Y); xGroup.set(xChildGroup, uno::UNO_QUERY); xChildGroup.set(xGroup->getByIndex(0), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? -1856 : -1858), xChildGroup->getPosition().X); - CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? 11336 : 11333), xChildGroup->getPosition().Y); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1859), xChildGroup->getPosition().X); + CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? 11333 : 11331), xChildGroup->getPosition().Y); xChildGroup.set(xGroup->getByIndex(1), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? -2120 : -2122), xChildGroup->getPosition().X); - CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? 14026 : 14023), xChildGroup->getPosition().Y); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-2123), xChildGroup->getPosition().X); + CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? 14023 : 14021), xChildGroup->getPosition().Y); } DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testDMLGradientFillTheme, "dml-gradientfill-theme.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx index 2e8c2c45aa42..e9d8ebd64fd7 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx @@ -443,7 +443,7 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testPictureEffectPreservation, "picture-effe // second picture: shadow and reflection effects assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/" "wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:outerShdw", - "dir", "8076614"); + "dir", "8100000"); assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/" "wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:outerShdw/a:srgbClr", "val", "000000"); diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index 94f0d5abac78..37b612034d44 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -862,15 +862,16 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_u if (aValue >>= nValue) { if (bAdjustX) - nValue += TwipsToHMM(aRect.getX()); + nValue += convertTwipToMm100(aRect.getX()); else if (bAdjustY) - nValue += TwipsToHMM(aRect.getY()); + nValue += convertTwipToMm100(aRect.getY()); aValue <<= nValue; } } else if (bAdjustSize) { - awt::Size aSize(TwipsToHMM(aRect.getWidth()), TwipsToHMM(aRect.getHeight())); + awt::Size aSize(convertTwipToMm100(aRect.getWidth()), + convertTwipToMm100(aRect.getHeight())); aValue <<= aSize; } } diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx index e6d75e7ceeba..bee858964b4e 100644 --- a/sw/source/filter/ww8/wrtw8esh.cxx +++ b/sw/source/filter/ww8/wrtw8esh.cxx @@ -90,6 +90,7 @@ #include <o3tl/enumrange.hxx> #include <o3tl/enumarray.hxx> #include <sfx2/docfile.hxx> +#include <tools/UnitConversion.hxx> #include <algorithm> @@ -3041,8 +3042,8 @@ void SwMSConvertControls::ExportControl(WW8Export &rWW8Wrt, const SdrUnoObj& rFo tools::Rectangle aRect = rFormObj.GetLogicRect(); aRect.SetPos(Point(0,0)); awt::Size aSize; - aSize.Width = TwipsToHMM(aRect.Right()); - aSize.Height = TwipsToHMM(aRect.Bottom()); + aSize.Width = convertTwipToMm100(aRect.Right()); + aSize.Height = convertTwipToMm100(aRect.Bottom()); //Open the ObjectPool tools::SvRef<SotStorage> xObjPool = rWW8Wrt.GetWriter().GetStorage().OpenSotStorage(SL::aObjectPool); diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx index cd5f2b18f115..e3ecbeac0d7e 100644 --- a/sw/source/filter/xml/xmlimp.cxx +++ b/sw/source/filter/xml/xmlimp.cxx @@ -64,7 +64,7 @@ #include <xmloff/xmluconv.hxx> #include <unotools/saveopt.hxx> #include <unotools/streamwrap.hxx> -#include <tools/helpers.hxx> +#include <tools/UnitConversion.hxx> #include <tools/diagnose_ex.h> #include <vcl/svapp.hxx> diff --git a/xmloff/source/transform/TransformerBase.cxx b/xmloff/source/transform/TransformerBase.cxx index c55e29562558..fd59d2c8bb96 100644 --- a/xmloff/source/transform/TransformerBase.cxx +++ b/xmloff/source/transform/TransformerBase.cxx @@ -20,6 +20,7 @@ #include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> +#include <tools/UnitConversion.hxx> #include <osl/diagnose.h> #include <com/sun/star/i18n/CharacterClassification.hpp> #include <com/sun/star/i18n/UnicodeType.hpp> @@ -557,11 +558,7 @@ XMLMutableAttributeList *XMLTransformerBase::ProcessAttrList( if (::sax::Converter::convertMeasure(nMeasure, aAttrValue)) { - - // #i13778#,#i36248# apply correct twip-to-1/100mm - nMeasure = static_cast<sal_Int32>( nMeasure >= 0 - ? ((nMeasure*127+36)/72) - : ((nMeasure*127-36)/72) ); + nMeasure = static_cast<sal_Int32>(convertTwipToMm100(nMeasure)); OUStringBuffer aBuffer; ::sax::Converter::convertMeasure(aBuffer, @@ -725,11 +722,7 @@ XMLMutableAttributeList *XMLTransformerBase::ProcessAttrList( if (::sax::Converter::convertMeasure(nMeasure, aAttrValue)) { - - // #i13778#,#i36248#/ apply correct 1/100mm-to-twip conversion - nMeasure = static_cast<sal_Int32>( nMeasure >= 0 - ? ((nMeasure*72+63)/127) - : ((nMeasure*72-63)/127) ); + nMeasure = static_cast<sal_Int32>(convertMm100ToTwip(nMeasure)); OUStringBuffer aBuffer; ::sax::Converter::convertMeasure( aBuffer, |