diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-02-05 09:36:59 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-02-05 17:04:00 +0100 |
commit | d7e5fa3bd8f4240665f13994589f5e72d362c097 (patch) | |
tree | 5709b7600d9f3ee8bec08b87e9b52f475990e16e /svx | |
parent | cb2a94a4a7ecb449d0731627ee6d58bd1b4e35f3 (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 'svx')
-rw-r--r-- | svx/source/table/tablertfexporter.cxx | 3 | ||||
-rw-r--r-- | svx/source/table/tablertfimporter.cxx | 3 | ||||
-rw-r--r-- | svx/source/unodraw/unoshape.cxx | 9 |
3 files changed, 9 insertions, 6 deletions
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: |