merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / draw / EnhancedCustomShapeToken.cxx
blob8b854fe860f1c24a3b1d853086b977d66726a6d6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: EnhancedCustomShapeToken.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "EnhancedCustomShapeToken.hxx"
34 #include <osl/mutex.hxx>
35 #include <hash_map>
36 #include <string.h>
38 namespace xmloff { namespace EnhancedCustomShapeToken {
40 struct TCheck
42 bool operator()( const char* s1, const char* s2 ) const
44 return strcmp( s1, s2 ) == 0;
47 typedef std::hash_map< const char*, EnhancedCustomShapeTokenEnum, std::hash<const char*>, TCheck> TypeNameHashMap;
48 static TypeNameHashMap* pHashMap = NULL;
49 static ::osl::Mutex& getHashMapMutex()
51 static osl::Mutex s_aHashMapProtection;
52 return s_aHashMapProtection;
55 struct TokenTable
57 const char* pS;
58 EnhancedCustomShapeTokenEnum pE;
61 static const TokenTable pTokenTableArray[] =
63 { "type", EAS_type },
64 { "name", EAS_name },
65 { "mirror-horizontal", EAS_mirror_horizontal },
66 { "mirror-vertical", EAS_mirror_vertical },
67 { "viewBox", EAS_viewBox },
68 { "text-rotate-angle", EAS_text_rotate_angle },
69 { "extrusion-allowed", EAS_extrusion_allowed },
70 { "extrusion-text-path-allowed", EAS_text_path_allowed },
71 { "extrusion-concentric-gradient-fill", EAS_concentric_gradient_fill_allowed },
72 { "extrusion", EAS_extrusion },
73 { "extrusion-brightness", EAS_extrusion_brightness },
74 { "extrusion-depth", EAS_extrusion_depth },
75 { "extrusion-diffusion", EAS_extrusion_diffusion },
76 { "extrusion-number-of-line-segments", EAS_extrusion_number_of_line_segments },
77 { "extrusion-light-face", EAS_extrusion_light_face },
78 { "extrusion-first-light-harsh", EAS_extrusion_first_light_harsh },
79 { "extrusion-second-light-harsh", EAS_extrusion_second_light_harsh },
80 { "extrusion-first-light-livel", EAS_extrusion_first_light_level },
81 { "extrusion-second-light-level", EAS_extrusion_second_light_level },
82 { "extrusion-first-light-direction", EAS_extrusion_first_light_direction },
83 { "extrusion-second-light-direction", EAS_extrusion_second_light_direction },
84 { "extrusion-metal", EAS_extrusion_metal },
85 { "shade-mode", EAS_shade_mode },
86 { "extrusion-rotation-angle", EAS_extrusion_rotation_angle },
87 { "extrusion-rotation-center", EAS_extrusion_rotation_center },
88 { "extrusion-shininess", EAS_extrusion_shininess },
89 { "extrusion-skew", EAS_extrusion_skew },
90 { "extrusion-specularity", EAS_extrusion_specularity },
91 { "projection", EAS_projection },
92 { "extrusion-viewpoint", EAS_extrusion_viewpoint },
93 { "extrusion-origin", EAS_extrusion_origin },
94 { "extrusion-color", EAS_extrusion_color },
95 { "enhanced-path", EAS_enhanced_path },
96 { "path-stretchpoint-x", EAS_path_stretchpoint_x },
97 { "path-stretchpoint-y", EAS_path_stretchpoint_y },
98 { "text-areas", EAS_text_areas },
99 { "glue-points", EAS_glue_points },
100 { "glue-point-type", EAS_glue_point_type },
101 { "glue-point-leaving-directions", EAS_glue_point_leaving_directions },
102 { "text-path", EAS_text_path },
103 { "text-path-mode", EAS_text_path_mode },
104 { "text-path-scale", EAS_text_path_scale },
105 { "text-path-same-letter-heights", EAS_text_path_same_letter_heights },
106 { "modifiers", EAS_modifiers },
107 { "equation", EAS_equation },
108 { "formula", EAS_formula },
109 { "handle", EAS_handle },
110 { "handle-mirror-horizontal", EAS_handle_mirror_horizontal },
111 { "handle-mirror-vertical", EAS_handle_mirror_vertical },
112 { "handle-switched", EAS_handle_switched },
113 { "handle-position", EAS_handle_position },
114 { "handle-range-x-minimum", EAS_handle_range_x_minimum },
115 { "handle-range-x-maximum", EAS_handle_range_x_maximum },
116 { "handle-range-y-minimum", EAS_handle_range_y_minimum },
117 { "handle-range-y-maximum", EAS_handle_range_y_maximum },
118 { "handle-polar", EAS_handle_polar },
119 { "handle-radius-range-minimum", EAS_handle_radius_range_minimum },
120 { "handle-radius-range-maximum", EAS_handle_radius_range_maximum },
122 { "CustomShapeEngine", EAS_CustomShapeEngine },
123 { "CustomShapeData", EAS_CustomShapeData },
124 { "Type", EAS_Type },
125 { "MirroredX", EAS_MirroredX },
126 { "MirroredY", EAS_MirroredY },
127 { "ViewBox", EAS_ViewBox },
128 { "TextRotateAngle", EAS_TextRotateAngle },
129 { "ExtrusionAllowed", EAS_ExtrusionAllowed },
130 { "TextPathAllowed", EAS_TextPathAllowed },
131 { "ConcentricGradientFillAllowed", EAS_ConcentricGradientFillAllowed },
132 { "Extrusion", EAS_Extrusion },
133 { "Equations", EAS_Equations },
134 { "Equation", EAS_Equation },
135 { "Path", EAS_Path },
136 { "TextPath", EAS_TextPath },
137 { "Handles", EAS_Handles },
138 { "Handle", EAS_Handle },
139 { "Brightness", EAS_Brightness },
140 { "Depth", EAS_Depth },
141 { "Diffusion", EAS_Diffusion },
142 { "NumberOfLineSegments", EAS_NumberOfLineSegments },
143 { "LightFace", EAS_LightFace },
144 { "FirstLightHarsh", EAS_FirstLightHarsh },
145 { "SecondLightHarsh", EAS_SecondLightHarsh },
146 { "FirstLightLevel", EAS_FirstLightLevel },
147 { "SecondLightLevel", EAS_SecondLightLevel },
148 { "FirstLightDirection", EAS_FirstLightDirection },
149 { "SecondLightDirection", EAS_SecondLightDirection },
150 { "Metal", EAS_Metal },
151 { "ShadeMode", EAS_ShadeMode },
152 { "RotateAngle", EAS_RotateAngle },
153 { "RotationCenter", EAS_RotationCenter },
154 { "Shininess", EAS_Shininess },
155 { "Skew", EAS_Skew },
156 { "Specularity", EAS_Specularity },
157 { "ProjectionMode", EAS_ProjectionMode },
158 { "ViewPoint", EAS_ViewPoint },
159 { "Origin", EAS_Origin },
160 { "Color", EAS_Color },
161 { "Switched", EAS_Switched },
162 { "Polar", EAS_Polar },
163 { "RangeXMinimum", EAS_RangeXMinimum },
164 { "RangeXMaximum", EAS_RangeXMaximum },
165 { "RangeYMinimum", EAS_RangeYMinimum },
166 { "RangeYMaximum", EAS_RangeYMaximum },
167 { "RadiusRangeMinimum", EAS_RadiusRangeMinimum },
168 { "RadiusRangeMaximum", EAS_RadiusRangeMaximum },
169 { "Coordinates", EAS_Coordinates },
170 { "Segments", EAS_Segments },
171 { "StretchX", EAS_StretchX },
172 { "StretchY", EAS_StretchY },
173 { "TextFrames", EAS_TextFrames },
174 { "GluePoints", EAS_GluePoints },
175 { "GluePointLeavingDirections", EAS_GluePointLeavingDirections },
176 { "GluePointType", EAS_GluePointType },
177 { "TextPathMode", EAS_TextPathMode },
178 { "ScaleX", EAS_ScaleX },
179 { "SameLetterHeights", EAS_SameLetterHeights },
180 { "Position", EAS_Position },
181 { "AdjustmentValues", EAS_AdjustmentValues },
183 { "Last", EAS_Last },
184 { "NotFound", EAS_NotFound }
187 EnhancedCustomShapeTokenEnum EASGet( const rtl::OUString& rShapeType )
189 if ( !pHashMap )
190 { // init hash map
191 ::osl::MutexGuard aGuard( getHashMapMutex() );
192 if ( !pHashMap )
194 TypeNameHashMap* pH = new TypeNameHashMap;
195 const TokenTable* pPtr = pTokenTableArray;
196 const TokenTable* pEnd = pPtr + ( sizeof( pTokenTableArray ) / sizeof( TokenTable ) );
197 for ( ; pPtr < pEnd; pPtr++ )
198 (*pH)[ pPtr->pS ] = pPtr->pE;
199 pHashMap = pH;
202 EnhancedCustomShapeTokenEnum eRetValue = EAS_NotFound;
203 int i, nLen = rShapeType.getLength();
204 char* pBuf = new char[ nLen + 1 ];
205 for ( i = 0; i < nLen; i++ )
206 pBuf[ i ] = (char)rShapeType[ i ];
207 pBuf[ i ] = 0;
208 TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf ) );
209 delete[] pBuf;
210 if ( aHashIter != pHashMap->end() )
211 eRetValue = (*aHashIter).second;
212 return eRetValue;
215 rtl::OUString EASGet( const EnhancedCustomShapeTokenEnum eToken )
217 sal_uInt32 i = eToken >= EAS_Last
218 ? (sal_uInt32)EAS_NotFound
219 : (sal_uInt32)eToken;
220 return rtl::OUString::createFromAscii( pTokenTableArray[ i ].pS );