summaryrefslogtreecommitdiff
path: root/sc/qa
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-02-05 09:36:59 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-02-05 17:04:00 +0100
commitd7e5fa3bd8f4240665f13994589f5e72d362c097 (patch)
tree5709b7600d9f3ee8bec08b87e9b52f475990e16e /sc/qa
parentcb2a94a4a7ecb449d0731627ee6d58bd1b4e35f3 (diff)
Make sanitiseMm100ToTwip simpler and more correct
The result's absolute value is always smaller than n. Returning an uncorrected value taken from reversing multiplication and division order when intermediate value would overflow is better than arbitrary constant. Also further deduplicate Twips <-> 100th-mm conversion, and make sure they all are in a single header. Using conversion implementation that handles negatives correctly improves accuracy, as seen in unit tests; e.g. in testPictureEffectPreservation (the original doc had "dir" equal to "8100000", while we tested that it was "8076614" after roundtrip). Change-Id: Icd027af6238a9f45f916f53f8684506cc959e696 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110433 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc/qa')
-rw-r--r--sc/qa/unit/helper/qahelper.cxx5
-rw-r--r--sc/qa/unit/subsequent_filters-test.cxx7
-rw-r--r--sc/qa/unit/ucalc.cxx9
3 files changed, 12 insertions, 9 deletions
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 );