LibreOffice Module oox (master) 1
pptshapecontext.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 <sal/log.hxx>
21
23#include <oox/ppt/pptshape.hxx>
31#include <oox/token/namespaces.hxx>
32#include <oox/token/properties.hxx>
33#include <oox/token/tokens.hxx>
34#include <utility>
35
36using namespace oox::core;
37using namespace ::com::sun::star;
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::text;
40
41namespace oox::ppt {
42
43// CT_Shape
44PPTShapeContext::PPTShapeContext( ContextHandler2Helper const & rParent, SlidePersistPtr pSlidePersistPtr, const oox::drawingml::ShapePtr& pMasterShapePtr, const oox::drawingml::ShapePtr& pShapePtr )
45: oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr )
46, mpSlidePersistPtr(std::move( pSlidePersistPtr ))
47{
48}
49
50ContextHandlerRef PPTShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
51{
52 if( getNamespace( aElementToken ) == NMSP_dsp )
53 aElementToken = NMSP_ppt | getBaseToken( aElementToken );
54
55 switch( aElementToken )
56 {
57 // nvSpPr CT_ShapeNonVisual begin
58 // case PPT_TOKEN( drElemPr ):
59 // break;
60 case PPT_TOKEN( cNvPr ):
61 {
62 mpShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
63 mpShapePtr->setId( rAttribs.getStringDefaulted( XML_id ) );
64 mpShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) );
65 break;
66 }
67 case PPT_TOKEN( ph ):
68 {
69 SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
70 std::optional< sal_Int32 > oSubType( rAttribs.getToken( XML_type) );
71 sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) );
72 oox::drawingml::ShapePtr pTmpPlaceholder;
73
74 mpShapePtr->setSubType( nSubType );
75
76 if( rAttribs.hasAttribute( XML_idx ) )
77 {
78 sal_Int32 nSubTypeIndex = rAttribs.getInteger( XML_idx, 0 );
79 mpShapePtr->setSubTypeIndex( nSubTypeIndex );
80
81 if(!oSubType.has_value() && pMasterPersist)
82 {
83 pTmpPlaceholder = PPTShape::findPlaceholderByIndex( nSubTypeIndex, pMasterPersist->getShapes()->getChildren() );
84
85 if(pTmpPlaceholder)
86 nSubType = pTmpPlaceholder->getSubType(); // When we don't have type attribute on slide but have on slidelayout we have to use it instead of default type
87 }
88 }
89
90 if ( nSubType )
91 {
92 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
93 if ( pPPTShapePtr )
94 {
95 oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
96 if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) )
97 {
98 // inheriting properties from placeholder objects by cloning shape
99 sal_Int32 nFirstPlaceholder = 0;
100 sal_Int32 nSecondPlaceholder = 0;
101 switch( nSubType )
102 {
103 case XML_ctrTitle : // slide/layout
104 nFirstPlaceholder = XML_ctrTitle;
105 nSecondPlaceholder = XML_title;
106 break;
107
108 case XML_subTitle : // slide/layout
109 nFirstPlaceholder = XML_subTitle;
110 nSecondPlaceholder = XML_body;
111 break;
112
113 case XML_obj : // slide/layout
114 nFirstPlaceholder = XML_obj;
115 nSecondPlaceholder = XML_body;
116 break;
117
118 case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster
119 case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster
120 case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster
121 case XML_hdr : // notes/notesmaster/handoutmaster
122 case XML_body : // slide/layout/master/notes/notesmaster
123 case XML_title : // slide/layout/master/
124 case XML_chart : // slide/layout
125 case XML_tbl : // slide/layout
126 case XML_clipArt : // slide/layout
127 case XML_dgm : // slide/layout
128 case XML_media : // slide/layout
129 case XML_sldImg : // notes/notesmaster
130 case XML_pic : // slide/layout
131 nFirstPlaceholder = nSubType;
132 break;
133 default:
134 break;
135 }
136 if ( nFirstPlaceholder )
137 {
138 oox::drawingml::ShapePtr pPlaceholder;
139 if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree
140 {
141 pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
142 pPPTShapePtr->getSubTypeIndex(), mpSlidePersistPtr->getShapes()->getChildren(), true );
143 }
144 else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
145 {
146 if ( pMasterPersist )
147 {
148 pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
149 pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
150 }
151 }
152 if ( pPlaceholder )
153 {
154 SAL_INFO("oox.ppt","shape " << mpShapePtr->getId() <<
155 " will get shape reference " << pPlaceholder->getId() << " applied");
156 mpShapePtr->applyShapeReference( *pPlaceholder );
157 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
158 if ( pPPTShape )
159 pPPTShape->setReferenced( true );
160 pPPTShapePtr->setPlaceholder( pPlaceholder );
161 }
162 }
163 }
164 }
165
166 }
167 break;
168 }
169
170 // nvSpPr CT_ShapeNonVisual end
171
172 case PPT_TOKEN( spPr ):
173 return new PPTShapePropertiesContext( *this, *mpShapePtr );
174
175 case PPT_TOKEN( style ):
176 return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
177
178 case PPT_TOKEN( txBody ):
179 {
180 oox::drawingml::TextBodyPtr xTextBody = std::make_shared<oox::drawingml::TextBody>( mpShapePtr->getTextBody() );
181 xTextBody->getTextProperties().maPropertyMap.setProperty( PROP_FontIndependentLineSpacing, true );
182 mpShapePtr->setTextBody( xTextBody );
183 return new oox::drawingml::TextBodyContext( *this, mpShapePtr );
184 }
185 case PPT_TOKEN( txXfrm ):
186 {
187 return new oox::drawingml::Transform2DContext( *this, rAttribs, *mpShapePtr, true );
188 }
189 }
190
191 return ShapeContext::onCreateContext(aElementToken, rAttribs);
192}
193
194}
195
196/* 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.
const std::optional< sal_Int32 > & getSubTypeIndex() const
Definition: shape.hxx:182
context to import a CT_Transform2D
PPTShapeContext(::oox::core::ContextHandler2Helper const &rParent, SlidePersistPtr xSlidePersistPtr, const oox::drawingml::ShapePtr &pMasterShapePtr, const oox::drawingml::ShapePtr &pShapePtr)
SlidePersistPtr mpSlidePersistPtr
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
static oox::drawingml::ShapePtr findPlaceholder(const sal_Int32 nFirstSubType, const sal_Int32 nSecondSubType, const std::optional< sal_Int32 > &oSubTypeIndex, std::vector< oox::drawingml::ShapePtr > &rShapes, bool bMasterOnly=false)
Definition: pptshape.cxx:642
ShapeLocation getShapeLocation() const
Definition: pptshape.hxx:74
void setReferenced(bool bReferenced)
Definition: pptshape.hxx:75
void setPlaceholder(oox::drawingml::ShapePtr pPlaceholder)
Definition: pptshape.hxx:76
static oox::drawingml::ShapePtr findPlaceholderByIndex(const sal_Int32 nIdx, std::vector< oox::drawingml::ShapePtr > &rShapes, bool bMasterOnly=false)
Definition: pptshape.cxx:742
#define SAL_INFO(area, stream)
std::shared_ptr< Shape > ShapePtr
std::shared_ptr< TextBody > TextBodyPtr
std::shared_ptr< SlidePersist > SlidePersistPtr
XML_type
constexpr OUStringLiteral PROP_FontIndependentLineSpacing