LibreOffice Module xmloff (master) 1
XMLLineNumberingImportContext.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
22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <com/sun/star/frame/XModel.hpp>
24#include <com/sun/star/text/XLineNumberingProperties.hpp>
25#include <com/sun/star/style/LineNumberPosition.hpp>
26#include <com/sun/star/style/NumberingType.hpp>
28#include <xmloff/xmlimp.hxx>
29#include <xmloff/xmluconv.hxx>
32#include <xmloff/xmltoken.hxx>
33#include <xmloff/xmlement.hxx>
34
35
36using namespace ::com::sun::star;
37using namespace ::com::sun::star::uno;
38using namespace ::com::sun::star::style;
39using namespace ::xmloff::token;
40
41using ::com::sun::star::beans::XPropertySet;
42using ::com::sun::star::xml::sax::XFastAttributeList;
43using ::com::sun::star::text::XLineNumberingProperties;
44
45
46constexpr OUStringLiteral gsCharStyleName(u"CharStyleName");
47constexpr OUStringLiteral gsCountEmptyLines(u"CountEmptyLines");
48constexpr OUStringLiteral gsCountLinesInFrames(u"CountLinesInFrames");
49constexpr OUStringLiteral gsDistance(u"Distance");
50constexpr OUStringLiteral gsInterval(u"Interval");
51constexpr OUStringLiteral gsSeparatorText(u"SeparatorText");
52constexpr OUStringLiteral gsNumberPosition(u"NumberPosition");
53constexpr OUStringLiteral gsNumberingType(u"NumberingType");
54constexpr OUStringLiteral gsIsOn(u"IsOn");
55constexpr OUStringLiteral gsRestartAtEachPage(u"RestartAtEachPage");
56constexpr OUStringLiteral gsSeparatorInterval(u"SeparatorInterval");
57
59 SvXMLImport& rImport)
61, sNumFormat(GetXMLToken(XML_1))
62, sNumLetterSync(GetXMLToken(XML_FALSE))
63, nOffset(-1)
64, nNumberPosition(style::LineNumberPosition::LEFT)
65, nIncrement(-1)
66, nSeparatorIncrement(-1)
67, bNumberLines(true)
68, bCountEmptyLines(true)
69, bCountInFloatingFrames(false)
70, bRestartNumbering(false)
71{
72}
73
75{
76}
77
79 const OUString& rValue )
80{
81 bool bTmp(false);
82 sal_Int32 nTmp;
83
84 switch (nElement)
85 {
87 sStyleName = rValue;
88 break;
89
91 if (::sax::Converter::convertBool(bTmp, rValue))
92 {
93 bNumberLines = bTmp;
94 }
95 break;
96
98 if (::sax::Converter::convertBool(bTmp, rValue))
99 {
100 bCountEmptyLines = bTmp;
101 }
102 break;
103
105 if (::sax::Converter::convertBool(bTmp, rValue))
106 {
108 }
109 break;
110
112 if (::sax::Converter::convertBool(bTmp, rValue))
113 {
114 bRestartNumbering = bTmp;
115 }
116 break;
117
119 if (GetImport().GetMM100UnitConverter().
120 convertMeasureToCore(nTmp, rValue))
121 {
122 nOffset = nTmp;
123 }
124 break;
125
127 sNumFormat = rValue;
128 break;
129
131 sNumLetterSync = rValue;
132 break;
133
135 {
137 {
138 { XML_LEFT, style::LineNumberPosition::LEFT },
139 { XML_RIGHT, style::LineNumberPosition::RIGHT },
140 { XML_INSIDE, style::LineNumberPosition::INSIDE },
141 { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE },
142 { XML_TOKEN_INVALID, 0 }
143 };
144
147 break;
148 }
149
151 if (::sax::Converter::convertNumber(nTmp, rValue, 0))
152 {
153 nIncrement = static_cast<sal_Int16>(nTmp);
154 }
155 break;
156 }
157}
158
160{
161 // insert and block mode is handled in insertStyleFamily
162
163 // we'll try to get the LineNumberingProperties
164 Reference<XLineNumberingProperties> xSupplier(GetImport().GetModel(),
165 UNO_QUERY);
166 if (!xSupplier.is())
167 return;
168
169 Reference<XPropertySet> xLineNumbering =
170 xSupplier->getLineNumberingProperties();
171
172 if (!xLineNumbering.is())
173 return;
174
175 Any aAny;
176
177 // set style name (if it exists)
178 if ( GetImport().GetStyles()->FindStyleChildContext(
180 {
181 aAny <<= GetImport().GetStyleDisplayName(
183 xLineNumbering->setPropertyValue(gsCharStyleName, aAny);
184 }
185
186 xLineNumbering->setPropertyValue(gsSeparatorText, Any(sSeparator));
187 xLineNumbering->setPropertyValue(gsDistance, Any(nOffset));
188 xLineNumbering->setPropertyValue(gsNumberPosition, Any(nNumberPosition));
189
190 if (nIncrement >= 0)
191 {
192 xLineNumbering->setPropertyValue(gsInterval, Any(nIncrement));
193 }
194
195 if (nSeparatorIncrement >= 0)
196 {
197 xLineNumbering->setPropertyValue(gsSeparatorInterval, Any(nSeparatorIncrement));
198 }
199
200 xLineNumbering->setPropertyValue(gsIsOn, Any(bNumberLines));
201 xLineNumbering->setPropertyValue(gsCountEmptyLines, Any(bCountEmptyLines));
202 xLineNumbering->setPropertyValue(gsCountLinesInFrames, Any(bCountInFloatingFrames));
203 xLineNumbering->setPropertyValue(gsRestartAtEachPage, Any(bRestartNumbering));
204
205 sal_Int16 nNumType = NumberingType::ARABIC;
206 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
209 xLineNumbering->setPropertyValue(gsNumberingType, Any(nNumType));
210}
211
212css::uno::Reference< css::xml::sax::XFastContextHandler > XMLLineNumberingImportContext::createFastChildContext(
213 sal_Int32 nElement,
214 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
215{
216 if ( nElement == XML_ELEMENT(TEXT, XML_LINENUMBERING_SEPARATOR) )
218 return nullptr;
219}
220
222 const OUString& sText)
223{
224 sSeparator = sText;
225}
226
228 sal_Int16 nIncr)
229{
230 nSeparatorIncrement = nIncr;
231}
232
233/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLEnumMapEntry< sal_uInt16 > const aLineNumberPositionMap[]
constexpr OUStringLiteral gsDistance(u"Distance")
constexpr OUStringLiteral gsCountLinesInFrames(u"CountLinesInFrames")
constexpr OUStringLiteral gsNumberingType(u"NumberingType")
constexpr OUStringLiteral gsCharStyleName(u"CharStyleName")
constexpr OUStringLiteral gsNumberPosition(u"NumberPosition")
constexpr OUStringLiteral gsRestartAtEachPage(u"RestartAtEachPage")
constexpr OUStringLiteral gsInterval(u"Interval")
constexpr OUStringLiteral gsIsOn(u"IsOn")
constexpr OUStringLiteral gsSeparatorText(u"SeparatorText")
constexpr OUStringLiteral gsSeparatorInterval(u"SeparatorInterval")
constexpr OUStringLiteral gsCountEmptyLines(u"CountEmptyLines")
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
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
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override
void SetSeparatorText(const OUString &sText)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
virtual void CreateAndInsert(bool bOverwrite) override
import <text:linenumbering-separator> elements
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
static bool convertBool(bool &rBool, std::u16string_view rString)
XmlStyleFamily
Definition: families.hxx:50
LineNumberPosition
sal_Int16 nNumType
const sal_uInt32 LEFT
Handling of tokens in XML:
@ XML_COUNT_IN_TEXT_BOXES
Definition: xmltoken.hxx:2706
@ XML_LINENUMBERING_SEPARATOR
Definition: xmltoken.hxx:1208
@ XML_COUNT_EMPTY_LINES
Definition: xmltoken.hxx:533
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541
TEXT
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97