Bump version to 24.04.3.4
[LibreOffice.git] / oox / source / ppt / pptshapecontext.cxx
blobf127c3a2a23f393ce306cb48d3959f78c158a385
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <sal/log.hxx>
22 #include <oox/helper/attributelist.hxx>
23 #include <oox/ppt/pptshape.hxx>
24 #include <oox/ppt/pptshapecontext.hxx>
25 #include <oox/ppt/pptshapepropertiescontext.hxx>
26 #include <oox/ppt/slidepersist.hxx>
27 #include <drawingml/shapestylecontext.hxx>
28 #include <oox/drawingml/drawingmltypes.hxx>
29 #include <drawingml/textbodycontext.hxx>
30 #include <drawingml/transform2dcontext.hxx>
31 #include <oox/token/namespaces.hxx>
32 #include <oox/token/properties.hxx>
33 #include <oox/token/tokens.hxx>
34 #include <utility>
36 using namespace oox::core;
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::text;
41 namespace oox::ppt {
43 // CT_Shape
44 PPTShapeContext::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 ))
50 ContextHandlerRef PPTShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
52 if( getNamespace( aElementToken ) == NMSP_dsp )
53 aElementToken = NMSP_ppt | getBaseToken( aElementToken );
55 switch( aElementToken )
57 // nvSpPr CT_ShapeNonVisual begin
58 // case PPT_TOKEN( drElemPr ):
59 // break;
60 case PPT_TOKEN( cNvPr ):
62 mpShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
63 mpShapePtr->setId( rAttribs.getStringDefaulted( XML_id ) );
64 mpShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) );
65 break;
67 case PPT_TOKEN( ph ):
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;
74 mpShapePtr->setSubType( nSubType );
76 if( rAttribs.hasAttribute( XML_idx ) )
78 sal_Int32 nSubTypeIndex = rAttribs.getInteger( XML_idx, 0 );
79 mpShapePtr->setSubTypeIndex( nSubTypeIndex );
81 if(!oSubType.has_value() && pMasterPersist)
83 pTmpPlaceholder = PPTShape::findPlaceholderByIndex( nSubTypeIndex, pMasterPersist->getShapes()->getChildren() );
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
90 if ( nSubType )
92 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
93 if ( pPPTShapePtr )
95 oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
96 if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) )
98 // inheriting properties from placeholder objects by cloning shape
99 sal_Int32 nFirstPlaceholder = 0;
100 sal_Int32 nSecondPlaceholder = 0;
101 switch( nSubType )
103 case XML_ctrTitle : // slide/layout
104 nFirstPlaceholder = XML_ctrTitle;
105 nSecondPlaceholder = XML_title;
106 break;
108 case XML_subTitle : // slide/layout
109 nFirstPlaceholder = XML_subTitle;
110 nSecondPlaceholder = XML_body;
111 break;
113 case XML_obj : // slide/layout
114 nFirstPlaceholder = XML_obj;
115 nSecondPlaceholder = XML_body;
116 break;
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;
136 if ( nFirstPlaceholder )
138 oox::drawingml::ShapePtr pPlaceholder;
139 if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree
141 pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
142 pPPTShapePtr->getSubTypeIndex(), mpSlidePersistPtr->getShapes()->getChildren(), true );
144 else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
146 if ( pMasterPersist )
148 pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
149 pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
152 if ( pPlaceholder )
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 );
167 break;
170 // nvSpPr CT_ShapeNonVisual end
172 case PPT_TOKEN( spPr ):
173 return new PPTShapePropertiesContext( *this, *mpShapePtr );
175 case PPT_TOKEN( style ):
176 return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
178 case PPT_TOKEN( txBody ):
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 );
185 case PPT_TOKEN( txXfrm ):
187 return new oox::drawingml::Transform2DContext( *this, rAttribs, *mpShapePtr, true );
191 return ShapeContext::onCreateContext(aElementToken, rAttribs);
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */