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