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 #include <tools/debug.hxx>
27 #include <rtl/ustrbuf.hxx>
28
29
30 #include <com/sun/star/text/XTextColumns.hpp>
31 #include <com/sun/star/text/TextColumn.hpp>
32 #include <com/sun/star/style/VerticalAlignment.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34
35
36 #include <xmloff/xmltoken.hxx>
37 #include "xmloff/xmlnmspe.hxx"
38 #include <xmloff/xmluconv.hxx>
39 #include <xmloff/xmlexp.hxx>
40 #include "XMLTextColumnsExport.hxx"
41
42 using namespace ::com::sun::star::style;
43 using namespace ::com::sun::star::text;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::beans;
46 using ::rtl::OUString;
47 using ::rtl::OUStringBuffer;
48 using namespace ::xmloff::token;
49
50
XMLTextColumnsExport(SvXMLExport & rExp)51 XMLTextColumnsExport::XMLTextColumnsExport( SvXMLExport& rExp ) :
52 rExport( rExp ),
53 sSeparatorLineIsOn(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineIsOn")),
54 sSeparatorLineWidth(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineWidth")),
55 sSeparatorLineColor(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineColor")),
56 sSeparatorLineRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineRelativeHeight")),
57 sSeparatorLineVerticalAlignment(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineVerticalAlignment")),
58 sIsAutomatic(RTL_CONSTASCII_USTRINGPARAM("IsAutomatic")),
59 sAutomaticDistance(RTL_CONSTASCII_USTRINGPARAM("AutomaticDistance"))
60 {
61 }
62
exportXML(const Any & rAny)63 void XMLTextColumnsExport::exportXML( const Any& rAny )
64 {
65 Reference < XTextColumns > xColumns;
66 rAny >>= xColumns;
67
68 Sequence < TextColumn > aColumns = xColumns->getColumns();
69 const TextColumn *pColumns = aColumns.getArray();
70 sal_Int32 nCount = aColumns.getLength();
71
72 OUStringBuffer sValue;
73 GetExport().GetMM100UnitConverter().convertNumber( sValue, nCount ? nCount : 1 );
74 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLUMN_COUNT,
75 sValue.makeStringAndClear() );
76
77 // handle 'automatic' columns
78 Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY );
79 if( xPropSet.is() )
80 {
81 Any aAny = xPropSet->getPropertyValue( sIsAutomatic );
82 if ( *(sal_Bool*)aAny.getValue() )
83 {
84 aAny = xPropSet->getPropertyValue( sAutomaticDistance );
85 sal_Int32 nDistance = 0;
86 aAny >>= nDistance;
87 OUStringBuffer aBuffer;
88 GetExport().GetMM100UnitConverter().convertMeasure(
89 aBuffer, nDistance );
90 GetExport().AddAttribute( XML_NAMESPACE_FO,
91 XML_COLUMN_GAP,
92 aBuffer.makeStringAndClear() );
93 }
94 }
95
96 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMNS,
97 sal_True, sal_True );
98
99 if( xPropSet.is() )
100 {
101 Any aAny = xPropSet->getPropertyValue( sSeparatorLineIsOn );
102 if( *(sal_Bool *)aAny.getValue() )
103 {
104 // style:width
105 aAny = xPropSet->getPropertyValue( sSeparatorLineWidth );
106 sal_Int32 nWidth = 0;
107 aAny >>= nWidth;
108 GetExport().GetMM100UnitConverter().convertMeasure( sValue,
109 nWidth );
110 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_WIDTH,
111 sValue.makeStringAndClear() );
112
113 // style:color
114 aAny = xPropSet->getPropertyValue( sSeparatorLineColor );
115 sal_Int32 nColor = 0;
116 aAny >>= nColor;
117 GetExport().GetMM100UnitConverter().convertColor( sValue,
118 nColor );
119 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_COLOR,
120 sValue.makeStringAndClear() );
121
122 // style:height
123 aAny = xPropSet->getPropertyValue( sSeparatorLineRelativeHeight );
124 sal_Int8 nHeight = 0;
125 aAny >>= nHeight;
126 GetExport().GetMM100UnitConverter().convertPercent( sValue,
127 nHeight );
128 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_HEIGHT,
129 sValue.makeStringAndClear() );
130
131 // style:vertical-align
132 aAny = xPropSet->getPropertyValue( sSeparatorLineVerticalAlignment );
133 VerticalAlignment eVertAlign;
134 aAny >>= eVertAlign;
135
136 enum XMLTokenEnum eStr = XML_TOKEN_INVALID;
137 switch( eVertAlign )
138 {
139 // case VerticalAlignment_TOP: eStr = XML_TOP;
140 case VerticalAlignment_MIDDLE: eStr = XML_MIDDLE; break;
141 case VerticalAlignment_BOTTOM: eStr = XML_BOTTOM; break;
142 default:
143 break;
144 }
145
146 if( eStr != XML_TOKEN_INVALID)
147 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
148 XML_VERTICAL_ALIGN, eStr );
149
150 // style:column-sep
151 SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
152 XML_COLUMN_SEP,
153 sal_True, sal_True );
154 }
155 }
156
157 while( nCount-- )
158 {
159 // style:rel-width
160 GetExport().GetMM100UnitConverter().convertNumber( sValue,
161 pColumns->Width );
162 sValue.append( (sal_Unicode)'*' );
163 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
164 sValue.makeStringAndClear() );
165
166 // fo:margin-left
167 GetExport().GetMM100UnitConverter().convertMeasure( sValue,
168 pColumns->LeftMargin );
169 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_START_INDENT,
170 sValue.makeStringAndClear() );
171
172 // fo:margin-right
173 GetExport().GetMM100UnitConverter().convertMeasure( sValue,
174 pColumns->RightMargin );
175 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_END_INDENT,
176 sValue.makeStringAndClear() );
177
178 // style:column
179 SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMN,
180 sal_True, sal_True );
181 pColumns++;
182 }
183 }
184
185
186