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