LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextColumnsExport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 50 93 53.8 %
Date: 2012-08-25 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 47 150 31.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <rtl/ustrbuf.hxx>
      30                 :            : 
      31                 :            : 
      32                 :            : #include <com/sun/star/text/XTextColumns.hpp>
      33                 :            : #include <com/sun/star/text/TextColumn.hpp>
      34                 :            : #include <com/sun/star/style/VerticalAlignment.hpp>
      35                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      36                 :            : 
      37                 :            : #include <sax/tools/converter.hxx>
      38                 :            : 
      39                 :            : #include <xmloff/xmltoken.hxx>
      40                 :            : #include "xmloff/xmlnmspe.hxx"
      41                 :            : #include <xmloff/xmluconv.hxx>
      42                 :            : #include <xmloff/xmlexp.hxx>
      43                 :            : #include "XMLTextColumnsExport.hxx"
      44                 :            : 
      45                 :            : using namespace ::com::sun::star::style;
      46                 :            : using namespace ::com::sun::star::text;
      47                 :            : using namespace ::com::sun::star::uno;
      48                 :            : using namespace ::com::sun::star::beans;
      49                 :            : using ::rtl::OUString;
      50                 :            : using ::rtl::OUStringBuffer;
      51                 :            : using namespace ::xmloff::token;
      52                 :            : 
      53                 :            : 
      54                 :        778 : XMLTextColumnsExport::XMLTextColumnsExport( SvXMLExport& rExp ) :
      55                 :            :     rExport( rExp ),
      56                 :            :     sSeparatorLineIsOn(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineIsOn")),
      57                 :            :     sSeparatorLineWidth(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineWidth")),
      58                 :            :     sSeparatorLineColor(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineColor")),
      59                 :            :     sSeparatorLineRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineRelativeHeight")),
      60                 :            :     sSeparatorLineVerticalAlignment(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineVerticalAlignment")),
      61                 :            :     sIsAutomatic(RTL_CONSTASCII_USTRINGPARAM("IsAutomatic")),
      62                 :            :     sAutomaticDistance(RTL_CONSTASCII_USTRINGPARAM("AutomaticDistance")),
      63 [ +  - ][ +  - ]:        778 :     sSeparatorLineStyle(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineStyle"))
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      64                 :            : {
      65                 :        778 : }
      66                 :            : 
      67                 :          8 : void XMLTextColumnsExport::exportXML( const Any& rAny )
      68                 :            : {
      69                 :          8 :     Reference < XTextColumns > xColumns;
      70         [ +  - ]:          8 :     rAny >>= xColumns;
      71                 :            : 
      72 [ +  - ][ +  - ]:          8 :     Sequence < TextColumn > aColumns = xColumns->getColumns();
      73         [ +  - ]:          8 :     const TextColumn *pColumns = aColumns.getArray();
      74                 :          8 :     sal_Int32 nCount = aColumns.getLength();
      75                 :            : 
      76                 :          8 :     OUStringBuffer sValue;
      77 [ +  - ][ +  + ]:          8 :     ::sax::Converter::convertNumber( sValue, (nCount) ? nCount : 1 );
      78                 :          8 :     GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLUMN_COUNT,
      79   [ +  -  +  - ]:         16 :                               sValue.makeStringAndClear() );
      80                 :            : 
      81                 :            :     // handle 'automatic' columns
      82         [ +  - ]:          8 :     Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY );
      83         [ +  - ]:          8 :     if( xPropSet.is() )
      84                 :            :     {
      85 [ +  - ][ +  - ]:          8 :         Any aAny = xPropSet->getPropertyValue( sIsAutomatic );
      86         [ +  - ]:          8 :         if ( *(sal_Bool*)aAny.getValue() )
      87                 :            :         {
      88 [ +  - ][ +  - ]:          8 :             aAny = xPropSet->getPropertyValue( sAutomaticDistance );
      89                 :          8 :             sal_Int32 nDistance = 0;
      90                 :          8 :             aAny >>= nDistance;
      91                 :          8 :             OUStringBuffer aBuffer;
      92                 :          8 :             GetExport().GetMM100UnitConverter().convertMeasureToXML(
      93         [ +  - ]:          8 :                 aBuffer, nDistance );
      94                 :          8 :             GetExport().AddAttribute( XML_NAMESPACE_FO,
      95                 :            :                                       XML_COLUMN_GAP,
      96   [ +  -  +  - ]:         16 :                                       aBuffer.makeStringAndClear() );
      97                 :          8 :         }
      98                 :            :     }
      99                 :            : 
     100                 :          8 :     SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMNS,
     101         [ +  - ]:          8 :                               sal_True, sal_True );
     102                 :            : 
     103         [ +  - ]:          8 :     if( xPropSet.is() )
     104                 :            :     {
     105 [ +  - ][ +  - ]:          8 :         Any aAny = xPropSet->getPropertyValue( sSeparatorLineIsOn );
     106         [ -  + ]:          8 :         if( *(sal_Bool *)aAny.getValue() )
     107                 :            :         {
     108                 :            :             // style:width
     109 [ #  # ][ #  # ]:          0 :             aAny = xPropSet->getPropertyValue( sSeparatorLineWidth );
     110                 :          0 :             sal_Int32 nWidth = 0;
     111                 :          0 :             aAny >>= nWidth;
     112                 :          0 :             GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
     113         [ #  # ]:          0 :                                                                 nWidth );
     114                 :          0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_WIDTH,
     115   [ #  #  #  # ]:          0 :                                       sValue.makeStringAndClear() );
     116                 :            : 
     117                 :            :             // style:color
     118 [ #  # ][ #  # ]:          0 :             aAny = xPropSet->getPropertyValue( sSeparatorLineColor );
     119                 :          0 :             sal_Int32 nColor = 0;
     120                 :          0 :             aAny >>= nColor;
     121         [ #  # ]:          0 :             ::sax::Converter::convertColor( sValue, nColor );
     122                 :          0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_COLOR,
     123   [ #  #  #  # ]:          0 :                                       sValue.makeStringAndClear() );
     124                 :            : 
     125                 :            :             // style:height
     126 [ #  # ][ #  # ]:          0 :             aAny = xPropSet->getPropertyValue( sSeparatorLineRelativeHeight );
     127                 :          0 :             sal_Int8 nHeight = 0;
     128                 :          0 :             aAny >>= nHeight;
     129         [ #  # ]:          0 :             ::sax::Converter::convertPercent( sValue, nHeight );
     130                 :          0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_HEIGHT,
     131   [ #  #  #  # ]:          0 :                                       sValue.makeStringAndClear() );
     132                 :            : 
     133                 :            :             // style::style
     134 [ #  # ][ #  # ]:          0 :             aAny = xPropSet->getPropertyValue( sSeparatorLineStyle );
     135                 :          0 :             sal_Int8 nStyle = 0;
     136                 :          0 :             aAny >>= nStyle;
     137                 :            : 
     138                 :          0 :             enum XMLTokenEnum eStr = XML_TOKEN_INVALID;
     139   [ #  #  #  #  :          0 :             switch ( nStyle )
                      # ]
     140                 :            :             {
     141                 :          0 :                 case 0:  eStr = XML_NONE; break;
     142                 :          0 :                 case 1:  eStr = XML_SOLID; break;
     143                 :          0 :                 case 2:  eStr = XML_DOTTED; break;
     144                 :          0 :                 case 3:  eStr = XML_DASHED; break;
     145                 :            :                 default:
     146                 :          0 :                          break;
     147                 :            :             }
     148         [ #  # ]:          0 :             if ( eStr != XML_TOKEN_INVALID )
     149         [ #  # ]:          0 :                 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_STYLE, eStr );
     150                 :            : 
     151                 :            :             // style:vertical-align
     152 [ #  # ][ #  # ]:          0 :             aAny = xPropSet->getPropertyValue( sSeparatorLineVerticalAlignment );
     153                 :            :             VerticalAlignment eVertAlign;
     154         [ #  # ]:          0 :             aAny >>= eVertAlign;
     155                 :            : 
     156                 :          0 :             eStr = XML_TOKEN_INVALID;
     157      [ #  #  # ]:          0 :             switch( eVertAlign )
     158                 :            :             {
     159                 :            : //          case VerticalAlignment_TOP: eStr = XML_TOP;
     160                 :          0 :             case VerticalAlignment_MIDDLE: eStr = XML_MIDDLE; break;
     161                 :          0 :             case VerticalAlignment_BOTTOM: eStr = XML_BOTTOM; break;
     162                 :            :             default:
     163                 :          0 :                 break;
     164                 :            :             }
     165                 :            : 
     166         [ #  # ]:          0 :             if( eStr != XML_TOKEN_INVALID)
     167                 :          0 :                 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     168         [ #  # ]:          0 :                                           XML_VERTICAL_ALIGN, eStr );
     169                 :            : 
     170                 :            :             // style:column-sep
     171                 :          0 :             SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
     172                 :            :                                       XML_COLUMN_SEP,
     173 [ #  # ][ #  # ]:          0 :                                       sal_True, sal_True );
     174                 :          8 :         }
     175                 :            :     }
     176                 :            : 
     177         [ +  + ]:         20 :     while( nCount-- )
     178                 :            :     {
     179                 :            :         // style:rel-width
     180         [ +  - ]:         12 :         ::sax::Converter::convertNumber( sValue, pColumns->Width );
     181         [ +  - ]:         12 :         sValue.append( (sal_Unicode)'*' );
     182                 :         12 :         GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
     183   [ +  -  +  - ]:         24 :                                   sValue.makeStringAndClear() );
     184                 :            : 
     185                 :            :         // fo:margin-left
     186                 :         12 :         GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
     187         [ +  - ]:         12 :                                                        pColumns->LeftMargin );
     188                 :         12 :         GetExport().AddAttribute( XML_NAMESPACE_FO, XML_START_INDENT,
     189   [ +  -  +  - ]:         24 :                                        sValue.makeStringAndClear() );
     190                 :            : 
     191                 :            :         // fo:margin-right
     192                 :         12 :         GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
     193         [ +  - ]:         12 :                                                        pColumns->RightMargin );
     194                 :         12 :         GetExport().AddAttribute( XML_NAMESPACE_FO, XML_END_INDENT,
     195   [ +  -  +  - ]:         24 :                                     sValue.makeStringAndClear() );
     196                 :            : 
     197                 :            :         // style:column
     198                 :         12 :         SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMN,
     199         [ +  - ]:         12 :                                   sal_True, sal_True );
     200                 :         12 :         pColumns++;
     201 [ +  - ][ +  - ]:         20 :     }
                 [ +  - ]
     202                 :          8 : }
     203                 :            : 
     204                 :            : 
     205                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10