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/ColumnSeparatorStyle.hpp>
28 #include <com/sun/star/text/TextColumn.hpp>
29 #include <com/sun/star/style/VerticalAlignment.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <sax/tools/converter.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmlnamespace.hxx>
36 #include <xmloff/xmluconv.hxx>
37 #include <xmloff/xmlexp.hxx>
38 #include <XMLTextColumnsExport.hxx>
40 using namespace ::com::sun::star::style
;
41 using namespace ::com::sun::star::text
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::beans
;
44 using namespace ::xmloff::token
;
47 constexpr OUStringLiteral
gsSeparatorLineIsOn(u
"SeparatorLineIsOn");
48 constexpr OUStringLiteral
gsSeparatorLineWidth(u
"SeparatorLineWidth");
49 constexpr OUStringLiteral
gsSeparatorLineColor(u
"SeparatorLineColor");
50 constexpr OUStringLiteral
gsSeparatorLineRelativeHeight(u
"SeparatorLineRelativeHeight");
51 constexpr OUStringLiteral
gsSeparatorLineVerticalAlignment(u
"SeparatorLineVerticalAlignment");
52 constexpr OUStringLiteral
gsIsAutomatic(u
"IsAutomatic");
53 constexpr OUStringLiteral
gsAutomaticDistance(u
"AutomaticDistance");
54 constexpr OUStringLiteral
gsSeparatorLineStyle(u
"SeparatorLineStyle");
56 XMLTextColumnsExport::XMLTextColumnsExport( SvXMLExport
& rExp
) :
61 void XMLTextColumnsExport::exportXML( const Any
& rAny
)
63 Reference
< XTextColumns
> xColumns
;
68 const Sequence
< TextColumn
> aColumns
= xColumns
->getColumns();
69 sal_Int32 nCount
= aColumns
.getLength();
71 OUStringBuffer sValue
;
72 GetExport().AddAttribute( XML_NAMESPACE_FO
, XML_COLUMN_COUNT
,
73 OUString::number(nCount
? nCount
: 1) );
75 // handle 'automatic' columns
76 Reference
< XPropertySet
> xPropSet( xColumns
, UNO_QUERY
);
79 Any aAny
= xPropSet
->getPropertyValue( gsIsAutomatic
);
80 if ( *o3tl::doAccess
<bool>(aAny
) )
82 aAny
= xPropSet
->getPropertyValue( gsAutomaticDistance
);
83 sal_Int32 nDistance
= 0;
85 OUStringBuffer aBuffer
;
86 GetExport().GetMM100UnitConverter().convertMeasureToXML(
88 GetExport().AddAttribute( XML_NAMESPACE_FO
,
90 aBuffer
.makeStringAndClear() );
94 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_STYLE
, XML_COLUMNS
,
99 Any aAny
= xPropSet
->getPropertyValue( gsSeparatorLineIsOn
);
100 if( *o3tl::doAccess
<bool>(aAny
) )
103 aAny
= xPropSet
->getPropertyValue( gsSeparatorLineWidth
);
104 sal_Int32 nWidth
= 0;
106 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue
,
108 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_WIDTH
,
109 sValue
.makeStringAndClear() );
112 aAny
= xPropSet
->getPropertyValue( gsSeparatorLineColor
);
113 sal_Int32 nColor
= 0;
115 ::sax::Converter::convertColor( sValue
, nColor
);
116 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_COLOR
,
117 sValue
.makeStringAndClear() );
120 aAny
= xPropSet
->getPropertyValue( gsSeparatorLineRelativeHeight
);
121 sal_Int32 nHeight
= 0;
123 ::sax::Converter::convertPercent( sValue
, nHeight
);
124 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_HEIGHT
,
125 sValue
.makeStringAndClear() );
128 aAny
= xPropSet
->getPropertyValue( gsSeparatorLineStyle
);
129 sal_Int16 nStyle
= css::text::ColumnSeparatorStyle::NONE
;
132 enum XMLTokenEnum eStr
= XML_TOKEN_INVALID
;
135 case css::text::ColumnSeparatorStyle::NONE
: eStr
= XML_NONE
; break;
136 case css::text::ColumnSeparatorStyle::SOLID
: eStr
= XML_SOLID
; break;
137 case css::text::ColumnSeparatorStyle::DOTTED
: eStr
= XML_DOTTED
; break;
138 case css::text::ColumnSeparatorStyle::DASHED
: eStr
= XML_DASHED
; break;
142 if ( eStr
!= XML_TOKEN_INVALID
)
143 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_STYLE
, eStr
);
145 // style:vertical-align
146 aAny
= xPropSet
->getPropertyValue( gsSeparatorLineVerticalAlignment
);
147 VerticalAlignment eVertAlign
;
150 eStr
= XML_TOKEN_INVALID
;
153 // case VerticalAlignment_TOP: eStr = XML_TOP;
154 case VerticalAlignment_MIDDLE
: eStr
= XML_MIDDLE
; break;
155 case VerticalAlignment_BOTTOM
: eStr
= XML_BOTTOM
; break;
160 if( eStr
!= XML_TOKEN_INVALID
)
161 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
162 XML_VERTICAL_ALIGN
, eStr
);
165 SvXMLElementExport
aElement( GetExport(), XML_NAMESPACE_STYLE
,
171 for (const auto& rColumn
: aColumns
)
174 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_REL_WIDTH
,
175 OUString::number(rColumn
.Width
) + "*" );
178 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue
,
179 rColumn
.LeftMargin
);
180 GetExport().AddAttribute( XML_NAMESPACE_FO
, XML_START_INDENT
,
181 sValue
.makeStringAndClear() );
184 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue
,
185 rColumn
.RightMargin
);
186 GetExport().AddAttribute( XML_NAMESPACE_FO
, XML_END_INDENT
,
187 sValue
.makeStringAndClear() );
190 SvXMLElementExport
aElement( GetExport(), XML_NAMESPACE_STYLE
, XML_COLUMN
,
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */