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 "EnhancedCustomShapeToken.hxx"
30 : : #include <osl/mutex.hxx>
31 : : #include <boost/unordered_map.hpp>
32 : : #include <string.h>
33 : :
34 : : namespace xmloff { namespace EnhancedCustomShapeToken {
35 : :
36 : : struct THash
37 : : {
38 : 15690 : size_t operator()( const char* s ) const
39 : : {
40 : 15690 : return rtl_str_hashCode(s);
41 : : }
42 : : };
43 : : struct TCheck
44 : : {
45 : 14490 : bool operator()( const char* s1, const char* s2 ) const
46 : : {
47 : 14490 : return strcmp( s1, s2 ) == 0;
48 : : }
49 : : };
50 : : typedef boost::unordered_map< const char*, EnhancedCustomShapeTokenEnum, THash, TCheck> TypeNameHashMap;
51 : : static TypeNameHashMap* pHashMap = NULL;
52 : 10 : static ::osl::Mutex& getHashMapMutex()
53 : : {
54 [ + - ][ + - ]: 10 : static osl::Mutex s_aHashMapProtection;
[ + - ][ # # ]
55 : 10 : return s_aHashMapProtection;
56 : : }
57 : :
58 : : struct TokenTable
59 : : {
60 : : const char* pS;
61 : : EnhancedCustomShapeTokenEnum pE;
62 : : };
63 : :
64 : : static const TokenTable pTokenTableArray[] =
65 : : {
66 : : { "type", EAS_type },
67 : : { "name", EAS_name },
68 : : { "mirror-horizontal", EAS_mirror_horizontal },
69 : : { "mirror-vertical", EAS_mirror_vertical },
70 : : { "viewBox", EAS_viewBox },
71 : : { "text-rotate-angle", EAS_text_rotate_angle },
72 : : { "extrusion-allowed", EAS_extrusion_allowed },
73 : : { "extrusion-text-path-allowed", EAS_text_path_allowed },
74 : : { "extrusion-concentric-gradient-fill", EAS_concentric_gradient_fill_allowed },
75 : : { "extrusion", EAS_extrusion },
76 : : { "extrusion-brightness", EAS_extrusion_brightness },
77 : : { "extrusion-depth", EAS_extrusion_depth },
78 : : { "extrusion-diffusion", EAS_extrusion_diffusion },
79 : : { "extrusion-number-of-line-segments", EAS_extrusion_number_of_line_segments },
80 : : { "extrusion-light-face", EAS_extrusion_light_face },
81 : : { "extrusion-first-light-harsh", EAS_extrusion_first_light_harsh },
82 : : { "extrusion-second-light-harsh", EAS_extrusion_second_light_harsh },
83 : : { "extrusion-first-light-livel", EAS_extrusion_first_light_level },
84 : : { "extrusion-second-light-level", EAS_extrusion_second_light_level },
85 : : { "extrusion-first-light-direction", EAS_extrusion_first_light_direction },
86 : : { "extrusion-second-light-direction", EAS_extrusion_second_light_direction },
87 : : { "extrusion-metal", EAS_extrusion_metal },
88 : : { "shade-mode", EAS_shade_mode },
89 : : { "extrusion-rotation-angle", EAS_extrusion_rotation_angle },
90 : : { "extrusion-rotation-center", EAS_extrusion_rotation_center },
91 : : { "extrusion-shininess", EAS_extrusion_shininess },
92 : : { "extrusion-skew", EAS_extrusion_skew },
93 : : { "extrusion-specularity", EAS_extrusion_specularity },
94 : : { "projection", EAS_projection },
95 : : { "extrusion-viewpoint", EAS_extrusion_viewpoint },
96 : : { "extrusion-origin", EAS_extrusion_origin },
97 : : { "extrusion-color", EAS_extrusion_color },
98 : : { "enhanced-path", EAS_enhanced_path },
99 : : { "path-stretchpoint-x", EAS_path_stretchpoint_x },
100 : : { "path-stretchpoint-y", EAS_path_stretchpoint_y },
101 : : { "text-areas", EAS_text_areas },
102 : : { "glue-points", EAS_glue_points },
103 : : { "glue-point-type", EAS_glue_point_type },
104 : : { "glue-point-leaving-directions", EAS_glue_point_leaving_directions },
105 : : { "text-path", EAS_text_path },
106 : : { "text-path-mode", EAS_text_path_mode },
107 : : { "text-path-scale", EAS_text_path_scale },
108 : : { "text-path-same-letter-heights", EAS_text_path_same_letter_heights },
109 : : { "modifiers", EAS_modifiers },
110 : : { "equation", EAS_equation },
111 : : { "formula", EAS_formula },
112 : : { "handle", EAS_handle },
113 : : { "handle-mirror-horizontal", EAS_handle_mirror_horizontal },
114 : : { "handle-mirror-vertical", EAS_handle_mirror_vertical },
115 : : { "handle-switched", EAS_handle_switched },
116 : : { "handle-position", EAS_handle_position },
117 : : { "handle-range-x-minimum", EAS_handle_range_x_minimum },
118 : : { "handle-range-x-maximum", EAS_handle_range_x_maximum },
119 : : { "handle-range-y-minimum", EAS_handle_range_y_minimum },
120 : : { "handle-range-y-maximum", EAS_handle_range_y_maximum },
121 : : { "handle-polar", EAS_handle_polar },
122 : : { "handle-radius-range-minimum", EAS_handle_radius_range_minimum },
123 : : { "handle-radius-range-maximum", EAS_handle_radius_range_maximum },
124 : :
125 : : { "CustomShapeEngine", EAS_CustomShapeEngine },
126 : : { "CustomShapeData", EAS_CustomShapeData },
127 : : { "Type", EAS_Type },
128 : : { "MirroredX", EAS_MirroredX },
129 : : { "MirroredY", EAS_MirroredY },
130 : : { "ViewBox", EAS_ViewBox },
131 : : { "TextRotateAngle", EAS_TextRotateAngle },
132 : : { "ExtrusionAllowed", EAS_ExtrusionAllowed },
133 : : { "TextPathAllowed", EAS_TextPathAllowed },
134 : : { "ConcentricGradientFillAllowed", EAS_ConcentricGradientFillAllowed },
135 : : { "Extrusion", EAS_Extrusion },
136 : : { "Equations", EAS_Equations },
137 : : { "Equation", EAS_Equation },
138 : : { "Path", EAS_Path },
139 : : { "TextPath", EAS_TextPath },
140 : : { "Handles", EAS_Handles },
141 : : { "Handle", EAS_Handle },
142 : : { "Brightness", EAS_Brightness },
143 : : { "Depth", EAS_Depth },
144 : : { "Diffusion", EAS_Diffusion },
145 : : { "NumberOfLineSegments", EAS_NumberOfLineSegments },
146 : : { "LightFace", EAS_LightFace },
147 : : { "FirstLightHarsh", EAS_FirstLightHarsh },
148 : : { "SecondLightHarsh", EAS_SecondLightHarsh },
149 : : { "FirstLightLevel", EAS_FirstLightLevel },
150 : : { "SecondLightLevel", EAS_SecondLightLevel },
151 : : { "FirstLightDirection", EAS_FirstLightDirection },
152 : : { "SecondLightDirection", EAS_SecondLightDirection },
153 : : { "Metal", EAS_Metal },
154 : : { "ShadeMode", EAS_ShadeMode },
155 : : { "RotateAngle", EAS_RotateAngle },
156 : : { "RotationCenter", EAS_RotationCenter },
157 : : { "Shininess", EAS_Shininess },
158 : : { "Skew", EAS_Skew },
159 : : { "Specularity", EAS_Specularity },
160 : : { "ProjectionMode", EAS_ProjectionMode },
161 : : { "ViewPoint", EAS_ViewPoint },
162 : : { "Origin", EAS_Origin },
163 : : { "Color", EAS_Color },
164 : : { "Switched", EAS_Switched },
165 : : { "Polar", EAS_Polar },
166 : : { "RangeXMinimum", EAS_RangeXMinimum },
167 : : { "RangeXMaximum", EAS_RangeXMaximum },
168 : : { "RangeYMinimum", EAS_RangeYMinimum },
169 : : { "RangeYMaximum", EAS_RangeYMaximum },
170 : : { "RadiusRangeMinimum", EAS_RadiusRangeMinimum },
171 : : { "RadiusRangeMaximum", EAS_RadiusRangeMaximum },
172 : : { "Coordinates", EAS_Coordinates },
173 : : { "Segments", EAS_Segments },
174 : : { "StretchX", EAS_StretchX },
175 : : { "StretchY", EAS_StretchY },
176 : : { "TextFrames", EAS_TextFrames },
177 : : { "GluePoints", EAS_GluePoints },
178 : : { "GluePointLeavingDirections", EAS_GluePointLeavingDirections },
179 : : { "GluePointType", EAS_GluePointType },
180 : : { "TextPathMode", EAS_TextPathMode },
181 : : { "ScaleX", EAS_ScaleX },
182 : : { "SameLetterHeights", EAS_SameLetterHeights },
183 : : { "Position", EAS_Position },
184 : : { "AdjustmentValues", EAS_AdjustmentValues },
185 : :
186 : : { "Last", EAS_Last },
187 : : { "NotFound", EAS_NotFound }
188 : : };
189 : :
190 : 14490 : EnhancedCustomShapeTokenEnum EASGet( const rtl::OUString& rShapeType )
191 : : {
192 [ + + ]: 14490 : if ( !pHashMap )
193 : : { // init hash map
194 [ + - ][ + - ]: 10 : ::osl::MutexGuard aGuard( getHashMapMutex() );
195 [ + - ]: 10 : if ( !pHashMap )
196 : : {
197 [ + - ][ + - ]: 10 : TypeNameHashMap* pH = new TypeNameHashMap;
198 : 10 : const TokenTable* pPtr = pTokenTableArray;
199 : 10 : const TokenTable* pEnd = pPtr + ( sizeof( pTokenTableArray ) / sizeof( TokenTable ) );
200 [ + + ]: 1210 : for ( ; pPtr < pEnd; pPtr++ )
201 [ + - ]: 1200 : (*pH)[ pPtr->pS ] = pPtr->pE;
202 : 10 : pHashMap = pH;
203 [ + - ]: 10 : }
204 : : }
205 : 14490 : EnhancedCustomShapeTokenEnum eRetValue = EAS_NotFound;
206 : 14490 : int i, nLen = rShapeType.getLength();
207 [ + - ]: 14490 : char* pBuf = new char[ nLen + 1 ];
208 [ + + ]: 129575 : for ( i = 0; i < nLen; i++ )
209 : 115085 : pBuf[ i ] = (char)rShapeType[ i ];
210 : 14490 : pBuf[ i ] = 0;
211 [ + - ]: 14490 : TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf ) );
212 [ + - ]: 14490 : delete[] pBuf;
213 [ + - ][ + - ]: 14490 : if ( aHashIter != pHashMap->end() )
214 [ + - ]: 14490 : eRetValue = (*aHashIter).second;
215 : 14490 : return eRetValue;
216 : : }
217 : :
218 : 4340 : rtl::OUString EASGet( const EnhancedCustomShapeTokenEnum eToken )
219 : : {
220 : : sal_uInt32 i = eToken >= EAS_Last
221 : : ? (sal_uInt32)EAS_NotFound
222 [ + - ]: 4340 : : (sal_uInt32)eToken;
223 : 4340 : return rtl::OUString::createFromAscii( pTokenTableArray[ i ].pS );
224 : : }
225 : :
226 : : }
227 : : }
228 : :
229 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|