Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/draw/ximpstyl.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 "ximpstyl.hxx"
21
#include <xmloff/maptype.hxx>
22
#include <xmloff/XMLDrawingPageStyleContext.hxx>
23
#include <xmloff/XMLShapeStyleContext.hxx>
24
#include <xmloff/xmlnamespace.hxx>
25
#include <xmloff/xmlprmap.hxx>
26
#include <xmloff/xmltoken.hxx>
27
#include <xmloff/xmluconv.hxx>
28
#include "ximpnote.hxx"
29
#include <xmlsdtypes.hxx>
30
#include <tools/gen.hxx>
31
#include <tools/debug.hxx>
32
#include <sal/log.hxx>
33
#include <comphelper/diagnose_ex.hxx>
34
#include <com/sun/star/frame/XModel.hpp>
35
#include <com/sun/star/style/XStyle.hpp>
36
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
37
#include <com/sun/star/presentation/XPresentationPage.hpp>
38
#include <com/sun/star/drawing/FillStyle.hpp>
39
#include <com/sun/star/drawing/XDrawPages.hpp>
40
#include <com/sun/star/container/XNamed.hpp>
41
#include <com/sun/star/beans/XPropertySet.hpp>
42
#include <com/sun/star/beans/XPropertyState.hpp>
43
#include <com/sun/star/presentation/XHandoutMasterSupplier.hpp>
44
#include <comphelper/namecontainer.hxx>
45
#include <xmloff/autolayout.hxx>
46
#include <xmloff/xmlprcon.hxx>
47
#include <xmloff/families.hxx>
48
#include <com/sun/star/container/XNameContainer.hpp>
49
#include <svl/numformat.hxx>
50
#include "layerimp.hxx"
51
#include <xmloff/XMLGraphicsDefaultStyle.hxx>
52
#include <XMLNumberStylesImport.hxx>
53
#include <XMLThemeContext.hxx>
54
#include <comphelper/configuration.hxx>
55
#include <xmloff/xmlerror.hxx>
56
#include <xmloff/table/XMLTableImport.hxx>
57
58
using namespace ::com::sun::star;
59
using namespace ::com::sun::star::uno;
60
using namespace ::com::sun::star::xml::sax;
61
using namespace ::xmloff::token;
62
63
namespace {
64
65
class SdXMLDrawingPagePropertySetContext : public SvXMLPropertySetContext
66
{
67
public:
68
69
    SdXMLDrawingPagePropertySetContext( SvXMLImport& rImport, sal_Int32 nElement,
70
                 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
71
                 ::std::vector< XMLPropertyState > &rProps,
72
                 SvXMLImportPropertyMapper* pMap );
73
74
    using SvXMLPropertySetContext::createFastChildContext;
75
    virtual css::uno::Reference< css::xml::sax::XFastContextHandler > createFastChildContext(
76
        sal_Int32 nElement,
77
        const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
78
        ::std::vector< XMLPropertyState > &rProperties,
79
        const XMLPropertyState& rProp ) override;
80
};
81
} // end anonymous namespace
82
83
SdXMLDrawingPagePropertySetContext::SdXMLDrawingPagePropertySetContext(
84
                 SvXMLImport& rImport, sal_Int32 nElement,
85
                 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList,
86
                 ::std::vector< XMLPropertyState > &rProps,
87
                 SvXMLImportPropertyMapper* pMap ) :
88
0
    SvXMLPropertySetContext( rImport, nElement, xAttrList,
89
0
                             XML_TYPE_PROP_DRAWING_PAGE, rProps, pMap )
90
0
{
91
0
}
92
93
css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLDrawingPagePropertySetContext::createFastChildContext(
94
    sal_Int32 nElement,
95
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
96
    ::std::vector< XMLPropertyState > &rProperties,
97
    const XMLPropertyState& rProp )
98
0
{
99
0
    switch( mpMapper->getPropertySetMapper()->GetEntryContextId( rProp.mnIndex ) )
100
0
    {
101
0
    case CTF_PAGE_SOUND_URL:
102
0
    {
103
0
        for (auto &aIter : sax_fastparser::castToFastAttributeList(xAttrList))
104
0
        {
105
0
            if( aIter.getToken() == XML_ELEMENT(XLINK, XML_HREF) )
106
0
            {
107
0
                uno::Any aAny( GetImport().GetAbsoluteReference( aIter.toString() ) );
108
0
                XMLPropertyState aPropState( rProp.mnIndex, aAny );
109
0
                rProperties.push_back( aPropState );
110
0
            }
111
0
            else
112
0
                XMLOFF_WARN_UNKNOWN("xmloff", aIter);
113
0
        }
114
0
        break;
115
0
    }
116
0
    }
117
118
0
    return SvXMLPropertySetContext::createFastChildContext( nElement,
119
0
                                                            xAttrList,
120
0
                                                            rProperties, rProp );
121
0
}
122
123
namespace {
124
125
126
class SdXMLDrawingPageStyleContext : public XMLDrawingPageStyleContext
127
{
128
public:
129
130
    SdXMLDrawingPageStyleContext(
131
        SvXMLImport& rImport,
132
        SvXMLStylesContext& rStyles);
133
134
    virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
135
        sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
136
137
    virtual void Finish( bool bOverwrite ) override;
138
};
139
140
const sal_uInt16 MAX_SPECIAL_DRAW_STYLES = 7;
141
ContextID_Index_Pair const g_ContextIDs[MAX_SPECIAL_DRAW_STYLES+1] =
142
{
143
    { CTF_DASHNAME,         -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE },
144
    { CTF_LINESTARTNAME,    -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE },
145
    { CTF_LINEENDNAME,      -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE },
146
    { CTF_FILLGRADIENTNAME, -1, drawing::FillStyle::FillStyle_GRADIENT},
147
    { CTF_FILLTRANSNAME,    -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE },
148
    { CTF_FILLHATCHNAME,    -1, drawing::FillStyle::FillStyle_HATCH },
149
    { CTF_FILLBITMAPNAME,   -1, drawing::FillStyle::FillStyle_BITMAP },
150
    { -1, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }
151
};
152
XmlStyleFamily const g_Families[MAX_SPECIAL_DRAW_STYLES] =
153
{
154
    XmlStyleFamily::SD_STROKE_DASH_ID,
155
    XmlStyleFamily::SD_MARKER_ID,
156
    XmlStyleFamily::SD_MARKER_ID,
157
    XmlStyleFamily::SD_GRADIENT_ID,
158
    XmlStyleFamily::SD_GRADIENT_ID,
159
    XmlStyleFamily::SD_HATCH_ID,
160
    XmlStyleFamily::SD_FILL_IMAGE_ID
161
};
162
163
}
164
165
XMLDrawingPageStyleContext::XMLDrawingPageStyleContext(
166
    SvXMLImport& rImport,
167
    SvXMLStylesContext& rStyles,
168
    ContextID_Index_Pair const pContextIDs[],
169
    XmlStyleFamily const pFamilies[])
170
505
    : XMLPropStyleContext(rImport, rStyles, XmlStyleFamily::SD_DRAWINGPAGE_ID)
171
505
    , m_pFamilies(pFamilies)
172
505
{
173
505
    size_t size(1); // for the -1 entry
174
2.52k
    for (ContextID_Index_Pair const* pTemp(pContextIDs); pTemp->nContextID != -1; ++size, ++pTemp);
175
505
    m_pContextIDs.reset(new ContextID_Index_Pair[size]);
176
505
    std::copy(pContextIDs, pContextIDs + size, m_pContextIDs.get());
177
505
}
178
179
SdXMLDrawingPageStyleContext::SdXMLDrawingPageStyleContext(
180
    SvXMLImport& rImport,
181
    SvXMLStylesContext& rStyles)
182
0
    : XMLDrawingPageStyleContext(rImport, rStyles, g_ContextIDs, g_Families)
183
0
{
184
0
}
185
186
css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLDrawingPageStyleContext::createFastChildContext(
187
    sal_Int32 nElement,
188
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
189
0
{
190
0
    if( nElement == XML_ELEMENT(STYLE, XML_DRAWING_PAGE_PROPERTIES) )
191
0
    {
192
0
        SvXMLImportPropertyMapper* pImpPrMap =
193
0
            GetStyles()->GetImportPropertyMapper( GetFamily() );
194
0
        if( pImpPrMap )
195
0
            return new SdXMLDrawingPagePropertySetContext( GetImport(), nElement,
196
0
                                                    xAttrList,
197
0
                                                    GetProperties(),
198
0
                                                    pImpPrMap );
199
0
    }
200
201
0
    return XMLPropStyleContext::createFastChildContext( nElement, xAttrList );
202
0
}
203
204
void SdXMLDrawingPageStyleContext::Finish( bool bOverwrite )
205
0
{
206
0
    XMLPropStyleContext::Finish( bOverwrite );
207
208
0
    ::std::vector< XMLPropertyState > &rProperties = GetProperties();
209
210
0
    const rtl::Reference< XMLPropertySetMapper >& rImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper();
211
212
0
    for(auto& property : rProperties)
213
0
    {
214
0
        if( property.mnIndex == -1 )
215
0
            continue;
216
217
0
        sal_Int16 nContextID = rImpPrMap->GetEntryContextId(property.mnIndex);
218
0
        switch( nContextID )
219
0
        {
220
0
            case CTF_DATE_TIME_FORMAT:
221
0
            {
222
0
                OUString sStyleName;
223
0
                property.maValue >>= sStyleName;
224
225
0
                sal_Int32 nStyle = 0;
226
227
0
                const SdXMLNumberFormatImportContext* pSdNumStyle =
228
0
                    dynamic_cast< const SdXMLNumberFormatImportContext*> (
229
0
                        GetStyles()->FindStyleChildContext( XmlStyleFamily::DATA_STYLE, sStyleName, true ) );
230
231
0
                if( pSdNumStyle )
232
0
                    nStyle = pSdNumStyle->GetDrawKey();
233
234
0
                property.maValue <<= nStyle;
235
0
            }
236
0
            break;
237
0
        }
238
0
    }
239
240
0
}
241
242
243
// #i35918#
244
void XMLDrawingPageStyleContext::FillPropertySet(
245
    const Reference< beans::XPropertySet > & rPropSet )
246
5.03k
{
247
5.03k
    SvXMLImportPropertyMapper* pImpPrMap =
248
5.03k
        GetStyles()->GetImportPropertyMapper( GetFamily() );
249
5.03k
    assert( pImpPrMap );
250
5.03k
    pImpPrMap->FillPropertySet(GetProperties(), rPropSet, m_pContextIDs.get());
251
252
5.03k
    Reference< beans::XPropertySetInfo > xInfo;
253
25.1k
    for (size_t i=0; m_pContextIDs[i].nContextID != -1; ++i)
254
20.1k
    {
255
20.1k
        sal_Int32 nIndex = m_pContextIDs[i].nIndex;
256
20.1k
        if( nIndex != -1 )
257
0
        {
258
0
            struct XMLPropertyState& rState = GetProperties()[nIndex];
259
0
            OUString sStyleName;
260
0
            rState.maValue >>= sStyleName;
261
262
0
            if (::xmloff::IsIgnoreFillStyleNamedItem(rPropSet, m_pContextIDs[i].nExpectedFillStyle))
263
0
            {
264
0
                SAL_INFO("xmloff.style", "XMLDrawingPageStyleContext: dropping fill named item: " << sStyleName);
265
0
                break; // ignore it, it's not used
266
0
            }
267
268
0
            sStyleName = GetImport().GetStyleDisplayName( m_pFamilies[i],
269
0
                                                          sStyleName );
270
            // get property set mapper
271
0
            rtl::Reference<XMLPropertySetMapper> rPropMapper =
272
0
                                        pImpPrMap->getPropertySetMapper();
273
274
            // set property
275
0
            const OUString& rPropertyName =
276
0
                    rPropMapper->GetEntryAPIName(rState.mnIndex);
277
0
            if( !xInfo.is() )
278
0
                xInfo = rPropSet->getPropertySetInfo();
279
0
            if ( xInfo->hasPropertyByName( rPropertyName ) )
280
0
            {
281
0
                rPropSet->setPropertyValue( rPropertyName, Any( sStyleName ) );
282
0
            }
283
0
        }
284
20.1k
    }
285
5.03k
}
286
287
288
SdXMLPageMasterStyleContext::SdXMLPageMasterStyleContext(
289
    SdXMLImport& rImport,
290
    sal_Int32 /*nElement*/,
291
    const uno::Reference< xml::sax::XFastAttributeList>& xAttrList)
292
0
:   SvXMLStyleContext(rImport, XmlStyleFamily::SD_PAGEMASTERSTYLECONTEXT_ID),
293
0
    mnBorderBottom( 0 ),
294
0
    mnBorderLeft( 0 ),
295
0
    mnBorderRight( 0 ),
296
0
    mnBorderTop( 0 ),
297
0
    mnWidth( 0 ),
298
0
    mnHeight( 0 ),
299
0
    meOrientation(GetSdImport().IsDraw() ? view::PaperOrientation_PORTRAIT : view::PaperOrientation_LANDSCAPE)
300
0
{
301
    // set family to something special at SvXMLStyleContext
302
    // for differences in search-methods
303
304
0
    for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
305
0
    {
306
0
        switch(aIter.getToken())
307
0
        {
308
0
            case XML_ELEMENT(FO, XML_MARGIN_TOP):
309
0
            case XML_ELEMENT(FO_COMPAT, XML_MARGIN_TOP):
310
0
            {
311
0
                GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
312
0
                        mnBorderTop, aIter.toView(), 0);
313
0
                break;
314
0
            }
315
0
            case XML_ELEMENT(FO, XML_MARGIN_BOTTOM):
316
0
            case XML_ELEMENT(FO_COMPAT, XML_MARGIN_BOTTOM):
317
0
            {
318
0
                GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
319
0
                        mnBorderBottom, aIter.toView(), 0);
320
0
                break;
321
0
            }
322
0
            case XML_ELEMENT(FO, XML_MARGIN_LEFT):
323
0
            case XML_ELEMENT(FO_COMPAT, XML_MARGIN_LEFT):
324
0
            {
325
0
                GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
326
0
                        mnBorderLeft, aIter.toView(), 0);
327
0
                break;
328
0
            }
329
0
            case XML_ELEMENT(FO, XML_MARGIN_RIGHT):
330
0
            case XML_ELEMENT(FO_COMPAT, XML_MARGIN_RIGHT):
331
0
            {
332
0
                GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
333
0
                        mnBorderRight, aIter.toView(), 0);
334
0
                break;
335
0
            }
336
0
            case XML_ELEMENT(FO, XML_PAGE_WIDTH):
337
0
            case XML_ELEMENT(FO_COMPAT, XML_PAGE_WIDTH):
338
0
            {
339
0
                GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
340
0
                        mnWidth, aIter.toView());
341
0
                break;
342
0
            }
343
0
            case XML_ELEMENT(FO, XML_PAGE_HEIGHT):
344
0
            case XML_ELEMENT(FO_COMPAT, XML_PAGE_HEIGHT):
345
0
            {
346
0
                GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
347
0
                        mnHeight, aIter.toView());
348
0
                break;
349
0
            }
350
0
            case XML_ELEMENT(STYLE, XML_PRINT_ORIENTATION):
351
0
            {
352
0
                if( IsXMLToken( aIter, XML_PORTRAIT ) )
353
0
                    meOrientation = view::PaperOrientation_PORTRAIT;
354
0
                else
355
0
                    meOrientation = view::PaperOrientation_LANDSCAPE;
356
0
                break;
357
0
            }
358
0
            default:
359
0
                XMLOFF_WARN_UNKNOWN("xmloff", aIter);
360
0
        }
361
0
    }
362
    // Set size to useful default value, same as in SdDrawDocument::CreateFirstPages
363
    // except we cannot call SvxPaperInfo::GetDefaultPaperSize from here.
364
0
    if (mnWidth == 0)
365
0
        mnWidth = 21000;
366
0
    if (mnHeight == 0)
367
0
        mnHeight = 29700;
368
0
}
369
370
SdXMLPageMasterStyleContext::~SdXMLPageMasterStyleContext()
371
0
{
372
0
}
373
374
375
SdXMLPageMasterContext::SdXMLPageMasterContext(
376
    SdXMLImport& rImport,
377
    sal_Int32 /*nElement*/,
378
    const uno::Reference< xml::sax::XFastAttributeList>& /*xAttrList*/)
379
0
:   SvXMLStyleContext(rImport, XmlStyleFamily::SD_PAGEMASTERCONTEXT_ID)
380
0
{
381
    // set family to something special at SvXMLStyleContext
382
    // for differences in search-methods
383
384
0
}
385
386
css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLPageMasterContext::createFastChildContext(
387
    sal_Int32 nElement,
388
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
389
0
{
390
0
    if(nElement == XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_PROPERTIES))
391
0
    {
392
0
        DBG_ASSERT(!mxPageMasterStyle.is(), "PageMasterStyle is set, there seem to be two of them (!)");
393
0
        mxPageMasterStyle.set(new SdXMLPageMasterStyleContext(GetSdImport(), nElement, xAttrList));
394
0
        return mxPageMasterStyle;
395
0
    }
396
0
    else
397
0
        XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
398
399
0
    return nullptr;
400
0
}
401
402
SdXMLPresentationPageLayoutContext::SdXMLPresentationPageLayoutContext(
403
    SdXMLImport& rImport,
404
    sal_Int32 /*nElement*/,
405
    const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/)
406
0
:   SvXMLStyleContext(rImport, XmlStyleFamily::SD_PRESENTATIONPAGELAYOUT_ID),
407
0
    mnTypeId( AUTOLAYOUT_NONE )
408
0
{
409
    // set family to something special at SvXMLStyleContext
410
    // for differences in search-methods
411
0
}
412
413
css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLPresentationPageLayoutContext::createFastChildContext(
414
    sal_Int32 nElement,
415
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
416
0
{
417
0
    SvXMLImportContextRef xContext;
418
419
0
    if(nElement == XML_ELEMENT(PRESENTATION, XML_PLACEHOLDER))
420
0
    {
421
0
        const rtl::Reference< SdXMLPresentationPlaceholderContext > xLclContext{
422
0
            new SdXMLPresentationPlaceholderContext(GetSdImport(), nElement, xAttrList)};
423
        // presentation:placeholder inside style:presentation-page-layout context
424
0
        xContext = xLclContext.get();
425
426
        // remember SdXMLPresentationPlaceholderContext for later evaluation
427
0
        maList.push_back(xLclContext);
428
0
    }
429
0
    else
430
0
        XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
431
432
0
    return xContext;
433
0
}
434
435
void SdXMLPresentationPageLayoutContext::endFastElement(sal_Int32 )
436
0
{
437
    // build presentation page layout type here
438
    // calc mnTpeId due to content of maList
439
    // at the moment only use number of types used there
440
0
    if( maList.empty() )
441
0
        return;
442
443
0
    SdXMLPresentationPlaceholderContext* pObj0 = maList[ 0 ].get();
444
0
    if( pObj0->GetName() == "handout" )
445
0
    {
446
0
        switch( maList.size() )
447
0
        {
448
0
        case 1:
449
0
            mnTypeId = AUTOLAYOUT_HANDOUT1;
450
0
            break;
451
0
        case 2:
452
0
            mnTypeId = AUTOLAYOUT_HANDOUT2;
453
0
            break;
454
0
        case 3:
455
0
            mnTypeId = AUTOLAYOUT_HANDOUT3;
456
0
            break;
457
0
        case 4:
458
0
            mnTypeId = AUTOLAYOUT_HANDOUT4;
459
0
            break;
460
0
        case 9:
461
0
            mnTypeId = AUTOLAYOUT_HANDOUT9;
462
0
            break;
463
0
        default:
464
0
            mnTypeId = AUTOLAYOUT_HANDOUT6;
465
0
        }
466
0
    }
467
0
    else
468
0
    {
469
0
        switch( maList.size() )
470
0
        {
471
0
            case 1:
472
0
            {
473
0
                if( pObj0->GetName() == "title" )
474
0
                {
475
0
                    mnTypeId = AUTOLAYOUT_TITLE_ONLY;
476
0
                }
477
0
                else
478
0
                {
479
0
                    mnTypeId = AUTOLAYOUT_ONLY_TEXT;
480
0
                }
481
0
                break;
482
0
            }
483
0
            case 2:
484
0
            {
485
0
                SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get();
486
487
0
                if( pObj1->GetName() == "subtitle" )
488
0
                {
489
0
                    mnTypeId = AUTOLAYOUT_TITLE;
490
0
                }
491
0
                else if( pObj1->GetName() == "outline" )
492
0
                {
493
0
                    mnTypeId = AUTOLAYOUT_TITLE_CONTENT;
494
0
                }
495
0
                else if( pObj1->GetName() == "chart" )
496
0
                {
497
0
                    mnTypeId = AUTOLAYOUT_CHART;
498
0
                }
499
0
                else if( pObj1->GetName() == "table" )
500
0
                {
501
0
                    mnTypeId = AUTOLAYOUT_TAB;
502
0
                }
503
0
                else if( pObj1->GetName() == "object" )
504
0
                {
505
0
                    mnTypeId = AUTOLAYOUT_OBJ;
506
0
                }
507
0
                else if( pObj1->GetName() == "vertical_outline" )
508
0
                {
509
0
                    if( pObj0->GetName() == "vertical_title" )
510
0
                    {
511
0
                        mnTypeId = AUTOLAYOUT_VTITLE_VCONTENT;
512
0
                    }
513
0
                    else
514
0
                    {
515
0
                        mnTypeId = AUTOLAYOUT_TITLE_VCONTENT;
516
0
                    }
517
0
                }
518
0
                else
519
0
                {
520
0
                    mnTypeId = AUTOLAYOUT_NOTES;
521
0
                }
522
0
                break;
523
0
            }
524
0
            case 3:
525
0
            {
526
0
                SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get();
527
0
                SdXMLPresentationPlaceholderContext* pObj2 = maList[ 2 ].get();
528
529
0
                if( pObj1->GetName() == "outline" )
530
0
                {
531
0
                    if( pObj2->GetName() == "outline" )
532
0
                    {
533
0
                        mnTypeId = AUTOLAYOUT_TITLE_2CONTENT;
534
0
                    }
535
0
                    else if( pObj2->GetName() == "chart" )
536
0
                    {
537
0
                        mnTypeId = AUTOLAYOUT_TEXTCHART;
538
0
                    }
539
0
                    else if( pObj2->GetName() == "graphic" )
540
0
                    {
541
0
                        mnTypeId = AUTOLAYOUT_TEXTCLIP;
542
0
                    }
543
0
                    else
544
0
                    {
545
0
                        if(pObj1->GetX() < pObj2->GetX())
546
0
                        {
547
0
                            mnTypeId = AUTOLAYOUT_TEXTOBJ; // outline left, object right
548
0
                        }
549
0
                        else
550
0
                        {
551
0
                            mnTypeId = AUTOLAYOUT_TEXTOVEROBJ; // outline top, object right
552
0
                        }
553
0
                    }
554
0
                }
555
0
                else if( pObj1->GetName() == "chart" )
556
0
                {
557
0
                    mnTypeId = AUTOLAYOUT_CHARTTEXT;
558
0
                }
559
0
                else if( pObj1->GetName() == "graphic" )
560
0
                {
561
0
                    if( pObj2->GetName() == "vertical_outline" )
562
0
                    {
563
0
                        mnTypeId = AUTOLAYOUT_TITLE_2VTEXT;
564
0
                    }
565
0
                    else
566
0
                    {
567
0
                        mnTypeId = AUTOLAYOUT_CLIPTEXT;
568
0
                    }
569
0
                }
570
0
                else if( pObj1->GetName() == "vertical_outline" )
571
0
                {
572
0
                    mnTypeId = AUTOLAYOUT_VTITLE_VCONTENT_OVER_VCONTENT;
573
0
                }
574
0
                else
575
0
                {
576
0
                    if(pObj1->GetX() < pObj2->GetX())
577
0
                    {
578
0
                        mnTypeId = AUTOLAYOUT_OBJTEXT; // left, right
579
0
                    }
580
0
                    else
581
0
                    {
582
0
                        mnTypeId = AUTOLAYOUT_TITLE_CONTENT_OVER_CONTENT; // top, bottom
583
0
                    }
584
0
                }
585
0
                break;
586
0
            }
587
0
            case 4:
588
0
            {
589
0
                SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get();
590
0
                SdXMLPresentationPlaceholderContext* pObj2 = maList[ 2 ].get();
591
592
0
                if( pObj1->GetName() == "object" )
593
0
                {
594
0
                    if(pObj1->GetX() < pObj2->GetX())
595
0
                    {
596
0
                        mnTypeId = AUTOLAYOUT_TITLE_2CONTENT_OVER_CONTENT;
597
0
                    }
598
0
                    else
599
0
                    {
600
0
                        mnTypeId = AUTOLAYOUT_TITLE_2CONTENT_CONTENT;
601
0
                    }
602
0
                }
603
0
                else
604
0
                {
605
0
                    mnTypeId = AUTOLAYOUT_TITLE_CONTENT_2CONTENT;
606
0
                }
607
0
                break;
608
0
            }
609
0
            case 5:
610
0
            {
611
0
                SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get();
612
613
0
                if( pObj1->GetName() == "object" )
614
0
                {
615
0
                    mnTypeId = AUTOLAYOUT_TITLE_4CONTENT;
616
0
                }
617
0
                else
618
0
                {
619
0
                    mnTypeId = AUTOLAYOUT_4CLIPART;
620
0
                }
621
0
                break;
622
623
0
            }
624
0
            case 7:
625
0
            {
626
0
                mnTypeId = AUTOLAYOUT_TITLE_6CONTENT; // tdf#141978: Apply 6content layout
627
0
                break;
628
0
            }
629
0
            default:
630
0
            {
631
0
                mnTypeId = AUTOLAYOUT_NONE;
632
0
                break;
633
0
            }
634
0
        }
635
0
    }
636
637
    // release remembered contexts, they are no longer needed
638
0
    maList.clear();
639
0
}
640
641
SdXMLPresentationPlaceholderContext::SdXMLPresentationPlaceholderContext(
642
    SdXMLImport& rImport,
643
    sal_Int32 /*nElement*/,
644
    const uno::Reference< xml::sax::XFastAttributeList>& xAttrList)
645
0
:   SvXMLImportContext( rImport ),
646
0
    mnX(0)
647
0
{
648
0
    for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
649
0
    {
650
0
        switch(aIter.getToken())
651
0
        {
652
0
            case XML_ELEMENT(PRESENTATION, XML_OBJECT):
653
0
            {
654
0
                msName = aIter.toString();
655
0
                break;
656
0
            }
657
0
            case XML_ELEMENT(SVG, XML_X):
658
0
            case XML_ELEMENT(SVG_COMPAT, XML_X):
659
0
            {
660
0
                GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
661
0
                        mnX, aIter.toView());
662
0
                break;
663
0
            }
664
0
            case XML_ELEMENT(SVG, XML_Y):
665
0
            case XML_ELEMENT(SVG_COMPAT, XML_Y):
666
0
            {
667
0
                break;
668
0
            }
669
0
            case XML_ELEMENT(SVG, XML_WIDTH):
670
0
            case XML_ELEMENT(SVG_COMPAT, XML_WIDTH):
671
0
            {
672
0
                break;
673
0
            }
674
0
            case XML_ELEMENT(SVG, XML_HEIGHT):
675
0
            case XML_ELEMENT(SVG_COMPAT, XML_HEIGHT):
676
0
            {
677
0
                break;
678
0
            }
679
0
            default:
680
0
                XMLOFF_WARN_UNKNOWN("xmloff", aIter);
681
0
        }
682
0
    }
683
0
}
684
685
SdXMLPresentationPlaceholderContext::~SdXMLPresentationPlaceholderContext()
686
0
{
687
0
}
688
689
690
// Only called for handout master
691
SdXMLMasterPageContext::SdXMLMasterPageContext(
692
    SdXMLImport& rImport,
693
    sal_Int32 nElement,
694
    const uno::Reference< xml::sax::XFastAttributeList>& xAttrList,
695
    uno::Reference< drawing::XShapes > const & rShapes)
696
0
:   SdXMLGenericPageContext( rImport, xAttrList, rShapes )
697
0
{
698
0
    assert((nElement & TOKEN_MASK) == XML_HANDOUT_MASTER); (void)nElement;
699
0
    OUString sStyleName, sPageMasterName;
700
701
0
    for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
702
0
    {
703
0
        const OUString sValue = aIter.toString();
704
0
        switch(aIter.getToken())
705
0
        {
706
0
            case XML_ELEMENT(STYLE, XML_NAME):
707
0
            {
708
0
                msName = sValue;
709
0
                break;
710
0
            }
711
0
            case XML_ELEMENT(STYLE, XML_DISPLAY_NAME):
712
0
            {
713
0
                msDisplayName = sValue;
714
0
                break;
715
0
            }
716
0
            case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_NAME):
717
0
            {
718
0
                sPageMasterName = sValue;
719
0
                break;
720
0
            }
721
0
            case XML_ELEMENT(DRAW, XML_STYLE_NAME):
722
0
            {
723
0
                sStyleName = sValue;
724
0
                break;
725
0
            }
726
0
            case XML_ELEMENT(PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME):
727
0
            {
728
0
                maPageLayoutName = sValue;
729
0
                break;
730
0
            }
731
0
            case XML_ELEMENT(PRESENTATION, XML_USE_HEADER_NAME):
732
0
            {
733
0
                maUseHeaderDeclName =  sValue;
734
0
                break;
735
0
            }
736
0
            case XML_ELEMENT(PRESENTATION, XML_USE_FOOTER_NAME):
737
0
            {
738
0
                maUseFooterDeclName =  sValue;
739
0
                break;
740
0
            }
741
0
            case XML_ELEMENT(PRESENTATION, XML_USE_DATE_TIME_NAME):
742
0
            {
743
0
                maUseDateTimeDeclName =  sValue;
744
0
                break;
745
0
            }
746
0
            default:
747
0
                XMLOFF_WARN_UNKNOWN("xmloff", aIter);
748
0
        }
749
0
    }
750
751
0
    if( msDisplayName.isEmpty() )
752
0
        msDisplayName = msName;
753
0
    else if( msDisplayName != msName )
754
0
        GetImport().AddStyleDisplayName( XmlStyleFamily::MASTER_PAGE, msName, msDisplayName );
755
756
0
    GetImport().GetShapeImport()->startPage( GetLocalShapesContext() );
757
758
    // set page-master?
759
0
    if(!sPageMasterName.isEmpty())
760
0
    {
761
0
        SetPageMaster( sPageMasterName );
762
0
    }
763
764
0
    SetStyle( sStyleName );
765
766
0
    SetLayout();
767
768
0
    DeleteAllShapes();
769
0
}
770
771
// only called for normal master pages
772
SdXMLMasterPageContext::SdXMLMasterPageContext(
773
    SdXMLImport& rImport,
774
    sal_Int32 nElement,
775
    const uno::Reference< xml::sax::XFastAttributeList>& xAttrList,
776
    uno::Reference< drawing::XDrawPages2 > const & xMasterPages)
777
0
:   SdXMLGenericPageContext( rImport, xAttrList )
778
0
{
779
0
    assert((nElement & TOKEN_MASK) != XML_HANDOUT_MASTER); (void)nElement;
780
0
    OUString sStyleName, sPageMasterName;
781
782
0
    for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
783
0
    {
784
0
        const OUString sValue = aIter.toString();
785
0
        switch(aIter.getToken())
786
0
        {
787
0
            case XML_ELEMENT(STYLE, XML_NAME):
788
0
            {
789
0
                msName = sValue;
790
0
                break;
791
0
            }
792
0
            case XML_ELEMENT(STYLE, XML_DISPLAY_NAME):
793
0
            {
794
0
                msDisplayName = sValue;
795
0
                break;
796
0
            }
797
0
            case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_NAME):
798
0
            {
799
0
                sPageMasterName = sValue;
800
0
                break;
801
0
            }
802
0
            case XML_ELEMENT(DRAW, XML_STYLE_NAME):
803
0
            {
804
0
                sStyleName = sValue;
805
0
                break;
806
0
            }
807
0
            case XML_ELEMENT(PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME):
808
0
            {
809
0
                maPageLayoutName = sValue;
810
0
                break;
811
0
            }
812
0
            case XML_ELEMENT(PRESENTATION, XML_USE_HEADER_NAME):
813
0
            {
814
0
                maUseHeaderDeclName =  sValue;
815
0
                break;
816
0
            }
817
0
            case XML_ELEMENT(PRESENTATION, XML_USE_FOOTER_NAME):
818
0
            {
819
0
                maUseFooterDeclName =  sValue;
820
0
                break;
821
0
            }
822
0
            case XML_ELEMENT(PRESENTATION, XML_USE_DATE_TIME_NAME):
823
0
            {
824
0
                maUseDateTimeDeclName =  sValue;
825
0
                break;
826
0
            }
827
0
            default:
828
0
                XMLOFF_WARN_UNKNOWN("xmloff", aIter);
829
0
        }
830
0
    }
831
832
0
    if( msDisplayName.isEmpty() )
833
0
        msDisplayName = msName;
834
0
    else if( msDisplayName != msName )
835
0
        GetImport().AddStyleDisplayName( XmlStyleFamily::MASTER_PAGE, msName, msDisplayName );
836
837
0
    sal_Int32 nNewMasterPageCount = GetSdImport().GetNewMasterPageCount();
838
0
    sal_Int32 nMasterPageCount = xMasterPages->getCount();
839
0
    uno::Reference< drawing::XDrawPage > xNewMasterPage;
840
0
    if (nNewMasterPageCount + 1 > nMasterPageCount)
841
0
    {
842
        // new page, create and insert
843
0
        xNewMasterPage = xMasterPages->insertNamedNewByIndex(nMasterPageCount, msDisplayName);
844
0
        SetShapes(xNewMasterPage);
845
0
    }
846
0
    else
847
0
    {
848
        // existing page, use it
849
0
        xMasterPages->getByIndex(nNewMasterPageCount) >>= xNewMasterPage;
850
0
        SetShapes(xNewMasterPage);
851
0
        if(!msDisplayName.isEmpty())
852
0
        {
853
0
            uno::Reference < container::XNamed > xNamed(xNewMasterPage, uno::UNO_QUERY);
854
0
            if(xNamed.is())
855
0
                xNamed->setName(msDisplayName);
856
0
        }
857
0
    }
858
    // increment global import page counter
859
0
    GetSdImport().IncrementNewMasterPageCount();
860
861
0
    GetImport().GetShapeImport()->startPage( GetLocalShapesContext() );
862
863
    // set page-master?
864
0
    if(!sPageMasterName.isEmpty())
865
0
    {
866
0
        SetPageMaster( sPageMasterName );
867
0
    }
868
869
0
    SetStyle( sStyleName );
870
871
0
    SetLayout();
872
873
0
    DeleteAllShapes();
874
0
}
875
876
SdXMLMasterPageContext::~SdXMLMasterPageContext()
877
0
{
878
0
}
879
880
void SdXMLMasterPageContext::endFastElement(sal_Int32 nElement)
881
0
{
882
    // set styles on master-page
883
0
    if(!msName.isEmpty() && GetSdImport().GetShapeImport()->GetStylesContext())
884
0
    {
885
0
        SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetStylesContext();
886
0
        if (SdXMLStylesContext* pSdContext = dynamic_cast<SdXMLStylesContext*>(pContext))
887
0
            pSdContext->SetMasterPageStyles(*this);
888
0
    }
889
890
0
    SdXMLGenericPageContext::endFastElement(nElement);
891
0
    GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
892
0
}
893
894
css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLMasterPageContext::createFastChildContext(
895
    sal_Int32 nElement,
896
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
897
0
{
898
0
    switch (nElement)
899
0
    {
900
        // some special objects inside style:masterpage context
901
0
        case XML_ELEMENT(STYLE, XML_STYLE):
902
0
        {
903
0
            if(GetSdImport().GetShapeImport()->GetStylesContext())
904
0
            {
905
                // style:style inside master-page context -> presentation style
906
0
                XMLShapeStyleContext* pNew = new XMLShapeStyleContext(
907
0
                    GetSdImport(),
908
0
                    *GetSdImport().GetShapeImport()->GetStylesContext(),
909
0
                    XmlStyleFamily::SD_PRESENTATION_ID);
910
911
                // add this style to the outer StylesContext class for later processing
912
0
                GetSdImport().GetShapeImport()->GetStylesContext()->AddStyle(*pNew);
913
0
                return pNew;
914
0
            }
915
0
            break;
916
0
        }
917
0
        case XML_ELEMENT(PRESENTATION, XML_NOTES):
918
0
        {
919
0
            if( GetSdImport().IsImpress() )
920
0
            {
921
                // get notes page
922
0
                uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
923
0
                if(xPresPage.is())
924
0
                {
925
0
                    uno::Reference< drawing::XDrawPage > xNotesDrawPage = xPresPage->getNotesPage();
926
0
                    if(xNotesDrawPage.is())
927
0
                    {
928
                        // presentation:notes inside master-page context
929
0
                        return new SdXMLNotesContext( GetSdImport(),  xAttrList, xNotesDrawPage);
930
0
                    }
931
0
                }
932
0
            }
933
0
            break;
934
0
        }
935
0
        case XML_ELEMENT(LO_EXT, XML_THEME):
936
0
        {
937
0
            uno::Reference<drawing::XDrawPage> xMasterPage(GetLocalShapesContext(), uno::UNO_QUERY);
938
0
            return new XMLThemeContext(GetSdImport(), xAttrList, xMasterPage);
939
0
            break;
940
0
        }
941
0
    }
942
0
    return SdXMLGenericPageContext::createFastChildContext(nElement, xAttrList);
943
0
}
944
945
SdXMLStylesContext::SdXMLStylesContext(
946
    SdXMLImport& rImport,
947
    bool bIsAutoStyle)
948
0
:   SvXMLStylesContext(rImport),
949
0
    mbIsAutoStyle(bIsAutoStyle)
950
0
{
951
0
    Reference< uno::XComponentContext > xContext = rImport.GetComponentContext();
952
0
    mpNumFormatter = std::make_unique<SvNumberFormatter>( xContext, LANGUAGE_SYSTEM );
953
0
    mpNumFmtHelper = std::make_unique<SvXMLNumFmtHelper>( mpNumFormatter.get() );
954
0
}
955
956
SvXMLStyleContext* SdXMLStylesContext::CreateStyleChildContext(
957
    sal_Int32 nElement,
958
    const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
959
0
{
960
0
    switch (nElement)
961
0
    {
962
0
        case XML_ELEMENT(TABLE, XML_TABLE_TEMPLATE):
963
0
        {
964
0
            auto pContext = GetImport().GetShapeImport()->GetShapeTableImport()->CreateTableTemplateContext(nElement, xAttrList );
965
0
            if (pContext)
966
0
                return pContext;
967
0
            break;
968
0
        }
969
0
        case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT):
970
            // style:page-master inside office:styles context
971
0
            return new SdXMLPageMasterContext(GetSdImport(), nElement, xAttrList);
972
0
        case XML_ELEMENT(STYLE, XML_PRESENTATION_PAGE_LAYOUT):
973
            // style:presentation-page-layout inside office:styles context
974
0
            return new SdXMLPresentationPageLayoutContext(GetSdImport(), nElement, xAttrList);
975
0
        case XML_ELEMENT(NUMBER, XML_DATE_STYLE):
976
            // number:date-style or number:time-style
977
0
            return new SdXMLNumberFormatImportContext( GetSdImport(), nElement, mpNumFmtHelper->getData(), SvXMLStylesTokens::DATE_STYLE, xAttrList, *this );
978
0
        case XML_ELEMENT(NUMBER, XML_TIME_STYLE):
979
            // number:date-style or number:time-style
980
0
            return new SdXMLNumberFormatImportContext( GetSdImport(), nElement, mpNumFmtHelper->getData(), SvXMLStylesTokens::TIME_STYLE, xAttrList, *this );
981
0
        case XML_ELEMENT(NUMBER, XML_NUMBER_STYLE):
982
0
            return new SvXMLNumFormatContext( GetSdImport(), nElement,
983
0
                                            mpNumFmtHelper->getData(), SvXMLStylesTokens::NUMBER_STYLE, xAttrList, *this );
984
0
        case XML_ELEMENT(NUMBER, XML_CURRENCY_STYLE):
985
0
            return new SvXMLNumFormatContext( GetSdImport(), nElement,
986
0
                                            mpNumFmtHelper->getData(), SvXMLStylesTokens::CURRENCY_STYLE, xAttrList, *this );
987
0
        case XML_ELEMENT(NUMBER, XML_PERCENTAGE_STYLE):
988
0
            return new SvXMLNumFormatContext( GetSdImport(), nElement,
989
0
                                            mpNumFmtHelper->getData(), SvXMLStylesTokens::PERCENTAGE_STYLE, xAttrList, *this );
990
0
        case XML_ELEMENT(NUMBER, XML_BOOLEAN_STYLE):
991
0
            return new SvXMLNumFormatContext( GetSdImport(), nElement,
992
0
                                            mpNumFmtHelper->getData(), SvXMLStylesTokens::BOOLEAN_STYLE, xAttrList, *this );
993
0
        case XML_ELEMENT(NUMBER, XML_TEXT_STYLE):
994
0
            return new SvXMLNumFormatContext( GetSdImport(), nElement,
995
0
                                            mpNumFmtHelper->getData(), SvXMLStylesTokens::TEXT_STYLE, xAttrList, *this );
996
0
        case XML_ELEMENT(PRESENTATION, XML_HEADER_DECL):
997
0
        case XML_ELEMENT(PRESENTATION, XML_FOOTER_DECL):
998
0
        case XML_ELEMENT(PRESENTATION, XML_DATE_TIME_DECL):
999
0
            return new SdXMLHeaderFooterDeclContext( GetImport(), xAttrList );
1000
0
        case XML_ELEMENT(STYLE, XML_STYLE):
1001
0
            break; // ignore
1002
0
        default:
1003
0
            XMLOFF_INFO_UNKNOWN_ELEMENT("xmloff", nElement);
1004
0
    }
1005
1006
    // call base class
1007
0
    return SvXMLStylesContext::CreateStyleChildContext(nElement, xAttrList);
1008
0
}
1009
1010
SvXMLStyleContext* SdXMLStylesContext::CreateStyleStyleChildContext(
1011
    XmlStyleFamily nFamily,
1012
    sal_Int32 nElement,
1013
    const uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
1014
0
{
1015
0
    switch( nFamily )
1016
0
    {
1017
0
    case XmlStyleFamily::SD_DRAWINGPAGE_ID:
1018
0
        return new SdXMLDrawingPageStyleContext(GetSdImport(), *this );
1019
0
    case XmlStyleFamily::TABLE_CELL:
1020
0
    case XmlStyleFamily::TABLE_COLUMN:
1021
0
    case XmlStyleFamily::TABLE_ROW:
1022
0
        return new XMLShapeStyleContext( GetSdImport(), *this, nFamily );
1023
0
    default: break;
1024
0
    }
1025
1026
    // call base class
1027
0
    return SvXMLStylesContext::CreateStyleStyleChildContext(nFamily, nElement, xAttrList);
1028
0
}
1029
1030
SvXMLStyleContext* SdXMLStylesContext::CreateDefaultStyleStyleChildContext(
1031
    XmlStyleFamily nFamily,
1032
    sal_Int32  nElement,
1033
    const Reference< XFastAttributeList > & xAttrList )
1034
0
{
1035
0
    switch( nFamily )
1036
0
    {
1037
0
    case XmlStyleFamily::SD_GRAPHICS_ID:
1038
0
        return new XMLGraphicsDefaultStyle(GetSdImport(), *this );
1039
0
    default: break;
1040
0
    }
1041
1042
    // call base class
1043
0
    return SvXMLStylesContext::CreateDefaultStyleStyleChildContext(nFamily, nElement, xAttrList);
1044
0
}
1045
1046
SvXMLImportPropertyMapper* SdXMLStylesContext::GetImportPropertyMapper(
1047
    XmlStyleFamily nFamily) const
1048
0
{
1049
0
    SvXMLImportPropertyMapper* pMapper = nullptr;
1050
1051
0
    switch( nFamily )
1052
0
    {
1053
0
    case XmlStyleFamily::SD_DRAWINGPAGE_ID:
1054
0
    {
1055
0
        pMapper = const_cast<SvXMLImport&>(GetImport()).GetShapeImport()->GetPresPagePropsMapper();
1056
0
        break;
1057
0
    }
1058
1059
0
    case XmlStyleFamily::TABLE_COLUMN:
1060
0
    case XmlStyleFamily::TABLE_ROW:
1061
0
    case XmlStyleFamily::TABLE_CELL:
1062
0
    {
1063
0
        const rtl::Reference< XMLTableImport >& xTableImport( const_cast< SvXMLImport& >( GetImport() ).GetShapeImport()->GetShapeTableImport() );
1064
1065
0
        switch( nFamily )
1066
0
        {
1067
0
        case XmlStyleFamily::TABLE_COLUMN: pMapper = xTableImport->GetColumnImportPropertySetMapper(); break;
1068
0
        case XmlStyleFamily::TABLE_ROW: pMapper = xTableImport->GetRowImportPropertySetMapper(); break;
1069
0
        case XmlStyleFamily::TABLE_CELL: pMapper = xTableImport->GetCellImportPropertySetMapper(); break;
1070
0
        default: break;
1071
0
        }
1072
0
        break;
1073
0
    }
1074
0
    default: break;
1075
0
    }
1076
1077
    // call base class
1078
0
    if( !pMapper )
1079
0
        pMapper = SvXMLStylesContext::GetImportPropertyMapper(nFamily);
1080
0
    return pMapper;
1081
0
}
1082
1083
// Process all style and object info
1084
1085
void SdXMLStylesContext::endFastElement(sal_Int32 )
1086
0
{
1087
0
    if(mbIsAutoStyle)
1088
0
    {
1089
        // AutoStyles for text import
1090
0
        GetImport().GetTextImport()->SetAutoStyles( this );
1091
1092
        // AutoStyles for chart
1093
0
        GetImport().GetChartImport()->SetAutoStylesContext( this );
1094
1095
        // AutoStyles for forms
1096
0
        GetImport().GetFormImport()->setAutoStyleContext( this );
1097
1098
        // associate AutoStyles with styles in preparation to setting Styles on shapes
1099
0
        for(sal_uInt32 a(0); a < GetStyleCount(); a++)
1100
0
        {
1101
0
            const SvXMLStyleContext* pStyle = GetStyle(a);
1102
0
            if (const XMLShapeStyleContext* pDocStyle = dynamic_cast<const XMLShapeStyleContext*>(pStyle))
1103
0
            {
1104
0
                SvXMLStylesContext* pStylesContext = GetSdImport().GetShapeImport()->GetStylesContext();
1105
0
                if (pStylesContext)
1106
0
                {
1107
0
                    pStyle = pStylesContext->FindStyleChildContext(pStyle->GetFamily(), pStyle->GetParentName());
1108
1109
0
                    if (const XMLShapeStyleContext* pParentStyle = dynamic_cast<const XMLShapeStyleContext*>(pStyle))
1110
0
                    {
1111
0
                        if(pParentStyle->GetStyle().is())
1112
0
                        {
1113
0
                            const_cast<XMLShapeStyleContext*>(pDocStyle)->SetStyle(pParentStyle->GetStyle());
1114
0
                        }
1115
0
                    }
1116
0
                }
1117
0
            }
1118
0
        }
1119
1120
0
        FinishStyles( false );
1121
0
    }
1122
0
    else
1123
0
    {
1124
        // Process styles list
1125
0
        ImpSetGraphicStyles();
1126
0
        ImpSetCellStyles();
1127
0
        GetImport().GetShapeImport()->GetShapeTableImport()->finishStyles();
1128
1129
        // put style infos in the info set for other components ( content import f.e. )
1130
0
        uno::Reference< beans::XPropertySet > xInfoSet( GetImport().getImportInfo() );
1131
0
        if( xInfoSet.is() )
1132
0
        {
1133
0
            uno::Reference< beans::XPropertySetInfo > xInfoSetInfo( xInfoSet->getPropertySetInfo() );
1134
1135
0
            if( xInfoSetInfo->hasPropertyByName(u"PageLayouts"_ustr) )
1136
0
                xInfoSet->setPropertyValue(u"PageLayouts"_ustr, uno::Any( getPageLayouts() ) );
1137
0
        }
1138
1139
0
    }
1140
0
}
1141
1142
// set master-page styles (all with family="presentation" and a special
1143
// prefix) on given master-page.
1144
1145
void SdXMLStylesContext::SetMasterPageStyles(SdXMLMasterPageContext const & rMaster) const
1146
0
{
1147
0
    const uno::Reference<container::XNameAccess>& rStyleFamilies =
1148
0
        GetSdImport().GetLocalDocStyleFamilies();
1149
1150
0
    if (!rStyleFamilies.is())
1151
0
        return;
1152
1153
0
    if (!rStyleFamilies->hasByName(rMaster.GetDisplayName()))
1154
0
        return;
1155
1156
0
    try
1157
0
    {
1158
0
        uno::Reference< container::XNameAccess > xMasterPageStyles( rStyleFamilies->getByName(rMaster.GetDisplayName()), UNO_QUERY_THROW );
1159
0
        OUString sPrefix(rMaster.GetDisplayName() + "-");
1160
0
        ImpSetGraphicStyles(xMasterPageStyles, XmlStyleFamily::SD_PRESENTATION_ID, sPrefix);
1161
0
    }
1162
0
    catch (const uno::Exception&)
1163
0
    {
1164
0
        TOOLS_WARN_EXCEPTION("xmloff.draw", "");
1165
0
    }
1166
0
}
1167
1168
// Process styles list:
1169
// set graphic styles (all with family="graphics"). Remember xStyle at list element.
1170
1171
void SdXMLStylesContext::ImpSetGraphicStyles() const
1172
0
{
1173
0
    if(GetSdImport().GetLocalDocStyleFamilies().is()) try
1174
0
    {
1175
0
        uno::Reference< container::XNameAccess > xGraphicPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName(u"graphics"_ustr), uno::UNO_QUERY_THROW );
1176
1177
0
        ImpSetGraphicStyles(xGraphicPageStyles, XmlStyleFamily::SD_GRAPHICS_ID, u""_ustr);
1178
0
    }
1179
0
    catch( uno::Exception& )
1180
0
    {
1181
0
        TOOLS_WARN_EXCEPTION("xmloff.draw", "");
1182
0
    }
1183
0
}
1184
1185
void SdXMLStylesContext::ImpSetCellStyles() const
1186
0
{
1187
0
    if(GetSdImport().GetLocalDocStyleFamilies().is()) try
1188
0
    {
1189
0
        uno::Reference< container::XNameAccess > xGraphicPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName(u"cell"_ustr), uno::UNO_QUERY_THROW );
1190
1191
0
        ImpSetGraphicStyles(xGraphicPageStyles, XmlStyleFamily::TABLE_CELL, u""_ustr);
1192
0
    }
1193
0
    catch( uno::Exception& )
1194
0
    {
1195
0
        TOOLS_WARN_EXCEPTION("xmloff.draw", "");
1196
0
    }
1197
0
}
1198
1199
//Resolves: fdo#34987 if the style's auto height before and after is the same
1200
//then don't reset it back to the underlying default of true for the small
1201
//period before it's going to be reset to false again. Doing this avoids the
1202
//master page shapes from resizing themselves due to autoheight becoming
1203
//enabled before having autoheight turned off again and getting stuck on that
1204
//autosized height
1205
static bool canSkipReset(std::u16string_view rName, const XMLPropStyleContext* pPropStyle,
1206
    const uno::Reference< beans::XPropertySet > &rPropSet, const rtl::Reference < XMLPropertySetMapper >& rPrMap)
1207
0
{
1208
0
    bool bCanSkipReset = false;
1209
0
    if (pPropStyle && rName == u"TextAutoGrowHeight")
1210
0
    {
1211
0
        bool bOldStyleTextAutoGrowHeight(false);
1212
0
        rPropSet->getPropertyValue(u"TextAutoGrowHeight"_ustr) >>= bOldStyleTextAutoGrowHeight;
1213
1214
0
        sal_Int32 nIndexStyle = rPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, u"auto-grow-height", 0);
1215
0
        if (nIndexStyle != -1)
1216
0
        {
1217
0
            const ::std::vector< XMLPropertyState > &rProperties = pPropStyle->GetProperties();
1218
0
            auto property = std::find_if(rProperties.cbegin(), rProperties.cend(),
1219
0
                [nIndexStyle](const XMLPropertyState& rProp) { return rProp.mnIndex == nIndexStyle; });
1220
0
            if (property != rProperties.cend())
1221
0
            {
1222
0
                bool bNewStyleTextAutoGrowHeight(false);
1223
0
                property->maValue >>= bNewStyleTextAutoGrowHeight;
1224
0
                bCanSkipReset = (bNewStyleTextAutoGrowHeight == bOldStyleTextAutoGrowHeight);
1225
0
            }
1226
0
        }
1227
0
    }
1228
0
    return bCanSkipReset;
1229
0
}
1230
1231
// help function used by ImpSetGraphicStyles() and ImpSetMasterPageStyles()
1232
1233
void SdXMLStylesContext::ImpSetGraphicStyles( uno::Reference< container::XNameAccess > const & xPageStyles,  XmlStyleFamily nFamily, const OUString& rPrefix) const
1234
0
{
1235
0
    sal_Int32 nPrefLen(rPrefix.getLength());
1236
1237
    // set defaults
1238
0
    auto [itStart1, itEnd1] = FindStyleChildContextByDisplayNamePrefix(nFamily, u""_ustr);
1239
0
    for (auto it = itStart1; it != itEnd1; ++it)
1240
0
    {
1241
0
        const SvXMLStyleContext* pStyle = *it;
1242
0
        if(pStyle->IsDefaultStyle())
1243
0
        {
1244
0
            const_cast<SvXMLStyleContext*>(pStyle)->SetDefaults();
1245
0
        }
1246
0
    }
1247
1248
    // create all styles and set properties
1249
0
    auto [itStart, itEnd] = FindStyleChildContextByDisplayNamePrefix(nFamily, rPrefix);
1250
0
    for (auto it = itStart; it != itEnd; ++it)
1251
0
    {
1252
0
        const SvXMLStyleContext* pStyle = *it;
1253
0
        try
1254
0
        {
1255
0
            if(!pStyle->IsDefaultStyle())
1256
0
            {
1257
0
                OUString aStyleName(pStyle->GetDisplayName());
1258
0
                if( nPrefLen )
1259
0
                    aStyleName = aStyleName.copy( nPrefLen );
1260
1261
0
                XMLPropStyleContext* pPropStyle = dynamic_cast< XMLPropStyleContext* >(const_cast< SvXMLStyleContext* >( pStyle ) );
1262
1263
0
                uno::Reference< style::XStyle > xStyle;
1264
0
                if(xPageStyles->hasByName(aStyleName))
1265
0
                {
1266
0
                    xPageStyles->getByName(aStyleName) >>= xStyle;
1267
1268
                    // set properties of existing styles to default
1269
0
                    uno::Reference< beans::XPropertySet > xPropSet( xStyle, uno::UNO_QUERY );
1270
0
                    uno::Reference< beans::XPropertySetInfo > xPropSetInfo;
1271
0
                    if( xPropSet.is() )
1272
0
                        xPropSetInfo = xPropSet->getPropertySetInfo();
1273
1274
0
                    uno::Reference< beans::XPropertyState > xPropState( xStyle, uno::UNO_QUERY );
1275
1276
0
                    if( xPropState.is() )
1277
0
                    {
1278
0
                        rtl::Reference < XMLPropertySetMapper > xPrMap;
1279
0
                        SvXMLImportPropertyMapper* pImpPrMap = GetImportPropertyMapper( nFamily );
1280
0
                        SAL_WARN_IF( !pImpPrMap, "xmloff", "There is the import prop mapper" );
1281
0
                        if( pImpPrMap )
1282
0
                            xPrMap = pImpPrMap->getPropertySetMapper();
1283
0
                        if( xPrMap.is() )
1284
0
                        {
1285
0
                            const sal_Int32 nCount = xPrMap->GetEntryCount();
1286
0
                            for( sal_Int32 i = 0; i < nCount; i++ )
1287
0
                            {
1288
0
                                const OUString& rName = xPrMap->GetEntryAPIName( i );
1289
0
                                if( xPropSetInfo->hasPropertyByName( rName ) && beans::PropertyState_DIRECT_VALUE == xPropState->getPropertyState( rName ) )
1290
0
                                {
1291
0
                                    bool bCanSkipReset = canSkipReset(rName, pPropStyle, xPropSet, xPrMap);
1292
0
                                    if (bCanSkipReset)
1293
0
                                        continue;
1294
0
                                    xPropState->setPropertyToDefault( rName );
1295
0
                                }
1296
0
                            }
1297
0
                        }
1298
0
                    }
1299
0
                }
1300
0
                else
1301
0
                {
1302
                    // graphics style does not exist, create and add it
1303
0
                    uno::Reference< lang::XSingleServiceFactory > xServiceFact(xPageStyles, uno::UNO_QUERY);
1304
0
                    if(xServiceFact.is())
1305
0
                    {
1306
0
                        uno::Reference< style::XStyle > xNewStyle( xServiceFact->createInstance(), uno::UNO_QUERY);
1307
1308
0
                        if(xNewStyle.is())
1309
0
                        {
1310
                            // remember style
1311
0
                            xStyle = std::move(xNewStyle);
1312
1313
                            // add new style to graphics style pool
1314
0
                            uno::Reference< container::XNameContainer > xInsertContainer(xPageStyles, uno::UNO_QUERY);
1315
0
                            if(xInsertContainer.is())
1316
0
                                xInsertContainer->insertByName(aStyleName, uno::Any( xStyle ) );
1317
0
                        }
1318
0
                    }
1319
0
                }
1320
1321
0
                if(xStyle.is())
1322
0
                {
1323
                    // set properties at style
1324
0
                    uno::Reference< beans::XPropertySet > xPropSet(xStyle, uno::UNO_QUERY);
1325
0
                    if(xPropSet.is() && pPropStyle)
1326
0
                    {
1327
0
                        pPropStyle->FillPropertySet(xPropSet);
1328
0
                        pPropStyle->SetStyle(xStyle);
1329
0
                    }
1330
0
                }
1331
0
            }
1332
0
        }
1333
0
        catch(const Exception& e)
1334
0
        {
1335
0
            const_cast<SdXMLImport*>(&GetSdImport())->SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, {}, e.Message, nullptr );
1336
0
        }
1337
0
    }
1338
1339
    // now set parents for all styles (when necessary)
1340
0
    for (auto it = itStart; it != itEnd; ++it)
1341
0
    {
1342
0
        const SvXMLStyleContext* pStyle = *it;
1343
1344
0
        if(pStyle->GetDisplayName().isEmpty())
1345
0
            continue;
1346
0
        try
1347
0
        {
1348
0
            OUString aStyleName(pStyle->GetDisplayName());
1349
0
            if( nPrefLen )
1350
0
                aStyleName = aStyleName.copy( nPrefLen );
1351
1352
0
            uno::Reference< style::XStyle > xStyle( xPageStyles->getByName(aStyleName), UNO_QUERY );
1353
0
            if(xStyle.is())
1354
0
            {
1355
                // set parent style name
1356
0
                OUString sParentStyleDisplayName( GetImport().GetStyleDisplayName( pStyle->GetFamily(), pStyle->GetParentName() ) );
1357
0
                if( nPrefLen )
1358
0
                {
1359
0
                    sal_Int32 nStylePrefLen = sParentStyleDisplayName.lastIndexOf( '-' ) + 1;
1360
0
                    if( (nPrefLen != nStylePrefLen) || !sParentStyleDisplayName.startsWith( rPrefix ) )
1361
0
                        continue;
1362
1363
0
                    sParentStyleDisplayName = sParentStyleDisplayName.copy( nPrefLen );
1364
0
                }
1365
0
                if (xStyle->getParentStyle() != sParentStyleDisplayName)
1366
0
                    xStyle->setParentStyle( sParentStyleDisplayName );
1367
0
            }
1368
0
        }
1369
0
        catch( const Exception& e )
1370
0
        {
1371
0
            const_cast<SdXMLImport*>(&GetSdImport())->SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, {}, e.Message, nullptr );
1372
0
        }
1373
0
    }
1374
0
}
1375
1376
// helper function to create the uno component that hold the mappings from
1377
// xml auto layout name to internal autolayout id
1378
1379
uno::Reference< container::XNameAccess > SdXMLStylesContext::getPageLayouts() const
1380
0
{
1381
0
    uno::Reference< container::XNameContainer > xLayouts( comphelper::NameContainer_createInstance( ::cppu::UnoType<sal_Int32>::get()) );
1382
1383
0
    for(sal_uInt32 a(0); a < GetStyleCount(); a++)
1384
0
    {
1385
0
        const SvXMLStyleContext* pStyle = GetStyle(a);
1386
0
        if (const SdXMLPresentationPageLayoutContext* pContext = dynamic_cast<const SdXMLPresentationPageLayoutContext*>(pStyle))
1387
0
        {
1388
0
            xLayouts->insertByName(pStyle->GetName(), uno::Any(static_cast<sal_Int32>(pContext->GetTypeId())));
1389
0
        }
1390
0
    }
1391
1392
0
    return xLayouts;
1393
0
}
1394
1395
1396
SdXMLMasterStylesContext::SdXMLMasterStylesContext(
1397
    SdXMLImport& rImport)
1398
0
:   SvXMLImportContext( rImport )
1399
0
{
1400
0
}
1401
1402
css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLMasterStylesContext::createFastChildContext(
1403
    sal_Int32 nElement,
1404
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
1405
0
{
1406
0
    if( nElement == XML_ELEMENT(DRAW, XML_LAYER_SET) )
1407
0
    {
1408
0
        return new SdXMLLayerSetContext( GetImport() );
1409
0
    }
1410
0
    else if( nElement == XML_ELEMENT(STYLE, XML_MASTER_PAGE) )
1411
0
    {
1412
        // style:masterpage inside office:styles context
1413
0
        uno::Reference< drawing::XDrawPages2 > xMasterPages(GetSdImport().GetLocalMasterPages());
1414
1415
0
        if( xMasterPages.is() )
1416
0
        {
1417
0
            sal_Int32 nMasterPageCount = xMasterPages->getCount();
1418
            // arbitrary limit to master pages when fuzzing to avoid deadend timeouts
1419
0
            if (nMasterPageCount >= 64 && comphelper::IsFuzzing())
1420
0
               return nullptr;
1421
1422
            // new page, create and insert
1423
1424
0
            if(GetSdImport().GetShapeImport()->GetStylesContext())
1425
0
            {
1426
0
                const rtl::Reference<SdXMLMasterPageContext> xLclContext{
1427
0
                    new SdXMLMasterPageContext(GetSdImport(),
1428
0
                        nElement, xAttrList, xMasterPages)};
1429
0
                maMasterPageList.push_back(xLclContext);
1430
0
                return xLclContext;
1431
0
            }
1432
0
        }
1433
0
    }
1434
0
    else if( nElement == XML_ELEMENT(STYLE, XML_HANDOUT_MASTER) )
1435
0
    {
1436
0
        uno::Reference< presentation::XHandoutMasterSupplier > xHandoutSupp( GetSdImport().GetModel(), uno::UNO_QUERY );
1437
0
        if( xHandoutSupp.is() )
1438
0
        {
1439
0
            uno::Reference< drawing::XShapes > xHandoutPage = xHandoutSupp->getHandoutMasterPage();
1440
0
            if(xHandoutPage.is() && GetSdImport().GetShapeImport()->GetStylesContext())
1441
0
            {
1442
0
                return new SdXMLMasterPageContext(GetSdImport(),
1443
0
                    nElement, xAttrList, xHandoutPage);
1444
0
            }
1445
0
        }
1446
0
    }
1447
0
    else
1448
0
        XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
1449
0
    return nullptr;
1450
0
}
1451
1452
SdXMLHeaderFooterDeclContext::SdXMLHeaderFooterDeclContext(SvXMLImport& rImport,
1453
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
1454
0
    : SvXMLStyleContext( rImport )
1455
0
    , mbFixed(false)
1456
0
{
1457
0
    for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
1458
0
    {
1459
0
        if( aIter.getToken() == XML_ELEMENT(PRESENTATION, XML_NAME) )
1460
0
        {
1461
0
            maStrName = aIter.toString();
1462
0
        }
1463
0
        else if( aIter.getToken() == XML_ELEMENT(PRESENTATION, XML_SOURCE) )
1464
0
        {
1465
0
            mbFixed = IsXMLToken( aIter, XML_FIXED );
1466
0
        }
1467
0
        else if( aIter.getToken() == XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME) )
1468
0
        {
1469
0
            maStrDateTimeFormat = aIter.toString();
1470
0
        }
1471
0
        else
1472
0
        {
1473
0
            XMLOFF_WARN_UNKNOWN("xmloff", aIter);
1474
0
        }
1475
0
    }
1476
0
}
1477
1478
bool SdXMLHeaderFooterDeclContext::IsTransient() const
1479
0
{
1480
0
    return true;
1481
0
}
1482
1483
void SdXMLHeaderFooterDeclContext::endFastElement(sal_Int32 nToken)
1484
0
{
1485
0
    SdXMLImport& rImport = dynamic_cast<SdXMLImport&>(GetImport());
1486
0
    auto nElement = nToken & TOKEN_MASK;
1487
0
    if( nElement == XML_HEADER_DECL )
1488
0
    {
1489
0
        rImport.AddHeaderDecl( maStrName, maStrText );
1490
0
    }
1491
0
    else if( nElement == XML_FOOTER_DECL )
1492
0
    {
1493
0
        rImport.AddFooterDecl( maStrName, maStrText );
1494
0
    }
1495
0
    else if( nElement == XML_DATE_TIME_DECL )
1496
0
    {
1497
0
        rImport.AddDateTimeDecl( maStrName, maStrText, mbFixed, maStrDateTimeFormat );
1498
0
    }
1499
0
    else
1500
0
    {
1501
0
        XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nToken);
1502
0
    }
1503
0
}
1504
1505
void SdXMLHeaderFooterDeclContext::characters( const OUString& rChars )
1506
0
{
1507
0
    maStrText += rChars;
1508
0
}
1509
1510
namespace xmloff {
1511
1512
bool IsIgnoreFillStyleNamedItem(
1513
        css::uno::Reference<css::beans::XPropertySet> const& xProps,
1514
        drawing::FillStyle const nExpectedFillStyle)
1515
445
{
1516
445
    assert(xProps.is());
1517
445
    if (nExpectedFillStyle == drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE)
1518
445
    {
1519
445
        return false;
1520
445
    }
1521
1522
    // note: the caller must have called FillPropertySet() previously
1523
0
    drawing::FillStyle fillStyle{drawing::FillStyle_NONE};
1524
0
    xProps->getPropertyValue(u"FillStyle"_ustr) >>= fillStyle;
1525
0
    return fillStyle != nExpectedFillStyle;
1526
445
}
1527
1528
} // namespace xmloff
1529
1530
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */