LibreOffice Module xmloff (master) 1
XMLTextColumnsExport.cxx
Go to the documentation of this file.
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 <sal/config.h>
21
22#include <o3tl/any.hxx>
23#include <rtl/ustrbuf.hxx>
24
25
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>
31
33
34#include <xmloff/xmltoken.hxx>
36#include <xmloff/xmluconv.hxx>
37#include <xmloff/xmlexp.hxx>
39
40using namespace ::com::sun::star::style;
41using namespace ::com::sun::star::text;
42using namespace ::com::sun::star::uno;
43using namespace ::com::sun::star::beans;
44using namespace ::xmloff::token;
45
46
47constexpr OUStringLiteral gsSeparatorLineIsOn(u"SeparatorLineIsOn");
48constexpr OUStringLiteral gsSeparatorLineWidth(u"SeparatorLineWidth");
49constexpr OUStringLiteral gsSeparatorLineColor(u"SeparatorLineColor");
50constexpr OUStringLiteral gsSeparatorLineRelativeHeight(u"SeparatorLineRelativeHeight");
51constexpr OUStringLiteral gsSeparatorLineVerticalAlignment(u"SeparatorLineVerticalAlignment");
52constexpr OUStringLiteral gsIsAutomatic(u"IsAutomatic");
53constexpr OUStringLiteral gsAutomaticDistance(u"AutomaticDistance");
54constexpr OUStringLiteral gsSeparatorLineStyle(u"SeparatorLineStyle");
55
57 rExport( rExp )
58{
59}
60
61void XMLTextColumnsExport::exportXML( const Any& rAny )
62{
63 Reference < XTextColumns > xColumns;
64 rAny >>= xColumns;
65 if (!xColumns)
66 return;
67
68 const Sequence < TextColumn > aColumns = xColumns->getColumns();
69 sal_Int32 nCount = aColumns.getLength();
70
71 OUStringBuffer sValue;
73 OUString::number(nCount ? nCount : 1) );
74
75 // handle 'automatic' columns
76 Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY );
77 if( xPropSet.is() )
78 {
79 Any aAny = xPropSet->getPropertyValue( gsIsAutomatic );
80 if ( *o3tl::doAccess<bool>(aAny) )
81 {
82 aAny = xPropSet->getPropertyValue( gsAutomaticDistance );
83 sal_Int32 nDistance = 0;
84 aAny >>= nDistance;
85 OUStringBuffer aBuffer;
87 aBuffer, nDistance );
90 aBuffer.makeStringAndClear() );
91 }
92 }
93
95 true, true );
96
97 if( xPropSet.is() )
98 {
99 Any aAny = xPropSet->getPropertyValue( gsSeparatorLineIsOn );
100 if( *o3tl::doAccess<bool>(aAny) )
101 {
102 // style:width
103 aAny = xPropSet->getPropertyValue( gsSeparatorLineWidth );
104 sal_Int32 nWidth = 0;
105 aAny >>= nWidth;
107 nWidth );
109 sValue.makeStringAndClear() );
110
111 // style:color
112 aAny = xPropSet->getPropertyValue( gsSeparatorLineColor );
113 sal_Int32 nColor = 0;
114 aAny >>= nColor;
115 ::sax::Converter::convertColor( sValue, nColor );
117 sValue.makeStringAndClear() );
118
119 // style:height
120 aAny = xPropSet->getPropertyValue( gsSeparatorLineRelativeHeight );
121 sal_Int32 nHeight = 0;
122 aAny >>= nHeight;
123 ::sax::Converter::convertPercent( sValue, nHeight );
125 sValue.makeStringAndClear() );
126
127 // style::style
128 aAny = xPropSet->getPropertyValue( gsSeparatorLineStyle );
129 sal_Int16 nStyle = css::text::ColumnSeparatorStyle::NONE;
130 aAny >>= nStyle;
131
133 switch ( nStyle )
134 {
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;
139 default:
140 break;
141 }
142 if ( eStr != XML_TOKEN_INVALID )
144
145 // style:vertical-align
146 aAny = xPropSet->getPropertyValue( gsSeparatorLineVerticalAlignment );
147 VerticalAlignment eVertAlign;
148 aAny >>= eVertAlign;
149
150 eStr = XML_TOKEN_INVALID;
151 switch( eVertAlign )
152 {
153// case VerticalAlignment_TOP: eStr = XML_TOP;
154 case VerticalAlignment_MIDDLE: eStr = XML_MIDDLE; break;
155 case VerticalAlignment_BOTTOM: eStr = XML_BOTTOM; break;
156 default:
157 break;
158 }
159
160 if( eStr != XML_TOKEN_INVALID)
162 XML_VERTICAL_ALIGN, eStr );
163
164 // style:column-sep
167 true, true );
168 }
169 }
170
171 for (const auto& rColumn : aColumns)
172 {
173 // style:rel-width
175 OUString::number(rColumn.Width) + "*" );
176
177 // fo:margin-left
179 rColumn.LeftMargin );
181 sValue.makeStringAndClear() );
182
183 // fo:margin-right
185 rColumn.RightMargin );
187 sValue.makeStringAndClear() );
188
189 // style:column
191 true, true );
192 }
193}
194
195
196/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral gsSeparatorLineVerticalAlignment(u"SeparatorLineVerticalAlignment")
constexpr OUStringLiteral gsSeparatorLineStyle(u"SeparatorLineStyle")
constexpr OUStringLiteral gsIsAutomatic(u"IsAutomatic")
constexpr OUStringLiteral gsSeparatorLineWidth(u"SeparatorLineWidth")
constexpr OUStringLiteral gsSeparatorLineColor(u"SeparatorLineColor")
constexpr OUStringLiteral gsSeparatorLineIsOn(u"SeparatorLineIsOn")
constexpr OUStringLiteral gsSeparatorLineRelativeHeight(u"SeparatorLineRelativeHeight")
constexpr OUStringLiteral gsAutomaticDistance(u"AutomaticDistance")
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
Definition: xmlexp.cxx:907
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlexp.hxx:391
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit
Definition: xmluconv.cxx:208
void exportXML(const css::uno::Any &rAny)
XMLTextColumnsExport(SvXMLExport &rExport)
static bool convertPercent(sal_Int32 &rValue, std::u16string_view rString)
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
int nCount
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
std::unique_ptr< char[]> aBuffer
constexpr sal_uInt16 XML_NAMESPACE_STYLE
constexpr sal_uInt16 XML_NAMESPACE_FO