LCOV - code coverage report
Current view: top level - xmloff/source/style - ImageStyle.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 60 60 100.0 %
Date: 2014-04-11 Functions: 6 6 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             : #include <xmloff/ImageStyle.hxx>
      21             : #include <com/sun/star/awt/XBitmap.hpp>
      22             : #include <xmloff/attrlist.hxx>
      23             : #include <xmloff/nmspmap.hxx>
      24             : #include <xmloff/xmluconv.hxx>
      25             : #include"xmloff/xmlnmspe.hxx"
      26             : #include <xmloff/xmltoken.hxx>
      27             : #include <xmloff/xmlexp.hxx>
      28             : #include <xmloff/xmlimp.hxx>
      29             : #include <rtl/ustrbuf.hxx>
      30             : #include <rtl/ustring.hxx>
      31             : #include <tools/debug.hxx>
      32             : #include <xmloff/xmltkmap.hxx>
      33             : 
      34             : using namespace ::com::sun::star;
      35             : 
      36             : using namespace ::xmloff::token;
      37             : 
      38             : enum SvXMLTokenMapAttrs
      39             : {
      40             :     XML_TOK_IMAGE_NAME,
      41             :     XML_TOK_IMAGE_DISPLAY_NAME,
      42             :     XML_TOK_IMAGE_URL,
      43             :     XML_TOK_IMAGE_TYPE,
      44             :     XML_TOK_IMAGE_SHOW,
      45             :     XML_TOK_IMAGE_ACTUATE,
      46             :     XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
      47             : };
      48             : 
      49             : 
      50         287 : XMLImageStyle::XMLImageStyle()
      51             : {
      52         287 : }
      53             : 
      54         287 : XMLImageStyle::~XMLImageStyle()
      55             : {
      56         287 : }
      57             : 
      58           7 : void XMLImageStyle::exportXML( const OUString& rStrName, const ::com::sun::star::uno::Any& rValue, SvXMLExport& rExport )
      59             : {
      60           7 :     ImpExportXML( rStrName, rValue, rExport );
      61           7 : }
      62             : 
      63           7 : void XMLImageStyle::ImpExportXML( const OUString& rStrName, const uno::Any& rValue, SvXMLExport& rExport )
      64             : {
      65           7 :     OUString sImageURL;
      66             : 
      67           7 :     if( !rStrName.isEmpty() )
      68             :     {
      69           7 :         if( rValue >>= sImageURL )
      70             :         {
      71             :             // Name
      72           7 :             bool bEncoded = false;
      73             :             rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
      74             :                                   rExport.EncodeStyleName( rStrName,
      75           7 :                                                            &bEncoded ) );
      76           7 :             if( bEncoded )
      77             :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
      78           7 :                                       rStrName );
      79             : 
      80             :             // uri
      81           7 :             const OUString aStr( rExport.AddEmbeddedGraphicObject( sImageURL ) );
      82           7 :             if( !aStr.isEmpty() )
      83             :             {
      84           7 :                 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, aStr );
      85           7 :                 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
      86           7 :                 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
      87           7 :                 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
      88             :             }
      89             : 
      90             :             // Do Write
      91          14 :             SvXMLElementExport aElem( rExport, XML_NAMESPACE_DRAW, XML_FILL_IMAGE, true, true );
      92             : 
      93           7 :             if( !sImageURL.isEmpty() )
      94             :             {
      95             :                 // optional office:binary-data
      96           7 :                 rExport.AddEmbeddedGraphicObjectAsBase64( sImageURL );
      97           7 :             }
      98             :         }
      99           7 :     }
     100           7 : }
     101             : 
     102          55 : bool XMLImageStyle::importXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList, uno::Any& rValue, OUString& rStrName, SvXMLImport& rImport )
     103             : {
     104          55 :     return ImpImportXML( xAttrList, rValue, rStrName, rImport );
     105             : }
     106             : 
     107          55 : bool XMLImageStyle::ImpImportXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList,
     108             :                                       uno::Any& rValue, OUString& rStrName,
     109             :                                       SvXMLImport& rImport )
     110             : {
     111             :     static const SvXMLTokenMapEntry aHatchAttrTokenMap[] =
     112             :     {
     113             :         { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_IMAGE_NAME },
     114             :         { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_IMAGE_DISPLAY_NAME },
     115             :         { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_IMAGE_URL },
     116             :         { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_IMAGE_TYPE },
     117             :         { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_IMAGE_SHOW },
     118             :         { XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_IMAGE_ACTUATE },
     119             :         XML_TOKEN_MAP_END
     120             :     };
     121             : 
     122          55 :     bool bHasHRef = false;
     123          55 :     bool bHasName = false;
     124          55 :     OUString aStrURL;
     125         110 :     OUString aDisplayName;
     126             : 
     127         110 :     SvXMLTokenMap aTokenMap( aHatchAttrTokenMap );
     128             : 
     129          55 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     130         330 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     131             :     {
     132         275 :         const OUString& rFullAttrName = xAttrList->getNameByIndex( i );
     133         550 :         OUString aStrAttrName;
     134         275 :         sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rFullAttrName, &aStrAttrName );
     135         550 :         const OUString& rStrValue = xAttrList->getValueByIndex( i );
     136             : 
     137         275 :         switch( aTokenMap.Get( nPrefix, aStrAttrName ) )
     138             :         {
     139             :             case XML_TOK_IMAGE_NAME:
     140             :                 {
     141          55 :                     rStrName = rStrValue;
     142          55 :                     bHasName = true;
     143             :                 }
     144          55 :                 break;
     145             :             case XML_TOK_IMAGE_DISPLAY_NAME:
     146             :                 {
     147           4 :                     aDisplayName = rStrValue;
     148             :                 }
     149           4 :                 break;
     150             :             case XML_TOK_IMAGE_URL:
     151             :                 {
     152          54 :                     aStrURL = rImport.ResolveGraphicObjectURL( rStrValue, false );
     153          54 :                     bHasHRef = true;
     154             :                 }
     155          54 :                 break;
     156             :             case XML_TOK_IMAGE_TYPE:
     157             :                 // ignore
     158          54 :                 break;
     159             :             case XML_TOK_IMAGE_SHOW:
     160             :                 // ignore
     161          54 :                 break;
     162             :             case XML_TOK_IMAGE_ACTUATE:
     163             :                 // ignore
     164          54 :                 break;
     165             :             default:
     166             :                 DBG_WARNING( "Unknown token at import fill bitmap style" )
     167             :                 ;
     168             :         }
     169         275 :     }
     170             : 
     171          55 :     rValue <<= aStrURL;
     172             : 
     173          55 :     if( !aDisplayName.isEmpty() )
     174             :     {
     175             :         rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_FILL_IMAGE_ID,
     176           4 :                                      rStrName, aDisplayName );
     177           4 :         rStrName = aDisplayName;
     178             :     }
     179             : 
     180          55 :     bool bRet = bHasName && bHasHRef;
     181             : 
     182         110 :     return bRet;
     183             : }
     184             : 
     185             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10