xref: /trunk/main/xmloff/source/style/xmltabe.cxx (revision 63bba73c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 
27 #include <tools/debug.hxx>
28 #include <com/sun/star/style/TabStop.hpp>
29 #include <com/sun/star/style/TabAlign.hpp>
30 #include <rtl/ustrbuf.hxx>
31 #include <xmloff/nmspmap.hxx>
32 #include "xmloff/xmlnmspe.hxx"
33 #include <xmloff/xmltoken.hxx>
34 #include <xmloff/xmluconv.hxx>
35 #include <xmloff/xmlexp.hxx>
36 #include "xmloff/xmltabe.hxx"
37 
38 using ::rtl::OUString;
39 using ::rtl::OUStringBuffer;
40 
41 using namespace ::com::sun::star;
42 using namespace ::xmloff::token;
43 
44 SvXMLEnumMapEntry pXML_tabstop_style[] =
45 {
46 	{ XML_LEFT,     style::TabAlign_LEFT	},
47 	{ XML_CENTER,   style::TabAlign_CENTER	},
48 	{ XML_RIGHT,    style::TabAlign_RIGHT	},
49 	{ XML_CHAR,     style::TabAlign_DECIMAL	},
50 	{ XML_DEFAULT,  style::TabAlign_DEFAULT  },	// ?????????????????????????????????????
51 	{ XML_TOKEN_INVALID,        0 }
52 };
53 
exportTabStop(const::com::sun::star::style::TabStop * pTabStop)54 void SvxXMLTabStopExport::exportTabStop( const ::com::sun::star::style::TabStop* pTabStop )
55 {
56     SvXMLUnitConverter& rUnitConv = rExport.GetMM100UnitConverter();
57 
58 	// text:level
59 	OUStringBuffer sBuffer;
60 
61 	// position attribute
62 	rUnitConv.convertMeasure( sBuffer, pTabStop->Position );
63 	rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_POSITION,
64                            sBuffer.makeStringAndClear() );
65 
66 	// type attribute
67 	if( style::TabAlign_LEFT != pTabStop->Alignment )
68 	{
69 		rUnitConv.convertEnum( sBuffer, pTabStop->Alignment,
70 								   pXML_tabstop_style );
71 		rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_TYPE,
72                                sBuffer.makeStringAndClear() );
73 	}
74 
75 	// char
76 	if( style::TabAlign_DECIMAL == pTabStop->Alignment &&
77 		pTabStop->DecimalChar != 0 )
78 	{
79 		sBuffer.append( pTabStop->DecimalChar );
80 		rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_CHAR,
81                                sBuffer.makeStringAndClear() );
82 	}
83 
84 	// leader-char
85 	if( ' ' != pTabStop->FillChar && 0 != pTabStop->FillChar )
86 	{
87 		rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_LEADER_STYLE,
88 					  GetXMLToken('.' == pTabStop->FillChar ? XML_DOTTED
89 							   							    : XML_SOLID) );
90 
91 		sBuffer.append( pTabStop->FillChar );
92 		rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_LEADER_TEXT,
93                                sBuffer.makeStringAndClear() );
94 	}
95 
96     SvXMLElementExport rElem( rExport, XML_NAMESPACE_STYLE, XML_TAB_STOP,
97                               sal_True, sal_True );
98 }
99 
100 
SvxXMLTabStopExport(SvXMLExport & rExp)101 SvxXMLTabStopExport::SvxXMLTabStopExport(
102     SvXMLExport& rExp)
103     : rExport( rExp )
104 {
105 }
106 
~SvxXMLTabStopExport()107 SvxXMLTabStopExport::~SvxXMLTabStopExport()
108 {
109 }
110 
Export(const uno::Any & rAny)111 void SvxXMLTabStopExport::Export( const uno::Any& rAny )
112 {
113 	uno::Sequence< ::com::sun::star::style::TabStop> aSeq;
114 	if(!(rAny >>= aSeq))
115 	{
116 		DBG_ERROR( "SvxXMLTabStopExport needs a Sequence ::com::sun::star::style::TabStop>" );
117 	}
118 	else
119 	{
120 		const ::com::sun::star::style::TabStop* pTabs = aSeq.getConstArray();
121 		const sal_Int32 nTabs   = aSeq.getLength();
122 
123 		// ignore default tab stop here
124 		//if( 1 == nTabs && style::TabAlign_DEFAULT == pTabs[0].Alignment )
125 		//	return;
126 
127         SvXMLElementExport rElem( rExport, XML_NAMESPACE_STYLE, XML_TAB_STOPS,
128                                   sal_True, sal_True );
129 
130 		for( sal_Int32 nIndex = 0; nIndex < nTabs; nIndex++ )
131 		{
132 			if( style::TabAlign_DEFAULT != pTabs[nIndex].Alignment )
133 				exportTabStop( &(pTabs[nIndex]) );
134 		}
135 	}
136 }
137 
138 
139