bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / XMLLineNumberingExport.cxx
blob7bd89c31ed143ce92709e86dd646ededff186aa2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "XMLLineNumberingExport.hxx"
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <com/sun/star/text/XLineNumberingProperties.hpp>
23 #include <com/sun/star/style/LineNumberPosition.hpp>
24 #include <sax/tools/converter.hxx>
25 #include <xmloff/xmlexp.hxx>
26 #include <xmloff/xmluconv.hxx>
27 #include <xmloff/xmlnmspe.hxx>
28 #include <xmloff/xmltoken.hxx>
29 #include <xmloff/xmlnume.hxx>
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star;
34 using namespace ::xmloff::token;
36 using ::com::sun::star::beans::XPropertySet;
37 using ::com::sun::star::text::XLineNumberingProperties;
40 XMLLineNumberingExport::XMLLineNumberingExport(SvXMLExport& rExp)
41 : sCharStyleName("CharStyleName")
42 , sCountEmptyLines("CountEmptyLines")
43 , sCountLinesInFrames("CountLinesInFrames")
44 , sDistance("Distance")
45 , sInterval("Interval")
46 , sSeparatorText("SeparatorText")
47 , sNumberPosition("NumberPosition")
48 , sNumberingType("NumberingType")
49 , sIsOn("IsOn")
50 , sRestartAtEachPage("RestartAtEachPage")
51 , sSeparatorInterval("SeparatorInterval")
52 , rExport(rExp)
56 SvXMLEnumMapEntry const aLineNumberPositionMap[] =
58 { XML_LEFT, style::LineNumberPosition::LEFT },
59 { XML_RIGHT, style::LineNumberPosition::RIGHT },
60 { XML_INSIDE, style::LineNumberPosition::INSIDE },
61 { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE },
62 { XML_TOKEN_INVALID, 0 }
67 void XMLLineNumberingExport::Export()
69 // export element if we have line numbering info
70 Reference<XLineNumberingProperties> xSupplier(rExport.GetModel(),
71 UNO_QUERY);
72 if (xSupplier.is())
74 Reference<XPropertySet> xLineNumbering =
75 xSupplier->getLineNumberingProperties();
77 if (xLineNumbering.is())
79 Any aAny;
81 // char style
82 aAny = xLineNumbering->getPropertyValue(sCharStyleName);
83 OUString sTmp;
84 aAny >>= sTmp;
85 if (!sTmp.isEmpty())
87 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
88 rExport.EncodeStyleName( sTmp ));
91 // enable
92 aAny = xLineNumbering->getPropertyValue(sIsOn);
93 if (! *static_cast<sal_Bool const *>(aAny.getValue()))
95 rExport.AddAttribute(XML_NAMESPACE_TEXT,
96 XML_NUMBER_LINES, XML_FALSE);
99 // count empty lines
100 aAny = xLineNumbering->getPropertyValue(sCountEmptyLines);
101 if (! *static_cast<sal_Bool const *>(aAny.getValue()))
103 rExport.AddAttribute(XML_NAMESPACE_TEXT,
104 XML_COUNT_EMPTY_LINES, XML_FALSE);
107 // count in frames
108 aAny = xLineNumbering->getPropertyValue(sCountLinesInFrames);
109 if (*static_cast<sal_Bool const *>(aAny.getValue()))
111 rExport.AddAttribute(XML_NAMESPACE_TEXT,
112 XML_COUNT_IN_TEXT_BOXES, XML_TRUE);
115 // restart numbering
116 aAny = xLineNumbering->getPropertyValue(sRestartAtEachPage);
117 if (*static_cast<sal_Bool const *>(aAny.getValue()))
119 rExport.AddAttribute(XML_NAMESPACE_TEXT,
120 XML_RESTART_ON_PAGE, XML_TRUE);
123 // Distance
124 aAny = xLineNumbering->getPropertyValue(sDistance);
125 sal_Int32 nLength = 0;
126 aAny >>= nLength;
127 if (nLength != 0)
129 OUStringBuffer sBuf;
130 rExport.GetMM100UnitConverter().convertMeasureToXML(
131 sBuf, nLength);
132 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OFFSET,
133 sBuf.makeStringAndClear());
136 // NumeringType
137 OUStringBuffer sNumPosBuf;
138 aAny = xLineNumbering->getPropertyValue(sNumberingType);
139 sal_Int16 nFormat = 0;
140 aAny >>= nFormat;
141 rExport.GetMM100UnitConverter().convertNumFormat( sNumPosBuf, nFormat );
142 rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
143 sNumPosBuf.makeStringAndClear());
144 SvXMLUnitConverter::convertNumLetterSync( sNumPosBuf, nFormat );
145 if( !sNumPosBuf.isEmpty() )
147 rExport.AddAttribute(XML_NAMESPACE_STYLE,
148 XML_NUM_LETTER_SYNC,
149 sNumPosBuf.makeStringAndClear() );
152 // number position
153 aAny = xLineNumbering->getPropertyValue(sNumberPosition);
154 sal_Int16 nPosition = 0;
155 aAny >>= nPosition;
156 if (SvXMLUnitConverter::convertEnum(sNumPosBuf, nPosition,
157 aLineNumberPositionMap))
159 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NUMBER_POSITION,
160 sNumPosBuf.makeStringAndClear());
163 // sInterval
164 aAny = xLineNumbering->getPropertyValue(sInterval);
165 sal_Int16 nLineInterval = 0;
166 aAny >>= nLineInterval;
167 OUStringBuffer sBuf;
168 ::sax::Converter::convertNumber(sBuf,
169 (sal_Int32)nLineInterval);
170 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
171 sBuf.makeStringAndClear());
173 SvXMLElementExport aConfigElem(rExport, XML_NAMESPACE_TEXT,
174 XML_LINENUMBERING_CONFIGURATION,
175 true, true);
177 // line separator
178 aAny = xLineNumbering->getPropertyValue(sSeparatorText);
179 OUString sSeparator;
180 aAny >>= sSeparator;
181 if (!sSeparator.isEmpty())
184 // SeparatorInterval
185 aAny = xLineNumbering->getPropertyValue(sSeparatorInterval);
186 sal_Int16 nLineDistance = 0;
187 aAny >>= nLineDistance;
188 ::sax::Converter::convertNumber(sBuf,
189 (sal_Int32)nLineDistance);
190 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
191 sBuf.makeStringAndClear());
193 SvXMLElementExport aSeparatorElem(rExport, XML_NAMESPACE_TEXT,
194 XML_LINENUMBERING_SEPARATOR,
195 true, false);
196 rExport.Characters(sSeparator);
199 // else: no configuration: don't save -> default
201 // can't even get supplier: don't save -> default
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */