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