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
;
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::xml::sax
;
31 namespace oox::drawingml
{
33 Scene3DPropertiesContext::Scene3DPropertiesContext( ContextHandler2Helper
const & rParent
, Shape3DProperties
& r3DProperties
) noexcept
34 : ContextHandler2( rParent
)
35 , mr3DProperties( r3DProperties
)
39 ContextHandlerRef
Scene3DPropertiesContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
41 switch( aElementToken
)
43 case A_TOKEN( camera
):
44 if( rAttribs
.hasAttribute( XML_fov
) )
45 mr3DProperties
.mfFieldOfVision
= rAttribs
.getInteger( XML_fov
, 0 ) / 60000.0; // 60000ths of degree
46 if( rAttribs
.hasAttribute( XML_zoom
) )
47 mr3DProperties
.mfZoom
= rAttribs
.getInteger( XML_zoom
, 100000 ) / 100000.0;
48 if( rAttribs
.hasAttribute( XML_prst
) )
49 mr3DProperties
.mnPreset
= rAttribs
.getToken( XML_prst
, XML_none
);
51 return new Scene3DRotationPropertiesContext( *this, mr3DProperties
.maCameraRotation
);
53 case A_TOKEN( lightRig
):
54 mr3DProperties
.mnLightRigDirection
= rAttribs
.getToken( XML_dir
, XML_none
);
55 mr3DProperties
.mnLightRigType
= rAttribs
.getToken( XML_rig
, XML_none
);
57 return new Scene3DRotationPropertiesContext( *this, mr3DProperties
.maLightRigRotation
);
59 case A_TOKEN( backdrop
):
60 case A_TOKEN( extLst
):
61 return nullptr; // TODO: later (backdrop is not supported by core anyway)
66 SceneText3DPropertiesContext::SceneText3DPropertiesContext( ContextHandler2Helper
const & rParent
, Text3DProperties
& r3DProperties
) noexcept
67 : ContextHandler2( rParent
)
68 , mr3DProperties( r3DProperties
)
72 ContextHandlerRef
SceneText3DPropertiesContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
74 switch( aElementToken
)
76 case A_TOKEN( camera
):
77 if( rAttribs
.hasAttribute( XML_fov
) )
78 mr3DProperties
.mfFieldOfVision
= rAttribs
.getInteger( XML_fov
, 0 ) / 60000.0; // 60000ths of degree
79 if( rAttribs
.hasAttribute( XML_zoom
) )
80 mr3DProperties
.mfZoom
= rAttribs
.getInteger( XML_zoom
, 100000 ) / 100000.0;
81 if( rAttribs
.hasAttribute( XML_prst
) )
82 mr3DProperties
.mnPreset
= rAttribs
.getToken( XML_prst
, XML_none
);
84 return new Scene3DRotationPropertiesContext( *this, mr3DProperties
.maCameraRotation
);
86 case A_TOKEN( lightRig
):
87 mr3DProperties
.mnLightRigDirection
= rAttribs
.getToken( XML_dir
, XML_none
);
88 mr3DProperties
.mnLightRigType
= rAttribs
.getToken( XML_rig
, XML_none
);
90 return new Scene3DRotationPropertiesContext( *this, mr3DProperties
.maLightRigRotation
);
92 case A_TOKEN( backdrop
):
93 case A_TOKEN( extLst
):
94 return nullptr; // TODO: later (backdrop is not supported by core anyway)
96 case A_TOKEN( bevelT
):
97 case A_TOKEN( bevelB
):
99 BevelProperties aProps
;
100 if( rAttribs
.hasAttribute( XML_w
) )
101 aProps
.mnWidth
= rAttribs
.getInteger( XML_w
, 0 );
102 if( rAttribs
.hasAttribute( XML_h
) )
103 aProps
.mnHeight
= rAttribs
.getInteger( XML_h
, 0 );
104 if( rAttribs
.hasAttribute( XML_prst
) )
105 aProps
.mnPreset
= rAttribs
.getToken( XML_prst
, XML_none
);
107 if( aElementToken
== A_TOKEN( bevelT
) )
108 mr3DProperties
.maTopBevelProperties
= aProps
;
110 mr3DProperties
.maBottomBevelProperties
= aProps
;
114 case A_TOKEN( extrusionClr
):
115 return new ColorContext( *this, mr3DProperties
.maExtrusionColor
);
117 case A_TOKEN( contourClr
):
118 return new ColorContext( *this, mr3DProperties
.maContourColor
);
123 Shape3DPropertiesContext::Shape3DPropertiesContext( ContextHandler2Helper
const & rParent
, const AttributeList
& rAttribs
, Shape3DProperties
& r3DProperties
) noexcept
124 : ContextHandler2( rParent
)
125 , mr3DProperties( r3DProperties
)
127 if( rAttribs
.hasAttribute( XML_extrusionH
) )
128 mr3DProperties
.mnExtrusionH
= rAttribs
.getInteger( XML_extrusionH
, 0 );
129 if( rAttribs
.hasAttribute( XML_contourW
) )
130 mr3DProperties
.mnContourW
= rAttribs
.getInteger( XML_contourW
, 0 );
131 if( rAttribs
.hasAttribute( XML_z
) )
132 mr3DProperties
.mnShapeZ
= rAttribs
.getInteger( XML_z
, 0 );
133 if( rAttribs
.hasAttribute( XML_prstMaterial
) )
134 mr3DProperties
.mnMaterial
= rAttribs
.getToken( XML_prstMaterial
, XML_none
);
137 ContextHandlerRef
Shape3DPropertiesContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
139 switch( aElementToken
)
141 case A_TOKEN( bevelT
):
142 case A_TOKEN( bevelB
):
144 BevelProperties aProps
;
145 if( rAttribs
.hasAttribute( XML_w
) )
146 aProps
.mnWidth
= rAttribs
.getInteger( XML_w
, 0 );
147 if( rAttribs
.hasAttribute( XML_h
) )
148 aProps
.mnHeight
= rAttribs
.getInteger( XML_h
, 0 );
149 if( rAttribs
.hasAttribute( XML_prst
) )
150 aProps
.mnPreset
= rAttribs
.getToken( XML_prst
, XML_none
);
152 if( aElementToken
== A_TOKEN( bevelT
) )
153 mr3DProperties
.maTopBevelProperties
= aProps
;
155 mr3DProperties
.maBottomBevelProperties
= aProps
;
159 case A_TOKEN( extrusionClr
):
160 return new ColorContext( *this, mr3DProperties
.maExtrusionColor
);
162 case A_TOKEN( contourClr
):
163 return new ColorContext( *this, mr3DProperties
.maContourColor
);
168 Scene3DRotationPropertiesContext::Scene3DRotationPropertiesContext( ContextHandler2Helper
const & rParent
, RotationProperties
& rRotationProperties
) noexcept
169 : ContextHandler2( rParent
)
170 , mrRotationProperties( rRotationProperties
)
174 ContextHandlerRef
Scene3DRotationPropertiesContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
176 switch( aElementToken
)
179 mrRotationProperties
.mnLatitude
= rAttribs
.getInteger( XML_lat
, 0 );
180 mrRotationProperties
.mnLongitude
= rAttribs
.getInteger( XML_lon
, 0 );
181 mrRotationProperties
.mnRevolution
= rAttribs
.getInteger( XML_rev
, 0 );
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */