xref: /trunk/main/xmloff/source/text/XMLTextColumnsExport.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include <tools/debug.hxx>
31 #include <rtl/ustrbuf.hxx>
32 
33 
34 #include <com/sun/star/text/XTextColumns.hpp>
35 #include <com/sun/star/text/TextColumn.hpp>
36 #include <com/sun/star/style/VerticalAlignment.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 
39 
40 #include <xmloff/xmltoken.hxx>
41 #include "xmloff/xmlnmspe.hxx"
42 #include <xmloff/xmluconv.hxx>
43 #include <xmloff/xmlexp.hxx>
44 #include "XMLTextColumnsExport.hxx"
45 
46 using namespace ::com::sun::star::style;
47 using namespace ::com::sun::star::text;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::beans;
50 using ::rtl::OUString;
51 using ::rtl::OUStringBuffer;
52 using namespace ::xmloff::token;
53 
54 
55 XMLTextColumnsExport::XMLTextColumnsExport( SvXMLExport& rExp ) :
56     rExport( rExp ),
57     sSeparatorLineIsOn(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineIsOn")),
58     sSeparatorLineWidth(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineWidth")),
59     sSeparatorLineColor(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineColor")),
60     sSeparatorLineRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineRelativeHeight")),
61     sSeparatorLineVerticalAlignment(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineVerticalAlignment")),
62     sIsAutomatic(RTL_CONSTASCII_USTRINGPARAM("IsAutomatic")),
63     sAutomaticDistance(RTL_CONSTASCII_USTRINGPARAM("AutomaticDistance"))
64 {
65 }
66 
67 void XMLTextColumnsExport::exportXML( const Any& rAny )
68 {
69     Reference < XTextColumns > xColumns;
70     rAny >>= xColumns;
71 
72     Sequence < TextColumn > aColumns = xColumns->getColumns();
73     const TextColumn *pColumns = aColumns.getArray();
74     sal_Int32 nCount = aColumns.getLength();
75 
76     OUStringBuffer sValue;
77     GetExport().GetMM100UnitConverter().convertNumber( sValue, nCount ? nCount : 1 );
78     GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLUMN_COUNT,
79                               sValue.makeStringAndClear() );
80 
81     // handle 'automatic' columns
82     Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY );
83     if( xPropSet.is() )
84     {
85         Any aAny = xPropSet->getPropertyValue( sIsAutomatic );
86         if ( *(sal_Bool*)aAny.getValue() )
87         {
88             aAny = xPropSet->getPropertyValue( sAutomaticDistance );
89             sal_Int32 nDistance = 0;
90             aAny >>= nDistance;
91             OUStringBuffer aBuffer;
92             GetExport().GetMM100UnitConverter().convertMeasure(
93                 aBuffer, nDistance );
94             GetExport().AddAttribute( XML_NAMESPACE_FO,
95                                       XML_COLUMN_GAP,
96                                       aBuffer.makeStringAndClear() );
97         }
98     }
99 
100     SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMNS,
101                               sal_True, sal_True );
102 
103     if( xPropSet.is() )
104     {
105         Any aAny = xPropSet->getPropertyValue( sSeparatorLineIsOn );
106         if( *(sal_Bool *)aAny.getValue() )
107         {
108             // style:width
109             aAny = xPropSet->getPropertyValue( sSeparatorLineWidth );
110             sal_Int32 nWidth = 0;
111             aAny >>= nWidth;
112             GetExport().GetMM100UnitConverter().convertMeasure( sValue,
113                                                                 nWidth );
114             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_WIDTH,
115                                       sValue.makeStringAndClear() );
116 
117             // style:color
118             aAny = xPropSet->getPropertyValue( sSeparatorLineColor );
119             sal_Int32 nColor = 0;
120             aAny >>= nColor;
121             GetExport().GetMM100UnitConverter().convertColor( sValue,
122                                                               nColor );
123             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_COLOR,
124                                       sValue.makeStringAndClear() );
125 
126             // style:height
127             aAny = xPropSet->getPropertyValue( sSeparatorLineRelativeHeight );
128             sal_Int8 nHeight = 0;
129             aAny >>= nHeight;
130             GetExport().GetMM100UnitConverter().convertPercent( sValue,
131                                                                 nHeight );
132             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_HEIGHT,
133                                       sValue.makeStringAndClear() );
134 
135             // style:vertical-align
136             aAny = xPropSet->getPropertyValue( sSeparatorLineVerticalAlignment );
137             VerticalAlignment eVertAlign;
138             aAny >>= eVertAlign;
139 
140             enum XMLTokenEnum eStr = XML_TOKEN_INVALID;
141             switch( eVertAlign )
142             {
143 //          case VerticalAlignment_TOP: eStr = XML_TOP;
144             case VerticalAlignment_MIDDLE: eStr = XML_MIDDLE; break;
145             case VerticalAlignment_BOTTOM: eStr = XML_BOTTOM; break;
146             default:
147                 break;
148             }
149 
150             if( eStr != XML_TOKEN_INVALID)
151                 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
152                                           XML_VERTICAL_ALIGN, eStr );
153 
154             // style:column-sep
155             SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
156                                       XML_COLUMN_SEP,
157                                       sal_True, sal_True );
158         }
159     }
160 
161     while( nCount-- )
162     {
163         // style:rel-width
164         GetExport().GetMM100UnitConverter().convertNumber( sValue,
165                                                        pColumns->Width );
166         sValue.append( (sal_Unicode)'*' );
167         GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
168                                   sValue.makeStringAndClear() );
169 
170         // fo:margin-left
171         GetExport().GetMM100UnitConverter().convertMeasure( sValue,
172                                                        pColumns->LeftMargin );
173         GetExport().AddAttribute( XML_NAMESPACE_FO, XML_START_INDENT,
174                                   sValue.makeStringAndClear() );
175 
176         // fo:margin-right
177         GetExport().GetMM100UnitConverter().convertMeasure( sValue,
178                                                        pColumns->RightMargin );
179         GetExport().AddAttribute( XML_NAMESPACE_FO, XML_END_INDENT,
180                                   sValue.makeStringAndClear() );
181 
182         // style:column
183         SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMN,
184                                   sal_True, sal_True );
185         pColumns++;
186     }
187 }
188 
189 
190