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>
27 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <xmloff/namespacemap.hxx>
32 #include <xmloff/xmltoken.hxx>
33 #include <xmloff/xmlement.hxx>
34 
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::style;
39 using namespace ::xmloff::token;
40 
41 using ::com::sun::star::beans::XPropertySet;
42 using ::com::sun::star::xml::sax::XAttributeList;
43 using ::com::sun::star::xml::sax::XFastAttributeList;
44 using ::com::sun::star::text::XLineNumberingProperties;
45 
46 
47 constexpr OUStringLiteral gsCharStyleName(u"CharStyleName");
48 constexpr OUStringLiteral gsCountEmptyLines(u"CountEmptyLines");
49 constexpr OUStringLiteral gsCountLinesInFrames(u"CountLinesInFrames");
50 constexpr OUStringLiteral gsDistance(u"Distance");
51 constexpr OUStringLiteral gsInterval(u"Interval");
52 constexpr OUStringLiteral gsSeparatorText(u"SeparatorText");
53 constexpr OUStringLiteral gsNumberPosition(u"NumberPosition");
54 constexpr OUStringLiteral gsNumberingType(u"NumberingType");
55 constexpr OUStringLiteral gsIsOn(u"IsOn");
56 constexpr OUStringLiteral gsRestartAtEachPage(u"RestartAtEachPage");
57 constexpr 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  {
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  {
108  bCountInFloatingFrames = bTmp;
109  }
110  break;
111 
113  if (::sax::Converter::convertBool(bTmp, rValue))
114  {
115  bRestartNumbering = bTmp;
116  }
117  break;
118 
119  case XML_ELEMENT(TEXT, XML_OFFSET):
120  if (GetImport().GetMM100UnitConverter().
121  convertMeasureToCore(nTmp, rValue))
122  {
123  nOffset = nTmp;
124  }
125  break;
126 
128  sNumFormat = rValue;
129  break;
130 
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 
147  aLineNumberPositionMap);
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)
180  XmlStyleFamily::TEXT_TEXT, sStyleName ) != nullptr )
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;
208  sNumFormat,
209  sNumLetterSync );
210  xLineNumbering->setPropertyValue(gsNumberingType, Any(nNumType));
211 }
212 
213 css::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: */
constexpr OUStringLiteral gsSeparatorText(u"SeparatorText")
constexpr OUStringLiteral gsSeparatorInterval(u"SeparatorInterval")
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
constexpr OUStringLiteral gsNumberPosition(u"NumberPosition")
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
XmlStyleFamily
Definition: families.hxx:47
virtual void CreateAndInsert(bool bOverwrite) override
constexpr OUStringLiteral gsDistance(u"Distance")
sal_Int16 nNumType
constexpr OUStringLiteral gsIsOn(u"IsOn")
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:701
SvXMLStylesContext * GetStyles()
Definition: xmlimp.cxx:1583
SvXMLEnumMapEntry< sal_uInt16 > const aLineNumberPositionMap[]
void SetSeparatorText(const OUString &sText)
constexpr OUStringLiteral gsCountLinesInFrames(u"CountLinesInFrames")
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
LineNumberPosition
exports com.sun.star. style
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override
static bool convertBool(bool &rBool, std::u16string_view rString)
constexpr OUStringLiteral gsCharStyleName(u"CharStyleName")
Map an XMLTokenEnum to an enum value.
Definition: ximpshap.hxx:39
const sal_uInt32 LEFT
constexpr OUStringLiteral gsNumberingType(u"NumberingType")
OUString GetStyleDisplayName(XmlStyleFamily nFamily, const OUString &rName) const
Definition: xmlimp.cxx:1412
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3426
constexpr OUStringLiteral gsCountEmptyLines(u"CountEmptyLines")
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:96
constexpr OUStringLiteral gsRestartAtEachPage(u"RestartAtEachPage")
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
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlimp.hxx:399
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
Definition: xmlstyle.cxx:788
TEXT
constexpr OUStringLiteral gsInterval(u"Interval")
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo