Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / drawingml / shape3dproperties.cxx
blobac94f882d539f5e0187b7098826d1f5834c8f058
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/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/awt/Gradient.hpp>
24 #include <com/sun/star/awt/Size.hpp>
25 #include <com/sun/star/awt/XBitmap.hpp>
26 #include <com/sun/star/awt/XDevice.hpp>
27 #include <com/sun/star/drawing/BitmapMode.hpp>
28 #include <com/sun/star/drawing/FillStyle.hpp>
29 #include <com/sun/star/drawing/RectanglePoint.hpp>
30 #include <com/sun/star/graphic/XGraphicTransformer.hpp>
31 #include <oox/helper/propertymap.hxx>
32 #include <oox/helper/propertyset.hxx>
33 #include <oox/token/tokens.hxx>
34 #include <sal/log.hxx>
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::drawing;
38 using namespace ::com::sun::star::graphic;
41 namespace oox {
42 namespace drawingml {
44 OUString Shape3DProperties::getCameraPrstName( sal_Int32 nElement )
46 switch( nElement )
48 case XML_legacyObliqueTopLeft: return "legacyObliqueTopLeft";
49 case XML_legacyObliqueTop: return "legacyObliqueTop";
50 case XML_legacyObliqueTopRight: return "legacyObliqueTopRight";
51 case XML_legacyObliqueLeft: return "legacyObliqueLeft";
52 case XML_legacyObliqueFront: return "legacyObliqueFront";
53 case XML_legacyObliqueRight: return "legacyObliqueRight";
54 case XML_legacyObliqueBottomLeft: return "legacyObliqueBottomLeft";
55 case XML_legacyObliqueBottom: return "legacyObliqueBottom";
56 case XML_legacyObliqueBottomRight: return "legacyObliqueBottomRight";
57 case XML_legacyPerspectiveTopLeft: return "legacyPerspectiveTopLeft";
58 case XML_legacyPerspectiveTop: return "legacyPerspectiveTop";
59 case XML_legacyPerspectiveTopRight: return "legacyPerspectiveTopRight";
60 case XML_legacyPerspectiveLeft: return "legacyPerspectiveLeft";
61 case XML_legacyPerspectiveFront: return "legacyPerspectiveFront";
62 case XML_legacyPerspectiveRight: return "legacyPerspectiveRight";
63 case XML_legacyPerspectiveBottomLeft: return "legacyPerspectiveBottomLeft";
64 case XML_legacyPerspectiveBottom: return "legacyPerspectiveBottom";
65 case XML_legacyPerspectiveBottomRight: return "legacyPerspectiveBottomRight";
66 case XML_orthographicFront: return "orthographicFront";
67 case XML_isometricTopUp: return "isometricTopUp";
68 case XML_isometricTopDown: return "isometricTopDown";
69 case XML_isometricBottomUp: return "isometricBottomUp";
70 case XML_isometricBottomDown: return "isometricBottomDown";
71 case XML_isometricLeftUp: return "isometricLeftUp";
72 case XML_isometricLeftDown: return "isometricLeftDown";
73 case XML_isometricRightUp: return "isometricRightUp";
74 case XML_isometricRightDown: return "isometricRightDown";
75 case XML_isometricOffAxis1Left: return "isometricOffAxis1Left";
76 case XML_isometricOffAxis1Right: return "isometricOffAxis1Right";
77 case XML_isometricOffAxis1Top: return "isometricOffAxis1Top";
78 case XML_isometricOffAxis2Left: return "isometricOffAxis2Left";
79 case XML_isometricOffAxis2Right: return "isometricOffAxis2Right";
80 case XML_isometricOffAxis2Top: return "isometricOffAxis2Top";
81 case XML_isometricOffAxis3Left: return "isometricOffAxis3Left";
82 case XML_isometricOffAxis3Right: return "isometricOffAxis3Right";
83 case XML_isometricOffAxis3Bottom: return "isometricOffAxis3Bottom";
84 case XML_isometricOffAxis4Left: return "isometricOffAxis4Left";
85 case XML_isometricOffAxis4Right: return "isometricOffAxis4Right";
86 case XML_isometricOffAxis4Bottom: return "isometricOffAxis4Bottom";
87 case XML_obliqueTopLeft: return "obliqueTopLeft";
88 case XML_obliqueTop: return "obliqueTop";
89 case XML_obliqueTopRight: return "obliqueTopRight";
90 case XML_obliqueLeft: return "obliqueLeft";
91 case XML_obliqueRight: return "obliqueRight";
92 case XML_obliqueBottomLeft: return "obliqueBottomLeft";
93 case XML_obliqueBottom: return "obliqueBottom";
94 case XML_obliqueBottomRight: return "obliqueBottomRight";
95 case XML_perspectiveFront: return "perspectiveFront";
96 case XML_perspectiveLeft: return "perspectiveLeft";
97 case XML_perspectiveRight: return "perspectiveRight";
98 case XML_perspectiveAbove: return "perspectiveAbove";
99 case XML_perspectiveBelow: return "perspectiveBelow";
100 case XML_perspectiveAboveLeftFacing: return "perspectiveAboveLeftFacing";
101 case XML_perspectiveAboveRightFacing: return "perspectiveAboveRightFacing";
102 case XML_perspectiveContrastingLeftFacing: return "perspectiveContrastingLeftFacing";
103 case XML_perspectiveContrastingRightFacing: return "perspectiveContrastingRightFacing";
104 case XML_perspectiveHeroicLeftFacing: return "perspectiveHeroicLeftFacing";
105 case XML_perspectiveHeroicRightFacing: return "perspectiveHeroicRightFacing";
106 case XML_perspectiveHeroicExtremeLeftFacing: return "perspectiveHeroicExtremeLeftFacing";
107 case XML_perspectiveHeroicExtremeRightFacing: return "perspectiveHeroicExtremeRightFacing";
108 case XML_perspectiveRelaxed: return "perspectiveRelaxed";
109 case XML_perspectiveRelaxedModerately: return "perspectiveRelaxedModerately";
111 SAL_WARN( "oox.drawingml", "Shape3DProperties::getCameraPrstName - unexpected prst type" );
112 return OUString();
115 OUString Shape3DProperties::getLightRigName( sal_Int32 nElement )
117 switch( nElement )
119 case XML_legacyFlat1: return "legacyFlat1";
120 case XML_legacyFlat2: return "legacyFlat2";
121 case XML_legacyFlat3: return "legacyFlat3";
122 case XML_legacyFlat4: return "legacyFlat4";
123 case XML_legacyNormal1: return "legacyNormal1";
124 case XML_legacyNormal2: return "legacyNormal2";
125 case XML_legacyNormal3: return "legacyNormal3";
126 case XML_legacyNormal4: return "legacyNormal4";
127 case XML_legacyHarsh1: return "legacyHarsh1";
128 case XML_legacyHarsh2: return "legacyHarsh2";
129 case XML_legacyHarsh3: return "legacyHarsh3";
130 case XML_legacyHarsh4: return "legacyHarsh4";
131 case XML_threePt: return "threePt";
132 case XML_balanced: return "balanced";
133 case XML_soft: return "soft";
134 case XML_harsh: return "harsh";
135 case XML_flood: return "flood";
136 case XML_contrasting: return "contrasting";
137 case XML_morning: return "morning";
138 case XML_sunrise: return "sunrise";
139 case XML_sunset: return "sunset";
140 case XML_chilly: return "chilly";
141 case XML_freezing: return "freezing";
142 case XML_flat: return "flat";
143 case XML_twoPt: return "twoPt";
144 case XML_glow: return "glow";
145 case XML_brightRoom: return "brightRoom";
147 SAL_WARN( "oox.drawingml", "Shape3DProperties::getLightRigName - unexpected token" );
148 return OUString();
151 OUString Shape3DProperties::getLightRigDirName( sal_Int32 nElement )
153 switch( nElement )
155 case XML_tl: return "tl";
156 case XML_t: return "t";
157 case XML_tr: return "tr";
158 case XML_l: return "l";
159 case XML_r: return "r";
160 case XML_bl: return "bl";
161 case XML_b: return "b";
162 case XML_br: return "br";
164 SAL_WARN( "oox.drawingml", "Shape3DProperties::getLightRigDirName - unexpected token" );
165 return OUString();
168 OUString Shape3DProperties::getBevelPresetTypeString( sal_Int32 nType )
170 switch (nType)
172 case XML_relaxedInset: return "relaxedInset";
173 case XML_circle: return "circle";
174 case XML_slope: return "slope";
175 case XML_cross: return "cross";
176 case XML_angle: return "angle";
177 case XML_softRound: return "softRound";
178 case XML_convex: return "convex";
179 case XML_coolSlant: return "coolSlant";
180 case XML_divot: return "divot";
181 case XML_riblet: return "riblet";
182 case XML_hardEdge: return "hardEdge";
183 case XML_artDeco: return "artDeco";
185 SAL_WARN( "oox.drawingml", "Shape3DProperties::getBevelPresetTypeString - unexpected token" );
186 return OUString();
189 OUString Shape3DProperties::getPresetMaterialTypeString( sal_Int32 nType )
191 switch (nType)
193 case XML_legacyMatte: return "legacyMatte";
194 case XML_legacyPlastic: return "legacyPlastic";
195 case XML_legacyMetal: return "legacyMetal";
196 case XML_legacyWireframe: return "legacyWireframe";
197 case XML_matte: return "matte";
198 case XML_plastic: return "plastic";
199 case XML_metal: return "metal";
200 case XML_warmMatte: return "warmMatte";
201 case XML_translucentPowder: return "translucentPowder";
202 case XML_powder: return "powder";
203 case XML_dkEdge: return "dkEdge";
204 case XML_softEdge: return "softEdge";
205 case XML_clear: return "clear";
206 case XML_flat: return "flat";
207 case XML_softmetal: return "softmetal";
208 case XML_none: return "none";
210 SAL_WARN( "oox.drawingml", "Shape3DProperties::getPresetMaterialTypeString - unexpected token" );
211 return OUString();
214 css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getCameraAttributes()
216 css::uno::Sequence<css::beans::PropertyValue> aSeq(6);
217 sal_Int32 nSize = 0;
218 if( mfFieldOfVision.has() )
220 aSeq[nSize].Name = "fov";
221 aSeq[nSize].Value <<= mfFieldOfVision.use();
222 nSize++;
224 if( mfZoom.has() )
226 aSeq[nSize].Name = "zoom";
227 aSeq[nSize].Value <<= mfZoom.use();
228 nSize++;
230 if( mnPreset.has() )
232 aSeq[nSize].Name = "prst";
233 aSeq[nSize].Value <<= getCameraPrstName( mnPreset.use() );
234 nSize++;
236 if( maCameraRotation.mnLatitude.has() )
238 aSeq[nSize].Name = "rotLat";
239 aSeq[nSize].Value <<= maCameraRotation.mnLatitude.use();
240 nSize++;
242 if( maCameraRotation.mnLongitude.has() )
244 aSeq[nSize].Name = "rotLon";
245 aSeq[nSize].Value <<= maCameraRotation.mnLongitude.use();
246 nSize++;
248 if( maCameraRotation.mnRevolution.has() )
250 aSeq[nSize].Name = "rotRev";
251 aSeq[nSize].Value <<= maCameraRotation.mnRevolution.use();
252 nSize++;
254 aSeq.realloc( nSize );
255 return aSeq;
258 css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getLightRigAttributes()
260 css::uno::Sequence<css::beans::PropertyValue> aSeq(5);
261 sal_Int32 nSize = 0;
262 if( mnLightRigDirection.has() )
264 aSeq[nSize].Name = "dir";
265 aSeq[nSize].Value <<= getLightRigDirName( mnLightRigDirection.use() );
266 nSize++;
268 if( mnLightRigType.has() )
270 aSeq[nSize].Name = "rig";
271 aSeq[nSize].Value <<= getLightRigName( mnLightRigType.use() );
272 nSize++;
274 if( maLightRigRotation.mnLatitude.has() )
276 aSeq[nSize].Name = "rotLat";
277 aSeq[nSize].Value <<= maLightRigRotation.mnLatitude.use();
278 nSize++;
280 if( maLightRigRotation.mnLongitude.has() )
282 aSeq[nSize].Name = "rotLon";
283 aSeq[nSize].Value <<= maLightRigRotation.mnLongitude.use();
284 nSize++;
286 if( maLightRigRotation.mnRevolution.has() )
288 aSeq[nSize].Name = "rotRev";
289 aSeq[nSize].Value <<= maLightRigRotation.mnRevolution.use();
290 nSize++;
292 aSeq.realloc( nSize );
293 return aSeq;
296 css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getBevelAttributes( BevelProperties rProps )
298 css::uno::Sequence<css::beans::PropertyValue> aSeq(3);
299 sal_Int32 nSize = 0;
300 if( rProps.mnPreset.has() )
302 aSeq[nSize].Name = "prst";
303 aSeq[nSize].Value <<= getBevelPresetTypeString( rProps.mnPreset.use() );
304 nSize++;
306 if( rProps.mnWidth.has() )
308 aSeq[nSize].Name = "w";
309 aSeq[nSize].Value <<= rProps.mnWidth.use();
310 nSize++;
312 if( rProps.mnHeight.has() )
314 aSeq[nSize].Name = "h";
315 aSeq[nSize].Value <<= rProps.mnHeight.use();
316 nSize++;
318 aSeq.realloc( nSize );
319 return aSeq;
322 css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getColorAttributes(
323 const Color& rColor, const GraphicHelper& rGraphicHelper, ::Color rPhClr )
325 css::uno::Sequence<css::beans::PropertyValue> aSeq(2);
326 const OUString& sColorScheme = rColor.getSchemeName();
327 if( sColorScheme.isEmpty() )
329 // RGB color and transparency value
330 aSeq[0].Name = "rgbClr";
331 aSeq[0].Value <<= rColor.getColor( rGraphicHelper, rPhClr );
332 aSeq[1].Name = "rgbClrTransparency";
333 aSeq[1].Value <<= rColor.getTransparency();
335 else
337 // scheme color with name and transformations
338 aSeq[0].Name = "schemeClr";
339 aSeq[0].Value <<= sColorScheme;
340 aSeq[1].Name = "schemeClrTransformations";
341 aSeq[1].Value <<= rColor.getTransformations();
343 return aSeq;
346 css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getShape3DAttributes(
347 const GraphicHelper& rGraphicHelper, ::Color rPhClr )
349 css::uno::Sequence<css::beans::PropertyValue> aSeq(8);
350 sal_Int32 nSize = 0;
351 if( mnExtrusionH.has() )
353 aSeq[nSize].Name = "extrusionH";
354 aSeq[nSize].Value <<= mnExtrusionH.use();
355 nSize++;
357 if( mnContourW.has() )
359 aSeq[nSize].Name = "contourW";
360 aSeq[nSize].Value <<= mnContourW.use();
361 nSize++;
363 if( mnShapeZ.has() )
365 aSeq[nSize].Name = "z";
366 aSeq[nSize].Value <<= mnShapeZ.use();
367 nSize++;
369 if( mnMaterial.has() )
371 aSeq[nSize].Name = "prstMaterial";
372 aSeq[nSize].Value <<= getPresetMaterialTypeString( mnMaterial.use() );
373 nSize++;
375 if( maTopBevelProperties.has() )
377 aSeq[nSize].Name = "bevelT";
378 aSeq[nSize].Value <<= getBevelAttributes( maTopBevelProperties.use() );
379 nSize++;
381 if( maBottomBevelProperties.has() )
383 aSeq[nSize].Name = "bevelB";
384 aSeq[nSize].Value <<= getBevelAttributes( maBottomBevelProperties.use() );
385 nSize++;
387 if( maExtrusionColor.isUsed() )
389 aSeq[nSize].Name = "extrusionClr";
390 aSeq[nSize].Value <<= getColorAttributes( maExtrusionColor, rGraphicHelper, rPhClr );
391 nSize++;
393 if( maContourColor.isUsed() )
395 aSeq[nSize].Name = "contourClr";
396 aSeq[nSize].Value <<= getColorAttributes( maContourColor, rGraphicHelper, rPhClr );
397 nSize++;
399 aSeq.realloc( nSize );
400 return aSeq;
403 } // namespace drawingml
404 } // namespace oox
406 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */