Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/text/XMLSectionFootnoteConfigExport.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 "XMLSectionFootnoteConfigExport.hxx"
21
#include <xmloff/xmlexp.hxx>
22
#include <xmloff/xmlprmap.hxx>
23
#include <com/sun/star/style/NumberingType.hpp>
24
#include <xmloff/maptype.hxx>
25
26
#include <xmloff/txtprmap.hxx>
27
#include <xmloff/xmlnamespace.hxx>
28
#include <xmloff/xmluconv.hxx>
29
#include <xmloff/xmltoken.hxx>
30
#include <rtl/ustring.hxx>
31
#include <rtl/ustrbuf.hxx>
32
#include <sal/log.hxx>
33
34
35
using namespace ::xmloff::token;
36
37
using ::std::vector;
38
using css::style::NumberingType::ARABIC;
39
40
41
void XMLSectionFootnoteConfigExport::exportXML(
42
    SvXMLExport& rExport,
43
    bool bEndnote,
44
    const vector<XMLPropertyState> *pProperties,
45
    sal_uInt32 nIdx,
46
    const rtl::Reference<XMLPropertySetMapper> & rMapper)
47
0
{
48
    // store and initialize the values
49
0
    bool bNumOwn = false;
50
0
    bool bNumRestart = false;
51
0
    sal_Int16 nNumRestartAt = 0;
52
0
    sal_Int16 nNumberingType = ARABIC;
53
0
    OUString sNumPrefix;
54
0
    OUString sNumSuffix;
55
0
    bool bEnd = false;
56
57
    // find entries in property states vector
58
0
    sal_uInt32 nCount = pProperties->size();
59
0
    for(sal_uInt32 i = 0; i < nCount; i++)
60
0
    {
61
0
        const XMLPropertyState& rState = (*pProperties)[i];
62
63
0
        sal_Int16 nContextId = rMapper->GetEntryContextId(rState.mnIndex);
64
0
        if (!bEndnote)
65
0
        {
66
0
            switch (nContextId)
67
0
            {
68
0
                case CTF_SECTION_FOOTNOTE_NUM_OWN:
69
0
                    rState.maValue >>= bNumOwn;
70
0
                    break;
71
0
                case CTF_SECTION_FOOTNOTE_NUM_RESTART:
72
0
                    rState.maValue >>= bNumRestart;
73
0
                    break;
74
0
                case CTF_SECTION_FOOTNOTE_NUM_RESTART_AT:
75
0
                    rState.maValue >>= nNumRestartAt;
76
0
                    break;
77
0
                case CTF_SECTION_FOOTNOTE_NUM_TYPE:
78
0
                    rState.maValue >>= nNumberingType;
79
0
                    break;
80
0
                case CTF_SECTION_FOOTNOTE_NUM_PREFIX:
81
0
                    rState.maValue >>= sNumPrefix;
82
0
                    break;
83
0
                case CTF_SECTION_FOOTNOTE_NUM_SUFFIX:
84
0
                    rState.maValue >>= sNumSuffix;
85
0
                    break;
86
0
                case CTF_SECTION_FOOTNOTE_END:
87
0
                    SAL_WARN_IF( i != nIdx, "xmloff",
88
0
                                "received wrong property state index" );
89
0
                    rState.maValue >>= bEnd;
90
0
                    break;
91
0
            }
92
0
        }
93
0
        else
94
0
        {
95
0
            switch (nContextId)
96
0
            {
97
0
                case CTF_SECTION_ENDNOTE_NUM_OWN:
98
0
                    rState.maValue >>= bNumOwn;
99
0
                    break;
100
0
                case CTF_SECTION_ENDNOTE_NUM_RESTART:
101
0
                    rState.maValue >>= bNumRestart;
102
0
                    break;
103
0
                case CTF_SECTION_ENDNOTE_NUM_RESTART_AT:
104
0
                    rState.maValue >>= nNumRestartAt;
105
0
                    break;
106
0
                case CTF_SECTION_ENDNOTE_NUM_TYPE:
107
0
                    rState.maValue >>= nNumberingType;
108
0
                    break;
109
0
                case CTF_SECTION_ENDNOTE_NUM_PREFIX:
110
0
                    rState.maValue >>= sNumPrefix;
111
0
                    break;
112
0
                case CTF_SECTION_ENDNOTE_NUM_SUFFIX:
113
0
                    rState.maValue >>= sNumSuffix;
114
0
                    break;
115
0
                case CTF_SECTION_ENDNOTE_END:
116
0
                    SAL_WARN_IF( i != nIdx, "xmloff",
117
0
                                "received wrong property state index" );
118
0
                    rState.maValue >>= bEnd;
119
0
                    break;
120
0
            }
121
0
        }
122
0
    }
123
124
    // we only make an element if we have an own footnote/endnote numbering
125
0
    if (!bEnd)
126
0
        return;
127
128
0
    rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
129
0
                             GetXMLToken( bEndnote ? XML_ENDNOTE
130
0
                                                     : XML_FOOTNOTE ) );
131
    // start numbering
132
0
    if (bNumRestart)
133
0
    {
134
        // restart number is stored as 0.., but interpreted as 1..
135
0
        rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_START_VALUE,
136
0
                             OUString::number(nNumRestartAt+1));
137
0
    }
138
139
0
    if (bNumOwn)
140
0
    {
141
        // prefix and suffix
142
0
        if (!sNumPrefix.isEmpty())
143
0
        {
144
0
                rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_PREFIX,
145
0
                                     sNumPrefix);
146
0
        }
147
0
        if (!sNumSuffix.isEmpty())
148
0
        {
149
0
            rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_SUFFIX,
150
0
                                 sNumSuffix);
151
0
        }
152
153
        // number type: num format
154
0
        OUStringBuffer sBuf;
155
0
        rExport.GetMM100UnitConverter().convertNumFormat( sBuf,
156
0
                                                          nNumberingType );
157
0
        rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
158
0
                             sBuf.makeStringAndClear());
159
160
        // and letter sync, if applicable
161
0
        SvXMLUnitConverter::convertNumLetterSync(
162
0
            sBuf, nNumberingType );
163
0
        if (!sBuf.isEmpty())
164
0
        {
165
0
            rExport.AddAttribute(XML_NAMESPACE_STYLE,
166
0
                                 XML_NUM_LETTER_SYNC,
167
0
                                 sBuf.makeStringAndClear());
168
0
        }
169
0
    }
170
171
    // and finally, the element
172
0
    SvXMLElementExport rElem(rExport, XML_NAMESPACE_TEXT,
173
0
                             XML_NOTES_CONFIGURATION,
174
0
                             true, true);
175
0
}
176
177
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */