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