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