Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "svx/EnhancedCustomShapeTypeNames.hxx"
30 : : #include <osl/mutex.hxx>
31 : : #include <boost/unordered_map.hpp>
32 : :
33 : : struct THash
34 : : {
35 : 10900 : size_t operator()( const char* s ) const
36 : : {
37 : 10900 : return rtl_str_hashCode(s);
38 : : }
39 : : };
40 : : struct TCheck
41 : : {
42 : 1690 : bool operator()( const char* s1, const char* s2 ) const
43 : : {
44 : 1690 : return strcmp( s1, s2 ) == 0;
45 : : }
46 : : };
47 : : typedef boost::unordered_map< const char*, MSO_SPT, THash, TCheck> TypeNameHashMap;
48 : : static TypeNameHashMap* pHashMap = NULL;
49 : 45 : static ::osl::Mutex& getHashMapMutex()
50 : : {
51 [ + - ][ + - ]: 45 : static osl::Mutex s_aHashMapProtection;
[ + - ][ # # ]
52 : 45 : return s_aHashMapProtection;
53 : : }
54 : :
55 : : struct NameTypeTable
56 : : {
57 : : const char* pS;
58 : : MSO_SPT pE;
59 : : };
60 : : static const NameTypeTable pNameTypeTableArray[] =
61 : : {
62 : : { "non-primitive", mso_sptMin },
63 : : { "rectangle", mso_sptRectangle },
64 : : { "round-rectangle", mso_sptRoundRectangle },
65 : : { "ellipse", mso_sptEllipse },
66 : : { "diamond", mso_sptDiamond },
67 : : { "isosceles-triangle", mso_sptIsocelesTriangle },
68 : : { "right-triangle", mso_sptRightTriangle },
69 : : { "parallelogram", mso_sptParallelogram },
70 : : { "trapezoid", mso_sptTrapezoid },
71 : : { "hexagon", mso_sptHexagon },
72 : : { "octagon", mso_sptOctagon },
73 : : { "cross", mso_sptPlus },
74 : : { "star5", mso_sptStar },
75 : : { "right-arrow", mso_sptArrow },
76 : : { "mso-spt14", mso_sptThickArrow },
77 : : { "pentagon-right", mso_sptHomePlate },
78 : : { "cube", mso_sptCube },
79 : : { "mso-spt17", mso_sptBalloon },
80 : : { "mso-spt18", mso_sptSeal },
81 : : { "mso-spt19", mso_sptArc },
82 : : { "mso-spt20", mso_sptLine },
83 : : { "mso-spt21", mso_sptPlaque },
84 : : { "can", mso_sptCan },
85 : : { "ring", mso_sptDonut },
86 : : { "mso-spt24", mso_sptTextSimple },
87 : : { "mso-spt25", mso_sptTextOctagon },
88 : : { "mso-spt26", mso_sptTextHexagon },
89 : : { "mso-spt27", mso_sptTextCurve },
90 : : { "mso-spt28", mso_sptTextWave },
91 : : { "mso-spt29", mso_sptTextRing },
92 : : { "mso-spt30", mso_sptTextOnCurve },
93 : : { "mso-spt31", mso_sptTextOnRing },
94 : : { "mso-spt32", mso_sptStraightConnector1 },
95 : : { "mso-spt33", mso_sptBentConnector2 },
96 : : { "mso-spt34", mso_sptBentConnector3 },
97 : : { "mso-spt35", mso_sptBentConnector4 },
98 : : { "mso-spt36", mso_sptBentConnector5 },
99 : : { "mso-spt37", mso_sptCurvedConnector2 },
100 : : { "mso-spt38", mso_sptCurvedConnector3 },
101 : : { "mso-spt39", mso_sptCurvedConnector4 },
102 : : { "mso-spt40", mso_sptCurvedConnector5 },
103 : : { "mso-spt41", mso_sptCallout1 },
104 : : { "mso-spt42", mso_sptCallout2 },
105 : : { "mso-spt43", mso_sptCallout3 },
106 : : { "mso-spt44", mso_sptAccentCallout1 },
107 : : { "mso-spt45", mso_sptAccentCallout2 },
108 : : { "mso-spt46", mso_sptAccentCallout3 },
109 : : { "line-callout-1", mso_sptBorderCallout1 },
110 : : { "line-callout-2", mso_sptBorderCallout2 },
111 : : { "mso-spt49", mso_sptBorderCallout3 },
112 : : { "mso-spt50", mso_sptAccentBorderCallout1 },
113 : : { "mso-spt51", mso_sptAccentBorderCallout2 },
114 : : { "mso-spt52", mso_sptAccentBorderCallout3 },
115 : : { "mso-spt53", mso_sptRibbon },
116 : : { "mso-spt54", mso_sptRibbon2 },
117 : : { "chevron", mso_sptChevron },
118 : : { "pentagon", mso_sptPentagon },
119 : : { "forbidden", mso_sptNoSmoking },
120 : : { "star8", mso_sptSeal8 },
121 : : { "mso-spt59", mso_sptSeal16 },
122 : : { "mso-spt60", mso_sptSeal32 },
123 : : { "rectangular-callout", mso_sptWedgeRectCallout },
124 : : { "round-rectangular-callout", mso_sptWedgeRRectCallout },
125 : : { "round-callout", mso_sptWedgeEllipseCallout },
126 : : { "mso-spt64", mso_sptWave },
127 : : { "paper", mso_sptFoldedCorner },
128 : : { "left-arrow", mso_sptLeftArrow },
129 : : { "down-arrow", mso_sptDownArrow },
130 : : { "up-arrow", mso_sptUpArrow },
131 : : { "left-right-arrow", mso_sptLeftRightArrow },
132 : : { "up-down-arrow", mso_sptUpDownArrow },
133 : : { "mso-spt71", mso_sptIrregularSeal1 },
134 : : { "bang", mso_sptIrregularSeal2 },
135 : : { "lightning", mso_sptLightningBolt },
136 : : { "heart", mso_sptHeart },
137 : : { "mso-spt75", mso_sptPictureFrame },
138 : : { "quad-arrow", mso_sptQuadArrow },
139 : : { "left-arrow-callout", mso_sptLeftArrowCallout },
140 : : { "right-arrow-callout", mso_sptRightArrowCallout },
141 : : { "up-arrow-callout", mso_sptUpArrowCallout },
142 : : { "down-arrow-callout", mso_sptDownArrowCallout },
143 : : { "left-right-arrow-callout", mso_sptLeftRightArrowCallout },
144 : : { "up-down-arrow-callout", mso_sptUpDownArrowCallout },
145 : : { "quad-arrow-callout", mso_sptQuadArrowCallout },
146 : : { "quad-bevel", mso_sptBevel },
147 : : { "left-bracket", mso_sptLeftBracket },
148 : : { "right-bracket", mso_sptRightBracket },
149 : : { "left-brace", mso_sptLeftBrace },
150 : : { "right-brace", mso_sptRightBrace },
151 : : { "mso-spt89", mso_sptLeftUpArrow },
152 : : { "mso-spt90", mso_sptBentUpArrow },
153 : : { "mso-spt91", mso_sptBentArrow },
154 : : { "star24", mso_sptSeal24 },
155 : : { "striped-right-arrow", mso_sptStripedRightArrow },
156 : : { "notched-right-arrow", mso_sptNotchedRightArrow },
157 : : { "block-arc", mso_sptBlockArc },
158 : : { "smiley", mso_sptSmileyFace },
159 : : { "vertical-scroll", mso_sptVerticalScroll },
160 : : { "horizontal-scroll", mso_sptHorizontalScroll },
161 : : { "circular-arrow", mso_sptCircularArrow },
162 : : { "mso-spt100", mso_sptNotchedCircularArrow },
163 : : { "mso-spt101", mso_sptUturnArrow },
164 : : { "mso-spt102", mso_sptCurvedRightArrow },
165 : : { "mso-spt103", mso_sptCurvedLeftArrow },
166 : : { "mso-spt104", mso_sptCurvedUpArrow },
167 : : { "mso-spt105", mso_sptCurvedDownArrow },
168 : : { "cloud-callout", mso_sptCloudCallout },
169 : : { "mso-spt107", mso_sptEllipseRibbon },
170 : : { "mso-spt108", mso_sptEllipseRibbon2 },
171 : : { "flowchart-process", mso_sptFlowChartProcess },
172 : : { "flowchart-decision", mso_sptFlowChartDecision },
173 : : { "flowchart-data", mso_sptFlowChartInputOutput },
174 : : { "flowchart-predefined-process", mso_sptFlowChartPredefinedProcess },
175 : : { "flowchart-internal-storage", mso_sptFlowChartInternalStorage },
176 : : { "flowchart-document", mso_sptFlowChartDocument },
177 : : { "flowchart-multidocument", mso_sptFlowChartMultidocument },
178 : : { "flowchart-terminator", mso_sptFlowChartTerminator },
179 : : { "flowchart-preparation", mso_sptFlowChartPreparation },
180 : : { "flowchart-manual-input", mso_sptFlowChartManualInput },
181 : : { "flowchart-manual-operation", mso_sptFlowChartManualOperation },
182 : : { "flowchart-connector", mso_sptFlowChartConnector },
183 : : { "flowchart-card", mso_sptFlowChartPunchedCard },
184 : : { "flowchart-punched-tape", mso_sptFlowChartPunchedTape },
185 : : { "flowchart-summing-junction", mso_sptFlowChartSummingJunction },
186 : : { "flowchart-or", mso_sptFlowChartOr },
187 : : { "flowchart-collate", mso_sptFlowChartCollate },
188 : : { "flowchart-sort", mso_sptFlowChartSort },
189 : : { "flowchart-extract", mso_sptFlowChartExtract },
190 : : { "flowchart-merge", mso_sptFlowChartMerge },
191 : : { "mso-spt129", mso_sptFlowChartOfflineStorage },
192 : : { "flowchart-stored-data", mso_sptFlowChartOnlineStorage },
193 : : { "flowchart-sequential-access", mso_sptFlowChartMagneticTape },
194 : : { "flowchart-magnetic-disk", mso_sptFlowChartMagneticDisk },
195 : : { "flowchart-direct-access-storage", mso_sptFlowChartMagneticDrum },
196 : : { "flowchart-display", mso_sptFlowChartDisplay },
197 : : { "flowchart-delay", mso_sptFlowChartDelay },
198 : : { "fontwork-plain-text", mso_sptTextPlainText },
199 : : { "fontwork-stop", mso_sptTextStop },
200 : : { "fontwork-triangle-up", mso_sptTextTriangle },
201 : : { "fontwork-triangle-down", mso_sptTextTriangleInverted },
202 : : { "fontwork-chevron-up", mso_sptTextChevron },
203 : : { "fontwork-chevron-down", mso_sptTextChevronInverted },
204 : : { "mso-spt142", mso_sptTextRingInside },
205 : : { "mso-spt143", mso_sptTextRingOutside },
206 : : { "fontwork-arch-up-curve", mso_sptTextArchUpCurve },
207 : : { "fontwork-arch-down-curve", mso_sptTextArchDownCurve },
208 : : { "fontwork-circle-curve", mso_sptTextCircleCurve },
209 : : { "fontwork-open-circle-curve", mso_sptTextButtonCurve },
210 : : { "fontwork-arch-up-pour", mso_sptTextArchUpPour },
211 : : { "fontwork-arch-down-pour", mso_sptTextArchDownPour },
212 : : { "fontwork-circle-pour", mso_sptTextCirclePour },
213 : : { "fontwork-open-circle-pour", mso_sptTextButtonPour },
214 : : { "fontwork-curve-up", mso_sptTextCurveUp },
215 : : { "fontwork-curve-down", mso_sptTextCurveDown },
216 : : { "fontwork-fade-up-and-right", mso_sptTextCascadeUp },
217 : : { "fontwork-fade-up-and-left", mso_sptTextCascadeDown },
218 : : { "fontwork-wave", mso_sptTextWave1 },
219 : : { "mso-spt157", mso_sptTextWave2 },
220 : : { "mso-spt158", mso_sptTextWave3 },
221 : : { "mso-spt159", mso_sptTextWave4 },
222 : : { "fontwork-inflate", mso_sptTextInflate },
223 : : { "mso-spt161", mso_sptTextDeflate },
224 : : { "mso-spt162", mso_sptTextInflateBottom },
225 : : { "mso-spt163", mso_sptTextDeflateBottom },
226 : : { "mso-spt164", mso_sptTextInflateTop },
227 : : { "mso-spt165", mso_sptTextDeflateTop },
228 : : { "mso-spt166", mso_sptTextDeflateInflate },
229 : : { "mso-spt167", mso_sptTextDeflateInflateDeflate },
230 : : { "fontwork-fade-right", mso_sptTextFadeRight },
231 : : { "fontwork-fade-left", mso_sptTextFadeLeft },
232 : : { "fontwork-fade-up", mso_sptTextFadeUp },
233 : : { "fontwork-fade-down", mso_sptTextFadeDown },
234 : : { "fontwork-slant-up", mso_sptTextSlantUp },
235 : : { "fontwork-slant-down", mso_sptTextSlantDown },
236 : : { "mso-spt174", mso_sptTextCanUp },
237 : : { "mso-spt175", mso_sptTextCanDown },
238 : : { "flowchart-alternate-process", mso_sptFlowChartAlternateProcess },
239 : : { "flowchart-off-page-connector", mso_sptFlowChartOffpageConnector },
240 : : { "mso-spt178", mso_sptCallout90 },
241 : : { "mso-spt179", mso_sptAccentCallout90 },
242 : : { "mso-spt180", mso_sptBorderCallout90 },
243 : : { "line-callout-3", mso_sptAccentBorderCallout90 },
244 : : { "mso-spt182", mso_sptLeftRightUpArrow },
245 : : { "sun", mso_sptSun },
246 : : { "moon", mso_sptMoon },
247 : : { "bracket-pair", mso_sptBracketPair },
248 : : { "brace-pair", mso_sptBracePair },
249 : : { "star4", mso_sptSeal4 },
250 : : { "mso-spt188", mso_sptDoubleWave },
251 : : { "mso-spt189", mso_sptActionButtonBlank },
252 : : { "mso-spt190", mso_sptActionButtonHome },
253 : : { "mso-spt191", mso_sptActionButtonHelp },
254 : : { "mso-spt192", mso_sptActionButtonInformation },
255 : : { "mso-spt193", mso_sptActionButtonForwardNext },
256 : : { "mso-spt194", mso_sptActionButtonBackPrevious },
257 : : { "mso-spt195", mso_sptActionButtonEnd },
258 : : { "mso-spt196", mso_sptActionButtonBeginning },
259 : : { "mso-spt197", mso_sptActionButtonReturn },
260 : : { "mso-spt198", mso_sptActionButtonDocument },
261 : : { "mso-spt199", mso_sptActionButtonSound },
262 : : { "mso-spt200", mso_sptActionButtonMovie },
263 : : { "mso-spt201", mso_sptHostControl },
264 : : { "mso-spt202", mso_sptTextBox }
265 : : };
266 : :
267 : : // gallery: quadrat
268 : : // gallery: round-quadrat
269 : : // gallery: circle
270 : : // gallery: circle-pie
271 : : // gallery: frame
272 : : // gallery: flower
273 : : // gallery: cloud
274 : : // gallery: puzzle
275 : : // gallery: octagon-bevel
276 : : // gallery: diamond-bevel
277 : : // gallery: up-right-arrow
278 : : // gallery: up-right-down-arrow
279 : : // gallery: corner-right-arrow
280 : : // gallery: split-arrow
281 : : // gallery: up-right-arrow-callout
282 : : // gallery: split-round-arrow
283 : : // gallery: s-sharped-arrow
284 : : // Gallery: star6
285 : : // Gallery: star12
286 : : // Gallery: concave-star6
287 : : // Gallery: signet
288 : : // Gallery: doorplate
289 : : // gallery: fontwork-arch-left-curve
290 : : // gallery: fontwork-arch-right-curve
291 : : // gallery: fontwork-arch-left-pour
292 : : // gallery: fontwork-arch-right-pour
293 : :
294 : 1765 : MSO_SPT EnhancedCustomShapeTypeNames::Get( const rtl::OUString& rShapeType )
295 : : {
296 [ + + ]: 1765 : if ( !pHashMap )
297 : : { // init hash map
298 [ + - ][ + - ]: 45 : ::osl::MutexGuard aGuard( getHashMapMutex() );
299 [ + - ]: 45 : if ( !pHashMap )
300 : : {
301 [ + - ][ + - ]: 45 : TypeNameHashMap* pH = new TypeNameHashMap;
302 : 45 : const NameTypeTable* pPtr = pNameTypeTableArray;
303 : 45 : const NameTypeTable* pEnd = pPtr + ( sizeof( pNameTypeTableArray ) / sizeof( NameTypeTable ) );
304 [ + + ]: 9180 : for ( ; pPtr < pEnd; pPtr++ )
305 [ + - ]: 9135 : (*pH)[ pPtr->pS ] = pPtr->pE;
306 : 45 : pHashMap = pH;
307 [ + - ]: 45 : }
308 : : }
309 : 1765 : MSO_SPT eRetValue = mso_sptNil;
310 : 1765 : int i, nLen = rShapeType.getLength();
311 [ + - ]: 1765 : char* pBuf = new char[ nLen + 1 ];
312 [ + + ]: 18165 : for ( i = 0; i < nLen; i++ )
313 : 16400 : pBuf[ i ] = (char)rShapeType[ i ];
314 : 1765 : pBuf[ i ] = 0;
315 [ + - ]: 1765 : TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf ) );
316 [ + - ]: 1765 : delete[] pBuf;
317 [ + - ][ + + ]: 1765 : if ( aHashIter != pHashMap->end() )
318 [ + - ]: 1690 : eRetValue = (*aHashIter).second;
319 : 1765 : return eRetValue;
320 : : }
321 : :
322 : 1747 : rtl::OUString EnhancedCustomShapeTypeNames::Get( const MSO_SPT eShapeType )
323 : : {
324 : : return eShapeType <= mso_sptTextBox
325 : : ? rtl::OUString::createFromAscii( pNameTypeTableArray[ eShapeType ].pS )
326 [ + - ]: 1747 : : rtl::OUString();
327 : : }
328 : :
329 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|