/src/libreoffice/include/tools/UnitConversion.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | */ |
10 | | |
11 | | #pragma once |
12 | | |
13 | | #include <o3tl/unit_conversion.hxx> |
14 | | #include <sal/types.h> |
15 | | #include <tools/fract.hxx> |
16 | | |
17 | | inline Fraction conversionFract(o3tl::Length from, o3tl::Length to) |
18 | 11.2M | { |
19 | 11.2M | const auto[mul, div] = o3tl::getConversionMulDiv(from, to); |
20 | 11.2M | return { mul, div }; |
21 | 11.2M | } |
22 | | |
23 | | template <typename N> constexpr auto convertTwipToMm100(N n) |
24 | 2.38M | { |
25 | 2.38M | using namespace o3tl; // Allow ADL find overloads e.g. in <tools/gen.hxx> |
26 | 2.38M | return convert(n, o3tl::Length::twip, o3tl::Length::mm100); |
27 | 2.38M | } auto convertTwipToMm100<int>(int) Line | Count | Source | 24 | 715k | { | 25 | 715k | using namespace o3tl; // Allow ADL find overloads e.g. in <tools/gen.hxx> | 26 | 715k | return convert(n, o3tl::Length::twip, o3tl::Length::mm100); | 27 | 715k | } |
auto convertTwipToMm100<unsigned short>(unsigned short) Line | Count | Source | 24 | 9.42k | { | 25 | 9.42k | using namespace o3tl; // Allow ADL find overloads e.g. in <tools/gen.hxx> | 26 | 9.42k | return convert(n, o3tl::Length::twip, o3tl::Length::mm100); | 27 | 9.42k | } |
auto convertTwipToMm100<double>(double) Line | Count | Source | 24 | 4.50k | { | 25 | 4.50k | using namespace o3tl; // Allow ADL find overloads e.g. in <tools/gen.hxx> | 26 | 4.50k | return convert(n, o3tl::Length::twip, o3tl::Length::mm100); | 27 | 4.50k | } |
auto convertTwipToMm100<long>(long) Line | Count | Source | 24 | 810k | { | 25 | 810k | using namespace o3tl; // Allow ADL find overloads e.g. in <tools/gen.hxx> | 26 | 810k | return convert(n, o3tl::Length::twip, o3tl::Length::mm100); | 27 | 810k | } |
auto convertTwipToMm100<unsigned int>(unsigned int) Line | Count | Source | 24 | 766k | { | 25 | 766k | using namespace o3tl; // Allow ADL find overloads e.g. in <tools/gen.hxx> | 26 | 766k | return convert(n, o3tl::Length::twip, o3tl::Length::mm100); | 27 | 766k | } |
Unexecuted instantiation: auto convertTwipToMm100<Point>(Point) auto convertTwipToMm100<short>(short) Line | Count | Source | 24 | 73.3k | { | 25 | 73.3k | using namespace o3tl; // Allow ADL find overloads e.g. in <tools/gen.hxx> | 26 | 73.3k | return convert(n, o3tl::Length::twip, o3tl::Length::mm100); | 27 | 73.3k | } |
Unexecuted instantiation: auto convertTwipToMm100<signed char>(signed char) Unexecuted instantiation: auto convertTwipToMm100<Size>(Size) auto convertTwipToMm100<unsigned long>(unsigned long) Line | Count | Source | 24 | 50 | { | 25 | 50 | using namespace o3tl; // Allow ADL find overloads e.g. in <tools/gen.hxx> | 26 | 50 | return convert(n, o3tl::Length::twip, o3tl::Length::mm100); | 27 | 50 | } |
|
28 | | |
29 | | constexpr sal_Int64 sanitiseMm100ToTwip(sal_Int64 n) |
30 | 52.7k | { |
31 | 52.7k | return o3tl::convertSaturate(n, o3tl::Length::mm100, o3tl::Length::twip); |
32 | 52.7k | } |
33 | | |
34 | | template <typename N> constexpr auto convertPointToMm100(N n) |
35 | 468k | { |
36 | 468k | return o3tl::convert(n, o3tl::Length::pt, o3tl::Length::mm100); |
37 | 468k | } auto convertPointToMm100<double>(double) Line | Count | Source | 35 | 48 | { | 36 | 48 | return o3tl::convert(n, o3tl::Length::pt, o3tl::Length::mm100); | 37 | 48 | } |
Unexecuted instantiation: auto convertPointToMm100<float>(float) Unexecuted instantiation: auto convertPointToMm100<long>(long) Unexecuted instantiation: auto convertPointToMm100<int>(int) Unexecuted instantiation: auto convertPointToMm100<short>(short) auto convertPointToMm100<unsigned long>(unsigned long) Line | Count | Source | 35 | 468k | { | 36 | 468k | return o3tl::convert(n, o3tl::Length::pt, o3tl::Length::mm100); | 37 | 468k | } |
|
38 | | template <typename N> constexpr auto convertMm100ToPoint(N n) |
39 | 0 | { |
40 | 0 | return o3tl::convert(n, o3tl::Length::mm100, o3tl::Length::pt); |
41 | 0 | } Unexecuted instantiation: auto convertMm100ToPoint<float>(float) Unexecuted instantiation: auto convertMm100ToPoint<double>(double) Unexecuted instantiation: auto convertMm100ToPoint<unsigned int>(unsigned int) |
42 | | |
43 | | // PPT's "master unit" (1/576 inch) <=> mm/100 |
44 | | template <typename N> constexpr auto convertMasterUnitToMm100(N n) |
45 | 4.28M | { |
46 | 4.28M | return o3tl::convert(n, o3tl::Length::master, o3tl::Length::mm100); |
47 | 4.28M | } auto convertMasterUnitToMm100<unsigned int>(unsigned int) Line | Count | Source | 45 | 3.93M | { | 46 | 3.93M | return o3tl::convert(n, o3tl::Length::master, o3tl::Length::mm100); | 47 | 3.93M | } |
auto convertMasterUnitToMm100<int>(int) Line | Count | Source | 45 | 345k | { | 46 | 345k | return o3tl::convert(n, o3tl::Length::master, o3tl::Length::mm100); | 47 | 345k | } |
Unexecuted instantiation: auto convertMasterUnitToMm100<double>(double) |
48 | | template <typename N> constexpr auto convertMm100ToMasterUnit(N n) |
49 | 0 | { |
50 | 0 | return o3tl::convert(n, o3tl::Length::mm100, o3tl::Length::master); |
51 | 0 | } Unexecuted instantiation: auto convertMm100ToMasterUnit<short>(short) Unexecuted instantiation: auto convertMm100ToMasterUnit<int>(int) Unexecuted instantiation: auto convertMm100ToMasterUnit<double>(double) |
52 | | |
53 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |