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 .
21 #include <com/sun/star/xml/sax/FastToken.hpp>
22 #include <com/sun/star/beans/XMultiPropertySet.hpp>
23 #include <com/sun/star/container/XNamed.hpp>
25 #include <oox/core/xmlfilterbase.hxx>
26 #include <oox/helper/attributelist.hxx>
27 #include <oox/ppt/pptshape.hxx>
28 #include <oox/ppt/pptgraphicshapecontext.hxx>
29 #include <oox/ppt/pptshapecontext.hxx>
30 #include <oox/ppt/pptshapegroupcontext.hxx>
31 #include <oox/drawingml/graphicshapecontext.hxx>
32 #include <drawingml/lineproperties.hxx>
33 #include <oox/drawingml/drawingmltypes.hxx>
34 #include <drawingml/customshapegeometry.hxx>
35 #include <drawingml/shapepropertiescontext.hxx>
36 #include <drawingml/textbodycontext.hxx>
37 #include <oox/drawingml/connectorshapecontext.hxx>
38 #include <drawingml/fillproperties.hxx>
39 #include "extdrawingfragmenthandler.hxx"
40 #include <oox/token/namespaces.hxx>
41 #include <oox/token/tokens.hxx>
43 using namespace oox::core
;
44 using namespace ::com::sun::star
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::drawing
;
47 using namespace ::com::sun::star::beans
;
48 using namespace ::com::sun::star::text
;
49 using namespace ::com::sun::star::xml::sax
;
51 namespace oox
{ namespace ppt
{
53 PPTShapeGroupContext::PPTShapeGroupContext(
54 ContextHandler2Helper
const & rParent
,
55 const oox::ppt::SlidePersistPtr
& rSlidePersistPtr
,
56 const ShapeLocation eShapeLocation
,
57 const oox::drawingml::ShapePtr
& pMasterShapePtr
,
58 const oox::drawingml::ShapePtr
& pGroupShapePtr
)
59 : ShapeGroupContext( rParent
, pMasterShapePtr
, pGroupShapePtr
)
60 , mpSlidePersistPtr( rSlidePersistPtr
)
61 , meShapeLocation( eShapeLocation
)
65 ContextHandlerRef
PPTShapeGroupContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
67 if( getNamespace( aElementToken
) == NMSP_dsp
)
68 aElementToken
= NMSP_ppt
| getBaseToken( aElementToken
);
70 switch( aElementToken
)
72 case PPT_TOKEN( cNvPr
):
74 // don't override SmartArt properties for embedded drawing's spTree
75 mpGroupShapePtr
->setHidden( rAttribs
.getBool( XML_hidden
, false ) );
76 if (mpGroupShapePtr
->getId().isEmpty())
77 mpGroupShapePtr
->setId(rAttribs
.getString(XML_id
).get());
78 if (mpGroupShapePtr
->getName().isEmpty())
79 mpGroupShapePtr
->setName( rAttribs
.getString( XML_name
).get() );
83 mpGroupShapePtr
->setSubType( rAttribs
.getToken( XML_type
, FastToken::DONTKNOW
) );
84 if( rAttribs
.hasAttribute( XML_idx
) )
85 mpGroupShapePtr
->setSubTypeIndex( rAttribs
.getString( XML_idx
).get().toInt32() );
87 // nvSpPr CT_ShapeNonVisual end
89 case PPT_TOKEN( grpSpPr
):
90 return new oox::drawingml::ShapePropertiesContext( *this, *mpGroupShapePtr
);
91 case PPT_TOKEN( spPr
):
92 return new oox::drawingml::ShapePropertiesContext( *this, *mpGroupShapePtr
);
94 case PPT_TOKEN( style ):
95 return new ShapeStyleContext( getParser() );
97 case PPT_TOKEN( cxnSp
): // connector shape
98 return new oox::drawingml::ConnectorShapeContext( *this, mpGroupShapePtr
, oox::drawingml::ShapePtr( new PPTShape( meShapeLocation
, "com.sun.star.drawing.ConnectorShape" ) ) );
99 case PPT_TOKEN( grpSp
): // group shape
100 return new PPTShapeGroupContext( *this, mpSlidePersistPtr
, meShapeLocation
, mpGroupShapePtr
, oox::drawingml::ShapePtr( new PPTShape( meShapeLocation
, "com.sun.star.drawing.GroupShape" ) ) );
101 case PPT_TOKEN( sp
): // Shape
103 std::shared_ptr
<PPTShape
> pShape( new PPTShape( meShapeLocation
, "com.sun.star.drawing.CustomShape" ) );
104 bool bUseBgFill
= rAttribs
.getBool(XML_useBgFill
, false);
105 pShape
->setUseBgFill(bUseBgFill
);
108 oox::drawingml::FillPropertiesPtr pBackgroundPropertiesPtr
= mpSlidePersistPtr
->getBackgroundProperties();
109 if (!pBackgroundPropertiesPtr
)
111 // The shape wants a background, but the slide doesn't have one.
112 SlidePersistPtr pMaster
= mpSlidePersistPtr
->getMasterPersist();
115 oox::drawingml::FillPropertiesPtr pMasterBackground
116 = pMaster
->getBackgroundProperties();
117 if (pMasterBackground
)
119 if (pMasterBackground
->moFillType
.has()
120 && pMasterBackground
->moFillType
.get() == XML_solidFill
)
122 // Master has a solid background, use that.
123 pBackgroundPropertiesPtr
= pMasterBackground
;
128 if (pBackgroundPropertiesPtr
)
130 pShape
->getFillProperties().assignUsed(*pBackgroundPropertiesPtr
);
133 pShape
->setModelId(rAttribs
.getString( XML_modelId
).get());
134 return new PPTShapeContext( *this, mpSlidePersistPtr
, mpGroupShapePtr
, pShape
);
136 case PPT_TOKEN( pic
): // CT_Picture
137 return new PPTGraphicShapeContext( *this, mpSlidePersistPtr
, mpGroupShapePtr
, oox::drawingml::ShapePtr( new PPTShape( meShapeLocation
, "com.sun.star.drawing.GraphicObjectShape" ) ) );
138 case PPT_TOKEN( graphicFrame
): // CT_GraphicalObjectFrame
140 pGraphicShape
= oox::drawingml::ShapePtr( new PPTShape( meShapeLocation
, "com.sun.star.drawing.OLE2Shape" ) );
141 return new oox::drawingml::GraphicalObjectFrameContext( *this, mpGroupShapePtr
, pGraphicShape
, true );
148 void PPTShapeGroupContext::importExtDrawings( )
152 for (auto const& extDrawing
: pGraphicShape
->getExtDrawings())
154 OUString aFragmentPath
= getFragmentPathFromRelId(extDrawing
);
155 getFilter().importFragment( new ExtDrawingFragmentHandler( getFilter(), aFragmentPath
,
160 pGraphicShape
->keepDiagramDrawing(getFilter(), aFragmentPath
);
162 // Apply font color imported from color fragment
163 if( pGraphicShape
->getFontRefColorForNodes().isUsed() )
164 applyFontRefColor(mpGroupShapePtr
, pGraphicShape
->getFontRefColorForNodes());
166 pGraphicShape
= oox::drawingml::ShapePtr( nullptr );
170 void PPTShapeGroupContext::applyFontRefColor(const oox::drawingml::ShapePtr
& pShape
, const oox::drawingml::Color
& rFontRefColor
)
172 pShape
->getShapeStyleRefs()[XML_fontRef
].maPhClr
= rFontRefColor
;
173 std::vector
< oox::drawingml::ShapePtr
>& vChildren
= pShape
->getChildren();
174 for (auto const& child
: vChildren
)
176 applyFontRefColor(child
, rFontRefColor
);
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */