tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / oox / source / drawingml / presetgeometrynames.cxx
blobfd2807f9d1a02dee94a0edd93f7a2080993c4fde
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <rtl/string.hxx>
11 #include <rtl/ustring.hxx>
12 #include <unordered_map>
13 #include <cstring>
14 #include <drawingml/presetgeometrynames.hxx>
15 #include <memory>
17 namespace
19 typedef std::unordered_map<const char*, const char*, rtl::CStringHash, rtl::CStringEqual>
20 PresetGeometryHashMap;
22 struct PresetGeometryName
24 const char* pMsoName;
25 const char* pFontworkType;
28 const PresetGeometryName pPresetGeometryNameArray[]
29 = { { "textNoShape", "" },
30 { "textPlain", "fontwork-plain-text" },
31 { "textStop", "fontwork-stop" },
32 { "textTriangle", "fontwork-triangle-up" },
33 { "textTriangleInverted", "fontwork-triangle-down" },
34 { "textChevron", "fontwork-chevron-up" },
35 { "textChevronInverted", "fontwork-chevron-down" },
36 { "textRingInside", "mso-spt142" },
37 { "textRingOutside", "mso-spt143" },
38 { "textArchUp", "fontwork-arch-up-curve" },
39 { "textArchDown", "fontwork-arch-down-curve" },
40 { "textCircle", "fontwork-circle-curve" },
41 { "textButton", "fontwork-open-circle-curve" },
42 { "textArchUpPour", "fontwork-arch-up-pour" },
43 { "textArchDownPour", "fontwork-arch-down-pour" },
44 { "textCirclePour", "fontwork-circle-pour" },
45 { "textButtonPour", "fontwork-open-circle-pour" },
46 { "textCurveUp", "fontwork-curve-up" },
47 { "textCurveDown", "fontwork-curve-down" },
48 { "textCanUp", "mso-spt174" },
49 { "textCanDown", "mso-spt175" },
50 { "textWave1", "fontwork-wave" },
51 { "textWave2", "mso-spt157" },
52 { "textDoubleWave1", "mso-spt158" },
53 { "textWave4", "mso-spt159" },
54 { "textInflate", "fontwork-inflate" },
55 { "textDeflate", "mso-spt161" },
56 { "textInflateBottom", "mso-spt162" },
57 { "textDeflateBottom", "mso-spt163" },
58 { "textInflateTop", "mso-spt164" },
59 { "textDeflateTop", "mso-spt165" },
60 { "textDeflateInflate", "mso-spt166" },
61 { "textDeflateInflateDeflate", "mso-spt167" },
62 { "textFadeRight", "fontwork-fade-right" },
63 { "textFadeLeft", "fontwork-fade-left" },
64 { "textFadeUp", "fontwork-fade-up" },
65 { "textFadeDown", "fontwork-fade-down" },
66 { "textSlantUp", "fontwork-slant-up" },
67 { "textSlantDown", "fontwork-slant-down" },
68 { "textCascadeUp", "fontwork-fade-up-and-right" },
69 { "textCascadeDown", "fontwork-fade-up-and-left" } };
72 OUString PresetGeometryTypeNames::GetFontworkType(std::u16string_view rMsoType)
74 static const PresetGeometryHashMap s_HashMap = []() {
75 PresetGeometryHashMap aH;
76 for (const auto& item : pPresetGeometryNameArray)
77 aH[item.pMsoName] = item.pFontworkType;
78 return aH;
79 }();
80 const char* pRetValue = "";
81 size_t i, nLen = rMsoType.size();
82 std::unique_ptr<char[]> pBuf(new char[nLen + 1]);
83 for (i = 0; i < nLen; i++)
84 pBuf[i] = static_cast<char>(rMsoType[i]);
85 pBuf[i] = 0;
86 PresetGeometryHashMap::const_iterator aHashIter(s_HashMap.find(pBuf.get()));
87 if (aHashIter != s_HashMap.end())
88 pRetValue = (*aHashIter).second;
90 return OUString(pRetValue, strlen(pRetValue), RTL_TEXTENCODING_ASCII_US);
93 OUString PresetGeometryTypeNames::GetMsoName(std::u16string_view rFontworkType)
95 static const PresetGeometryHashMap s_HashMapInv = []() {
96 PresetGeometryHashMap aHInv;
97 for (const auto& item : pPresetGeometryNameArray)
98 aHInv[item.pFontworkType] = item.pMsoName;
99 return aHInv;
100 }();
101 const char* pRetValue = "";
102 size_t i, nLen = rFontworkType.size();
103 std::unique_ptr<char[]> pBuf(new char[nLen + 1]);
104 for (i = 0; i < nLen; i++)
105 pBuf[i] = static_cast<char>(rFontworkType[i]);
106 pBuf[i] = 0;
107 PresetGeometryHashMap::const_iterator aHashIter(s_HashMapInv.find(pBuf.get()));
108 if (aHashIter != s_HashMapInv.end())
109 pRetValue = (*aHashIter).second;
111 return OUString(pRetValue, strlen(pRetValue), RTL_TEXTENCODING_ASCII_US);
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */