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