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