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

Generated by: LCOV version 1.11