summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-05-01 17:20:26 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-07-29 18:32:22 +0200
commit001ef8612d938299781dec4730ae702082d18a24 (patch)
tree5a08eecf6e7651ee24fb6a4fb7f35be5036478d4 /include
parente0af7e85eb3b99cceb8302b3ff0a7656816b6174 (diff)
move unit conversions to UnitConversion, add convertPointToMm100
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93332 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit 09e28008376e2f2a187067409d3076e81eba022e) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95783 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit fab4420f23ae77f8c7266d4b4d44313f2e3129d8) Change-Id: I3e5a4632e9809562885c1e0ec5c5262acec145d0
Diffstat (limited to 'include')
-rw-r--r--include/tools/UnitConversion.hxx31
-rw-r--r--include/tools/mapunit.hxx11
2 files changed, 32 insertions, 10 deletions
diff --git a/include/tools/UnitConversion.hxx b/include/tools/UnitConversion.hxx
new file mode 100644
index 000000000000..e59077d8a5fa
--- /dev/null
+++ b/include/tools/UnitConversion.hxx
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+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;
+}
+
+// Convert PPT's "master unit" (1/576 inch) to twips
+constexpr sal_Int64 convertMasterUnitToTwip(sal_Int64 n) { return n * 2540.0 / 576.0; }
+
+// Convert twips to PPT's "master unit"
+constexpr sal_Int64 convertTwipToMasterUnit(sal_Int64 n) { return n / (2540.0 / 576.0); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/tools/mapunit.hxx b/include/tools/mapunit.hxx
index 2209f4d35261..6112bc7ef461 100644
--- a/include/tools/mapunit.hxx
+++ b/include/tools/mapunit.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_TOOLS_MAPUNIT_HXX
#include <sal/types.h>
+#include <tools/UnitConversion.hxx>
enum class MapUnit
{
@@ -34,16 +35,6 @@ enum class MapUnit
LASTENUMDUMMY // used as an error return
};
-constexpr sal_Int64 convertTwipToMm100(sal_Int64 n)
-{
- return (n >= 0)? (n*127+36)/72: (n*127-36)/72;
-}
-
-constexpr sal_Int64 convertMm100ToTwip(sal_Int64 n)
-{
- return (n >= 0)? (n*72+63)/127: (n*72-63)/127;
-}
-
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */