sdext/source/pdfimport/inc/imagecontainer.hxx  |    1 
 sdext/source/pdfimport/tree/imagecontainer.cxx |   31 +++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

New commits:
commit d7e5eae44e18ab89e85a0e6ed633853ede70ec71
Author:     Dr. David Alan Gilbert <[email protected]>
AuthorDate: Mon Feb 12 00:44:31 2024 +0000
Commit:     Noel Grandin <[email protected]>
CommitDate: Thu Feb 29 08:26:04 2024 +0100

    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 <[email protected]>

diff --git a/sdext/source/pdfimport/inc/imagecontainer.hxx 
b/sdext/source/pdfimport/inc/imagecontainer.hxx
index d21ed7504f63..03672e8ca8b2 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 a7154164d771..b9f7ef52e061 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: */

Reply via email to