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>
28 #include <xmloff/xmlnmspe.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 
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 },
52  { XML_TOKEN_INVALID, 0 }
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  {
63  Reference<XPropertySet> xLineNumbering =
64  xSupplier->getLineNumberingProperties();
65 
66  if (xLineNumbering.is())
67  {
68  // char style
69  Any aAny = xLineNumbering->getPropertyValue("CharStyleName");
70  OUString sTmp;
71  aAny >>= sTmp;
72  if (!sTmp.isEmpty())
73  {
75  rExport.EncodeStyleName( sTmp ));
76  }
77 
78  // enable
79  aAny = xLineNumbering->getPropertyValue("IsOn");
80  if (! *o3tl::doAccess<bool>(aAny))
81  {
84  }
85 
86  // count empty lines
87  aAny = xLineNumbering->getPropertyValue("CountEmptyLines");
88  if (! *o3tl::doAccess<bool>(aAny))
89  {
92  }
93 
94  // count in frames
95  aAny = xLineNumbering->getPropertyValue("CountLinesInFrames");
96  if (*o3tl::doAccess<bool>(aAny))
97  {
100  }
101 
102  // restart numbering
103  aAny = xLineNumbering->getPropertyValue("RestartAtEachPage");
104  if (*o3tl::doAccess<bool>(aAny))
105  {
108  }
109 
110  // Distance
111  aAny = xLineNumbering->getPropertyValue("Distance");
112  sal_Int32 nLength = 0;
113  aAny >>= nLength;
114  if (nLength != 0)
115  {
116  OUStringBuffer sBuf;
118  sBuf, nLength);
120  sBuf.makeStringAndClear());
121  }
122 
123  // NumberingType
124  OUStringBuffer sNumPosBuf;
125  aAny = xLineNumbering->getPropertyValue("NumberingType");
126  sal_Int16 nFormat = 0;
127  aAny >>= nFormat;
128  rExport.GetMM100UnitConverter().convertNumFormat( sNumPosBuf, nFormat );
130  sNumPosBuf.makeStringAndClear());
131  SvXMLUnitConverter::convertNumLetterSync( sNumPosBuf, nFormat );
132  if( !sNumPosBuf.isEmpty() )
133  {
136  sNumPosBuf.makeStringAndClear() );
137  }
138 
139  // number position
140  aAny = xLineNumbering->getPropertyValue("NumberPosition");
141  sal_uInt16 nPosition = 0;
142  aAny >>= nPosition;
143  if (SvXMLUnitConverter::convertEnum(sNumPosBuf, nPosition,
144  aLineNumberPositionMap))
145  {
147  sNumPosBuf.makeStringAndClear());
148  }
149 
150  // sInterval
151  aAny = xLineNumbering->getPropertyValue("Interval");
152  sal_Int16 nLineInterval = 0;
153  aAny >>= nLineInterval;
155  OUString::number(nLineInterval));
156 
159  true, true);
160 
161  // line separator
162  aAny = xLineNumbering->getPropertyValue("SeparatorText");
163  OUString sSeparator;
164  aAny >>= sSeparator;
165  if (!sSeparator.isEmpty())
166  {
167 
168  // SeparatorInterval
169  aAny = xLineNumbering->getPropertyValue("SeparatorInterval");
170  sal_Int16 nLineDistance = 0;
171  aAny >>= nLineDistance;
173  OUString::number(nLineDistance));
174 
177  true, false);
178  rExport.Characters(sSeparator);
179  }
180  }
181  // else: no configuration: don't save -> default
182  }
183  // can't even get supplier: don't save -> default
184 }
185 
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_uInt16 XML_NAMESPACE_STYLE
Definition: xmlnmspe.hxx:30
static bool convertEnum(EnumT &rEnum, const OUString &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:128
bool convertNumFormat(sal_Int16 &rType, const OUString &rNumFormat, const OUString &rNumLetterSync, bool bNumberNone=false) const
convert num-format and num-letter-sync values to NumberingType
Definition: xmluconv.cxx:574
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlexp.hxx:395
constexpr sal_uInt16 XML_NAMESPACE_TEXT
Definition: xmlnmspe.hxx:31
const css::uno::Reference< css::frame::XModel > & GetModel() const
Definition: xmlexp.hxx:415
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:926
SvXMLEnumMapEntry< sal_uInt16 > const aLineNumberPositionMap[]
OUString EncodeStyleName(const OUString &rName, bool *pEncoded=nullptr) const
Definition: xmlexp.cxx:1959
static void convertNumLetterSync(OUStringBuffer &rBuffer, sal_Int16 nType)
Definition: xmluconv.cxx:671
Handling of tokens in XML:
XMLLineNumberingExport(SvXMLExport &rExp)
void Characters(const OUString &rChars)
Definition: xmlexp.cxx:2163
sal_Int32 nLength
Definition: xmltoken.cxx:36
css::uno::Any const SvXMLExport & rExport
Definition: ImageStyle.hxx:38
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit
Definition: xmluconv.cxx:181