summaryrefslogtreecommitdiff
path: root/include/tools
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2018-05-04 03:40:11 +1000
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-05-08 20:35:18 +0200
commit6064e4f3b03411b8898804ba4dac389686791c67 (patch)
treebb517c6fc25698a65125f298089a90334c83f382 /include/tools
parent6b2fa7792a8e4feafb6920f0b289bf2c525d14e5 (diff)
tools: document and test sanitiseMm100ToTwip()
Change-Id: I2f6349c679a714e5168ae3c5eccd054c5522bbc9 Reviewed-on: https://gerrit.libreoffice.org/53814 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/tools')
-rw-r--r--include/tools/helpers.hxx16
1 files changed, 14 insertions, 2 deletions
diff --git a/include/tools/helpers.hxx b/include/tools/helpers.hxx
index 8325f095bad8..0a349ea62d1d 100644
--- a/include/tools/helpers.hxx
+++ b/include/tools/helpers.hxx
@@ -55,7 +55,19 @@ inline long FRound( double fVal )
return fVal > 0.0 ? static_cast<long>( fVal + 0.5 ) : -static_cast<long>( -fVal + 0.5 );
}
-// return (n >= 0)? (n*72+63)/127: (n*72-63)/127;
+/** Convert 100th-mm to twips
+
+ A twip is 1/20 of a point, one inch is equal to 72 points, and
+ one inch is 2,540 100th-mm.
+
+ Thus:
+ twips = n * 72 / 2,540 / 20
+ = n * 72 / 127
+
+ Adding 63 (half of 127) fixes truncation issues in int arithmetic.
+
+ This formula is (n>=0) ? (n*72+63) / 127 : (n*72-63) / 127
+ */
inline sal_Int64 sanitiseMm100ToTwip(sal_Int64 n)
{
if (n >= 0)
@@ -68,7 +80,7 @@ inline sal_Int64 sanitiseMm100ToTwip(sal_Int64 n)
if (o3tl::checked_multiply<sal_Int64>(n, 72, n) || o3tl::checked_sub<sal_Int64>(n, 63, n))
n = SAL_MIN_INT64;
}
- return n / 127;
+ return n / 127; // 127 is 2,540 100th-mm divided by 20pts
}
#endif