LibreOffice Module oox (master)  1
shape3dproperties.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 <com/sun/star/drawing/BitmapMode.hpp>
22 #include <com/sun/star/graphic/XGraphicTransformer.hpp>
23 
25 #include <oox/token/tokens.hxx>
26 #include <sal/log.hxx>
27 
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::drawing;
30 using namespace ::com::sun::star::graphic;
31 
32 
33 namespace oox::drawingml {
34 
35 OUString Generic3DProperties::getCameraPrstName( sal_Int32 nElement )
36 {
37  switch( nElement )
38  {
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";
101  }
102  SAL_WARN( "oox.drawingml", "Generic3DProperties::getCameraPrstName - unexpected prst type" );
103  return OUString();
104 }
105 
106 OUString Generic3DProperties::getLightRigName( sal_Int32 nElement )
107 {
108  switch( nElement )
109  {
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";
137  }
138  SAL_WARN( "oox.drawingml", "Generic3DProperties::getLightRigName - unexpected token" );
139  return OUString();
140 }
141 
142 OUString Generic3DProperties::getLightRigDirName( sal_Int32 nElement )
143 {
144  switch( nElement )
145  {
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";
154  }
155  SAL_WARN( "oox.drawingml", "Generic3DProperties::getLightRigDirName - unexpected token" );
156  return OUString();
157 }
158 
160 {
161  switch (nType)
162  {
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";
175  }
176  SAL_WARN( "oox.drawingml", "Generic3DProperties::getBevelPresetTypeString - unexpected token" );
177  return OUString();
178 }
179 
181 {
182  switch (nType)
183  {
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";
200  }
201  SAL_WARN( "oox.drawingml", "Generic3DProperties::getPresetMaterialTypeString - unexpected token" );
202  return OUString();
203 }
204 
205 css::uno::Sequence< css::beans::PropertyValue > Generic3DProperties::getCameraAttributes()
206 {
207  css::uno::Sequence<css::beans::PropertyValue> aSeq(6);
208  auto pSeq = aSeq.getArray();
209  sal_Int32 nSize = 0;
210  if( mfFieldOfVision.has() )
211  {
212  pSeq[nSize].Name = "fov";
213  pSeq[nSize].Value <<= mfFieldOfVision.use();
214  nSize++;
215  }
216  if( mfZoom.has() )
217  {
218  pSeq[nSize].Name = "zoom";
219  pSeq[nSize].Value <<= mfZoom.use();
220  nSize++;
221  }
222  if( mnPreset.has() )
223  {
224  pSeq[nSize].Name = "prst";
225  pSeq[nSize].Value <<= getCameraPrstName( mnPreset.use() );
226  nSize++;
227  }
229  {
230  pSeq[nSize].Name = "rotLat";
231  pSeq[nSize].Value <<= maCameraRotation.mnLatitude.use();
232  nSize++;
233  }
235  {
236  pSeq[nSize].Name = "rotLon";
237  pSeq[nSize].Value <<= maCameraRotation.mnLongitude.use();
238  nSize++;
239  }
241  {
242  pSeq[nSize].Name = "rotRev";
243  pSeq[nSize].Value <<= maCameraRotation.mnRevolution.use();
244  nSize++;
245  }
246  aSeq.realloc( nSize );
247  return aSeq;
248 }
249 
250 css::uno::Sequence< css::beans::PropertyValue > Generic3DProperties::getLightRigAttributes()
251 {
252  css::uno::Sequence<css::beans::PropertyValue> aSeq(5);
253  auto pSeq = aSeq.getArray();
254  sal_Int32 nSize = 0;
255  if( mnLightRigDirection.has() )
256  {
257  pSeq[nSize].Name = "dir";
258  pSeq[nSize].Value <<= getLightRigDirName( mnLightRigDirection.use() );
259  nSize++;
260  }
261  if( mnLightRigType.has() )
262  {
263  pSeq[nSize].Name = "rig";
264  pSeq[nSize].Value <<= getLightRigName( mnLightRigType.use() );
265  nSize++;
266  }
268  {
269  pSeq[nSize].Name = "rotLat";
270  pSeq[nSize].Value <<= maLightRigRotation.mnLatitude.use();
271  nSize++;
272  }
274  {
275  pSeq[nSize].Name = "rotLon";
276  pSeq[nSize].Value <<= maLightRigRotation.mnLongitude.use();
277  nSize++;
278  }
280  {
281  pSeq[nSize].Name = "rotRev";
282  pSeq[nSize].Value <<= maLightRigRotation.mnRevolution.use();
283  nSize++;
284  }
285  aSeq.realloc( nSize );
286  return aSeq;
287 }
288 
289 css::uno::Sequence< css::beans::PropertyValue > Generic3DProperties::getBevelAttributes( BevelProperties rProps )
290 {
291  css::uno::Sequence<css::beans::PropertyValue> aSeq(3);
292  auto pSeq = aSeq.getArray();
293  sal_Int32 nSize = 0;
294  if( rProps.mnPreset.has() )
295  {
296  pSeq[nSize].Name = "prst";
297  pSeq[nSize].Value <<= getBevelPresetTypeString( rProps.mnPreset.use() );
298  nSize++;
299  }
300  if( rProps.mnWidth.has() )
301  {
302  pSeq[nSize].Name = "w";
303  pSeq[nSize].Value <<= rProps.mnWidth.use();
304  nSize++;
305  }
306  if( rProps.mnHeight.has() )
307  {
308  pSeq[nSize].Name = "h";
309  pSeq[nSize].Value <<= rProps.mnHeight.use();
310  nSize++;
311  }
312  aSeq.realloc( nSize );
313  return aSeq;
314 }
315 
316 css::uno::Sequence< css::beans::PropertyValue > Generic3DProperties::getColorAttributes(
317  const Color& rColor, const GraphicHelper& rGraphicHelper, ::Color rPhClr )
318 {
319  const OUString& sColorScheme = rColor.getSchemeColorName();
320  if( sColorScheme.isEmpty() )
321  {
322  // RGB color and transparency value
323  return { comphelper::makePropertyValue("rgbClr", rColor.getColor( rGraphicHelper, rPhClr )),
324  comphelper::makePropertyValue("rgbClrTransparency", rColor.getTransparency()) };
325  }
326  // scheme color with name and transformations
327  return { comphelper::makePropertyValue("schemeClr", sColorScheme),
328  comphelper::makePropertyValue("schemeClrTransformations",
329  rColor.getTransformations()) };
330 }
331 
332 css::uno::Sequence< css::beans::PropertyValue > Generic3DProperties::getShape3DAttributes(
333  const GraphicHelper& rGraphicHelper, ::Color rPhClr )
334 {
335  css::uno::Sequence<css::beans::PropertyValue> aSeq(8);
336  auto pSeq = aSeq.getArray();
337  sal_Int32 nSize = 0;
338  if( mnExtrusionH.has() )
339  {
340  pSeq[nSize].Name = "extrusionH";
341  pSeq[nSize].Value <<= mnExtrusionH.use();
342  nSize++;
343  }
344  if( mnContourW.has() )
345  {
346  pSeq[nSize].Name = "contourW";
347  pSeq[nSize].Value <<= mnContourW.use();
348  nSize++;
349  }
350  if( mnShapeZ.has() )
351  {
352  pSeq[nSize].Name = "z";
353  pSeq[nSize].Value <<= mnShapeZ.use();
354  nSize++;
355  }
356  if( mnMaterial.has() )
357  {
358  pSeq[nSize].Name = "prstMaterial";
359  pSeq[nSize].Value <<= getPresetMaterialTypeString( mnMaterial.use() );
360  nSize++;
361  }
362  if( maTopBevelProperties.has() )
363  {
364  pSeq[nSize].Name = "bevelT";
365  pSeq[nSize].Value <<= getBevelAttributes( maTopBevelProperties.use() );
366  nSize++;
367  }
368  if( maBottomBevelProperties.has() )
369  {
370  pSeq[nSize].Name = "bevelB";
371  pSeq[nSize].Value <<= getBevelAttributes( maBottomBevelProperties.use() );
372  nSize++;
373  }
374  if( maExtrusionColor.isUsed() )
375  {
376  pSeq[nSize].Name = "extrusionClr";
377  pSeq[nSize].Value <<= getColorAttributes( maExtrusionColor, rGraphicHelper, rPhClr );
378  nSize++;
379  }
380  if( maContourColor.isUsed() )
381  {
382  pSeq[nSize].Name = "contourClr";
383  pSeq[nSize].Value <<= getColorAttributes( maContourColor, rGraphicHelper, rPhClr );
384  nSize++;
385  }
386  aSeq.realloc( nSize );
387  return aSeq;
388 }
389 
390 } // namespace oox
391 
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides helper functions for colors, device measurement conversion, graphics, and graphic objects ha...
const OUString & getSchemeColorName() const
Returns the scheme name from the a:schemeClr element for interoperability purposes.
Definition: color.hxx:100
static css::uno::Sequence< css::beans::PropertyValue > getColorAttributes(const Color &rColor, const GraphicHelper &rGraphicHelper,::Color rPhClr)
OptValue< BevelProperties > maBottomBevelProperties
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
static OUString getLightRigName(sal_Int32 nElement)
::Color getColor(const GraphicHelper &rGraphicHelper,::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
Definition: color.cxx:531
Type & use()
Definition: helper.hxx:189
bool isUsed() const
Returns true, if the color is initialized.
Definition: color.hxx:87
static OUString getCameraPrstName(sal_Int32 nElement)
const css::uno::Sequence< css::beans::PropertyValue > & getTransformations() const
Returns the unaltered list of transformations for interoperability purposes.
Definition: color.hxx:107
static OUString getBevelPresetTypeString(sal_Int32 nType)
OptValue< BevelProperties > maTopBevelProperties
static css::uno::Sequence< css::beans::PropertyValue > getBevelAttributes(BevelProperties rProps)
css::uno::Sequence< css::beans::PropertyValue > getShape3DAttributes(const GraphicHelper &rGraphicHelper,::Color rPhClr)
static OUString getPresetMaterialTypeString(sal_Int32 nType)
sal_Int16 getTransparency() const
Returns the transparency of the color (0 = opaque, 100 = full transparent).
Definition: color.cxx:708
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
css::uno::Sequence< css::beans::PropertyValue > getCameraAttributes()
static OUString getLightRigDirName(sal_Int32 nElement)
bool has() const
Definition: helper.hxx:181
css::uno::Sequence< css::beans::PropertyValue > getLightRigAttributes()