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

Generated by: LCOV version 1.11