/src/libreoffice/oox/source/ppt/pptshapecontext.cxx
Line | Count | Source |
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 | | |
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> |
35 | | |
36 | | using namespace oox::core; |
37 | | using namespace ::com::sun::star; |
38 | | using namespace ::com::sun::star::uno; |
39 | | |
40 | | namespace oox::ppt { |
41 | | |
42 | | // CT_Shape |
43 | | PPTShapeContext::PPTShapeContext( ContextHandler2Helper const & rParent, SlidePersistPtr pSlidePersistPtr, const oox::drawingml::ShapePtr& pMasterShapePtr, const oox::drawingml::ShapePtr& pShapePtr ) |
44 | 97.3k | : oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr ) |
45 | 97.3k | , mpSlidePersistPtr(std::move( pSlidePersistPtr )) |
46 | 97.3k | { |
47 | 97.3k | } |
48 | | |
49 | | ContextHandlerRef PPTShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs ) |
50 | 745k | { |
51 | 745k | if( getNamespace( aElementToken ) == NMSP_dsp ) |
52 | 0 | aElementToken = NMSP_ppt | getBaseToken( aElementToken ); |
53 | | |
54 | 745k | switch( aElementToken ) |
55 | 745k | { |
56 | | // nvSpPr CT_ShapeNonVisual begin |
57 | | // case PPT_TOKEN( drElemPr ): |
58 | | // break; |
59 | 97.3k | case PPT_TOKEN( cNvPr ): |
60 | 97.3k | { |
61 | 97.3k | mpShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) ); |
62 | 97.3k | mpShapePtr->setId( rAttribs.getStringDefaulted( XML_id ) ); |
63 | 97.3k | mpShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) ); |
64 | 97.3k | break; |
65 | 0 | } |
66 | 83.4k | case PPT_TOKEN( ph ): |
67 | 83.4k | { |
68 | 83.4k | SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() ); |
69 | 83.4k | std::optional< sal_Int32 > oSubType( rAttribs.getToken( XML_type) ); |
70 | 83.4k | sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) ); |
71 | 83.4k | oox::drawingml::ShapePtr pTmpPlaceholder; |
72 | | |
73 | 83.4k | mpShapePtr->setSubType( nSubType ); |
74 | | |
75 | 83.4k | if( rAttribs.hasAttribute( XML_idx ) ) |
76 | 44.0k | { |
77 | 44.0k | sal_Int32 nSubTypeIndex = rAttribs.getInteger( XML_idx, 0 ); |
78 | 44.0k | mpShapePtr->setSubTypeIndex( nSubTypeIndex ); |
79 | | |
80 | 44.0k | if(!oSubType.has_value() && pMasterPersist) |
81 | 63 | { |
82 | 63 | pTmpPlaceholder = PPTShape::findPlaceholderByIndex( nSubTypeIndex, pMasterPersist->getShapes()->getChildren() ); |
83 | | |
84 | 63 | if(pTmpPlaceholder) |
85 | 56 | 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 |
86 | 63 | } |
87 | 44.0k | } |
88 | | |
89 | 83.4k | if ( nSubType ) |
90 | 83.4k | { |
91 | 83.4k | PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() ); |
92 | 83.4k | if ( pPPTShapePtr ) |
93 | 83.4k | { |
94 | 83.4k | oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation(); |
95 | 83.4k | if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) ) |
96 | 44.5k | { |
97 | | // inheriting properties from placeholder objects by cloning shape |
98 | 44.5k | sal_Int32 nFirstPlaceholder = 0; |
99 | 44.5k | sal_Int32 nSecondPlaceholder = 0; |
100 | 44.5k | switch( nSubType ) |
101 | 44.5k | { |
102 | 799 | case XML_ctrTitle : // slide/layout |
103 | 799 | nFirstPlaceholder = XML_ctrTitle; |
104 | 799 | nSecondPlaceholder = XML_title; |
105 | 799 | break; |
106 | | |
107 | 1.56k | case XML_subTitle : // slide/layout |
108 | 1.56k | nFirstPlaceholder = XML_subTitle; |
109 | 1.56k | nSecondPlaceholder = XML_body; |
110 | 1.56k | break; |
111 | | |
112 | 3.07k | case XML_obj : // slide/layout |
113 | 3.07k | nFirstPlaceholder = XML_obj; |
114 | 3.07k | nSecondPlaceholder = XML_body; |
115 | 3.07k | break; |
116 | | |
117 | 5.62k | case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster |
118 | 11.2k | case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster |
119 | 16.9k | case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster |
120 | 16.9k | case XML_hdr : // notes/notesmaster/handoutmaster |
121 | 29.6k | case XML_body : // slide/layout/master/notes/notesmaster |
122 | 38.6k | case XML_title : // slide/layout/master/ |
123 | 38.6k | case XML_chart : // slide/layout |
124 | 38.6k | case XML_tbl : // slide/layout |
125 | 38.6k | case XML_clipArt : // slide/layout |
126 | 38.6k | case XML_dgm : // slide/layout |
127 | 38.6k | case XML_media : // slide/layout |
128 | 38.6k | case XML_sldImg : // notes/notesmaster |
129 | 39.1k | case XML_pic : // slide/layout |
130 | 39.1k | nFirstPlaceholder = nSubType; |
131 | 39.1k | break; |
132 | 0 | default: |
133 | 0 | break; |
134 | 44.5k | } |
135 | 44.5k | if ( nFirstPlaceholder ) |
136 | 44.5k | { |
137 | 44.5k | oox::drawingml::ShapePtr pPlaceholder; |
138 | 44.5k | if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree |
139 | 43.7k | { |
140 | 43.7k | pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, |
141 | 43.7k | pPPTShapePtr->getSubTypeIndex(), mpSlidePersistPtr->getShapes()->getChildren(), true ); |
142 | 43.7k | } |
143 | 830 | else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects |
144 | 830 | { |
145 | 830 | if ( pMasterPersist ) |
146 | 613 | { |
147 | 613 | pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, |
148 | 613 | pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() ); |
149 | 613 | } |
150 | 830 | } |
151 | 44.5k | if ( pPlaceholder ) |
152 | 25.2k | { |
153 | 25.2k | SAL_INFO("oox.ppt","shape " << mpShapePtr->getId() << |
154 | 25.2k | " will get shape reference " << pPlaceholder->getId() << " applied"); |
155 | 25.2k | mpShapePtr->applyShapeReference( *pPlaceholder ); |
156 | 25.2k | PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() ); |
157 | 25.2k | if ( pPPTShape ) |
158 | 25.2k | pPPTShape->setReferenced( true ); |
159 | 25.2k | pPPTShapePtr->setPlaceholder( pPlaceholder ); |
160 | 25.2k | } |
161 | 44.5k | } |
162 | 44.5k | } |
163 | 83.4k | } |
164 | | |
165 | 83.4k | } |
166 | 83.4k | break; |
167 | 83.4k | } |
168 | | |
169 | | // nvSpPr CT_ShapeNonVisual end |
170 | | |
171 | 97.3k | case PPT_TOKEN( spPr ): |
172 | 97.3k | return new PPTShapePropertiesContext( *this, *mpShapePtr ); |
173 | | |
174 | 319 | case PPT_TOKEN( style ): |
175 | 319 | return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr ); |
176 | | |
177 | 91.1k | case PPT_TOKEN( txBody ): |
178 | 91.1k | { |
179 | 91.1k | oox::drawingml::TextBodyPtr xTextBody = std::make_shared<oox::drawingml::TextBody>( mpShapePtr->getTextBody() ); |
180 | 91.1k | xTextBody->getTextProperties().maPropertyMap.setProperty( PROP_FontIndependentLineSpacing, true ); |
181 | 91.1k | mpShapePtr->setTextBody( xTextBody ); |
182 | 91.1k | return new oox::drawingml::TextBodyContext( *this, mpShapePtr ); |
183 | 83.4k | } |
184 | 0 | case PPT_TOKEN( txXfrm ): |
185 | 0 | { |
186 | 0 | return new oox::drawingml::Transform2DContext( *this, rAttribs, *mpShapePtr, true ); |
187 | 83.4k | } |
188 | 745k | } |
189 | | |
190 | 556k | return ShapeContext::onCreateContext(aElementToken, rAttribs); |
191 | 745k | } |
192 | | |
193 | | } |
194 | | |
195 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |