Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/text/XMLLineNumberingExport.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 "XMLLineNumberingExport.hxx"
21
#include <com/sun/star/beans/XPropertySet.hpp>
22
#include <com/sun/star/frame/XModel.hpp>
23
#include <com/sun/star/text/XLineNumberingProperties.hpp>
24
#include <com/sun/star/style/LineNumberPosition.hpp>
25
#include <o3tl/any.hxx>
26
#include <xmloff/xmlexp.hxx>
27
#include <xmloff/xmluconv.hxx>
28
#include <xmloff/xmlnamespace.hxx>
29
#include <xmloff/xmltoken.hxx>
30
#include <xmloff/xmlement.hxx>
31
32
33
using namespace ::com::sun::star::uno;
34
using namespace ::com::sun::star;
35
using namespace ::xmloff::token;
36
37
using ::com::sun::star::beans::XPropertySet;
38
using ::com::sun::star::text::XLineNumberingProperties;
39
40
41
XMLLineNumberingExport::XMLLineNumberingExport(SvXMLExport& rExp)
42
0
: rExport(rExp)
43
0
{
44
0
}
45
46
SvXMLEnumMapEntry<sal_uInt16> const aLineNumberPositionMap[] =
47
{
48
    { XML_LEFT,     style::LineNumberPosition::LEFT },
49
    { XML_RIGHT,    style::LineNumberPosition::RIGHT },
50
    { XML_INSIDE,   style::LineNumberPosition::INSIDE },
51
    { XML_OUTSIDE,  style::LineNumberPosition::OUTSIDE },
52
    { XML_TOKEN_INVALID, 0 }
53
};
54
55
56
void XMLLineNumberingExport::Export()
57
0
{
58
    // export element if we have line numbering info
59
0
    Reference<XLineNumberingProperties> xSupplier(rExport.GetModel(),
60
0
                                                  UNO_QUERY);
61
0
    if (!xSupplier.is())
62
0
        return;
63
64
0
    Reference<XPropertySet> xLineNumbering =
65
0
        xSupplier->getLineNumberingProperties();
66
67
0
    if (!xLineNumbering.is())
68
0
        return;
69
70
    // char style
71
0
    Any aAny = xLineNumbering->getPropertyValue(u"CharStyleName"_ustr);
72
0
    OUString sTmp;
73
0
    aAny >>= sTmp;
74
0
    if (!sTmp.isEmpty())
75
0
    {
76
0
        rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
77
0
                             rExport.EncodeStyleName( sTmp ));
78
0
    }
79
80
    // enable
81
0
    aAny = xLineNumbering->getPropertyValue(u"IsOn"_ustr);
82
0
    if (! *o3tl::doAccess<bool>(aAny))
83
0
    {
84
0
        rExport.AddAttribute(XML_NAMESPACE_TEXT,
85
0
                             XML_NUMBER_LINES, XML_FALSE);
86
0
    }
87
88
    // count empty lines
89
0
    aAny = xLineNumbering->getPropertyValue(u"CountEmptyLines"_ustr);
90
0
    if (! *o3tl::doAccess<bool>(aAny))
91
0
    {
92
0
        rExport.AddAttribute(XML_NAMESPACE_TEXT,
93
0
                             XML_COUNT_EMPTY_LINES, XML_FALSE);
94
0
    }
95
96
    // count in frames
97
0
    aAny = xLineNumbering->getPropertyValue(u"CountLinesInFrames"_ustr);
98
0
    if (*o3tl::doAccess<bool>(aAny))
99
0
    {
100
0
        rExport.AddAttribute(XML_NAMESPACE_TEXT,
101
0
                             XML_COUNT_IN_TEXT_BOXES, XML_TRUE);
102
0
    }
103
104
    // restart numbering
105
0
    aAny = xLineNumbering->getPropertyValue(u"RestartAtEachPage"_ustr);
106
0
    if (*o3tl::doAccess<bool>(aAny))
107
0
    {
108
0
        rExport.AddAttribute(XML_NAMESPACE_TEXT,
109
0
                             XML_RESTART_ON_PAGE, XML_TRUE);
110
0
    }
111
112
    // Distance
113
0
    aAny = xLineNumbering->getPropertyValue(u"Distance"_ustr);
114
0
    sal_Int32 nLength = 0;
115
0
    aAny >>= nLength;
116
0
    if (nLength != 0)
117
0
    {
118
0
        OUStringBuffer sBuf;
119
0
        rExport.GetMM100UnitConverter().convertMeasureToXML(
120
0
                sBuf, nLength);
121
0
        rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OFFSET,
122
0
                             sBuf.makeStringAndClear());
123
0
    }
124
125
    // NumberingType
126
0
    OUStringBuffer sNumPosBuf;
127
0
    aAny = xLineNumbering->getPropertyValue(u"NumberingType"_ustr);
128
0
    sal_Int16 nFormat = 0;
129
0
    aAny >>= nFormat;
130
0
    rExport.GetMM100UnitConverter().convertNumFormat( sNumPosBuf, nFormat );
131
0
    rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
132
0
                         sNumPosBuf.makeStringAndClear());
133
0
    SvXMLUnitConverter::convertNumLetterSync( sNumPosBuf, nFormat );
134
0
    if( !sNumPosBuf.isEmpty() )
135
0
    {
136
0
        rExport.AddAttribute(XML_NAMESPACE_STYLE,
137
0
                             XML_NUM_LETTER_SYNC,
138
0
                             sNumPosBuf.makeStringAndClear() );
139
0
    }
140
141
    // number position
142
0
    aAny = xLineNumbering->getPropertyValue(u"NumberPosition"_ustr);
143
0
    sal_uInt16 nPosition = 0;
144
0
    aAny >>= nPosition;
145
0
    if (SvXMLUnitConverter::convertEnum(sNumPosBuf, nPosition,
146
0
                                        aLineNumberPositionMap))
147
0
    {
148
0
        rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NUMBER_POSITION,
149
0
                             sNumPosBuf.makeStringAndClear());
150
0
    }
151
152
    // sInterval
153
0
    aAny = xLineNumbering->getPropertyValue(u"Interval"_ustr);
154
0
    sal_Int16 nLineInterval = 0;
155
0
    aAny >>= nLineInterval;
156
0
    rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
157
0
                         OUString::number(nLineInterval));
158
159
0
    SvXMLElementExport aConfigElem(rExport, XML_NAMESPACE_TEXT,
160
0
                                   XML_LINENUMBERING_CONFIGURATION,
161
0
                                   true, true);
162
163
    // line separator
164
0
    aAny = xLineNumbering->getPropertyValue(u"SeparatorText"_ustr);
165
0
    OUString sSeparator;
166
0
    aAny >>= sSeparator;
167
0
    if (sSeparator.isEmpty())
168
0
        return;
169
170
    // SeparatorInterval
171
0
    aAny = xLineNumbering->getPropertyValue(u"SeparatorInterval"_ustr);
172
0
    sal_Int16 nLineDistance = 0;
173
0
    aAny >>= nLineDistance;
174
0
    rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
175
0
                         OUString::number(nLineDistance));
176
177
0
    SvXMLElementExport aSeparatorElem(rExport, XML_NAMESPACE_TEXT,
178
0
                                      XML_LINENUMBERING_SEPARATOR,
179
0
                                      true, false);
180
0
    rExport.Characters(sSeparator);
181
    // else: no configuration: don't save -> default
182
    // can't even get supplier: don't save -> default
183
0
}
184
185
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */