1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/scene3dcontext.hxx>
21 #include <drawingml/colorchoicecontext.hxx>
22 #include <oox/helper/attributelist.hxx>
23 #include <oox/token/namespaces.hxx>
24 #include <oox/token/tokens.hxx>
26 using namespace ::oox::core
;
27 using namespace ::com::sun::star
;
29 namespace oox::drawingml
{
31 Scene3DPropertiesContext::Scene3DPropertiesContext( ContextHandler2Helper
const & rParent
, Shape3DProperties
& r3DProperties
) noexcept
32 : ContextHandler2( rParent
)
33 , mr3DProperties( r3DProperties
)
37 ContextHandlerRef
Scene3DPropertiesContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
39 switch( aElementToken
)
41 case A_TOKEN( camera
):
42 if( rAttribs
.hasAttribute( XML_fov
) )
43 mr3DProperties
.mfFieldOfVision
= rAttribs
.getInteger( XML_fov
, 0 ) / 60000.0; // 60000ths of degree
44 if( rAttribs
.hasAttribute( XML_zoom
) )
45 mr3DProperties
.mfZoom
= rAttribs
.getInteger( XML_zoom
, 100000 ) / 100000.0;
46 if( rAttribs
.hasAttribute( XML_prst
) )
47 mr3DProperties
.mnPreset
= rAttribs
.getToken( XML_prst
, XML_none
);
49 return new Scene3DRotationPropertiesContext( *this, mr3DProperties
.maCameraRotation
);
51 case A_TOKEN( lightRig
):
52 mr3DProperties
.mnLightRigDirection
= rAttribs
.getToken( XML_dir
, XML_none
);
53 mr3DProperties
.mnLightRigType
= rAttribs
.getToken( XML_rig
, XML_none
);
55 return new Scene3DRotationPropertiesContext( *this, mr3DProperties
.maLightRigRotation
);
57 case A_TOKEN( backdrop
):
58 case A_TOKEN( extLst
):
59 return nullptr; // TODO: later (backdrop is not supported by core anyway)
64 SceneText3DPropertiesContext::SceneText3DPropertiesContext( ContextHandler2Helper
const & rParent
, Text3DProperties
& r3DProperties
) noexcept
65 : ContextHandler2( rParent
)
66 , mr3DProperties( r3DProperties
)
70 ContextHandlerRef
SceneText3DPropertiesContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
72 switch( aElementToken
)
74 case A_TOKEN( camera
):
75 if( rAttribs
.hasAttribute( XML_fov
) )
76 mr3DProperties
.mfFieldOfVision
= rAttribs
.getInteger( XML_fov
, 0 ) / 60000.0; // 60000ths of degree
77 if( rAttribs
.hasAttribute( XML_zoom
) )
78 mr3DProperties
.mfZoom
= rAttribs
.getInteger( XML_zoom
, 100000 ) / 100000.0;
79 if( rAttribs
.hasAttribute( XML_prst
) )
80 mr3DProperties
.mnPreset
= rAttribs
.getToken( XML_prst
, XML_none
);
82 return new Scene3DRotationPropertiesContext( *this, mr3DProperties
.maCameraRotation
);
84 case A_TOKEN( lightRig
):
85 mr3DProperties
.mnLightRigDirection
= rAttribs
.getToken( XML_dir
, XML_none
);
86 mr3DProperties
.mnLightRigType
= rAttribs
.getToken( XML_rig
, XML_none
);
88 return new Scene3DRotationPropertiesContext( *this, mr3DProperties
.maLightRigRotation
);
90 case A_TOKEN( backdrop
):
91 case A_TOKEN( extLst
):
92 return nullptr; // TODO: later (backdrop is not supported by core anyway)
94 case A_TOKEN( bevelT
):
95 case A_TOKEN( bevelB
):
97 BevelProperties aProps
;
98 if( rAttribs
.hasAttribute( XML_w
) )
99 aProps
.mnWidth
= rAttribs
.getInteger( XML_w
, 0 );
100 if( rAttribs
.hasAttribute( XML_h
) )
101 aProps
.mnHeight
= rAttribs
.getInteger( XML_h
, 0 );
102 if( rAttribs
.hasAttribute( XML_prst
) )
103 aProps
.mnPreset
= rAttribs
.getToken( XML_prst
, XML_none
);
105 if( aElementToken
== A_TOKEN( bevelT
) )
106 mr3DProperties
.maTopBevelProperties
= aProps
;
108 mr3DProperties
.maBottomBevelProperties
= aProps
;
112 case A_TOKEN( extrusionClr
):
113 return new ColorContext( *this, mr3DProperties
.maExtrusionColor
);
115 case A_TOKEN( contourClr
):
116 return new ColorContext( *this, mr3DProperties
.maContourColor
);
121 Shape3DPropertiesContext::Shape3DPropertiesContext( ContextHandler2Helper
const & rParent
, const AttributeList
& rAttribs
, Shape3DProperties
& r3DProperties
) noexcept
122 : ContextHandler2( rParent
)
123 , mr3DProperties( r3DProperties
)
125 if( rAttribs
.hasAttribute( XML_extrusionH
) )
126 mr3DProperties
.mnExtrusionH
= rAttribs
.getInteger( XML_extrusionH
, 0 );
127 if( rAttribs
.hasAttribute( XML_contourW
) )
128 mr3DProperties
.mnContourW
= rAttribs
.getInteger( XML_contourW
, 0 );
129 if( rAttribs
.hasAttribute( XML_z
) )
130 mr3DProperties
.mnShapeZ
= rAttribs
.getInteger( XML_z
, 0 );
131 if( rAttribs
.hasAttribute( XML_prstMaterial
) )
132 mr3DProperties
.mnMaterial
= rAttribs
.getToken( XML_prstMaterial
, XML_none
);
135 ContextHandlerRef
Shape3DPropertiesContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
137 switch( aElementToken
)
139 case A_TOKEN( bevelT
):
140 case A_TOKEN( bevelB
):
142 BevelProperties aProps
;
143 if( rAttribs
.hasAttribute( XML_w
) )
144 aProps
.mnWidth
= rAttribs
.getInteger( XML_w
, 0 );
145 if( rAttribs
.hasAttribute( XML_h
) )
146 aProps
.mnHeight
= rAttribs
.getInteger( XML_h
, 0 );
147 if( rAttribs
.hasAttribute( XML_prst
) )
148 aProps
.mnPreset
= rAttribs
.getToken( XML_prst
, XML_none
);
150 if( aElementToken
== A_TOKEN( bevelT
) )
151 mr3DProperties
.maTopBevelProperties
= aProps
;
153 mr3DProperties
.maBottomBevelProperties
= aProps
;
157 case A_TOKEN( extrusionClr
):
158 return new ColorContext( *this, mr3DProperties
.maExtrusionColor
);
160 case A_TOKEN( contourClr
):
161 return new ColorContext( *this, mr3DProperties
.maContourColor
);
166 Scene3DRotationPropertiesContext::Scene3DRotationPropertiesContext( ContextHandler2Helper
const & rParent
, RotationProperties
& rRotationProperties
) noexcept
167 : ContextHandler2( rParent
)
168 , mrRotationProperties( rRotationProperties
)
172 ContextHandlerRef
Scene3DRotationPropertiesContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
174 switch( aElementToken
)
177 mrRotationProperties
.mnLatitude
= rAttribs
.getInteger( XML_lat
, 0 );
178 mrRotationProperties
.mnLongitude
= rAttribs
.getInteger( XML_lon
, 0 );
179 mrRotationProperties
.mnRevolution
= rAttribs
.getInteger( XML_rev
, 0 );
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */