LibreOffice Module oox (master) 1
presetgeometrynames.cxx
Go to the documentation of this file.
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>
15#include <memory>
16
17namespace
18{
19typedef std::unordered_map<const char*, const char*, rtl::CStringHash, rtl::CStringEqual>
20 PresetGeometryHashMap;
21
22struct PresetGeometryName
23{
24 const char* pMsoName;
25 const char* pFontworkType;
26};
27
28const 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
72OUString PresetGeometryTypeNames::GetFontworkType(const OUString& rMsoType)
73{
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 int i, nLen = rMsoType.getLength();
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;
89
90 return OUString(pRetValue, strlen(pRetValue), RTL_TEXTENCODING_ASCII_US);
91}
92
93OUString PresetGeometryTypeNames::GetMsoName(const OUString& rFontworkType)
94{
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 int i, nLen = rFontworkType.getLength();
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;
110
111 return OUString(pRetValue, strlen(pRetValue), RTL_TEXTENCODING_ASCII_US);
112}
113
114/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
OUString GetFontworkType(const OUString &rMsoType)
OUString GetMsoName(const OUString &rFontworkType)