Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/ppt/slidefragmenthandler.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 <com/sun/star/beans/XPropertySet.hpp>
21
#include <com/sun/star/container/XNamed.hpp>
22
#include <com/sun/star/drawing/XDrawPage.hpp>
23
#include <comphelper/diagnose_ex.hxx>
24
25
#include <oox/drawingml/theme.hxx>
26
#include <oox/helper/attributelist.hxx>
27
#include <oox/helper/propertyset.hxx>
28
#include <oox/core/xmlfilterbase.hxx>
29
#include "headerfootercontext.hxx"
30
#include <oox/ppt/backgroundproperties.hxx>
31
#include <oox/ppt/slidefragmenthandler.hxx>
32
#include <oox/ppt/slidetimingcontext.hxx>
33
#include <oox/ppt/slidetransitioncontext.hxx>
34
#include <oox/ppt/slidemastertextstylescontext.hxx>
35
#include <oox/ppt/pptshapegroupcontext.hxx>
36
#include <oox/ppt/pptshape.hxx>
37
#include <oox/vml/vmldrawing.hxx>
38
#include <oox/vml/vmldrawingfragment.hxx>
39
#include <drawingml/clrschemecontext.hxx>
40
#include <drawingml/fillproperties.hxx>
41
#include <oox/ppt/pptimport.hxx>
42
#include <oox/token/namespaces.hxx>
43
#include <oox/token/properties.hxx>
44
#include <oox/token/tokens.hxx>
45
46
using namespace ::com::sun::star;
47
using namespace ::oox::core;
48
using namespace ::oox::drawingml;
49
using namespace ::com::sun::star::uno;
50
using namespace ::com::sun::star::drawing;
51
using namespace ::com::sun::star::xml::sax;
52
using namespace ::com::sun::star::container;
53
54
namespace oox::ppt {
55
56
SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath, const SlidePersistPtr& pPersistPtr, const ShapeLocation eShapeLocation )
57
35.5k
: FragmentHandler2( rFilter, rFragmentPath )
58
35.5k
, mpSlidePersistPtr( pPersistPtr )
59
35.5k
, meShapeLocation( eShapeLocation )
60
35.5k
{
61
35.5k
    OUString aVMLPath = getFragmentPathFromFirstTypeFromOfficeDoc(u"vmlDrawing");
62
35.5k
    if (aVMLPath.isEmpty())
63
35.5k
        aVMLPath = getFragmentPathFromFirstTypeFromOfficeDoc(u"legacyDrawing");
64
65
35.5k
    if (!aVMLPath.isEmpty())
66
0
        getFilter().importFragment(
67
0
            new oox::vml::DrawingFragment(getFilter(), aVMLPath, *pPersistPtr->getDrawing()));
68
35.5k
}
69
70
SlideFragmentHandler::~SlideFragmentHandler()
71
35.5k
{
72
35.5k
    try
73
35.5k
    {
74
        // convert and insert all VML shapes (mostly form controls)
75
35.5k
        mpSlidePersistPtr->getDrawing()->convertAndInsert();
76
35.5k
    }
77
35.5k
    catch (const uno::Exception&)
78
35.5k
    {
79
0
        TOOLS_WARN_EXCEPTION("oox", "SlideFragmentHandler dtor: VML shape insertion failed");
80
0
    }
81
35.5k
}
82
83
::oox::core::ContextHandlerRef SlideFragmentHandler::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
84
217k
{
85
217k
    switch( aElementToken )
86
217k
    {
87
8.54k
    case PPT_TOKEN( sldMaster ):        // CT_SlideMaster
88
8.54k
    case PPT_TOKEN( handoutMaster ):    // CT_HandoutMaster
89
11.1k
    case PPT_TOKEN( sld ):              // CT_CommonSlideData
90
11.1k
    {
91
11.1k
        Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
92
11.1k
        Reference< css::beans::XPropertySet > xSet(xSlide, UNO_QUERY);
93
11.1k
        PropertyMap aPropMap;
94
11.1k
        PropertySet aSlideProp( xSlide );
95
96
11.1k
        std::optional<bool> aShowMasterShapes = rAttribs.getBool(XML_showMasterSp);
97
11.1k
        if (aShowMasterShapes.has_value() && !aShowMasterShapes.value())
98
7
            xSet->setPropertyValue(u"IsBackgroundObjectsVisible"_ustr, Any(false));
99
100
11.1k
        aPropMap.setProperty( PROP_Visible, rAttribs.getBool( XML_show, true ));
101
11.1k
        aSlideProp.setProperties( aPropMap );
102
103
11.1k
        return this;
104
8.54k
    }
105
94
    case PPT_TOKEN( notes ):            // CT_NotesSlide
106
94
    {
107
        // Import notesMaster
108
94
        PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
109
94
        OUString aNotesFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( u"notesMaster" );
110
111
94
        std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
112
94
        bool bNotesFragmentPathFound = false;
113
94
        for (auto const& masterPage : rMasterPages)
114
991
        {
115
991
            if( masterPage->getPath() == aNotesFragmentPath )
116
17
            {
117
17
                if( !mpSlidePersistPtr->getMasterPersist() )
118
17
                    mpSlidePersistPtr->setMasterPersist(masterPage);
119
17
                bNotesFragmentPathFound=true;
120
17
                break;
121
17
            }
122
991
        }
123
94
        if( !bNotesFragmentPathFound && !mpSlidePersistPtr->getMasterPersist() )
124
77
        {
125
77
            SlidePersistPtr pMasterPersistPtr = std::make_shared<SlidePersist>( rFilter, true, true, mpSlidePersistPtr->getPage(),
126
77
                                std::make_shared<PPTShape>( Master, u"com.sun.star.drawing.GroupShape"_ustr ), mpSlidePersistPtr->getNotesTextStyle() );
127
77
            pMasterPersistPtr->setPath( aNotesFragmentPath );
128
77
            rFilter.getMasterPages().push_back( pMasterPersistPtr );
129
77
            FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aNotesFragmentPath, pMasterPersistPtr, Master ) );
130
77
            rFilter.importFragment( xMasterFragmentHandler );
131
77
            mpSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
132
77
        }
133
94
        return this;
134
8.54k
    }
135
39
    case PPT_TOKEN( notesMaster ):      // CT_NotesMaster
136
39
        return this;
137
21.3k
    case PPT_TOKEN( cSld ):             // CT_CommonSlideData
138
21.3k
        maSlideName = rAttribs.getStringDefaulted(XML_name);
139
21.3k
        return this;
140
141
21.3k
    case PPT_TOKEN( spTree ):           // CT_GroupShape
142
21.3k
        {
143
21.3k
            return new PPTShapeGroupContext(
144
21.3k
                *this, mpSlidePersistPtr, meShapeLocation, mpSlidePersistPtr->getShapes(),
145
21.3k
                std::make_shared<PPTShape>( meShapeLocation, u"com.sun.star.drawing.GroupShape"_ustr ) );
146
8.54k
        }
147
0
        break;
148
149
0
    case PPT_TOKEN( controls ):
150
0
        return this;
151
0
    case PPT_TOKEN( control ):
152
0
        {
153
0
            ::oox::vml::ControlInfo aInfo;
154
0
            aInfo.setShapeId( rAttribs.getInteger( XML_spid, 0 ) );
155
0
            aInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getStringDefaulted( R_TOKEN( id )) );
156
0
            aInfo.maName = rAttribs.getXString( XML_name, OUString() );
157
0
            mpSlidePersistPtr->getDrawing()->registerControl( aInfo );
158
0
        }
159
0
        return this;
160
161
777
    case PPT_TOKEN( timing ): // CT_SlideTiming
162
777
        return new SlideTimingContext( *this, mpSlidePersistPtr->getTimeNodeList() );
163
975
    case PPT_TOKEN( transition ): // CT_SlideTransition
164
975
        return new SlideTransitionContext( *this, rAttribs, maSlideProperties );
165
114
    case PPT_TOKEN( hf ):
166
114
        return new HeaderFooterContext( *this, rAttribs, mpSlidePersistPtr->getHeaderFooter() );
167
168
    // BackgroundGroup
169
5.79k
    case PPT_TOKEN( bg ):
170
5.79k
        return this;
171
2.15k
    case PPT_TOKEN( bgPr ):             // CT_BackgroundProperties
172
2.15k
        {
173
2.15k
            FillPropertiesPtr pFillPropertiesPtr =std::make_shared<FillProperties>();
174
2.15k
            mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
175
2.15k
            return new BackgroundPropertiesContext( *this, *pFillPropertiesPtr );
176
8.54k
        }
177
0
        break;
178
179
3.64k
    case PPT_TOKEN( bgRef ):            // a:CT_StyleMatrixReference
180
3.64k
        {
181
3.64k
            const FillProperties *pFillProperties = nullptr;
182
3.64k
            if( mpSlidePersistPtr->getTheme() )
183
3.62k
                pFillProperties = mpSlidePersistPtr->getTheme()->getFillStyle( rAttribs.getInteger( XML_idx, -1 ) );
184
3.64k
            FillPropertiesPtr pFillPropertiesPtr =
185
3.64k
                pFillProperties
186
3.64k
                ? std::make_shared<FillProperties>( *pFillProperties )
187
3.64k
                : std::make_shared<FillProperties>();
188
3.64k
            mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
189
3.64k
            ContextHandlerRef ret = new ColorContext(*this, &mpSlidePersistPtr->getBackgroundColor());
190
3.64k
            return ret;
191
8.54k
        }
192
0
        break;
193
194
0
    case A_TOKEN( overrideClrMapping ):
195
8.58k
    case PPT_TOKEN( clrMap ):           // CT_ColorMapping
196
8.58k
        {
197
8.58k
            oox::drawingml::ClrMapPtr pClrMapPtr =
198
8.58k
                ( aElementToken == PPT_TOKEN( clrMap ) || !mpSlidePersistPtr || !mpSlidePersistPtr->getClrMap() )
199
8.58k
                ? std::make_shared<oox::drawingml::ClrMap>()
200
8.58k
                : std::make_shared<oox::drawingml::ClrMap>( *mpSlidePersistPtr->getClrMap() );
201
8.58k
            ContextHandlerRef ret = new oox::drawingml::clrMapContext( *this, rAttribs, *pClrMapPtr );
202
8.58k
            mpSlidePersistPtr->setClrMap( pClrMapPtr );
203
8.58k
            return ret;
204
0
        }
205
0
        break;
206
5.59k
    case PPT_TOKEN( clrMapOvr ):        // CT_ColorMappingOverride
207
14.1k
    case PPT_TOKEN( sldLayoutIdLst ):   // CT_SlideLayoutIdList
208
14.1k
        return this;
209
4.29k
    case PPT_TOKEN( txStyles ):         // CT_SlideMasterTextStyles
210
4.29k
        return new SlideMasterTextStylesContext( *this, mpSlidePersistPtr );
211
0
    case PPT_TOKEN( custDataLst ):      // CT_CustomerDataList
212
0
    case PPT_TOKEN( tagLst ):           // CT_TagList
213
0
        return this;
214
215
    //for Comments
216
26
    case PPT_TOKEN( cmLst ):
217
26
        break;
218
61
    case PPT_TOKEN( cm ):
219
61
        if (!mpSlidePersistPtr->getCommentsList().cmLst.empty() && !getCharVector().empty())
220
35
        {
221
            // set comment text for earlier comment
222
35
            mpSlidePersistPtr->getCommentsList().cmLst.back().setText( getCharVector().back() );
223
35
        }
224
        // insert a new comment in vector commentsList
225
61
        mpSlidePersistPtr->getCommentsList().cmLst.emplace_back();
226
61
        mpSlidePersistPtr->getCommentsList().cmLst.back().setAuthorId(rAttribs.getStringDefaulted(XML_authorId));
227
61
        mpSlidePersistPtr->getCommentsList().cmLst.back().setdt(rAttribs.getStringDefaulted(XML_dt));
228
61
        mpSlidePersistPtr->getCommentsList().cmLst.back().setidx(rAttribs.getStringDefaulted(XML_idx));
229
61
        break;
230
231
61
    case PPT_TOKEN( pos ):
232
61
        mpSlidePersistPtr->getCommentsList().cmLst.back().setPoint(
233
61
            rAttribs.getStringDefaulted(XML_x),
234
61
            rAttribs.getStringDefaulted(XML_y));
235
61
        break;
236
237
11
    case PPT_TOKEN( cmAuthor ):
238
11
        CommentAuthor _author;
239
11
        _author.clrIdx = rAttribs.getStringDefaulted(XML_clrIdx);
240
11
        _author.id = rAttribs.getStringDefaulted(XML_id);
241
11
        _author.initials = rAttribs.getStringDefaulted(XML_initials);
242
11
        _author.lastIdx = rAttribs.getStringDefaulted(XML_lastIdx);
243
11
        _author.name = rAttribs.getStringDefaulted(XML_name);
244
11
        mpSlidePersistPtr->getCommentAuthors().addAuthor(_author);
245
11
        break;
246
217k
    }
247
248
123k
    return this;
249
217k
}
250
void SlideFragmentHandler::onCharacters( const OUString& rChars)
251
61
{
252
61
    maCharVector.push_back(rChars);
253
61
}
254
void SlideFragmentHandler::finalizeImport()
255
21.4k
{
256
21.4k
    try
257
21.4k
    {
258
21.4k
        Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
259
21.4k
        PropertySet aSlideProp( xSlide );
260
21.4k
        aSlideProp.setProperties( maSlideProperties );
261
21.4k
        if ( !maSlideName.isEmpty() )
262
10.0k
        {
263
10.0k
            Reference< XNamed > xNamed( xSlide, UNO_QUERY );
264
10.0k
            if( xNamed.is() )
265
10.0k
                xNamed->setName( maSlideName );
266
10.0k
        }
267
21.4k
    }
268
21.4k
    catch( uno::Exception& )
269
21.4k
    {
270
0
        TOOLS_WARN_EXCEPTION( "oox", "oox::ppt::SlideFragmentHandler::EndElement()" );
271
0
    }
272
21.4k
}
273
274
}
275
276
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */