LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/tree - imagecontainer.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 52 0.0 %
Date: 2014-04-14 Functions: 0 6 0.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             : 
      21             : #include "imagecontainer.hxx"
      22             : #include "genericelements.hxx"
      23             : #include "xmlemitter.hxx"
      24             : 
      25             : #include <rtl/ustrbuf.hxx>
      26             : #include <osl/file.h>
      27             : #include <rtl/crc.h>
      28             : 
      29             : #include <com/sun/star/graphic/XGraphicProvider.hpp>
      30             : #include <com/sun/star/beans/PropertyValue.hpp>
      31             : 
      32             : #include <cppuhelper/implbase1.hxx>
      33             : #include <comphelper/stl_types.hxx>
      34             : 
      35             : #include <boost/bind.hpp>
      36             : 
      37             : using namespace com::sun::star;
      38             : 
      39             : namespace pdfi
      40             : {
      41             : 
      42             : namespace
      43             : {
      44             : 
      45             : static const sal_Char aBase64EncodeTable[] =
      46             :     { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
      47             :       'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
      48             :       'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
      49             :       'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
      50             :       '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
      51             : 
      52           0 : OUString encodeBase64( const sal_Int8* i_pBuffer, const sal_uInt32 i_nBufferLength )
      53             : {
      54           0 :     OUStringBuffer aBuf( (i_nBufferLength+1) * 4 / 3 );
      55           0 :     const sal_Int32 nRemain(i_nBufferLength%3);
      56           0 :     const sal_Int32 nFullTripleLength( i_nBufferLength - (i_nBufferLength%3));
      57           0 :     sal_Int32 nBufPos( 0 );
      58           0 :     for( sal_Int32 i = 0; i < nFullTripleLength; i += 3, nBufPos += 4 )
      59             :     {
      60           0 :         const sal_Int32 nBinary = (((sal_uInt8)i_pBuffer[i + 0]) << 16) +
      61           0 :                                   (((sal_uInt8)i_pBuffer[i + 1]) <<  8) +
      62           0 :                                   ((sal_uInt8)i_pBuffer[i + 2]);
      63             : 
      64           0 :         aBuf.appendAscii("====");
      65             : 
      66           0 :         sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinary & 0xFC0000) >> 18));
      67           0 :         aBuf[nBufPos] = aBase64EncodeTable [nIndex];
      68             : 
      69           0 :         nIndex = static_cast<sal_uInt8>((nBinary & 0x3F000) >> 12);
      70           0 :         aBuf[nBufPos+1] = aBase64EncodeTable [nIndex];
      71             : 
      72           0 :         nIndex = static_cast<sal_uInt8>((nBinary & 0xFC0) >> 6);
      73           0 :         aBuf[nBufPos+2] = aBase64EncodeTable [nIndex];
      74             : 
      75           0 :         nIndex = static_cast<sal_uInt8>((nBinary & 0x3F));
      76           0 :         aBuf[nBufPos+3] = aBase64EncodeTable [nIndex];
      77             :     }
      78           0 :     if( nRemain > 0 )
      79             :     {
      80           0 :         aBuf.appendAscii("====");
      81           0 :         sal_Int32 nBinary( 0 );
      82           0 :         const sal_Int32 nStart(i_nBufferLength-nRemain);
      83           0 :         switch(nRemain)
      84             :         {
      85           0 :             case 1: nBinary = ((sal_uInt8)i_pBuffer[nStart + 0]) << 16;
      86           0 :                 break;
      87           0 :             case 2: nBinary = (((sal_uInt8)i_pBuffer[nStart + 0]) << 16) +
      88           0 :                               (((sal_uInt8)i_pBuffer[nStart + 1]) <<  8);
      89           0 :                 break;
      90             :         }
      91           0 :         sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinary & 0xFC0000) >> 18));
      92           0 :         aBuf[nBufPos] = aBase64EncodeTable [nIndex];
      93             : 
      94           0 :         nIndex = static_cast<sal_uInt8>((nBinary & 0x3F000) >> 12);
      95           0 :         aBuf[nBufPos+1] = aBase64EncodeTable [nIndex];
      96             : 
      97           0 :         if( nRemain == 2 )
      98             :         {
      99           0 :             nIndex = static_cast<sal_uInt8>((nBinary & 0xFC0) >> 6);
     100           0 :             aBuf[nBufPos+2] = aBase64EncodeTable [nIndex];
     101             :         }
     102             :     }
     103             : 
     104           0 :     return aBuf.makeStringAndClear();
     105             : }
     106             : 
     107             : } // namespace
     108             : 
     109           0 : ImageContainer::ImageContainer() :
     110           0 :     m_aImages()
     111           0 : {}
     112             : 
     113           0 : ImageId ImageContainer::addImage( const uno::Sequence<beans::PropertyValue>& xBitmap )
     114             : {
     115           0 :     m_aImages.push_back( xBitmap );
     116           0 :     return m_aImages.size()-1;
     117             : }
     118             : 
     119           0 : void ImageContainer::writeBase64EncodedStream( ImageId nId, EmitContext& rContext )
     120             : {
     121             :     OSL_ASSERT( nId >= 0 && nId < ImageId( m_aImages.size()) );
     122             : 
     123           0 :     const uno::Sequence<beans::PropertyValue>& rEntry( m_aImages[nId] );
     124             : 
     125             :     // find "InputSequence" property
     126           0 :     const beans::PropertyValue* pAry(rEntry.getConstArray());
     127           0 :     const sal_Int32             nLen(rEntry.getLength());
     128             :     const beans::PropertyValue* pValue(
     129             :         std::find_if(pAry,pAry+nLen,
     130             :                      boost::bind(comphelper::TPropertyValueEqualFunctor(),
     131             :                                  _1,
     132           0 :                                  OUString("InputSequence"))));
     133             :     OSL_ENSURE( pValue != pAry+nLen,
     134             :                 "InputSequence not found" );
     135             : 
     136           0 :     uno::Sequence<sal_Int8> aData;
     137           0 :     if( !(pValue->Value >>= aData) )
     138             :         OSL_FAIL("Wrong data type");
     139             : 
     140           0 :     rContext.rEmitter.write( encodeBase64( aData.getConstArray(), aData.getLength() ));
     141           0 : }
     142             : 
     143           0 : }
     144             : 
     145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10