tdf#113050 sdext.pdfimport: Add ImageContainer::asBase64EncodedString'

For fill-images we need the image as a string.

Change-Id: I4a8429563b0e19ad977b4e933a0ffee378dab244
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163569
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/sdext/source/pdfimport/inc/imagecontainer.hxx b/sdext/source/pdfimport/inc/imagecontainer.hxx
index d21ed75..03672e8 100644
--- a/sdext/source/pdfimport/inc/imagecontainer.hxx
+++ b/sdext/source/pdfimport/inc/imagecontainer.hxx
@@ -42,6 +42,7 @@ namespace pdfi
        ImageId addImage( const css::uno::Sequence<
                                css::beans::PropertyValue>& xBitmap );
        void writeBase64EncodedStream( ImageId nImageId, EmitContext& rContext );
        OUString asBase64EncodedString( ImageId nId ) const;
    };
}

diff --git a/sdext/source/pdfimport/tree/imagecontainer.cxx b/sdext/source/pdfimport/tree/imagecontainer.cxx
index a715416..b9f7ef5 100644
--- a/sdext/source/pdfimport/tree/imagecontainer.cxx
+++ b/sdext/source/pdfimport/tree/imagecontainer.cxx
@@ -141,6 +141,37 @@ void ImageContainer::writeBase64EncodedStream( ImageId nId, EmitContext& rContex
    rContext.rEmitter.write( encodeBase64( aData.getConstArray(), aData.getLength() ));
}

OUString ImageContainer::asBase64EncodedString( ImageId nId ) const
{
    OSL_ASSERT( nId >= 0 && o3tl::make_unsigned(nId) < 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,
            [] (beans::PropertyValue const& v) -> bool {
                return v.Name == "InputSequence";
            }));

    if (pValue == pAry + nLen )
    {
        SAL_WARN("sdext.pdfimport", "InputSequence not found");
        return "";
    }

    uno::Sequence<sal_Int8> aData;
    if( !(pValue->Value >>= aData) )
    {
        SAL_WARN("sdext.pdfimport", "Wrong data type");
        return "";
    }

    return encodeBase64( aData.getConstArray(), aData.getLength() );
}

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */