From 0e29e9ea7f4fe58d8dbdc7a9b9f58543a93d5bf5 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Sun, 17 May 2020 20:12:33 +0200 Subject: vcl: add conversion point to 100th mm for double values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Integer conversion throws away percision, which is problematic when we work with floating point values. Change-Id: Ib34e46bd59aa67e933d49bc800e96cc6426414e5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95260 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- include/tools/UnitConversion.hxx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/tools/UnitConversion.hxx b/include/tools/UnitConversion.hxx index e59077d8a5fa..2093db6181d9 100644 --- a/include/tools/UnitConversion.hxx +++ b/include/tools/UnitConversion.hxx @@ -15,13 +15,18 @@ constexpr sal_Int64 convertTwipToMm100(sal_Int64 n) return (n >= 0) ? (n * 127 + 36) / 72 : (n * 127 - 36) / 72; } -constexpr sal_Int64 convertPointToMm100(sal_Int64 n) { return convertTwipToMm100(n * 20); } - constexpr sal_Int64 convertMm100ToTwip(sal_Int64 n) { return (n >= 0) ? (n * 72 + 63) / 127 : (n * 72 - 63) / 127; } +constexpr sal_Int64 convertPointToMm100(sal_Int64 nNumber) +{ + return convertTwipToMm100(nNumber * 20); +} + +constexpr double convertPointToMm100(double fNumber) { return fNumber * 35.27777777778; } + // Convert PPT's "master unit" (1/576 inch) to twips constexpr sal_Int64 convertMasterUnitToTwip(sal_Int64 n) { return n * 2540.0 / 576.0; } -- cgit