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 /o3tl | |
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 'o3tl')
-rw-r--r-- | o3tl/qa/test-unit_conversion.cxx | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/o3tl/qa/test-unit_conversion.cxx b/o3tl/qa/test-unit_conversion.cxx index 983c0845a4cd..80b01ea2bf2b 100644 --- a/o3tl/qa/test-unit_conversion.cxx +++ b/o3tl/qa/test-unit_conversion.cxx @@ -869,4 +869,11 @@ static_assert(o3tl::convert(100, o3tl::Length::line, o3tl::Length::line) == 100) static_assert(o3tl::convert(49, o3tl::Length::mm100, o3tl::Length::mm) == 0); static_assert(o3tl::convert(50, o3tl::Length::mm100, o3tl::Length::mm) == 1); +// Conversions used in the code - to make sure they produce the expected and unchanged result + +static_assert(o3tl::toTwips(25, o3tl::Length::in100) == 1440 / 4); +static_assert(o3tl::toTwips(15, o3tl::Length::in100) == 216); +// the following twip value used to the constant for 20mm +static_assert(o3tl::toTwips(20, o3tl::Length::mm) == 1134); + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |