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
28namespace {
29
30struct TokenTable
31{
32 const char* pS;
34};
35
36}
37
38const 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 { "extrusion-metal-type", EAS_extrusion_metal_type },
63 { "shade-mode", EAS_shade_mode },
64 { "extrusion-rotation-angle", EAS_extrusion_rotation_angle },
65 { "extrusion-rotation-center", EAS_extrusion_rotation_center },
66 { "extrusion-shininess", EAS_extrusion_shininess },
67 { "extrusion-skew", EAS_extrusion_skew },
68 { "extrusion-specularity", EAS_extrusion_specularity },
69 { "extrusion-specularity-loext", EAS_extrusion_specularity_loext },
70 { "projection", EAS_projection },
71 { "extrusion-viewpoint", EAS_extrusion_viewpoint },
72 { "extrusion-origin", EAS_extrusion_origin },
73 { "extrusion-color", EAS_extrusion_color },
74 { "enhanced-path", EAS_enhanced_path },
75 { "path-stretchpoint-x", EAS_path_stretchpoint_x },
76 { "path-stretchpoint-y", EAS_path_stretchpoint_y },
77 { "text-areas", EAS_text_areas },
78 { "glue-points", EAS_glue_points },
79 { "glue-point-type", EAS_glue_point_type },
80 { "glue-point-leaving-directions", EAS_glue_point_leaving_directions },
81 { "text-path", EAS_text_path },
82 { "text-path-mode", EAS_text_path_mode },
83 { "text-path-scale", EAS_text_path_scale },
84 { "text-path-same-letter-heights", EAS_text_path_same_letter_heights },
85 { "modifiers", EAS_modifiers },
86 { "equation", EAS_equation },
87 { "formula", EAS_formula },
88 { "handle", EAS_handle },
89 { "handle-mirror-horizontal", EAS_handle_mirror_horizontal },
90 { "handle-mirror-vertical", EAS_handle_mirror_vertical },
91 { "handle-switched", EAS_handle_switched },
92 { "handle-position", EAS_handle_position },
93 { "handle-range-x-minimum", EAS_handle_range_x_minimum },
94 { "handle-range-x-maximum", EAS_handle_range_x_maximum },
95 { "handle-range-y-minimum", EAS_handle_range_y_minimum },
96 { "handle-range-y-maximum", EAS_handle_range_y_maximum },
97 { "handle-polar", EAS_handle_polar },
98 { "handle-radius-range-minimum", EAS_handle_radius_range_minimum },
99 { "handle-radius-range-maximum", EAS_handle_radius_range_maximum },
100 { "sub-view-size", EAS_sub_view_size },
101
102 { "CustomShapeEngine", EAS_CustomShapeEngine },
103 { "CustomShapeData", EAS_CustomShapeData },
104 { "Type", EAS_Type },
105 { "MirroredX", EAS_MirroredX },
106 { "MirroredY", EAS_MirroredY },
107 { "ViewBox", EAS_ViewBox },
108 { "TextRotateAngle", EAS_TextRotateAngle },
109 { "TextPreRotateAngle", EAS_TextPreRotateAngle },
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 { "MetalType", EAS_MetalType },
133 { "ShadeMode", EAS_ShadeMode },
134 { "RotateAngle", EAS_RotateAngle },
135 { "RotationCenter", EAS_RotationCenter },
136 { "Shininess", EAS_Shininess },
137 { "Skew", EAS_Skew },
138 { "Specularity", EAS_Specularity },
139 { "ProjectionMode", EAS_ProjectionMode },
140 { "ViewPoint", EAS_ViewPoint },
141 { "Origin", EAS_Origin },
142 { "Color", EAS_Color },
143 { "Switched", EAS_Switched },
144 { "Polar", EAS_Polar },
145 { "RangeXMinimum", EAS_RangeXMinimum },
146 { "RangeXMaximum", EAS_RangeXMaximum },
147 { "RangeYMinimum", EAS_RangeYMinimum },
148 { "RangeYMaximum", EAS_RangeYMaximum },
149 { "RadiusRangeMinimum", EAS_RadiusRangeMinimum },
150 { "RadiusRangeMaximum", EAS_RadiusRangeMaximum },
151 { "Coordinates", EAS_Coordinates },
152 { "Segments", EAS_Segments },
153 { "StretchX", EAS_StretchX },
154 { "StretchY", EAS_StretchY },
155 { "TextFrames", EAS_TextFrames },
156 { "GluePoints", EAS_GluePoints },
157 { "GluePointLeavingDirections", EAS_GluePointLeavingDirections },
158 { "GluePointType", EAS_GluePointType },
159 { "TextPathMode", EAS_TextPathMode },
160 { "ScaleX", EAS_ScaleX },
161 { "SameLetterHeights", EAS_SameLetterHeights },
162 { "Position", EAS_Position },
163 { "AdjustmentValues", EAS_AdjustmentValues },
164 { "SubViewSize", EAS_SubViewSize },
165
166 { "Last", EAS_Last },
167 { "NotFound", EAS_NotFound }
168};
169
170typedef std::unordered_map< const char*, EnhancedCustomShapeTokenEnum, rtl::CStringHash, rtl::CStringEqual> TypeNameHashMap;
172{
173 static TypeNameHashMap aHashMap = []()
174 { // init hash map
175 TypeNameHashMap res;
176 for (auto const & pair : pTokenTableArray)
177 res[pair.pS] = pair.pE;
178 return res;
179 }();
180
181 return aHashMap;
182}
183
184EnhancedCustomShapeTokenEnum EASGet( std::u16string_view rShapeType )
185{
187 size_t i, nLen = rShapeType.size();
188 std::unique_ptr<char[]> pBuf(new char[ nLen + 1 ]);
189 for ( i = 0; i < nLen; i++ )
190 pBuf[ i ] = static_cast<char>(rShapeType[ i ]);
191 pBuf[ i ] = 0;
192 auto& rHashMap = GetNameHashMap();
193 TypeNameHashMap::const_iterator aHashIter( rHashMap.find( pBuf.get() ) );
194 if ( aHashIter != rHashMap.end() )
195 eRetValue = (*aHashIter).second;
196 return eRetValue;
197}
198
200{
201 return EASGet(SvXMLImport::getNameFromToken(nToken));
202}
203
205{
206 sal_uInt32 i = eToken >= EAS_Last
207 ? sal_uInt32(EAS_NotFound)
208 : static_cast<sal_uInt32>(eToken);
209 return OUString::createFromAscii( pTokenTableArray[ i ].pS );
210}
211
212}
213
214/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
EnhancedCustomShapeTokenEnum pE
const char * pS
int i
static const TypeNameHashMap & GetNameHashMap()
std::unordered_map< const char *, EnhancedCustomShapeTokenEnum, rtl::CStringHash, rtl::CStringEqual > TypeNameHashMap
EnhancedCustomShapeTokenEnum EASGet(std::u16string_view rShapeType)
DefTokenId nToken
XMLTokenEnum eToken
Definition: xmltoken.cxx:40