Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/ppt/pptgraphicshapecontext.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 <oox/ppt/pptshape.hxx>
21
#include <oox/ppt/pptgraphicshapecontext.hxx>
22
#include <oox/ppt/pptshapepropertiescontext.hxx>
23
#include <oox/ppt/slidepersist.hxx>
24
#include <drawingml/shapestylecontext.hxx>
25
#include <oox/drawingml/drawingmltypes.hxx>
26
#include <drawingml/textbodycontext.hxx>
27
#include <oox/helper/attributelist.hxx>
28
#include <oox/token/namespaces.hxx>
29
#include <oox/token/tokens.hxx>
30
#include <oox/token/properties.hxx>
31
#include <utility>
32
33
using namespace oox::core;
34
using namespace ::com::sun::star;
35
using namespace ::com::sun::star::uno;
36
37
namespace oox::ppt {
38
39
// CT_Shape
40
PPTGraphicShapeContext::PPTGraphicShapeContext( ContextHandler2Helper const & rParent, SlidePersistPtr pSlidePersistPtr, const oox::drawingml::ShapePtr& pMasterShapePtr, const oox::drawingml::ShapePtr& pShapePtr )
41
1.52k
: oox::drawingml::GraphicShapeContext( rParent, pMasterShapePtr, pShapePtr )
42
1.52k
, mpSlidePersistPtr(std::move( pSlidePersistPtr ))
43
1.52k
{
44
1.52k
}
45
46
ContextHandlerRef PPTGraphicShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
47
9.13k
{
48
9.13k
    switch( aElementToken )
49
9.13k
    {
50
    // nvSpPr CT_ShapeNonVisual begin
51
//  case NMSP_PPT|XML_drElemPr:
52
//      break;
53
1.52k
    case PPT_TOKEN(cNvPr):
54
1.52k
        mpShapePtr->setId( rAttribs.getStringDefaulted( XML_id ) );
55
1.52k
        mpShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) );
56
1.52k
        break;
57
0
    case PPT_TOKEN(ph):
58
0
    {
59
0
        sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) );
60
0
        mpShapePtr->setSubType( nSubType );
61
0
        OUString sIdx( rAttribs.getStringDefaulted( XML_idx ) );
62
0
        bool bHasIdx = !sIdx.isEmpty();
63
0
        sal_uInt32 nUnsignedIdx = rAttribs.getUnsigned( XML_idx, 0 );
64
0
        bool bSkipPlaceholderLookup = (bHasIdx && nUnsignedIdx == SAL_MAX_UINT32);
65
0
        sal_Int32 nIdx = static_cast<sal_Int32>(nUnsignedIdx);
66
0
        if( rAttribs.hasAttribute( XML_idx ) && !bSkipPlaceholderLookup )
67
0
            mpShapePtr->setSubTypeIndex( nIdx );
68
69
0
        if ( (nSubType || bHasIdx) && !bSkipPlaceholderLookup )
70
0
        {
71
0
            PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
72
0
            if ( pPPTShapePtr )
73
0
            {
74
0
                oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
75
0
                oox::drawingml::ShapePtr pPlaceholder;
76
77
0
                if ( bHasIdx && eShapeLocation == Slide )
78
0
                {
79
                    // TODO: use id to shape map
80
0
                    SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
81
0
                    if ( pMasterPersist && rAttribs.hasAttribute( XML_idx ) )
82
0
                        pPlaceholder = PPTShape::findPlaceholderByIndex( nIdx, pMasterPersist->getShapes()->getChildren() );
83
0
                }
84
0
                if ( !pPlaceholder && ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) ) )
85
0
                {
86
                    // inheriting properties from placeholder objects by cloning shape
87
88
0
                    sal_Int32 nFirstPlaceholder = 0;
89
0
                    sal_Int32 nSecondPlaceholder = 0;
90
0
                    switch( nSubType )
91
0
                    {
92
0
                        case XML_ctrTitle :     // slide/layout
93
0
                            nFirstPlaceholder = XML_ctrTitle;
94
0
                            nSecondPlaceholder = XML_title;
95
0
                            break;
96
0
                        case XML_subTitle :     // slide/layout
97
0
                            nFirstPlaceholder = XML_subTitle;
98
0
                            nSecondPlaceholder = XML_title;
99
0
                            break;
100
0
                        case XML_obj :          // slide/layout
101
0
                            nFirstPlaceholder = XML_body;
102
0
                            break;
103
0
                        case XML_dt :           // slide/layout/master/notes/notesmaster/handoutmaster
104
0
                        case XML_sldNum :       // slide/layout/master/notes/notesmaster/handoutmaster
105
0
                        case XML_ftr :          // slide/layout/master/notes/notesmaster/handoutmaster
106
0
                        case XML_hdr :          // notes/notesmaster/handoutmaster
107
0
                        case XML_body :         // slide/layout/master/notes/notesmaster
108
0
                        case XML_title :        // slide/layout/master/
109
0
                        case XML_chart :        // slide/layout
110
0
                        case XML_tbl :          // slide/layout
111
0
                        case XML_clipArt :      // slide/layout
112
0
                        case XML_dgm :          // slide/layout
113
0
                        case XML_media :        // slide/layout
114
0
                        case XML_sldImg :       // notes/notesmaster
115
0
                        case XML_pic :          // slide/layout
116
0
                            nFirstPlaceholder = nSubType;
117
0
                            break;
118
0
                        default:
119
0
                            break;
120
0
                    }
121
0
                    if ( nFirstPlaceholder )
122
0
                    {
123
0
                        if ( eShapeLocation == Layout )     // for layout objects the referenced object can be found within the same shape tree
124
0
                            pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
125
0
                                    pPPTShapePtr->getSubTypeIndex(), mpSlidePersistPtr->getShapes()->getChildren(), true );
126
0
                        else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
127
0
                        {
128
0
                            SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
129
0
                            if ( pMasterPersist )
130
0
                                pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
131
0
                                        pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
132
0
                        }
133
0
                    }
134
0
                }
135
0
                if ( pPlaceholder )
136
0
                {
137
0
                    bool bUseText = true;
138
0
                    switch( pPlaceholder->getSubType() )
139
0
                    {
140
0
                        case XML_title :
141
0
                        case XML_body :
142
0
                        case XML_ctrTitle :
143
0
                        case XML_subTitle :
144
0
                        case XML_dt :
145
0
                        case XML_sldNum :
146
0
                        case XML_ftr :
147
0
                        case XML_hdr :
148
0
                        case XML_obj :
149
0
                        case XML_chart :
150
0
                        case XML_tbl :
151
0
                        case XML_clipArt :
152
0
                        case XML_dgm :
153
0
                        case XML_media :
154
0
                        case XML_sldImg :
155
0
                        case XML_pic :
156
0
                            bUseText = false;
157
0
                    }
158
0
                    pPlaceholder->getShapeProperties().setAnyProperty(
159
0
                        PROP_URL, mpShapePtr->getShapeProperties().getProperty(PROP_URL));
160
0
                    mpShapePtr->applyShapeReference( *pPlaceholder, bUseText );
161
0
                    PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
162
0
                    if ( pPPTShape )
163
0
                        pPPTShape->setReferenced( true );
164
0
                    pPPTShapePtr->setPlaceholder( pPlaceholder );
165
0
                }
166
0
            }
167
0
        }
168
0
        break;
169
0
    }
170
    // nvSpPr CT_ShapeNonVisual end
171
172
1.52k
    case PPT_TOKEN(spPr):
173
1.52k
        return new PPTShapePropertiesContext( *this, *mpShapePtr );
174
175
0
    case PPT_TOKEN(style):
176
0
        return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
177
178
0
    case PPT_TOKEN(txBody):
179
0
    {
180
0
        oox::drawingml::TextBodyPtr xTextBody = std::make_shared<oox::drawingml::TextBody>();
181
0
        mpShapePtr->setTextBody( xTextBody );
182
0
        return new oox::drawingml::TextBodyContext( *this, *xTextBody );
183
0
    }
184
9.13k
    }
185
186
7.61k
    return GraphicShapeContext::onCreateContext( aElementToken, rAttribs );
187
9.13k
}
188
189
}
190
191
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */