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