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