svtools/source/misc/unitconv.cxx |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit f7e52df2dde0b80f33123790681e94785154d566
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Jun 12 12:23:17 2023 +0300
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Jun 14 10:58:08 2023 +0200

    tdf#154349: round before converting to an integer
    
    Commit cfff893b9c82843a90aac4ecdb3a3936721b74a0 (Move unit conversion
    code to o3tl, and unify on that in more places, 2021-02-14) changed a
    custom conversion code in CalcToUnit doing inexact conversion from
    points to mm/20 (with "* 10 / 567"), with correct conversion function.
    A side effect was, however, that the imprecise arithmetics provided
    floating-point values that rounded down to correct integers (or maybe
    it was all the chain of calculations down to this function), while
    the correctly converted values could round down to a smaller value.
    
    Fix this problem using rounding.
    
    Change-Id: I42e0d56b068832ef309f6b696f661642e62ddacb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152894
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit cf0fe26f95b5435d65623165cf7ba381eaa0738a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152981
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/svtools/source/misc/unitconv.cxx b/svtools/source/misc/unitconv.cxx
index 395c1b4ac810..cb4fdf6901dd 100644
--- a/svtools/source/misc/unitconv.cxx
+++ b/svtools/source/misc/unitconv.cxx
@@ -128,7 +128,7 @@ tools::Long CalcToUnit( float nIn, MapUnit eUnit )
                 eUnit == MapUnit::MapCM, "this unit is not implemented" );
 
     if (const auto eTo = MapToO3tlLength(eUnit); eTo != o3tl::Length::invalid)
-        return o3tl::convert(nIn, o3tl::Length::pt, eTo);
+        return std::round(o3tl::convert(nIn, o3tl::Length::pt, eTo));
 
     return 0;
 }

Reply via email to