LibreOffice Module oox (master)  1
pptshapegroupcontext.cxx
Go to the documentation of this file.
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 <memory>
21 #include <com/sun/star/xml/sax/FastToken.hpp>
22 
26 #include <oox/ppt/pptshape.hxx>
36 #include <oox/token/namespaces.hxx>
37 #include <oox/token/tokens.hxx>
38 
39 using namespace oox::core;
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::drawing;
43 using namespace ::com::sun::star::text;
44 using namespace ::com::sun::star::xml::sax;
45 
46 namespace oox::ppt {
47 
48 PPTShapeGroupContext::PPTShapeGroupContext(
49  FragmentHandler2 const & rParent,
50  const oox::ppt::SlidePersistPtr& rSlidePersistPtr,
51  const ShapeLocation eShapeLocation,
52  const oox::drawingml::ShapePtr& pMasterShapePtr,
53  const oox::drawingml::ShapePtr& pGroupShapePtr )
54 : ShapeGroupContext( rParent, pMasterShapePtr, pGroupShapePtr )
55 , mpSlidePersistPtr( rSlidePersistPtr )
56 , meShapeLocation( eShapeLocation )
57 {
58 }
59 
60 ContextHandlerRef PPTShapeGroupContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
61 {
62  if( getNamespace( aElementToken ) == NMSP_dsp )
63  aElementToken = NMSP_ppt | getBaseToken( aElementToken );
64 
65  switch( aElementToken )
66  {
67  case PPT_TOKEN( cNvPr ):
68  {
69  // don't override SmartArt properties for embedded drawing's spTree
70  mpGroupShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
71  if (mpGroupShapePtr->getId().isEmpty())
72  mpGroupShapePtr->setId(rAttribs.getString(XML_id).get());
73  if (mpGroupShapePtr->getName().isEmpty())
74  mpGroupShapePtr->setName( rAttribs.getString( XML_name ).get() );
75  break;
76  }
77  case PPT_TOKEN( ph ):
78  mpGroupShapePtr->setSubType( rAttribs.getToken( XML_type, FastToken::DONTKNOW ) );
79  if( rAttribs.hasAttribute( XML_idx ) )
80  mpGroupShapePtr->setSubTypeIndex( rAttribs.getString( XML_idx ).get().toInt32() );
81  break;
82  // nvSpPr CT_ShapeNonVisual end
83 
84  case PPT_TOKEN( grpSpPr ):
86  case PPT_TOKEN( spPr ):
88 /*
89  case PPT_TOKEN( style ):
90  return new ShapeStyleContext( getParser() );
91 */
92  case PPT_TOKEN( cxnSp ): // connector shape
93  return new oox::drawingml::ConnectorShapeContext( *this, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.ConnectorShape" ) );
94  case PPT_TOKEN( grpSp ): // group shape
95  return new PPTShapeGroupContext( *this, mpSlidePersistPtr, meShapeLocation, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.GroupShape" ) );
96  case PPT_TOKEN( sp ): // Shape
97  {
98  auto pShape = std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.CustomShape" );
99  bool bUseBgFill = rAttribs.getBool(XML_useBgFill, false);
100  pShape->setUseBgFill(bUseBgFill);
101  if (bUseBgFill)
102  {
103  oox::drawingml::FillPropertiesPtr pBackgroundPropertiesPtr = mpSlidePersistPtr->getBackgroundProperties();
104  if (!pBackgroundPropertiesPtr)
105  {
106  // The shape wants a background, but the slide doesn't have one.
107  SlidePersistPtr pMaster = mpSlidePersistPtr->getMasterPersist();
108  if (pMaster)
109  {
110  oox::drawingml::FillPropertiesPtr pMasterBackground
111  = pMaster->getBackgroundProperties();
112  if (pMasterBackground)
113  {
114  if (pMasterBackground->moFillType.has()
115  && pMasterBackground->moFillType.get() == XML_solidFill)
116  {
117  // Master has a solid background, use that.
118  pBackgroundPropertiesPtr = pMasterBackground;
119  }
120  }
121  }
122  }
123  if (pBackgroundPropertiesPtr)
124  {
125  pShape->getFillProperties().assignUsed(*pBackgroundPropertiesPtr);
126  }
127  }
128  pShape->setModelId(rAttribs.getString( XML_modelId ).get());
129  return new PPTShapeContext( *this, mpSlidePersistPtr, mpGroupShapePtr, pShape );
130  }
131  case PPT_TOKEN( pic ): // CT_Picture
132  return new PPTGraphicShapeContext( *this, mpSlidePersistPtr, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.GraphicObjectShape" ) );
133  case PPT_TOKEN( graphicFrame ): // CT_GraphicalObjectFrame
134  {
135  pGraphicShape = std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.OLE2Shape" );
137  }
138  }
139 
140  return this;
141 }
142 
144 {
145  if( !pGraphicShape )
146  return;
147 
148  for (auto const& extDrawing : pGraphicShape->getExtDrawings())
149  {
150  OUString aFragmentPath = getFragmentPathFromRelId(extDrawing);
151  getFilter().importFragment( new ExtDrawingFragmentHandler( getFilter(), aFragmentPath,
155  pGraphicShape ) );
156  pGraphicShape->keepDiagramDrawing(getFilter(), aFragmentPath);
157 
158  // Apply font color imported from color fragment
159  if( pGraphicShape->getFontRefColorForNodes().isUsed() )
160  applyFontRefColor(mpGroupShapePtr, pGraphicShape->getFontRefColorForNodes());
161  }
163 }
164 
166 {
167  pShape->getShapeStyleRefs()[XML_fontRef].maPhClr = rFontRefColor;
168  std::vector< oox::drawingml::ShapePtr >& vChildren = pShape->getChildren();
169  for (auto const& child : vChildren)
170  {
171  applyFontRefColor(child, rFontRefColor);
172  }
173 }
174 
175 }
176 
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< FillProperties > FillPropertiesPtr
void applyFontRefColor(const oox::drawingml::ShapePtr &pShape, const oox::drawingml::Color &rFontRefColor)
OptValue< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
const Type & get() const
Definition: helper.hxx:185
oox::drawingml::ShapePtr pGraphicShape
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
Provides access to attribute values of an element.
PPTShapeGroupContext(::oox::core::FragmentHandler2 const &rParent, const oox::ppt::SlidePersistPtr &rSlidePersistPtr, const oox::ppt::ShapeLocation eShapeLocation, const oox::drawingml::ShapePtr &pMasterShapePtr, const oox::drawingml::ShapePtr &pGroupShapePtr)
std::shared_ptr< SlidePersist > SlidePersistPtr
std::shared_ptr< Shape > ShapePtr
OptValue< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.