summaryrefslogtreecommitdiff
path: root/oox/source/drawingml/shape3dproperties.cxx
blob: e3f39b6267a9a7fed759892d6e953c1c7366d1b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "oox/drawingml/shape3dproperties.hxx"
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/frame/XFramesSupplier.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/awt/Gradient.hpp>
#include <com/sun/star/awt/Size.hpp>
#include <com/sun/star/awt/XBitmap.hpp>
#include <com/sun/star/awt/XDevice.hpp>
#include <com/sun/star/drawing/BitmapMode.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/RectanglePoint.hpp>
#include <com/sun/star/graphic/XGraphicTransformer.hpp>
#include "oox/helper/propertymap.hxx"
#include "oox/helper/propertyset.hxx"
#include "oox/token/tokens.hxx"

using namespace ::com::sun::star;
using namespace ::com::sun::star::drawing;
using namespace ::com::sun::star::graphic;

using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::oox::core::XmlFilterBase;

namespace oox {
namespace drawingml {


OUString Shape3DProperties::getCameraPrstName( sal_Int32 nElement )
{
    switch( nElement )
    {
        case XML_legacyObliqueTopLeft:          return OUString( "legacyObliqueTopLeft" );
        case XML_legacyObliqueTop:              return OUString( "legacyObliqueTop" );
        case XML_legacyObliqueTopRight:         return OUString( "legacyObliqueTopRight" );
        case XML_legacyObliqueLeft:             return OUString( "legacyObliqueLeft" );
        case XML_legacyObliqueFront:            return OUString( "legacyObliqueFront" );
        case XML_legacyObliqueRight:            return OUString( "legacyObliqueRight" );
        case XML_legacyObliqueBottomLeft:       return OUString( "legacyObliqueBottomLeft" );
        case XML_legacyObliqueBottom:           return OUString( "legacyObliqueBottom" );
        case XML_legacyObliqueBottomRight:      return OUString( "legacyObliqueBottomRight" );
        case XML_legacyPerspectiveTopLeft:      return OUString( "legacyPerspectiveTopLeft" );
        case XML_legacyPerspectiveTop:          return OUString( "legacyPerspectiveTop" );
        case XML_legacyPerspectiveTopRight:     return OUString( "legacyPerspectiveTopRight" );
        case XML_legacyPerspectiveLeft:         return OUString( "legacyPerspectiveLeft" );
        case XML_legacyPerspectiveFront:        return OUString( "legacyPerspectiveFront" );
        case XML_legacyPerspectiveRight:        return OUString( "legacyPerspectiveRight" );
        case XML_legacyPerspectiveBottomLeft:   return OUString( "legacyPerspectiveBottomLeft" );
        case XML_legacyPerspectiveBottom:       return OUString( "legacyPerspectiveBottom" );
        case XML_legacyPerspectiveBottomRight:  return OUString( "legacyPerspectiveBottomRight" );
        case XML_orthographicFront:             return OUString( "orthographicFront" );
        case XML_isometricTopUp:                return OUString( "isometricTopUp" );
        case XML_isometricTopDown:              return OUString( "isometricTopDown" );
        case XML_isometricBottomUp:             return OUString( "isometricBottomUp" );
        case XML_isometricBottomDown:           return OUString( "isometricBottomDown" );
        case XML_isometricLeftUp:               return OUString( "isometricLeftUp" );
        case XML_isometricLeftDown:             return OUString( "isometricLeftDown" );
        case XML_isometricRightUp:              return OUString( "isometricRightUp" );
        case XML_isometricRightDown:            return OUString( "isometricRightDown" );
        case XML_isometricOffAxis1Left:         return OUString( "isometricOffAxis1Left" );
        case XML_isometricOffAxis1Right:        return OUString( "isometricOffAxis1Right" );
        case XML_isometricOffAxis1Top:          return OUString( "isometricOffAxis1Top" );
        case XML_isometricOffAxis2Left:         return OUString( "isometricOffAxis2Left" );
        case XML_isometricOffAxis2Right:        return OUString( "isometricOffAxis2Right" );
        case XML_isometricOffAxis2Top:          return OUString( "isometricOffAxis2Top" );
        case XML_isometricOffAxis3Left:         return OUString( "isometricOffAxis3Left" );
        case XML_isometricOffAxis3Right:        return OUString( "isometricOffAxis3Right" );
        case XML_isometricOffAxis3Bottom:       return OUString( "isometricOffAxis3Bottom" );
        case XML_isometricOffAxis4Left:         return OUString( "isometricOffAxis4Left" );
        case XML_isometricOffAxis4Right:        return OUString( "isometricOffAxis4Right" );
        case XML_isometricOffAxis4Bottom:       return OUString( "isometricOffAxis4Bottom" );
        case XML_obliqueTopLeft:                return OUString( "obliqueTopLeft" );
        case XML_obliqueTop:                    return OUString( "obliqueTop" );
        case XML_obliqueTopRight:               return OUString( "obliqueTopRight" );
        case XML_obliqueLeft:                   return OUString( "obliqueLeft" );
        case XML_obliqueRight:                  return OUString( "obliqueRight" );
        case XML_obliqueBottomLeft:             return OUString( "obliqueBottomLeft" );
        case XML_obliqueBottom:                 return OUString( "obliqueBottom" );
        case XML_obliqueBottomRight:            return OUString( "obliqueBottomRight" );
        case XML_perspectiveFront:              return OUString( "perspectiveFront" );
        case XML_perspectiveLeft:               return OUString( "perspectiveLeft" );
        case XML_perspectiveRight:              return OUString( "perspectiveRight" );
        case XML_perspectiveAbove:              return OUString( "perspectiveAbove" );
        case XML_perspectiveBelow:              return OUString( "perspectiveBelow" );
        case XML_perspectiveAboveLeftFacing:        return OUString( "perspectiveAboveLeftFacing" );
        case XML_perspectiveAboveRightFacing:       return OUString( "perspectiveAboveRightFacing" );
        case XML_perspectiveContrastingLeftFacing:  return OUString( "perspectiveContrastingLeftFacing" );
        case XML_perspectiveContrastingRightFacing: return OUString( "perspectiveContrastingRightFacing" );
        case XML_perspectiveHeroicLeftFacing:       return OUString( "perspectiveHeroicLeftFacing" );
        case XML_perspectiveHeroicRightFacing:      return OUString( "perspectiveHeroicRightFacing" );
        case XML_perspectiveHeroicExtremeLeftFacing:    return OUString( "perspectiveHeroicExtremeLeftFacing" );
        case XML_perspectiveHeroicExtremeRightFacing:   return OUString( "perspectiveHeroicExtremeRightFacing" );
        case XML_perspectiveRelaxed:                    return OUString( "perspectiveRelaxed" );
        case XML_perspectiveRelaxedModerately:          return OUString( "perspectiveRelaxedModerately" );
    }
    SAL_WARN( "oox.drawingml", "Shape3DProperties::getCameraPrstName - unexpected prst type" );
    return OUString();
}

OUString Shape3DProperties::getLightRigName( sal_Int32 nElement )
{
    switch( nElement )
    {
        case XML_legacyFlat1:       return OUString( "legacyFlat1" );
        case XML_legacyFlat2:       return OUString( "legacyFlat2" );
        case XML_legacyFlat3:       return OUString( "legacyFlat3" );
        case XML_legacyFlat4:       return OUString( "legacyFlat4" );
        case XML_legacyNormal1:     return OUString( "legacyNormal1" );
        case XML_legacyNormal2:     return OUString( "legacyNormal2" );
        case XML_legacyNormal3:     return OUString( "legacyNormal3" );
        case XML_legacyNormal4:     return OUString( "legacyNormal4" );
        case XML_legacyHarsh1:      return OUString( "legacyHarsh1" );
        case XML_legacyHarsh2:      return OUString( "legacyHarsh2" );
        case XML_legacyHarsh3:      return OUString( "legacyHarsh3" );
        case XML_legacyHarsh4:      return OUString( "legacyHarsh4" );
        case XML_threePt:           return OUString( "threePt" );
        case XML_balanced:          return OUString( "balanced" );
        case XML_soft:              return OUString( "soft" );
        case XML_harsh:             return OUString( "harsh" );
        case XML_flood:             return OUString( "flood" );
        case XML_contrasting:       return OUString( "contrasting" );
        case XML_morning:           return OUString( "morning" );
        case XML_sunrise:           return OUString( "sunrise" );
        case XML_sunset:            return OUString( "sunset" );
        case XML_chilly:            return OUString( "chilly" );
        case XML_freezing:          return OUString( "freezing" );
        case XML_flat:              return OUString( "flat" );
        case XML_twoPt:             return OUString( "twoPt" );
        case XML_glow:              return OUString( "glow" );
        case XML_brightRoom:        return OUString( "brightRoom" );
    }
    SAL_WARN( "oox.drawingml", "Shape3DProperties::getLightRigName - unexpected token" );
    return OUString();
}

OUString Shape3DProperties::getLightRigDirName( sal_Int32 nElement )
{
    switch( nElement )
    {
        case XML_tl:    return OUString( "tl" );
        case XML_t:     return OUString( "t" );
        case XML_tr:    return OUString( "tr" );
        case XML_l:     return OUString( "l" );
        case XML_r:     return OUString( "r" );
        case XML_bl:    return OUString( "bl" );
        case XML_b:     return OUString( "b" );
        case XML_br:    return OUString( "br" );
    }
    SAL_WARN( "oox.drawingml", "Shape3DProperties::getLightRigDirName - unexpected token" );
    return OUString();
}

OUString Shape3DProperties::getBevelPresetTypeString( sal_Int32 nType )
{
    switch (nType)
    {
        case XML_relaxedInset:  return OUString("relaxedInset");
        case XML_circle:        return OUString("circle");
        case XML_slope:         return OUString("slope");
        case XML_cross:         return OUString("cross");
        case XML_angle:         return OUString("angle");
        case XML_softRound:     return OUString("softRound");
        case XML_convex:        return OUString("convex");
        case XML_coolSlant:     return OUString("coolSlant");
        case XML_divot:         return OUString("divot");
        case XML_riblet:        return OUString("riblet");
        case XML_hardEdge:      return OUString("hardEdge");
        case XML_artDeco:       return OUString("artDeco");
    }
    SAL_WARN( "oox.drawingml", "Shape3DProperties::getBevelPresetTypeString - unexpected token" );
    return OUString();
}

OUString Shape3DProperties::getPresetMaterialTypeString( sal_Int32 nType )
{
    switch (nType)
    {
        case XML_legacyMatte:       return OUString("legacyMatte");
        case XML_legacyPlastic:     return OUString("legacyPlastic");
        case XML_legacyMetal:       return OUString("legacyMetal");
        case XML_legacyWireframe:   return OUString("legacyWireframe");
        case XML_matte:             return OUString("matte");
        case XML_plastic:           return OUString("plastic");
        case XML_metal:             return OUString("metal");
        case XML_warmMatte:         return OUString("warmMatte");
        case XML_translucentPowder: return OUString("translucentPowder");
        case XML_powder:            return OUString("powder");
        case XML_dkEdge:            return OUString("dkEdge");
        case XML_softEdge:          return OUString("softEdge");
        case XML_clear:             return OUString("clear");
        case XML_flat:              return OUString("flat");
        case XML_softmetal:         return OUString("softmetal");
        case XML_none:              return OUString("none");
    }
    SAL_WARN( "oox.drawingml", "Shape3DProperties::getPresetMaterialTypeString - unexpected token" );
    return OUString();
}

css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getCameraAttributes()
{
    css::uno::Sequence<css::beans::PropertyValue> aSeq(6);
    sal_Int32 nSize = 0;
    if( mfFieldOfVision.has() )
    {
        aSeq[nSize].Name = "fov";
        aSeq[nSize].Value = css::uno::Any( mfFieldOfVision.use() );
        nSize++;
    }
    if( mfZoom.has() )
    {
        aSeq[nSize].Name = "zoom";
        aSeq[nSize].Value = css::uno::Any( mfZoom.use() );
        nSize++;
    }
    if( mnPreset.has() )
    {
        aSeq[nSize].Name = "prst";
        aSeq[nSize].Value = css::uno::Any( getCameraPrstName( mnPreset.use() ) );
        nSize++;
    }
    if( maCameraRotation.mnLatitude.has() )
    {
        aSeq[nSize].Name = "rotLat";
        aSeq[nSize].Value = css::uno::Any( maCameraRotation.mnLatitude.use() );
        nSize++;
    }
    if( maCameraRotation.mnLongitude.has() )
    {
        aSeq[nSize].Name = "rotLon";
        aSeq[nSize].Value = css::uno::Any( maCameraRotation.mnLongitude.use() );
        nSize++;
    }
    if( maCameraRotation.mnRevolution.has() )
    {
        aSeq[nSize].Name = "rotRev";
        aSeq[nSize].Value = css::uno::Any( maCameraRotation.mnRevolution.use() );
        nSize++;
    }
    aSeq.realloc( nSize );
    return aSeq;
}

css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getLightRigAttributes()
{
    css::uno::Sequence<css::beans::PropertyValue> aSeq(5);
    sal_Int32 nSize = 0;
    if( mnLightRigDirection.has() )
    {
        aSeq[nSize].Name = "dir";
        aSeq[nSize].Value = css::uno::Any( getLightRigDirName( mnLightRigDirection.use() ) );
        nSize++;
    }
    if( mnLightRigType.has() )
    {
        aSeq[nSize].Name = "rig";
        aSeq[nSize].Value = css::uno::Any( getLightRigName( mnLightRigType.use() ) );
        nSize++;
    }
    if( maLightRigRotation.mnLatitude.has() )
    {
        aSeq[nSize].Name = "rotLat";
        aSeq[nSize].Value = css::uno::Any( maLightRigRotation.mnLatitude.use() );
        nSize++;
    }
    if( maLightRigRotation.mnLongitude.has() )
    {
        aSeq[nSize].Name = "rotLon";
        aSeq[nSize].Value = css::uno::Any( maLightRigRotation.mnLongitude.use() );
        nSize++;
    }
    if( maLightRigRotation.mnRevolution.has() )
    {
        aSeq[nSize].Name = "rotRev";
        aSeq[nSize].Value = css::uno::Any( maLightRigRotation.mnRevolution.use() );
        nSize++;
    }
    aSeq.realloc( nSize );
    return aSeq;
}

css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getBevelAttributes( BevelProperties rProps )
{
    css::uno::Sequence<css::beans::PropertyValue> aSeq(3);
    sal_Int32 nSize = 0;
    if( rProps.mnPreset.has() )
    {
        aSeq[nSize].Name = "prst";
        aSeq[nSize].Value = css::uno::Any( getBevelPresetTypeString( rProps.mnPreset.use() ) );
        nSize++;
    }
    if( rProps.mnWidth.has() )
    {
        aSeq[nSize].Name = "w";
        aSeq[nSize].Value = css::uno::Any( rProps.mnWidth.use() );
        nSize++;
    }
    if( rProps.mnHeight.has() )
    {
        aSeq[nSize].Name = "h";
        aSeq[nSize].Value = css::uno::Any( rProps.mnHeight.use() );
        nSize++;
    }
    aSeq.realloc( nSize );
    return aSeq;
}

css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getColorAttributes(
        const Color& rColor, const GraphicHelper& rGraphicHelper, sal_Int32 rPhClr )
{
    css::uno::Sequence<css::beans::PropertyValue> aSeq(2);
    OUString sColorScheme = rColor.getSchemeName();
    if( sColorScheme.isEmpty() )
    {
        // RGB color and transparency value
        aSeq[0].Name = "rgbClr";
        aSeq[0].Value = css::uno::Any( rColor.getColor( rGraphicHelper, rPhClr ) );
        aSeq[1].Name = "rgbClrTransparency";
        aSeq[1].Value = css::uno::Any( rColor.getTransparency() );
    }
    else
    {
        // scheme color with name and transformations
        aSeq[0].Name = "schemeClr";
        aSeq[0].Value = css::uno::Any( sColorScheme );
        aSeq[1].Name = "schemeClrTransformations";
        aSeq[1].Value = css::uno::Any( rColor.getTransformations() );
    }
    return aSeq;
}

css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getShape3DAttributes(
        const GraphicHelper& rGraphicHelper, sal_Int32 rPhClr )
{
    css::uno::Sequence<css::beans::PropertyValue> aSeq(8);
    sal_Int32 nSize = 0;
    if( mnExtrusionH.has() )
    {
        aSeq[nSize].Name = "extrusionH";
        aSeq[nSize].Value = css::uno::Any( mnExtrusionH.use() );
        nSize++;
    }
    if( mnContourW.has() )
    {
        aSeq[nSize].Name = "contourW";
        aSeq[nSize].Value = css::uno::Any( mnContourW.use() );
        nSize++;
    }
    if( mnShapeZ.has() )
    {
        aSeq[nSize].Name = "z";
        aSeq[nSize].Value = css::uno::Any( mnShapeZ.use() );
        nSize++;
    }
    if( mnMaterial.has() )
    {
        aSeq[nSize].Name = "prstMaterial";
        aSeq[nSize].Value = css::uno::Any( getPresetMaterialTypeString( mnMaterial.use() ) );
        nSize++;
    }
    if( maTopBevelProperties.has() )
    {
        aSeq[nSize].Name = "bevelT";
        aSeq[nSize].Value = css::uno::Any( getBevelAttributes( maTopBevelProperties.use() ) );
        nSize++;
    }
    if( maBottomBevelProperties.has() )
    {
        aSeq[nSize].Name = "bevelB";
        aSeq[nSize].Value = css::uno::Any( getBevelAttributes( maBottomBevelProperties.use() ) );
        nSize++;
    }
    if( maExtrusionColor.isUsed() )
    {
        aSeq[nSize].Name = "extrusionClr";
        aSeq[nSize].Value = css::uno::Any( getColorAttributes( maExtrusionColor, rGraphicHelper, rPhClr ) );
        nSize++;
    }
    if( maContourColor.isUsed() )
    {
        aSeq[nSize].Name = "contourClr";
        aSeq[nSize].Value = css::uno::Any( getColorAttributes( maContourColor, rGraphicHelper, rPhClr ) );
        nSize++;
    }
    aSeq.realloc( nSize );
    return aSeq;
}



} // namespace drawingml
} // namespace oox

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */