nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / text / XMLTextColumnsExport.cxx
blob13f06fde36e6d32ad9dcbe3f3fdc2eb2ce02bfc7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 ) :
56 rExport( rExp )
60 void XMLTextColumnsExport::exportXML( const Any& rAny )
62 Reference < XTextColumns > xColumns;
63 rAny >>= 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 );
74 if( xPropSet.is() )
76 Any aAny = xPropSet->getPropertyValue( gsIsAutomatic );
77 if ( *o3tl::doAccess<bool>(aAny) )
79 aAny = xPropSet->getPropertyValue( gsAutomaticDistance );
80 sal_Int32 nDistance = 0;
81 aAny >>= nDistance;
82 OUStringBuffer aBuffer;
83 GetExport().GetMM100UnitConverter().convertMeasureToXML(
84 aBuffer, nDistance );
85 GetExport().AddAttribute( XML_NAMESPACE_FO,
86 XML_COLUMN_GAP,
87 aBuffer.makeStringAndClear() );
91 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMNS,
92 true, true );
94 if( xPropSet.is() )
96 Any aAny = xPropSet->getPropertyValue( gsSeparatorLineIsOn );
97 if( *o3tl::doAccess<bool>(aAny) )
99 // style:width
100 aAny = xPropSet->getPropertyValue( gsSeparatorLineWidth );
101 sal_Int32 nWidth = 0;
102 aAny >>= nWidth;
103 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
104 nWidth );
105 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_WIDTH,
106 sValue.makeStringAndClear() );
108 // style:color
109 aAny = xPropSet->getPropertyValue( gsSeparatorLineColor );
110 sal_Int32 nColor = 0;
111 aAny >>= nColor;
112 ::sax::Converter::convertColor( sValue, nColor );
113 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_COLOR,
114 sValue.makeStringAndClear() );
116 // style:height
117 aAny = xPropSet->getPropertyValue( gsSeparatorLineRelativeHeight );
118 sal_Int8 nHeight = 0;
119 aAny >>= nHeight;
120 ::sax::Converter::convertPercent( sValue, nHeight );
121 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_HEIGHT,
122 sValue.makeStringAndClear() );
124 // style::style
125 aAny = xPropSet->getPropertyValue( gsSeparatorLineStyle );
126 sal_Int8 nStyle = 0;
127 aAny >>= nStyle;
129 enum XMLTokenEnum eStr = XML_TOKEN_INVALID;
130 switch ( nStyle )
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;
136 default:
137 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;
145 aAny >>= eVertAlign;
147 eStr = XML_TOKEN_INVALID;
148 switch( eVertAlign )
150 // case VerticalAlignment_TOP: eStr = XML_TOP;
151 case VerticalAlignment_MIDDLE: eStr = XML_MIDDLE; break;
152 case VerticalAlignment_BOTTOM: eStr = XML_BOTTOM; break;
153 default:
154 break;
157 if( eStr != XML_TOKEN_INVALID)
158 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
159 XML_VERTICAL_ALIGN, eStr );
161 // style:column-sep
162 SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
163 XML_COLUMN_SEP,
164 true, true );
168 for (const auto& rColumn : aColumns)
170 // style:rel-width
171 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
172 OUString::number(rColumn.Width) + "*" );
174 // fo:margin-left
175 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
176 rColumn.LeftMargin );
177 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_START_INDENT,
178 sValue.makeStringAndClear() );
180 // fo:margin-right
181 GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
182 rColumn.RightMargin );
183 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_END_INDENT,
184 sValue.makeStringAndClear() );
186 // style:column
187 SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMN,
188 true, true );
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */