Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/style/xmlaustp.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/container/XIndexReplace.hpp>
21
#include "impastpl.hxx"
22
#include <xmloff/xmlaustp.hxx>
23
#include <xmloff/families.hxx>
24
#include <xmloff/xmlnamespace.hxx>
25
#include <xmloff/xmltoken.hxx>
26
#include <xmloff/xmlexp.hxx>
27
#include <xmloff/xmlprhdl.hxx>
28
#include <xmloff/xmlprmap.hxx>
29
#include <xmloff/XMLTextListAutoStylePool.hxx>
30
31
#include <PageMasterStyleMap.hxx>
32
#include <osl/diagnose.h>
33
34
35
using namespace ::com::sun::star;
36
using namespace ::xmloff::token;
37
38
39
namespace
40
{
41
    void lcl_exportDataStyle( SvXMLExport& _rExport, const rtl::Reference< XMLPropertySetMapper >& _rxMapper,
42
        const XMLPropertyState& _rProperty )
43
0
    {
44
0
        assert(_rxMapper.is());
45
        // obtain the data style name
46
0
        OUString sDataStyleName;
47
0
        _rProperty.maValue >>= sDataStyleName;
48
0
        assert(!sDataStyleName.isEmpty() && "xmloff::lcl_exportDataStyle: invalid property value for the data style name!");
49
50
        // add the attribute
51
0
        _rExport.AddAttribute(
52
0
            _rxMapper->GetEntryNameSpace( _rProperty.mnIndex ),
53
0
            _rxMapper->GetEntryXMLName( _rProperty.mnIndex ),
54
0
            sDataStyleName );
55
0
    }
56
}
57
58
void SvXMLAutoStylePoolP::exportStyleAttributes(
59
        comphelper::AttributeList&,
60
        XmlStyleFamily nFamily,
61
        const std::vector< XMLPropertyState >& rProperties,
62
        const SvXMLExportPropertyMapper& rPropExp,
63
        const SvXMLUnitConverter&,
64
        const SvXMLNamespaceMap&
65
        ) const
66
545
{
67
545
    if ( XmlStyleFamily::CONTROL_ID == nFamily )
68
0
    {   // it's a control-related style
69
0
        const rtl::Reference< XMLPropertySetMapper >& aPropertyMapper = rPropExp.getPropertySetMapper();
70
71
0
        for (const auto& rProp : rProperties)
72
0
        {
73
0
            if  (   ( rProp.mnIndex > -1 )
74
0
                &&  ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( rProp.mnIndex ) )
75
0
                )
76
0
            {   // it's the data-style for a grid column
77
0
                lcl_exportDataStyle( GetExport(), aPropertyMapper, rProp );
78
0
            }
79
0
        }
80
0
    }
81
82
545
    if( (XmlStyleFamily::SD_GRAPHICS_ID == nFamily) || (XmlStyleFamily::SD_PRESENTATION_ID == nFamily) )
83
155
    {   // it's a graphics style
84
155
        const rtl::Reference< XMLPropertySetMapper >& aPropertyMapper = rPropExp.getPropertySetMapper();
85
155
        assert(aPropertyMapper.is());
86
87
155
        bool bFoundControlShapeDataStyle = false;
88
155
        bool bFoundNumberingRulesName = false;
89
90
155
        for (const auto& rProp : rProperties)
91
2.52k
        {
92
2.52k
            if (rProp.mnIndex > -1)
93
2.20k
            {   // it's a valid property
94
2.20k
                switch( aPropertyMapper->GetEntryContextId(rProp.mnIndex) )
95
2.20k
                {
96
0
                case CTF_SD_CONTROL_SHAPE_DATA_STYLE:
97
0
                    {   // it's the control shape data style property
98
99
0
                        if (bFoundControlShapeDataStyle)
100
0
                        {
101
0
                            OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
102
                            // already added the attribute for the first occurrence
103
0
                            break;
104
0
                        }
105
106
0
                        lcl_exportDataStyle( GetExport(), aPropertyMapper, rProp );
107
108
                        // check if there is another property with the special context id we're handling here
109
0
                        bFoundControlShapeDataStyle = true;
110
0
                        break;
111
0
                    }
112
0
                case CTF_SD_NUMBERINGRULES_NAME:
113
0
                    {
114
0
                        if (bFoundNumberingRulesName)
115
0
                        {
116
0
                            OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the numbering rules name context id!");
117
                            // already added the attribute for the first occurrence
118
0
                            break;
119
0
                        }
120
121
0
                        uno::Reference< container::XIndexReplace > xNumRule;
122
0
                        rProp.maValue >>= xNumRule;
123
0
                        if( xNumRule.is() && (xNumRule->getCount() > 0 ) )
124
0
                        {
125
0
                            const OUString sName(const_cast<XMLTextListAutoStylePool*>(&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule ));
126
127
0
                            GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_LIST_STYLE_NAME, GetExport().EncodeStyleName( sName ) );
128
0
                        }
129
130
0
                        bFoundNumberingRulesName = true;
131
0
                        break;
132
0
                    }
133
2.20k
                }
134
2.20k
            }
135
2.52k
        }
136
155
    }
137
138
545
    if( nFamily != XmlStyleFamily::PAGE_MASTER )
139
545
        return;
140
141
0
    for( const auto& rProp : rProperties )
142
0
    {
143
0
        if (rProp.mnIndex > -1)
144
0
        {
145
0
            const rtl::Reference< XMLPropertySetMapper >& aPropMapper = rPropExp.getPropertySetMapper();
146
0
            sal_Int32 nIndex = rProp.mnIndex;
147
0
            sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex );
148
0
            switch( nContextID )
149
0
            {
150
0
                case CTF_PM_PAGEUSAGE:
151
0
                {
152
0
                    OUString sValue;
153
0
                    const XMLPropertyHandler* pPropHdl = aPropMapper->GetPropertyHandler( nIndex );
154
0
                    if( pPropHdl &&
155
0
                        pPropHdl->exportXML( sValue, rProp.maValue,
156
0
                                             GetExport().GetMM100UnitConverter() ) &&
157
0
                        ( ! IsXMLToken( sValue, XML_ALL ) ) )
158
0
                    {
159
0
                        GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue );
160
0
                    }
161
0
                }
162
0
                break;
163
0
            }
164
0
        }
165
0
    }
166
0
}
167
168
void SvXMLAutoStylePoolP::exportStyleContent(
169
        const css::uno::Reference< css::xml::sax::XDocumentHandler > &,
170
        XmlStyleFamily nFamily,
171
        const std::vector< XMLPropertyState >& rProperties,
172
        const SvXMLExportPropertyMapper& rPropExp,
173
        const SvXMLUnitConverter&,
174
        const SvXMLNamespaceMap&
175
        ) const
176
545
{
177
545
    if( nFamily != XmlStyleFamily::PAGE_MASTER )
178
545
        return;
179
180
0
    sal_Int32       nHeaderStartIndex(-1);
181
0
    sal_Int32       nHeaderEndIndex(-1);
182
0
    sal_Int32       nFooterStartIndex(-1);
183
0
    sal_Int32       nFooterEndIndex(-1);
184
0
    bool        bHeaderStartIndex(false);
185
0
    bool        bHeaderEndIndex(false);
186
0
    bool        bFooterStartIndex(false);
187
0
    bool        bFooterEndIndex(false);
188
189
0
    const rtl::Reference< XMLPropertySetMapper >& aPropMapper = rPropExp.getPropertySetMapper();
190
191
0
    sal_Int32 nIndex(0);
192
0
    while(nIndex < aPropMapper->GetEntryCount())
193
0
    {
194
0
        switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK )
195
0
        {
196
0
            case CTF_PM_HEADERFLAG:
197
0
            {
198
0
                if (!bHeaderStartIndex)
199
0
                {
200
0
                    nHeaderStartIndex = nIndex;
201
0
                    bHeaderStartIndex = true;
202
0
                }
203
0
                if (bFooterStartIndex && !bFooterEndIndex)
204
0
                {
205
0
                    nFooterEndIndex = nIndex;
206
0
                    bFooterEndIndex = true;
207
0
                }
208
0
            }
209
0
            break;
210
0
            case CTF_PM_FOOTERFLAG:
211
0
            {
212
0
                if (!bFooterStartIndex)
213
0
                {
214
0
                    nFooterStartIndex = nIndex;
215
0
                    bFooterStartIndex = true;
216
0
                }
217
0
                if (bHeaderStartIndex && !bHeaderEndIndex)
218
0
                {
219
0
                    nHeaderEndIndex = nIndex;
220
0
                    bHeaderEndIndex = true;
221
0
                }
222
0
            }
223
0
            break;
224
0
        }
225
0
        nIndex++;
226
0
    }
227
0
    if (!bHeaderEndIndex)
228
0
        nHeaderEndIndex = nIndex;
229
0
    if (!bFooterEndIndex)
230
0
        nFooterEndIndex = nIndex;
231
232
    // export header style element
233
0
    {
234
0
        SvXMLElementExport aElem(
235
0
            GetExport(), XML_NAMESPACE_STYLE, XML_HEADER_STYLE,
236
0
            true, true );
237
238
0
        rPropExp.exportXML(
239
0
            GetExport(), rProperties,
240
0
            nHeaderStartIndex, nHeaderEndIndex, SvXmlExportFlags::IGN_WS);
241
0
    }
242
243
    // export footer style
244
0
    {
245
0
        SvXMLElementExport aElem(
246
0
            GetExport(), XML_NAMESPACE_STYLE, XML_FOOTER_STYLE,
247
0
            true, true );
248
249
0
        rPropExp.exportXML(
250
0
            GetExport(), rProperties,
251
0
            nFooterStartIndex, nFooterEndIndex, SvXmlExportFlags::IGN_WS);
252
0
    }
253
254
0
}
255
256
SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport& rExport )
257
69
    : m_pImpl( new SvXMLAutoStylePoolP_Impl( rExport ) )
258
69
{
259
69
}
260
261
SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP()
262
69
{
263
69
}
264
265
SvXMLExport& SvXMLAutoStylePoolP::GetExport() const
266
0
{
267
0
    return m_pImpl->GetExport();
268
0
}
269
270
// TODO: remove this
271
void SvXMLAutoStylePoolP::AddFamily(
272
        XmlStyleFamily nFamily,
273
        const OUString& rStrName,
274
        SvXMLExportPropertyMapper* pMapper,
275
        const OUString& aStrPrefix )
276
483
{
277
483
    rtl::Reference <SvXMLExportPropertyMapper> xTmp = pMapper;
278
483
    AddFamily( nFamily, rStrName, xTmp, aStrPrefix );
279
483
}
280
281
void SvXMLAutoStylePoolP::AddFamily(
282
        XmlStyleFamily nFamily,
283
        const OUString& rStrName,
284
        const rtl::Reference < SvXMLExportPropertyMapper > & rMapper,
285
        const OUString& rStrPrefix,
286
        bool bAsFamily )
287
966
{
288
966
    m_pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily );
289
966
}
290
291
void  SvXMLAutoStylePoolP::SetFamilyPropSetMapper(
292
        XmlStyleFamily nFamily,
293
        const rtl::Reference < SvXMLExportPropertyMapper > & rMapper )
294
0
{
295
0
    m_pImpl->SetFamilyPropSetMapper( nFamily, rMapper );
296
0
}
297
298
void SvXMLAutoStylePoolP::RegisterName( XmlStyleFamily nFamily,
299
                                         const OUString& rName )
300
1.21k
{
301
1.21k
    m_pImpl->RegisterName( nFamily, rName );
302
1.21k
}
303
304
void SvXMLAutoStylePoolP::RegisterDefinedName( XmlStyleFamily nFamily,
305
                                         const OUString& rName )
306
0
{
307
0
    m_pImpl->RegisterDefinedName( nFamily, rName );
308
0
}
309
310
void SvXMLAutoStylePoolP::GetRegisteredNames(
311
    uno::Sequence<sal_Int32>& rFamilies,
312
    uno::Sequence<OUString>& rNames )
313
0
{
314
0
    m_pImpl->GetRegisteredNames( rFamilies, rNames );
315
0
}
316
317
void SvXMLAutoStylePoolP::RegisterNames(
318
    uno::Sequence<sal_Int32> const & aFamilies,
319
    uno::Sequence<OUString> const & aNames )
320
0
{
321
0
    assert(aFamilies.getLength() == aNames.getLength());
322
323
    // iterate over sequence(s) and call RegisterName(..) for each pair
324
0
    const sal_Int32* pFamilies = aFamilies.getConstArray();
325
0
    const OUString* pNames = aNames.getConstArray();
326
0
    sal_Int32 nCount = std::min( aFamilies.getLength(), aNames.getLength() );
327
0
    for( sal_Int32 n = 0; n < nCount; n++ )
328
0
        RegisterName( static_cast<XmlStyleFamily>(pFamilies[n]), pNames[n] );
329
0
}
330
331
OUString SvXMLAutoStylePoolP::Add( XmlStyleFamily nFamily,
332
                                   std::vector< XMLPropertyState >&& rProperties )
333
0
{
334
0
    OUString sName;
335
0
    m_pImpl->Add(sName, nFamily, u""_ustr, std::move(rProperties) );
336
0
    return sName;
337
0
}
338
339
OUString SvXMLAutoStylePoolP::Add( XmlStyleFamily nFamily,
340
                                  const OUString& rParent,
341
                                  std::vector< XMLPropertyState >&& rProperties, bool bDontSeek )
342
1.25k
{
343
1.25k
    OUString sName;
344
1.25k
    m_pImpl->Add(sName, nFamily, rParent, std::move(rProperties), bDontSeek);
345
1.25k
    return sName;
346
1.25k
}
347
348
bool SvXMLAutoStylePoolP::Add(OUString& rName, XmlStyleFamily nFamily, const OUString& rParent, ::std::vector< XMLPropertyState >&& rProperties )
349
0
{
350
0
    return m_pImpl->Add(rName, nFamily, rParent, std::move(rProperties));
351
0
}
352
353
bool SvXMLAutoStylePoolP::AddNamed( const OUString& rName, XmlStyleFamily nFamily, const OUString& rParent,
354
                                    std::vector< XMLPropertyState > rProperties )
355
356
0
{
357
0
    return m_pImpl->AddNamed(rName, nFamily, rParent, std::move(rProperties));
358
0
}
359
360
OUString SvXMLAutoStylePoolP::Find( XmlStyleFamily nFamily,
361
                                   const OUString& rParent,
362
                                   const std::vector< XMLPropertyState >& rProperties ) const
363
4.44k
{
364
4.44k
    return m_pImpl->Find( nFamily, rParent, rProperties );
365
4.44k
}
366
367
void SvXMLAutoStylePoolP::exportXML( XmlStyleFamily nFamily ) const
368
540
{
369
540
    m_pImpl->exportXML( nFamily, this );
370
540
}
371
372
void SvXMLAutoStylePoolP::ClearEntries()
373
0
{
374
0
    m_pImpl->ClearEntries();
375
0
}
376
377
std::vector<xmloff::AutoStyleEntry> SvXMLAutoStylePoolP::GetAutoStyleEntries() const
378
45
{
379
45
    return m_pImpl->GetAutoStyleEntries();
380
45
}
381
382
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */