bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / XMLTextColumnsExport.cxx
blobee797e2c6b702589343d29d8c40e56398395d377
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <rtl/ustrbuf.hxx>
23 #include <com/sun/star/text/XTextColumns.hpp>
24 #include <com/sun/star/text/TextColumn.hpp>
25 #include <com/sun/star/style/VerticalAlignment.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <sax/tools/converter.hxx>
30 #include <xmloff/xmltoken.hxx>
31 #include <xmloff/xmlnmspe.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include <xmloff/xmlexp.hxx>
34 #include "XMLTextColumnsExport.hxx"
36 using namespace ::com::sun::star::style;
37 using namespace ::com::sun::star::text;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
40 using namespace ::xmloff::token;
43 XMLTextColumnsExport::XMLTextColumnsExport( SvXMLExport& rExp ) :
44 rExport( rExp ),
45 sSeparatorLineIsOn("SeparatorLineIsOn"),
46 sSeparatorLineWidth("SeparatorLineWidth"),
47 sSeparatorLineColor("SeparatorLineColor"),
48 sSeparatorLineRelativeHeight("SeparatorLineRelativeHeight"),
49 sSeparatorLineVerticalAlignment("SeparatorLineVerticalAlignment"),
50 sIsAutomatic("IsAutomatic"),
51 sAutomaticDistance("AutomaticDistance"),
52 sSeparatorLineStyle("SeparatorLineStyle")
56 void XMLTextColumnsExport::exportXML( const Any& rAny )
58 Reference < XTextColumns > xColumns;
59 rAny >>= xColumns;
61 Sequence < TextColumn > aColumns = xColumns->getColumns();
62 const TextColumn *pColumns = aColumns.getArray();
63 sal_Int32 nCount = aColumns.getLength();
65 OUStringBuffer sValue;
66 ::sax::Converter::convertNumber( sValue, (nCount) ? nCount : 1 );
67 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLUMN_COUNT,
68 sValue.makeStringAndClear() );
70 // handle 'automatic' columns
71 Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY );
72 if( xPropSet.is() )
74 Any aAny = xPropSet->getPropertyValue( sIsAutomatic );
75 if ( *static_cast<sal_Bool const *>(aAny.getValue()) )
77 aAny = xPropSet->getPropertyValue( sAutomaticDistance );
78 sal_Int32 nDistance = 0;
79 aAny >>= nDistance;
80 OUStringBuffer aBuffer;
81 GetExport().GetMM100UnitConverter().convertMeasureToXML(
82 aBuffer, nDistance );
83 GetExport().AddAttribute( XML_NAMESPACE_FO,
84 XML_COLUMN_GAP,
85 aBuffer.makeStringAndClear() );
89 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMNS,
90 true, true );
92 if( xPropSet.is() )
94 Any aAny = xPropSet->getPropertyValue( sSeparatorLineIsOn );
95 if( *static_cast<sal_Bool const *>(aAny.getValue()) )
97 // style:width
98 aAny = xPropSet->getPropertyValue( sSeparatorLineWidth );
99 sal_Int32 nWidth = 0;
100 aAny >>= nWidth;
101 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
102 nWidth );
103 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_WIDTH,
104 sValue.makeStringAndClear() );
106 // style:color
107 aAny = xPropSet->getPropertyValue( sSeparatorLineColor );
108 sal_Int32 nColor = 0;
109 aAny >>= nColor;
110 ::sax::Converter::convertColor( sValue, nColor );
111 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_COLOR,
112 sValue.makeStringAndClear() );
114 // style:height
115 aAny = xPropSet->getPropertyValue( sSeparatorLineRelativeHeight );
116 sal_Int8 nHeight = 0;
117 aAny >>= nHeight;
118 ::sax::Converter::convertPercent( sValue, nHeight );
119 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_HEIGHT,
120 sValue.makeStringAndClear() );
122 // style::style
123 aAny = xPropSet->getPropertyValue( sSeparatorLineStyle );
124 sal_Int8 nStyle = 0;
125 aAny >>= nStyle;
127 enum XMLTokenEnum eStr = XML_TOKEN_INVALID;
128 switch ( nStyle )
130 case 0: eStr = XML_NONE; break;
131 case 1: eStr = XML_SOLID; break;
132 case 2: eStr = XML_DOTTED; break;
133 case 3: eStr = XML_DASHED; break;
134 default:
135 break;
137 if ( eStr != XML_TOKEN_INVALID )
138 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_STYLE, eStr );
140 // style:vertical-align
141 aAny = xPropSet->getPropertyValue( sSeparatorLineVerticalAlignment );
142 VerticalAlignment eVertAlign;
143 aAny >>= eVertAlign;
145 eStr = XML_TOKEN_INVALID;
146 switch( eVertAlign )
148 // case VerticalAlignment_TOP: eStr = XML_TOP;
149 case VerticalAlignment_MIDDLE: eStr = XML_MIDDLE; break;
150 case VerticalAlignment_BOTTOM: eStr = XML_BOTTOM; break;
151 default:
152 break;
155 if( eStr != XML_TOKEN_INVALID)
156 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
157 XML_VERTICAL_ALIGN, eStr );
159 // style:column-sep
160 SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
161 XML_COLUMN_SEP,
162 true, true );
166 while( nCount-- )
168 // style:rel-width
169 ::sax::Converter::convertNumber( sValue, pColumns->Width );
170 sValue.append( '*' );
171 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
172 sValue.makeStringAndClear() );
174 // fo:margin-left
175 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
176 pColumns->LeftMargin );
177 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_START_INDENT,
178 sValue.makeStringAndClear() );
180 // fo:margin-right
181 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
182 pColumns->RightMargin );
183 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_END_INDENT,
184 sValue.makeStringAndClear() );
186 // style:column
187 SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMN,
188 true, true );
189 pColumns++;
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */