LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/tree - imagecontainer.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 50 52 96.2 %
Date: 2014-11-03 Functions: 6 6 100.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           6 : OUString encodeBase64( const sal_Int8* i_pBuffer, const sal_uInt32 i_nBufferLength )
      53             : {
      54           6 :     OUStringBuffer aBuf( (i_nBufferLength+1) * 4 / 3 );
      55           6 :     const sal_Int32 nRemain(i_nBufferLength%3);
      56           6 :     const sal_Int32 nFullTripleLength( i_nBufferLength - (i_nBufferLength%3));
      57           6 :     sal_Int32 nBufPos( 0 );
      58       88260 :     for( sal_Int32 i = 0; i < nFullTripleLength; i += 3, nBufPos += 4 )
      59             :     {
      60      176508 :         const sal_Int32 nBinary = (((sal_uInt8)i_pBuffer[i + 0]) << 16) +
      61      176508 :                                   (((sal_uInt8)i_pBuffer[i + 1]) <<  8) +
      62      176508 :                                   ((sal_uInt8)i_pBuffer[i + 2]);
      63             : 
      64       88254 :         aBuf.appendAscii("====");
      65             : 
      66       88254 :         sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinary & 0xFC0000) >> 18));
      67       88254 :         aBuf[nBufPos] = aBase64EncodeTable [nIndex];
      68             : 
      69       88254 :         nIndex = static_cast<sal_uInt8>((nBinary & 0x3F000) >> 12);
      70       88254 :         aBuf[nBufPos+1] = aBase64EncodeTable [nIndex];
      71             : 
      72       88254 :         nIndex = static_cast<sal_uInt8>((nBinary & 0xFC0) >> 6);
      73       88254 :         aBuf[nBufPos+2] = aBase64EncodeTable [nIndex];
      74             : 
      75       88254 :         nIndex = static_cast<sal_uInt8>((nBinary & 0x3F));
      76       88254 :         aBuf[nBufPos+3] = aBase64EncodeTable [nIndex];
      77             :     }
      78           6 :     if( nRemain > 0 )
      79             :     {
      80           6 :         aBuf.appendAscii("====");
      81           6 :         sal_Int32 nBinary( 0 );
      82           6 :         const sal_Int32 nStart(i_nBufferLength-nRemain);
      83           6 :         switch(nRemain)
      84             :         {
      85           0 :             case 1: nBinary = ((sal_uInt8)i_pBuffer[nStart + 0]) << 16;
      86           0 :                 break;
      87           6 :             case 2: nBinary = (((sal_uInt8)i_pBuffer[nStart + 0]) << 16) +
      88           6 :                               (((sal_uInt8)i_pBuffer[nStart + 1]) <<  8);
      89           6 :                 break;
      90             :         }
      91           6 :         sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinary & 0xFC0000) >> 18));
      92           6 :         aBuf[nBufPos] = aBase64EncodeTable [nIndex];
      93             : 
      94           6 :         nIndex = static_cast<sal_uInt8>((nBinary & 0x3F000) >> 12);
      95           6 :         aBuf[nBufPos+1] = aBase64EncodeTable [nIndex];
      96             : 
      97           6 :         if( nRemain == 2 )
      98             :         {
      99           6 :             nIndex = static_cast<sal_uInt8>((nBinary & 0xFC0) >> 6);
     100           6 :             aBuf[nBufPos+2] = aBase64EncodeTable [nIndex];
     101             :         }
     102             :     }
     103             : 
     104           6 :     return aBuf.makeStringAndClear();
     105             : }
     106             : 
     107             : } // namespace
     108             : 
     109           4 : ImageContainer::ImageContainer() :
     110           4 :     m_aImages()
     111           4 : {}
     112             : 
     113           4 : ImageId ImageContainer::addImage( const uno::Sequence<beans::PropertyValue>& xBitmap )
     114             : {
     115           4 :     m_aImages.push_back( xBitmap );
     116           4 :     return m_aImages.size()-1;
     117             : }
     118             : 
     119           6 : void ImageContainer::writeBase64EncodedStream( ImageId nId, EmitContext& rContext )
     120             : {
     121             :     OSL_ASSERT( nId >= 0 && nId < ImageId( m_aImages.size()) );
     122             : 
     123           6 :     const uno::Sequence<beans::PropertyValue>& rEntry( m_aImages[nId] );
     124             : 
     125             :     // find "InputSequence" property
     126           6 :     const beans::PropertyValue* pAry(rEntry.getConstArray());
     127           6 :     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           6 :                                  OUString("InputSequence"))));
     133             :     OSL_ENSURE( pValue != pAry+nLen,
     134             :                 "InputSequence not found" );
     135             : 
     136           6 :     uno::Sequence<sal_Int8> aData;
     137           6 :     if( !(pValue->Value >>= aData) )
     138             :         OSL_FAIL("Wrong data type");
     139             : 
     140           6 :     rContext.rEmitter.write( encodeBase64( aData.getConstArray(), aData.getLength() ));
     141           6 : }
     142             : 
     143           6 : }
     144             : 
     145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10