LibreOffice Module tools (master) 1
UnitConversion.hxx
Go to the documentation of this file.
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
14#include <sal/types.h>
15#include <tools/fldunit.hxx>
16#include <tools/fract.hxx>
17#include <tools/mapunit.hxx>
18
20{
21 switch (eU)
22 {
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;
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;
50 return ePixelValue;
51 default:
53 }
54}
55
57{
58 switch (eU)
59 {
63 return o3tl::Length::mm10;
64 case MapUnit::MapMM:
65 return o3tl::Length::mm;
66 case MapUnit::MapCM:
67 return o3tl::Length::cm;
73 return o3tl::Length::in10;
75 return o3tl::Length::in;
77 return o3tl::Length::pt;
79 return o3tl::Length::twip;
81 return ePixelValue;
82 default:
84 }
85}
86
88{
89 const auto & [ mul, div ] = o3tl::getConversionMulDiv(from, to);
90 return { mul, div };
91}
92
93template <typename N> constexpr auto convertTwipToMm100(N n)
94{
96}
97
98constexpr sal_Int64 sanitiseMm100ToTwip(sal_Int64 n)
99{
101}
102
103template <typename N> constexpr auto convertPointToMm100(N n)
104{
106}
107template <typename N> constexpr auto convertMm100ToPoint(N n)
108{
110}
111
112// PPT's "master unit" (1/576 inch) <=> mm/100
113template <typename N> constexpr auto convertMasterUnitToMm100(N n)
114{
116}
117template <typename N> constexpr auto convertMm100ToMasterUnit(N n)
118{
120}
121
122/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr auto convertMasterUnitToMm100(N n)
Fraction conversionFract(o3tl::Length from, o3tl::Length to)
constexpr o3tl::Length FieldToO3tlLength(FieldUnit eU, o3tl::Length ePixelValue=o3tl::Length::px)
constexpr auto convertMm100ToMasterUnit(N n)
constexpr sal_Int64 sanitiseMm100ToTwip(sal_Int64 n)
constexpr auto convertPointToMm100(N n)
constexpr o3tl::Length MapToO3tlLength(MapUnit eU, o3tl::Length ePixelValue=o3tl::Length::px)
constexpr auto convertMm100ToPoint(N n)
constexpr auto convertTwipToMm100(N n)
UBlockCode from
To to(Degree< IofFrom, NofFrom > x)
conversion functions
Definition: degree.hxx:50
FieldUnit
Definition: fldunit.hxx:26
sal_Int64 n
MapUnit
Definition: mapunit.hxx:24
@ Map100thInch
@ Map1000thInch
constexpr auto convert(N n, sal_Int64 mul, sal_Int64 div)
constexpr auto convertSaturate(N n, U from, U to)
double div(const double &fNumerator, const double &fDenominator)