LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextColumnsExport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 50 93 53.8 %
Date: 2014-11-03 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <rtl/ustrbuf.hxx>
      21             : 
      22             : 
      23             : #include <com/sun/star/text/XTextColumns.hpp>
      24             : #include <com/sun/star/text/TextColumn.hpp>
      25             : #include <com/sun/star/style/VerticalAlignment.hpp>
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : 
      28             : #include <sax/tools/converter.hxx>
      29             : 
      30             : #include <xmloff/xmltoken.hxx>
      31             : #include <xmloff/xmlnmspe.hxx>
      32             : #include <xmloff/xmluconv.hxx>
      33             : #include <xmloff/xmlexp.hxx>
      34             : #include "XMLTextColumnsExport.hxx"
      35             : 
      36             : using namespace ::com::sun::star::style;
      37             : using namespace ::com::sun::star::text;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::xmloff::token;
      41             : 
      42             : 
      43       12936 : XMLTextColumnsExport::XMLTextColumnsExport( SvXMLExport& rExp ) :
      44             :     rExport( rExp ),
      45             :     sSeparatorLineIsOn("SeparatorLineIsOn"),
      46             :     sSeparatorLineWidth("SeparatorLineWidth"),
      47             :     sSeparatorLineColor("SeparatorLineColor"),
      48             :     sSeparatorLineRelativeHeight("SeparatorLineRelativeHeight"),
      49             :     sSeparatorLineVerticalAlignment("SeparatorLineVerticalAlignment"),
      50             :     sIsAutomatic("IsAutomatic"),
      51             :     sAutomaticDistance("AutomaticDistance"),
      52       12936 :     sSeparatorLineStyle("SeparatorLineStyle")
      53             : {
      54       12936 : }
      55             : 
      56          16 : void XMLTextColumnsExport::exportXML( const Any& rAny )
      57             : {
      58          16 :     Reference < XTextColumns > xColumns;
      59          16 :     rAny >>= xColumns;
      60             : 
      61          32 :     Sequence < TextColumn > aColumns = xColumns->getColumns();
      62          16 :     const TextColumn *pColumns = aColumns.getArray();
      63          16 :     sal_Int32 nCount = aColumns.getLength();
      64             : 
      65          32 :     OUStringBuffer sValue;
      66          16 :     ::sax::Converter::convertNumber( sValue, (nCount) ? nCount : 1 );
      67          16 :     GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLUMN_COUNT,
      68          32 :                               sValue.makeStringAndClear() );
      69             : 
      70             :     // handle 'automatic' columns
      71          32 :     Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY );
      72          16 :     if( xPropSet.is() )
      73             :     {
      74          16 :         Any aAny = xPropSet->getPropertyValue( sIsAutomatic );
      75          16 :         if ( *(sal_Bool*)aAny.getValue() )
      76             :         {
      77          16 :             aAny = xPropSet->getPropertyValue( sAutomaticDistance );
      78          16 :             sal_Int32 nDistance = 0;
      79          16 :             aAny >>= nDistance;
      80          16 :             OUStringBuffer aBuffer;
      81          16 :             GetExport().GetMM100UnitConverter().convertMeasureToXML(
      82          32 :                 aBuffer, nDistance );
      83          16 :             GetExport().AddAttribute( XML_NAMESPACE_FO,
      84             :                                       XML_COLUMN_GAP,
      85          32 :                                       aBuffer.makeStringAndClear() );
      86          16 :         }
      87             :     }
      88             : 
      89          16 :     SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMNS,
      90          32 :                               true, true );
      91             : 
      92          16 :     if( xPropSet.is() )
      93             :     {
      94          16 :         Any aAny = xPropSet->getPropertyValue( sSeparatorLineIsOn );
      95          16 :         if( *(sal_Bool *)aAny.getValue() )
      96             :         {
      97             :             // style:width
      98           0 :             aAny = xPropSet->getPropertyValue( sSeparatorLineWidth );
      99           0 :             sal_Int32 nWidth = 0;
     100           0 :             aAny >>= nWidth;
     101           0 :             GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
     102           0 :                                                                 nWidth );
     103           0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_WIDTH,
     104           0 :                                       sValue.makeStringAndClear() );
     105             : 
     106             :             // style:color
     107           0 :             aAny = xPropSet->getPropertyValue( sSeparatorLineColor );
     108           0 :             sal_Int32 nColor = 0;
     109           0 :             aAny >>= nColor;
     110           0 :             ::sax::Converter::convertColor( sValue, nColor );
     111           0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_COLOR,
     112           0 :                                       sValue.makeStringAndClear() );
     113             : 
     114             :             // style:height
     115           0 :             aAny = xPropSet->getPropertyValue( sSeparatorLineRelativeHeight );
     116           0 :             sal_Int8 nHeight = 0;
     117           0 :             aAny >>= nHeight;
     118           0 :             ::sax::Converter::convertPercent( sValue, nHeight );
     119           0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_HEIGHT,
     120           0 :                                       sValue.makeStringAndClear() );
     121             : 
     122             :             // style::style
     123           0 :             aAny = xPropSet->getPropertyValue( sSeparatorLineStyle );
     124           0 :             sal_Int8 nStyle = 0;
     125           0 :             aAny >>= nStyle;
     126             : 
     127           0 :             enum XMLTokenEnum eStr = XML_TOKEN_INVALID;
     128           0 :             switch ( nStyle )
     129             :             {
     130           0 :                 case 0:  eStr = XML_NONE; break;
     131           0 :                 case 1:  eStr = XML_SOLID; break;
     132           0 :                 case 2:  eStr = XML_DOTTED; break;
     133           0 :                 case 3:  eStr = XML_DASHED; break;
     134             :                 default:
     135           0 :                          break;
     136             :             }
     137           0 :             if ( eStr != XML_TOKEN_INVALID )
     138           0 :                 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_STYLE, eStr );
     139             : 
     140             :             // style:vertical-align
     141           0 :             aAny = xPropSet->getPropertyValue( sSeparatorLineVerticalAlignment );
     142             :             VerticalAlignment eVertAlign;
     143           0 :             aAny >>= eVertAlign;
     144             : 
     145           0 :             eStr = XML_TOKEN_INVALID;
     146           0 :             switch( eVertAlign )
     147             :             {
     148             : //          case VerticalAlignment_TOP: eStr = XML_TOP;
     149           0 :             case VerticalAlignment_MIDDLE: eStr = XML_MIDDLE; break;
     150           0 :             case VerticalAlignment_BOTTOM: eStr = XML_BOTTOM; break;
     151             :             default:
     152           0 :                 break;
     153             :             }
     154             : 
     155           0 :             if( eStr != XML_TOKEN_INVALID)
     156           0 :                 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     157           0 :                                           XML_VERTICAL_ALIGN, eStr );
     158             : 
     159             :             // style:column-sep
     160           0 :             SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
     161             :                                       XML_COLUMN_SEP,
     162           0 :                                       true, true );
     163          16 :         }
     164             :     }
     165             : 
     166          44 :     while( nCount-- )
     167             :     {
     168             :         // style:rel-width
     169          12 :         ::sax::Converter::convertNumber( sValue, pColumns->Width );
     170          12 :         sValue.append( '*' );
     171          12 :         GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
     172          24 :                                   sValue.makeStringAndClear() );
     173             : 
     174             :         // fo:margin-left
     175          12 :         GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
     176          24 :                                                        pColumns->LeftMargin );
     177          12 :         GetExport().AddAttribute( XML_NAMESPACE_FO, XML_START_INDENT,
     178          24 :                                        sValue.makeStringAndClear() );
     179             : 
     180             :         // fo:margin-right
     181          12 :         GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
     182          24 :                                                        pColumns->RightMargin );
     183          12 :         GetExport().AddAttribute( XML_NAMESPACE_FO, XML_END_INDENT,
     184          24 :                                     sValue.makeStringAndClear() );
     185             : 
     186             :         // style:column
     187          12 :         SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMN,
     188          12 :                                   true, true );
     189          12 :         pColumns++;
     190          28 :     }
     191          16 : }
     192             : 
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10