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