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 
31 #include <sax/tools/converter.hxx>
32 
33 #include <xmloff/xmltoken.hxx>
34 #include <xmloff/xmlnamespace.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include <xmloff/xmlexp.hxx>
37 #include <XMLTextColumnsExport.hxx>
38 
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;
44 
45 
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");
54 
56  rExport( rExp )
57 {
58 }
59 
60 void 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 
131  enum XMLTokenEnum eStr = XML_TOKEN_INVALID;
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 gsSeparatorLineStyle(u"SeparatorLineStyle")
signed char sal_Int8
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlexp.hxx:400
XMLTextColumnsExport(SvXMLExport &rExport)
int nCount
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:939
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:49
constexpr OUStringLiteral gsSeparatorLineVerticalAlignment(u"SeparatorLineVerticalAlignment")
constexpr OUStringLiteral gsSeparatorLineIsOn(u"SeparatorLineIsOn")
constexpr sal_uInt16 XML_NAMESPACE_FO
constexpr OUStringLiteral gsSeparatorLineWidth(u"SeparatorLineWidth")
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
static bool convertPercent(sal_Int32 &rValue, std::u16string_view rString)
std::unique_ptr< char[]> aBuffer
constexpr OUStringLiteral gsSeparatorLineRelativeHeight(u"SeparatorLineRelativeHeight")
constexpr OUStringLiteral gsAutomaticDistance(u"AutomaticDistance")
Handling of tokens in XML:
css::uno::Any const SvXMLExport & rExport
Definition: ImageStyle.hxx:38
constexpr OUStringLiteral gsSeparatorLineColor(u"SeparatorLineColor")
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit
Definition: xmluconv.cxx:206
constexpr sal_uInt16 XML_NAMESPACE_STYLE
constexpr OUStringLiteral gsIsAutomatic(u"IsAutomatic")
void exportXML(const css::uno::Any &rAny)