Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <rtl/ustrbuf.hxx>
21 :
22 :
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>
27 :
28 : #include <sax/tools/converter.hxx>
29 :
30 : #include <xmloff/xmltoken.hxx>
31 : #include <xmloff/xmlnmspe.hxx>
32 : #include <xmloff/xmluconv.hxx>
33 : #include <xmloff/xmlexp.hxx>
34 : #include "XMLTextColumnsExport.hxx"
35 :
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;
41 :
42 :
43 7405 : 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 7405 : sSeparatorLineStyle("SeparatorLineStyle")
53 : {
54 7405 : }
55 :
56 21 : void XMLTextColumnsExport::exportXML( const Any& rAny )
57 : {
58 21 : Reference < XTextColumns > xColumns;
59 21 : rAny >>= xColumns;
60 :
61 42 : Sequence < TextColumn > aColumns = xColumns->getColumns();
62 21 : const TextColumn *pColumns = aColumns.getArray();
63 21 : sal_Int32 nCount = aColumns.getLength();
64 :
65 42 : OUStringBuffer sValue;
66 21 : ::sax::Converter::convertNumber( sValue, (nCount) ? nCount : 1 );
67 21 : GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLUMN_COUNT,
68 42 : sValue.makeStringAndClear() );
69 :
70 : // handle 'automatic' columns
71 42 : Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY );
72 21 : if( xPropSet.is() )
73 : {
74 21 : Any aAny = xPropSet->getPropertyValue( sIsAutomatic );
75 21 : if ( *static_cast<sal_Bool const *>(aAny.getValue()) )
76 : {
77 21 : aAny = xPropSet->getPropertyValue( sAutomaticDistance );
78 21 : sal_Int32 nDistance = 0;
79 21 : aAny >>= nDistance;
80 21 : OUStringBuffer aBuffer;
81 21 : GetExport().GetMM100UnitConverter().convertMeasureToXML(
82 42 : aBuffer, nDistance );
83 21 : GetExport().AddAttribute( XML_NAMESPACE_FO,
84 : XML_COLUMN_GAP,
85 42 : aBuffer.makeStringAndClear() );
86 21 : }
87 : }
88 :
89 21 : SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMNS,
90 42 : true, true );
91 :
92 21 : if( xPropSet.is() )
93 : {
94 21 : Any aAny = xPropSet->getPropertyValue( sSeparatorLineIsOn );
95 21 : if( *static_cast<sal_Bool const *>(aAny.getValue()) )
96 : {
97 : // style:width
98 0 : aAny = xPropSet->getPropertyValue( sSeparatorLineWidth );
99 0 : sal_Int32 nWidth = 0;
100 0 : aAny >>= nWidth;
101 0 : GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
102 0 : nWidth );
103 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_WIDTH,
104 0 : sValue.makeStringAndClear() );
105 :
106 : // style:color
107 0 : aAny = xPropSet->getPropertyValue( sSeparatorLineColor );
108 0 : sal_Int32 nColor = 0;
109 0 : aAny >>= nColor;
110 0 : ::sax::Converter::convertColor( sValue, nColor );
111 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_COLOR,
112 0 : sValue.makeStringAndClear() );
113 :
114 : // style:height
115 0 : aAny = xPropSet->getPropertyValue( sSeparatorLineRelativeHeight );
116 0 : sal_Int8 nHeight = 0;
117 0 : aAny >>= nHeight;
118 0 : ::sax::Converter::convertPercent( sValue, nHeight );
119 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_HEIGHT,
120 0 : sValue.makeStringAndClear() );
121 :
122 : // style::style
123 0 : aAny = xPropSet->getPropertyValue( sSeparatorLineStyle );
124 0 : sal_Int8 nStyle = 0;
125 0 : aAny >>= nStyle;
126 :
127 0 : enum XMLTokenEnum eStr = XML_TOKEN_INVALID;
128 0 : switch ( nStyle )
129 : {
130 0 : case 0: eStr = XML_NONE; break;
131 0 : case 1: eStr = XML_SOLID; break;
132 0 : case 2: eStr = XML_DOTTED; break;
133 0 : case 3: eStr = XML_DASHED; break;
134 : default:
135 0 : break;
136 : }
137 0 : if ( eStr != XML_TOKEN_INVALID )
138 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_STYLE, eStr );
139 :
140 : // style:vertical-align
141 0 : aAny = xPropSet->getPropertyValue( sSeparatorLineVerticalAlignment );
142 : VerticalAlignment eVertAlign;
143 0 : aAny >>= eVertAlign;
144 :
145 0 : eStr = XML_TOKEN_INVALID;
146 0 : switch( eVertAlign )
147 : {
148 : // case VerticalAlignment_TOP: eStr = XML_TOP;
149 0 : case VerticalAlignment_MIDDLE: eStr = XML_MIDDLE; break;
150 0 : case VerticalAlignment_BOTTOM: eStr = XML_BOTTOM; break;
151 : default:
152 0 : break;
153 : }
154 :
155 0 : if( eStr != XML_TOKEN_INVALID)
156 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE,
157 0 : XML_VERTICAL_ALIGN, eStr );
158 :
159 : // style:column-sep
160 0 : SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
161 : XML_COLUMN_SEP,
162 0 : true, true );
163 21 : }
164 : }
165 :
166 48 : while( nCount-- )
167 : {
168 : // style:rel-width
169 6 : ::sax::Converter::convertNumber( sValue, pColumns->Width );
170 6 : sValue.append( '*' );
171 6 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
172 12 : sValue.makeStringAndClear() );
173 :
174 : // fo:margin-left
175 6 : GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
176 12 : pColumns->LeftMargin );
177 6 : GetExport().AddAttribute( XML_NAMESPACE_FO, XML_START_INDENT,
178 12 : sValue.makeStringAndClear() );
179 :
180 : // fo:margin-right
181 6 : GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
182 12 : pColumns->RightMargin );
183 6 : GetExport().AddAttribute( XML_NAMESPACE_FO, XML_END_INDENT,
184 12 : sValue.makeStringAndClear() );
185 :
186 : // style:column
187 6 : SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMN,
188 6 : true, true );
189 6 : pColumns++;
190 27 : }
191 21 : }
192 :
193 :
194 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|