Line data Source code
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 :
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>
30 :
31 :
32 : using namespace ::com::sun::star::uno;
33 : using namespace ::com::sun::star;
34 : using namespace ::xmloff::token;
35 :
36 : using ::rtl::OUString;
37 : using ::rtl::OUStringBuffer;
38 : using ::com::sun::star::beans::XPropertySet;
39 : using ::com::sun::star::text::XLineNumberingProperties;
40 :
41 :
42 2 : XMLLineNumberingExport::XMLLineNumberingExport(SvXMLExport& rExp)
43 : : sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName"))
44 : , sCountEmptyLines(RTL_CONSTASCII_USTRINGPARAM("CountEmptyLines"))
45 : , sCountLinesInFrames(RTL_CONSTASCII_USTRINGPARAM("CountLinesInFrames"))
46 : , sDistance(RTL_CONSTASCII_USTRINGPARAM("Distance"))
47 : , sInterval(RTL_CONSTASCII_USTRINGPARAM("Interval"))
48 : , sSeparatorText(RTL_CONSTASCII_USTRINGPARAM("SeparatorText"))
49 : , sNumberPosition(RTL_CONSTASCII_USTRINGPARAM("NumberPosition"))
50 : , sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType"))
51 : , sIsOn(RTL_CONSTASCII_USTRINGPARAM("IsOn"))
52 : , sRestartAtEachPage(RTL_CONSTASCII_USTRINGPARAM("RestartAtEachPage"))
53 : , sSeparatorInterval(RTL_CONSTASCII_USTRINGPARAM("SeparatorInterval"))
54 2 : , rExport(rExp)
55 : {
56 2 : }
57 :
58 : SvXMLEnumMapEntry const aLineNumberPositionMap[] =
59 : {
60 : { XML_LEFT, style::LineNumberPosition::LEFT },
61 : { XML_RIGHT, style::LineNumberPosition::RIGHT },
62 : { XML_INSIDE, style::LineNumberPosition::INSIDE },
63 : { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE },
64 : { XML_TOKEN_INVALID, 0 }
65 : };
66 :
67 :
68 :
69 2 : void XMLLineNumberingExport::Export()
70 : {
71 : // export element if we have line numbering info
72 2 : Reference<XLineNumberingProperties> xSupplier(rExport.GetModel(),
73 2 : UNO_QUERY);
74 2 : if (xSupplier.is())
75 : {
76 : Reference<XPropertySet> xLineNumbering =
77 2 : xSupplier->getLineNumberingProperties();
78 :
79 2 : if (xLineNumbering.is())
80 : {
81 2 : Any aAny;
82 :
83 : // char style
84 2 : aAny = xLineNumbering->getPropertyValue(sCharStyleName);
85 2 : OUString sTmp;
86 2 : aAny >>= sTmp;
87 2 : if (!sTmp.isEmpty())
88 : {
89 : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
90 0 : rExport.EncodeStyleName( sTmp ));
91 : }
92 :
93 : // enable
94 2 : aAny = xLineNumbering->getPropertyValue(sIsOn);
95 2 : if (! *(sal_Bool*)aAny.getValue())
96 : {
97 : rExport.AddAttribute(XML_NAMESPACE_TEXT,
98 2 : XML_NUMBER_LINES, XML_FALSE);
99 : }
100 :
101 : // count empty lines
102 2 : aAny = xLineNumbering->getPropertyValue(sCountEmptyLines);
103 2 : if (! *(sal_Bool*)aAny.getValue())
104 : {
105 : rExport.AddAttribute(XML_NAMESPACE_TEXT,
106 0 : XML_COUNT_EMPTY_LINES, XML_FALSE);
107 : }
108 :
109 : // count in frames
110 2 : aAny = xLineNumbering->getPropertyValue(sCountLinesInFrames);
111 2 : if (*(sal_Bool*)aAny.getValue())
112 : {
113 : rExport.AddAttribute(XML_NAMESPACE_TEXT,
114 0 : XML_COUNT_IN_TEXT_BOXES, XML_TRUE);
115 : }
116 :
117 : // restart numbering
118 2 : aAny = xLineNumbering->getPropertyValue(sRestartAtEachPage);
119 2 : if (*(sal_Bool*)aAny.getValue())
120 : {
121 : rExport.AddAttribute(XML_NAMESPACE_TEXT,
122 0 : XML_RESTART_ON_PAGE, XML_TRUE);
123 : }
124 :
125 : // Distance
126 2 : aAny = xLineNumbering->getPropertyValue(sDistance);
127 2 : sal_Int32 nLength = 0;
128 2 : aAny >>= nLength;
129 2 : if (nLength != 0)
130 : {
131 2 : OUStringBuffer sBuf;
132 2 : rExport.GetMM100UnitConverter().convertMeasureToXML(
133 4 : sBuf, nLength);
134 : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OFFSET,
135 2 : sBuf.makeStringAndClear());
136 : }
137 :
138 : // NumeringType
139 2 : OUStringBuffer sNumPosBuf;
140 2 : aAny = xLineNumbering->getPropertyValue(sNumberingType);
141 2 : sal_Int16 nFormat = 0;
142 2 : aAny >>= nFormat;
143 2 : rExport.GetMM100UnitConverter().convertNumFormat( sNumPosBuf, nFormat );
144 : rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
145 2 : sNumPosBuf.makeStringAndClear());
146 2 : rExport.GetMM100UnitConverter().convertNumLetterSync( sNumPosBuf, nFormat );
147 2 : if( sNumPosBuf.getLength() )
148 : {
149 : rExport.AddAttribute(XML_NAMESPACE_STYLE,
150 : XML_NUM_LETTER_SYNC,
151 0 : sNumPosBuf.makeStringAndClear() );
152 : }
153 :
154 : // number position
155 2 : aAny = xLineNumbering->getPropertyValue(sNumberPosition);
156 2 : sal_Int16 nPosition = 0;
157 2 : aAny >>= nPosition;
158 2 : if (SvXMLUnitConverter::convertEnum(sNumPosBuf, nPosition,
159 2 : aLineNumberPositionMap))
160 : {
161 : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NUMBER_POSITION,
162 2 : sNumPosBuf.makeStringAndClear());
163 : }
164 :
165 : // sInterval
166 2 : aAny = xLineNumbering->getPropertyValue(sInterval);
167 2 : sal_Int16 nLineInterval = 0;
168 2 : aAny >>= nLineInterval;
169 2 : OUStringBuffer sBuf;
170 : ::sax::Converter::convertNumber(sBuf,
171 2 : (sal_Int32)nLineInterval);
172 : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
173 2 : sBuf.makeStringAndClear());
174 :
175 : SvXMLElementExport aConfigElem(rExport, XML_NAMESPACE_TEXT,
176 : XML_LINENUMBERING_CONFIGURATION,
177 2 : sal_True, sal_True);
178 :
179 : // line separator
180 2 : aAny = xLineNumbering->getPropertyValue(sSeparatorText);
181 2 : OUString sSeparator;
182 2 : aAny >>= sSeparator;
183 2 : if (!sSeparator.isEmpty())
184 : {
185 :
186 : // SeparatorInterval
187 0 : aAny = xLineNumbering->getPropertyValue(sSeparatorInterval);
188 0 : sal_Int16 nLineDistance = 0;
189 0 : aAny >>= nLineDistance;
190 : ::sax::Converter::convertNumber(sBuf,
191 0 : (sal_Int32)nLineDistance);
192 : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
193 0 : sBuf.makeStringAndClear());
194 :
195 : SvXMLElementExport aSeparatorElem(rExport, XML_NAMESPACE_TEXT,
196 : XML_LINENUMBERING_SEPARATOR,
197 0 : sal_True, sal_False);
198 0 : rExport.Characters(sSeparator);
199 2 : }
200 2 : }
201 : // else: no configuration: don't save -> default
202 2 : }
203 : // can't even get supplier: don't save -> default
204 2 : }
205 :
206 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|