Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "XMLLineNumberingExport.hxx"
30 : : #include "com/sun/star/beans/XPropertySet.hpp"
31 : : #include "com/sun/star/text/XLineNumberingProperties.hpp"
32 : : #include <com/sun/star/style/LineNumberPosition.hpp>
33 : : #include <sax/tools/converter.hxx>
34 : : #include <xmloff/xmlexp.hxx>
35 : : #include <xmloff/xmluconv.hxx>
36 : : #include "xmloff/xmlnmspe.hxx"
37 : : #include <xmloff/xmltoken.hxx>
38 : : #include <xmloff/xmlnume.hxx>
39 : :
40 : :
41 : : using namespace ::com::sun::star::uno;
42 : : using namespace ::com::sun::star;
43 : : using namespace ::xmloff::token;
44 : :
45 : : using ::rtl::OUString;
46 : : using ::rtl::OUStringBuffer;
47 : : using ::com::sun::star::beans::XPropertySet;
48 : : using ::com::sun::star::text::XLineNumberingProperties;
49 : :
50 : :
51 : 19 : XMLLineNumberingExport::XMLLineNumberingExport(SvXMLExport& rExp)
52 : : : sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName"))
53 : : , sCountEmptyLines(RTL_CONSTASCII_USTRINGPARAM("CountEmptyLines"))
54 : : , sCountLinesInFrames(RTL_CONSTASCII_USTRINGPARAM("CountLinesInFrames"))
55 : : , sDistance(RTL_CONSTASCII_USTRINGPARAM("Distance"))
56 : : , sInterval(RTL_CONSTASCII_USTRINGPARAM("Interval"))
57 : : , sSeparatorText(RTL_CONSTASCII_USTRINGPARAM("SeparatorText"))
58 : : , sNumberPosition(RTL_CONSTASCII_USTRINGPARAM("NumberPosition"))
59 : : , sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType"))
60 : : , sIsOn(RTL_CONSTASCII_USTRINGPARAM("IsOn"))
61 : : , sRestartAtEachPage(RTL_CONSTASCII_USTRINGPARAM("RestartAtEachPage"))
62 : : , sSeparatorInterval(RTL_CONSTASCII_USTRINGPARAM("SeparatorInterval"))
63 [ + - ][ + - ]: 19 : , rExport(rExp)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
64 : : {
65 : 19 : }
66 : :
67 : : SvXMLEnumMapEntry const aLineNumberPositionMap[] =
68 : : {
69 : : { XML_LEFT, style::LineNumberPosition::LEFT },
70 : : { XML_RIGHT, style::LineNumberPosition::RIGHT },
71 : : { XML_INSIDE, style::LineNumberPosition::INSIDE },
72 : : { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE },
73 : : { XML_TOKEN_INVALID, 0 }
74 : : };
75 : :
76 : :
77 : :
78 : 19 : void XMLLineNumberingExport::Export()
79 : : {
80 : : // export element if we have line numbering info
81 : 19 : Reference<XLineNumberingProperties> xSupplier(rExport.GetModel(),
82 [ + - ]: 19 : UNO_QUERY);
83 [ + - ]: 19 : if (xSupplier.is())
84 : : {
85 : : Reference<XPropertySet> xLineNumbering =
86 [ + - ][ + - ]: 19 : xSupplier->getLineNumberingProperties();
87 : :
88 [ + - ]: 19 : if (xLineNumbering.is())
89 : : {
90 : 19 : Any aAny;
91 : :
92 : : // char style
93 [ + - ][ + - ]: 19 : aAny = xLineNumbering->getPropertyValue(sCharStyleName);
94 : 19 : OUString sTmp;
95 : 19 : aAny >>= sTmp;
96 [ - + ]: 19 : if (!sTmp.isEmpty())
97 : : {
98 : : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
99 [ # # ][ # # ]: 0 : rExport.EncodeStyleName( sTmp ));
100 : : }
101 : :
102 : : // enable
103 [ + - ][ + - ]: 19 : aAny = xLineNumbering->getPropertyValue(sIsOn);
104 [ + - ]: 19 : if (! *(sal_Bool*)aAny.getValue())
105 : : {
106 : : rExport.AddAttribute(XML_NAMESPACE_TEXT,
107 [ + - ]: 19 : XML_NUMBER_LINES, XML_FALSE);
108 : : }
109 : :
110 : : // count empty lines
111 [ + - ][ + - ]: 19 : aAny = xLineNumbering->getPropertyValue(sCountEmptyLines);
112 [ - + ]: 19 : if (! *(sal_Bool*)aAny.getValue())
113 : : {
114 : : rExport.AddAttribute(XML_NAMESPACE_TEXT,
115 [ # # ]: 0 : XML_COUNT_EMPTY_LINES, XML_FALSE);
116 : : }
117 : :
118 : : // count in frames
119 [ + - ][ + - ]: 19 : aAny = xLineNumbering->getPropertyValue(sCountLinesInFrames);
120 [ - + ]: 19 : if (*(sal_Bool*)aAny.getValue())
121 : : {
122 : : rExport.AddAttribute(XML_NAMESPACE_TEXT,
123 [ # # ]: 0 : XML_COUNT_IN_TEXT_BOXES, XML_TRUE);
124 : : }
125 : :
126 : : // restart numbering
127 [ + - ][ + - ]: 19 : aAny = xLineNumbering->getPropertyValue(sRestartAtEachPage);
128 [ - + ]: 19 : if (*(sal_Bool*)aAny.getValue())
129 : : {
130 : : rExport.AddAttribute(XML_NAMESPACE_TEXT,
131 [ # # ]: 0 : XML_RESTART_ON_PAGE, XML_TRUE);
132 : : }
133 : :
134 : : // Distance
135 [ + - ][ + - ]: 19 : aAny = xLineNumbering->getPropertyValue(sDistance);
136 : 19 : sal_Int32 nLength = 0;
137 : 19 : aAny >>= nLength;
138 [ + - ]: 19 : if (nLength != 0)
139 : : {
140 : 19 : OUStringBuffer sBuf;
141 : 19 : rExport.GetMM100UnitConverter().convertMeasureToXML(
142 [ + - ]: 19 : sBuf, nLength);
143 : : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OFFSET,
144 [ + - ][ + - ]: 19 : sBuf.makeStringAndClear());
145 : : }
146 : :
147 : : // NumeringType
148 : 19 : OUStringBuffer sNumPosBuf;
149 [ + - ][ + - ]: 19 : aAny = xLineNumbering->getPropertyValue(sNumberingType);
150 : 19 : sal_Int16 nFormat = 0;
151 : 19 : aAny >>= nFormat;
152 [ + - ]: 19 : rExport.GetMM100UnitConverter().convertNumFormat( sNumPosBuf, nFormat );
153 : : rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
154 [ + - ][ + - ]: 19 : sNumPosBuf.makeStringAndClear());
155 [ + - ]: 19 : rExport.GetMM100UnitConverter().convertNumLetterSync( sNumPosBuf, nFormat );
156 [ - + ]: 19 : if( sNumPosBuf.getLength() )
157 : : {
158 : : rExport.AddAttribute(XML_NAMESPACE_STYLE,
159 : : XML_NUM_LETTER_SYNC,
160 [ # # ][ # # ]: 0 : sNumPosBuf.makeStringAndClear() );
161 : : }
162 : :
163 : : // number position
164 [ + - ][ + - ]: 19 : aAny = xLineNumbering->getPropertyValue(sNumberPosition);
165 : 19 : sal_Int16 nPosition = 0;
166 : 19 : aAny >>= nPosition;
167 [ + - ]: 19 : if (SvXMLUnitConverter::convertEnum(sNumPosBuf, nPosition,
168 [ + - ]: 19 : aLineNumberPositionMap))
169 : : {
170 : : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NUMBER_POSITION,
171 [ + - ][ + - ]: 19 : sNumPosBuf.makeStringAndClear());
172 : : }
173 : :
174 : : // sInterval
175 [ + - ][ + - ]: 19 : aAny = xLineNumbering->getPropertyValue(sInterval);
176 : 19 : sal_Int16 nLineInterval = 0;
177 : 19 : aAny >>= nLineInterval;
178 : 19 : OUStringBuffer sBuf;
179 : : ::sax::Converter::convertNumber(sBuf,
180 [ + - ]: 19 : (sal_Int32)nLineInterval);
181 : : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
182 [ + - ][ + - ]: 19 : sBuf.makeStringAndClear());
183 : :
184 : : SvXMLElementExport aConfigElem(rExport, XML_NAMESPACE_TEXT,
185 : : XML_LINENUMBERING_CONFIGURATION,
186 [ + - ]: 19 : sal_True, sal_True);
187 : :
188 : : // line separator
189 [ + - ][ + - ]: 19 : aAny = xLineNumbering->getPropertyValue(sSeparatorText);
190 : 19 : OUString sSeparator;
191 : 19 : aAny >>= sSeparator;
192 [ - + ]: 19 : if (!sSeparator.isEmpty())
193 : : {
194 : :
195 : : // SeparatorInterval
196 [ # # ][ # # ]: 0 : aAny = xLineNumbering->getPropertyValue(sSeparatorInterval);
197 : 0 : sal_Int16 nLineDistance = 0;
198 : 0 : aAny >>= nLineDistance;
199 : : ::sax::Converter::convertNumber(sBuf,
200 [ # # ]: 0 : (sal_Int32)nLineDistance);
201 : : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
202 [ # # ][ # # ]: 0 : sBuf.makeStringAndClear());
203 : :
204 : : SvXMLElementExport aSeparatorElem(rExport, XML_NAMESPACE_TEXT,
205 : : XML_LINENUMBERING_SEPARATOR,
206 [ # # ]: 0 : sal_True, sal_False);
207 [ # # ][ # # ]: 0 : rExport.Characters(sSeparator);
208 [ + - ]: 19 : }
209 : 19 : }
210 : : // else: no configuration: don't save -> default
211 : 19 : }
212 : : // can't even get supplier: don't save -> default
213 : 19 : }
214 : :
215 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|