1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
) :
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
;
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
);
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;
80 OUStringBuffer aBuffer
;
81 GetExport().GetMM100UnitConverter().convertMeasureToXML(
83 GetExport().AddAttribute( XML_NAMESPACE_FO
,
85 aBuffer
.makeStringAndClear() );
89 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_STYLE
, XML_COLUMNS
,
94 Any aAny
= xPropSet
->getPropertyValue( sSeparatorLineIsOn
);
95 if( *static_cast<sal_Bool
const *>(aAny
.getValue()) )
98 aAny
= xPropSet
->getPropertyValue( sSeparatorLineWidth
);
101 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue
,
103 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_WIDTH
,
104 sValue
.makeStringAndClear() );
107 aAny
= xPropSet
->getPropertyValue( sSeparatorLineColor
);
108 sal_Int32 nColor
= 0;
110 ::sax::Converter::convertColor( sValue
, nColor
);
111 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_COLOR
,
112 sValue
.makeStringAndClear() );
115 aAny
= xPropSet
->getPropertyValue( sSeparatorLineRelativeHeight
);
116 sal_Int8 nHeight
= 0;
118 ::sax::Converter::convertPercent( sValue
, nHeight
);
119 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_HEIGHT
,
120 sValue
.makeStringAndClear() );
123 aAny
= xPropSet
->getPropertyValue( sSeparatorLineStyle
);
127 enum XMLTokenEnum eStr
= XML_TOKEN_INVALID
;
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;
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
;
145 eStr
= XML_TOKEN_INVALID
;
148 // case VerticalAlignment_TOP: eStr = XML_TOP;
149 case VerticalAlignment_MIDDLE
: eStr
= XML_MIDDLE
; break;
150 case VerticalAlignment_BOTTOM
: eStr
= XML_BOTTOM
; break;
155 if( eStr
!= XML_TOKEN_INVALID
)
156 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
157 XML_VERTICAL_ALIGN
, eStr
);
160 SvXMLElementExport
aElement( GetExport(), XML_NAMESPACE_STYLE
,
169 ::sax::Converter::convertNumber( sValue
, pColumns
->Width
);
170 sValue
.append( '*' );
171 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_REL_WIDTH
,
172 sValue
.makeStringAndClear() );
175 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue
,
176 pColumns
->LeftMargin
);
177 GetExport().AddAttribute( XML_NAMESPACE_FO
, XML_START_INDENT
,
178 sValue
.makeStringAndClear() );
181 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue
,
182 pColumns
->RightMargin
);
183 GetExport().AddAttribute( XML_NAMESPACE_FO
, XML_END_INDENT
,
184 sValue
.makeStringAndClear() );
187 SvXMLElementExport
aElement( GetExport(), XML_NAMESPACE_STYLE
, XML_COLUMN
,
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */