LCOV - code coverage report
Current view: top level - sfx2/source/doc - graphhelp.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 13 71 18.3 %
Date: 2014-11-03 Functions: 3 9 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             : 
      21             : #ifdef WNT
      22             : #include <prewin.h>
      23             : #include <postwin.h>
      24             : #endif
      25             : 
      26             : #include <com/sun/star/uno/Exception.hpp>
      27             : #include <com/sun/star/datatransfer/XTransferable.hpp>
      28             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      29             : #include <com/sun/star/graphic/GraphicProvider.hpp>
      30             : #include <com/sun/star/graphic/XGraphicProvider.hpp>
      31             : #include <com/sun/star/graphic/XGraphic.hpp>
      32             : #include <com/sun/star/io/XStream.hpp>
      33             : 
      34             : 
      35             : #include <osl/thread.h>
      36             : #include <vcl/gdimtf.hxx>
      37             : #include <vcl/graph.hxx>
      38             : #include <vcl/cvtgrf.hxx>
      39             : #include <vcl/outdev.hxx>
      40             : #include <vcl/virdev.hxx>
      41             : #include <vcl/bitmapex.hxx>
      42             : #include <vcl/graphicfilter.hxx>
      43             : 
      44             : #include <tools/stream.hxx>
      45             : #include <tools/helpers.hxx>
      46             : #include <unotools/tempfile.hxx>
      47             : #include <unotools/ucbstreamhelper.hxx>
      48             : #include <unotools/streamwrap.hxx>
      49             : #include <comphelper/processfactory.hxx>
      50             : 
      51             : 
      52             : #include <sfx2/sfxresid.hxx>
      53             : #include "graphhelp.hxx"
      54             : #include "doc.hrc"
      55             : 
      56             : using namespace css;
      57             : 
      58           0 : SvMemoryStream* GraphicHelper::getFormatStrFromGDI_Impl( const GDIMetaFile* pGDIMeta, sal_uInt32 nFormat )
      59             : {
      60           0 :     SvMemoryStream* pResult = NULL;
      61           0 :     if ( pGDIMeta )
      62             :     {
      63           0 :         SvMemoryStream* pStream = new SvMemoryStream( 65535, 65535 );
      64           0 :         if ( pStream )
      65             :         {
      66           0 :             Graphic aGraph( *pGDIMeta );
      67           0 :             if ( GraphicConverter::Export( *pStream, aGraph, nFormat ) == 0 )
      68           0 :                 pResult = pStream;
      69             :             else
      70           0 :                 delete pStream;
      71             :         }
      72             :     }
      73             : 
      74           0 :     return pResult;
      75             : }
      76             : 
      77             : 
      78             : // static
      79           0 : void* GraphicHelper::getEnhMetaFileFromGDI_Impl( const GDIMetaFile* pGDIMeta )
      80             : {
      81             :     (void)pGDIMeta;  // unused
      82           0 :     void* pResult = NULL;
      83             : 
      84             : #ifdef WNT
      85             :     if ( pGDIMeta )
      86             :     {
      87             :         OUString const aStr(".emf");
      88             :         ::utl::TempFile aTempFile( OUString(), true, &aStr );
      89             : 
      90             :         OUString aMetaFile = aTempFile.GetFileName();
      91             :         OUString aMetaURL = aTempFile.GetURL();
      92             :         OString aWinFile = OUStringToOString( aMetaFile, osl_getThreadTextEncoding() );
      93             : 
      94             :         SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aMetaURL, STREAM_STD_READWRITE );
      95             :         if ( pStream )
      96             :         {
      97             :             Graphic aGraph( *pGDIMeta );
      98             :             sal_Bool bFailed = (sal_Bool)GraphicConverter::Export( *pStream, aGraph, CVT_EMF );
      99             :             pStream->Flush();
     100             :             delete pStream;
     101             : 
     102             :             if ( !bFailed )
     103             :                 pResult = GetEnhMetaFileA( aWinFile.getStr() );
     104             :         }
     105             :     }
     106             : #endif
     107             : 
     108           0 :     return pResult;
     109             : }
     110             : 
     111             : 
     112             : // static
     113           0 : void* GraphicHelper::getWinMetaFileFromGDI_Impl( const GDIMetaFile* pGDIMeta, const Size& aMetaSize )
     114             : {
     115             :     (void)pGDIMeta;  // unused
     116             :     (void)aMetaSize; // unused
     117           0 :     void* pResult = NULL;
     118             : 
     119             : #ifdef WNT
     120             :     if ( pGDIMeta )
     121             :     {
     122             :         SvMemoryStream* pStream = new SvMemoryStream( 65535, 65535 );
     123             :         if ( pStream )
     124             :         {
     125             :             Graphic aGraph( *pGDIMeta );
     126             :             sal_Bool bFailed = (sal_Bool)GraphicConverter::Export( *pStream, aGraph, CVT_WMF );
     127             :             pStream->Flush();
     128             :             if ( !bFailed )
     129             :             {
     130             :                 sal_Int32 nLength = pStream->Seek( STREAM_SEEK_TO_END );
     131             :                 if ( nLength > 22 )
     132             :                 {
     133             :                     HMETAFILE hMeta = SetMetaFileBitsEx( nLength - 22,
     134             :                                     ( reinterpret_cast< const unsigned char*>( pStream->GetData() ) ) + 22 );
     135             : 
     136             :                     if ( hMeta )
     137             :                     {
     138             :                         HGLOBAL hMemory = GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, sizeof( METAFILEPICT ) );
     139             : 
     140             :                         if ( hMemory )
     141             :                         {
     142             :                                METAFILEPICT* pMF = (METAFILEPICT*)GlobalLock( hMemory );
     143             : 
     144             :                                pMF->hMF = hMeta;
     145             :                                pMF->mm = MM_ANISOTROPIC;
     146             : 
     147             :                             MapMode aMetaMode = pGDIMeta->GetPrefMapMode();
     148             :                             MapMode aWinMode( MAP_100TH_MM );
     149             : 
     150             :                             if ( aWinMode == pGDIMeta->GetPrefMapMode() )
     151             :                             {
     152             :                                 pMF->xExt = aMetaSize.Width();
     153             :                                 pMF->yExt = aMetaSize.Height();
     154             :                             }
     155             :                             else
     156             :                             {
     157             :                                 Size aWinSize = OutputDevice::LogicToLogic( Size( aMetaSize.Width(), aMetaSize.Height() ),
     158             :                                                                             pGDIMeta->GetPrefMapMode(),
     159             :                                                                             aWinMode );
     160             :                                 pMF->xExt = aWinSize.Width();
     161             :                                 pMF->yExt = aWinSize.Height();
     162             :                             }
     163             : 
     164             :                             GlobalUnlock( hMemory );
     165             :                             pResult = (void*)hMemory;
     166             :                         }
     167             :                         else
     168             :                                DeleteMetaFile( hMeta );
     169             :                     }
     170             :                 }
     171             :             }
     172             : 
     173             :             delete pStream;
     174             :         }
     175             :     }
     176             : 
     177             : #endif
     178             : 
     179             : 
     180           0 :     return pResult;
     181             : }
     182             : 
     183             : 
     184             : // static
     185           0 : bool GraphicHelper::supportsMetaFileHandle_Impl()
     186             : {
     187             : #ifdef WNT
     188             :     return true;
     189             : #else
     190           0 :     return false;
     191             : #endif
     192             : }
     193             : 
     194             : 
     195             : // static
     196          68 : bool GraphicHelper::getThumbnailFormatFromGDI_Impl(GDIMetaFile* pMetaFile, const uno::Reference<io::XStream>& xStream)
     197             : {
     198          68 :     bool bResult = false;
     199             : 
     200          68 :     if (!pMetaFile || !xStream.is())
     201           0 :         return false;
     202             : 
     203          68 :     boost::scoped_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xStream));
     204             : 
     205          68 :     if (pStream->GetError())
     206           0 :         return false;
     207             : 
     208         136 :     BitmapEx aResultBitmap;
     209             : 
     210          68 :     bResult = pMetaFile->CreateThumbnail(aResultBitmap, 256, BMP_CONVERSION_8BIT_COLORS, BMP_SCALE_DEFAULT);
     211             : 
     212          68 :     if (!bResult || aResultBitmap.IsEmpty())
     213           0 :         return false;
     214             : 
     215          68 :     GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
     216             : 
     217          68 :     if (rFilter.compressAsPNG(aResultBitmap, *pStream.get(), 9) != GRFILTER_OK)
     218           0 :         return false;
     219             : 
     220          68 :     pStream->Flush();
     221             : 
     222         136 :     return !pStream->GetError();
     223             : }
     224             : 
     225             : // static
     226           0 : bool GraphicHelper::getThumbnailReplacement_Impl( sal_Int32 nResID, const uno::Reference< io::XStream >& xStream )
     227             : {
     228           0 :     bool bResult = false;
     229           0 :     if ( nResID && xStream.is() )
     230             :     {
     231           0 :         uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     232             :         try
     233             :         {
     234           0 :             uno::Reference< graphic::XGraphicProvider > xGraphProvider(graphic::GraphicProvider::create(xContext));
     235           0 :             OUString aURL("private:resource/sfx/bitmapex/");
     236           0 :             aURL += OUString::number( nResID );
     237             : 
     238           0 :             uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
     239           0 :             aMediaProps[0].Name = "URL";
     240           0 :             aMediaProps[0].Value <<= aURL;
     241             : 
     242           0 :             uno::Reference< graphic::XGraphic > xGraphic = xGraphProvider->queryGraphic( aMediaProps );
     243           0 :             if ( xGraphic.is() )
     244             :             {
     245           0 :                 uno::Sequence< beans::PropertyValue > aStoreProps( 2 );
     246           0 :                 aStoreProps[0].Name = "OutputStream";
     247           0 :                 aStoreProps[0].Value <<= xStream;
     248           0 :                 aStoreProps[1].Name = "MimeType";
     249           0 :                 aStoreProps[1].Value <<= OUString("image/png");
     250             : 
     251           0 :                 xGraphProvider->storeGraphic( xGraphic, aStoreProps );
     252           0 :                 bResult = true;
     253           0 :             }
     254             :         }
     255           0 :         catch(const uno::Exception&)
     256             :         {
     257           0 :         }
     258             :     }
     259             : 
     260           0 :     return bResult;
     261             : }
     262             : 
     263             : 
     264             : // static
     265           0 : sal_uInt16 GraphicHelper::getThumbnailReplacementIDByFactoryName_Impl( const OUString& aFactoryShortName, bool /*bIsTemplate*/ )
     266             : {
     267           0 :     sal_uInt16 nResult = 0;
     268             : 
     269           0 :     if ( aFactoryShortName == "scalc" )
     270             :     {
     271           0 :         nResult = BMP_128X128_CALC_DOC;
     272             :     }
     273           0 :     else if ( aFactoryShortName == "sdraw" )
     274             :     {
     275           0 :         nResult = BMP_128X128_DRAW_DOC;
     276             :     }
     277           0 :     else if ( aFactoryShortName == "simpress" )
     278             :     {
     279           0 :         nResult = BMP_128X128_IMPRESS_DOC;
     280             :     }
     281           0 :     else if ( aFactoryShortName == "smath" )
     282             :     {
     283           0 :         nResult = BMP_128X128_MATH_DOC;
     284             :     }
     285           0 :     else if ( aFactoryShortName == "swriter" || aFactoryShortName.startsWith("swriter/") )
     286             :     {
     287           0 :         nResult = BMP_128X128_WRITER_DOC;
     288             :     }
     289             : 
     290           0 :     return nResult;
     291         951 : }
     292             : 
     293             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10