LCOV - code coverage report
Current view: top level - svx/source/core - graphichelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 76 0.0 %
Date: 2012-08-25 Functions: 0 2 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 279 0.0 %

           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 <tools/string.hxx>
      30                 :            : #include <svx/graphichelper.hxx>
      31                 :            : #include <unotools/pathoptions.hxx>
      32                 :            : #include <svtools/filter.hxx>
      33                 :            : #include <sfx2/docfile.hxx>
      34                 :            : #include <svx/xoutbmp.hxx>
      35                 :            : #include <sfx2/filedlghelper.hxx>
      36                 :            : #include <svx/dialmgr.hxx>
      37                 :            : #include <svx/dialogs.hrc>
      38                 :            : 
      39                 :            : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      40                 :            : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
      41                 :            : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      42                 :            : 
      43                 :            : using namespace ::com::sun::star::uno;
      44                 :            : using namespace ::com::sun::star::ui::dialogs;
      45                 :            : using namespace ::sfx2;
      46                 :            : 
      47                 :          0 : void GraphicHelper::GetPreferedExtension( String &rExtension, const Graphic &rGraphic )
      48                 :            : {
      49                 :            :     // propose the "best" filter using the native-info, if applicable
      50                 :          0 :     const sal_Char* pExtension = "png";
      51 [ #  # ][ #  #  :          0 :     switch( const_cast<Graphic&>( rGraphic ).GetLink().GetType() )
             #  #  #  #  
                      # ]
      52                 :            :     {
      53                 :            :         case GFX_LINK_TYPE_NATIVE_GIF:
      54                 :          0 :             pExtension = "gif";
      55                 :          0 :             break;
      56                 :            :         case GFX_LINK_TYPE_NATIVE_TIF:
      57                 :          0 :             pExtension = "tif";
      58                 :          0 :             break;
      59                 :            :         case GFX_LINK_TYPE_NATIVE_WMF:
      60                 :          0 :             pExtension = "wmf";
      61                 :          0 :             break;
      62                 :            :         case GFX_LINK_TYPE_NATIVE_MET:
      63                 :          0 :             pExtension = "met";
      64                 :          0 :             break;
      65                 :            :         case GFX_LINK_TYPE_NATIVE_PCT:
      66                 :          0 :             pExtension = "pct";
      67                 :          0 :             break;
      68                 :            :         case GFX_LINK_TYPE_NATIVE_JPG:
      69                 :          0 :             pExtension = "jpg";
      70                 :          0 :             break;
      71                 :            :         default:
      72                 :          0 :             break;
      73                 :            :     }
      74                 :          0 :     rExtension.AssignAscii( pExtension );
      75                 :          0 : }
      76                 :            : 
      77                 :          0 : String GraphicHelper::ExportGraphic( const Graphic &rGraphic, const String &rGrfName )
      78                 :            : {
      79         [ #  # ]:          0 :     SvtPathOptions aPathOpt;
      80 [ #  # ][ #  # ]:          0 :     String sGrfPath( aPathOpt.GetGraphicPath() );
      81                 :            : 
      82         [ #  # ]:          0 :     FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION, 0 );
      83         [ #  # ]:          0 :     Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
      84                 :            : 
      85         [ #  # ]:          0 :     INetURLObject aPath;
      86 [ #  # ][ #  # ]:          0 :     aPath.SetSmartURL( sGrfPath );
      87                 :            : 
      88                 :            :     // fish out the graphic's name
      89         [ #  # ]:          0 :     String aName = rGrfName;
      90                 :            : 
      91 [ #  # ][ #  # ]:          0 :     aDlgHelper.SetTitle( SVX_RESSTR(RID_SVXSTR_EXPORT_GRAPHIC_TITLE));
         [ #  # ][ #  # ]
                 [ #  # ]
      92 [ #  # ][ #  # ]:          0 :     aDlgHelper.SetDisplayDirectory( aPath.GetMainURL(INetURLObject::DECODE_TO_IURI) );
         [ #  # ][ #  # ]
      93         [ #  # ]:          0 :     INetURLObject aURL;
      94 [ #  # ][ #  # ]:          0 :     aURL.SetSmartURL( aName );
      95 [ #  # ][ #  # ]:          0 :     aDlgHelper.SetFileName( aURL.GetName() );
         [ #  # ][ #  # ]
      96                 :            : 
      97         [ #  # ]:          0 :     GraphicFilter& rGF = GraphicFilter::GetGraphicFilter();
      98         [ #  # ]:          0 :     const sal_uInt16 nCount = rGF.GetExportFormatCount();
      99                 :            : 
     100 [ #  # ][ #  # ]:          0 :     String aExt( aURL.GetExtension() );
     101         [ #  # ]:          0 :     if( !aExt.Len() )
     102         [ #  # ]:          0 :         GetPreferedExtension( aExt, rGraphic );
     103                 :            : 
     104         [ #  # ]:          0 :     aExt.ToLowerAscii();
     105                 :          0 :     sal_uInt16 nDfltFilter = USHRT_MAX;
     106                 :            : 
     107         [ #  # ]:          0 :     Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
     108                 :            : 
     109         [ #  # ]:          0 :     for ( sal_uInt16 i = 0; i < nCount; i++ )
     110                 :            :     {
     111 [ #  # ][ #  # ]:          0 :         xFltMgr->appendFilter( rGF.GetExportFormatName( i ), rGF.GetExportWildcard( i ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     112 [ #  # ][ #  # ]:          0 :         if ( COMPARE_EQUAL == aExt.CompareIgnoreCaseToAscii(rGF.GetExportFormatShortName( i ).ToLowerAscii() ))
         [ #  # ][ #  # ]
                 [ #  # ]
     113                 :          0 :             nDfltFilter = i;
     114                 :            :     }
     115         [ #  # ]:          0 :     if ( USHRT_MAX == nDfltFilter )
     116                 :            :     {
     117                 :            :         // "wrong" extension?
     118         [ #  # ]:          0 :         GetPreferedExtension( aExt, rGraphic );
     119         [ #  # ]:          0 :         for ( sal_uInt16 i = 0; i < nCount; ++i )
     120 [ #  # ][ #  # ]:          0 :             if ( aExt == rGF.GetExportFormatShortName( i ).ToLowerAscii() )
         [ #  # ][ #  # ]
                 [ #  # ]
     121                 :            :             {
     122                 :          0 :                 nDfltFilter =  i;
     123                 :          0 :                 break;
     124                 :            :             }
     125                 :            :     }
     126                 :            : 
     127         [ #  # ]:          0 :     if( USHRT_MAX != nDfltFilter )
     128                 :            :     {
     129 [ #  # ][ #  # ]:          0 :         xFltMgr->setCurrentFilter( rGF.GetExportFormatName( nDfltFilter ) ) ;
         [ #  # ][ #  # ]
                 [ #  # ]
     130                 :            : 
     131 [ #  # ][ #  # ]:          0 :         if( aDlgHelper.Execute() == ERRCODE_NONE )
     132                 :            :         {
     133 [ #  # ][ #  # ]:          0 :             String sPath( xFP->getFiles().getConstArray()[0] );
         [ #  # ][ #  # ]
     134                 :            :             // remember used path - please don't optimize away!
     135 [ #  # ][ #  # ]:          0 :             aPath.SetSmartURL( sPath);
     136 [ #  # ][ #  # ]:          0 :             sGrfPath = aPath.GetPath();
     137                 :            : 
     138 [ #  # ][ #  # ]:          0 :             if( rGrfName.Len() &&
                 [ #  # ]
     139 [ #  # ][ #  # ]:          0 :                  nDfltFilter == rGF.GetExportFormatNumber( xFltMgr->getCurrentFilter()))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     140                 :            :             {
     141                 :            :                 // try to save the original graphic
     142         [ #  # ]:          0 :                 SfxMedium aIn( rGrfName, STREAM_READ | STREAM_NOCREATE );
     143 [ #  # ][ #  # ]:          0 :                 if( aIn.GetInStream() && !aIn.GetInStream()->GetError() )
         [ #  # ][ #  # ]
                 [ #  # ]
     144                 :            :                 {
     145         [ #  # ]:          0 :                     SfxMedium aOut( sPath, STREAM_WRITE | STREAM_SHARE_DENYNONE);
     146 [ #  # ][ #  # ]:          0 :                     if( aOut.GetOutStream() && !aOut.GetOutStream()->GetError())
         [ #  # ][ #  # ]
                 [ #  # ]
     147                 :            :                     {
     148 [ #  # ][ #  # ]:          0 :                         *aOut.GetOutStream() << *aIn.GetInStream();
                 [ #  # ]
     149 [ #  # ][ #  # ]:          0 :                         if ( 0 == aIn.GetError() )
     150                 :            :                         {
     151         [ #  # ]:          0 :                             aOut.Close();
     152         [ #  # ]:          0 :                             aOut.Commit();
     153 [ #  # ][ #  # ]:          0 :                             if ( 0 == aOut.GetError() )
     154         [ #  # ]:          0 :                                 return sPath;
     155                 :            :                         }
     156 [ #  # ][ #  # ]:          0 :                     }
     157 [ #  # ][ #  # ]:          0 :                 }
     158                 :            :             }
     159                 :            : 
     160                 :            :             sal_uInt16 nFilter;
     161 [ #  # ][ #  # ]:          0 :             if ( !xFltMgr->getCurrentFilter().isEmpty() && rGF.GetExportFormatCount() )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     162 [ #  # ][ #  # ]:          0 :                 nFilter = rGF.GetExportFormatNumber( xFltMgr->getCurrentFilter() );
         [ #  # ][ #  # ]
                 [ #  # ]
     163                 :            :             else
     164                 :          0 :                 nFilter = GRFILTER_FORMAT_DONTKNOW;
     165         [ #  # ]:          0 :             String aFilter( rGF.GetExportFormatShortName( nFilter ) );
     166                 :            :             XOutBitmap::WriteGraphic( rGraphic, sPath, aFilter,
     167                 :            :                                         XOUTBMP_DONT_EXPAND_FILENAME|
     168                 :            :                                         XOUTBMP_DONT_ADD_EXTENSION|
     169         [ #  # ]:          0 :                                         XOUTBMP_USE_NATIVE_IF_POSSIBLE );
     170 [ #  # ][ #  # ]:          0 :             return sPath;
                 [ #  # ]
     171                 :            :         }
     172                 :            :     }
     173 [ #  # ][ #  # ]:          0 :     return String();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     174                 :            : }
     175                 :            : 
     176                 :            : 
     177                 :            : 
     178                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10