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/scene3dcontext.hxx>
21 #include <com/sun/star/io/XInputStream.hpp>
22 #include <cppuhelper/exc_hlp.hxx>
23 #include <drawingml/colorchoicecontext.hxx>
24 #include <oox/drawingml/drawingmltypes.hxx>
25 #include <drawingml/fillproperties.hxx>
26 #include <oox/core/xmlfilterbase.hxx>
27 #include <oox/helper/attributelist.hxx>
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
30 
31 using namespace ::oox::core;
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::xml::sax;
35 
36 namespace oox { namespace drawingml {
37 
Scene3DPropertiesContext(ContextHandler2Helper const & rParent,Shape3DProperties & r3DProperties)38 Scene3DPropertiesContext::Scene3DPropertiesContext( ContextHandler2Helper const & rParent, Shape3DProperties& r3DProperties ) throw()
39 : ContextHandler2( rParent )
40 , mr3DProperties( r3DProperties )
41 {
42 }
43 
onCreateContext(sal_Int32 aElementToken,const AttributeList & rAttribs)44 ContextHandlerRef Scene3DPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
45 {
46     switch( aElementToken )
47     {
48     case A_TOKEN( camera ):
49         if( rAttribs.hasAttribute( XML_fov ) )
50             mr3DProperties.mfFieldOfVision = rAttribs.getInteger( XML_fov, 0 ) / 60000.0; // 60000ths of degree
51         if( rAttribs.hasAttribute( XML_zoom ) )
52             mr3DProperties.mfZoom = rAttribs.getInteger( XML_zoom, 100000 ) / 100000.0;
53         if( rAttribs.hasAttribute( XML_prst ) )
54             mr3DProperties.mnPreset = rAttribs.getToken( XML_prst, XML_none );
55 
56         return new Scene3DRotationPropertiesContext( *this, mr3DProperties.maCameraRotation );
57 
58     case A_TOKEN( lightRig ):
59         mr3DProperties.mnLightRigDirection = rAttribs.getToken( XML_dir, XML_none );
60         mr3DProperties.mnLightRigType = rAttribs.getToken( XML_rig, XML_none );
61 
62         return new Scene3DRotationPropertiesContext( *this, mr3DProperties.maLightRigRotation );
63 
64     case A_TOKEN( backdrop ):
65     case A_TOKEN( extLst ):
66         return nullptr; // TODO: later (backdrop is not supported by core anyway)
67     }
68     return nullptr;
69 }
70 
Shape3DPropertiesContext(ContextHandler2Helper const & rParent,const AttributeList & rAttribs,Shape3DProperties & r3DProperties)71 Shape3DPropertiesContext::Shape3DPropertiesContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs, Shape3DProperties& r3DProperties ) throw()
72 : ContextHandler2( rParent )
73 , mr3DProperties( r3DProperties )
74 {
75     if( rAttribs.hasAttribute( XML_extrusionH ) )
76         mr3DProperties.mnExtrusionH = rAttribs.getInteger( XML_extrusionH, 0 );
77     if( rAttribs.hasAttribute( XML_contourW ) )
78         mr3DProperties.mnContourW = rAttribs.getInteger( XML_contourW, 0 );
79     if( rAttribs.hasAttribute( XML_z ) )
80         mr3DProperties.mnShapeZ = rAttribs.getInteger( XML_z, 0 );
81     if( rAttribs.hasAttribute( XML_prstMaterial ) )
82         mr3DProperties.mnMaterial = rAttribs.getToken( XML_prstMaterial, XML_none );
83 }
84 
onCreateContext(sal_Int32 aElementToken,const AttributeList & rAttribs)85 ContextHandlerRef Shape3DPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
86 {
87     switch( aElementToken )
88     {
89     case A_TOKEN( bevelT ):
90     case A_TOKEN( bevelB ):
91     {
92         BevelProperties aProps;
93         if( rAttribs.hasAttribute( XML_w ) )
94             aProps.mnWidth = rAttribs.getInteger( XML_w, 0 );
95         if( rAttribs.hasAttribute( XML_h ) )
96             aProps.mnHeight = rAttribs.getInteger( XML_h, 0 );
97         if( rAttribs.hasAttribute( XML_prst ) )
98             aProps.mnPreset = rAttribs.getToken( XML_prst, XML_none );
99 
100         if( aElementToken == A_TOKEN( bevelT ) )
101             mr3DProperties.maTopBevelProperties.set( aProps );
102         else
103             mr3DProperties.maBottomBevelProperties.set( aProps );
104 
105         break;
106     }
107     case A_TOKEN( extrusionClr ):
108         return new ColorContext( *this, mr3DProperties.maExtrusionColor );
109 
110     case A_TOKEN( contourClr ):
111         return new ColorContext( *this, mr3DProperties.maContourColor );
112     }
113     return nullptr;
114 }
115 
Scene3DRotationPropertiesContext(ContextHandler2Helper const & rParent,RotationProperties & rRotationProperties)116 Scene3DRotationPropertiesContext::Scene3DRotationPropertiesContext( ContextHandler2Helper const & rParent, RotationProperties& rRotationProperties ) throw()
117 : ContextHandler2( rParent )
118 , mrRotationProperties( rRotationProperties )
119 {
120 }
121 
onCreateContext(sal_Int32 aElementToken,const AttributeList & rAttribs)122 ContextHandlerRef Scene3DRotationPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
123 {
124     switch( aElementToken )
125     {
126     case A_TOKEN( rot ):
127         mrRotationProperties.mnLatitude = rAttribs.getInteger( XML_lat, 0 );
128         mrRotationProperties.mnLongitude = rAttribs.getInteger( XML_lon, 0 );
129         mrRotationProperties.mnRevolution = rAttribs.getInteger( XML_rev, 0 );
130         break;
131     }
132     return nullptr;
133 }
134 
135 } }
136 
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
138