diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-07-23 08:44:14 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-08-10 03:02:52 +0200 |
commit | 9da7b1592e010928c26c43ee93b91cdd66403985 (patch) | |
tree | 213723545904c4c4549b7f635c4ac6182e0af06e /include | |
parent | eeeef98796df322d89912070c8e431c5f6d1283f (diff) |
sw: remove all uses of MM50 with (added) o3tl::toTwip
MM50 constant is the number of twips for 5mm. This is (ab)used as
a "shortcut" to set or compare various variables through the code
and also to set a multiplied value (like 1cm, 2cm, 4cm) or divided
value (2.5mm, 1.25mm). The problem with this is that converting the
5mm to twip doesn't round up exactly and multiplied and divided
values increase the error even more.
Instead of basing it from MM50 constant, it is just better to use
our o3tl::convert (or the added variant o3tl::toTwip), which can
actually calculate the conversion at compile time, so there is no
added complexity at runtime and we get a more readable code with
more exact result.
i.e.
o3tl::toTwip(4, o3tl::Length::cm)
instead of the more cryptic
MM50 * 8
In addition also sanitize and comment the values of the constants
in sw/inc/swtypes.hxx.
Change-Id: I85c306c36207d47ac3dc207094b68d0fb1ca5b70
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119397
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/o3tl/unit_conversion.hxx | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx index 4c76375737a2..cf293662e7b2 100644 --- a/include/o3tl/unit_conversion.hxx +++ b/include/o3tl/unit_conversion.hxx @@ -199,6 +199,12 @@ template <typename N, typename U> constexpr auto convert(N n, U from, U to) return convert(n, detail::md(from, to), detail::md(to, from)); } +// Convert to twips - for convenience as we do this a lot +template <typename N> constexpr auto toTwips(N number, Length from) +{ + return convert(number, from, Length::twip); +} + // Returns nDefault if intermediate multiplication overflows sal_Int64 (only for integral types). // On return, bOverflow indicates if overflow happened. nDefault is returned when overflow occurs. template <typename N, typename U> |