summaryrefslogtreecommitdiff
path: root/sdext/source/pdfimport/tree/imagecontainer.cxx
blob: a4a8a5665997f8873e1c9605d6d139f1da6e68cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sdext.hxx"

#include "imagecontainer.hxx"
#include "genericelements.hxx"
#include "xmlemitter.hxx"

#include <rtl/ustrbuf.hxx>
#include <osl/file.h>
#include <rtl/crc.h>

#include <com/sun/star/graphic/XGraphicProvider.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>

#include <cppuhelper/implbase1.hxx>
#include <comphelper/stl_types.hxx>

#include <boost/bind.hpp>

using namespace com::sun::star;

namespace pdfi
{

namespace
{

static const sal_Char aBase64EncodeTable[] =
    { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
      'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
      'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
      'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
      '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };

rtl::OUString encodeBase64( const sal_Int8* i_pBuffer, const sal_uInt32 i_nBufferLength )
{
    rtl::OUStringBuffer aBuf( (i_nBufferLength+1) * 4 / 3 );
    const sal_Int32 nRemain(i_nBufferLength%3);
    const sal_Int32 nFullTripleLength( i_nBufferLength - (i_nBufferLength%3));
    sal_Int32 nBufPos( 0 );
    for( sal_Int32 i = 0; i < nFullTripleLength; i += 3, nBufPos += 4 )
    {
        const sal_Int32 nBinary = (((sal_uInt8)i_pBuffer[i + 0]) << 16) +
                                  (((sal_uInt8)i_pBuffer[i + 1]) <<  8) +
                                  ((sal_uInt8)i_pBuffer[i + 2]);

        aBuf.appendAscii("====");

        sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinary & 0xFC0000) >> 18));
        aBuf.setCharAt(nBufPos, aBase64EncodeTable [nIndex]);

        nIndex = static_cast<sal_uInt8>((nBinary & 0x3F000) >> 12);
        aBuf.setCharAt(nBufPos+1, aBase64EncodeTable [nIndex]);

        nIndex = static_cast<sal_uInt8>((nBinary & 0xFC0) >> 6);
        aBuf.setCharAt(nBufPos+2, aBase64EncodeTable [nIndex]);

        nIndex = static_cast<sal_uInt8>((nBinary & 0x3F));
        aBuf.setCharAt(nBufPos+3, aBase64EncodeTable [nIndex]);
    }
    if( nRemain > 0 )
    {
        aBuf.appendAscii("====");
        sal_Int32 nBinary( 0 );
        const sal_Int32 nStart(i_nBufferLength-nRemain);
        switch(nRemain)
        {
            case 1: nBinary = ((sal_uInt8)i_pBuffer[nStart + 0]) << 16;
                break;
            case 2: nBinary = (((sal_uInt8)i_pBuffer[nStart + 0]) << 16) +
                              (((sal_uInt8)i_pBuffer[nStart + 1]) <<  8);
                break;
        }
        sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinary & 0xFC0000) >> 18));
        aBuf.setCharAt(nBufPos, aBase64EncodeTable [nIndex]);

        nIndex = static_cast<sal_uInt8>((nBinary & 0x3F000) >> 12);
        aBuf.setCharAt(nBufPos+1, aBase64EncodeTable [nIndex]);

        if( nRemain == 2 )
        {
            nIndex = static_cast<sal_uInt8>((nBinary & 0xFC0) >> 6);
            aBuf.setCharAt(nBufPos+2, aBase64EncodeTable [nIndex]);
        }
    }

    return aBuf.makeStringAndClear();
}

} // namespace

ImageContainer::ImageContainer() :
    m_aImages()
{}

ImageId ImageContainer::addImage( const uno::Sequence<beans::PropertyValue>& xBitmap )
{
    m_aImages.push_back( xBitmap );
    return m_aImages.size()-1;
}

void ImageContainer::writeBase64EncodedStream( ImageId nId, EmitContext& rContext )
{
    OSL_ASSERT( nId >= 0 && nId < ImageId( m_aImages.size()) );

    const uno::Sequence<beans::PropertyValue>& rEntry( m_aImages[nId] );

    // find "InputSequence" property
    const beans::PropertyValue* pAry(rEntry.getConstArray());
    const sal_Int32             nLen(rEntry.getLength());
    const beans::PropertyValue* pValue(
        std::find_if(pAry,pAry+nLen,
                     boost::bind(comphelper::TPropertyValueEqualFunctor(),
                                 _1,
                                 rtl::OUString::createFromAscii("InputSequence"))));
    OSL_ENSURE( pValue != pAry+nLen,
                "InputSequence not found" );

    uno::Sequence<sal_Int8> aData;
    if( !(pValue->Value >>= aData) )
        OSL_ENSURE(false,"Wrong data type");

    rContext.rEmitter.write( encodeBase64( aData.getConstArray(), aData.getLength() ));
}

}
/td>svx: sal_Bool->boolNoel Grandin Change-Id: I78da39fc553b2e5040ee6665377ea51a1c4d04d7 2014-02-26Remove visual noise from svxAlexander Wilms Change-Id: I56497d953b0500ba0967fddb36ca8bbbe86c62ad Reviewed-on: https://gerrit.libreoffice.org/8321 Tested-by: Caolán McNamara <caolanm@redhat.com> Reviewed-by: Caolán McNamara <caolanm@redhat.com> 2014-02-20svl: sal_Bool -> boolStephan Bergmann Change-Id: Ic31455a1f5ffffa35d4fdde901dd70734207b6f4 2014-02-10coverity#735512 Logically dead codeCaolán McNamara Change-Id: I026bb291d8d0c87ef8166331a7e084fa339052f6 2014-01-28bool improvementsStephan Bergmann Change-Id: Ic32faa81bfbb66a9d8632fb3db187e33c31188ed 2014-01-17bool improvementsStephan Bergmann Change-Id: Ic46fa46c200b94e2e6c5a073ba89b9aae5c14542 2013-11-14remove unnecessary sal_Unicode casts in SVX moduleNoel Grandin Change-Id: I5d39af3bda3f1197fd1d706e7ef8d28b58d4851a 2013-11-11remove unnecessary use of OUString constructorNoel Grandin Change-Id: Ifb220af71857ddacd64e8204fb6d3e4aad8eef71 2013-11-08remove unnecessary use of OUString constructor in SVX moduleNoel Grandin Change-Id: I1506daaa4a3b736ee6bbb00100fca24df8368298 2013-08-31fdo#62475 - remove visual noisePhilipp Riemer Change-Id: I7409f7a58796c9bf7542b6a7904ad40581637eeb 2013-08-31fdo#62475 - remove visual noisePhilipp Riemer This is a follow up commit to - 22d1beb78a475e4846af945afde1c4d6c263b5d6 - 1c7af455ab9345304a7ac48ce2e0310de2ac8a75 Change-Id: I102685391125f3b4f7bdf838f8bd17a2283d558d 2013-08-23XubString->OUString and German->EnglishCaolán McNamara and remove the use of the current environment encoding, which can only match the encoding of the text by chance Change-Id: Iff6027a8d91db3644c9b827fb9460728c2b61751 2013-08-21finish deprecation of O(U)String::valueOf()Luboš Luňák Compiler plugin to replace with matching number(), boolean() or OUString ctor, ran it, few manual tweaks, mark as really deprecated. Change-Id: I4a79bdbcf4c460d21e73b635d2bd3725c22876b2 2013-08-20Re-work 8bit characters in source code, or remove them.Michael Meeks Change-Id: I93e14d4936c0ffbe03425d4a54bb0e09bc62b3e3 Reviewed-on: https://gerrit.libreoffice.org/5550 Tested-by: LibreOffice gerrit bot <gerrit@libreoffice.org> Reviewed-by: Michael Meeks <michael.meeks@suse.com> Tested-by: Michael Meeks <michael.meeks@suse.com>