[Libreoffice-commits] core.git: Branch 'feature/drawinglayercore' - 9 commits - basic/source chart2/source editeng/source include/vcl offapi/com offapi/UnoApi_offapi.mk sc/source sd/qa sd/source sfx2/source svtools/source svx/source sw/qa sw/source vcl/CppunitTest_vcl_graphic_test.mk vcl/inc vcl/Library_vcl.mk vcl/qa vcl/source vcl/vcl.common.component

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Mon Dec 28 01:08:36 UTC 2020


Rebased ref, commits from common ancestor:
commit 7a2977ec8827751f02d836a62ea6931d4a2785b5
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Dec 28 10:03:18 2020 +0900
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon Dec 28 10:07:50 2020 +0900

    vcl: use BinaryDataContianer in VectorGraphicData
    
    This change is needed so we can use the same data in GfxLink and
    in VectorGraphicData. Currently the data needed to be duplicated,
    which is less than ideal.
    
    Change-Id: I79419921d09681fa8f0b1ac4bf8ea84199d4aae6

diff --git a/include/vcl/vectorgraphicdata.hxx b/include/vcl/vectorgraphicdata.hxx
index e231435312e8..8d55a9487d26 100644
--- a/include/vcl/vectorgraphicdata.hxx
+++ b/include/vcl/vectorgraphicdata.hxx
@@ -23,6 +23,7 @@
 #include <basegfx/range/b2drange.hxx>
 #include <com/sun/star/uno/Sequence.hxx>
 #include <vcl/bitmapex.hxx>
+#include <vcl/BinaryDataContainer.hxx>
 #include <rtl/ustring.hxx>
 #include <deque>
 #include <memory>
@@ -55,7 +56,7 @@ class VCL_DLLPUBLIC VectorGraphicData
 {
 private:
     // the file and length
-    VectorGraphicDataArray      maVectorGraphicDataArray;
+    BinaryDataContainer maDataContainer;
 
     // on demand created content
     bool                        mbSequenceCreated;
@@ -89,6 +90,10 @@ public:
         const VectorGraphicDataArray& rVectorGraphicDataArray,
         VectorGraphicDataType eVectorDataType,
         sal_Int32 nPageIndex = -1);
+    VectorGraphicData(
+        const BinaryDataContainer& rDataContainer,
+        VectorGraphicDataType eVectorDataType,
+        sal_Int32 nPageIndex = -1);
     ~VectorGraphicData();
 
     /// compare op
@@ -98,8 +103,16 @@ public:
     void setWmfExternalHeader(const WmfExternal& aExtHeader);
 
     /// data read
-    const VectorGraphicDataArray& getVectorGraphicDataArray() const { return maVectorGraphicDataArray; }
-    sal_uInt32 getVectorGraphicDataArrayLength() const { return maVectorGraphicDataArray.getLength(); }
+    const BinaryDataContainer& getBinaryDataContainer() const
+    {
+        return maDataContainer;
+    }
+
+    sal_uInt32 getVectorGraphicDataArrayLength() const
+    {
+        return maDataContainer.getSize();
+    }
+
     enum class State { UNPARSED, PARSED };
     std::pair<State, size_t> getSizeBytes() const;
 
diff --git a/sd/qa/unit/SdrPdfImportTest.cxx b/sd/qa/unit/SdrPdfImportTest.cxx
index f5e24fd19ede..85fb33d8243c 100644
--- a/sd/qa/unit/SdrPdfImportTest.cxx
+++ b/sd/qa/unit/SdrPdfImportTest.cxx
@@ -175,8 +175,7 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testAnnotationsImportExport)
     sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
     CPPUNIT_ASSERT(pViewShell);
 
-    const void* pData = nullptr;
-    int nLength = 0;
+    BinaryDataContainer aContainer;
 
     {
         // Get the first page - there should be only one.
@@ -202,13 +201,15 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testAnnotationsImportExport)
                              pVectorGraphicData->getVectorGraphicDataType());
 
         // Write the PDF
-        pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray();
-        nLength = pVectorGraphicData->getVectorGraphicDataArrayLength();
+        aContainer = pVectorGraphicData->getBinaryDataContainer();
     }
 
     { // check graphic PDF has annotations
 
-        auto pPDFDocument = pPdfiumLibrary->openDocument(pData, nLength);
+        CPPUNIT_ASSERT_EQUAL(false, aContainer.isEmpty());
+
+        auto pPDFDocument
+            = pPdfiumLibrary->openDocument(aContainer.getData(), aContainer.getSize());
         auto pPDFPage = pPDFDocument->openPage(0);
 
         CPPUNIT_ASSERT_EQUAL(2, pPDFPage->getAnnotationCount());
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 12b340ccf3fa..3de5d48b1f75 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -1380,8 +1380,8 @@ void SdImportTest::testPDFImportShared()
     {
         Graphic const & rGraphic = aGraphics[i];
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected all PDF streams to be identical.",
-                                     rFirstGraphic.getVectorGraphicData()->getVectorGraphicDataArray().getConstArray(),
-                                     rGraphic.getVectorGraphicData()->getVectorGraphicDataArray().getConstArray());
+                                     rFirstGraphic.getVectorGraphicData()->getBinaryDataContainer().getData(),
+                                     rGraphic.getVectorGraphicData()->getBinaryDataContainer().getData());
 
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected all GfxLinks to be identical.",
                                      rFirstGraphic.GetSharedGfxLink().get(),
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index e1ae905cef33..4cd84120fafe 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -125,8 +125,8 @@ ImpSdrPdfImport::ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const tools:
 
     // Load the buffer using pdfium.
     auto const& rVectorGraphicData = rGraphic.getVectorGraphicData();
-    auto* pData = rVectorGraphicData->getVectorGraphicDataArray().getConstArray();
-    sal_Int32 nSize = rVectorGraphicData->getVectorGraphicDataArrayLength();
+    auto* pData = rVectorGraphicData->getBinaryDataContainer().getData();
+    sal_Int32 nSize = rVectorGraphicData->getBinaryDataContainer().getSize();
     mpPdfDocument = mpPDFium->openDocument(pData, nSize);
     if (!mpPdfDocument)
         return;
diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx
index 1d0c23e92780..6dba9e722a7d 100644
--- a/svx/source/xoutdev/_xoutbmp.cxx
+++ b/svx/source/xoutdev/_xoutbmp.cxx
@@ -149,7 +149,8 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName,
 
                 if (pOStm)
                 {
-                    pOStm->WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength());
+                    auto & rDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
+                    pOStm->WriteBytes(rDataContainer.getData(), rDataContainer.getSize());
                     aMedium.Commit();
 
                     if (!aMedium.GetError())
diff --git a/vcl/inc/pdf/ExternalPDFStreams.hxx b/vcl/inc/pdf/ExternalPDFStreams.hxx
index ab3d057bd83c..f47aa56578d8 100644
--- a/vcl/inc/pdf/ExternalPDFStreams.hxx
+++ b/vcl/inc/pdf/ExternalPDFStreams.hxx
@@ -18,6 +18,7 @@
 #include <memory>
 
 #include <vcl/filter/pdfdocument.hxx>
+#include <vcl/BinaryDataContainer.hxx>
 
 namespace vcl
 {
@@ -27,7 +28,7 @@ namespace vcl
 // reused to avoid unnecessary parsing.
 struct VCL_DLLPUBLIC ExternalPDFStream
 {
-    std::vector<sal_uInt8> maData;
+    BinaryDataContainer maDataContainer;
     std::shared_ptr<filter::PDFDocument> mpPDFDocument;
     std::map<sal_Int32, sal_Int32> maCopiedResources;
 
@@ -38,7 +39,7 @@ struct VCL_DLLPUBLIC ExternalPDFStream
         if (!mpPDFDocument)
         {
             SvMemoryStream aPDFStream;
-            aPDFStream.WriteBytes(maData.data(), maData.size());
+            aPDFStream.WriteBytes(maDataContainer.getData(), maDataContainer.getSize());
             aPDFStream.Seek(0);
             mpPDFDocument = std::make_shared<filter::PDFDocument>();
             if (!mpPDFDocument->Read(aPDFStream))
@@ -61,7 +62,7 @@ private:
 public:
     ExternalPDFStreams() {}
 
-    sal_Int32 store(const sal_uInt8* pData, sal_uInt32 nLength);
+    sal_Int32 store(BinaryDataContainer const& rDataContainer);
 
     ExternalPDFStream& get(sal_uInt32 nIndex);
 };
diff --git a/vcl/qa/cppunit/PDFiumLibraryTest.cxx b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
index 577f73ed1130..597737864a87 100644
--- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx
+++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
@@ -65,12 +65,11 @@ void PDFiumLibraryTest::testDocument()
     CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf,
                          pVectorGraphicData->getVectorGraphicDataType());
 
-    const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray();
-    int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength();
+    auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer();
 
     auto pPdfium = vcl::pdf::PDFiumLibrary::get();
     CPPUNIT_ASSERT(pPdfium);
-    auto pDocument = pPdfium->openDocument(pData, nLength);
+    auto pDocument = pPdfium->openDocument(rDataContainer.getData(), rDataContainer.getSize());
     CPPUNIT_ASSERT(pDocument);
 
     CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount());
@@ -93,11 +92,10 @@ void PDFiumLibraryTest::testPages()
     CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf,
                          pVectorGraphicData->getVectorGraphicDataType());
 
-    const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray();
-    int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength();
+    auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer();
 
     auto pPdfium = vcl::pdf::PDFiumLibrary::get();
-    auto pDocument = pPdfium->openDocument(pData, nLength);
+    auto pDocument = pPdfium->openDocument(rDataContainer.getData(), rDataContainer.getSize());
     CPPUNIT_ASSERT(pDocument);
 
     CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount());
@@ -119,11 +117,10 @@ void PDFiumLibraryTest::testPageObjects()
     CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf,
                          pVectorGraphicData->getVectorGraphicDataType());
 
-    const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray();
-    int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength();
+    auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer();
 
     auto pPdfium = vcl::pdf::PDFiumLibrary::get();
-    auto pDocument = pPdfium->openDocument(pData, nLength);
+    auto pDocument = pPdfium->openDocument(rDataContainer.getData(), rDataContainer.getSize());
     CPPUNIT_ASSERT(pDocument);
 
     CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount());
@@ -169,11 +166,10 @@ void PDFiumLibraryTest::testAnnotationsMadeInEvince()
     CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf,
                          pVectorGraphicData->getVectorGraphicDataType());
 
-    const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray();
-    int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength();
+    auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer();
 
     auto pPdfium = vcl::pdf::PDFiumLibrary::get();
-    auto pDocument = pPdfium->openDocument(pData, nLength);
+    auto pDocument = pPdfium->openDocument(rDataContainer.getData(), rDataContainer.getSize());
     CPPUNIT_ASSERT(pDocument);
 
     CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount());
@@ -226,11 +222,10 @@ void PDFiumLibraryTest::testAnnotationsMadeInAcrobat()
     CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf,
                          pVectorGraphicData->getVectorGraphicDataType());
 
-    const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray();
-    int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength();
+    auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer();
 
     auto pPdfium = vcl::pdf::PDFiumLibrary::get();
-    auto pDocument = pPdfium->openDocument(pData, nLength);
+    auto pDocument = pPdfium->openDocument(rDataContainer.getData(), rDataContainer.getSize());
     CPPUNIT_ASSERT(pDocument);
 
     CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount());
@@ -304,11 +299,10 @@ void PDFiumLibraryTest::testAnnotationsDifferentTypes()
     CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf,
                          pVectorGraphicData->getVectorGraphicDataType());
 
-    const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray();
-    int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength();
+    auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer();
 
     auto pPdfium = vcl::pdf::PDFiumLibrary::get();
-    auto pDocument = pPdfium->openDocument(pData, nLength);
+    auto pDocument = pPdfium->openDocument(rDataContainer.getData(), rDataContainer.getSize());
     CPPUNIT_ASSERT(pDocument);
 
     CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount());
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index 02747b4e869b..65f3b8bb450f 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1986,7 +1986,8 @@ ErrCode GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString& r
                            == rVectorGraphicDataPtr->getVectorGraphicDataType()
                     && !bIsEMF)
                 {
-                    rOStm.WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength());
+                    auto & aDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
+                    rOStm.WriteBytes(aDataContainer.getData(), aDataContainer.getSize());
 
                     if (rOStm.GetError())
                     {
@@ -2019,7 +2020,8 @@ ErrCode GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString& r
                     && rVectorGraphicDataPtr->getVectorGraphicDataArrayLength()
                     && VectorGraphicDataType::Emf == rVectorGraphicDataPtr->getVectorGraphicDataType())
                 {
-                    rOStm.WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength());
+                    auto & aDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
+                    rOStm.WriteBytes(aDataContainer.getData(), aDataContainer.getSize());
 
                     if (rOStm.GetError())
                     {
@@ -2113,7 +2115,8 @@ ErrCode GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString& r
                     && rVectorGraphicDataPtr->getVectorGraphicDataArrayLength()
                     && VectorGraphicDataType::Svg == rVectorGraphicDataPtr->getVectorGraphicDataType())
                 {
-                    rOStm.WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength());
+                    auto & aDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
+                    rOStm.WriteBytes(aDataContainer.getData(), aDataContainer.getSize());
 
                     if( rOStm.GetError() )
                     {
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index c70363cef0f8..2c2c8526e779 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -442,18 +442,17 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rG
         ::utl::UcbStreamHelper::CreateStream(rURL, StreamMode::READ | StreamMode::SHARE_DENYNONE));
 
     // Save the original PDF stream for later use.
-    VectorGraphicDataArray aPdfDataArray = createVectorGraphicDataArray(*xStream);
-    if (!aPdfDataArray.hasElements())
-        return 0;
+    BinaryDataContainer aBinaryDataContainer;
+    {
+        VectorGraphicDataArray aPdfDataArray = createVectorGraphicDataArray(*xStream);
+        if (!aPdfDataArray.hasElements())
+            return 0;
+        const sal_uInt8* pData = reinterpret_cast<const sal_uInt8*>(aPdfDataArray.getConstArray());
+        aBinaryDataContainer = BinaryDataContainer(pData, aPdfDataArray.getLength());
+    }
 
     // Prepare the link with the PDF stream.
-    const size_t nGraphicContentSize = aPdfDataArray.getLength();
-    std::unique_ptr<sal_uInt8[]> pGraphicContent(new sal_uInt8[nGraphicContentSize]);
-
-    std::copy(aPdfDataArray.begin(), aPdfDataArray.end(), pGraphicContent.get());
-
-    auto pGfxLink = std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize,
-                                              GfxLinkType::NativePdf);
+    auto pGfxLink = std::make_shared<GfxLink>(aBinaryDataContainer, GfxLinkType::NativePdf);
 
     auto pPdfium = vcl::pdf::PDFiumLibrary::get();
 
@@ -481,7 +480,7 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rG
         tools::Long nPageHeight = convertTwipToMm100(aPageSize.getY() * pointToTwipconversionRatio);
 
         auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(
-            aPdfDataArray, VectorGraphicDataType::Pdf, nPageIndex);
+            aBinaryDataContainer, VectorGraphicDataType::Pdf, nPageIndex);
 
         // Create the Graphic with the VectorGraphicDataPtr and link the original PDF stream.
         // We swap out this Graphic as soon as possible, and a later swap in
diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx
index 114a8de73719..b1cdf4790c01 100644
--- a/vcl/source/gdi/TypeSerializer.cxx
+++ b/vcl/source/gdi/TypeSerializer.cxx
@@ -386,10 +386,10 @@ void TypeSerializer::writeGraphic(const Graphic& rGraphic)
                         }
                     }
 
-                    sal_uInt32 nSize = pVectorGraphicData->getVectorGraphicDataArrayLength();
+                    sal_uInt32 nSize = pVectorGraphicData->getBinaryDataContainer().getSize();
                     mrStream.WriteUInt32(nSize);
-                    mrStream.WriteBytes(
-                        pVectorGraphicData->getVectorGraphicDataArray().getConstArray(), nSize);
+                    mrStream.WriteBytes(pVectorGraphicData->getBinaryDataContainer().getData(),
+                                        nSize);
                     // For backwards compatibility, used to serialize path
                     mrStream.WriteUniOrByteString(OUString(), mrStream.GetStreamCharSet());
                 }
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 8dc81eb4987f..aeb471852ec8 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1200,8 +1200,8 @@ bool ImpGraphic::swapOutGraphic(SvStream& rStream)
                 rStream.WriteUInt32(maVectorGraphicData->getVectorGraphicDataArrayLength());
 
                 rStream.WriteBytes(
-                    maVectorGraphicData->getVectorGraphicDataArray().getConstArray(),
-                    maVectorGraphicData->getVectorGraphicDataArrayLength());
+                    maVectorGraphicData->getBinaryDataContainer().getData(),
+                    maVectorGraphicData->getBinaryDataContainer().getSize());
             }
             else if (ImplIsAnimated())
             {
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index ea8273592989..36b7460a69cf 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -4485,12 +4485,12 @@ bool PDFWriterImpl::emitEmbeddedFiles()
         aLine.append(rEmbeddedFile.m_nObject);
         aLine.append(" 0 obj\n");
         aLine.append("<< /Type /EmbeddedFile /Length ");
-        aLine.append(static_cast<sal_Int64>(rEmbeddedFile.m_pData->size()));
+        aLine.append(static_cast<sal_Int64>(rEmbeddedFile.m_aDataContainer.getSize()));
         aLine.append(" >>\nstream\n");
         CHECK_RETURN(writeBuffer(aLine.getStr(), aLine.getLength()));
         aLine.setLength(0);
 
-        CHECK_RETURN(writeBuffer(rEmbeddedFile.m_pData->data(), rEmbeddedFile.m_pData->size()));
+        CHECK_RETURN(writeBuffer(rEmbeddedFile.m_aDataContainer.getData(), rEmbeddedFile.m_aDataContainer.getSize()));
 
         aLine.append("\nendstream\nendobj\n\n");
         CHECK_RETURN(writeBuffer(aLine.getStr(), aLine.getLength()));
@@ -9004,22 +9004,19 @@ void PDFWriterImpl::createEmbeddedFile(const Graphic& rGraphic, ReferenceXObject
     if (!rGraphic.getVectorGraphicData() || rGraphic.getVectorGraphicData()->getVectorGraphicDataType() != VectorGraphicDataType::Pdf)
         return;
 
-    sal_uInt32 nLength = rGraphic.getVectorGraphicData()->getVectorGraphicDataArrayLength();
-    auto const & rArray = rGraphic.getVectorGraphicData()->getVectorGraphicDataArray();
+    BinaryDataContainer const & rDataContainer = rGraphic.getVectorGraphicData()->getBinaryDataContainer();
 
     if (m_aContext.UseReferenceXObject)
     {
-        auto pPDFData = std::make_shared<std::vector<sal_Int8>>(rArray.getConstArray(), rArray.getConstArray() + nLength);
-
         // Store the original PDF data as an embedded file.
         m_aEmbeddedFiles.emplace_back();
         m_aEmbeddedFiles.back().m_nObject = createObject();
-        m_aEmbeddedFiles.back().m_pData = pPDFData;
+        m_aEmbeddedFiles.back().m_aDataContainer = rDataContainer;
         rEmit.m_nEmbeddedObject = m_aEmbeddedFiles.back().m_nObject;
     }
     else
     {
-        sal_Int32 aIndex = m_aExternalPDFStreams.store(reinterpret_cast<const sal_uInt8*>(rArray.getConstArray()), nLength);
+        sal_Int32 aIndex = m_aExternalPDFStreams.store(rDataContainer);
         rEmit.m_nExternalPDFPageIndex = rGraphic.getVectorGraphicData()->getPageIndex();
         rEmit.m_nExternalPDFDataIndex = aIndex;
     }
diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx
index 00d016ace285..992ba59d1dd2 100644
--- a/vcl/source/gdi/pdfwriter_impl.hxx
+++ b/vcl/source/gdi/pdfwriter_impl.hxx
@@ -50,6 +50,7 @@
 #include <o3tl/lru_map.hxx>
 #include <comphelper/hash.hxx>
 #include <tools/stream.hxx>
+#include <vcl/BinaryDataContainer.hxx>
 
 #include <outdata.hxx>
 #include <vcl/filter/pdfobjectcontainer.hxx>
@@ -403,7 +404,7 @@ struct PDFEmbeddedFile
     /// ID of the file.
     sal_Int32 m_nObject;
     /// Contents of the file.
-    std::shared_ptr<std::vector<sal_Int8>> m_pData;
+    BinaryDataContainer m_aDataContainer;
 
     PDFEmbeddedFile()
         : m_nObject(0)
diff --git a/vcl/source/gdi/vectorgraphicdata.cxx b/vcl/source/gdi/vectorgraphicdata.cxx
index 61618b7adfe8..609040f44129 100644
--- a/vcl/source/gdi/vectorgraphicdata.cxx
+++ b/vcl/source/gdi/vectorgraphicdata.cxx
@@ -39,6 +39,7 @@
 #include <vcl/outdev.hxx>
 #include <vcl/wmfexternal.hxx>
 #include <vcl/pdfread.hxx>
+#include <unotools/streamwrap.hxx>
 
 using namespace ::com::sun::star;
 
@@ -117,9 +118,9 @@ bool VectorGraphicData::operator==(const VectorGraphicData& rCandidate) const
         if (getVectorGraphicDataArrayLength() == rCandidate.getVectorGraphicDataArrayLength())
         {
             if (0 == memcmp(
-                getVectorGraphicDataArray().getConstArray(),
-                rCandidate.getVectorGraphicDataArray().getConstArray(),
-                getVectorGraphicDataArrayLength()))
+                maDataContainer.getData(),
+                rCandidate.maDataContainer.getData(),
+                maDataContainer.getSize()))
             {
                 return true;
             }
@@ -151,8 +152,8 @@ void VectorGraphicData::ensurePdfReplacement()
     sal_Int32 nUsePageIndex = 0;
     if (mnPageIndex >= 0)
         nUsePageIndex = mnPageIndex;
-    vcl::RenderPDFBitmaps(maVectorGraphicDataArray.getConstArray(),
-                          maVectorGraphicDataArray.getLength(), aBitmaps, nUsePageIndex, 1,
+    vcl::RenderPDFBitmaps(maDataContainer.getData(),
+                          maDataContainer.getSize(), aBitmaps, nUsePageIndex, 1,
                           &maSizeHint);
     if (!aBitmaps.empty())
         maReplacement = aBitmaps[0];
@@ -181,7 +182,9 @@ void VectorGraphicData::ensureReplacement()
 
 void VectorGraphicData::ensureSequenceAndRange()
 {
-    if (mbSequenceCreated || !maVectorGraphicDataArray.hasElements())
+    printf ("VectorGraphicData::ensureSequenceAndRange\n");
+
+    if (mbSequenceCreated || maDataContainer.isEmpty())
         return;
 
     // import SVG to maSequence, also set maRange
@@ -194,11 +197,15 @@ void VectorGraphicData::ensureSequenceAndRange()
     {
         case VectorGraphicDataType::Svg:
         {
+            css::uno::Sequence<sal_Int8> aDataSequence(maDataContainer.getSize());
+            std::copy(maDataContainer.cbegin(), maDataContainer.cend(), aDataSequence.begin());
+            const uno::Reference<io::XInputStream> xInputStream(new comphelper::SequenceInputStream(aDataSequence));
+
+
             const uno::Reference< graphic::XSvgParser > xSvgParser = graphic::SvgTools::create(xContext);
-            const uno::Reference< io::XInputStream > myInputStream(new comphelper::SequenceInputStream(maVectorGraphicDataArray));
 
-            if (myInputStream.is())
-                maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xSvgParser->getDecomposition(myInputStream, OUString()));
+            if (xInputStream.is())
+                maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xSvgParser->getDecomposition(xInputStream, OUString()));
 
             break;
         }
@@ -206,7 +213,11 @@ void VectorGraphicData::ensureSequenceAndRange()
         case VectorGraphicDataType::Wmf:
         {
             const uno::Reference< graphic::XEmfParser > xEmfParser = graphic::EmfTools::create(xContext);
-            const uno::Reference< io::XInputStream > myInputStream(new comphelper::SequenceInputStream(maVectorGraphicDataArray));
+
+            css::uno::Sequence<sal_Int8> aDataSequence(maDataContainer.getSize());
+            std::copy(maDataContainer.cbegin(), maDataContainer.cend(), aDataSequence.begin());
+            const uno::Reference<io::XInputStream> xInputStream(new comphelper::SequenceInputStream(aDataSequence));
+
             uno::Sequence< ::beans::PropertyValue > aSequence;
 
             if (mpExternalHeader)
@@ -214,7 +225,7 @@ void VectorGraphicData::ensureSequenceAndRange()
                 aSequence = mpExternalHeader->getSequence();
             }
 
-            if (myInputStream.is())
+            if (xInputStream.is())
             {
                 // Pass the size hint of the graphic to the EMF parser.
                 geometry::RealPoint2D aSizeHint;
@@ -224,15 +235,12 @@ void VectorGraphicData::ensureSequenceAndRange()
 
                 if (!mbEnableEMFPlus)
                 {
-                    auto aVector
-                        = comphelper::sequenceToContainer<std::vector<beans::PropertyValue>>(
-                            aSequence);
-                    aVector.push_back(
-                        comphelper::makePropertyValue("EMFPlusEnable", uno::makeAny(false)));
+                    auto aVector = comphelper::sequenceToContainer<std::vector<beans::PropertyValue>>(aSequence);
+                    aVector.push_back(comphelper::makePropertyValue("EMFPlusEnable", uno::makeAny(false)));
                     aSequence = comphelper::containerToSequence(aVector);
                 }
 
-                maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xEmfParser->getDecomposition(myInputStream, OUString(), aSequence));
+                maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xEmfParser->getDecomposition(xInputStream, OUString(), aSequence));
             }
 
             break;
@@ -243,7 +251,10 @@ void VectorGraphicData::ensureSequenceAndRange()
             uno::Sequence<beans::PropertyValue> aDecompositionParameters = comphelper::InitPropertySequence({
                 {"PageIndex", uno::makeAny<sal_Int32>(mnPageIndex)},
             });
-            auto xPrimitive2D = xPdfDecomposer->getDecomposition(maVectorGraphicDataArray, aDecompositionParameters);
+            // TODO: change xPdfDecomposer to use BinaryDataContainer directly
+            VectorGraphicDataArray aVectorGraphicDataArray(maDataContainer.getSize());
+            std::copy(maDataContainer.cbegin(), maDataContainer.cend(), aVectorGraphicDataArray.begin());
+            auto xPrimitive2D = xPdfDecomposer->getDecomposition(aVectorGraphicDataArray, aDecompositionParameters);
             maSequence = comphelper::sequenceToContainer<std::deque<uno::Reference<graphic::XPrimitive2D>>>(xPrimitive2D);
 
             break;
@@ -280,13 +291,13 @@ void VectorGraphicData::ensureSequenceAndRange()
 
 std::pair<VectorGraphicData::State, size_t> VectorGraphicData::getSizeBytes() const
 {
-    if (!maSequence.empty() && maVectorGraphicDataArray.hasElements())
+    if (!maSequence.empty() && !maDataContainer.isEmpty())
     {
-        return std::make_pair(State::PARSED, maVectorGraphicDataArray.getLength() + mNestedBitmapSize);
+        return std::make_pair(State::PARSED, maDataContainer.getSize() + mNestedBitmapSize);
     }
     else
     {
-        return std::make_pair(State::UNPARSED, maVectorGraphicDataArray.getLength());
+        return std::make_pair(State::UNPARSED, maDataContainer.getSize());
     }
 }
 
@@ -294,7 +305,22 @@ VectorGraphicData::VectorGraphicData(
     const VectorGraphicDataArray& rVectorGraphicDataArray,
     VectorGraphicDataType eVectorDataType,
     sal_Int32 nPageIndex)
-:   maVectorGraphicDataArray(rVectorGraphicDataArray),
+:   maDataContainer(reinterpret_cast<const sal_uInt8*>(rVectorGraphicDataArray.begin()), rVectorGraphicDataArray.getLength()),
+    mbSequenceCreated(false),
+    maRange(),
+    maSequence(),
+    maReplacement(),
+    mNestedBitmapSize(0),
+    meVectorGraphicDataType(eVectorDataType),
+    mnPageIndex(nPageIndex)
+{
+}
+
+VectorGraphicData::VectorGraphicData(
+    const BinaryDataContainer& rDataContainer,
+    VectorGraphicDataType eVectorDataType,
+    sal_Int32 nPageIndex)
+:   maDataContainer(rDataContainer),
     mbSequenceCreated(false),
     maRange(),
     maSequence(),
@@ -332,7 +358,7 @@ const BitmapEx& VectorGraphicData::getReplacement() const
 
 BitmapChecksum VectorGraphicData::GetChecksum() const
 {
-    return vcl_get_checksum(0, maVectorGraphicDataArray.getConstArray(), maVectorGraphicDataArray.getLength());
+    return vcl_get_checksum(0, maDataContainer.getData(), maDataContainer.getSize());
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/graphic/GraphicID.cxx b/vcl/source/graphic/GraphicID.cxx
index 1cad217241fa..cfd2d751d246 100644
--- a/vcl/source/graphic/GraphicID.cxx
+++ b/vcl/source/graphic/GraphicID.cxx
@@ -39,9 +39,8 @@ GraphicID::GraphicID(ImpGraphic const& rGraphic)
             mnID1 |= rVectorGraphicDataPtr->getVectorGraphicDataArrayLength();
             mnID2 = basegfx::fround(rRange.getWidth());
             mnID3 = basegfx::fround(rRange.getHeight());
-            mnID4 = vcl_get_checksum(
-                0, rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(),
-                rVectorGraphicDataPtr->getVectorGraphicDataArrayLength());
+            mnID4 = vcl_get_checksum(0, rVectorGraphicDataPtr->getBinaryDataContainer().getData(),
+                                     rVectorGraphicDataPtr->getBinaryDataContainer().getSize());
         }
         else if (rGraphic.ImplIsAnimated())
         {
diff --git a/vcl/source/graphic/VectorGraphicSearch.cxx b/vcl/source/graphic/VectorGraphicSearch.cxx
index dfa747bc1a6a..3c1003d29654 100644
--- a/vcl/source/graphic/VectorGraphicSearch.cxx
+++ b/vcl/source/graphic/VectorGraphicSearch.cxx
@@ -252,8 +252,8 @@ bool VectorGraphicSearch::search(OUString const& rSearchString,
 bool VectorGraphicSearch::searchPDF(std::shared_ptr<VectorGraphicData> const& rData)
 {
     mpImplementation->mpPdfDocument
-        = FPDF_LoadMemDocument(rData->getVectorGraphicDataArray().getConstArray(),
-                               rData->getVectorGraphicDataArrayLength(), /*password=*/nullptr);
+        = FPDF_LoadMemDocument(rData->getBinaryDataContainer().getData(),
+                               rData->getBinaryDataContainer().getSize(), /*password=*/nullptr);
 
     if (!mpImplementation->mpPdfDocument)
     {
diff --git a/vcl/source/pdf/ExternalPDFStreams.cxx b/vcl/source/pdf/ExternalPDFStreams.cxx
index 08f31ed22829..e3716e1e0aed 100644
--- a/vcl/source/pdf/ExternalPDFStreams.cxx
+++ b/vcl/source/pdf/ExternalPDFStreams.cxx
@@ -13,19 +13,18 @@
 
 namespace vcl
 {
-sal_Int32 ExternalPDFStreams::store(const sal_uInt8* pData, sal_uInt32 nLength)
+sal_Int32 ExternalPDFStreams::store(BinaryDataContainer const& rDataContainer)
 {
     sal_Int32 nIndex = -1;
 
-    std::vector<sal_uInt8> aHash
-        = comphelper::Hash::calculateHash(pData, nLength, comphelper::HashType::SHA1);
+    std::vector<sal_uInt8> aHash = comphelper::Hash::calculateHash(
+        rDataContainer.getData(), rDataContainer.getSize(), comphelper::HashType::SHA1);
 
     auto it = maStreamIndexMap.find(aHash);
     if (it == maStreamIndexMap.end())
     {
         auto& rExternalStream = maStreamList.emplace_back();
-        rExternalStream.maData.resize(nLength);
-        std::copy(pData, pData + nLength, rExternalStream.maData.begin());
+        rExternalStream.maDataContainer = rDataContainer;
         nIndex = maStreamList.size() - 1;
         maStreamIndexMap.emplace(aHash, nIndex);
     }
commit 03f7c24d0d1bb5d6a4a26a36dff3701c6a21bcb1
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Dec 27 19:07:57 2020 +0900
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon Dec 28 10:07:50 2020 +0900

    vcl: implement BinaryDataContainer copy, move + test
    
    Also remove constructor that takes size only - BinaryDataContainer
    should always be constructed with data, that is copied into the
    container and should be immutable.
    
    Change-Id: Ic61b393b7729b948843bd20e6676c9290c68936f

diff --git a/include/vcl/BinaryDataContainer.hxx b/include/vcl/BinaryDataContainer.hxx
index 844d6c5bb81f..da0607cdfc97 100644
--- a/include/vcl/BinaryDataContainer.hxx
+++ b/include/vcl/BinaryDataContainer.hxx
@@ -27,13 +27,29 @@ private:
 
 public:
     explicit BinaryDataContainer();
-    explicit BinaryDataContainer(size_t nSize);
     explicit BinaryDataContainer(const sal_uInt8* pData, size_t nSize);
 
-    explicit BinaryDataContainer(const BinaryDataContainer& rBinaryDataContainer) = default;
-    explicit BinaryDataContainer(BinaryDataContainer&& rBinaryDataContainer) = default;
-    BinaryDataContainer& operator=(const BinaryDataContainer& rBinaryDataContainer) = default;
-    BinaryDataContainer& operator=(BinaryDataContainer&& rBinaryDataContainer) = default;
+    BinaryDataContainer(const BinaryDataContainer& rBinaryDataContainer)
+        : mpData(rBinaryDataContainer.mpData)
+    {
+    }
+
+    BinaryDataContainer(BinaryDataContainer&& rBinaryDataContainer)
+        : mpData(std::move(rBinaryDataContainer.mpData))
+    {
+    }
+
+    BinaryDataContainer& operator=(const BinaryDataContainer& rBinaryDataContainer)
+    {
+        mpData = rBinaryDataContainer.mpData;
+        return *this;
+    }
+
+    BinaryDataContainer& operator=(BinaryDataContainer&& rBinaryDataContainer)
+    {
+        mpData = std::move(rBinaryDataContainer.mpData);
+        return *this;
+    }
 
     size_t getSize() const { return mpData ? mpData->size() : 0; }
     bool isEmpty() const { return mpData ? mpData->empty() : true; }
diff --git a/vcl/CppunitTest_vcl_graphic_test.mk b/vcl/CppunitTest_vcl_graphic_test.mk
index 2f2c61735ef8..9221fd474fdd 100644
--- a/vcl/CppunitTest_vcl_graphic_test.mk
+++ b/vcl/CppunitTest_vcl_graphic_test.mk
@@ -15,6 +15,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,vcl_graphic_test, \
     vcl/qa/cppunit/GraphicFormatDetectorTest \
     vcl/qa/cppunit/GraphicNativeMetadataTest \
     vcl/qa/cppunit/VectorGraphicSearchTest \
+    vcl/qa/cppunit/BinaryDataContainerTest \
 ))
 
 $(eval $(call gb_CppunitTest_use_externals,vcl_graphic_test, \
diff --git a/vcl/qa/cppunit/BinaryDataContainerTest.cxx b/vcl/qa/cppunit/BinaryDataContainerTest.cxx
new file mode 100644
index 000000000000..597e7d4bc3aa
--- /dev/null
+++ b/vcl/qa/cppunit/BinaryDataContainerTest.cxx
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <vcl/BinaryDataContainer.hxx>
+
+using namespace css;
+
+namespace
+{
+class BinaryDataContainerTest : public CppUnit::TestFixture
+{
+    void test();
+
+    CPPUNIT_TEST_SUITE(BinaryDataContainerTest);
+    CPPUNIT_TEST(test);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void BinaryDataContainerTest::test()
+{
+    {
+        BinaryDataContainer aContainer;
+        CPPUNIT_ASSERT_EQUAL(true, bool(aContainer.isEmpty()));
+        CPPUNIT_ASSERT_EQUAL(size_t(0), aContainer.getSize());
+    }
+    {
+        std::vector<sal_uInt8> aTestByteArray = { 1, 2, 3, 4 };
+        BinaryDataContainer aContainer(aTestByteArray.data(), aTestByteArray.size());
+        CPPUNIT_ASSERT_EQUAL(false, bool(aContainer.isEmpty()));
+        CPPUNIT_ASSERT_EQUAL(size_t(4), aContainer.getSize());
+
+        // Test Copy
+        BinaryDataContainer aCopyOfContainer = aContainer;
+        CPPUNIT_ASSERT_EQUAL(false, bool(aCopyOfContainer.isEmpty()));
+        CPPUNIT_ASSERT_EQUAL(size_t(4), aCopyOfContainer.getSize());
+        CPPUNIT_ASSERT_EQUAL(aCopyOfContainer.getData(), aContainer.getData());
+
+        // Test Move
+        BinaryDataContainer aMovedInContainer = std::move(aCopyOfContainer);
+        CPPUNIT_ASSERT_EQUAL(false, bool(aMovedInContainer.isEmpty()));
+        CPPUNIT_ASSERT_EQUAL(size_t(4), aMovedInContainer.getSize());
+        CPPUNIT_ASSERT_EQUAL(aMovedInContainer.getData(), aContainer.getData());
+
+        CPPUNIT_ASSERT_EQUAL(true, bool(aCopyOfContainer.isEmpty()));
+        CPPUNIT_ASSERT_EQUAL(size_t(0), aCopyOfContainer.getSize());
+    }
+}
+
+} // namespace
+
+CPPUNIT_TEST_SUITE_REGISTRATION(BinaryDataContainerTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/graphic/BinaryDataContainer.cxx b/vcl/source/graphic/BinaryDataContainer.cxx
index 4c556195fe6a..7576852215b1 100644
--- a/vcl/source/graphic/BinaryDataContainer.cxx
+++ b/vcl/source/graphic/BinaryDataContainer.cxx
@@ -13,11 +13,6 @@
 
 BinaryDataContainer::BinaryDataContainer() = default;
 
-BinaryDataContainer::BinaryDataContainer(size_t nSize)
-    : mpData(std::make_shared<std::vector<sal_uInt8>>(nSize))
-{
-}
-
 BinaryDataContainer::BinaryDataContainer(const sal_uInt8* pData, size_t nSize)
     : mpData(std::make_shared<std::vector<sal_uInt8>>(nSize))
 {
commit db90f77b8e03cd51401f9d91a819b0c13284eeb0
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sat Dec 26 12:41:08 2020 +0900
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon Dec 28 10:07:49 2020 +0900

    vcl: remove "path" attribute from VectorGraphicData
    
    This isn't used for anything important for the vector graphic
    and is mostly empty string anyways.
    
    Change-Id: I1c5b52b5b407bd320cb5053141f1699971607399

diff --git a/include/vcl/vectorgraphicdata.hxx b/include/vcl/vectorgraphicdata.hxx
index cb3963947d2d..e231435312e8 100644
--- a/include/vcl/vectorgraphicdata.hxx
+++ b/include/vcl/vectorgraphicdata.hxx
@@ -57,9 +57,6 @@ private:
     // the file and length
     VectorGraphicDataArray      maVectorGraphicDataArray;
 
-    // The absolute Path if available
-    OUString                    maPath;
-
     // on demand created content
     bool                        mbSequenceCreated;
     basegfx::B2DRange           maRange;
@@ -90,7 +87,6 @@ private:
 public:
     VectorGraphicData(
         const VectorGraphicDataArray& rVectorGraphicDataArray,
-        const OUString& rPath,
         VectorGraphicDataType eVectorDataType,
         sal_Int32 nPageIndex = -1);
     ~VectorGraphicData();
@@ -106,7 +102,7 @@ public:
     sal_uInt32 getVectorGraphicDataArrayLength() const { return maVectorGraphicDataArray.getLength(); }
     enum class State { UNPARSED, PARSED };
     std::pair<State, size_t> getSizeBytes() const;
-    const OUString& getPath() const { return maPath; }
+
     const VectorGraphicDataType& getVectorGraphicDataType() const { return meVectorGraphicDataType; }
 
     /// data read and evtl. on demand creation
diff --git a/sfx2/source/appl/appmisc.cxx b/sfx2/source/appl/appmisc.cxx
index 37011ff1cc2f..c62fcd47a1e5 100644
--- a/sfx2/source/appl/appmisc.cxx
+++ b/sfx2/source/appl/appmisc.cxx
@@ -166,13 +166,13 @@ bool SfxApplication::loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWid
 
     std::vector<sal_uInt8> aBinaryData;
     OUString aPath = aObj.PathToFileName();
-    if (!loadDataFromFile(aObj.PathToFileName(), aBinaryData))
+    if (!loadDataFromFile(aPath, aBinaryData))
         return false;
 
     VectorGraphicDataArray aVectorGraphicDataArray;
     std::copy(aBinaryData.cbegin(), aBinaryData.cend(), aVectorGraphicDataArray.begin());
 
-    VectorGraphicData aVectorGraphicData(aVectorGraphicDataArray, aPath, VectorGraphicDataType::Svg);
+    VectorGraphicData aVectorGraphicData(aVectorGraphicDataArray, VectorGraphicDataType::Svg);
 
     // transform into [0,0,width,width*aspect] std dimensions
 
diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index 4c6a1a6972dc..e68d5cdc6c0e 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -325,6 +325,10 @@ void GraphicTest::testUnloadedGraphicSizeUnit()
     Size aMtfSize100(42, 42);
     SvFileStream aStream(aURL, StreamMode::READ);
     Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream, 0, &aMtfSize100);
+
+    CPPUNIT_ASSERT_EQUAL(Size(42, 42), aGraphic.GetPrefSize());
+
+    // Force it to swap in
     aGraphic.makeAvailable();
 
     // Without the accompanying fix in place, this test would have failed with:
@@ -753,10 +757,10 @@ void GraphicTest::testSwappingVectorGraphic_SVG_WithoutGfxLink()
         CPPUNIT_ASSERT_EQUAL(true, bool(xStream));
 
         // Check size of the stream
-        CPPUNIT_ASSERT_EQUAL(sal_uInt64(249), xStream->remainingSize());
+        CPPUNIT_ASSERT_EQUAL(sal_uInt64(247), xStream->remainingSize());
 
         std::vector<unsigned char> aHash = calculateHash(xStream);
-        CPPUNIT_ASSERT_EQUAL(std::string("322da9ea0683f03ce35cf8a71e59b686b9be28e8"),
+        CPPUNIT_ASSERT_EQUAL(std::string("666820973fd95e6cd9e7bc5f1c53732acbc99326"),
                              toHexString(aHash));
     }
 
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index 2a708336d233..02747b4e869b 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1620,7 +1620,7 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
 
                         if(!aMemStream.GetError() )
                         {
-                            auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, rPath, VectorGraphicDataType::Svg);
+                            auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, VectorGraphicDataType::Svg);
                             rGraphic = Graphic(aVectorGraphicDataPtr);
                             bOkay = true;
                         }
@@ -1633,7 +1633,7 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
 
                     if(!rIStream.GetError())
                     {
-                        auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, rPath, VectorGraphicDataType::Svg);
+                        auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, VectorGraphicDataType::Svg);
                         rGraphic = Graphic(aVectorGraphicDataPtr);
                         bOkay = true;
                     }
@@ -1710,7 +1710,6 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
                 auto aVectorGraphicDataPtr =
                     std::make_shared<VectorGraphicData>(
                         aNewData,
-                        rPath,
                         aDataType);
 
                 if (pExtHeader)
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index dbfa5ceeaf68..c70363cef0f8 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -240,8 +240,8 @@ bool importPdfVectorGraphicData(SvStream& rStream,
         return false;
     }
 
-    rVectorGraphicData = std::make_shared<VectorGraphicData>(aPdfDataArray, OUString(),
-                                                             VectorGraphicDataType::Pdf);
+    rVectorGraphicData
+        = std::make_shared<VectorGraphicData>(aPdfDataArray, VectorGraphicDataType::Pdf);
 
     return true;
 }
@@ -481,7 +481,7 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rG
         tools::Long nPageHeight = convertTwipToMm100(aPageSize.getY() * pointToTwipconversionRatio);
 
         auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(
-            aPdfDataArray, OUString(), VectorGraphicDataType::Pdf, nPageIndex);
+            aPdfDataArray, VectorGraphicDataType::Pdf, nPageIndex);
 
         // Create the Graphic with the VectorGraphicDataPtr and link the original PDF stream.
         // We swap out this Graphic as soon as possible, and a later swap in
diff --git a/vcl/source/filter/wmf/wmf.cxx b/vcl/source/filter/wmf/wmf.cxx
index 8a04bc1d3025..70ff37f7473f 100644
--- a/vcl/source/filter/wmf/wmf.cxx
+++ b/vcl/source/filter/wmf/wmf.cxx
@@ -54,7 +54,6 @@ bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF )
         auto aVectorGraphicDataPtr =
             std::make_shared<VectorGraphicData>(
                 aNewData,
-                OUString(),
                 VectorGraphicDataType::Emf);
 
         // create a Graphic and grep Metafile from it
@@ -97,7 +96,7 @@ bool ConvertGraphicToWMF(const Graphic& rGraphic, SvStream& rTargetStream,
         uno::Sequence<sal_Int8> aData(reinterpret_cast<const sal_Int8*>(aLink.GetData()),
                                       aLink.GetDataSize());
         auto aVectorGraphicData
-            = std::make_shared<VectorGraphicData>(aData, OUString(), VectorGraphicDataType::Emf);
+            = std::make_shared<VectorGraphicData>(aData, VectorGraphicDataType::Emf);
         aVectorGraphicData->setEnableEMFPlus(false);
         Graphic aGraphic(aVectorGraphicData);
         bool bRet = ConvertGDIMetaFileToWMF(aGraphic.GetGDIMetaFile(), rTargetStream, pConfigItem,
diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx
index e501c58c6be7..114a8de73719 100644
--- a/vcl/source/gdi/TypeSerializer.cxx
+++ b/vcl/source/gdi/TypeSerializer.cxx
@@ -281,7 +281,6 @@ void TypeSerializer::readGraphic(Graphic& rGraphic)
                         VectorGraphicDataArray aData(nLength);
 
                         mrStream.ReadBytes(aData.getArray(), nLength);
-                        OUString aPath = mrStream.ReadUniOrByteString(mrStream.GetStreamCharSet());
 
                         if (!mrStream.GetError())
                         {
@@ -301,7 +300,7 @@ void TypeSerializer::readGraphic(Graphic& rGraphic)
                             }
 
                             auto aVectorGraphicDataPtr
-                                = std::make_shared<VectorGraphicData>(aData, aPath, aDataType);
+                                = std::make_shared<VectorGraphicData>(aData, aDataType);
                             rGraphic = Graphic(aVectorGraphicDataPtr);
                         }
                     }
@@ -391,8 +390,8 @@ void TypeSerializer::writeGraphic(const Graphic& rGraphic)
                     mrStream.WriteUInt32(nSize);
                     mrStream.WriteBytes(
                         pVectorGraphicData->getVectorGraphicDataArray().getConstArray(), nSize);
-                    mrStream.WriteUniOrByteString(pVectorGraphicData->getPath(),
-                                                  mrStream.GetStreamCharSet());
+                    // For backwards compatibility, used to serialize path
+                    mrStream.WriteUniOrByteString(OUString(), mrStream.GetStreamCharSet());
                 }
                 else if (aGraphic.IsAnimated())
                 {
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 02709008d31f..8dc81eb4987f 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1202,8 +1202,6 @@ bool ImpGraphic::swapOutGraphic(SvStream& rStream)
                 rStream.WriteBytes(
                     maVectorGraphicData->getVectorGraphicDataArray().getConstArray(),
                     maVectorGraphicData->getVectorGraphicDataArrayLength());
-
-                rStream.WriteUniOrByteString(maVectorGraphicData->getPath(), rStream.GetStreamCharSet());
             }
             else if (ImplIsAnimated())
             {
@@ -1557,8 +1555,6 @@ bool ImpGraphic::swapInGraphic(SvStream& rStream)
 
                         rStream.ReadBytes(aNewData.getArray(), nVectorGraphicDataArrayLength);
 
-                        OUString aPath = rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
-
                         if (rStream.GetError())
                             return false;
 
@@ -1582,7 +1578,7 @@ bool ImpGraphic::swapInGraphic(SvStream& rStream)
                                 return false;
                         }
 
-                        auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, aPath, aDataType);
+                        auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, aDataType);
 
                         if (!rStream.GetError())
                         {
diff --git a/vcl/source/gdi/vectorgraphicdata.cxx b/vcl/source/gdi/vectorgraphicdata.cxx
index b36b232061b2..61618b7adfe8 100644
--- a/vcl/source/gdi/vectorgraphicdata.cxx
+++ b/vcl/source/gdi/vectorgraphicdata.cxx
@@ -198,7 +198,7 @@ void VectorGraphicData::ensureSequenceAndRange()
             const uno::Reference< io::XInputStream > myInputStream(new comphelper::SequenceInputStream(maVectorGraphicDataArray));
 
             if (myInputStream.is())
-                maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xSvgParser->getDecomposition(myInputStream, maPath));
+                maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xSvgParser->getDecomposition(myInputStream, OUString()));
 
             break;
         }
@@ -232,7 +232,7 @@ void VectorGraphicData::ensureSequenceAndRange()
                     aSequence = comphelper::containerToSequence(aVector);
                 }
 
-                maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xEmfParser->getDecomposition(myInputStream, maPath, aSequence));
+                maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xEmfParser->getDecomposition(myInputStream, OUString(), aSequence));
             }
 
             break;
@@ -292,11 +292,9 @@ std::pair<VectorGraphicData::State, size_t> VectorGraphicData::getSizeBytes() co
 
 VectorGraphicData::VectorGraphicData(
     const VectorGraphicDataArray& rVectorGraphicDataArray,
-    const OUString& rPath,
     VectorGraphicDataType eVectorDataType,
     sal_Int32 nPageIndex)
 :   maVectorGraphicDataArray(rVectorGraphicDataArray),
-    maPath(rPath),
     mbSequenceCreated(false),
     maRange(),
     maSequence(),
commit f5100ac2896a8927381aeccd7c95334c7a6a856a
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sat Dec 26 08:50:01 2020 +0900
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon Dec 28 10:07:49 2020 +0900

    vcl: remove VectorGraphicData const. which loads data from file
    
    It is not VectorGraphicData responsibility to load data from a
    file, so remove the constructor which attemts to do it and move
    it to the only user of this constructor.
    
    Change-Id: Ie03defb0cb4f17f4039aee44bb3e41bffc17488d

diff --git a/include/vcl/vectorgraphicdata.hxx b/include/vcl/vectorgraphicdata.hxx
index 1787d060e11b..cb3963947d2d 100644
--- a/include/vcl/vectorgraphicdata.hxx
+++ b/include/vcl/vectorgraphicdata.hxx
@@ -93,7 +93,6 @@ public:
         const OUString& rPath,
         VectorGraphicDataType eVectorDataType,
         sal_Int32 nPageIndex = -1);
-    VectorGraphicData(const OUString& rPath, VectorGraphicDataType eVectorDataType);
     ~VectorGraphicData();
 
     /// compare op
diff --git a/sfx2/source/appl/appmisc.cxx b/sfx2/source/appl/appmisc.cxx
index f7ddfb297d6a..37011ff1cc2f 100644
--- a/sfx2/source/appl/appmisc.cxx
+++ b/sfx2/source/appl/appmisc.cxx
@@ -31,6 +31,7 @@
 #include <rtl/bootstrap.hxx>
 #include <svl/stritem.hxx>
 #include <tools/urlobj.hxx>
+#include <tools/stream.hxx>
 
 #include <sfx2/app.hxx>
 #include <appdata.hxx>
@@ -124,6 +125,32 @@ static bool FileExists( const INetURLObject& rURL )
     return bRet;
 }
 
+namespace
+{
+
+bool loadDataFromFile(OUString const & rPath, std::vector<sal_uInt8> & rBinaryData)
+{
+    SvFileStream rStream(rPath, StreamMode::STD_READ);
+    if (rStream.GetError())
+        return false;
+
+    const sal_uInt32 nStreamLength(rStream.remainingSize());
+
+    if (nStreamLength)
+    {
+        rBinaryData.clear();
+        rBinaryData.resize(nStreamLength);
+        rStream.ReadBytes(rBinaryData.data(), nStreamLength);
+
+        if (!rStream.GetError())
+        {
+            return true;
+        }
+    }
+    return false;
+}
+} // end anonymous namespace
+
 bool SfxApplication::loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWidth)
 {
     // Load from disk
@@ -137,7 +164,15 @@ bool SfxApplication::loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWid
     if ( !FileExists(aObj) )
         return false;
 
-    VectorGraphicData aVectorGraphicData(aObj.PathToFileName(), VectorGraphicDataType::Svg);
+    std::vector<sal_uInt8> aBinaryData;
+    OUString aPath = aObj.PathToFileName();
+    if (!loadDataFromFile(aObj.PathToFileName(), aBinaryData))
+        return false;
+
+    VectorGraphicDataArray aVectorGraphicDataArray;
+    std::copy(aBinaryData.cbegin(), aBinaryData.cend(), aVectorGraphicDataArray.begin());
+
+    VectorGraphicData aVectorGraphicData(aVectorGraphicDataArray, aPath, VectorGraphicDataType::Svg);
 
     // transform into [0,0,width,width*aspect] std dimensions
 
diff --git a/vcl/source/gdi/vectorgraphicdata.cxx b/vcl/source/gdi/vectorgraphicdata.cxx
index a8134a60c852..b36b232061b2 100644
--- a/vcl/source/gdi/vectorgraphicdata.cxx
+++ b/vcl/source/gdi/vectorgraphicdata.cxx
@@ -307,35 +307,6 @@ VectorGraphicData::VectorGraphicData(
 {
 }
 
-VectorGraphicData::VectorGraphicData(
-    const OUString& rPath,
-    VectorGraphicDataType eVectorDataType)
-:   maVectorGraphicDataArray(),
-    maPath(rPath),
-    mbSequenceCreated(false),
-    maRange(),
-    maSequence(),
-    maReplacement(),
-    mNestedBitmapSize(0),
-    meVectorGraphicDataType(eVectorDataType),
-    mnPageIndex(-1)
-{
-    SvFileStream rIStm(rPath, StreamMode::STD_READ);
-    if(rIStm.GetError())
-        return;
-    const sal_uInt32 nStmLen(rIStm.remainingSize());
-    if (nStmLen)
-    {
-        maVectorGraphicDataArray.realloc(nStmLen);
-        rIStm.ReadBytes(maVectorGraphicDataArray.begin(), nStmLen);
-
-        if (rIStm.GetError())
-        {
-            maVectorGraphicDataArray = VectorGraphicDataArray();
-        }
-    }
-}
-
 VectorGraphicData::~VectorGraphicData()
 {
 }
commit 96b4c597c84dbd4a53b94ff4e01e0d884d04dd4b
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sat Dec 26 08:48:03 2020 +0900
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon Dec 28 10:07:49 2020 +0900

    vcl: remove unneeded check
    
    Change-Id: I3da0449afe3d21581934278f9a6fe03c4e652214

diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 6e444e3712ef..02709008d31f 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -786,8 +786,7 @@ Size ImpGraphic::ImplGetPrefSize() const
 
             case GraphicType::GdiMetafile:
             {
-                if (ImplIsSupportedGraphic())
-                  aSize = maMetaFile.GetPrefSize();
+                aSize = maMetaFile.GetPrefSize();
             }
             break;
 
commit 4f347e5236f9429c64c9a1c3539dfbf1bfda1b54
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Fri Dec 25 20:10:44 2020 +0900
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon Dec 28 10:07:49 2020 +0900

    vcl: add an UNO interface and impl. for BinaryDataContainer
    
    Change-Id: Icbc384892bee8c31eb7f3a39ff9a64f1199b23b1

diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index eabb1272588a..5e7fa60ebc34 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -446,6 +446,7 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/ui/test,\
     UITest \
 ))
 $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/util,\
+	BinaryDataContainer \
 	JobManager \
 	NumberFormatter \
 	NumberFormatsSupplier \
@@ -4143,6 +4144,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/util,\
 	VetoException \
 	XAccounting \
 	XAtomServer \
+	XBinaryDataContainer \
 	XBroadcaster \
 	XCancellable \
 	XChainable \
diff --git a/offapi/com/sun/star/util/BinaryDataContainer.idl b/offapi/com/sun/star/util/BinaryDataContainer.idl
new file mode 100644
index 000000000000..be4102a20b1c
--- /dev/null
+++ b/offapi/com/sun/star/util/BinaryDataContainer.idl
@@ -0,0 +1,30 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef com_sun_star_util_BinaryDataContainer_idl
+#define com_sun_star_util_BinaryDataContainer_idl
+
+
+module com { module sun { module star { module util
+{
+
+/** Implementation of a container for binary data.
+
+    @since LibreOffice 7.2
+ */
+
+service BinaryDataContainer : XBinaryDataContainer
+{
+};
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/offapi/com/sun/star/util/XBinaryDataContainer.idl b/offapi/com/sun/star/util/XBinaryDataContainer.idl
new file mode 100644
index 000000000000..563ac4db7e00
--- /dev/null
+++ b/offapi/com/sun/star/util/XBinaryDataContainer.idl
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef com_sun_star_util_XBinaryDataContainer_idl
+#define com_sun_star_util_XBinaryDataContainer_idl
+
+module com { module sun { module star { module util
+{
+
+/** Container for binary data, typically an in-memory content of files.
+
+    @since LibreOffice 7.2
+ */
+interface XBinaryDataContainer
+{
+    sequence<byte> getCopyAsByteSequence();
+};
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index b326147ca5a1..a1ea249cb964 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -337,6 +337,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/graphic/GraphicObject2 \
     vcl/source/graphic/GraphicReader \
     vcl/source/graphic/Manager \
+    vcl/source/graphic/UnoBinaryDataContainer \
     vcl/source/graphic/UnoGraphic \
     vcl/source/graphic/UnoGraphicMapper \
     vcl/source/graphic/UnoGraphicDescriptor \
diff --git a/vcl/source/graphic/UnoBinaryDataContainer.cxx b/vcl/source/graphic/UnoBinaryDataContainer.cxx
new file mode 100644
index 000000000000..cd6ce99d4a39
--- /dev/null
+++ b/vcl/source/graphic/UnoBinaryDataContainer.cxx
@@ -0,0 +1,84 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/supportsservice.hxx>
+
+#include <com/sun/star/util/XBinaryDataContainer.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+#include <vcl/BinaryDataContainer.hxx>
+
+using namespace css;
+
+namespace
+{
+typedef ::cppu::WeakImplHelper<util::XBinaryDataContainer, css::lang::XServiceInfo>
+    BinaryDataContainer_BASE;
+
+class UnoBinaryDataContainer : public BinaryDataContainer_BASE
+{
+private:
+    BinaryDataContainer maBinaryDataContainer;
+
+public:
+    explicit UnoBinaryDataContainer() {}
+
+    BinaryDataContainer const& getBinaryDataContainer() { return maBinaryDataContainer; }
+
+    void setBinaryDataContainer(BinaryDataContainer const& rBinaryDataContainer)
+    {
+        maBinaryDataContainer = rBinaryDataContainer;
+    }
+
+    // XBinaryDataContainer
+    css::uno::Sequence<sal_Int8> SAL_CALL getCopyAsByteSequence() override
+    {
+        if (maBinaryDataContainer.isEmpty())
+            return css::uno::Sequence<sal_Int8>();
+
+        size_t nSize = maBinaryDataContainer.getSize();
+
+        css::uno::Sequence<sal_Int8> aData(nSize);
+
+        std::copy(maBinaryDataContainer.cbegin(), maBinaryDataContainer.cend(), aData.getArray());
+
+        return aData;
+    }
+
+    // XServiceInfo
+    virtual OUString SAL_CALL getImplementationName() override
+    {
+        return "com.sun.star.util.BinaryDataContainer";
+    }
+
+    virtual sal_Bool SAL_CALL supportsService(OUString const& rServiceName) override
+    {
+        return cppu::supportsService(this, rServiceName);
+    }
+
+    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
+    {
+        return uno::Sequence<OUString>{ "com.sun.star.util.BinaryDataContainer" };
+    }
+};
+
+} // end anonymous namespace
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+com_sun_star_comp_util_BinaryDataContainer_get_implementation(
+    SAL_UNUSED_PARAMETER uno::XComponentContext*,
+    SAL_UNUSED_PARAMETER uno::Sequence<uno::Any> const&)
+{
+    return cppu::acquire(new UnoBinaryDataContainer());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/vcl.common.component b/vcl/vcl.common.component
index 2665a136afcc..abf5da9c10dd 100644
--- a/vcl/vcl.common.component
+++ b/vcl/vcl.common.component
@@ -35,4 +35,8 @@
     constructor="dtrans_CMimeContentTypeFactory_get_implementation">
     <service name="com.sun.star.datatransfer.MimeContentTypeFactory"/>
   </implementation>
+  <implementation name="com.sun.star.util.BinaryDataContainer"
+    constructor="com_sun_star_comp_util_BinaryDataContainer_get_implementation">
+    <service name="com.sun.star.util.BinaryDataContainer"/>
+  </implementation>
 </component>
commit a038bfbbd798d31a12cceacfa58c0e564f6aac0f
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Dec 24 11:18:47 2020 +0900
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon Dec 28 10:07:49 2020 +0900

    Same SvStream reading fix as in commit [1] but for TypeSerializer
    
    [1] 8c9a4ff511a3b1d84a7a6d08a1b153c07f164abb
    
    Explanation from the commit:
    "to avoid chasing weird problems where we read past the end
    of file, which leads to random data in the variable we read into.
    
    I expect a couple of possible regressions from this change
    
    (1) memory leaks caused by non-exception-safe memory handling.
    Of which there should not be much because we're pretty good
    about using smart pointer classes these days.
    
    (2) Broken files which used to load, will no longer do so.
    These will have to be debugged by putting a breakpoint
    on the SvStreamEOFException constructor, and examining
    the backtrace to see where we should be catching and ignoring
    the exception to make the code continue to handle such broken
    files."
    
    Change-Id: I6f9ba7599c208b4340e86014e326e9a0693cd528

diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx
index 6e1e504ee670..e501c58c6be7 100644
--- a/vcl/source/gdi/TypeSerializer.cxx
+++ b/vcl/source/gdi/TypeSerializer.cxx
@@ -170,16 +170,15 @@ void TypeSerializer::readGraphic(Graphic& rGraphic)
     const sal_uLong nInitialStreamPosition = mrStream.Tell();
     sal_uInt32 nType;
 
-    // read Id
-    mrStream.ReadUInt32(nType);
-
     // if there is no more data, avoid further expensive
     // reading which will create VDevs and other stuff, just to
-    // read nothing. CAUTION: Eof is only true AFTER reading another
-    // byte, a speciality of SvMemoryStream (!)
-    if (!mrStream.good())
+    // read nothing.
+    if (mrStream.remainingSize() < 4)
         return;
 
+    // read Id
+    mrStream.ReadUInt32(nType);
+
     if (NATIVE_FORMAT_50 == nType)
     {
         Graphic aGraphic;
commit ffad87af76df6bd065b3f7ce6fdd83b253d6ef18
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Dec 24 09:22:35 2020 +0900
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Mon Dec 28 10:07:49 2020 +0900

    vcl: remove {Read,Write}ImpGraphic and ImplExportNative from Graphic
    
    ReadImpGraphic and WriteImpGraphic have been reimplemented in the
    TypeSerializer some time ago, but the code has not yet been moved
    to use that class. This commits does that and changes all the code
    using those 2 methods and removes them. With this implemented in
    the TypeSerializer, it is easier to handle
    
    In addition it also removes ImplExportNative (and the method on
    the Graphic interface). This was really used only in one method,
    and it could be implemented in the mthod itself.
    
    Change-Id: I0982429d1c1d5ed7ef07627d87ed9a08df43f040

diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 84d51c760f1e..d8c0c3f9a583 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -101,6 +101,7 @@ using namespace com::sun::star::uno;
 
 #include <com/sun/star/i18n/XCharacterClassification.hpp>
 #include <vcl/unohelp.hxx>
+#include <vcl/TypeSerializer.hxx>
 
 #if HAVE_FEATURE_SCRIPTING
 
@@ -4332,7 +4333,8 @@ void SbRtl_SavePicture(StarBASIC *, SbxArray & rPar, bool)
     {
         SvFileStream aOStream( rPar.Get32(2)->GetOUString(), StreamMode::WRITE | StreamMode::TRUNC );
         const Graphic& aGraphic = pPicture->GetGraphic();
-        WriteGraphic( aOStream, aGraphic );
+        TypeSerializer aSerializer(aOStream);
+        aSerializer.writeGraphic(aGraphic);
     }
 }
 
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx
index 8d78185159d9..6a6b7269b893 100644
--- a/chart2/source/controller/main/ChartController_Tools.cxx
+++ b/chart2/source/controller/main/ChartController_Tools.cxx
@@ -57,6 +57,7 @@
 #include <vcl/transfer.hxx>
 #include <sot/storage.hxx>
 #include <vcl/graph.hxx>
+#include <vcl/TypeSerializer.hxx>
 #include <svx/unomodel.hxx>
 #include <svx/svdmodel.hxx>
 #include <unotools/streamwrap.hxx>
@@ -290,7 +291,10 @@ void ChartController::executeDispatch_Paste()
             // graphic exchange format (graphic manager bitmap format?)
             tools::SvRef<SotTempStream> xStm;
             if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB, xStm ))
-                ReadGraphic( *xStm, aGraphic );
+            {
+                TypeSerializer aSerializer(*xStm);
+                aSerializer.readGraphic(aGraphic);
+            }
         }
         else if( aDataHelper.HasFormat( SotClipboardFormatId::GDIMETAFILE ))
         {
diff --git a/editeng/source/items/legacyitem.cxx b/editeng/source/items/legacyitem.cxx
index af41980b2d2c..fd4334aed245 100644
--- a/editeng/source/items/legacyitem.cxx
+++ b/editeng/source/items/legacyitem.cxx
@@ -24,6 +24,7 @@
 #include <comphelper/fileformat.h>
 #include <vcl/graph.hxx>
 #include <vcl/GraphicObject.hxx>
+#include <vcl/TypeSerializer.hxx>
 #include <osl/diagnose.h>
 #include <tools/urlobj.hxx>
 #include <editeng/fontitem.hxx>
@@ -493,7 +494,7 @@ namespace legacy
             sal_Int8 nStyle;
 
             rStrm.ReadCharAsBool( bTrans );
-            tools::GenericTypeSerializer aSerializer(rStrm);
+            TypeSerializer aSerializer(rStrm);
             aSerializer.readColor(aTempColor);
             aSerializer.readColor(aTempFillColor);
             rStrm.ReadSChar( nStyle );
@@ -555,8 +556,7 @@ namespace legacy
             if ( nDoLoad & LOAD_GRAPHIC )
             {
                 Graphic aGraphic;
-
-                ReadGraphic( rStrm, aGraphic );
+                aSerializer.readGraphic(aGraphic);
                 rItem.SetGraphicObject(GraphicObject(aGraphic));
 
                 if( SVSTREAM_FILEFORMAT_ERROR == rStrm.GetError() )
@@ -592,7 +592,7 @@ namespace legacy
         SvStream& Store(const SvxBrushItem& rItem, SvStream& rStrm, sal_uInt16)
         {
             rStrm.WriteBool( false );
-            tools::GenericTypeSerializer aSerializer(rStrm);
+            TypeSerializer aSerializer(rStrm);
             aSerializer.writeColor(rItem.GetColor());
             aSerializer.writeColor(rItem.GetColor());
             rStrm.WriteSChar( rItem.GetColor().GetTransparency() > 0 ? 0 : 1 ); //BRUSH_NULL : BRUSH_SOLID
@@ -609,7 +609,9 @@ namespace legacy
             rStrm.WriteUInt16( nDoLoad );
 
             if (nullptr != pGraphicObject && rItem.GetGraphicLink().isEmpty())
-                WriteGraphic(rStrm, pGraphicObject->GetGraphic());
+            {
+                aSerializer.writeGraphic(pGraphicObject->GetGraphic());
+            }
             if ( !rItem.GetGraphicLink().isEmpty() )
             {
                 OSL_FAIL("No BaseURL!");
diff --git a/vcl/inc/TypeSerializer.hxx b/include/vcl/TypeSerializer.hxx
similarity index 100%
rename from vcl/inc/TypeSerializer.hxx
rename to include/vcl/TypeSerializer.hxx
diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx
index 983330a89745..86d885a326ac 100644
--- a/include/vcl/graph.hxx
+++ b/include/vcl/graph.hxx
@@ -185,11 +185,6 @@ public:
     GfxLink         GetGfxLink() const;
     bool            IsGfxLink() const;
 
-    bool            ExportNative( SvStream& rOStream ) const;
-
-    friend VCL_DLLPUBLIC void WriteGraphic(SvStream& rOStream, const Graphic& rGraphic);
-    friend VCL_DLLPUBLIC void ReadGraphic(SvStream& rIStream, Graphic& rGraphic);
-
     const std::shared_ptr<VectorGraphicData>& getVectorGraphicData() const;
 
     /// Get the page number of the multi-page source this Graphic is rendered from.
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 95b6bd3d7cde..11f03b0b92fd 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -31,6 +31,7 @@
 #include <memory>
 #include <vcl/uitest/logger.hxx>
 #include <vcl/uitest/eventdescription.hxx>
+#include <vcl/TypeSerializer.hxx>
 
 #include <attrib.hxx>
 #include <patattr.hxx>
@@ -783,8 +784,8 @@ bool ScViewFunc::PasteOnDrawObjectLinked(
         if( pScDrawView && aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB, xStm ) )
         {
             Graphic aGraphic;
-
-            ReadGraphic( *xStm, aGraphic );
+            TypeSerializer aSerializer(*xStm);
+            aSerializer.readGraphic(aGraphic);
 
             const OUString aBeginUndo(ScResId(STR_UNDO_DRAGDROP));
 
diff --git a/sc/source/ui/view/viewfun5.cxx b/sc/source/ui/view/viewfun5.cxx
index e5d52fabfe83..1773c2fb4474 100644
--- a/sc/source/ui/view/viewfun5.cxx
+++ b/sc/source/ui/view/viewfun5.cxx
@@ -40,6 +40,7 @@
 #include <svl/stritem.hxx>
 #include <vcl/transfer.hxx>
 #include <vcl/graph.hxx>
+#include <vcl/TypeSerializer.hxx>
 #include <osl/thread.h>
 
 #include <comphelper/automationinvokedzone.hxx>
@@ -501,7 +502,8 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId,
         if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB, xStm ) )
         {
             Graphic aGraphic;
-            ReadGraphic( *xStm, aGraphic );
+            TypeSerializer aSerializer(*xStm);
+            aSerializer.readGraphic(aGraphic);
             bRet = PasteGraphic( aPos, aGraphic, EMPTY_OUSTRING );
         }
     }
diff --git a/sd/source/ui/view/sdview3.cxx b/sd/source/ui/view/sdview3.cxx
index 9657e76fc492..d334cb7a2254 100644
--- a/sd/source/ui/view/sdview3.cxx
+++ b/sd/source/ui/view/sdview3.cxx
@@ -41,6 +41,7 @@
 #include <svx/ImageMapInfo.hxx>
 #include <unotools/streamwrap.hxx>
 #include <vcl/metaact.hxx>
+#include <vcl/TypeSerializer.hxx>
 #include <svx/svxids.hrc>
 #include <toolkit/helper/vclunohelper.hxx>
 #include <svtools/embedhlp.hxx>
@@ -1200,7 +1201,8 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper,
             Point   aInsertPos( rPos );
             Graphic aGraphic;
 
-            ReadGraphic( *xStm, aGraphic );
+            TypeSerializer aSerializer(*xStm);
+            aSerializer.readGraphic(aGraphic);
 
             if( pOwnData && pOwnData->GetWorkDocument() )
             {
diff --git a/sfx2/source/appl/linkmgr2.cxx b/sfx2/source/appl/linkmgr2.cxx
index befb7510f82a..0bdfd7b3788e 100644
--- a/sfx2/source/appl/linkmgr2.cxx
+++ b/sfx2/source/appl/linkmgr2.cxx
@@ -42,6 +42,7 @@
 #include <unotools/charclass.hxx>
 #include <unotools/securityoptions.hxx>
 #include <vcl/GraphicLoader.hxx>
+#include <vcl/TypeSerializer.hxx>
 
 #include "fileobj.hxx"
 #include "impldde.hxx"
@@ -543,7 +544,8 @@ bool LinkManager::GetGraphicFromAny(const OUString& rMimeType,
         {
         case SotClipboardFormatId::SVXB:
             {
-                ReadGraphic( aMemStm, rGraphic );
+                TypeSerializer aSerializer(aMemStm);
+                aSerializer.readGraphic(rGraphic);
                 bRet = true;
             }
             break;
diff --git a/svtools/source/misc/embedhlp.cxx b/svtools/source/misc/embedhlp.cxx
index 27a9703fdc7f..6536747f1b3a 100644
--- a/svtools/source/misc/embedhlp.cxx
+++ b/svtools/source/misc/embedhlp.cxx
@@ -22,6 +22,8 @@
 #include <vcl/graphicfilter.hxx>
 #include <vcl/gdimtf.hxx>
 #include <vcl/outdev.hxx>
+#include <vcl/gfxlink.hxx>
+#include <vcl/TypeSerializer.hxx>
 #include <bitmaps.hlst>
 
 #include <sal/log.hxx>
@@ -770,15 +772,32 @@ void EmbeddedObjectRef::SetGraphicToContainer( const Graphic& rGraphic,
 {
     SvMemoryStream aStream;
     aStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
-    if ( rGraphic.ExportNative( aStream ) )
-    {
-        aStream.Seek( 0 );
 
-        uno::Reference < io::XInputStream > xStream = new ::utl::OSeekableInputStreamWrapper( aStream );
-        aContainer.InsertGraphicStream( xStream, aName, aMediaType );
+    auto pGfxLink = rGraphic.GetSharedGfxLink();
+    if (pGfxLink && pGfxLink->IsNative())
+    {
+        if (pGfxLink->ExportNative(aStream))
+        {
+            aStream.Seek(0);
+            uno::Reference <io::XInputStream> xStream = new ::utl::OSeekableInputStreamWrapper(aStream);
+            aContainer.InsertGraphicStream(xStream, aName, aMediaType);
+        }
+        else
+            OSL_FAIL("Export of graphic is failed!");
     }
     else
-        OSL_FAIL( "Export of graphic is failed!" );
+    {
+        TypeSerializer aSerializer(aStream);
+        aSerializer.writeGraphic(rGraphic);
+        if (aStream.GetError() == ERRCODE_NONE)
+        {
+            aStream.Seek(0);
+            uno::Reference <io::XInputStream> xStream = new ::utl::OSeekableInputStreamWrapper(aStream);
+            aContainer.InsertGraphicStream(xStream, aName, aMediaType);
+        }
+        else
+            OSL_FAIL("Export of graphic is failed!");
+    }
 }
 
 uno::Reference< io::XInputStream > EmbeddedObjectRef::GetGraphicReplacementStream(
diff --git a/svx/source/dialog/compressgraphicdialog.cxx b/svx/source/dialog/compressgraphicdialog.cxx
index 856dd7a08149..1c32e8de0606 100644
--- a/svx/source/dialog/compressgraphicdialog.cxx
+++ b/svx/source/dialog/compressgraphicdialog.cxx
@@ -121,40 +121,41 @@ void CompressGraphicsDialog::Initialize()
 
 void CompressGraphicsDialog::Update()
 {
-    GfxLinkType aLinkType = m_aGraphic.GetGfxLink().GetType();
-    OUString aGraphicTypeString;
-    switch(aLinkType)
+    OUString aGraphicTypeString = SvxResId(STR_IMAGE_UNKNOWN);
+
+    auto pGfxLink = m_aGraphic.GetSharedGfxLink();
+    if (pGfxLink)
     {
-        case GfxLinkType::NativeGif:
-            aGraphicTypeString = SvxResId(STR_IMAGE_GIF);
-            break;
-        case GfxLinkType::NativeJpg:
-            aGraphicTypeString = SvxResId(STR_IMAGE_JPEG);
-            break;
-        case GfxLinkType::NativePng:
-            aGraphicTypeString = SvxResId(STR_IMAGE_PNG);
-            break;
-        case GfxLinkType::NativeTif:
-            aGraphicTypeString = SvxResId(STR_IMAGE_TIFF);
-            break;
-        case GfxLinkType::NativeWmf:
-            aGraphicTypeString = SvxResId(STR_IMAGE_WMF);
-            break;
-        case GfxLinkType::NativeMet:
-            aGraphicTypeString = SvxResId(STR_IMAGE_MET);
-            break;
-        case GfxLinkType::NativePct:
-            aGraphicTypeString = SvxResId(STR_IMAGE_PCT);
-            break;
-        case GfxLinkType::NativeSvg:
-            aGraphicTypeString = SvxResId(STR_IMAGE_SVG);
-            break;
-        case GfxLinkType::NativeBmp:
-            aGraphicTypeString = SvxResId(STR_IMAGE_BMP);
-            break;
-        default:
-            aGraphicTypeString = SvxResId(STR_IMAGE_UNKNOWN);
-            break;
+        switch (pGfxLink->GetType())
+        {
+            case GfxLinkType::NativeGif:
+                aGraphicTypeString = SvxResId(STR_IMAGE_GIF);
+                break;
+            case GfxLinkType::NativeJpg:
+                aGraphicTypeString = SvxResId(STR_IMAGE_JPEG);
+                break;
+            case GfxLinkType::NativePng:
+                aGraphicTypeString = SvxResId(STR_IMAGE_PNG);
+                break;
+            case GfxLinkType::NativeTif:
+                aGraphicTypeString = SvxResId(STR_IMAGE_TIFF);
+                break;
+            case GfxLinkType::NativeWmf:
+                aGraphicTypeString = SvxResId(STR_IMAGE_WMF);
+                break;
+            case GfxLinkType::NativeMet:
+                aGraphicTypeString = SvxResId(STR_IMAGE_MET);
+                break;
+            case GfxLinkType::NativePct:
+                aGraphicTypeString = SvxResId(STR_IMAGE_PCT);
+                break;
+            case GfxLinkType::NativeSvg:
+                aGraphicTypeString = SvxResId(STR_IMAGE_SVG);
+                break;
+            case GfxLinkType::NativeBmp:
+                aGraphicTypeString = SvxResId(STR_IMAGE_BMP);
+                break;
+        }
     }
     m_xLabelGraphicType->set_label(aGraphicTypeString);
 
@@ -189,10 +190,7 @@ void CompressGraphicsDialog::Update()
     aViewSizeString = aViewSizeString.replaceAll("$(DPI)", OUString::number(aValX));
     m_xFixedText3->set_label(aViewSizeString);
 
-    SvMemoryStream aMemStream;
-    aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
-    m_aGraphic.ExportNative(aMemStream);
-    m_aNativeSize = aMemStream.TellEnd();
+    m_aNativeSize = pGfxLink ? pGfxLink->GetDataSize() : 0;
 
     OUString aNativeSizeString = SvxResId(STR_IMAGE_CAPACITY);
     aNativeSizeString = aNativeSizeString.replaceAll("$(CAPACITY)",  OUString::number( m_aNativeSize  / 1024 ));
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index e39d475d8718..3d185a72afb9 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -64,6 +64,8 @@
 #include <comphelper/propertysequence.hxx>
 #include <osl/time.h>
 #include <comphelper/processfactory.hxx>
+#include <vcl/TypeSerializer.hxx>
+
 
 class Test : public SwModelTestBase
 {
@@ -1554,7 +1556,8 @@ DECLARE_OOXMLIMPORT_TEST(testTdf100072, "tdf100072.docx")
 
     // Read it back and dump it as an XML file.
     Graphic aGraphic;
-    ReadGraphic(aStream, aGraphic);
+    TypeSerializer aSerializer(aStream);
+    aSerializer.readGraphic(aGraphic);
     const GDIMetaFile& rMetaFile = aGraphic.GetGDIMetaFile();
     MetafileXmlDump dumper;
     xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, rMetaFile);
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index fec30772d5dd..c651fd8859f3 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -46,6 +46,7 @@
 #include <AnnotationWin.hxx>
 #include <com/sun/star/text/XDefaultNumberingProvider.hpp>
 #include <com/sun/star/awt/FontUnderline.hpp>
+#include <vcl/TypeSerializer.hxx>
 
 #include <svx/svdpage.hxx>
 #include <svx/svdview.hxx>
@@ -2151,7 +2152,8 @@ void SwUiWriterTest::testFdo87448()
 
     // Read it back and dump it as an XML file.
     Graphic aGraphic;
-    ReadGraphic(aStream, aGraphic);
+    TypeSerializer aSerializer(aStream);
+    aSerializer.readGraphic(aGraphic);
     const GDIMetaFile& rMetaFile = aGraphic.GetGDIMetaFile();
     MetafileXmlDump dumper;
     xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, rMetaFile);
diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx
index a598386ede3d..0e4ca6203a71 100644
--- a/sw/qa/extras/uiwriter/uiwriter3.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter3.cxx
@@ -10,6 +10,7 @@
 #include <swmodeltestbase.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <vcl/scheduler.hxx>
+#include <vcl/TypeSerializer.hxx>
 #include <com/sun/star/drawing/GraphicExportFilter.hpp>
 #include <IDocumentDrawModelAccess.hxx>
 #include <com/sun/star/text/TextContentAnchorType.hpp>
@@ -2084,7 +2085,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf133477)
 
     // Read it back and check the color of the first pixel.
     Graphic aGraphic;
-    ReadGraphic(aStream, aGraphic);
+    TypeSerializer aSerializer(aStream);
+    aSerializer.readGraphic(aGraphic);
+
     BitmapEx aBitmap = aGraphic.GetBitmapEx();
     CPPUNIT_ASSERT_EQUAL(Color(0, 102, 204), aBitmap.GetPixelColor(0, 0));
 }
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index e5312d2be203..c6f8091daebc 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -124,6 +124,7 @@
 
 #include <vcl/GraphicNativeTransform.hxx>
 #include <vcl/GraphicNativeMetadata.hxx>
+#include <vcl/TypeSerializer.hxx>
 #include <comphelper/lok.hxx>
 #include <sfx2/classificationhelper.hxx>
 #include <sfx2/sfxdlg.hxx>
@@ -2770,7 +2771,8 @@ bool SwTransferable::PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh,
 
         if(rData.GetSotStorageStream(SotClipboardFormatId::SVXB, xStm))
         {
-            ReadGraphic( *xStm, aGraphic );
+            TypeSerializer aSerializer(*xStm);
+            aSerializer.readGraphic(aGraphic);
             bRet = (GraphicType::NONE != aGraphic.GetType() && GraphicType::Default != aGraphic.GetType());
         }
 
diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx
index f4417a262d1c..1b80f0f452f1 100644
--- a/vcl/inc/impgraph.hxx
+++ b/vcl/inc/impgraph.hxx
@@ -197,11 +197,6 @@ private:
 
     BitmapChecksum      ImplGetChecksum() const;
 
-    bool                ImplExportNative( SvStream& rOStm ) const;
-
-    friend void         WriteImpGraphic(SvStream& rOStm, const ImpGraphic& rImpGraphic);
-    friend void         ReadImpGraphic(SvStream& rIStm, ImpGraphic& rImpGraphic);
-
     const std::shared_ptr<VectorGraphicData>& getVectorGraphicData() const;
 
     /// Gets the bitmap replacement for a vector graphic.
diff --git a/vcl/inc/pch/precompiled_vcl.hxx b/vcl/inc/pch/precompiled_vcl.hxx
index a816716d3ab6..2410dd92b4b0 100644
--- a/vcl/inc/pch/precompiled_vcl.hxx
+++ b/vcl/inc/pch/precompiled_vcl.hxx
@@ -247,7 +247,6 @@
 #if PCH_LEVEL >= 4
 #include <PhysicalFontCollection.hxx>
 #include <PhysicalFontFace.hxx>
-#include <TypeSerializer.hxx>
 #include <bitmapwriteaccess.hxx>
 #include <brdwin.hxx>
 #include <configsettings.hxx>
@@ -274,6 +273,7 @@
 #include <vcl/AccessibleBrowseBoxObjType.hxx>
 #include <vcl/BitmapFilter.hxx>
 #include <vcl/BitmapTools.hxx>
+#include <vcl/TypeSerializer.hxx>
 #include <vcl/QueueInfo.hxx>
 #include <vcl/accel.hxx>
 #include <vcl/alpha.hxx>
diff --git a/vcl/qa/cppunit/TypeSerializerTest.cxx b/vcl/qa/cppunit/TypeSerializerTest.cxx
index fd45662bdf20..265b7f760496 100644
--- a/vcl/qa/cppunit/TypeSerializerTest.cxx
+++ b/vcl/qa/cppunit/TypeSerializerTest.cxx
@@ -25,7 +25,7 @@
 #include <tools/vcompat.hxx>
 #include <comphelper/fileformat.h>
 
-#include <TypeSerializer.hxx>
+#include <vcl/TypeSerializer.hxx>
 
 #if USE_TLS_NSS
 #include <nss.h>
@@ -124,56 +124,6 @@ void TypeSerializerTest::testGraphic_Vector()
     aGraphic.makeAvailable();
     BitmapChecksum aChecksum = aGraphic.getVectorGraphicData()->GetChecksum();
 
-    // Test WriteGraphic - Native Format 5
-    {
-        SvMemoryStream aMemoryStream;
-        aMemoryStream.SetVersion(SOFFICE_FILEFORMAT_50);
-        aMemoryStream.SetCompressMode(SvStreamCompressFlags::NATIVE);
-        WriteGraphic(aMemoryStream, aGraphic);
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-
-        CPPUNIT_ASSERT_EQUAL(sal_uInt64(290), aMemoryStream.remainingSize());
-        std::vector<unsigned char> aHash = calculateHash(aMemoryStream);
-        CPPUNIT_ASSERT_EQUAL(std::string("ee55ab6faa73b61b68bc3d5628d95f0d3c528e2a"),
-                             toHexString(aHash));
-
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-        sal_uInt32 nType;
-        aMemoryStream.ReadUInt32(nType);
-        CPPUNIT_ASSERT_EQUAL(COMPAT_FORMAT('N', 'A', 'T', '5'), nType);
-
-        // Read it back
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-        Graphic aNewGraphic;
-        ReadGraphic(aMemoryStream, aNewGraphic);
-        CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aNewGraphic.GetType());
-        CPPUNIT_ASSERT_EQUAL(aChecksum, aNewGraphic.getVectorGraphicData()->GetChecksum());
-    }
-
-    // Test WriteGraphic - Normal
-    {
-        SvMemoryStream aMemoryStream;
-        WriteGraphic(aMemoryStream, aGraphic);
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-
-        CPPUNIT_ASSERT_EQUAL(sal_uInt64(233), aMemoryStream.remainingSize());
-        std::vector<unsigned char> aHash = calculateHash(aMemoryStream);
-        CPPUNIT_ASSERT_EQUAL(std::string("c2bed2099ce617f1cc035701de5186f0d43e3064"),
-                             toHexString(aHash));
-
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-        sal_uInt32 nType;
-        aMemoryStream.ReadUInt32(nType);
-        CPPUNIT_ASSERT_EQUAL(createMagic('s', 'v', 'g', '0'), nType);
-
-        // Read it back
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-        Graphic aNewGraphic;
-        ReadGraphic(aMemoryStream, aNewGraphic);
-        CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aNewGraphic.GetType());
-        CPPUNIT_ASSERT_EQUAL(aChecksum, aNewGraphic.getVectorGraphicData()->GetChecksum());
-    }
-
     // Test TypeSerializer - Native Format 5
     {
         SvMemoryStream aMemoryStream;
@@ -244,30 +194,6 @@ void TypeSerializerTest::testGraphic_Bitmap_NoGfxLink()
     BitmapEx aBitmapEx(aBitmap);
     Graphic aGraphic(aBitmapEx);
 
-    // Test WriteGraphic
-    {
-        SvMemoryStream aMemoryStream;
-        WriteGraphic(aMemoryStream, aGraphic);
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-
-        CPPUNIT_ASSERT_EQUAL(sal_uInt64(383), aMemoryStream.remainingSize());
-        std::vector<unsigned char> aHash = calculateHash(aMemoryStream);
-        CPPUNIT_ASSERT_EQUAL(std::string("da831418499146d51bf245fadf60b9111faa76c2"),
-                             toHexString(aHash));
-
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-        sal_uInt16 nType;
-        aMemoryStream.ReadUInt16(nType);
-        CPPUNIT_ASSERT_EQUAL(sal_uInt16(0x4D42), nType); // Magic written with WriteDIBBitmapEx
-
-        // Read it back
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-        Graphic aNewGraphic;
-        ReadGraphic(aMemoryStream, aNewGraphic);
-        CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aNewGraphic.GetType());
-        CPPUNIT_ASSERT_EQUAL(aBitmapEx.GetChecksum(), aNewGraphic.GetBitmapExRef().GetChecksum());
-    }
-
     // Test TypeSerializer
     {
         SvMemoryStream aMemoryStream;
@@ -310,56 +236,6 @@ void TypeSerializerTest::testGraphic_Animation()
     CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
     CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsAnimated());
 
-    // Test WriteGraphic
-    {
-        SvMemoryStream aMemoryStream;
-        WriteGraphic(aMemoryStream, aGraphic);
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-
-        CPPUNIT_ASSERT_EQUAL(sal_uInt64(15167), aMemoryStream.remainingSize());
-        std::vector<unsigned char> aHash = calculateHash(aMemoryStream);
-        CPPUNIT_ASSERT_EQUAL(std::string("69d0f80832a0aebcbda7ad43ecadf85e99fc1057"),
-                             toHexString(aHash));
-
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-        sal_uInt16 nType;
-        aMemoryStream.ReadUInt16(nType);
-        CPPUNIT_ASSERT_EQUAL(sal_uInt16(0x4D42), nType);
-
-        // Read it back
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-        Graphic aNewGraphic;
-        ReadGraphic(aMemoryStream, aNewGraphic);
-        CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aNewGraphic.GetType());
-        CPPUNIT_ASSERT_EQUAL(true, aNewGraphic.IsAnimated());
-    }
-
-    // Test WriteGraphic - Native Format 5
-    {
-        SvMemoryStream aMemoryStream;
-        aMemoryStream.SetVersion(SOFFICE_FILEFORMAT_50);
-        aMemoryStream.SetCompressMode(SvStreamCompressFlags::NATIVE);
-        WriteGraphic(aMemoryStream, aGraphic);
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-
-        CPPUNIT_ASSERT_EQUAL(sal_uInt64(1582), aMemoryStream.remainingSize());
-        std::vector<unsigned char> aHash = calculateHash(aMemoryStream);
-        CPPUNIT_ASSERT_EQUAL(std::string("da3b9600340fa80a895f2107357e4ab65a9292eb"),
-                             toHexString(aHash));
-
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-        sal_uInt32 nType;
-        aMemoryStream.ReadUInt32(nType);
-        CPPUNIT_ASSERT_EQUAL(COMPAT_FORMAT('N', 'A', 'T', '5'), nType);
-
-        // Read it back
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-        Graphic aNewGraphic;
-        ReadGraphic(aMemoryStream, aNewGraphic);
-        CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aNewGraphic.GetType());
-        CPPUNIT_ASSERT_EQUAL(true, aNewGraphic.IsAnimated());
-    }
-
     // Test TypeSerializer
     {
         SvMemoryStream aMemoryStream;
@@ -438,30 +314,6 @@ void TypeSerializerTest::testGraphic_GDIMetaFile()
     Graphic aGraphic(aGDIMetaFile);
     CPPUNIT_ASSERT_EQUAL(GraphicType::GdiMetafile, aGraphic.GetType());
 
-    // Test WriteGraphic
-    {
-        SvMemoryStream aMemoryStream;
-        WriteGraphic(aMemoryStream, aGraphic);
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-
-        CPPUNIT_ASSERT_EQUAL(sal_uInt64(229), aMemoryStream.remainingSize());
-        std::vector<unsigned char> aHash = calculateHash(aMemoryStream);
-        CPPUNIT_ASSERT_EQUAL(std::string("144c518e5149d61ab4bc34643df820372405d61d"),
-                             toHexString(aHash));
-
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-        char aIdCharArray[7] = { 0, 0, 0, 0, 0, 0, 0 };
-        aMemoryStream.ReadBytes(aIdCharArray, 6);
-        OString sID(aIdCharArray);
-        CPPUNIT_ASSERT_EQUAL(OString("VCLMTF"), sID);
-
-        // Read it back
-        aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
-        Graphic aNewGraphic;
-        ReadGraphic(aMemoryStream, aNewGraphic);
-        CPPUNIT_ASSERT_EQUAL(GraphicType::GdiMetafile, aNewGraphic.GetType());
-    }
-
     // Test TypeSerializer
     {
         SvMemoryStream aMemoryStream;
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index 65ae12a65931..2a708336d233 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -65,6 +65,7 @@
 #include <vector>
 #include <memory>
 #include <string_view>
+#include <vcl/TypeSerializer.hxx>
 
 #include "FilterConfigCache.hxx"
 #include "graphicfilter_internal.hxx"
@@ -1662,7 +1663,9 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
                     aFilterName.equalsIgnoreAsciiCase( IMP_SVMETAFILE ) )
         {
             // SV internal filters for import bitmaps and MetaFiles
-            ReadGraphic( rIStream, rGraphic );
+            TypeSerializer aSerializer(rIStream);
+            aSerializer.readGraphic(rGraphic);
+
             if( rIStream.GetError() )
             {
                 nStatus = ERRCODE_GRFILTER_FORMATERROR;
@@ -1675,7 +1678,9 @@ ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath,
         }
         else if( aFilterName.equalsIgnoreAsciiCase( IMP_MOV ) )
         {
-            ReadGraphic( rIStream, rGraphic );
+            TypeSerializer aSerializer(rIStream);
+            aSerializer.readGraphic(rGraphic);
+
             if( rIStream.GetError() )
                 nStatus = ERRCODE_GRFILTER_FORMATERROR;
             else
diff --git a/vcl/source/filter/graphicfilter2.cxx b/vcl/source/filter/graphicfilter2.cxx
index 382ee0777d96..987948917536 100644
--- a/vcl/source/filter/graphicfilter2.cxx
+++ b/vcl/source/filter/graphicfilter2.cxx
@@ -21,7 +21,7 @@
 #include <tools/stream.hxx>
 #include <tools/fract.hxx>
 #include <tools/urlobj.hxx>
-#include <TypeSerializer.hxx>
+#include <vcl/TypeSerializer.hxx>
 #include <vcl/outdev.hxx>
 #include <vcl/graphicfilter.hxx>
 #include <unotools/ucbstreamhelper.hxx>
diff --git a/vcl/source/font/font.cxx b/vcl/source/font/font.cxx
index e3fced8fc158..fdd9ef68413e 100644
--- a/vcl/source/font/font.cxx
+++ b/vcl/source/font/font.cxx
@@ -33,7 +33,7 @@
 #include <string_view>
 
 #include <rtl/instance.hxx>
-#include <TypeSerializer.hxx>
+#include <vcl/TypeSerializer.hxx>
 
 using namespace vcl;
 
diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx
index ac06a0d3bcb3..6e1e504ee670 100644
--- a/vcl/source/gdi/TypeSerializer.cxx
+++ b/vcl/source/gdi/TypeSerializer.cxx
@@ -17,7 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include <TypeSerializer.hxx>
+#include <vcl/TypeSerializer.hxx>
 #include <tools/vcompat.hxx>
 #include <sal/log.hxx>
 #include <comphelper/fileformat.h>
diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx
index 89390752d185..2da133abb35d 100644
--- a/vcl/source/gdi/gdimtf.cxx
+++ b/vcl/source/gdi/gdimtf.cxx
@@ -39,7 +39,7 @@
 #include <vcl/mtfxmldump.hxx>
 
 #include <svmconverter.hxx>
-#include <TypeSerializer.hxx>
+#include <vcl/TypeSerializer.hxx>
 
 #include <com/sun/star/beans/XFastPropertySet.hpp>
 #include <com/sun/star/rendering/MtfRenderer.hpp>
diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx
index 61f0dc3de354..bd59be143d5a 100644
--- a/vcl/source/gdi/graph.cxx
+++ b/vcl/source/gdi/graph.cxx
@@ -515,22 +515,6 @@ BitmapChecksum Graphic::GetChecksum() const
     return mxImpGraphic->ImplGetChecksum();
 }
 
-bool Graphic::ExportNative( SvStream& rOStream ) const
-{
-    return mxImpGraphic->ImplExportNative( rOStream );
-}
-
-void ReadGraphic(SvStream& rIStream, Graphic& rGraphic)
-{
-    rGraphic.ImplTestRefCount();
-    ReadImpGraphic(rIStream, *rGraphic.mxImpGraphic);
-}
-
-void WriteGraphic( SvStream& rOStream, const Graphic& rGraphic )
-{
-    WriteImpGraphic(rOStream, *rGraphic.mxImpGraphic);
-}
-
 const std::shared_ptr<VectorGraphicData>& Graphic::getVectorGraphicData() const
 {
     return mxImpGraphic->getVectorGraphicData();
diff --git a/vcl/source/gdi/graphictools.cxx b/vcl/source/gdi/graphictools.cxx
index 4be1b43fadb7..7ec3d7d36588 100644
--- a/vcl/source/gdi/graphictools.cxx
+++ b/vcl/source/gdi/graphictools.cxx
@@ -19,8 +19,7 @@
 
 #include <tools/stream.hxx>
 #include <tools/vcompat.hxx>
-#include <tools/GenericTypeSerializer.hxx>
-
+#include <vcl/TypeSerializer.hxx>
 #include <vcl/graphictools.hxx>
 
 SvtGraphicFill::Transform::Transform()
@@ -237,7 +236,7 @@ SvStream& WriteSvtGraphicFill( SvStream& rOStm, const SvtGraphicFill& rClass )
     VersionCompat aCompat( rOStm, StreamMode::WRITE, 1 );
 
     rClass.maPath.Write( rOStm );
-    tools::GenericTypeSerializer aSerializer(rOStm);
+    TypeSerializer aSerializer(rOStm);
     aSerializer.writeColor(rClass.maFillColor);
     rOStm.WriteDouble( rClass.mfTransparency );
     sal_uInt16 nTmp = sal::static_int_cast<sal_uInt16>( rClass.maFillRule );
@@ -257,7 +256,7 @@ SvStream& WriteSvtGraphicFill( SvStream& rOStm, const SvtGraphicFill& rClass )
     aSerializer.writeColor(rClass.maGradient1stColor);
     aSerializer.writeColor(rClass.maGradient2ndColor);
     rOStm.WriteInt32( rClass.maGradientStepCount );
-    WriteGraphic( rOStm, rClass.maFillGraphic );
+    aSerializer.writeGraphic(rClass.maFillGraphic);
 
     return rOStm;
 }
@@ -268,7 +267,7 @@ SvStream& ReadSvtGraphicFill( SvStream& rIStm, SvtGraphicFill& rClass )
 
     rClass.maPath.Read( rIStm );
 
-    tools::GenericTypeSerializer aSerializer(rIStm);
+    TypeSerializer aSerializer(rIStm);
     aSerializer.readColor(rClass.maFillColor);
     rIStm.ReadDouble( rClass.mfTransparency );
     sal_uInt16 nTmp;
@@ -288,7 +287,7 @@ SvStream& ReadSvtGraphicFill( SvStream& rIStm, SvtGraphicFill& rClass )
     aSerializer.readColor(rClass.maGradient1stColor);
     aSerializer.readColor(rClass.maGradient2ndColor);
     rIStm.ReadInt32( rClass.maGradientStepCount );
-    ReadGraphic( rIStm, rClass.maFillGraphic );
+    aSerializer.readGraphic(rClass.maFillGraphic);
 
     return rIStm;
 }
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index f40500b44519..6e444e3712ef 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -44,14 +44,13 @@
 #include <map>
 #include <memory>
 #include <vcl/gdimetafiletools.hxx>
-#include <TypeSerializer.hxx>
+#include <vcl/TypeSerializer.hxx>
 #include <vcl/pdfread.hxx>
 
 #define GRAPHIC_MTFTOBMP_MAXEXT     2048
 #define GRAPHIC_STREAMBUFSIZE       8192UL
 
 #define SWAP_FORMAT_ID COMPAT_FORMAT( 'S', 'W', 'A', 'P' )
-#define NATIVE_FORMAT_50            COMPAT_FORMAT( 'N', 'A', 'T', '5' )
 
 using namespace com::sun::star;
 
@@ -1667,31 +1666,6 @@ BitmapChecksum ImpGraphic::ImplGetChecksum() const
     return mnChecksum;
 }
 
-bool ImpGraphic::ImplExportNative( SvStream& rOStm ) const
-{
-    ensureAvailable();
-
-    if( rOStm.GetError() )
-        return false;
-
-    bool bResult = false;
-
-    if( !isSwappedOut() )
-    {
-        if( mpGfxLink && mpGfxLink->IsNative() )
-            bResult = mpGfxLink->ExportNative( rOStm );
-        else
-        {

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list