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