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