Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / oox / source / drawingml / shape3dproperties.cxx
blob3f9ac87158c48badff38508687632b5c11c3ae42
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 <drawingml/shape3dproperties.hxx>
21 #include <com/sun/star/drawing/BitmapMode.hpp>
22 #include <com/sun/star/graphic/XGraphicTransformer.hpp>
24 #include <comphelper/propertyvalue.hxx>
25 #include <oox/token/tokens.hxx>
26 #include <sal/log.hxx>
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::drawing;
30 using namespace ::com::sun::star::graphic;
33 namespace oox::drawingml {
35 OUString Generic3DProperties::getCameraPrstName( sal_Int32 nElement )
37 switch( nElement )
39 case XML_legacyObliqueTopLeft: return "legacyObliqueTopLeft";
40 case XML_legacyObliqueTop: return "legacyObliqueTop";
41 case XML_legacyObliqueTopRight: return "legacyObliqueTopRight";
42 case XML_legacyObliqueLeft: return "legacyObliqueLeft";
43 case XML_legacyObliqueFront: return "legacyObliqueFront";
44 case XML_legacyObliqueRight: return "legacyObliqueRight";
45 case XML_legacyObliqueBottomLeft: return "legacyObliqueBottomLeft";
46 case XML_legacyObliqueBottom: return "legacyObliqueBottom";
47 case XML_legacyObliqueBottomRight: return "legacyObliqueBottomRight";
48 case XML_legacyPerspectiveTopLeft: return "legacyPerspectiveTopLeft";
49 case XML_legacyPerspectiveTop: return "legacyPerspectiveTop";
50 case XML_legacyPerspectiveTopRight: return "legacyPerspectiveTopRight";
51 case XML_legacyPerspectiveLeft: return "legacyPerspectiveLeft";
52 case XML_legacyPerspectiveFront: return "legacyPerspectiveFront";
53 case XML_legacyPerspectiveRight: return "legacyPerspectiveRight";
54 case XML_legacyPerspectiveBottomLeft: return "legacyPerspectiveBottomLeft";
55 case XML_legacyPerspectiveBottom: return "legacyPerspectiveBottom";
56 case XML_legacyPerspectiveBottomRight: return "legacyPerspectiveBottomRight";
57 case XML_orthographicFront: return "orthographicFront";
58 case XML_isometricTopUp: return "isometricTopUp";
59 case XML_isometricTopDown: return "isometricTopDown";
60 case XML_isometricBottomUp: return "isometricBottomUp";
61 case XML_isometricBottomDown: return "isometricBottomDown";
62 case XML_isometricLeftUp: return "isometricLeftUp";
63 case XML_isometricLeftDown: return "isometricLeftDown";
64 case XML_isometricRightUp: return "isometricRightUp";
65 case XML_isometricRightDown: return "isometricRightDown";
66 case XML_isometricOffAxis1Left: return "isometricOffAxis1Left";
67 case XML_isometricOffAxis1Right: return "isometricOffAxis1Right";
68 case XML_isometricOffAxis1Top: return "isometricOffAxis1Top";
69 case XML_isometricOffAxis2Left: return "isometricOffAxis2Left";
70 case XML_isometricOffAxis2Right: return "isometricOffAxis2Right";
71 case XML_isometricOffAxis2Top: return "isometricOffAxis2Top";
72 case XML_isometricOffAxis3Left: return "isometricOffAxis3Left";
73 case XML_isometricOffAxis3Right: return "isometricOffAxis3Right";
74 case XML_isometricOffAxis3Bottom: return "isometricOffAxis3Bottom";
75 case XML_isometricOffAxis4Left: return "isometricOffAxis4Left";
76 case XML_isometricOffAxis4Right: return "isometricOffAxis4Right";
77 case XML_isometricOffAxis4Bottom: return "isometricOffAxis4Bottom";
78 case XML_obliqueTopLeft: return "obliqueTopLeft";
79 case XML_obliqueTop: return "obliqueTop";
80 case XML_obliqueTopRight: return "obliqueTopRight";
81 case XML_obliqueLeft: return "obliqueLeft";
82 case XML_obliqueRight: return "obliqueRight";
83 case XML_obliqueBottomLeft: return "obliqueBottomLeft";
84 case XML_obliqueBottom: return "obliqueBottom";
85 case XML_obliqueBottomRight: return "obliqueBottomRight";
86 case XML_perspectiveFront: return "perspectiveFront";
87 case XML_perspectiveLeft: return "perspectiveLeft";
88 case XML_perspectiveRight: return "perspectiveRight";
89 case XML_perspectiveAbove: return "perspectiveAbove";
90 case XML_perspectiveBelow: return "perspectiveBelow";
91 case XML_perspectiveAboveLeftFacing: return "perspectiveAboveLeftFacing";
92 case XML_perspectiveAboveRightFacing: return "perspectiveAboveRightFacing";
93 case XML_perspectiveContrastingLeftFacing: return "perspectiveContrastingLeftFacing";
94 case XML_perspectiveContrastingRightFacing: return "perspectiveContrastingRightFacing";
95 case XML_perspectiveHeroicLeftFacing: return "perspectiveHeroicLeftFacing";
96 case XML_perspectiveHeroicRightFacing: return "perspectiveHeroicRightFacing";
97 case XML_perspectiveHeroicExtremeLeftFacing: return "perspectiveHeroicExtremeLeftFacing";
98 case XML_perspectiveHeroicExtremeRightFacing: return "perspectiveHeroicExtremeRightFacing";
99 case XML_perspectiveRelaxed: return "perspectiveRelaxed";
100 case XML_perspectiveRelaxedModerately: return "perspectiveRelaxedModerately";
102 SAL_WARN( "oox.drawingml", "Generic3DProperties::getCameraPrstName - unexpected prst type" );
103 return OUString();
106 OUString Generic3DProperties::getLightRigName( sal_Int32 nElement )
108 switch( nElement )
110 case XML_legacyFlat1: return "legacyFlat1";
111 case XML_legacyFlat2: return "legacyFlat2";
112 case XML_legacyFlat3: return "legacyFlat3";
113 case XML_legacyFlat4: return "legacyFlat4";
114 case XML_legacyNormal1: return "legacyNormal1";
115 case XML_legacyNormal2: return "legacyNormal2";
116 case XML_legacyNormal3: return "legacyNormal3";
117 case XML_legacyNormal4: return "legacyNormal4";
118 case XML_legacyHarsh1: return "legacyHarsh1";
119 case XML_legacyHarsh2: return "legacyHarsh2";
120 case XML_legacyHarsh3: return "legacyHarsh3";
121 case XML_legacyHarsh4: return "legacyHarsh4";
122 case XML_threePt: return "threePt";
123 case XML_balanced: return "balanced";
124 case XML_soft: return "soft";
125 case XML_harsh: return "harsh";
126 case XML_flood: return "flood";
127 case XML_contrasting: return "contrasting";
128 case XML_morning: return "morning";
129 case XML_sunrise: return "sunrise";
130 case XML_sunset: return "sunset";
131 case XML_chilly: return "chilly";
132 case XML_freezing: return "freezing";
133 case XML_flat: return "flat";
134 case XML_twoPt: return "twoPt";
135 case XML_glow: return "glow";
136 case XML_brightRoom: return "brightRoom";
138 SAL_WARN( "oox.drawingml", "Generic3DProperties::getLightRigName - unexpected token" );
139 return OUString();
142 OUString Generic3DProperties::getLightRigDirName( sal_Int32 nElement )
144 switch( nElement )
146 case XML_tl: return "tl";
147 case XML_t: return "t";
148 case XML_tr: return "tr";
149 case XML_l: return "l";
150 case XML_r: return "r";
151 case XML_bl: return "bl";
152 case XML_b: return "b";
153 case XML_br: return "br";
155 SAL_WARN( "oox.drawingml", "Generic3DProperties::getLightRigDirName - unexpected token" );
156 return OUString();
159 OUString Generic3DProperties::getBevelPresetTypeString( sal_Int32 nType )
161 switch (nType)
163 case XML_relaxedInset: return "relaxedInset";
164 case XML_circle: return "circle";
165 case XML_slope: return "slope";
166 case XML_cross: return "cross";
167 case XML_angle: return "angle";
168 case XML_softRound: return "softRound";
169 case XML_convex: return "convex";
170 case XML_coolSlant: return "coolSlant";
171 case XML_divot: return "divot";
172 case XML_riblet: return "riblet";
173 case XML_hardEdge: return "hardEdge";
174 case XML_artDeco: return "artDeco";
176 SAL_WARN( "oox.drawingml", "Generic3DProperties::getBevelPresetTypeString - unexpected token" );
177 return OUString();
180 OUString Generic3DProperties::getPresetMaterialTypeString( sal_Int32 nType )
182 switch (nType)
184 case XML_legacyMatte: return "legacyMatte";
185 case XML_legacyPlastic: return "legacyPlastic";
186 case XML_legacyMetal: return "legacyMetal";
187 case XML_legacyWireframe: return "legacyWireframe";
188 case XML_matte: return "matte";
189 case XML_plastic: return "plastic";
190 case XML_metal: return "metal";
191 case XML_warmMatte: return "warmMatte";
192 case XML_translucentPowder: return "translucentPowder";
193 case XML_powder: return "powder";
194 case XML_dkEdge: return "dkEdge";
195 case XML_softEdge: return "softEdge";
196 case XML_clear: return "clear";
197 case XML_flat: return "flat";
198 case XML_softmetal: return "softmetal";
199 case XML_none: return "none";
201 SAL_WARN( "oox.drawingml", "Generic3DProperties::getPresetMaterialTypeString - unexpected token" );
202 return OUString();
205 css::uno::Sequence< css::beans::PropertyValue > Generic3DProperties::getCameraAttributes()
207 css::uno::Sequence<css::beans::PropertyValue> aSeq(6);
208 auto pSeq = aSeq.getArray();
209 sal_Int32 nSize = 0;
210 if( mfFieldOfVision.has_value() )
212 pSeq[nSize].Name = "fov";
213 pSeq[nSize].Value <<= *mfFieldOfVision;
214 nSize++;
216 if( mfZoom.has_value() )
218 pSeq[nSize].Name = "zoom";
219 pSeq[nSize].Value <<= *mfZoom;
220 nSize++;
222 if( mnPreset.has_value() )
224 pSeq[nSize].Name = "prst";
225 pSeq[nSize].Value <<= getCameraPrstName( *mnPreset );
226 nSize++;
228 if( maCameraRotation.mnLatitude.has_value() )
230 pSeq[nSize].Name = "rotLat";
231 pSeq[nSize].Value <<= *maCameraRotation.mnLatitude;
232 nSize++;
234 if( maCameraRotation.mnLongitude.has_value() )
236 pSeq[nSize].Name = "rotLon";
237 pSeq[nSize].Value <<= *maCameraRotation.mnLongitude;
238 nSize++;
240 if( maCameraRotation.mnRevolution.has_value() )
242 pSeq[nSize].Name = "rotRev";
243 pSeq[nSize].Value <<= *maCameraRotation.mnRevolution;
244 nSize++;
246 aSeq.realloc( nSize );
247 return aSeq;
250 css::uno::Sequence< css::beans::PropertyValue > Generic3DProperties::getLightRigAttributes()
252 css::uno::Sequence<css::beans::PropertyValue> aSeq(5);
253 auto pSeq = aSeq.getArray();
254 sal_Int32 nSize = 0;
255 if( mnLightRigDirection.has_value() )
257 pSeq[nSize].Name = "dir";
258 pSeq[nSize].Value <<= getLightRigDirName( *mnLightRigDirection );
259 nSize++;
261 if( mnLightRigType.has_value() )
263 pSeq[nSize].Name = "rig";
264 pSeq[nSize].Value <<= getLightRigName( *mnLightRigType );
265 nSize++;
267 if( maLightRigRotation.mnLatitude.has_value() )
269 pSeq[nSize].Name = "rotLat";
270 pSeq[nSize].Value <<= *maLightRigRotation.mnLatitude;
271 nSize++;
273 if( maLightRigRotation.mnLongitude.has_value() )
275 pSeq[nSize].Name = "rotLon";
276 pSeq[nSize].Value <<= *maLightRigRotation.mnLongitude;
277 nSize++;
279 if( maLightRigRotation.mnRevolution.has_value() )
281 pSeq[nSize].Name = "rotRev";
282 pSeq[nSize].Value <<= *maLightRigRotation.mnRevolution;
283 nSize++;
285 aSeq.realloc( nSize );
286 return aSeq;
289 css::uno::Sequence< css::beans::PropertyValue > Generic3DProperties::getBevelAttributes( BevelProperties rProps )
291 css::uno::Sequence<css::beans::PropertyValue> aSeq(3);
292 auto pSeq = aSeq.getArray();
293 sal_Int32 nSize = 0;
294 if( rProps.mnPreset.has_value() )
296 pSeq[nSize].Name = "prst";
297 pSeq[nSize].Value <<= getBevelPresetTypeString( *rProps.mnPreset );
298 nSize++;
300 if( rProps.mnWidth.has_value() )
302 pSeq[nSize].Name = "w";
303 pSeq[nSize].Value <<= *rProps.mnWidth;
304 nSize++;
306 if( rProps.mnHeight.has_value() )
308 pSeq[nSize].Name = "h";
309 pSeq[nSize].Value <<= *rProps.mnHeight;
310 nSize++;
312 aSeq.realloc( nSize );
313 return aSeq;
316 css::uno::Sequence< css::beans::PropertyValue > Generic3DProperties::getColorAttributes(
317 const Color& rColor, const GraphicHelper& rGraphicHelper, ::Color rPhClr )
319 const OUString& sColorScheme = rColor.getSchemeColorName();
320 if( sColorScheme.isEmpty() )
322 // RGB color and transparency value
323 return { comphelper::makePropertyValue("rgbClr", rColor.getColor( rGraphicHelper, rPhClr )),
324 comphelper::makePropertyValue("rgbClrTransparency", rColor.getTransparency()) };
326 // scheme color with name and transformations
327 return { comphelper::makePropertyValue("schemeClr", sColorScheme),
328 comphelper::makePropertyValue("schemeClrTransformations",
329 rColor.getTransformations()) };
332 css::uno::Sequence< css::beans::PropertyValue > Generic3DProperties::getShape3DAttributes(
333 const GraphicHelper& rGraphicHelper, ::Color rPhClr )
335 css::uno::Sequence<css::beans::PropertyValue> aSeq(8);
336 auto pSeq = aSeq.getArray();
337 sal_Int32 nSize = 0;
338 if( mnExtrusionH.has_value() )
340 pSeq[nSize].Name = "extrusionH";
341 pSeq[nSize].Value <<= *mnExtrusionH;
342 nSize++;
344 if( mnContourW.has_value() )
346 pSeq[nSize].Name = "contourW";
347 pSeq[nSize].Value <<= *mnContourW;
348 nSize++;
350 if( mnShapeZ.has_value() )
352 pSeq[nSize].Name = "z";
353 pSeq[nSize].Value <<= *mnShapeZ;
354 nSize++;
356 if( mnMaterial.has_value() )
358 pSeq[nSize].Name = "prstMaterial";
359 pSeq[nSize].Value <<= getPresetMaterialTypeString( *mnMaterial );
360 nSize++;
362 if( maTopBevelProperties.has_value() )
364 pSeq[nSize].Name = "bevelT";
365 pSeq[nSize].Value <<= getBevelAttributes( *maTopBevelProperties );
366 nSize++;
368 if( maBottomBevelProperties.has_value() )
370 pSeq[nSize].Name = "bevelB";
371 pSeq[nSize].Value <<= getBevelAttributes( *maBottomBevelProperties );
372 nSize++;
374 if( maExtrusionColor.isUsed() )
376 pSeq[nSize].Name = "extrusionClr";
377 pSeq[nSize].Value <<= getColorAttributes( maExtrusionColor, rGraphicHelper, rPhClr );
378 nSize++;
380 if( maContourColor.isUsed() )
382 pSeq[nSize].Name = "contourClr";
383 pSeq[nSize].Value <<= getColorAttributes( maContourColor, rGraphicHelper, rPhClr );
384 nSize++;
386 aSeq.realloc( nSize );
387 return aSeq;
390 } // namespace oox
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */