/src/libreoffice/oox/source/drawingml/presetgeometrynames.cxx
Line | Count | Source |
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. |
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 | | #include <rtl/string.hxx> |
11 | | #include <rtl/ustring.hxx> |
12 | | #include <unordered_map> |
13 | | #include <cstring> |
14 | | #include <drawingml/presetgeometrynames.hxx> |
15 | | #include <memory> |
16 | | |
17 | | namespace |
18 | | { |
19 | | typedef std::unordered_map<const char*, const char*, rtl::CStringHash, rtl::CStringEqual> |
20 | | PresetGeometryHashMap; |
21 | | |
22 | | struct PresetGeometryName |
23 | | { |
24 | | const char* pMsoName; |
25 | | const char* pFontworkType; |
26 | | }; |
27 | | |
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" } }; |
70 | | } |
71 | | |
72 | | OUString PresetGeometryTypeNames::GetFontworkType(std::u16string_view rMsoType) |
73 | 0 | { |
74 | 0 | static const PresetGeometryHashMap s_HashMap = []() { |
75 | 0 | PresetGeometryHashMap aH; |
76 | 0 | for (const auto& item : pPresetGeometryNameArray) |
77 | 0 | aH[item.pMsoName] = item.pFontworkType; |
78 | 0 | return aH; |
79 | 0 | }(); |
80 | 0 | const char* pRetValue = ""; |
81 | 0 | size_t i, nLen = rMsoType.size(); |
82 | 0 | std::unique_ptr<char[]> pBuf(new char[nLen + 1]); |
83 | 0 | for (i = 0; i < nLen; i++) |
84 | 0 | pBuf[i] = static_cast<char>(rMsoType[i]); |
85 | 0 | pBuf[i] = 0; |
86 | 0 | PresetGeometryHashMap::const_iterator aHashIter(s_HashMap.find(pBuf.get())); |
87 | 0 | if (aHashIter != s_HashMap.end()) |
88 | 0 | pRetValue = (*aHashIter).second; |
89 | |
|
90 | 0 | return OUString(pRetValue, strlen(pRetValue), RTL_TEXTENCODING_ASCII_US); |
91 | 0 | } |
92 | | |
93 | | OUString PresetGeometryTypeNames::GetMsoName(std::u16string_view rFontworkType) |
94 | 0 | { |
95 | 0 | static const PresetGeometryHashMap s_HashMapInv = []() { |
96 | 0 | PresetGeometryHashMap aHInv; |
97 | 0 | for (const auto& item : pPresetGeometryNameArray) |
98 | 0 | aHInv[item.pFontworkType] = item.pMsoName; |
99 | 0 | return aHInv; |
100 | 0 | }(); |
101 | 0 | const char* pRetValue = ""; |
102 | 0 | size_t i, nLen = rFontworkType.size(); |
103 | 0 | std::unique_ptr<char[]> pBuf(new char[nLen + 1]); |
104 | 0 | for (i = 0; i < nLen; i++) |
105 | 0 | pBuf[i] = static_cast<char>(rFontworkType[i]); |
106 | 0 | pBuf[i] = 0; |
107 | 0 | PresetGeometryHashMap::const_iterator aHashIter(s_HashMapInv.find(pBuf.get())); |
108 | 0 | if (aHashIter != s_HashMapInv.end()) |
109 | 0 | pRetValue = (*aHashIter).second; |
110 | |
|
111 | 0 | return OUString(pRetValue, strlen(pRetValue), RTL_TEXTENCODING_ASCII_US); |
112 | 0 | } |
113 | | |
114 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |