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

Generated by: LCOV version 1.10