LCOV - code coverage report
Current view: top level - xmloff/source/style - ImageStyle.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 34 60 56.7 %
Date: 2012-08-25 Functions: 4 6 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 23 75 30.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "xmloff/ImageStyle.hxx"
      30                 :            : #include <com/sun/star/awt/XBitmap.hpp>
      31                 :            : #include <xmloff/attrlist.hxx>
      32                 :            : #include <xmloff/nmspmap.hxx>
      33                 :            : #include <xmloff/xmluconv.hxx>
      34                 :            : #include"xmloff/xmlnmspe.hxx"
      35                 :            : #include <xmloff/xmltoken.hxx>
      36                 :            : #include <xmloff/xmlexp.hxx>
      37                 :            : #include <xmloff/xmlimp.hxx>
      38                 :            : #include <rtl/ustrbuf.hxx>
      39                 :            : #include <rtl/ustring.hxx>
      40                 :            : #include <tools/debug.hxx>
      41                 :            : #include <xmloff/xmltkmap.hxx>
      42                 :            : 
      43                 :            : using namespace ::com::sun::star;
      44                 :            : using ::rtl::OUString;
      45                 :            : using ::rtl::OUStringBuffer;
      46                 :            : 
      47                 :            : using namespace ::xmloff::token;
      48                 :            : 
      49                 :            : enum SvXMLTokenMapAttrs
      50                 :            : {
      51                 :            :     XML_TOK_IMAGE_NAME,
      52                 :            :     XML_TOK_IMAGE_DISPLAY_NAME,
      53                 :            :     XML_TOK_IMAGE_URL,
      54                 :            :     XML_TOK_IMAGE_TYPE,
      55                 :            :     XML_TOK_IMAGE_SHOW,
      56                 :            :     XML_TOK_IMAGE_ACTUATE,
      57                 :            :     XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
      58                 :            : };
      59                 :            : 
      60                 :            : 
      61                 :        226 : XMLImageStyle::XMLImageStyle()
      62                 :            : {
      63                 :        226 : }
      64                 :            : 
      65                 :        226 : XMLImageStyle::~XMLImageStyle()
      66                 :            : {
      67                 :        226 : }
      68                 :            : 
      69                 :          0 : sal_Bool XMLImageStyle::exportXML( const OUString& rStrName, const ::com::sun::star::uno::Any& rValue, SvXMLExport& rExport )
      70                 :            : {
      71                 :          0 :     return ImpExportXML( rStrName, rValue, rExport );
      72                 :            : }
      73                 :            : 
      74                 :          0 : sal_Bool XMLImageStyle::ImpExportXML( const OUString& rStrName, const uno::Any& rValue, SvXMLExport& rExport )
      75                 :            : {
      76                 :          0 :     sal_Bool bRet = sal_False;
      77                 :            : 
      78                 :          0 :     OUString sImageURL;
      79                 :            : 
      80         [ #  # ]:          0 :     if( !rStrName.isEmpty() )
      81                 :            :     {
      82         [ #  # ]:          0 :         if( rValue >>= sImageURL )
      83                 :            :         {
      84                 :            :             // Name
      85                 :          0 :             sal_Bool bEncoded = sal_False;
      86                 :            :             rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
      87                 :            :                                   rExport.EncodeStyleName( rStrName,
      88 [ #  # ][ #  # ]:          0 :                                                            &bEncoded ) );
      89         [ #  # ]:          0 :             if( bEncoded )
      90                 :            :                 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
      91         [ #  # ]:          0 :                                       rStrName );
      92                 :            : 
      93                 :            :             // uri
      94         [ #  # ]:          0 :             const OUString aStr( rExport.AddEmbeddedGraphicObject( sImageURL ) );
      95         [ #  # ]:          0 :             if( !aStr.isEmpty() )
      96                 :            :             {
      97         [ #  # ]:          0 :                 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, aStr );
      98         [ #  # ]:          0 :                 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
      99         [ #  # ]:          0 :                 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
     100         [ #  # ]:          0 :                 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
     101                 :            :             }
     102                 :            : 
     103                 :            :             // Do Write
     104         [ #  # ]:          0 :             SvXMLElementExport aElem( rExport, XML_NAMESPACE_DRAW, XML_FILL_IMAGE, sal_True, sal_True );
     105                 :            : 
     106         [ #  # ]:          0 :             if( !sImageURL.isEmpty() )
     107                 :            :             {
     108                 :            :                 // optional office:binary-data
     109         [ #  # ]:          0 :                 rExport.AddEmbeddedGraphicObjectAsBase64( sImageURL );
     110         [ #  # ]:          0 :             }
     111                 :            :         }
     112                 :            :     }
     113                 :            : 
     114                 :          0 :     return bRet;
     115                 :            : }
     116                 :            : 
     117                 :        180 : sal_Bool XMLImageStyle::importXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList, uno::Any& rValue, OUString& rStrName, SvXMLImport& rImport )
     118                 :            : {
     119                 :        180 :     return ImpImportXML( xAttrList, rValue, rStrName, rImport );
     120                 :            : }
     121                 :            : 
     122                 :        180 : sal_Bool XMLImageStyle::ImpImportXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList,
     123                 :            :                                       uno::Any& rValue, OUString& rStrName,
     124                 :            :                                       SvXMLImport& rImport )
     125                 :            : {
     126                 :        180 :     sal_Bool bRet     = sal_False;
     127                 :        180 :     sal_Bool bHasHRef = sal_False;
     128                 :        180 :     sal_Bool bHasName = sal_False;
     129                 :        180 :     OUString aStrURL;
     130                 :        180 :     OUString aDisplayName;
     131                 :            : 
     132                 :            :     {
     133                 :            :         static SvXMLTokenMapEntry aHatchAttrTokenMap[] =
     134                 :            : {
     135                 :            :     { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_IMAGE_NAME },
     136                 :            :     { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_IMAGE_DISPLAY_NAME },
     137                 :            :     { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_IMAGE_URL },
     138                 :            :     { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_IMAGE_TYPE },
     139                 :            :     { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_IMAGE_SHOW },
     140                 :            :     { XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_IMAGE_ACTUATE },
     141                 :            :     XML_TOKEN_MAP_END
     142                 :            : };
     143                 :            : 
     144         [ +  - ]:        180 :     SvXMLTokenMap aTokenMap( aHatchAttrTokenMap );
     145                 :            : 
     146 [ +  - ][ +  - ]:        180 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
                 [ +  - ]
     147         [ +  + ]:       1080 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     148                 :            :     {
     149 [ +  - ][ +  - ]:        900 :         const OUString& rFullAttrName = xAttrList->getNameByIndex( i );
     150                 :        900 :         OUString aStrAttrName;
     151         [ +  - ]:        900 :         sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rFullAttrName, &aStrAttrName );
     152 [ +  - ][ +  - ]:        900 :         const OUString& rStrValue = xAttrList->getValueByIndex( i );
     153                 :            : 
     154 [ +  - ][ +  -  :        900 :         switch( aTokenMap.Get( nPrefix, aStrAttrName ) )
             +  +  +  +  
                      - ]
     155                 :            :         {
     156                 :            :             case XML_TOK_IMAGE_NAME:
     157                 :            :                 {
     158                 :        180 :                     rStrName = rStrValue;
     159                 :        180 :                     bHasName = sal_True;
     160                 :            :                 }
     161                 :        180 :                 break;
     162                 :            :             case XML_TOK_IMAGE_DISPLAY_NAME:
     163                 :            :                 {
     164                 :          0 :                     aDisplayName = rStrValue;
     165                 :            :                 }
     166                 :          0 :                 break;
     167                 :            :             case XML_TOK_IMAGE_URL:
     168                 :            :                 {
     169         [ +  - ]:        180 :                     aStrURL = rImport.ResolveGraphicObjectURL( rStrValue, sal_False );
     170                 :        180 :                     bHasHRef = sal_True;
     171                 :            :                 }
     172                 :        180 :                 break;
     173                 :            :             case XML_TOK_IMAGE_TYPE:
     174                 :            :                 // ignore
     175                 :        180 :                 break;
     176                 :            :             case XML_TOK_IMAGE_SHOW:
     177                 :            :                 // ignore
     178                 :        180 :                 break;
     179                 :            :             case XML_TOK_IMAGE_ACTUATE:
     180                 :            :                 // ignore
     181                 :        180 :                 break;
     182                 :            :             default:
     183                 :            :                 DBG_WARNING( "Unknown token at import fill bitmap style" )
     184                 :            :                 ;
     185                 :            :         }
     186                 :        900 :     }
     187                 :            : 
     188         [ +  - ]:        180 :     rValue <<= aStrURL;
     189                 :            : 
     190         [ -  + ]:        180 :     if( !aDisplayName.isEmpty() )
     191                 :            :     {
     192                 :            :         rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_FILL_IMAGE_ID,
     193         [ #  # ]:          0 :                                      rStrName, aDisplayName );
     194                 :          0 :         rStrName = aDisplayName;
     195                 :            :     }
     196                 :            : 
     197 [ +  - ][ +  - ]:        180 :     bRet = bHasName && bHasHRef;
                 [ +  - ]
     198                 :            : 
     199                 :            :     }
     200                 :            : 
     201                 :        180 :     return bRet;
     202                 :            : }
     203                 :            : 
     204                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10