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