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/TextColumn.hpp>
28#include <com/sun/star/style/VerticalAlignment.hpp>
29#include <com/sun/star/beans/XPropertySet.hpp>
30
32
33#include <xmloff/xmltoken.hxx>
35#include <xmloff/xmluconv.hxx>
36#include <xmloff/xmlexp.hxx>
38
39using namespace ::com::sun::star::style;
40using namespace ::com::sun::star::text;
41using namespace ::com::sun::star::uno;
42using namespace ::com::sun::star::beans;
43using namespace ::xmloff::token;
44
45
46constexpr OUStringLiteral gsSeparatorLineIsOn(u"SeparatorLineIsOn");
47constexpr OUStringLiteral gsSeparatorLineWidth(u"SeparatorLineWidth");
48constexpr OUStringLiteral gsSeparatorLineColor(u"SeparatorLineColor");
49constexpr OUStringLiteral gsSeparatorLineRelativeHeight(u"SeparatorLineRelativeHeight");
50constexpr OUStringLiteral gsSeparatorLineVerticalAlignment(u"SeparatorLineVerticalAlignment");
51constexpr OUStringLiteral gsIsAutomatic(u"IsAutomatic");
52constexpr OUStringLiteral gsAutomaticDistance(u"AutomaticDistance");
53constexpr OUStringLiteral gsSeparatorLineStyle(u"SeparatorLineStyle");
54
56 rExport( rExp )
57{
58}
59
60void XMLTextColumnsExport::exportXML( const Any& rAny )
61{
62 Reference < XTextColumns > xColumns;
63 rAny >>= xColumns;
64 if (!xColumns)
65 return;
66
67 const Sequence < TextColumn > aColumns = xColumns->getColumns();
68 sal_Int32 nCount = aColumns.getLength();
69
70 OUStringBuffer sValue;
72 OUString::number(nCount ? nCount : 1) );
73
74 // handle 'automatic' columns
75 Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY );
76 if( xPropSet.is() )
77 {
78 Any aAny = xPropSet->getPropertyValue( gsIsAutomatic );
79 if ( *o3tl::doAccess<bool>(aAny) )
80 {
81 aAny = xPropSet->getPropertyValue( gsAutomaticDistance );
82 sal_Int32 nDistance = 0;
83 aAny >>= nDistance;
84 OUStringBuffer aBuffer;
86 aBuffer, nDistance );
89 aBuffer.makeStringAndClear() );
90 }
91 }
92
94 true, true );
95
96 if( xPropSet.is() )
97 {
98 Any aAny = xPropSet->getPropertyValue( gsSeparatorLineIsOn );
99 if( *o3tl::doAccess<bool>(aAny) )
100 {
101 // style:width
102 aAny = xPropSet->getPropertyValue( gsSeparatorLineWidth );
103 sal_Int32 nWidth = 0;
104 aAny >>= nWidth;
106 nWidth );
108 sValue.makeStringAndClear() );
109
110 // style:color
111 aAny = xPropSet->getPropertyValue( gsSeparatorLineColor );
112 sal_Int32 nColor = 0;
113 aAny >>= nColor;
114 ::sax::Converter::convertColor( sValue, nColor );
116 sValue.makeStringAndClear() );
117
118 // style:height
119 aAny = xPropSet->getPropertyValue( gsSeparatorLineRelativeHeight );
120 sal_Int8 nHeight = 0;
121 aAny >>= nHeight;
122 ::sax::Converter::convertPercent( sValue, nHeight );
124 sValue.makeStringAndClear() );
125
126 // style::style
127 aAny = xPropSet->getPropertyValue( gsSeparatorLineStyle );
128 sal_Int8 nStyle = 0;
129 aAny >>= nStyle;
130
132 switch ( nStyle )
133 {
134 case 0: eStr = XML_NONE; break;
135 case 1: eStr = XML_SOLID; break;
136 case 2: eStr = XML_DOTTED; break;
137 case 3: eStr = XML_DASHED; break;
138 default:
139 break;
140 }
141 if ( eStr != XML_TOKEN_INVALID )
143
144 // style:vertical-align
145 aAny = xPropSet->getPropertyValue( gsSeparatorLineVerticalAlignment );
146 VerticalAlignment eVertAlign;
147 aAny >>= eVertAlign;
148
149 eStr = XML_TOKEN_INVALID;
150 switch( eVertAlign )
151 {
152// case VerticalAlignment_TOP: eStr = XML_TOP;
153 case VerticalAlignment_MIDDLE: eStr = XML_MIDDLE; break;
154 case VerticalAlignment_BOTTOM: eStr = XML_BOTTOM; break;
155 default:
156 break;
157 }
158
159 if( eStr != XML_TOKEN_INVALID)
161 XML_VERTICAL_ALIGN, eStr );
162
163 // style:column-sep
166 true, true );
167 }
168 }
169
170 for (const auto& rColumn : aColumns)
171 {
172 // style:rel-width
174 OUString::number(rColumn.Width) + "*" );
175
176 // fo:margin-left
178 rColumn.LeftMargin );
180 sValue.makeStringAndClear() );
181
182 // fo:margin-right
184 rColumn.RightMargin );
186 sValue.makeStringAndClear() );
187
188 // style:column
190 true, true );
191 }
192}
193
194
195/* 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:911
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlexp.hxx:396
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit
Definition: xmluconv.cxx:206
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
signed char sal_Int8
std::unique_ptr< char[]> aBuffer
constexpr sal_uInt16 XML_NAMESPACE_STYLE
constexpr sal_uInt16 XML_NAMESPACE_FO