add some protocols that don't make sense as floating frame targets
[LibreOffice.git] / include / tools / UnitConversion.hxx
blob43237e0514c5523594bfbc5da4b7d9bfb2e91377
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 */
11 #pragma once
13 #include <o3tl/unit_conversion.hxx>
14 #include <sal/types.h>
15 #include <tools/fldunit.hxx>
16 #include <tools/fract.hxx>
17 #include <tools/mapunit.hxx>
19 constexpr o3tl::Length FieldToO3tlLength(FieldUnit eU, o3tl::Length ePixelValue = o3tl::Length::px)
21 switch (eU)
23 case FieldUnit::MM:
24 return o3tl::Length::mm;
25 case FieldUnit::CM:
26 return o3tl::Length::cm;
27 case FieldUnit::M:
28 return o3tl::Length::m;
29 case FieldUnit::KM:
30 return o3tl::Length::km;
31 case FieldUnit::TWIP:
32 return o3tl::Length::twip;
33 case FieldUnit::POINT:
34 return o3tl::Length::pt;
35 case FieldUnit::PICA:
36 return o3tl::Length::pc;
37 case FieldUnit::INCH:
38 return o3tl::Length::in;
39 case FieldUnit::FOOT:
40 return o3tl::Length::ft;
41 case FieldUnit::MILE:
42 return o3tl::Length::mi;
43 case FieldUnit::CHAR:
44 return o3tl::Length::ch;
45 case FieldUnit::LINE:
46 return o3tl::Length::line;
47 case FieldUnit::MM_100TH:
48 return o3tl::Length::mm100;
49 case FieldUnit::PIXEL:
50 return ePixelValue;
51 default:
52 return o3tl::Length::invalid;
56 constexpr o3tl::Length MapToO3tlLength(MapUnit eU, o3tl::Length ePixelValue = o3tl::Length::px)
58 switch (eU)
60 case MapUnit::Map100thMM:
61 return o3tl::Length::mm100;
62 case MapUnit::Map10thMM:
63 return o3tl::Length::mm10;
64 case MapUnit::MapMM:
65 return o3tl::Length::mm;
66 case MapUnit::MapCM:
67 return o3tl::Length::cm;
68 case MapUnit::Map1000thInch:
69 return o3tl::Length::in1000;
70 case MapUnit::Map100thInch:
71 return o3tl::Length::in100;
72 case MapUnit::Map10thInch:
73 return o3tl::Length::in10;
74 case MapUnit::MapInch:
75 return o3tl::Length::in;
76 case MapUnit::MapPoint:
77 return o3tl::Length::pt;
78 case MapUnit::MapTwip:
79 return o3tl::Length::twip;
80 case MapUnit::MapPixel:
81 return ePixelValue;
82 default:
83 return o3tl::Length::invalid;
87 inline Fraction conversionFract(o3tl::Length from, o3tl::Length to)
89 const auto & [ mul, div ] = o3tl::getConversionMulDiv(from, to);
90 return { mul, div };
93 template <typename N> constexpr auto convertTwipToMm100(N n)
95 return o3tl::convert(n, o3tl::Length::twip, o3tl::Length::mm100);
98 constexpr sal_Int64 sanitiseMm100ToTwip(sal_Int64 n)
100 return o3tl::convertSaturate(n, o3tl::Length::mm100, o3tl::Length::twip);
103 template <typename N> constexpr auto convertPointToMm100(N n)
105 return o3tl::convert(n, o3tl::Length::pt, o3tl::Length::mm100);
107 template <typename N> constexpr auto convertMm100ToPoint(N n)
109 return o3tl::convert(n, o3tl::Length::mm100, o3tl::Length::pt);
112 // PPT's "master unit" (1/576 inch) <=> mm/100
113 template <typename N> constexpr auto convertMasterUnitToMm100(N n)
115 return o3tl::convert(n, o3tl::Length::master, o3tl::Length::mm100);
117 template <typename N> constexpr auto convertMm100ToMasterUnit(N n)
119 return o3tl::convert(n, o3tl::Length::mm100, o3tl::Length::master);
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */