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

Generated by: LCOV version 1.10