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#include <utility>
39
40using namespace oox::core;
41using namespace ::com::sun::star;
42using namespace ::com::sun::star::uno;
43using namespace ::com::sun::star::drawing;
44using namespace ::com::sun::star::text;
45using namespace ::com::sun::star::xml::sax;
46
47namespace oox::ppt {
48
50 FragmentHandler2 const & rParent,
51 oox::ppt::SlidePersistPtr pSlidePersistPtr,
52 const ShapeLocation eShapeLocation,
53 const oox::drawingml::ShapePtr& pMasterShapePtr,
54 const oox::drawingml::ShapePtr& pGroupShapePtr )
55: ShapeGroupContext( rParent, pMasterShapePtr, pGroupShapePtr )
56, mpSlidePersistPtr(std::move( pSlidePersistPtr ))
57, meShapeLocation( eShapeLocation )
58{
59}
60
62{
63 if( getNamespace( aElementToken ) == NMSP_dsp )
64 aElementToken = NMSP_ppt | getBaseToken( aElementToken );
65
66 switch( aElementToken )
67 {
68 case PPT_TOKEN( cNvPr ):
69 {
70 // don't override SmartArt properties for embedded drawing's spTree
71 mpGroupShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
72 if (mpGroupShapePtr->getId().isEmpty())
73 mpGroupShapePtr->setId(rAttribs.getStringDefaulted(XML_id));
74 if (mpGroupShapePtr->getName().isEmpty())
75 mpGroupShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) );
76 break;
77 }
78 case PPT_TOKEN( ph ):
79 mpGroupShapePtr->setSubType( rAttribs.getToken( XML_type, FastToken::DONTKNOW ) );
80 if( rAttribs.hasAttribute( XML_idx ) )
81 mpGroupShapePtr->setSubTypeIndex( rAttribs.getInteger( XML_idx, 0 ) );
82 break;
83 // nvSpPr CT_ShapeNonVisual end
84
85 case PPT_TOKEN( grpSpPr ):
87 case PPT_TOKEN( spPr ):
89/*
90 case PPT_TOKEN( style ):
91 return new ShapeStyleContext( getParser() );
92*/
93 case PPT_TOKEN( cxnSp ): // connector shape
94 {
95 auto pShape = std::make_shared<PPTShape>(meShapeLocation, "com.sun.star.drawing.ConnectorShape");
97 pShape->getConnectorShapeProperties());
98 }
99 case PPT_TOKEN( grpSp ): // group shape
100 return new PPTShapeGroupContext( *this, mpSlidePersistPtr, meShapeLocation, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.GroupShape" ) );
101 case PPT_TOKEN( sp ): // Shape
102 {
103 auto pShape = std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.CustomShape" );
104 bool bUseBgFill = rAttribs.getBool(XML_useBgFill, false);
105 if (bUseBgFill)
106 {
107 pShape->getFillProperties().moFillType = XML_noFill;
108 pShape->getFillProperties().moUseBgFill = true;
109 }
110 pShape->setModelId(rAttribs.getStringDefaulted( XML_modelId ));
111 return new PPTShapeContext( *this, mpSlidePersistPtr, mpGroupShapePtr, pShape );
112 }
113 case PPT_TOKEN( pic ): // CT_Picture
114 return new PPTGraphicShapeContext( *this, mpSlidePersistPtr, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.GraphicObjectShape" ) );
115 case PPT_TOKEN( graphicFrame ): // CT_GraphicalObjectFrame
116 {
117 pGraphicShape = std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.OLE2Shape" );
119 }
120 }
121
122 return this;
123}
124
126{
127 if( !pGraphicShape )
128 return;
129
130 for (auto const& extDrawing : pGraphicShape->getExtDrawings())
131 {
132 OUString aFragmentPath = getFragmentPathFromRelId(extDrawing);
133 getFilter().importFragment( new ExtDrawingFragmentHandler( getFilter(), aFragmentPath,
137 pGraphicShape ) );
138 pGraphicShape->keepDiagramDrawing(getFilter(), aFragmentPath);
139
140 // Apply font color imported from color fragment
141 if( pGraphicShape->getFontRefColorForNodes().isUsed() )
142 applyFontRefColor(mpGroupShapePtr, pGraphicShape->getFontRefColorForNodes());
143 }
145}
146
148{
149 pShape->getShapeStyleRefs()[XML_fontRef].maPhClr = rFontRefColor;
150 std::vector< oox::drawingml::ShapePtr >& vChildren = pShape->getChildren();
151 for (auto const& child : vChildren)
152 {
153 applyFontRefColor(child, rFontRefColor);
154 }
155}
156
157}
158
159/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to attribute values of an element.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
std::optional< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
oox::drawingml::ShapePtr pGraphicShape
void applyFontRefColor(const oox::drawingml::ShapePtr &pShape, const oox::drawingml::Color &rFontRefColor)
PPTShapeGroupContext(::oox::core::FragmentHandler2 const &rParent, oox::ppt::SlidePersistPtr xSlidePersistPtr, const oox::ppt::ShapeLocation eShapeLocation, const oox::drawingml::ShapePtr &pMasterShapePtr, const oox::drawingml::ShapePtr &pGroupShapePtr)
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
std::shared_ptr< Shape > ShapePtr
std::shared_ptr< SlidePersist > SlidePersistPtr
XML_type