LCOV - code coverage report
Current view: top level - xmloff/source/style - XMLBackgroundImageExport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 15 67 22.4 %
Date: 2012-08-25 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 114 8.8 %

           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                 :            : 
      30                 :            : #include <com/sun/star/style/GraphicLocation.hpp>
      31                 :            : 
      32                 :            : #include <sax/tools/converter.hxx>
      33                 :            : 
      34                 :            : #include <xmloff/xmlnmspe.hxx>
      35                 :            : #include <xmloff/xmltoken.hxx>
      36                 :            : #include <rtl/ustrbuf.hxx>
      37                 :            : #include <xmloff/xmlexp.hxx>
      38                 :            : #include "XMLBackgroundImageExport.hxx"
      39                 :            : 
      40                 :            : using ::rtl::OUString;
      41                 :            : using ::rtl::OUStringBuffer;
      42                 :            : 
      43                 :            : using namespace ::com::sun::star;
      44                 :            : using namespace ::com::sun::star::uno;
      45                 :            : using namespace ::com::sun::star::style;
      46                 :            : using namespace ::xmloff::token;
      47                 :            : 
      48                 :        778 : XMLBackgroundImageExport::XMLBackgroundImageExport( SvXMLExport& rExp ) :
      49                 :        778 :     rExport( rExp )
      50                 :            : {
      51                 :        778 : }
      52                 :            : 
      53                 :        768 : XMLBackgroundImageExport::~XMLBackgroundImageExport()
      54                 :            : {
      55                 :        768 : }
      56                 :            : 
      57                 :         10 : void XMLBackgroundImageExport::exportXML( const Any& rURL,
      58                 :            :             const Any *pPos,
      59                 :            :             const Any *pFilter,
      60                 :            :             const Any *pTransparency,
      61                 :            :             sal_uInt16 nPrefix,
      62                 :            :             const ::rtl::OUString& rLocalName )
      63                 :            : {
      64                 :            :     GraphicLocation ePos;
      65 [ +  - ][ +  - ]:         10 :     if( !(pPos && ((*pPos) >>= ePos)) )
         [ -  + ][ -  + ]
      66                 :          0 :         ePos = GraphicLocation_AREA;
      67                 :            : 
      68                 :         10 :     OUString sURL;
      69                 :         10 :     rURL >>= sURL;
      70 [ #  # ][ -  + ]:         10 :     if( !sURL.isEmpty() && GraphicLocation_NONE != ePos )
                 [ -  + ]
      71                 :            :     {
      72         [ #  # ]:          0 :         OUString sTempURL( GetExport().AddEmbeddedGraphicObject( sURL ) );
      73         [ #  # ]:          0 :         if( !sTempURL.isEmpty() )
      74                 :            :         {
      75         [ #  # ]:          0 :             GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sTempURL );
      76                 :          0 :             GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE,
      77         [ #  # ]:          0 :                                       XML_SIMPLE );
      78                 :          0 :             GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE,
      79         [ #  # ]:          0 :                                       XML_ONLOAD );
      80                 :            :         }
      81                 :            : 
      82                 :          0 :         OUStringBuffer aOut;
      83   [ #  #  #  # ]:          0 :         switch( ePos )
      84                 :            :         {
      85                 :            :         case GraphicLocation_LEFT_TOP:
      86                 :            :         case GraphicLocation_MIDDLE_TOP:
      87                 :            :         case GraphicLocation_RIGHT_TOP:
      88 [ #  # ][ #  # ]:          0 :             aOut.append( GetXMLToken(XML_TOP) );
      89                 :          0 :             break;
      90                 :            :         case GraphicLocation_LEFT_MIDDLE:
      91                 :            :         case GraphicLocation_MIDDLE_MIDDLE:
      92                 :            :         case GraphicLocation_RIGHT_MIDDLE:
      93 [ #  # ][ #  # ]:          0 :             aOut.append( GetXMLToken(XML_CENTER) );
      94                 :          0 :             break;
      95                 :            :         case GraphicLocation_LEFT_BOTTOM:
      96                 :            :         case GraphicLocation_MIDDLE_BOTTOM:
      97                 :            :         case GraphicLocation_RIGHT_BOTTOM:
      98 [ #  # ][ #  # ]:          0 :             aOut.append( GetXMLToken(XML_BOTTOM) );
      99                 :          0 :             break;
     100                 :            :         default:
     101                 :          0 :             break;
     102                 :            :         }
     103                 :            : 
     104         [ #  # ]:          0 :         if( aOut.getLength() )
     105                 :            :         {
     106         [ #  # ]:          0 :             aOut.append( sal_Unicode( ' ' ) );
     107                 :            : 
     108   [ #  #  #  # ]:          0 :             switch( ePos )
     109                 :            :             {
     110                 :            :             case GraphicLocation_LEFT_TOP:
     111                 :            :             case GraphicLocation_LEFT_BOTTOM:
     112                 :            :             case GraphicLocation_LEFT_MIDDLE:
     113 [ #  # ][ #  # ]:          0 :                 aOut.append( GetXMLToken(XML_LEFT) );
     114                 :          0 :                 break;
     115                 :            :             case GraphicLocation_MIDDLE_TOP:
     116                 :            :             case GraphicLocation_MIDDLE_MIDDLE:
     117                 :            :             case GraphicLocation_MIDDLE_BOTTOM:
     118 [ #  # ][ #  # ]:          0 :                 aOut.append( GetXMLToken(XML_CENTER) );
     119                 :          0 :                 break;
     120                 :            :             case GraphicLocation_RIGHT_MIDDLE:
     121                 :            :             case GraphicLocation_RIGHT_TOP:
     122                 :            :             case GraphicLocation_RIGHT_BOTTOM:
     123 [ #  # ][ #  # ]:          0 :                 aOut.append( GetXMLToken(XML_RIGHT) );
     124                 :          0 :                 break;
     125                 :            :             default:
     126                 :          0 :                 break;
     127                 :            :             }
     128                 :            :         }
     129         [ #  # ]:          0 :         if( aOut.getLength() )
     130                 :          0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     131   [ #  #  #  # ]:          0 :                                   XML_POSITION, aOut.makeStringAndClear() );
     132                 :            : 
     133         [ #  # ]:          0 :         if( GraphicLocation_AREA == ePos )
     134                 :            :         {
     135 [ #  # ][ #  # ]:          0 :             aOut.append( GetXMLToken(XML_BACKGROUND_STRETCH) );
     136                 :            :         }
     137 [ #  # ][ #  # ]:          0 :         else if( GraphicLocation_NONE != ePos && GraphicLocation_TILED != ePos  )
     138                 :            :         {
     139 [ #  # ][ #  # ]:          0 :             aOut.append( GetXMLToken(XML_BACKGROUND_NO_REPEAT) );
     140                 :            :         }
     141         [ #  # ]:          0 :         if( aOut.getLength() )
     142                 :          0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REPEAT,
     143   [ #  #  #  # ]:          0 :                           aOut.makeStringAndClear() );
     144                 :            : 
     145         [ #  # ]:          0 :         if( pFilter )
     146                 :            :         {
     147                 :          0 :             OUString sFilter;
     148                 :          0 :             (*pFilter) >>= sFilter;
     149         [ #  # ]:          0 :             if( !sFilter.isEmpty() )
     150                 :          0 :                 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FILTER_NAME,
     151         [ #  # ]:          0 :                                           sFilter );
     152                 :            :         }
     153                 :            : 
     154         [ #  # ]:          0 :         if( pTransparency )
     155                 :            :         {
     156                 :          0 :             sal_Int8 nTransparency = sal_Int8();
     157         [ #  # ]:          0 :             if( (*pTransparency) >>= nTransparency )
     158                 :            :             {
     159                 :          0 :                 OUStringBuffer aTransOut;
     160         [ #  # ]:          0 :                 ::sax::Converter::convertPercent(aTransOut, 100-nTransparency);
     161                 :          0 :                 GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_OPACITY,
     162   [ #  #  #  # ]:          0 :                                           aTransOut.makeStringAndClear() );
     163                 :            :             }
     164                 :          0 :         }
     165                 :            :     }
     166                 :            : 
     167                 :            :     {
     168         [ +  - ]:         10 :         SvXMLElementExport aElem( GetExport(), nPrefix, rLocalName, sal_True, sal_True );
     169 [ -  + ][ #  # ]:         10 :         if( !sURL.isEmpty() && GraphicLocation_NONE != ePos )
                 [ -  + ]
     170                 :            :         {
     171                 :            :             // optional office:binary-data
     172         [ #  # ]:          0 :             GetExport().AddEmbeddedGraphicObjectAsBase64( sURL );
     173         [ +  - ]:         10 :         }
     174                 :         10 :     }
     175                 :         10 : }
     176                 :            : 
     177                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10