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 <sal/config.h>
22 #include <o3tl/any.hxx>
23 #include <rtl/ustrbuf.hxx>
26 #include <com/sun/star/text/XTextColumns.hpp>
27 #include <com/sun/star/text/TextColumn.hpp>
28 #include <com/sun/star/style/VerticalAlignment.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <sax/tools/converter.hxx>
33 #include <xmloff/xmltoken.hxx>
34 #include <xmloff/xmlnamespace.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include <xmloff/xmlexp.hxx>
37 #include <XMLTextColumnsExport.hxx>
39 using namespace ::com::sun::star::style
;
40 using namespace ::com::sun::star::text
;
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::beans
;
43 using namespace ::xmloff::token
;
46 constexpr OUStringLiteral
gsSeparatorLineIsOn(u
"SeparatorLineIsOn");
47 constexpr OUStringLiteral
gsSeparatorLineWidth(u
"SeparatorLineWidth");
48 constexpr OUStringLiteral
gsSeparatorLineColor(u
"SeparatorLineColor");
49 constexpr OUStringLiteral
gsSeparatorLineRelativeHeight(u
"SeparatorLineRelativeHeight");
50 constexpr OUStringLiteral
gsSeparatorLineVerticalAlignment(u
"SeparatorLineVerticalAlignment");
51 constexpr OUStringLiteral
gsIsAutomatic(u
"IsAutomatic");
52 constexpr OUStringLiteral
gsAutomaticDistance(u
"AutomaticDistance");
53 constexpr OUStringLiteral
gsSeparatorLineStyle(u
"SeparatorLineStyle");
55 XMLTextColumnsExport::XMLTextColumnsExport( SvXMLExport
& rExp
) :
60 void XMLTextColumnsExport::exportXML( const Any
& rAny
)
62 Reference
< XTextColumns
> xColumns
;
65 const Sequence
< TextColumn
> aColumns
= xColumns
->getColumns();
66 sal_Int32 nCount
= aColumns
.getLength();
68 OUStringBuffer sValue
;
69 GetExport().AddAttribute( XML_NAMESPACE_FO
, XML_COLUMN_COUNT
,
70 OUString::number(nCount
? nCount
: 1) );
72 // handle 'automatic' columns
73 Reference
< XPropertySet
> xPropSet( xColumns
, UNO_QUERY
);
76 Any aAny
= xPropSet
->getPropertyValue( gsIsAutomatic
);
77 if ( *o3tl::doAccess
<bool>(aAny
) )
79 aAny
= xPropSet
->getPropertyValue( gsAutomaticDistance
);
80 sal_Int32 nDistance
= 0;
82 OUStringBuffer aBuffer
;
83 GetExport().GetMM100UnitConverter().convertMeasureToXML(
85 GetExport().AddAttribute( XML_NAMESPACE_FO
,
87 aBuffer
.makeStringAndClear() );
91 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_STYLE
, XML_COLUMNS
,
96 Any aAny
= xPropSet
->getPropertyValue( gsSeparatorLineIsOn
);
97 if( *o3tl::doAccess
<bool>(aAny
) )
100 aAny
= xPropSet
->getPropertyValue( gsSeparatorLineWidth
);
101 sal_Int32 nWidth
= 0;
103 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue
,
105 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_WIDTH
,
106 sValue
.makeStringAndClear() );
109 aAny
= xPropSet
->getPropertyValue( gsSeparatorLineColor
);
110 sal_Int32 nColor
= 0;
112 ::sax::Converter::convertColor( sValue
, nColor
);
113 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_COLOR
,
114 sValue
.makeStringAndClear() );
117 aAny
= xPropSet
->getPropertyValue( gsSeparatorLineRelativeHeight
);
118 sal_Int8 nHeight
= 0;
120 ::sax::Converter::convertPercent( sValue
, nHeight
);
121 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_HEIGHT
,
122 sValue
.makeStringAndClear() );
125 aAny
= xPropSet
->getPropertyValue( gsSeparatorLineStyle
);
129 enum XMLTokenEnum eStr
= XML_TOKEN_INVALID
;
132 case 0: eStr
= XML_NONE
; break;
133 case 1: eStr
= XML_SOLID
; break;
134 case 2: eStr
= XML_DOTTED
; break;
135 case 3: eStr
= XML_DASHED
; break;
139 if ( eStr
!= XML_TOKEN_INVALID
)
140 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_STYLE
, eStr
);
142 // style:vertical-align
143 aAny
= xPropSet
->getPropertyValue( gsSeparatorLineVerticalAlignment
);
144 VerticalAlignment eVertAlign
;
147 eStr
= XML_TOKEN_INVALID
;
150 // case VerticalAlignment_TOP: eStr = XML_TOP;
151 case VerticalAlignment_MIDDLE
: eStr
= XML_MIDDLE
; break;
152 case VerticalAlignment_BOTTOM
: eStr
= XML_BOTTOM
; break;
157 if( eStr
!= XML_TOKEN_INVALID
)
158 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
159 XML_VERTICAL_ALIGN
, eStr
);
162 SvXMLElementExport
aElement( GetExport(), XML_NAMESPACE_STYLE
,
168 for (const auto& rColumn
: aColumns
)
171 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_REL_WIDTH
,
172 OUString::number(rColumn
.Width
) + "*" );
175 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue
,
176 rColumn
.LeftMargin
);
177 GetExport().AddAttribute( XML_NAMESPACE_FO
, XML_START_INDENT
,
178 sValue
.makeStringAndClear() );
181 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue
,
182 rColumn
.RightMargin
);
183 GetExport().AddAttribute( XML_NAMESPACE_FO
, XML_END_INDENT
,
184 sValue
.makeStringAndClear() );
187 SvXMLElementExport
aElement( GetExport(), XML_NAMESPACE_STYLE
, XML_COLUMN
,
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */