chart2/qa/extras/xshape/data/reference/tdf90839-1.xml | 4 +- chart2/qa/extras/xshape/data/reference/tdf90839-2.xml | 4 +- chart2/qa/extras/xshape/data/reference/tdf90839-3.xml | 4 +- sc/inc/global.hxx | 35 ++++++------------ sc/qa/extras/macros-test.cxx | 6 +-- sc/qa/unit/filters-test.cxx | 2 - sc/qa/unit/scshapetest.cxx | 12 +++--- sc/qa/unit/subsequent_filters_test2.cxx | 20 +++++----- sc/qa/unit/tiledrendering/tiledrendering.cxx | 6 +-- sc/qa/unit/uicalc/uicalc.cxx | 4 +- sc/source/core/data/documen3.cxx | 24 ++++-------- sc/source/core/data/drwlayer.cxx | 10 ++--- sc/source/ui/docshell/docsh4.cxx | 12 +++--- sc/source/ui/inc/printfun.hxx | 4 +- sc/source/ui/unoobj/docuno.cxx | 8 ++-- sc/source/ui/view/output2.cxx | 1 sc/source/ui/view/printfun.cxx | 5 +- sc/source/ui/view/viewdata.cxx | 1 sw/qa/extras/odfexport/odfexport.cxx | 6 +-- sw/qa/extras/ooxmlexport/ooxmlexport12.cxx | 6 +-- 20 files changed, 78 insertions(+), 96 deletions(-)
New commits: commit 00d74a5e0291a40e532b2a0f51fdd5a3e1f487ed Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Aug 11 17:36:12 2021 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Nov 12 09:44:10 2021 +0100 Use more o3tl::convert in sc Change-Id: I624b6c570eff8b6cdc83ffcb2d0dbadf848715b0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120330 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/chart2/qa/extras/xshape/data/reference/tdf90839-1.xml b/chart2/qa/extras/xshape/data/reference/tdf90839-1.xml index 2af62c344940..eb48c3f7293d 100644 --- a/chart2/qa/extras/xshape/data/reference/tdf90839-1.xml +++ b/chart2/qa/extras/xshape/data/reference/tdf90839-1.xml @@ -1,6 +1,6 @@ <?xml version="1.0"?> <XShapes> - <XShape positionX="0" positionY="0" sizeX="26494" sizeY="18367" type="com.sun.star.drawing.RectangleShape" name="CID/Page=" fontHeight="12.000000" fontColor="ffffffff" textAutoGrowHeight="true" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="CENTER" textVerticalAdjust="CENTER" textLeftDistance="0" textRightDistance="0" textUpperDistance="0" textLowerDistance="0" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="ffffff" fillTransparence="0" fillTransparenceGradientName=""> + <XShape positionX="0" positionY="0" sizeX="26494" sizeY="18368" type="com.sun.star.drawing.RectangleShape" name="CID/Page=" fontHeight="12.000000" fontColor="ffffffff" textAutoGrowHeight="true" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="CENTER" textVerticalAdjust="CENTER" textLeftDistance="0" textRightDistance="0" textUpperDistance="0" textLowerDistance="0" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="ffffff" fillTransparence="0" fillTransparenceGradientName=""> <FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillGradient style="LINEAR" startColor="000000" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillHatch style="SINGLE" color="3465a4" distance="20" angle="0"/> @@ -10,7 +10,7 @@ <LineEnd/> <Transformation> <Line1 column1="26495.000000" column2="0.000000" column3="0.000000"/> - <Line2 column1="0.000000" column2="18368.000000" column3="0.000000"/> + <Line2 column1="0.000000" column2="18369.000000" column3="0.000000"/> <Line3 column1="0.000000" column2="0.000000" column3="1.000000"/> </Transformation> </XShape> diff --git a/chart2/qa/extras/xshape/data/reference/tdf90839-2.xml b/chart2/qa/extras/xshape/data/reference/tdf90839-2.xml index d7e5c4a364f9..639c32d00491 100644 --- a/chart2/qa/extras/xshape/data/reference/tdf90839-2.xml +++ b/chart2/qa/extras/xshape/data/reference/tdf90839-2.xml @@ -1,6 +1,6 @@ <?xml version="1.0"?> <XShapes> - <XShape positionX="0" positionY="0" sizeX="26494" sizeY="18367" type="com.sun.star.drawing.RectangleShape" name="CID/Page=" fontHeight="12.000000" fontColor="ffffffff" textAutoGrowHeight="true" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="CENTER" textVerticalAdjust="CENTER" textLeftDistance="0" textRightDistance="0" textUpperDistance="0" textLowerDistance="0" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="ffffff" fillTransparence="0" fillTransparenceGradientName=""> + <XShape positionX="0" positionY="0" sizeX="26494" sizeY="18368" type="com.sun.star.drawing.RectangleShape" name="CID/Page=" fontHeight="12.000000" fontColor="ffffffff" textAutoGrowHeight="true" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="CENTER" textVerticalAdjust="CENTER" textLeftDistance="0" textRightDistance="0" textUpperDistance="0" textLowerDistance="0" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="ffffff" fillTransparence="0" fillTransparenceGradientName=""> <FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillGradient style="LINEAR" startColor="000000" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillHatch style="SINGLE" color="3465a4" distance="20" angle="0"/> @@ -10,7 +10,7 @@ <LineEnd/> <Transformation> <Line1 column1="26495.000000" column2="0.000000" column3="0.000000"/> - <Line2 column1="0.000000" column2="18368.000000" column3="0.000000"/> + <Line2 column1="0.000000" column2="18369.000000" column3="0.000000"/> <Line3 column1="0.000000" column2="0.000000" column3="1.000000"/> </Transformation> </XShape> diff --git a/chart2/qa/extras/xshape/data/reference/tdf90839-3.xml b/chart2/qa/extras/xshape/data/reference/tdf90839-3.xml index 77a1ac06f80a..77be20e2147f 100644 --- a/chart2/qa/extras/xshape/data/reference/tdf90839-3.xml +++ b/chart2/qa/extras/xshape/data/reference/tdf90839-3.xml @@ -1,6 +1,6 @@ <?xml version="1.0"?> <XShapes> - <XShape positionX="0" positionY="0" sizeX="26494" sizeY="18367" type="com.sun.star.drawing.RectangleShape" name="CID/Page=" fontHeight="12.000000" fontColor="ffffffff" textAutoGrowHeight="true" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="CENTER" textVerticalAdjust="CENTER" textLeftDistance="0" textRightDistance="0" textUpperDistance="0" textLowerDistance="0" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="ffffff" fillTransparence="0" fillTransparenceGradientName=""> + <XShape positionX="0" positionY="0" sizeX="26494" sizeY="18368" type="com.sun.star.drawing.RectangleShape" name="CID/Page=" fontHeight="12.000000" fontColor="ffffffff" textAutoGrowHeight="true" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="CENTER" textVerticalAdjust="CENTER" textLeftDistance="0" textRightDistance="0" textUpperDistance="0" textLowerDistance="0" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="ffffff" fillTransparence="0" fillTransparenceGradientName=""> <FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillGradient style="LINEAR" startColor="000000" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillHatch style="SINGLE" color="3465a4" distance="20" angle="0"/> @@ -10,7 +10,7 @@ <LineEnd/> <Transformation> <Line1 column1="26495.000000" column2="0.000000" column3="0.000000"/> - <Line2 column1="0.000000" column2="18368.000000" column3="0.000000"/> + <Line2 column1="0.000000" column2="18369.000000" column3="0.000000"/> <Line3 column1="0.000000" column2="0.000000" column3="1.000000"/> </Transformation> </XShape> diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx index 7881395d802e..3eab2e36d8e2 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -28,6 +28,7 @@ #include "scdllapi.h" #include <rtl/ustring.hxx> #include <tools/long.hxx> +#include <o3tl/unit_conversion.hxx> #include <atomic> // HACK: <atomic> includes <stdbool.h>, which in some Clang versions does '#define bool bool', @@ -79,35 +80,23 @@ const sal_Unicode CHAR_NNBSP = 0x202F; //NARROW NO-BREAK SPACE const SCSIZE MAXSUBTOTAL = 3; -#define PIXEL_PER_INCH 96.0 -#define CM_PER_INCH 2.54 -#define POINTS_PER_INCH 72.0 /**< PostScript points per inch */ -#define PIXEL_PER_POINT (PIXEL_PER_INCH / POINTS_PER_INCH) -#define TWIPS_PER_POINT 20.0 -#define TWIPS_PER_INCH (TWIPS_PER_POINT * POINTS_PER_INCH) -#define TWIPS_PER_CM (TWIPS_PER_INCH / CM_PER_INCH) -#define CM_PER_TWIPS (CM_PER_INCH / TWIPS_PER_INCH) -#define TWIPS_PER_PIXEL (TWIPS_PER_INCH / PIXEL_PER_INCH) -#define TWIPS_PER_CHAR (TWIPS_PER_INCH / 13.6) -#define PIXEL_PER_TWIPS (PIXEL_PER_INCH / TWIPS_PER_INCH) -#define HMM_PER_TWIPS (CM_PER_TWIPS * 1000.0) - -#define STD_COL_WIDTH 1280 /* 2.2577cm, 64.00pt PS */ -#define STD_EXTRA_WIDTH 113 /* 2mm extra for optimal width, - * 0.1986cm with TeX points, - * 0.1993cm with PS points. */ - -#define MAX_EXTRA_WIDTH 23811 /* 42cm in TWIPS, 41.8430cm TeX, 41.9999cm PS */ -#define MAX_EXTRA_HEIGHT 23811 -#define MAX_COL_WIDTH 56693 /* 1m in TWIPS, 99.6266cm TeX, 100.0001cm PS */ -#define MAX_ROW_HEIGHT 56693 +// ~105.88 twip, i.e. about 2 times narrower than o3tl::Length::ch, which is 210 twip +constexpr auto TWIPS_PER_CHAR = o3tl::toTwips(1 / 13.6, o3tl::Length::in); + +constexpr sal_Int32 STD_COL_WIDTH = o3tl::convert(64, o3tl::Length::pt, o3tl::Length::twip); +constexpr sal_Int32 STD_EXTRA_WIDTH = o3tl::convert(2, o3tl::Length::mm, o3tl::Length::twip); + +constexpr sal_Int32 MAX_EXTRA_WIDTH = o3tl::convert(42, o3tl::Length::cm, o3tl::Length::twip); +constexpr sal_Int32 MAX_EXTRA_HEIGHT = o3tl::convert(42, o3tl::Length::cm, o3tl::Length::twip); +constexpr sal_Int32 MAX_COL_WIDTH = o3tl::convert(1, o3tl::Length::m, o3tl::Length::twip); +constexpr sal_Int32 MAX_ROW_HEIGHT = o3tl::convert(1, o3tl::Length::m, o3tl::Length::twip); /* standard row height: text + margin - STD_ROWHEIGHT_DIFF */ #define STD_ROWHEIGHT_DIFF 23 namespace sc { - inline ::tools::Long TwipsToEvenHMM( ::tools::Long nTwips ) { return ( (nTwips * 127 + 72) / 144 ) * 2; } + constexpr ::tools::Long TwipsToEvenHMM( ::tools::Long nTwips ) { return o3tl::convert(nTwips, 127, 144) * 2; } } // standard size as OLE server (cells) diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index f6745d3a711a..a68b39ce1cbc 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -478,15 +478,15 @@ void ScMacrosTest::testRowColumn() "vnd.sun.Star.script:Standard.Module1.Macro_RowHeight?language=Basic&location=document", aParams, aRet, aOutParamIndex, aOutParam); - sal_uInt16 nHeight = rDoc.GetRowHeight(0, 0) * HMM_PER_TWIPS; + sal_uInt16 nHeight = o3tl::convert(rDoc.GetRowHeight(0, 0), o3tl::Length::twip, o3tl::Length::mm100); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(2000), nHeight); SfxObjectShell::CallXScript( xComponent, "vnd.sun.Star.script:Standard.Module1.Macro_ColumnWidth?language=Basic&location=document", aParams, aRet, aOutParamIndex, aOutParam); - sal_uInt16 nWidth = rDoc.GetColWidth(0, 0) * HMM_PER_TWIPS; - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(4000), nWidth); + sal_uInt16 nWidth = o3tl::convert(rDoc.GetColWidth(0, 0), o3tl::Length::twip, o3tl::Length::mm100); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(4001), nWidth); pDocSh->DoClose(); } diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx index e6a736799663..923f2e229391 100644 --- a/sc/qa/unit/filters-test.cxx +++ b/sc/qa/unit/filters-test.cxx @@ -627,7 +627,7 @@ void ScFiltersTest::testLegacyCellAnchoredRotatedShape() aAnchor.maStart.SetRow( 3 ); aAnchor.maStart.SetCol( 6 ); aAnchor.maEnd.SetRow( 9 ); - aAnchor.maEnd.SetCol( 7 ); + aAnchor.maEnd.SetCol( 8 ); // test import impl_testLegacyCellAnchoredRotatedShape( rDoc, aRect, aAnchor ); // test save and reload diff --git a/sc/qa/unit/scshapetest.cxx b/sc/qa/unit/scshapetest.cxx index f08a909aac68..8784fb1a125a 100644 --- a/sc/qa/unit/scshapetest.cxx +++ b/sc/qa/unit/scshapetest.cxx @@ -696,14 +696,14 @@ void ScShapeTest::testTdf137033_RotShear_ResizeHide() Degree100 aShearAngle(pObj->GetShearAngle()); // mathematical exact would be Point(3868, 4795), Size(9763, 1909) // current values as of LO 7.2 - const tools::Rectangle aExpectRect(Point(3871, 4796), Size(9764, 1910)); - const Degree100 aExpectRotateAngle(20923_deg100); - const Degree100 aExpectShearAngle(-6572_deg100); + const tools::Rectangle aExpectRect(Point(3875, 4796), Size(9760, 1911)); + const Degree100 aExpectRotateAngle(20925_deg100); + const Degree100 aExpectShearAngle(-6570_deg100); CPPUNIT_ASSERT_MESSAGE("Hide rows, shear angle: ", abs(aShearAngle - aExpectShearAngle) <= 1_deg100); CPPUNIT_ASSERT_MESSAGE("Hide rows, rotate angle: ", abs(aRotateAngle - aExpectRotateAngle) <= 1_deg100); - lcl_AssertRectEqualWithTolerance("Reload: wrong pos or size", aExpectRect, aSnapRect, 1); + lcl_AssertRectEqualWithTolerance("Load: wrong pos or size", aExpectRect, aSnapRect, 1); // Save and reload. saveAndReload(xComponent, "calc8"); @@ -722,7 +722,7 @@ void ScShapeTest::testTdf137033_RotShear_ResizeHide() abs(aShearAngle - aExpectShearAngle) <= 3_deg100); CPPUNIT_ASSERT_MESSAGE("Reload, rotate angle: ", abs(aRotateAngle - aExpectRotateAngle) <= 3_deg100); - lcl_AssertRectEqualWithTolerance("Reload: wrong pos or size", aExpectRect, aSnapRect, 4); + lcl_AssertRectEqualWithTolerance("Reload: wrong pos or size", aExpectRect, aSnapRect, 7); pDocSh->DoClose(); } @@ -1196,7 +1196,7 @@ void ScShapeTest::testFitToCellSize() const tools::Rectangle& rShapeRect(pObj->GetSnapRect()); const tools::Rectangle aCellRect = rDoc.GetMMRect(1, 1, 1, 1, 0); - lcl_AssertRectEqualWithTolerance("Cell and SnapRect should be equal", aCellRect, rShapeRect, 1); + lcl_AssertRectEqualWithTolerance("Cell and SnapRect should be equal", aCellRect, rShapeRect, 2); pDocSh->DoClose(); } diff --git a/sc/qa/unit/subsequent_filters_test2.cxx b/sc/qa/unit/subsequent_filters_test2.cxx index 0963e547ddcf..f10474d17172 100644 --- a/sc/qa/unit/subsequent_filters_test2.cxx +++ b/sc/qa/unit/subsequent_filters_test2.cxx @@ -2521,18 +2521,18 @@ void ScFiltersTest2::testShapeRotationImport() // The expected values are in the map below. Note that some of the angles are outside of the set which contains // the value of the wrong angles. This is to check the border cases and one value on both sides. std::map<sal_Int32, std::map<std::string, sal_Int32>> aExpectedValues{ - { 4400, { { "x", 6832 }, { "y", 36893 }, { "width", 8898 }, { "height", 1163 } } }, - { 4500, { { "x", 4490 }, { "y", 36400 }, { "width", 8898 }, { "height", 1163 } } }, - { 4600, { { "x", 1673 }, { "y", 36270 }, { "width", 8862 }, { "height", 1144 } } }, + { 4400, { { "x", 6832 }, { "y", 36894 }, { "width", 8898 }, { "height", 1163 } } }, + { 4500, { { "x", 4491 }, { "y", 36400 }, { "width", 8898 }, { "height", 1164 } } }, + { 4600, { { "x", 1674 }, { "y", 36271 }, { "width", 8863 }, { "height", 1143 } } }, { 13400, { { "x", 13762 }, { "y", 28403 }, { "width", 8863 }, { "height", 1194 } } }, - { 13500, { { "x", 10817 }, { "y", 27951 }, { "width", 8863 }, { "height", 1170 } } }, - { 13600, { { "x", 8449 }, { "y", 28336 }, { "width", 8897 }, { "height", 1164 } } }, - { 22400, { { "x", 14948 }, { "y", 12978 }, { "width", 8898 }, { "height", 1164 } } }, - { 22500, { { "x", 11765 }, { "y", 12834 }, { "width", 8898 }, { "height", 1164 } } }, - { 22600, { { "x", 8253 }, { "y", 12919 }, { "width", 8863 }, { "height", 1171 } } }, + { 13500, { { "x", 10818 }, { "y", 27951 }, { "width", 8863 }, { "height", 1170 } } }, + { 13600, { { "x", 8450 }, { "y", 28337 }, { "width", 8898 }, { "height", 1163 } } }, + { 22400, { { "x", 14949 }, { "y", 12978 }, { "width", 8898 }, { "height", 1163 } } }, + { 22500, { { "x", 11765 }, { "y", 12834 }, { "width", 8898 }, { "height", 1163 } } }, + { 22600, { { "x", 8253 }, { "y", 12920 }, { "width", 8862 }, { "height", 1170 } } }, { 31400, { { "x", 8099 }, { "y", 1160 }, { "width", 9815 }, { "height", 1171 } } }, - { 31500, { { "x", 4427 }, { "y", 1274 }, { "width", 10238 }, { "height", 1171 } } }, - { 31600, { { "x", 1964 }, { "y", 1878 }, { "width", 10307 }, { "height", 1164 } } }, + { 31500, { { "x", 4428 }, { "y", 1274 }, { "width", 10238 }, { "height", 1171 } } }, + { 31600, { { "x", 1964 }, { "y", 1879 }, { "width", 10307 }, { "height", 1163 } } }, }; for (sal_Int32 ind = 0; ind < 12; ++ind) diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index ba51cc996969..c4e0da7b9f87 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -891,8 +891,8 @@ void ScTiledRenderingTest::testColRowResize() })); comphelper::dispatchCommand(".uno:ColumnWidth", aArgs); - sal_uInt16 nWidth = rDoc.GetColWidth(static_cast<SCCOL>(2), static_cast<SCTAB>(0), false) * HMM_PER_TWIPS; - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(4000), nWidth); + sal_uInt16 nWidth = o3tl::convert(rDoc.GetColWidth(static_cast<SCCOL>(2), static_cast<SCTAB>(0), false), o3tl::Length::twip, o3tl::Length::mm100); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(4001), nWidth); // Row 5, Tab 0 uno::Sequence<beans::PropertyValue> aArgs2( comphelper::InitPropertySequence({ @@ -901,7 +901,7 @@ void ScTiledRenderingTest::testColRowResize() })); comphelper::dispatchCommand(".uno:RowHeight", aArgs2); - sal_uInt16 nHeight = rDoc.GetRowHeight(static_cast<SCROW>(4), static_cast<SCTAB>(0), false) * HMM_PER_TWIPS; + sal_uInt16 nHeight = o3tl::convert(rDoc.GetRowHeight(static_cast<SCROW>(4), static_cast<SCTAB>(0), false), o3tl::Length::twip, o3tl::Length::mm100); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(2000), nHeight); } diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx index ea44aaa3cd40..a06dd66b5117 100644 --- a/sc/qa/unit/uicalc/uicalc.cxx +++ b/sc/qa/unit/uicalc/uicalc.cxx @@ -1449,7 +1449,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf136113) SdrPage* pPage = pDrawLayer->GetPage(0); SdrObject* pObj = pPage->GetObj(0); - CPPUNIT_ASSERT_EQUAL(tools::Long(18159), pObj->GetSnapRect().Left()); + CPPUNIT_ASSERT_EQUAL(tools::Long(18160), pObj->GetSnapRect().Left()); CPPUNIT_ASSERT_EQUAL(tools::Long(1709), pObj->GetSnapRect().Top()); lcl_SelectObjectByName(u"Arrow"); @@ -1459,7 +1459,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf136113) pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::UP); Scheduler::ProcessEventsToIdle(); - CPPUNIT_ASSERT_EQUAL(tools::Long(18159), pObj->GetSnapRect().Left()); + CPPUNIT_ASSERT_EQUAL(tools::Long(18160), pObj->GetSnapRect().Left()); CPPUNIT_ASSERT_EQUAL(tools::Long(1609), pObj->GetSnapRect().Top()); // Without the fix in place, this test would have failed here diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index ecaeeb3f940a..5d5583628985 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -1735,10 +1735,7 @@ tools::Rectangle ScDocument::GetEmbeddedRect() const // 1/100 mm aRect.SetBottom( aRect.Top() ); aRect.AdjustBottom(pTable->GetRowHeight( aEmbedRange.aStart.Row(), aEmbedRange.aEnd.Row()) ); - aRect.SetLeft( static_cast<tools::Long>( aRect.Left() * HMM_PER_TWIPS ) ); - aRect.SetRight( static_cast<tools::Long>( aRect.Right() * HMM_PER_TWIPS ) ); - aRect.SetTop( static_cast<tools::Long>( aRect.Top() * HMM_PER_TWIPS ) ); - aRect.SetBottom( static_cast<tools::Long>( aRect.Bottom() * HMM_PER_TWIPS ) ); + aRect = o3tl::convert(aRect, o3tl::Length::twip, o3tl::Length::mm100); } return aRect; } @@ -1815,7 +1812,7 @@ ScRange ScDocument::GetRange( SCTAB nTab, const tools::Rectangle& rMMRect, bool return ScRange(); } - tools::Rectangle aPosRect = rMMRect; + tools::Rectangle aPosRect = o3tl::convert(rMMRect, o3tl::Length::mm100, o3tl::Length::twip); if ( IsNegativePage( nTab ) ) ScDrawLayer::MirrorRectRTL( aPosRect ); // Always with positive (LTR) values @@ -1825,13 +1822,13 @@ ScRange ScDocument::GetRange( SCTAB nTab, const tools::Rectangle& rMMRect, bool bool bEnd; nSize = 0; - nTwips = static_cast<tools::Long>(aPosRect.Left() / HMM_PER_TWIPS); + nTwips = aPosRect.Left(); SCCOL nX1 = 0; bEnd = false; while (!bEnd) { - nAdd = static_cast<tools::Long>(pTable->GetColWidth(nX1, bHiddenAsZero)); + nAdd = pTable->GetColWidth(nX1, bHiddenAsZero); if (nSize+nAdd <= nTwips+1 && nX1<MaxCol()) { nSize += nAdd; @@ -1846,10 +1843,10 @@ ScRange ScDocument::GetRange( SCTAB nTab, const tools::Rectangle& rMMRect, bool if (!aPosRect.IsEmpty()) { bEnd = false; - nTwips = static_cast<tools::Long>(aPosRect.Right() / HMM_PER_TWIPS); + nTwips = aPosRect.Right(); while (!bEnd) { - nAdd = static_cast<tools::Long>(pTable->GetColWidth(nX2, bHiddenAsZero)); + nAdd = pTable->GetColWidth(nX2, bHiddenAsZero); if (nSize+nAdd < nTwips && nX2<MaxCol()) { nSize += nAdd; @@ -1861,7 +1858,7 @@ ScRange ScDocument::GetRange( SCTAB nTab, const tools::Rectangle& rMMRect, bool } nSize = 0; - nTwips = static_cast<tools::Long>(aPosRect.Top() / HMM_PER_TWIPS); + nTwips = aPosRect.Top(); SCROW nY1 = 0; // Was if(nSize+nAdd<=nTwips+1) inside loop => if(nSize+nAdd<nTwips+2) @@ -1871,7 +1868,7 @@ ScRange ScDocument::GetRange( SCTAB nTab, const tools::Rectangle& rMMRect, bool SCROW nY2 = nY1; if (!aPosRect.IsEmpty()) { - nTwips = static_cast<tools::Long>(aPosRect.Bottom() / HMM_PER_TWIPS); + nTwips = aPosRect.Bottom(); // Was if(nSize+nAdd<nTwips) inside loop => if(nSize+nAdd<nTwips) if (lcl_AddTwipsWhile( nSize, nTwips, nY2, MaxRow(), pTable, bHiddenAsZero) && nY2 < MaxRow()) ++nY2; // original loop ended on last matched +1 unless that was rDoc.MaxRow() @@ -2014,10 +2011,7 @@ tools::Rectangle ScDocument::GetMMRect( SCCOL nStartCol, SCROW nStartRow, SCCOL aRect.AdjustRight(GetColWidth(i,nTab, bHiddenAsZero) ); aRect.AdjustBottom(GetRowHeight( nStartRow, nEndRow, nTab, bHiddenAsZero ) ); - aRect.SetLeft( static_cast<tools::Long>(aRect.Left() * HMM_PER_TWIPS) ); - aRect.SetRight( static_cast<tools::Long>(aRect.Right() * HMM_PER_TWIPS) ); - aRect.SetTop( static_cast<tools::Long>(aRect.Top() * HMM_PER_TWIPS) ); - aRect.SetBottom( static_cast<tools::Long>(aRect.Bottom() * HMM_PER_TWIPS) ); + aRect = o3tl::convert(aRect, o3tl::Length::twip, o3tl::Length::mm100); if ( IsNegativePage( nTab ) ) ScDrawLayer::MirrorRectRTL( aRect ); diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx index 27e860af94bc..8addc5060844 100644 --- a/sc/source/core/data/drwlayer.cxx +++ b/sc/source/core/data/drwlayer.cxx @@ -647,8 +647,8 @@ namespace Point lcl_calcAvailableDiff(const ScDocument &rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, const Point &aWantedDiff) { Point aAvailableDiff(aWantedDiff); - tools::Long nHeight = static_cast<tools::Long>(rDoc.GetRowHeight( nRow, nTab ) * HMM_PER_TWIPS); - tools::Long nWidth = static_cast<tools::Long>(rDoc.GetColWidth( nCol, nTab ) * HMM_PER_TWIPS); + tools::Long nHeight = o3tl::convert(rDoc.GetRowHeight( nRow, nTab ), o3tl::Length::twip, o3tl::Length::mm100); + tools::Long nWidth = o3tl::convert(rDoc.GetColWidth( nCol, nTab ), o3tl::Length::twip, o3tl::Length::mm100); if (aAvailableDiff.Y() > nHeight) aAvailableDiff.setY( nHeight ); if (aAvailableDiff.X() > nWidth) @@ -2124,10 +2124,8 @@ tools::Rectangle ScDrawLayer::GetCellRect( const ScDocument& rDoc, const ScAddre aBotRight.AdjustY(rDoc.GetRowHeight( rPos.Row(), aEndPos.Row(), rPos.Tab() ) ); // twips -> 1/100 mm - aTopLeft.setX( static_cast< tools::Long >( aTopLeft.X() * HMM_PER_TWIPS ) ); - aTopLeft.setY( static_cast< tools::Long >( aTopLeft.Y() * HMM_PER_TWIPS ) ); - aBotRight.setX( static_cast< tools::Long >( aBotRight.X() * HMM_PER_TWIPS ) ); - aBotRight.setY( static_cast< tools::Long >( aBotRight.Y() * HMM_PER_TWIPS ) ); + aTopLeft = o3tl::convert(aTopLeft, o3tl::Length::twip, o3tl::Length::mm100); + aBotRight = o3tl::convert(aBotRight, o3tl::Length::twip, o3tl::Length::mm100); aCellRect = tools::Rectangle( aTopLeft, aBotRight ); if( rDoc.IsNegativePage( rPos.Tab() ) ) diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index 1c32a670baf1..289c66f756d9 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -1692,7 +1692,7 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange ) tools::Long nBlkTwipsX = 0; if (bHeaders) - nBlkTwipsX += tools::Long(PRINT_HEADER_WIDTH); + nBlkTwipsX += PRINT_HEADER_WIDTH; SCCOL nStartCol = rRange.aStart.Col(); SCCOL nEndCol = rRange.aEnd.Col(); if ( pRepeatCol && nStartCol >= pRepeatCol->aStart.Col() ) @@ -1710,7 +1710,7 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange ) tools::Long nBlkTwipsY = 0; if (bHeaders) - nBlkTwipsY += tools::Long(PRINT_HEADER_HEIGHT); + nBlkTwipsY += PRINT_HEADER_HEIGHT; SCROW nStartRow = rRange.aStart.Row(); SCROW nEndRow = rRange.aEnd.Row(); if ( pRepeatRow && nStartRow >= pRepeatRow->aStart.Row() ) @@ -2259,7 +2259,7 @@ namespace { tools::Long SnapHorizontal( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCCOL& rStartCol ) { SCCOL nCol = 0; - tools::Long nTwips = static_cast<tools::Long>(nVal / HMM_PER_TWIPS); + tools::Long nTwips = o3tl::convert(nVal, o3tl::Length::mm100, o3tl::Length::twip); tools::Long nSnap = 0; while ( nCol<rDoc.MaxCol() ) { @@ -2272,7 +2272,7 @@ tools::Long SnapHorizontal( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal else break; } - nVal = static_cast<tools::Long>( nSnap * HMM_PER_TWIPS ); + nVal = o3tl::convert(nSnap, o3tl::Length::twip, o3tl::Length::mm100); rStartCol = nCol; return nVal; } @@ -2281,7 +2281,7 @@ tools::Long SnapHorizontal( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal tools::Long SnapVertical( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCROW& rStartRow ) { SCROW nRow = 0; - tools::Long nTwips = static_cast<tools::Long>(nVal / HMM_PER_TWIPS); + tools::Long nTwips = o3tl::convert(nVal, o3tl::Length::mm100, o3tl::Length::twip); tools::Long nSnap = 0; bool bFound = false; @@ -2310,7 +2310,7 @@ tools::Long SnapVertical( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, if (!bFound) nRow = rDoc.MaxRow(); // all hidden down to the bottom - nVal = static_cast<tools::Long>( nSnap * HMM_PER_TWIPS ); + nVal = o3tl::convert(nSnap, o3tl::Length::twip, o3tl::Length::mm100); rStartRow = nRow; return nVal; } diff --git a/sc/source/ui/inc/printfun.hxx b/sc/source/ui/inc/printfun.hxx index 9ad5c27e547b..b58acd9f4c52 100644 --- a/sc/source/ui/inc/printfun.hxx +++ b/sc/source/ui/inc/printfun.hxx @@ -42,8 +42,8 @@ class FmFormView; #define RANGENO_NORANGE USHRT_MAX -#define PRINT_HEADER_WIDTH (1.0 * TWIPS_PER_CM) -#define PRINT_HEADER_HEIGHT (12.8 * TWIPS_PER_POINT) +constexpr sal_Int64 PRINT_HEADER_WIDTH = o3tl::toTwips(1, o3tl::Length::cm); +constexpr sal_Int64 PRINT_HEADER_HEIGHT = o3tl::toTwips(12.8, o3tl::Length::pt); // Settings for headers/footers struct ScPrintHFParam diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 11016aafb202..162eb706c1ae 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -533,8 +533,8 @@ void ScModelObj::paintTile( VirtualDevice& rDevice, return; ScViewData* pActiveViewData = &pViewShell->GetViewData(); - Fraction aFracX(tools::Long(nOutputWidth * TWIPS_PER_PIXEL), nTileWidth); - Fraction aFracY(tools::Long(nOutputHeight * TWIPS_PER_PIXEL), nTileHeight); + Fraction aFracX(o3tl::toTwips(nOutputWidth, o3tl::Length::px), nTileWidth); + Fraction aFracY(o3tl::toTwips(nOutputHeight, o3tl::Length::px), nTileHeight); // Try to find a view that matches the tile-zoom requested by iterating over // first few shells. This is to avoid switching of zooms in ScGridWindow::PaintTile @@ -980,8 +980,8 @@ void ScModelObj::setClientZoom(int nTilePixelWidth_, int nTilePixelHeight_, int // Doing this in ScTabViewShell init code does not work because callbacks do not work at that point for the first view. lcl_sendLOKDocumentBackground(pViewData); - const Fraction newZoomX(nTilePixelWidth_ * TWIPS_PER_PIXEL, nTileTwipWidth_); - const Fraction newZoomY(nTilePixelHeight_ * TWIPS_PER_PIXEL, nTileTwipHeight_); + const Fraction newZoomX(o3tl::toTwips(nTilePixelWidth_, o3tl::Length::px), nTileTwipWidth_); + const Fraction newZoomY(o3tl::toTwips(nTilePixelHeight_, o3tl::Length::px), nTileTwipHeight_); if (pViewData->GetZoomX() == newZoomX && pViewData->GetZoomY() == newZoomY) return; diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx index 8da5ec78118a..31b0076bc0bc 100644 --- a/sc/source/ui/view/output2.cxx +++ b/sc/source/ui/view/output2.cxx @@ -91,6 +91,7 @@ using namespace com::sun::star; #define DRAWTEXT_MAX 32767 const sal_uInt16 SC_SHRINKAGAIN_MAX = 7; +constexpr auto HMM_PER_TWIPS = o3tl::convert(1.0, o3tl::Length::twip, o3tl::Length::mm100); class ScDrawStringsVars { diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx index eb7de664694b..ccd015552074 100644 --- a/sc/source/ui/view/printfun.cxx +++ b/sc/source/ui/view/printfun.cxx @@ -1564,9 +1564,7 @@ void ScPrintFunc::LocateArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, aTwipOffset.AdjustX( -(rDoc.GetColWidth( nCol, nPrintTab )) ); aTwipOffset.AdjustY( -sal_Int32(rDoc.GetRowHeight( 0, nY1-1, nPrintTab )) ); - Point aMMOffset( aTwipOffset ); - aMMOffset.setX( static_cast<tools::Long>(aMMOffset.X() * HMM_PER_TWIPS) ); - aMMOffset.setY( static_cast<tools::Long>(aMMOffset.Y() * HMM_PER_TWIPS) ); + Point aMMOffset(o3tl::convert(aTwipOffset, o3tl::Length::twip, o3tl::Length::mm100)); aMMOffset += Point( nLogStX, nLogStY ); MapMode aDrawMapMode( MapUnit::Map100thMM, aMMOffset, aLogicMode.GetScaleX(), aLogicMode.GetScaleY() ); @@ -2597,6 +2595,7 @@ void ScPrintFunc::InitModes() // set MapModes from nZoom etc. aOffset = Point( aSrcOffset.X()*100/nZoom, aSrcOffset.Y()*100/nZoom ); tools::Long nEffZoom = nZoom * static_cast<tools::Long>(nManualZoom); + constexpr auto HMM_PER_TWIPS = o3tl::convert(1.0, o3tl::Length::twip, o3tl::Length::mm100); nScaleX = nScaleY = HMM_PER_TWIPS; // output in 1/100 mm Fraction aZoomFract( nEffZoom,10000 ); diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index d4b4092291a1..6ac95430a84e 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -1730,6 +1730,7 @@ void ScViewData::SetEditEngine( ScSplitPos eWhich, // (and same line breaks) as for output. Fraction aFract(1,1); + constexpr auto HMM_PER_TWIPS = o3tl::convert(1.0, o3tl::Length::twip, o3tl::Length::mm100); tools::Rectangle aUtilRect = ScEditUtil(&mrDoc, nNewX, nNewY, nTabNo, Point(0, 0), pWin->GetOutDev(), HMM_PER_TWIPS, HMM_PER_TWIPS, aFract, aFract ).GetEditArea( pPattern, false ); aPaperSize.setWidth( aUtilRect.GetWidth() ); diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index 18447752a46f..0d5b2eed0ec8 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -3001,12 +3001,12 @@ DECLARE_ODFEXPORT_EXPORTONLY_TEST(tdf99631, "tdf99631.docx") { // check import of VisualArea settings of the embedded XLSX OLE objects xmlDocUniquePtr pXmlDoc = parseExport("Object 1/settings.xml"); - assertXPathContent(pXmlDoc, "//config:config-item[@config:name='VisibleAreaWidth']", "4515"); + assertXPathContent(pXmlDoc, "//config:config-item[@config:name='VisibleAreaWidth']", "4516"); assertXPathContent(pXmlDoc, "//config:config-item[@config:name='VisibleAreaHeight']", "903"); xmlDocUniquePtr pXmlDoc2 = parseExport("Object 2/settings.xml"); - assertXPathContent(pXmlDoc2, "//config:config-item[@config:name='VisibleAreaWidth']", "4515"); - assertXPathContent(pXmlDoc2, "//config:config-item[@config:name='VisibleAreaHeight']", "1354"); + assertXPathContent(pXmlDoc2, "//config:config-item[@config:name='VisibleAreaWidth']", "4516"); + assertXPathContent(pXmlDoc2, "//config:config-item[@config:name='VisibleAreaHeight']", "1355"); } DECLARE_ODFEXPORT_TEST(tdf128504, "tdf128504.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx index 8b00733fafb3..1416f59fcbc6 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx @@ -964,11 +964,11 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf99631) assertXPath(pXmlDoc, "//w:object", 2); assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:object", 2); // first XSLX OLE object (1:1 scale) - assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[1]/w:object[1]", "dxaOrig", "2560"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[1]/w:object[1]", "dxaOrig", "2561"); assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[1]/w:object[1]", "dyaOrig", "513"); // second XLSX OLE object (same content + 1 row, but zoomed) - assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:object[1]", "dxaOrig", "2560"); - assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:object[1]", "dyaOrig", "768"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:object[1]", "dxaOrig", "2561"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:object[1]", "dyaOrig", "769"); } CPPUNIT_TEST_FIXTURE(Test, testTdf138899)