1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
)
24 return o3tl::Length::mm
;
26 return o3tl::Length::cm
;
28 return o3tl::Length::m
;
30 return o3tl::Length::km
;
32 return o3tl::Length::twip
;
33 case FieldUnit::POINT
:
34 return o3tl::Length::pt
;
36 return o3tl::Length::pc
;
38 return o3tl::Length::in
;
40 return o3tl::Length::ft
;
42 return o3tl::Length::mi
;
44 return o3tl::Length::ch
;
46 return o3tl::Length::line
;
47 case FieldUnit::MM_100TH
:
48 return o3tl::Length::mm100
;
49 case FieldUnit::PIXEL
:
52 return o3tl::Length::invalid
;
56 constexpr o3tl::Length
MapToO3tlLength(MapUnit eU
, o3tl::Length ePixelValue
= o3tl::Length::px
)
60 case MapUnit::Map100thMM
:
61 return o3tl::Length::mm100
;
62 case MapUnit::Map10thMM
:
63 return o3tl::Length::mm10
;
65 return o3tl::Length::mm
;
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
:
83 return o3tl::Length::invalid
;
87 inline Fraction
conversionFract(o3tl::Length from
, o3tl::Length to
)
89 const auto & [ mul
, div
] = o3tl::getConversionMulDiv(from
, to
);
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: */