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::XAttributeList;
43using ::com::sun::star::xml::sax::XFastAttributeList;
44using ::com::sun::star::text::XLineNumberingProperties;
45
46
47constexpr OUStringLiteral gsCharStyleName(u"CharStyleName");
48constexpr OUStringLiteral gsCountEmptyLines(u"CountEmptyLines");
49constexpr OUStringLiteral gsCountLinesInFrames(u"CountLinesInFrames");
50constexpr OUStringLiteral gsDistance(u"Distance");
51constexpr OUStringLiteral gsInterval(u"Interval");
52constexpr OUStringLiteral gsSeparatorText(u"SeparatorText");
53constexpr OUStringLiteral gsNumberPosition(u"NumberPosition");
54constexpr OUStringLiteral gsNumberingType(u"NumberingType");
55constexpr OUStringLiteral gsIsOn(u"IsOn");
56constexpr OUStringLiteral gsRestartAtEachPage(u"RestartAtEachPage");
57constexpr OUStringLiteral gsSeparatorInterval(u"SeparatorInterval");
58
60 SvXMLImport& rImport)
62, sNumFormat(GetXMLToken(XML_1))
63, sNumLetterSync(GetXMLToken(XML_FALSE))
64, nOffset(-1)
65, nNumberPosition(style::LineNumberPosition::LEFT)
66, nIncrement(-1)
67, nSeparatorIncrement(-1)
68, bNumberLines(true)
69, bCountEmptyLines(true)
70, bCountInFloatingFrames(false)
71, bRestartNumbering(false)
72{
73}
74
76{
77}
78
80 const OUString& rValue )
81{
82 bool bTmp(false);
83 sal_Int32 nTmp;
84
85 switch (nElement)
86 {
88 sStyleName = rValue;
89 break;
90
92 if (::sax::Converter::convertBool(bTmp, rValue))
93 {
94 bNumberLines = bTmp;
95 }
96 break;
97
99 if (::sax::Converter::convertBool(bTmp, rValue))
100 {
101 bCountEmptyLines = bTmp;
102 }
103 break;
104
106 if (::sax::Converter::convertBool(bTmp, rValue))
107 {
109 }
110 break;
111
113 if (::sax::Converter::convertBool(bTmp, rValue))
114 {
115 bRestartNumbering = bTmp;
116 }
117 break;
118
120 if (GetImport().GetMM100UnitConverter().
121 convertMeasureToCore(nTmp, rValue))
122 {
123 nOffset = nTmp;
124 }
125 break;
126
128 sNumFormat = rValue;
129 break;
130
132 sNumLetterSync = rValue;
133 break;
134
136 {
138 {
139 { XML_LEFT, style::LineNumberPosition::LEFT },
140 { XML_RIGHT, style::LineNumberPosition::RIGHT },
141 { XML_INSIDE, style::LineNumberPosition::INSIDE },
142 { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE },
143 { XML_TOKEN_INVALID, 0 }
144 };
145
148 break;
149 }
150
152 if (::sax::Converter::convertNumber(nTmp, rValue, 0))
153 {
154 nIncrement = static_cast<sal_Int16>(nTmp);
155 }
156 break;
157 }
158}
159
161{
162 // insert and block mode is handled in insertStyleFamily
163
164 // we'll try to get the LineNumberingProperties
165 Reference<XLineNumberingProperties> xSupplier(GetImport().GetModel(),
166 UNO_QUERY);
167 if (!xSupplier.is())
168 return;
169
170 Reference<XPropertySet> xLineNumbering =
171 xSupplier->getLineNumberingProperties();
172
173 if (!xLineNumbering.is())
174 return;
175
176 Any aAny;
177
178 // set style name (if it exists)
179 if ( GetImport().GetStyles()->FindStyleChildContext(
181 {
182 aAny <<= GetImport().GetStyleDisplayName(
184 xLineNumbering->setPropertyValue(gsCharStyleName, aAny);
185 }
186
187 xLineNumbering->setPropertyValue(gsSeparatorText, Any(sSeparator));
188 xLineNumbering->setPropertyValue(gsDistance, Any(nOffset));
189 xLineNumbering->setPropertyValue(gsNumberPosition, Any(nNumberPosition));
190
191 if (nIncrement >= 0)
192 {
193 xLineNumbering->setPropertyValue(gsInterval, Any(nIncrement));
194 }
195
196 if (nSeparatorIncrement >= 0)
197 {
198 xLineNumbering->setPropertyValue(gsSeparatorInterval, Any(nSeparatorIncrement));
199 }
200
201 xLineNumbering->setPropertyValue(gsIsOn, Any(bNumberLines));
202 xLineNumbering->setPropertyValue(gsCountEmptyLines, Any(bCountEmptyLines));
203 xLineNumbering->setPropertyValue(gsCountLinesInFrames, Any(bCountInFloatingFrames));
204 xLineNumbering->setPropertyValue(gsRestartAtEachPage, Any(bRestartNumbering));
205
206 sal_Int16 nNumType = NumberingType::ARABIC;
207 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
210 xLineNumbering->setPropertyValue(gsNumberingType, Any(nNumType));
211}
212
213css::uno::Reference< css::xml::sax::XFastContextHandler > XMLLineNumberingImportContext::createFastChildContext(
214 sal_Int32 nElement,
215 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
216{
217 if ( nElement == XML_ELEMENT(TEXT, XML_LINENUMBERING_SEPARATOR) )
219 return nullptr;
220}
221
223 const OUString& sText)
224{
225 sSeparator = sText;
226}
227
229 sal_Int16 nIncr)
230{
231 nSeparatorIncrement = nIncr;
232}
233
234/* 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:2700
@ XML_LINENUMBERING_SEPARATOR
Definition: xmltoken.hxx:1205
@ XML_COUNT_EMPTY_LINES
Definition: xmltoken.hxx:531
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3529
TEXT
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97