LibreOffice Module xmloff (master) 1
XMLLineNumberingExport.cxx
Go to the documentation of this file.
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
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>
29#include <xmloff/xmltoken.hxx>
30#include <xmloff/xmlement.hxx>
31
32
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star;
35using namespace ::xmloff::token;
36
37using ::com::sun::star::beans::XPropertySet;
38using ::com::sun::star::text::XLineNumberingProperties;
39
40
42: rExport(rExp)
43{
44}
45
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 },
53};
54
55
57{
58 // export element if we have line numbering info
59 Reference<XLineNumberingProperties> xSupplier(rExport.GetModel(),
60 UNO_QUERY);
61 if (!xSupplier.is())
62 return;
63
64 Reference<XPropertySet> xLineNumbering =
65 xSupplier->getLineNumberingProperties();
66
67 if (!xLineNumbering.is())
68 return;
69
70 // char style
71 Any aAny = xLineNumbering->getPropertyValue("CharStyleName");
72 OUString sTmp;
73 aAny >>= sTmp;
74 if (!sTmp.isEmpty())
75 {
77 rExport.EncodeStyleName( sTmp ));
78 }
79
80 // enable
81 aAny = xLineNumbering->getPropertyValue("IsOn");
82 if (! *o3tl::doAccess<bool>(aAny))
83 {
86 }
87
88 // count empty lines
89 aAny = xLineNumbering->getPropertyValue("CountEmptyLines");
90 if (! *o3tl::doAccess<bool>(aAny))
91 {
94 }
95
96 // count in frames
97 aAny = xLineNumbering->getPropertyValue("CountLinesInFrames");
98 if (*o3tl::doAccess<bool>(aAny))
99 {
102 }
103
104 // restart numbering
105 aAny = xLineNumbering->getPropertyValue("RestartAtEachPage");
106 if (*o3tl::doAccess<bool>(aAny))
107 {
110 }
111
112 // Distance
113 aAny = xLineNumbering->getPropertyValue("Distance");
114 sal_Int32 nLength = 0;
115 aAny >>= nLength;
116 if (nLength != 0)
117 {
118 OUStringBuffer sBuf;
120 sBuf, nLength);
122 sBuf.makeStringAndClear());
123 }
124
125 // NumberingType
126 OUStringBuffer sNumPosBuf;
127 aAny = xLineNumbering->getPropertyValue("NumberingType");
128 sal_Int16 nFormat = 0;
129 aAny >>= nFormat;
130 rExport.GetMM100UnitConverter().convertNumFormat( sNumPosBuf, nFormat );
132 sNumPosBuf.makeStringAndClear());
133 SvXMLUnitConverter::convertNumLetterSync( sNumPosBuf, nFormat );
134 if( !sNumPosBuf.isEmpty() )
135 {
138 sNumPosBuf.makeStringAndClear() );
139 }
140
141 // number position
142 aAny = xLineNumbering->getPropertyValue("NumberPosition");
143 sal_uInt16 nPosition = 0;
144 aAny >>= nPosition;
145 if (SvXMLUnitConverter::convertEnum(sNumPosBuf, nPosition,
147 {
149 sNumPosBuf.makeStringAndClear());
150 }
151
152 // sInterval
153 aAny = xLineNumbering->getPropertyValue("Interval");
154 sal_Int16 nLineInterval = 0;
155 aAny >>= nLineInterval;
157 OUString::number(nLineInterval));
158
161 true, true);
162
163 // line separator
164 aAny = xLineNumbering->getPropertyValue("SeparatorText");
165 OUString sSeparator;
166 aAny >>= sSeparator;
167 if (sSeparator.isEmpty())
168 return;
169
170 // SeparatorInterval
171 aAny = xLineNumbering->getPropertyValue("SeparatorInterval");
172 sal_Int16 nLineDistance = 0;
173 aAny >>= nLineDistance;
175 OUString::number(nLineDistance));
176
179 true, false);
180 rExport.Characters(sSeparator);
181 // else: no configuration: don't save -> default
182 // can't even get supplier: don't save -> default
183}
184
185/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLEnumMapEntry< sal_uInt16 > const aLineNumberPositionMap[]
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
Definition: xmlexp.cxx:911
void Characters(const OUString &rChars)
Definition: xmlexp.cxx:2133
const css::uno::Reference< css::frame::XModel > & GetModel() const
Definition: xmlexp.hxx:416
OUString EncodeStyleName(const OUString &rName, bool *pEncoded=nullptr) const
Definition: xmlexp.cxx:1938
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlexp.hxx:396
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:145
bool convertNumFormat(sal_Int16 &rType, const OUString &rNumFormat, std::u16string_view rNumLetterSync, bool bNumberNone=false) const
convert num-format and num-letter-sync values to NumberingType
Definition: xmluconv.cxx:654
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit
Definition: xmluconv.cxx:207
static void convertNumLetterSync(OUStringBuffer &rBuffer, sal_Int16 nType)
Definition: xmluconv.cxx:751
XMLLineNumberingExport(SvXMLExport &rExp)
Handling of tokens in XML:
@ XML_LINENUMBERING_CONFIGURATION
Definition: xmltoken.hxx:1204
@ XML_COUNT_IN_TEXT_BOXES
Definition: xmltoken.hxx:2699
@ XML_LINENUMBERING_SEPARATOR
Definition: xmltoken.hxx:1205
@ XML_COUNT_EMPTY_LINES
Definition: xmltoken.hxx:531
constexpr sal_uInt16 XML_NAMESPACE_TEXT
constexpr sal_uInt16 XML_NAMESPACE_STYLE
sal_Int32 nLength
Definition: xmltoken.cxx:38