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 const OUStringLiteral gsSeparatorLineIsOn(u"SeparatorLineIsOn");
47 const OUStringLiteral gsSeparatorLineWidth(u"SeparatorLineWidth");
48 const OUStringLiteral gsSeparatorLineColor(u"SeparatorLineColor");
49 const OUStringLiteral gsSeparatorLineRelativeHeight(u"SeparatorLineRelativeHeight");
50 const OUStringLiteral gsSeparatorLineVerticalAlignment(u"SeparatorLineVerticalAlignment");
51 const OUStringLiteral gsIsAutomatic(u"IsAutomatic");
52 const OUStringLiteral gsAutomaticDistance(u"AutomaticDistance");
53 const 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 
65  const Sequence < TextColumn > aColumns = xColumns->getColumns();
66  sal_Int32 nCount = aColumns.getLength();
67 
68  OUStringBuffer sValue;
70  OUString::number(nCount ? nCount : 1) );
71 
72  // handle 'automatic' columns
73  Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY );
74  if( xPropSet.is() )
75  {
76  Any aAny = xPropSet->getPropertyValue( gsIsAutomatic );
77  if ( *o3tl::doAccess<bool>(aAny) )
78  {
79  aAny = xPropSet->getPropertyValue( gsAutomaticDistance );
80  sal_Int32 nDistance = 0;
81  aAny >>= nDistance;
82  OUStringBuffer aBuffer;
84  aBuffer, nDistance );
87  aBuffer.makeStringAndClear() );
88  }
89  }
90 
92  true, true );
93 
94  if( xPropSet.is() )
95  {
96  Any aAny = xPropSet->getPropertyValue( gsSeparatorLineIsOn );
97  if( *o3tl::doAccess<bool>(aAny) )
98  {
99  // style:width
100  aAny = xPropSet->getPropertyValue( gsSeparatorLineWidth );
101  sal_Int32 nWidth = 0;
102  aAny >>= nWidth;
104  nWidth );
106  sValue.makeStringAndClear() );
107 
108  // style:color
109  aAny = xPropSet->getPropertyValue( gsSeparatorLineColor );
110  sal_Int32 nColor = 0;
111  aAny >>= nColor;
112  ::sax::Converter::convertColor( sValue, nColor );
114  sValue.makeStringAndClear() );
115 
116  // style:height
117  aAny = xPropSet->getPropertyValue( gsSeparatorLineRelativeHeight );
118  sal_Int8 nHeight = 0;
119  aAny >>= nHeight;
120  ::sax::Converter::convertPercent( sValue, nHeight );
122  sValue.makeStringAndClear() );
123 
124  // style::style
125  aAny = xPropSet->getPropertyValue( gsSeparatorLineStyle );
126  sal_Int8 nStyle = 0;
127  aAny >>= nStyle;
128 
129  enum XMLTokenEnum eStr = XML_TOKEN_INVALID;
130  switch ( nStyle )
131  {
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;
138  }
139  if ( eStr != XML_TOKEN_INVALID )
141 
142  // style:vertical-align
143  aAny = xPropSet->getPropertyValue( gsSeparatorLineVerticalAlignment );
144  VerticalAlignment eVertAlign;
145  aAny >>= eVertAlign;
146 
147  eStr = XML_TOKEN_INVALID;
148  switch( eVertAlign )
149  {
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;
155  }
156 
157  if( eStr != XML_TOKEN_INVALID)
159  XML_VERTICAL_ALIGN, eStr );
160 
161  // style:column-sep
164  true, true );
165  }
166  }
167 
168  for (const auto& rColumn : aColumns)
169  {
170  // style:rel-width
172  OUString::number(rColumn.Width) + "*" );
173 
174  // fo:margin-left
176  rColumn.LeftMargin );
178  sValue.makeStringAndClear() );
179 
180  // fo:margin-right
182  rColumn.RightMargin );
184  sValue.makeStringAndClear() );
185 
186  // style:column
188  true, true );
189  }
190 }
191 
192 
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
signed char sal_Int8
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlexp.hxx:394
XMLTextColumnsExport(SvXMLExport &rExport)
const OUStringLiteral gsSeparatorLineWidth(u"SeparatorLineWidth")
const OUStringLiteral gsSeparatorLineIsOn(u"SeparatorLineIsOn")
const OUStringLiteral gsSeparatorLineStyle(u"SeparatorLineStyle")
int nCount
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:909
const OUStringLiteral gsSeparatorLineColor(u"SeparatorLineColor")
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:49
constexpr sal_uInt16 XML_NAMESPACE_FO
const OUStringLiteral gsAutomaticDistance(u"AutomaticDistance")
const OUStringLiteral gsSeparatorLineRelativeHeight(u"SeparatorLineRelativeHeight")
std::unique_ptr< char[]> aBuffer
static bool convertColor(sal_Int32 &rColor, const OUString &rValue)
Handling of tokens in XML:
const OUStringLiteral gsSeparatorLineVerticalAlignment(u"SeparatorLineVerticalAlignment")
const OUStringLiteral gsIsAutomatic(u"IsAutomatic")
css::uno::Any const SvXMLExport & rExport
Definition: ImageStyle.hxx:38
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit
Definition: xmluconv.cxx:181
constexpr sal_uInt16 XML_NAMESPACE_STYLE
static bool convertPercent(sal_Int32 &rValue, const OUString &rString)
void exportXML(const css::uno::Any &rAny)