1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "XMLLineNumberingExport.hxx"
27cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
28cdf0e10cSrcweir #include "com/sun/star/text/XLineNumberingProperties.hpp"
29cdf0e10cSrcweir #include <com/sun/star/style/LineNumberPosition.hpp>
30cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
31cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
32cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
33cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
34cdf0e10cSrcweir #include <xmloff/xmlnume.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir using namespace ::com::sun::star;
39cdf0e10cSrcweir using namespace ::xmloff::token;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using ::rtl::OUString;
42cdf0e10cSrcweir using ::rtl::OUStringBuffer;
43cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet;
44cdf0e10cSrcweir using ::com::sun::star::text::XLineNumberingProperties;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
XMLLineNumberingExport(SvXMLExport & rExp)47cdf0e10cSrcweir XMLLineNumberingExport::XMLLineNumberingExport(SvXMLExport& rExp)
48cdf0e10cSrcweir :	sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName"))
49cdf0e10cSrcweir ,	sCountEmptyLines(RTL_CONSTASCII_USTRINGPARAM("CountEmptyLines"))
50cdf0e10cSrcweir ,	sCountLinesInFrames(RTL_CONSTASCII_USTRINGPARAM("CountLinesInFrames"))
51cdf0e10cSrcweir ,	sDistance(RTL_CONSTASCII_USTRINGPARAM("Distance"))
52cdf0e10cSrcweir ,	sInterval(RTL_CONSTASCII_USTRINGPARAM("Interval"))
53cdf0e10cSrcweir ,	sSeparatorText(RTL_CONSTASCII_USTRINGPARAM("SeparatorText"))
54cdf0e10cSrcweir ,	sNumberPosition(RTL_CONSTASCII_USTRINGPARAM("NumberPosition"))
55cdf0e10cSrcweir ,	sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType"))
56cdf0e10cSrcweir ,	sIsOn(RTL_CONSTASCII_USTRINGPARAM("IsOn"))
57cdf0e10cSrcweir ,	sRestartAtEachPage(RTL_CONSTASCII_USTRINGPARAM("RestartAtEachPage"))
58cdf0e10cSrcweir ,	sSeparatorInterval(RTL_CONSTASCII_USTRINGPARAM("SeparatorInterval"))
59cdf0e10cSrcweir ,	rExport(rExp)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir SvXMLEnumMapEntry __READONLY_DATA aLineNumberPositionMap[] =
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	{ XML_LEFT,	    style::LineNumberPosition::LEFT },
66cdf0e10cSrcweir 	{ XML_RIGHT,	style::LineNumberPosition::RIGHT },
67cdf0e10cSrcweir 	{ XML_INSIDE,	style::LineNumberPosition::INSIDE },
68cdf0e10cSrcweir 	{ XML_OUTSIDE,  style::LineNumberPosition::OUTSIDE },
69cdf0e10cSrcweir 	{ XML_TOKEN_INVALID, 0 }
70cdf0e10cSrcweir };
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 
Export()74cdf0e10cSrcweir void XMLLineNumberingExport::Export()
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 	// export element if we have line numbering info
77cdf0e10cSrcweir 	Reference<XLineNumberingProperties> xSupplier(rExport.GetModel(),
78cdf0e10cSrcweir 												  UNO_QUERY);
79cdf0e10cSrcweir 	if (xSupplier.is())
80cdf0e10cSrcweir 	{
81cdf0e10cSrcweir 		Reference<XPropertySet> xLineNumbering =
82cdf0e10cSrcweir 			xSupplier->getLineNumberingProperties();
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 		if (xLineNumbering.is())
85cdf0e10cSrcweir 		{
86cdf0e10cSrcweir 			Any aAny;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 			// char style
89cdf0e10cSrcweir 			aAny = xLineNumbering->getPropertyValue(sCharStyleName);
90cdf0e10cSrcweir 			OUString sTmp;
91cdf0e10cSrcweir 			aAny >>= sTmp;
92cdf0e10cSrcweir 			if (sTmp.getLength() > 0)
93cdf0e10cSrcweir 			{
94cdf0e10cSrcweir 				rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
95cdf0e10cSrcweir 									 rExport.EncodeStyleName( sTmp ));
96cdf0e10cSrcweir 			}
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 			// enable
99cdf0e10cSrcweir 			aAny = xLineNumbering->getPropertyValue(sIsOn);
100cdf0e10cSrcweir 			if (! *(sal_Bool*)aAny.getValue())
101cdf0e10cSrcweir 			{
102cdf0e10cSrcweir 				rExport.AddAttribute(XML_NAMESPACE_TEXT,
103cdf0e10cSrcweir                                      XML_NUMBER_LINES, XML_FALSE);
104cdf0e10cSrcweir 			}
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 			// count empty lines
107cdf0e10cSrcweir 			aAny = xLineNumbering->getPropertyValue(sCountEmptyLines);
108cdf0e10cSrcweir 			if (! *(sal_Bool*)aAny.getValue())
109cdf0e10cSrcweir 			{
110cdf0e10cSrcweir 				rExport.AddAttribute(XML_NAMESPACE_TEXT,
111cdf0e10cSrcweir                                      XML_COUNT_EMPTY_LINES, XML_FALSE);
112cdf0e10cSrcweir 			}
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 			// count in frames
115cdf0e10cSrcweir 			aAny = xLineNumbering->getPropertyValue(sCountLinesInFrames);
116cdf0e10cSrcweir 			if (*(sal_Bool*)aAny.getValue())
117cdf0e10cSrcweir 			{
118cdf0e10cSrcweir 				rExport.AddAttribute(XML_NAMESPACE_TEXT,
119cdf0e10cSrcweir                                      XML_COUNT_IN_TEXT_BOXES, XML_TRUE);
120cdf0e10cSrcweir 			}
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 			// restart numbering
123cdf0e10cSrcweir 			aAny = xLineNumbering->getPropertyValue(sRestartAtEachPage);
124cdf0e10cSrcweir 			if (*(sal_Bool*)aAny.getValue())
125cdf0e10cSrcweir 			{
126cdf0e10cSrcweir 				rExport.AddAttribute(XML_NAMESPACE_TEXT,
127cdf0e10cSrcweir                                      XML_RESTART_ON_PAGE, XML_TRUE);
128cdf0e10cSrcweir 			}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 			// Distance
131cdf0e10cSrcweir 			aAny = xLineNumbering->getPropertyValue(sDistance);
132cdf0e10cSrcweir 			sal_Int32 nLength = 0;
133cdf0e10cSrcweir 			aAny >>= nLength;
134cdf0e10cSrcweir 			if (nLength != 0)
135cdf0e10cSrcweir 			{
136cdf0e10cSrcweir 				OUStringBuffer sBuf;
137cdf0e10cSrcweir 				rExport.GetMM100UnitConverter().convertMeasure(sBuf, nLength);
138cdf0e10cSrcweir 				rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OFFSET,
139cdf0e10cSrcweir 									 sBuf.makeStringAndClear());
140cdf0e10cSrcweir 			}
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 			// NumeringType
143cdf0e10cSrcweir 			OUStringBuffer sNumPosBuf;
144cdf0e10cSrcweir 			aAny = xLineNumbering->getPropertyValue(sNumberingType);
145cdf0e10cSrcweir 			sal_Int16 nFormat = 0;
146cdf0e10cSrcweir 			aAny >>= nFormat;
147cdf0e10cSrcweir 			rExport.GetMM100UnitConverter().convertNumFormat( sNumPosBuf, nFormat );
148cdf0e10cSrcweir 			rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
149cdf0e10cSrcweir 								 sNumPosBuf.makeStringAndClear());
150cdf0e10cSrcweir 			rExport.GetMM100UnitConverter().convertNumLetterSync( sNumPosBuf, nFormat );
151cdf0e10cSrcweir 			if( sNumPosBuf.getLength() )
152cdf0e10cSrcweir 			{
153cdf0e10cSrcweir 				rExport.AddAttribute(XML_NAMESPACE_STYLE,
154cdf0e10cSrcweir 									 XML_NUM_LETTER_SYNC,
155cdf0e10cSrcweir 									 sNumPosBuf.makeStringAndClear() );
156cdf0e10cSrcweir 			}
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 			// number position
159cdf0e10cSrcweir 			aAny = xLineNumbering->getPropertyValue(sNumberPosition);
160cdf0e10cSrcweir 			sal_Int16 nPosition = 0;
161cdf0e10cSrcweir 			aAny >>= nPosition;
162cdf0e10cSrcweir 			if (SvXMLUnitConverter::convertEnum(sNumPosBuf, nPosition,
163cdf0e10cSrcweir 												aLineNumberPositionMap))
164cdf0e10cSrcweir 			{
165cdf0e10cSrcweir 				rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NUMBER_POSITION,
166cdf0e10cSrcweir 									 sNumPosBuf.makeStringAndClear());
167cdf0e10cSrcweir 			}
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 			// sInterval
170cdf0e10cSrcweir 			aAny = xLineNumbering->getPropertyValue(sInterval);
171cdf0e10cSrcweir 			sal_Int16 nLineInterval = 0;
172cdf0e10cSrcweir 			aAny >>= nLineInterval;
173cdf0e10cSrcweir 			OUStringBuffer sBuf;
174cdf0e10cSrcweir 			SvXMLUnitConverter::convertNumber(sBuf,
175cdf0e10cSrcweir 											  (sal_Int32)nLineInterval);
176cdf0e10cSrcweir 			rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
177cdf0e10cSrcweir 								 sBuf.makeStringAndClear());
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 			SvXMLElementExport aConfigElem(rExport, XML_NAMESPACE_TEXT,
180cdf0e10cSrcweir 										   XML_LINENUMBERING_CONFIGURATION,
181cdf0e10cSrcweir 										   sal_True, sal_True);
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 			// line separator
184cdf0e10cSrcweir 			aAny = xLineNumbering->getPropertyValue(sSeparatorText);
185cdf0e10cSrcweir 			OUString sSeparator;
186cdf0e10cSrcweir 			aAny >>= sSeparator;
187cdf0e10cSrcweir 			if (sSeparator.getLength() > 0)
188cdf0e10cSrcweir 			{
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 				// SeparatorInterval
191cdf0e10cSrcweir 				aAny = xLineNumbering->getPropertyValue(sSeparatorInterval);
192cdf0e10cSrcweir 				sal_Int16 nLineDistance = 0;
193cdf0e10cSrcweir 				aAny >>= nLineDistance;
194cdf0e10cSrcweir 				SvXMLUnitConverter::convertNumber(sBuf,
195cdf0e10cSrcweir 												  (sal_Int32)nLineDistance);
196cdf0e10cSrcweir 				rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
197cdf0e10cSrcweir 									 sBuf.makeStringAndClear());
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 				SvXMLElementExport aSeparatorElem(rExport, XML_NAMESPACE_TEXT,
200cdf0e10cSrcweir 												  XML_LINENUMBERING_SEPARATOR,
201cdf0e10cSrcweir 												  sal_True, sal_False);
202cdf0e10cSrcweir 				rExport.Characters(sSeparator);
203cdf0e10cSrcweir 			}
204cdf0e10cSrcweir 		}
205cdf0e10cSrcweir 		// else: no configuration: don't save -> default
206cdf0e10cSrcweir 	}
207cdf0e10cSrcweir 	// can't even get supplier: don't save -> default
208cdf0e10cSrcweir }
209