tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / oox / source / export / ColorExportUtils.cxx
blobd46ab493b5ab5fac7c3271b6ceba81ff7650ae36
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/.
8 */
10 #include <sal/config.h>
11 #include <array>
12 #include <oox/export/ColorExportUtils.hxx>
13 #include <docmodel/color/ComplexColor.hxx>
15 namespace oox
17 double convertColorTransformsToTintOrShade(model::ComplexColor const& rComplexColor)
19 sal_Int16 nLumMod = 10'000;
20 sal_Int16 nLumOff = 0;
22 for (auto const& rTransform : rComplexColor.getTransformations())
24 if (rTransform.meType == model::TransformationType::LumMod)
25 nLumMod = rTransform.mnValue;
26 if (rTransform.meType == model::TransformationType::LumOff)
27 nLumOff = rTransform.mnValue;
30 if (nLumMod == 10'000 && nLumOff == 0)
31 return 0.0;
33 double fTint = 0.0;
35 if (nLumOff > 0) // tint
36 fTint = double(nLumOff) / 10'000.0;
37 else
38 fTint = -double(10'000 - nLumMod) / 10'000.0;
40 return fTint;
43 sal_Int32 convertThemeColorTypeToExcelThemeNumber(model::ThemeColorType eType)
45 if (eType == model::ThemeColorType::Unknown)
46 return -1;
48 // Change position of text1 and text2 and background1 and background2 - needed because of an bug in excel, where
49 // the text and background index positions are switched.
50 // 0 -> 1, 1 -> 0
51 // 2 -> 3, 3 -> 2
52 // everything else stays the same
53 static constexpr std::array<sal_Int32, 12> constThemeColorMapToXmlMap
54 = { 1, 0, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11 };
56 return constThemeColorMapToXmlMap[sal_Int32(eType)];
58 } // end oox
60 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */