Coverage Report

Created: 2025-12-31 10:39

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
42.5k
: FragmentHandler2( rFilter, rFragmentPath )
58
42.5k
, mpSlidePersistPtr( pPersistPtr )
59
42.5k
, meShapeLocation( eShapeLocation )
60
42.5k
{
61
42.5k
    OUString aVMLPath = getFragmentPathFromFirstTypeFromOfficeDoc(u"vmlDrawing");
62
42.5k
    if (aVMLPath.isEmpty())
63
42.5k
        aVMLPath = getFragmentPathFromFirstTypeFromOfficeDoc(u"legacyDrawing");
64
65
42.5k
    if (!aVMLPath.isEmpty())
66
0
        getFilter().importFragment(
67
0
            new oox::vml::DrawingFragment(getFilter(), aVMLPath, *pPersistPtr->getDrawing()));
68
42.5k
}
69
70
SlideFragmentHandler::~SlideFragmentHandler()
71
42.5k
{
72
42.5k
    try
73
42.5k
    {
74
        // convert and insert all VML shapes (mostly form controls)
75
42.5k
        mpSlidePersistPtr->getDrawing()->convertAndInsert();
76
42.5k
    }
77
42.5k
    catch (const uno::Exception&)
78
42.5k
    {
79
0
        TOOLS_WARN_EXCEPTION("oox", "SlideFragmentHandler dtor: VML shape insertion failed");
80
0
    }
81
42.5k
}
82
83
::oox::core::ContextHandlerRef SlideFragmentHandler::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
84
250k
{
85
250k
    switch( aElementToken )
86
250k
    {
87
9.81k
    case PPT_TOKEN( sldMaster ):        // CT_SlideMaster
88
9.81k
    case PPT_TOKEN( handoutMaster ):    // CT_HandoutMaster
89
13.0k
    case PPT_TOKEN( sld ):              // CT_CommonSlideData
90
13.0k
    {
91
13.0k
        Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
92
13.0k
        Reference< css::beans::XPropertySet > xSet(xSlide, UNO_QUERY);
93
13.0k
        PropertyMap aPropMap;
94
13.0k
        PropertySet aSlideProp( xSlide );
95
96
13.0k
        std::optional<bool> aShowMasterShapes = rAttribs.getBool(XML_showMasterSp);
97
13.0k
        if (aShowMasterShapes.has_value() && !aShowMasterShapes.value())
98
8
            xSet->setPropertyValue(u"IsBackgroundObjectsVisible"_ustr, Any(false));
99
100
13.0k
        aPropMap.setProperty( PROP_Visible, rAttribs.getBool( XML_show, true ));
101
13.0k
        aSlideProp.setProperties( aPropMap );
102
103
13.0k
        return this;
104
9.81k
    }
105
85
    case PPT_TOKEN( notes ):            // CT_NotesSlide
106
85
    {
107
        // Import notesMaster
108
85
        PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
109
85
        OUString aNotesFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( u"notesMaster" );
110
111
85
        std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
112
85
        bool bNotesFragmentPathFound = false;
113
85
        for (auto const& masterPage : rMasterPages)
114
858
        {
115
858
            if( masterPage->getPath() == aNotesFragmentPath )
116
19
            {
117
19
                if( !mpSlidePersistPtr->getMasterPersist() )
118
19
                    mpSlidePersistPtr->setMasterPersist(masterPage);
119
19
                bNotesFragmentPathFound=true;
120
19
                break;
121
19
            }
122
858
        }
123
85
        if( !bNotesFragmentPathFound && !mpSlidePersistPtr->getMasterPersist() )
124
66
        {
125
66
            SlidePersistPtr pMasterPersistPtr = std::make_shared<SlidePersist>( rFilter, true, true, mpSlidePersistPtr->getPage(),
126
66
                                std::make_shared<PPTShape>( Master, u"com.sun.star.drawing.GroupShape"_ustr ), mpSlidePersistPtr->getNotesTextStyle() );
127
66
            pMasterPersistPtr->setPath( aNotesFragmentPath );
128
66
            rFilter.getMasterPages().push_back( pMasterPersistPtr );
129
66
            FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aNotesFragmentPath, pMasterPersistPtr, Master ) );
130
66
            rFilter.importFragment( xMasterFragmentHandler );
131
66
            mpSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
132
66
        }
133
85
        return this;
134
9.81k
    }
135
35
    case PPT_TOKEN( notesMaster ):      // CT_NotesMaster
136
35
        return this;
137
25.1k
    case PPT_TOKEN( cSld ):             // CT_CommonSlideData
138
25.1k
        maSlideName = rAttribs.getStringDefaulted(XML_name);
139
25.1k
        return this;
140
141
25.1k
    case PPT_TOKEN( spTree ):           // CT_GroupShape
142
25.1k
        {
143
25.1k
            return new PPTShapeGroupContext(
144
25.1k
                *this, mpSlidePersistPtr, meShapeLocation, mpSlidePersistPtr->getShapes(),
145
25.1k
                std::make_shared<PPTShape>( meShapeLocation, u"com.sun.star.drawing.GroupShape"_ustr ) );
146
9.81k
        }
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
925
    case PPT_TOKEN( timing ): // CT_SlideTiming
162
925
        return new SlideTimingContext( *this, mpSlidePersistPtr->getTimeNodeList() );
163
981
    case PPT_TOKEN( transition ): // CT_SlideTransition
164
981
        return new SlideTransitionContext( *this, rAttribs, maSlideProperties );
165
150
    case PPT_TOKEN( hf ):
166
150
        return new HeaderFooterContext( *this, rAttribs, mpSlidePersistPtr->getHeaderFooter() );
167
168
    // BackgroundGroup
169
6.57k
    case PPT_TOKEN( bg ):
170
6.57k
        return this;
171
2.23k
    case PPT_TOKEN( bgPr ):             // CT_BackgroundProperties
172
2.23k
        {
173
2.23k
            FillPropertiesPtr pFillPropertiesPtr =std::make_shared<FillProperties>();
174
2.23k
            mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
175
2.23k
            return new BackgroundPropertiesContext( *this, *pFillPropertiesPtr );
176
9.81k
        }
177
0
        break;
178
179
4.34k
    case PPT_TOKEN( bgRef ):            // a:CT_StyleMatrixReference
180
4.34k
        {
181
4.34k
            const FillProperties *pFillProperties = nullptr;
182
4.34k
            if( mpSlidePersistPtr->getTheme() )
183
4.33k
                pFillProperties = mpSlidePersistPtr->getTheme()->getFillStyle( rAttribs.getInteger( XML_idx, -1 ) );
184
4.34k
            FillPropertiesPtr pFillPropertiesPtr =
185
4.34k
                pFillProperties
186
4.34k
                ? std::make_shared<FillProperties>( *pFillProperties )
187
4.34k
                : std::make_shared<FillProperties>();
188
4.34k
            mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
189
4.34k
            ContextHandlerRef ret = new ColorContext(*this, &mpSlidePersistPtr->getBackgroundColor());
190
4.34k
            return ret;
191
9.81k
        }
192
0
        break;
193
194
0
    case A_TOKEN( overrideClrMapping ):
195
9.84k
    case PPT_TOKEN( clrMap ):           // CT_ColorMapping
196
9.84k
        {
197
9.84k
            oox::drawingml::ClrMapPtr pClrMapPtr =
198
9.84k
                ( aElementToken == PPT_TOKEN( clrMap ) || !mpSlidePersistPtr || !mpSlidePersistPtr->getClrMap() )
199
9.84k
                ? std::make_shared<oox::drawingml::ClrMap>()
200
9.84k
                : std::make_shared<oox::drawingml::ClrMap>( *mpSlidePersistPtr->getClrMap() );
201
9.84k
            ContextHandlerRef ret = new oox::drawingml::clrMapContext( *this, rAttribs, *pClrMapPtr );
202
9.84k
            mpSlidePersistPtr->setClrMap( pClrMapPtr );
203
9.84k
            return ret;
204
0
        }
205
0
        break;
206
6.34k
    case PPT_TOKEN( clrMapOvr ):        // CT_ColorMappingOverride
207
16.1k
    case PPT_TOKEN( sldLayoutIdLst ):   // CT_SlideLayoutIdList
208
16.1k
        return this;
209
4.91k
    case PPT_TOKEN( txStyles ):         // CT_SlideMasterTextStyles
210
4.91k
        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
30
    case PPT_TOKEN( cmLst ):
217
30
        break;
218
68
    case PPT_TOKEN( cm ):
219
68
        if (!mpSlidePersistPtr->getCommentsList().cmLst.empty() && !getCharVector().empty())
220
38
        {
221
            // set comment text for earlier comment
222
38
            mpSlidePersistPtr->getCommentsList().cmLst.back().setText( getCharVector().back() );
223
38
        }
224
        // insert a new comment in vector commentsList
225
68
        mpSlidePersistPtr->getCommentsList().cmLst.emplace_back();
226
68
        mpSlidePersistPtr->getCommentsList().cmLst.back().setAuthorId(rAttribs.getStringDefaulted(XML_authorId));
227
68
        mpSlidePersistPtr->getCommentsList().cmLst.back().setdt(rAttribs.getStringDefaulted(XML_dt));
228
68
        mpSlidePersistPtr->getCommentsList().cmLst.back().setidx(rAttribs.getStringDefaulted(XML_idx));
229
68
        break;
230
231
68
    case PPT_TOKEN( pos ):
232
68
        mpSlidePersistPtr->getCommentsList().cmLst.back().setPoint(
233
68
            rAttribs.getStringDefaulted(XML_x),
234
68
            rAttribs.getStringDefaulted(XML_y));
235
68
        break;
236
237
16
    case PPT_TOKEN( cmAuthor ):
238
16
        CommentAuthor _author;
239
16
        _author.clrIdx = rAttribs.getStringDefaulted(XML_clrIdx);
240
16
        _author.id = rAttribs.getStringDefaulted(XML_id);
241
16
        _author.initials = rAttribs.getStringDefaulted(XML_initials);
242
16
        _author.lastIdx = rAttribs.getStringDefaulted(XML_lastIdx);
243
16
        _author.name = rAttribs.getStringDefaulted(XML_name);
244
16
        mpSlidePersistPtr->getCommentAuthors().addAuthor(_author);
245
16
        break;
246
250k
    }
247
248
141k
    return this;
249
250k
}
250
void SlideFragmentHandler::onCharacters( const OUString& rChars)
251
68
{
252
68
    maCharVector.push_back(rChars);
253
68
}
254
void SlideFragmentHandler::finalizeImport()
255
25.1k
{
256
25.1k
    try
257
25.1k
    {
258
25.1k
        Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
259
25.1k
        PropertySet aSlideProp( xSlide );
260
25.1k
        aSlideProp.setProperties( maSlideProperties );
261
25.1k
        if ( !maSlideName.isEmpty() )
262
11.9k
        {
263
11.9k
            Reference< XNamed > xNamed( xSlide, UNO_QUERY );
264
11.9k
            if( xNamed.is() )
265
11.9k
                xNamed->setName( maSlideName );
266
11.9k
        }
267
25.1k
    }
268
25.1k
    catch( uno::Exception& )
269
25.1k
    {
270
0
        TOOLS_WARN_EXCEPTION( "oox", "oox::ppt::SlideFragmentHandler::EndElement()" );
271
0
    }
272
25.1k
}
273
274
}
275
276
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */