LCOV - code coverage report
Current view: top level - libreoffice/sw/source/filter/xml - xmlbrsh.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 5 91 5.5 %
Date: 2012-12-27 Functions: 2 15 13.3 %
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 "hintids.hxx"
      21             : #include <com/sun/star/io/XOutputStream.hpp>
      22             : #include <editeng/memberids.hrc>
      23             : 
      24             : #include <xmloff/nmspmap.hxx>
      25             : #include <xmloff/xmlnmspe.hxx>
      26             : #include <xmloff/xmlimp.hxx>
      27             : #include <xmloff/xmltkmap.hxx>
      28             : #include <xmloff/XMLBase64ImportContext.hxx>
      29             : #include <svtools/grfmgr.hxx>
      30             : #include <svx/unomid.hxx>
      31             : #include <editeng/brshitem.hxx>
      32             : #include <xmloff/xmluconv.hxx>
      33             : 
      34             : #include "xmlbrshi.hxx"
      35             : #include "xmlbrshe.hxx"
      36             : #include "xmlexp.hxx"
      37             : #include "xmlimpit.hxx"
      38             : #include "xmlexpit.hxx"
      39             : 
      40             : using ::rtl::OUString;
      41             : using namespace ::com::sun::star;
      42             : using namespace ::com::sun::star::uno;
      43             : using namespace ::xmloff::token;
      44             : 
      45             : enum SvXMLTokenMapAttrs
      46             : {
      47             :     XML_TOK_BGIMG_HREF,
      48             :     XML_TOK_BGIMG_TYPE,
      49             :     XML_TOK_BGIMG_ACTUATE,
      50             :     XML_TOK_BGIMG_SHOW,
      51             :     XML_TOK_BGIMG_POSITION,
      52             :     XML_TOK_BGIMG_REPEAT,
      53             :     XML_TOK_BGIMG_FILTER,
      54             :     XML_TOK_NGIMG_END=XML_TOK_UNKNOWN
      55             : };
      56             : 
      57             : static SvXMLTokenMapEntry aBGImgAttributesAttrTokenMap[] =
      58             : {
      59             :     { XML_NAMESPACE_XLINK, XML_HREF,        XML_TOK_BGIMG_HREF      },
      60             :     { XML_NAMESPACE_XLINK, XML_TYPE,        XML_TOK_BGIMG_TYPE      },
      61             :     { XML_NAMESPACE_XLINK, XML_ACTUATE,     XML_TOK_BGIMG_ACTUATE   },
      62             :     { XML_NAMESPACE_XLINK, XML_SHOW,        XML_TOK_BGIMG_SHOW      },
      63             :     { XML_NAMESPACE_STYLE, XML_POSITION,    XML_TOK_BGIMG_POSITION  },
      64             :     { XML_NAMESPACE_STYLE, XML_REPEAT,      XML_TOK_BGIMG_REPEAT    },
      65             :     { XML_NAMESPACE_STYLE, XML_FILTER_NAME, XML_TOK_BGIMG_FILTER    },
      66             :     XML_TOKEN_MAP_END
      67             : };
      68             : 
      69           0 : TYPEINIT1( SwXMLBrushItemImportContext, SvXMLImportContext );
      70             : 
      71           0 : void SwXMLBrushItemImportContext::ProcessAttrs(
      72             :     const uno::Reference< xml::sax::XAttributeList >& xAttrList,
      73             :         const SvXMLUnitConverter& rUnitConv )
      74             : {
      75           0 :     SvXMLTokenMap aTokenMap( aBGImgAttributesAttrTokenMap );
      76             : 
      77           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      78           0 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      79             :     {
      80           0 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      81           0 :         OUString aLocalName;
      82             :         sal_uInt16 nPrefix =
      83           0 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      84           0 :                                                             &aLocalName );
      85           0 :         const OUString& rValue = xAttrList->getValueByIndex( i );
      86             : 
      87           0 :         switch( aTokenMap.Get( nPrefix, aLocalName ) )
      88             :         {
      89             :         case XML_TOK_BGIMG_HREF:
      90             :             SvXMLImportItemMapper::PutXMLValue(
      91           0 :                 *pItem, GetImport().ResolveGraphicObjectURL( rValue,sal_False),
      92           0 :                 MID_GRAPHIC_LINK, rUnitConv );
      93           0 :             break;
      94             :         case XML_TOK_BGIMG_TYPE:
      95             :         case XML_TOK_BGIMG_ACTUATE:
      96             :         case XML_TOK_BGIMG_SHOW:
      97           0 :             break;
      98             :         case XML_TOK_BGIMG_POSITION:
      99             :             SvXMLImportItemMapper::PutXMLValue(
     100           0 :                 *pItem, rValue, MID_GRAPHIC_POSITION, rUnitConv );
     101           0 :             break;
     102             :         case XML_TOK_BGIMG_REPEAT:
     103             :             SvXMLImportItemMapper::PutXMLValue(
     104           0 :                 *pItem, rValue, MID_GRAPHIC_REPEAT, rUnitConv );
     105           0 :             break;
     106             :         case XML_TOK_BGIMG_FILTER:
     107             :             SvXMLImportItemMapper::PutXMLValue(
     108           0 :                 *pItem, rValue, MID_GRAPHIC_FILTER, rUnitConv );
     109           0 :             break;
     110             :         }
     111           0 :     }
     112             : 
     113           0 : }
     114             : 
     115           0 : SvXMLImportContext *SwXMLBrushItemImportContext::CreateChildContext(
     116             :         sal_uInt16 nPrefix, const OUString& rLocalName,
     117             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     118             : {
     119           0 :     SvXMLImportContext *pContext = 0;
     120           0 :     if( xmloff::token::IsXMLToken( rLocalName,
     121           0 :                                         xmloff::token::XML_BINARY_DATA ) )
     122             :     {
     123           0 :         if( !xBase64Stream.is() && !pItem->GetGraphicLink() )
     124             :         {
     125           0 :             const GraphicObject *pGrObj = pItem->GetGraphicObject();
     126           0 :             if( !pGrObj || GRAPHIC_NONE == pGrObj->GetType() )
     127             :             {
     128             :                 xBase64Stream =
     129           0 :                     GetImport().GetStreamForGraphicObjectURLFromBase64();
     130           0 :                 if( xBase64Stream.is() )
     131           0 :                     pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
     132             :                                                         rLocalName, xAttrList,
     133           0 :                                                         xBase64Stream );
     134             :             }
     135             :         }
     136             :     }
     137           0 :     if( !pContext )
     138             :     {
     139           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     140             :     }
     141             : 
     142           0 :     return pContext;
     143             : }
     144             : 
     145           0 : void SwXMLBrushItemImportContext::EndElement()
     146             : {
     147           0 :     if( xBase64Stream.is() )
     148             :     {
     149           0 :         OUString sURL( GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream ) );
     150           0 :         xBase64Stream = 0;
     151           0 :         SvXMLImportItemMapper::PutXMLValue( *pItem, sURL, MID_GRAPHIC_LINK, GetImport().GetMM100UnitConverter() );
     152             :     }
     153             : 
     154           0 :     if( !(pItem->GetGraphicLink() || pItem->GetGraphic() ) )
     155           0 :         pItem->SetGraphicPos( GPOS_NONE );
     156           0 :     else if( GPOS_NONE == pItem->GetGraphicPos() )
     157           0 :         pItem->SetGraphicPos( GPOS_TILED );
     158           0 : }
     159             : 
     160           0 : SwXMLBrushItemImportContext::SwXMLBrushItemImportContext(
     161             :         SvXMLImport& rImport, sal_uInt16 nPrfx,
     162             :         const OUString& rLName,
     163             :         const uno::Reference< xml::sax::XAttributeList >& xAttrList,
     164             :         const SvXMLUnitConverter& rUnitConv,
     165             :         const SvxBrushItem& rItem ) :
     166             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     167           0 :     pItem( new SvxBrushItem( rItem ) )
     168             : {
     169             :     // delete any grephic that is existing
     170           0 :     pItem->SetGraphicPos( GPOS_NONE );
     171             : 
     172           0 :     ProcessAttrs( xAttrList, rUnitConv );
     173           0 : }
     174             : 
     175           0 : SwXMLBrushItemImportContext::SwXMLBrushItemImportContext(
     176             :         SvXMLImport& rImport, sal_uInt16 nPrfx,
     177             :         const OUString& rLName,
     178             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList,
     179             :         const SvXMLUnitConverter& rUnitConv,
     180             :         sal_uInt16 nWhich ) :
     181             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     182           0 :     pItem( new SvxBrushItem( nWhich ) )
     183             : {
     184           0 :     ProcessAttrs( xAttrList, rUnitConv );
     185           0 : }
     186             : 
     187           0 : SwXMLBrushItemImportContext::~SwXMLBrushItemImportContext()
     188             : {
     189           0 :     delete pItem;
     190           0 : }
     191             : 
     192           8 : SwXMLBrushItemExport::SwXMLBrushItemExport( SwXMLExport& rExp ) :
     193           8 :     rExport( rExp )
     194             : {
     195           8 : }
     196             : 
     197           8 : SwXMLBrushItemExport::~SwXMLBrushItemExport()
     198             : {
     199           8 : }
     200             : 
     201             : 
     202           0 : void SwXMLBrushItemExport::exportXML( const SvxBrushItem& rItem )
     203             : {
     204           0 :     GetExport().CheckAttrList();
     205             : 
     206           0 :     OUString sValue, sURL;
     207           0 :     const SvXMLUnitConverter& rUnitConv = GetExport().GetTwipUnitConverter();
     208           0 :     if( SvXMLExportItemMapper::QueryXMLValue(
     209           0 :             rItem, sURL, MID_GRAPHIC_LINK, rUnitConv ) )
     210             :     {
     211           0 :         sValue = GetExport().AddEmbeddedGraphicObject( sURL );
     212           0 :         if( !sValue.isEmpty() )
     213             :         {
     214           0 :             GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sValue );
     215           0 :             GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
     216           0 :             GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
     217             :         }
     218             : 
     219           0 :         if( SvXMLExportItemMapper::QueryXMLValue(
     220           0 :                 rItem, sValue, MID_GRAPHIC_POSITION, rUnitConv ) )
     221           0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_POSITION, sValue );
     222             : 
     223           0 :         if( SvXMLExportItemMapper::QueryXMLValue(
     224           0 :                 rItem, sValue, MID_GRAPHIC_REPEAT, rUnitConv ) )
     225           0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REPEAT, sValue );
     226             : 
     227           0 :         if( SvXMLExportItemMapper::QueryXMLValue(
     228           0 :                 rItem, sValue, MID_GRAPHIC_FILTER, rUnitConv ) )
     229           0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FILTER_NAME, sValue );
     230             :     }
     231             : 
     232             :     {
     233           0 :         SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_BACKGROUND_IMAGE,
     234           0 :                                   sal_True, sal_True );
     235           0 :         if( !sURL.isEmpty() )
     236             :         {
     237             :             // optional office:binary-data
     238           0 :             GetExport().AddEmbeddedGraphicObjectAsBase64( sURL );
     239           0 :         }
     240           0 :     }
     241           0 : }
     242             : 
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10