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 /xmloff | |
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 'xmloff')
-rw-r--r-- | xmloff/source/transform/TransformerBase.cxx | 13 |
1 files changed, 3 insertions, 10 deletions
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, |