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 OOX_TOKEN(dml, extLst):
69 case OOX_TOKEN(dml, ext):
70 break;
71 case OOX_TOKEN(adec, decorative):
72 {
73 mpGroupShapePtr->setDecorative(rAttribs.getBool(XML_val, false));
74 }
75 break;
76 case PPT_TOKEN( cNvPr ):
77 {
78 // don't override SmartArt properties for embedded drawing's spTree
79 mpGroupShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
80 if (mpGroupShapePtr->getId().isEmpty())
81 mpGroupShapePtr->setId(rAttribs.getStringDefaulted(XML_id));
82 if (mpGroupShapePtr->getName().isEmpty())
83 mpGroupShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) );
84 break;
85 }
86 case PPT_TOKEN( ph ):
87 mpGroupShapePtr->setSubType( rAttribs.getToken( XML_type, FastToken::DONTKNOW ) );
88 if( rAttribs.hasAttribute( XML_idx ) )
89 mpGroupShapePtr->setSubTypeIndex( rAttribs.getInteger( XML_idx, 0 ) );
90 break;
91 // nvSpPr CT_ShapeNonVisual end
92
93 case PPT_TOKEN( grpSpPr ):
95 case PPT_TOKEN( spPr ):
97/*
98 case PPT_TOKEN( style ):
99 return new ShapeStyleContext( getParser() );
100*/
101 case PPT_TOKEN( cxnSp ): // connector shape
102 {
103 auto pShape = std::make_shared<PPTShape>(meShapeLocation, "com.sun.star.drawing.ConnectorShape");
105 pShape->getConnectorShapeProperties());
106 }
107 case PPT_TOKEN( grpSp ): // group shape
108 return new PPTShapeGroupContext( *this, mpSlidePersistPtr, meShapeLocation, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.GroupShape" ) );
109 case PPT_TOKEN( sp ): // Shape
110 {
111 auto pShape = std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.CustomShape" );
112 bool bUseBgFill = rAttribs.getBool(XML_useBgFill, false);
113 if (bUseBgFill)
114 {
115 pShape->getFillProperties().moFillType = XML_noFill;
116 pShape->getFillProperties().moUseBgFill = true;
117 }
118 pShape->setModelId(rAttribs.getStringDefaulted( XML_modelId ));
119 return new PPTShapeContext( *this, mpSlidePersistPtr, mpGroupShapePtr, pShape );
120 }
121 case PPT_TOKEN( pic ): // CT_Picture
122 return new PPTGraphicShapeContext( *this, mpSlidePersistPtr, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.GraphicObjectShape" ) );
123 case PPT_TOKEN( graphicFrame ): // CT_GraphicalObjectFrame
124 {
125 pGraphicShape = std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.OLE2Shape" );
127 }
128 }
129
130 return this;
131}
132
134{
135 if( !pGraphicShape )
136 return;
137
138 for (auto const& extDrawing : pGraphicShape->getExtDrawings())
139 {
140 OUString aFragmentPath = getFragmentPathFromRelId(extDrawing);
141 getFilter().importFragment( new ExtDrawingFragmentHandler( getFilter(), aFragmentPath,
145 pGraphicShape ) );
146 pGraphicShape->keepDiagramDrawing(getFilter(), aFragmentPath);
147
148 // Apply font color imported from color fragment
149 if( pGraphicShape->getFontRefColorForNodes().isUsed() )
150 applyFontRefColor(mpGroupShapePtr, pGraphicShape->getFontRefColorForNodes());
151 }
153}
154
156{
157 pShape->getShapeStyleRefs()[XML_fontRef].maPhClr = rFontRefColor;
158 std::vector< oox::drawingml::ShapePtr >& vChildren = pShape->getChildren();
159 for (auto const& child : vChildren)
160 {
161 applyFontRefColor(child, rFontRefColor);
162 }
163}
164
165}
166
167/* 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