LCOV - code coverage report
Current view: top level - xmloff/source/style - XMLBackgroundImageExport.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 67 0.0 %
Date: 2014-04-14 Functions: 0 3 0.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           0 : XMLBackgroundImageExport::XMLBackgroundImageExport( SvXMLExport& rExp ) :
      38           0 :     rExport( rExp )
      39             : {
      40           0 : }
      41             : 
      42           0 : XMLBackgroundImageExport::~XMLBackgroundImageExport()
      43             : {
      44           0 : }
      45             : 
      46           0 : 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           0 :     if( !(pPos && ((*pPos) >>= ePos)) )
      55           0 :         ePos = GraphicLocation_AREA;
      56             : 
      57           0 :     OUString sURL;
      58           0 :     rURL >>= sURL;
      59           0 :     if( !sURL.isEmpty() && GraphicLocation_NONE != ePos )
      60             :     {
      61           0 :         OUString sTempURL( GetExport().AddEmbeddedGraphicObject( sURL ) );
      62           0 :         if( !sTempURL.isEmpty() )
      63             :         {
      64           0 :             GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sTempURL );
      65           0 :             GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE,
      66           0 :                                       XML_SIMPLE );
      67           0 :             GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE,
      68           0 :                                       XML_ONLOAD );
      69             :         }
      70             : 
      71           0 :         OUStringBuffer aOut;
      72           0 :         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           0 :             aOut.append( GetXMLToken(XML_CENTER) );
      83           0 :             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           0 :             break;
      91             :         }
      92             : 
      93           0 :         if( !aOut.isEmpty() )
      94             :         {
      95           0 :             aOut.append( ' ' );
      96             : 
      97           0 :             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           0 :                 aOut.append( GetXMLToken(XML_CENTER) );
     108           0 :                 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           0 :         if( !aOut.isEmpty() )
     119           0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     120           0 :                                   XML_POSITION, aOut.makeStringAndClear() );
     121             : 
     122           0 :         if( GraphicLocation_AREA == ePos )
     123             :         {
     124           0 :             aOut.append( GetXMLToken(XML_BACKGROUND_STRETCH) );
     125             :         }
     126           0 :         else if( GraphicLocation_NONE != ePos && GraphicLocation_TILED != ePos  )
     127             :         {
     128           0 :             aOut.append( GetXMLToken(XML_BACKGROUND_NO_REPEAT) );
     129             :         }
     130           0 :         if( !aOut.isEmpty() )
     131           0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REPEAT,
     132           0 :                           aOut.makeStringAndClear() );
     133             : 
     134           0 :         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           0 :         if( pTransparency )
     144             :         {
     145           0 :             sal_Int8 nTransparency = sal_Int8();
     146           0 :             if( (*pTransparency) >>= nTransparency )
     147             :             {
     148           0 :                 OUStringBuffer aTransOut;
     149           0 :                 ::sax::Converter::convertPercent(aTransOut, 100-nTransparency);
     150           0 :                 GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_OPACITY,
     151           0 :                                           aTransOut.makeStringAndClear() );
     152             :             }
     153           0 :         }
     154             :     }
     155             : 
     156             :     {
     157           0 :         SvXMLElementExport aElem( GetExport(), nPrefix, rLocalName, true, true );
     158           0 :         if( !sURL.isEmpty() && GraphicLocation_NONE != ePos )
     159             :         {
     160             :             // optional office:binary-data
     161           0 :             GetExport().AddEmbeddedGraphicObjectAsBase64( sURL );
     162           0 :         }
     163           0 :     }
     164           0 : }
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10