LibreOffice Module svx (master) 1
presetooxhandleadjustmentrelations.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 <sal/config.h>
11
12#include <string_view>
13
14#include <o3tl/string_view.hxx>
15#include <rtl/ustring.hxx>
16#include <unordered_map>
18
19namespace
20{
21typedef std::unordered_map<OUString, OUString> HandleAdjRelHashMap;
22
23struct HandleAdjRel
24{
25 // Shape name without leading "ooxml-", underscore, zero based handle index
26 // e.g. The third handle in shape of type "ooxml-circularArrow" will be
27 // identified by key "circularArrow_2"
28 const char* sShape_Handle;
29
30 // 4 tokens with separator "|"
31 // first: RefX or RefR, na if not exists
32 // second: adj, or adj1 or adj2, etc. as in preset, na if not exists
33 // third: RefY or RefAngle, na if not exists
34 // forth: adj, or adj1 or adj2, etc. as in preset, na if not exists
35 // e.g. The third handle in shape <circularArrow> has in the preset
36 // the tag <ahPolar gdRefR="adj5" minR="0" maxR="25000"> .
37 // The resulting value in the map here is "RefR|adj5|na|na"
38 const char* sAdjReferences;
39};
40
41// The array initializer has been extracted from
42// oox/source/drawingml/customshapes/presetShapeDefinitions.xml
43// by using an XSLT file. That file is attached to tdf#126512.
44constexpr HandleAdjRel aHandleAdjRelArray[]
45 = { { "accentBorderCallout1_0", "RefX|adj2|RefY|adj1" },
46 { "accentBorderCallout1_1", "RefX|adj4|RefY|adj3" },
47 { "accentBorderCallout2_0", "RefX|adj2|RefY|adj1" },
48 { "accentBorderCallout2_1", "RefX|adj4|RefY|adj3" },
49 { "accentBorderCallout2_2", "RefX|adj6|RefY|adj5" },
50 { "accentBorderCallout3_0", "RefX|adj2|RefY|adj1" },
51 { "accentBorderCallout3_1", "RefX|adj4|RefY|adj3" },
52 { "accentBorderCallout3_2", "RefX|adj6|RefY|adj5" },
53 { "accentBorderCallout3_3", "RefX|adj8|RefY|adj7" },
54 { "accentCallout1_0", "RefX|adj2|RefY|adj1" },
55 { "accentCallout1_1", "RefX|adj4|RefY|adj3" },
56 { "accentCallout2_0", "RefX|adj2|RefY|adj1" },
57 { "accentCallout2_1", "RefX|adj4|RefY|adj3" },
58 { "accentCallout2_2", "RefX|adj6|RefY|adj5" },
59 { "accentCallout3_0", "RefX|adj2|RefY|adj1" },
60 { "accentCallout3_1", "RefX|adj4|RefY|adj3" },
61 { "accentCallout3_2", "RefX|adj6|RefY|adj5" },
62 { "accentCallout3_3", "RefX|adj8|RefY|adj7" },
63 { "arc_0", "na|na|RefAngle|adj1" },
64 { "arc_1", "na|na|RefAngle|adj2" },
65 { "bentArrow_0", "RefX|adj1|na|na" },
66 { "bentArrow_1", "na|na|RefY|adj2" },
67 { "bentArrow_2", "RefX|adj3|na|na" },
68 { "bentArrow_3", "RefX|adj4|na|na" },
69 { "bentConnector3_0", "RefX|adj1|na|na" },
70 { "bentConnector4_0", "RefX|adj1|na|na" },
71 { "bentConnector4_1", "na|na|RefY|adj2" },
72 { "bentConnector5_0", "RefX|adj1|na|na" },
73 { "bentConnector5_1", "na|na|RefY|adj2" },
74 { "bentConnector5_2", "RefX|adj3|na|na" },
75 { "bentUpArrow_0", "na|na|RefY|adj1" },
76 { "bentUpArrow_1", "RefX|adj2|na|na" },
77 { "bentUpArrow_2", "na|na|RefY|adj3" },
78 { "bevel_0", "RefX|adj|na|na" },
79 { "blockArc_0", "na|na|RefAngle|adj1" },
80 { "blockArc_1", "RefR|adj3|RefAngle|adj2" },
81 { "borderCallout1_0", "RefX|adj2|RefY|adj1" },
82 { "borderCallout1_1", "RefX|adj4|RefY|adj3" },
83 { "borderCallout2_0", "RefX|adj2|RefY|adj1" },
84 { "borderCallout2_1", "RefX|adj4|RefY|adj3" },
85 { "borderCallout2_2", "RefX|adj6|RefY|adj5" },
86 { "borderCallout3_0", "RefX|adj2|RefY|adj1" },
87 { "borderCallout3_1", "RefX|adj4|RefY|adj3" },
88 { "borderCallout3_2", "RefX|adj6|RefY|adj5" },
89 { "borderCallout3_3", "RefX|adj8|RefY|adj7" },
90 { "bracePair_0", "na|na|RefY|adj" },
91 { "bracketPair_0", "na|na|RefY|adj" },
92 { "callout1_0", "RefX|adj2|RefY|adj1" },
93 { "callout1_1", "RefX|adj4|RefY|adj3" },
94 { "callout2_0", "RefX|adj2|RefY|adj1" },
95 { "callout2_1", "RefX|adj4|RefY|adj3" },
96 { "callout2_2", "RefX|adj6|RefY|adj5" },
97 { "callout3_0", "RefX|adj2|RefY|adj1" },
98 { "callout3_1", "RefX|adj4|RefY|adj3" },
99 { "callout3_2", "RefX|adj6|RefY|adj5" },
100 { "callout3_3", "RefX|adj8|RefY|adj7" },
101 { "can_0", "na|na|RefY|adj" },
102 { "chevron_0", "RefX|adj|na|na" },
103 { "chord_0", "na|na|RefAngle|adj1" },
104 { "chord_1", "na|na|RefAngle|adj2" },
105 { "circularArrow_0", "na|na|RefAngle|adj2" },
106 { "circularArrow_1", "na|na|RefAngle|adj4" },
107 { "circularArrow_2", "RefR|adj1|RefAngle|adj3" },
108 { "circularArrow_3", "RefR|adj5|na|na" },
109 { "cloudCallout_0", "RefX|adj1|RefY|adj2" },
110 { "corner_0", "na|na|RefY|adj1" },
111 { "corner_1", "RefX|adj2|na|na" },
112 { "cube_0", "na|na|RefY|adj" },
113 { "curvedConnector3_0", "RefX|adj1|na|na" },
114 { "curvedConnector4_0", "RefX|adj1|na|na" },
115 { "curvedConnector4_1", "na|na|RefY|adj2" },
116 { "curvedConnector5_0", "RefX|adj1|na|na" },
117 { "curvedConnector5_1", "na|na|RefY|adj2" },
118 { "curvedConnector5_2", "RefX|adj3|na|na" },
119 { "curvedDownArrow_0", "RefX|adj1|na|na" },
120 { "curvedDownArrow_1", "RefX|adj2|na|na" },
121 { "curvedDownArrow_2", "na|na|RefY|adj3" },
122 { "curvedLeftArrow_0", "na|na|RefY|adj1" },
123 { "curvedLeftArrow_1", "na|na|RefY|adj2" },
124 { "curvedLeftArrow_2", "RefX|adj3|na|na" },
125 { "curvedRightArrow_0", "na|na|RefY|adj1" },
126 { "curvedRightArrow_1", "na|na|RefY|adj2" },
127 { "curvedRightArrow_2", "RefX|adj3|na|na" },
128 { "curvedUpArrow_0", "RefX|adj1|na|na" },
129 { "curvedUpArrow_1", "RefX|adj2|na|na" },
130 { "curvedUpArrow_2", "na|na|RefY|adj3" },
131 { "diagStripe_0", "na|na|RefY|adj" },
132 { "donut_0", "RefR|adj|na|na" },
133 { "doubleWave_0", "na|na|RefY|adj1" },
134 { "doubleWave_1", "RefX|adj2|na|na" },
135 { "downArrow_0", "RefX|adj1|na|na" },
136 { "downArrow_1", "na|na|RefY|adj2" },
137 { "downArrowCallout_0", "RefX|adj1|na|na" },
138 { "downArrowCallout_1", "RefX|adj2|na|na" },
139 { "downArrowCallout_2", "na|na|RefY|adj3" },
140 { "downArrowCallout_3", "na|na|RefY|adj4" },
141 { "ellipseRibbon_0", "na|na|RefY|adj1" },
142 { "ellipseRibbon_1", "RefX|adj2|na|na" },
143 { "ellipseRibbon_2", "na|na|RefY|adj3" },
144 { "ellipseRibbon2_0", "na|na|RefY|adj1" },
145 { "ellipseRibbon2_1", "RefX|adj2|na|na" },
146 { "ellipseRibbon2_2", "na|na|RefY|adj3" },
147 { "foldedCorner_0", "RefX|adj|na|na" },
148 { "frame_0", "RefX|adj1|na|na" },
149 { "gear6_0", "na|na|RefY|adj1" },
150 { "gear6_1", "RefX|adj2|na|na" },
151 { "gear9_0", "na|na|RefY|adj1" },
152 { "gear9_1", "RefX|adj2|na|na" },
153 { "halfFrame_0", "na|na|RefY|adj1" },
154 { "halfFrame_1", "RefX|adj2|na|na" },
155 { "hexagon_0", "RefX|adj|na|na" },
156 { "homePlate_0", "RefX|adj|na|na" },
157 { "horizontalScroll_0", "RefX|adj|na|na" },
158 { "leftArrow_0", "na|na|RefY|adj1" },
159 { "leftArrow_1", "RefX|adj2|na|na" },
160 { "leftArrowCallout_0", "na|na|RefY|adj1" },
161 { "leftArrowCallout_1", "na|na|RefY|adj2" },
162 { "leftArrowCallout_2", "RefX|adj3|na|na" },
163 { "leftArrowCallout_3", "RefX|adj4|na|na" },
164 { "leftBrace_0", "na|na|RefY|adj1" },
165 { "leftBrace_1", "na|na|RefY|adj2" },
166 { "leftBracket_0", "na|na|RefY|adj" },
167 { "leftCircularArrow_0", "na|na|RefAngle|adj2" },
168 { "leftCircularArrow_1", "na|na|RefAngle|adj4" },
169 { "leftCircularArrow_2", "RefR|adj1|RefAngle|adj3" },
170 { "leftCircularArrow_3", "RefR|adj5|na|na" },
171 { "leftRightArrow_0", "na|na|RefY|adj1" },
172 { "leftRightArrow_1", "RefX|adj2|na|na" },
173 { "leftRightArrowCallout_0", "na|na|RefY|adj1" },
174 { "leftRightArrowCallout_1", "na|na|RefY|adj2" },
175 { "leftRightArrowCallout_2", "RefX|adj3|na|na" },
176 { "leftRightArrowCallout_3", "RefX|adj4|na|na" },
177 { "leftRightCircularArrow_0", "na|na|RefAngle|adj2" },
178 { "leftRightCircularArrow_1", "na|na|RefAngle|adj4" },
179 { "leftRightCircularArrow_2", "RefR|adj1|RefAngle|adj3" },
180 { "leftRightCircularArrow_3", "RefR|adj5|na|na" },
181 { "leftRightRibbon_0", "na|na|RefY|adj1" },
182 { "leftRightRibbon_1", "RefX|adj2|na|na" },
183 { "leftRightRibbon_2", "na|na|RefY|adj3" },
184 { "leftRightUpArrow_0", "RefX|adj1|na|na" },
185 { "leftRightUpArrow_1", "RefX|adj2|na|na" },
186 { "leftRightUpArrow_2", "na|na|RefY|adj3" },
187 { "leftUpArrow_0", "na|na|RefY|adj1" },
188 { "leftUpArrow_1", "RefX|adj2|na|na" },
189 { "leftUpArrow_2", "na|na|RefY|adj3" },
190 { "mathDivide_0", "na|na|RefY|adj1" },
191 { "mathDivide_1", "na|na|RefY|adj2" },
192 { "mathDivide_2", "RefX|adj3|na|na" },
193 { "mathEqual_0", "na|na|RefY|adj1" },
194 { "mathEqual_1", "na|na|RefY|adj2" },
195 { "mathMinus_0", "na|na|RefY|adj1" },
196 { "mathMultiply_0", "na|na|RefY|adj1" },
197 { "mathNotEqual_0", "na|na|RefY|adj1" },
198 { "mathNotEqual_1", "na|na|RefAngle|adj2" },
199 { "mathNotEqual_2", "na|na|RefY|adj3" },
200 { "mathPlus_0", "na|na|RefY|adj1" },
201 { "moon_0", "RefX|adj|na|na" },
202 { "nonIsoscelesTrapezoid_0", "RefX|adj1|na|na" },
203 { "nonIsoscelesTrapezoid_1", "RefX|adj2|na|na" },
204 { "noSmoking_0", "RefR|adj|na|na" },
205 { "notchedRightArrow_0", "na|na|RefY|adj1" },
206 { "notchedRightArrow_1", "RefX|adj2|na|na" },
207 { "octagon_0", "RefX|adj|na|na" },
208 { "parallelogram_0", "RefX|adj|na|na" },
209 { "pie_0", "na|na|RefAngle|adj1" },
210 { "pie_1", "na|na|RefAngle|adj2" },
211 { "plaque_0", "RefX|adj|na|na" },
212 { "plus_0", "RefX|adj|na|na" },
213 { "quadArrow_0", "RefX|adj1|na|na" },
214 { "quadArrow_1", "RefX|adj2|na|na" },
215 { "quadArrow_2", "na|na|RefY|adj3" },
216 { "quadArrowCallout_0", "RefX|adj1|na|na" },
217 { "quadArrowCallout_1", "RefX|adj2|na|na" },
218 { "quadArrowCallout_2", "na|na|RefY|adj3" },
219 { "quadArrowCallout_3", "na|na|RefY|adj4" },
220 { "ribbon_0", "na|na|RefY|adj1" },
221 { "ribbon_1", "RefX|adj2|na|na" },
222 { "ribbon2_0", "na|na|RefY|adj1" },
223 { "ribbon2_1", "RefX|adj2|na|na" },
224 { "rightArrow_0", "na|na|RefY|adj1" },
225 { "rightArrow_1", "RefX|adj2|na|na" },
226 { "rightArrowCallout_0", "na|na|RefY|adj1" },
227 { "rightArrowCallout_1", "na|na|RefY|adj2" },
228 { "rightArrowCallout_2", "RefX|adj3|na|na" },
229 { "rightArrowCallout_3", "RefX|adj4|na|na" },
230 { "rightBrace_0", "na|na|RefY|adj1" },
231 { "rightBrace_1", "na|na|RefY|adj2" },
232 { "rightBracket_0", "na|na|RefY|adj" },
233 { "round1Rect_0", "RefX|adj|na|na" },
234 { "round2DiagRect_0", "RefX|adj1|na|na" },
235 { "round2DiagRect_1", "RefX|adj2|na|na" },
236 { "round2SameRect_0", "RefX|adj1|na|na" },
237 { "round2SameRect_1", "RefX|adj2|na|na" },
238 { "roundRect_0", "RefX|adj|na|na" },
239 { "smileyFace_0", "na|na|RefY|adj" },
240 { "snip1Rect_0", "RefX|adj|na|na" },
241 { "snip2DiagRect_0", "RefX|adj1|na|na" },
242 { "snip2DiagRect_1", "RefX|adj2|na|na" },
243 { "snip2SameRect_0", "RefX|adj1|na|na" },
244 { "snip2SameRect_1", "RefX|adj2|na|na" },
245 { "snipRoundRect_0", "RefX|adj1|na|na" },
246 { "snipRoundRect_1", "RefX|adj2|na|na" },
247 { "star10_0", "na|na|RefY|adj" },
248 { "star12_0", "na|na|RefY|adj" },
249 { "star16_0", "na|na|RefY|adj" },
250 { "star24_0", "na|na|RefY|adj" },
251 { "star32_0", "na|na|RefY|adj" },
252 { "star4_0", "na|na|RefY|adj" },
253 { "star5_0", "na|na|RefY|adj" },
254 { "star6_0", "na|na|RefY|adj" },
255 { "star7_0", "na|na|RefY|adj" },
256 { "star8_0", "na|na|RefY|adj" },
257 { "stripedRightArrow_0", "na|na|RefY|adj1" },
258 { "stripedRightArrow_1", "RefX|adj2|na|na" },
259 { "sun_0", "RefX|adj|na|na" },
260 { "swooshArrow_0", "na|na|RefY|adj1" },
261 { "swooshArrow_1", "RefX|adj2|na|na" },
262 { "teardrop_0", "RefX|adj|na|na" },
263 { "trapezoid_0", "RefX|adj|na|na" },
264 { "triangle_0", "RefX|adj|na|na" },
265 { "upArrowCallout_0", "RefX|adj1|na|na" },
266 { "upArrowCallout_1", "RefX|adj2|na|na" },
267 { "upArrowCallout_2", "na|na|RefY|adj3" },
268 { "upArrowCallout_3", "na|na|RefY|adj4" },
269 { "upDownArrow_0", "RefX|adj1|na|na" },
270 { "upDownArrow_1", "na|na|RefY|adj2" },
271 { "upArrow_0", "RefX|adj1|na|na" },
272 { "upArrow_1", "na|na|RefY|adj2" },
273 { "upDownArrowCallout_0", "RefX|adj1|na|na" },
274 { "upDownArrowCallout_1", "RefX|adj2|na|na" },
275 { "upDownArrowCallout_2", "na|na|RefY|adj3" },
276 { "upDownArrowCallout_3", "na|na|RefY|adj4" },
277 { "uturnArrow_0", "RefX|adj1|na|na" },
278 { "uturnArrow_1", "RefX|adj2|na|na" },
279 { "uturnArrow_2", "na|na|RefY|adj3" },
280 { "uturnArrow_3", "RefX|adj4|na|na" },
281 { "uturnArrow_4", "na|na|RefY|adj5" },
282 { "verticalScroll_0", "na|na|RefY|adj" },
283 { "wave_0", "na|na|RefY|adj1" },
284 { "wave_1", "RefX|adj2|na|na" },
285 { "wedgeEllipseCallout_0", "RefX|adj1|RefY|adj2" },
286 { "wedgeRectCallout_0", "RefX|adj1|RefY|adj2" },
287 { "wedgeRoundRectCallout_0", "RefX|adj1|RefY|adj2" } };
288}
289
290static sal_Int32 lcl_getAdjIndexFromToken(const sal_Int32 nTokenPos, std::u16string_view rMapValue)
291{
292 std::u16string_view sAdjRef = o3tl::getToken(rMapValue, nTokenPos, '|');
293 std::u16string_view sNumber; // number part from "adj1", "adj2" etc.
294 if (o3tl::starts_with(sAdjRef, u"adj", &sNumber))
295 {
296 if (sNumber.empty() || sNumber == u"1")
297 return 0;
298 else
299 return o3tl::toInt32(sNumber) - 1;
300 }
301 else
302 return -1;
303}
304
306 std::u16string_view sFullOOXShapeName, const sal_Int32 nHandleIndex, OUString& rFirstRefType,
307 sal_Int32& rFirstAdjValueIndex, OUString& rSecondRefType, sal_Int32& rSecondAdjValueIndex)
308{
309 static const HandleAdjRelHashMap s_HashMap = []() {
310 HandleAdjRelHashMap aH;
311 aH.reserve(std::size(aHandleAdjRelArray));
312 for (const auto& item : aHandleAdjRelArray)
313 aH.emplace(OUString::createFromAscii(item.sShape_Handle),
314 OUString::createFromAscii(item.sAdjReferences));
315 return aH;
316 }();
317
318 std::u16string_view sKey;
319 OUString sValue;
320 rFirstRefType = "na";
321 rFirstAdjValueIndex = -1;
322 rSecondRefType = "na";
323 rSecondAdjValueIndex = -1;
324 if (o3tl::starts_with(sFullOOXShapeName, u"ooxml-", &sKey))
325 {
326 HandleAdjRelHashMap::const_iterator aHashIter(
327 s_HashMap.find(OUString::Concat(sKey) + "_" + OUString::number(nHandleIndex)));
328 if (aHashIter != s_HashMap.end())
329 sValue = (*aHashIter).second;
330 else
331 return;
332 }
333 else
334 return;
335
336 rFirstRefType = sValue.getToken(0, '|');
337 rFirstAdjValueIndex = lcl_getAdjIndexFromToken(1, sValue);
338 rSecondRefType = sValue.getToken(2, '|');
339 rSecondAdjValueIndex = lcl_getAdjIndexFromToken(3, sValue);
340 return;
341}
342
343/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
float u
void GetOOXHandleAdjRelation(std::u16string_view sFullOOXShapeName, const sal_Int32 nHandleIndex, OUString &rFirstRefType, sal_Int32 &rFirstAdjValueIndex, OUString &rSecondRefType, sal_Int32 &rSecondAdjValueIndex)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
static sal_Int32 lcl_getAdjIndexFromToken(const sal_Int32 nTokenPos, std::u16string_view rMapValue)